Skip to content

Commit

Permalink
Fix showing SetAddressModal if chain id isn't supported by the wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
toddkao committed Jan 13, 2025
1 parent 7709f59 commit aa29208
Showing 1 changed file with 46 additions and 31 deletions.
77 changes: 46 additions & 31 deletions packages/widget/src/hooks/useAutoSetAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ export const useAutoSetAddress = () => {
if (chainAddresses[index]?.address) return;
switch (chainType) {
case ChainType.Cosmos: {
const wallets = createCosmosWallets(chainID);
const wallet = wallets.find((w) => w.walletName === sourceWallet.cosmos?.walletName);
if (!wallet) {
if (!openModal) return;
NiceModal.show(Modals.SetAddressModal, {
signRequired: isSignRequired,
chainId: chainID,
chainAddressIndex: index,
});
return;
}
try {
const wallets = createCosmosWallets(chainID);
const wallet = wallets.find((w) => w.walletName === sourceWallet.cosmos?.walletName);
if (!wallet) {
if (!openModal) return;
NiceModal.show(Modals.SetAddressModal, {
signRequired: isSignRequired,
chainId: chainID,
chainAddressIndex: index,
});
return;
}
const address = await wallet?.getAddress?.({
signRequired: isSignRequired,
});
Expand All @@ -116,22 +116,27 @@ export const useAutoSetAddress = () => {
},
}));
} catch (_) {
return;
}
break;
}
case ChainType.SVM: {
const wallets = createSolanaWallets();
const wallet = wallets.find((w) => w.walletName === sourceWallet.svm?.walletName);
if (!wallet) {
if (!openModal) return;
NiceModal.show(Modals.SetAddressModal, {
signRequired: isSignRequired,
chainId: chainID,
chainAddressIndex: index,
});
return;
}
break;
}
case ChainType.SVM: {
try {
const wallets = createSolanaWallets();
const wallet = wallets.find((w) => w.walletName === sourceWallet.svm?.walletName);
if (!wallet) {
if (!openModal) return;
NiceModal.show(Modals.SetAddressModal, {
signRequired: isSignRequired,
chainId: chainID,
});
return;
}
const address = await wallet?.getAddress?.({
signRequired: isSignRequired,
});
Expand All @@ -154,23 +159,28 @@ export const useAutoSetAddress = () => {
},
}));
} catch (_) {
return;
}

break;
}
case ChainType.EVM: {
const wallets = createEvmWallets(chainID);
const wallet = wallets.find((w) => w.walletName === sourceWallet.evm?.walletName);
if (!wallet) {
if (!openModal) return;
NiceModal.show(Modals.SetAddressModal, {
signRequired: isSignRequired,
chainId: chainID,
chainAddressIndex: index,
});
return;
}

break;
}
case ChainType.EVM: {
try {
const wallets = createEvmWallets(chainID);
const wallet = wallets.find((w) => w.walletName === sourceWallet.evm?.walletName);
if (!wallet) {
if (!openModal) return;
NiceModal.show(Modals.SetAddressModal, {
signRequired: isSignRequired,
chainId: chainID,
});
return;
}
const address = await wallet?.getAddress?.({
signRequired: isSignRequired,
});
Expand All @@ -193,7 +203,12 @@ export const useAutoSetAddress = () => {
},
}));
} catch (_) {
return;
if (!openModal) return;
NiceModal.show(Modals.SetAddressModal, {
signRequired: isSignRequired,
chainId: chainID,
chainAddressIndex: index,
});
}
break;
}
Expand Down

0 comments on commit aa29208

Please sign in to comment.