Skip to content

Commit

Permalink
feat: add a timeout when approving a wallet connect request
Browse files Browse the repository at this point in the history
  • Loading branch information
manu0466 committed Mar 25, 2024
1 parent cac365a commit 596fac5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/assets/locales/en/walletConnect.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"app authorized, you can return to the app": "{{app}} authorized, you can return to the app",
"go to authorization": "Go to authorization",
"error while closing session": "Ooops an error occurred while terminating the session:\n{{error}}",
"initializing new session": "Initializing new WalletConnect session..."
"initializing new session": "Initializing new WalletConnect session...",
"request timed out": "Request timed out, please try again.\nIf the issue persists, please reinitialize the WalletConnect session"
}
19 changes: 13 additions & 6 deletions src/screens/WalletConnectRequest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { SigningMode } from '@desmoslabs/desmjs';
import SingleButtonModal from 'modals/SingleButtonModal';
import useShowModal from 'hooks/useShowModal';
import { useRemoveWalletConnectSessionRequest } from '@recoil/walletConnectRequests';
import { PromiseTimeout } from 'lib/PromiseUtils';
import { useRejectAllRequests, useRequestFields } from './useHooks';
import useStyles from './useStyles';

Expand Down Expand Up @@ -104,19 +105,25 @@ const WalletConnectRequest: React.FC<NavProps> = (props) => {
request.accountAddress,
request.signDoc,
);
const responseResult = await walletConnectResponse(
request,
encodeDirectSignRpcResponse(signResponse),
const responseResult = await PromiseTimeout.wrap(
walletConnectResponse(request, encodeDirectSignRpcResponse(signResponse)),
10000,
);
if (responseResult.isErr()) {
showErrorModal(responseResult.error.message);
if (responseResult.isCompleted()) {
const result = responseResult.resultData;

if (result.isErr()) {
showErrorModal(result.error.message);
}
} else {
showErrorModal(t('request timeout'));
}
} else {
showErrorModal(`Unsupported method ${request.method}`);
}
setSigning(false);
}
}, [request, showErrorModal, unlockWallet, walletConnectResponse]);
}, [request, showErrorModal, t, unlockWallet, walletConnectResponse]);

return request !== null ? (
<StyledSafeAreaView topBar={<TopBar stackProps={props} title={t('common:tx details')} />}>
Expand Down

0 comments on commit 596fac5

Please sign in to comment.