Skip to content

Commit

Permalink
fix: wallet not exist states
Browse files Browse the repository at this point in the history
  • Loading branch information
chalabi2 committed Dec 10, 2024
1 parent f059f3b commit 6994d01
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
18 changes: 12 additions & 6 deletions components/react/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,18 @@ export const TailwindModal: React.FC<
// 1ms timeout prevents _render from determining the view to show first
setTimeout(() => {
const wallet = walletRepo?.getWallet(name);

if (wallet?.isWalletNotExist) {
console.log(wallet?.state);
if (
wallet?.walletInfo.name === 'cosmos-extension-metamask' &&
wallet.message?.includes("Cannot read properties of undefined (reading 'request')")
) {
// This specific error indicates Metamask is not installed

Check warning on line 91 in components/react/modal.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/modal.tsx#L86-L91

Added lines #L86 - L91 were not covered by tests
setCurrentView(ModalView.NotExist);
setSelectedWallet(wallet);
}
if (wallet?.walletInfo.mode === 'wallet-connect') {
} else if (wallet?.isWalletNotExist) {
setCurrentView(ModalView.NotExist);
setSelectedWallet(wallet);
} else if (wallet?.walletInfo.mode === 'wallet-connect') {

Check warning on line 97 in components/react/modal.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/modal.tsx#L94-L97

Added lines #L94 - L97 were not covered by tests
setCurrentView(ModalView.QRCode);
setQRWallet(wallet);
}
Expand Down Expand Up @@ -125,11 +131,11 @@ export const TailwindModal: React.FC<
);
case ModalView.Connecting:
let subtitle: string;
if (currentWalletData!.mode === 'wallet-connect') {
if (currentWalletData!?.mode === 'wallet-connect') {

Check warning on line 134 in components/react/modal.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/modal.tsx#L134

Added line #L134 was not covered by tests
subtitle = `Approve ${currentWalletData!.prettyName} connection request on your mobile.`;
} else {
subtitle = `Open the ${
currentWalletData!.prettyName
currentWalletData!?.prettyName

Check warning on line 138 in components/react/modal.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/modal.tsx#L138

Added line #L138 was not covered by tests
} browser extension to connect your wallet.`;
}

Expand Down
2 changes: 1 addition & 1 deletion components/react/views/Error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const Error = ({
<div className="p-3 border rounded-full border-red-600 mx-auto aspect-1 flex-shrink-0">
<Image
src={
currentWalletName === 'Cosmos MetaMask Extension'
currentWalletName === 'cosmos-extension-metamask'
? '/metamask.svg'
: getRealLogo(logo)
}

Check warning on line 52 in components/react/views/Error.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/views/Error.tsx#L48-L52

Added lines #L48 - L52 were not covered by tests
Expand Down
11 changes: 7 additions & 4 deletions components/react/views/NotExist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const NotExist = ({
<ChevronLeftIcon className="w-5 h-5" aria-hidden="true" />
</button>
<Dialog.Title as="h3" className="text-lg font-semibold">
{name}
{name === 'Cosmos MetaMask Extension' ? 'Metamask' : name}

Check warning on line 31 in components/react/views/NotExist.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/views/NotExist.tsx#L31

Added line #L31 was not covered by tests
</Dialog.Title>
<button
type="button"
Expand All @@ -44,16 +44,19 @@ export const NotExist = ({
alt={name}
className="flex-shrink-0 w-16 h-16 mx-auto aspect-1"
/>
<p className="mt-3 font-medium text-black dark:text-white">Install {name}</p>
<p className="mt-3 font-medium text-black dark:text-white">
Install {name === 'Cosmos MetaMask Extension' ? 'Metamask' : name}
</p>

Check warning on line 49 in components/react/views/NotExist.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/views/NotExist.tsx#L47-L49

Added lines #L47 - L49 were not covered by tests
<p className="mt-1 text-sm text-gray-500 dark:text-white/75">
To connect your {name} wallet, install the browser extension.
To connect your {name === 'Cosmos MetaMask Extension' ? 'Metamask' : name} wallet, install
the browser extension.

Check warning on line 52 in components/react/views/NotExist.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/views/NotExist.tsx#L51-L52

Added lines #L51 - L52 were not covered by tests
</p>
<button
className={`rounded-lg btn-primary btn btn-md ${name.length >= 12 ? 'w-1/2' : 'w-1/3'} mx-auto inline-flex justify-center items-center py-2.5 font-medium mt-4 text-white`}
onClick={onInstall}
>
<ArrowDownTrayIcon className="flex-shrink-0 w-5 h-5 mr-2 text-white" />
Install {name}
Install {name === 'Cosmos MetaMask Extension' ? 'Metamask' : name}

Check warning on line 59 in components/react/views/NotExist.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/views/NotExist.tsx#L59

Added line #L59 was not covered by tests
</button>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/react/views/WalletList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const WalletList = ({
wallet.walletInfo.prettyName
)

Check warning on line 26 in components/react/views/WalletList.tsx

View check run for this annotation

Codecov / codecov/patch

components/react/views/WalletList.tsx#L24-L26

Added lines #L24 - L26 were not covered by tests
);
console.log(wallets);

const mobile = wallets.filter(wallet =>
['Wallet Connect', 'Keplr Mobile', 'Cosmostation Mobile', 'Leap Mobile'].includes(
wallet.walletInfo.prettyName
Expand Down
2 changes: 1 addition & 1 deletion pages/groups/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function CreateGroup() {
const [currentStep, setCurrentStep] = useState(1);
const [formData, dispatch] = useReducer(formDataReducer, initialFormData);
const { address } = useChain(chainName);
console.log(formData);

const nextStep = () => {
if (currentStep < 5) {
setCurrentStep(currentStep + 1);
Expand Down

0 comments on commit 6994d01

Please sign in to comment.