Skip to content

Commit

Permalink
fix: walletconnect throw error if empty accounts (#1591)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidmorizon authored Sep 20, 2022
1 parent f6025fe commit 43f7bd7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class ProviderApiWalletConnect extends WalletConnectClientForWallet {
});

const chainId = await this.getChainIdInteger(connector);
// walletConnect approve empty accounts is not allowed
if (!result || !result.length) {
throw new Error('WalletConnect Session error: accounts is empty');
}
return { chainId, accounts: result };
}

Expand Down
16 changes: 14 additions & 2 deletions packages/kit/src/views/DappModals/Connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type RouteProps = RouteProp<
DappConnectionModalRoutes.ConnectionModal
>;

let lastWalletConnectUri: string | undefined = '';

/* Connection Modal are use to accept user with permission to dapp */
const defaultSourceInfo = Object.freeze({}) as IDappSourceInfo;
const Connection = () => {
Expand All @@ -90,6 +92,7 @@ const Connection = () => {
}, [origin]);
const route = useRoute<RouteProps>();
const walletConnectUri = route?.params?.walletConnectUri;
lastWalletConnectUri = walletConnectUri;
const isWalletConnectPreloading = Boolean(walletConnectUri);
const [walletConnectError, setWalletConnectError] = useState<string>('');
const closeModal = useModalClose();
Expand All @@ -115,15 +118,24 @@ const Connection = () => {
isWalletConnectPreloading,
]);

useEffect(
() => () => {
isClosedDone.current = true;
},
[],
);

useEffect(() => {
if (walletConnectUri) {
backgroundApiProxy.walletConnect
.connect({
uri: walletConnectUri || '',
})
.then(() => {
isClosedDone.current = true;
closeModal();
if (!isClosedDone.current && lastWalletConnectUri) {
closeModal();
isClosedDone.current = true;
}
dispatch(refreshConnectedSites());
})
.catch((error) => {
Expand Down

0 comments on commit 43f7bd7

Please sign in to comment.