From 96c0a4df06092ac412ce80007080fcdfcea98b48 Mon Sep 17 00:00:00 2001 From: nabarun Date: Tue, 15 Jul 2025 16:05:02 +0000 Subject: [PATCH] Add support for `wallet_getCapabilities` from WalletConnect (#39) Part of https://www.notion.so/Integrate-eSIM-buy-flow-into-app-18aa6b22d47280d4a77cf1b27e2ba193 - Add Base network - Check sufficient balance for Eth tx fees Co-authored-by: pranavjadhav007 Reviewed-on: https://git.vdb.to/LaconicNetwork/laconic-wallet-web/pulls/39 --- src/App.tsx | 18 ++++++++ src/components/Header.tsx | 2 +- src/components/PairingModal.tsx | 32 ++++++++------ src/screens/AddSession.tsx | 2 +- src/screens/ApproveTransfer.tsx | 60 +++++++++++++++----------- src/screens/SignRequest.tsx | 5 ++- src/screens/WalletConnect.tsx | 21 +++++---- src/utils/accounts.ts | 2 +- src/utils/constants.ts | 12 ++++++ src/utils/wallet-connect/EIP155Data.ts | 16 +++---- 10 files changed, 109 insertions(+), 61 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 9cbe0bf..52b76ac 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -146,6 +146,23 @@ const App = (): React.JSX.Element => { requestSessionData, }); break; + + case EIP155_SIGNING_METHODS.WALLET_GET_CAPABILITIES: + const supportedNetworks = networksData + .filter(network => network.namespace === EIP155) + .map(network => `${network.namespace}:${network.chainId}`); + const capabilitiesResponse = formatJsonRpcResult(id, { + accountManagement: true, + sessionManagement: true, + supportedAuthMethods: ['personal_sign', 'eth_sendTransaction'], + supportedNetworks: supportedNetworks, + }); + + await web3wallet!.respondSessionRequest({ + topic, + response: capabilitiesResponse, + }); + break; case COSMOS_METHODS.COSMOS_SIGN_DIRECT: const message = { @@ -347,6 +364,7 @@ const App = (): React.JSX.Element => { // eslint-disable-next-line react/no-unstable-nested-components headerRight: () => ( )} diff --git a/src/components/PairingModal.tsx b/src/components/PairingModal.tsx index 5fbec48..b8249d7 100644 --- a/src/components/PairingModal.tsx +++ b/src/components/PairingModal.tsx @@ -282,20 +282,24 @@ const PairingModal = ({ )} - - - - - - + + {currentProposal && namespaces && ( + + + + + + )} + diff --git a/src/screens/AddSession.tsx b/src/screens/AddSession.tsx index 430cccb..5beaa8a 100644 --- a/src/screens/AddSession.tsx +++ b/src/screens/AddSession.tsx @@ -44,7 +44,7 @@ const AddSession = () => { /> - diff --git a/src/screens/ApproveTransfer.tsx b/src/screens/ApproveTransfer.tsx index f32e2a3..8a5c54a 100644 --- a/src/screens/ApproveTransfer.tsx +++ b/src/screens/ApproveTransfer.tsx @@ -82,23 +82,27 @@ const ApproveTransfer = ({ route }: ApproveTransferProps) => { useState(); const isSufficientFunds = useMemo(() => { - if (!transaction.value) { - return; - } - if (!balance) { return; } - const amountBigNum = BigNumber.from(String(transaction.value)); - const balanceBigNum = BigNumber.from(balance); - - if (amountBigNum.gte(balanceBigNum)) { - return false; - } else { - return true; + if (!fees) { + return; } - }, [balance, transaction]); + + const balanceBigNum = BigNumber.from(balance); + const feesBigNum = BigNumber.from(fees); + let totalRequiredBigNum = feesBigNum; + + if (transaction.value) { + const amountBigNum = BigNumber.from(String(transaction.value)); + totalRequiredBigNum = amountBigNum.add(feesBigNum); + } + + // Compare the user's balance with the total required amount + const isSufficient = balanceBigNum.gte(totalRequiredBigNum); + return isSufficient; + }, [balance, transaction.value, fees]); const requestedNetwork = networksData.find( networkData => @@ -273,8 +277,12 @@ const ApproveTransfer = ({ route }: ApproveTransferProps) => { useEffect(() => { if (namespace === EIP155) { - const ethFees = BigNumber.from(ethGasLimit ?? 0) - .mul(BigNumber.from(ethMaxFee ?? ethGasPrice ?? 0)) + if (!ethGasLimit || !(ethMaxFee || ethGasPrice)){ + return; + } + + const ethFees = BigNumber.from(ethGasLimit) + .mul(BigNumber.from(ethMaxFee ?? ethGasPrice)) .toString(); setFees(ethFees); } else { @@ -495,7 +503,7 @@ const ApproveTransfer = ({ route }: ApproveTransferProps) => { useEffect(() => { const getEthGas = async () => { try { - if (!isSufficientFunds || !provider) { + if (!provider) { return; } @@ -568,11 +576,11 @@ const ApproveTransfer = ({ route }: ApproveTransferProps) => { }, [cosmosStargateClient, isSufficientFunds, sendMsg, transaction,txMemo]); useEffect(() => { - if (balance && !isSufficientFunds) { + if (balance && !isSufficientFunds && !fees) { setTxError('Insufficient funds'); setIsTxErrorDialogOpen(true); } - }, [isSufficientFunds, balance]); + }, [isSufficientFunds, balance, fees]); return ( <> @@ -614,14 +622,16 @@ const ApproveTransfer = ({ route }: ApproveTransferProps) => { {transaction && ( - + {transaction.value !== undefined && transaction.value !== null && ( + + )} {namespace === COSMOS && ( { ); useEffect(() => { - if (route.path) { + const requestEvent = route.params.requestEvent; + if (route.path && !requestEvent) { const sanitizedRoute = sanitizePath(route.path); sanitizedRoute && retrieveData( @@ -127,7 +128,6 @@ const SignRequest = ({ route }: SignRequestProps) => { ); return; } - const requestEvent = route.params.requestEvent; const requestChainId = requestEvent?.params.chainId; const requestedChain = networksData.find( @@ -310,6 +310,7 @@ const SignRequest = ({ route }: SignRequestProps) => {