From 6ff622270a33467c91bb165341cc20e4ac09ea25 Mon Sep 17 00:00:00 2001 From: Ilias Trichopoulos Date: Thu, 9 Jan 2025 14:22:11 +0800 Subject: [PATCH] Support alph_signAndSubmitUnsignedTx in mobile wallet Closes #1083 --- .changeset/red-cows-fly.md | 5 +++++ .../walletConnect/WalletConnectContext.tsx | 6 ++++-- .../WalletConnectSessionRequestModal.tsx | 15 ++++++++++++++- apps/mobile-wallet/src/types/walletConnect.ts | 1 + 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 .changeset/red-cows-fly.md diff --git a/.changeset/red-cows-fly.md b/.changeset/red-cows-fly.md new file mode 100644 index 000000000..2debdeb27 --- /dev/null +++ b/.changeset/red-cows-fly.md @@ -0,0 +1,5 @@ +--- +"@alephium/mobile-wallet": patch +--- + +Support alph_signAndSubmitUnsignedTx diff --git a/apps/mobile-wallet/src/contexts/walletConnect/WalletConnectContext.tsx b/apps/mobile-wallet/src/contexts/walletConnect/WalletConnectContext.tsx index 7db851e54..59aedcf2b 100644 --- a/apps/mobile-wallet/src/contexts/walletConnect/WalletConnectContext.tsx +++ b/apps/mobile-wallet/src/contexts/walletConnect/WalletConnectContext.tsx @@ -690,7 +690,8 @@ export const WalletConnectContextProvider = ({ children }: { children: ReactNode break } - case 'alph_signUnsignedTx': { + case 'alph_signUnsignedTx': + case 'alph_signAndSubmitUnsignedTx': { const { signerAddress, signerKeyType, unsignedTx } = requestEvent.params.request .params as SignUnsignedTxParams @@ -725,7 +726,8 @@ export const WalletConnectContextProvider = ({ children }: { children: ReactNode requestData: { type: 'sign-unsigned-tx', wcData: wcTxData, - unsignedTxData: decodedResult + unsignedTxData: decodedResult, + submit: requestEvent.params.request.method === 'alph_signAndSubmitUnsignedTx' } } }) diff --git a/apps/mobile-wallet/src/contexts/walletConnect/WalletConnectSessionRequestModal.tsx b/apps/mobile-wallet/src/contexts/walletConnect/WalletConnectSessionRequestModal.tsx index 9c3942f34..14635ec59 100644 --- a/apps/mobile-wallet/src/contexts/walletConnect/WalletConnectSessionRequestModal.tsx +++ b/apps/mobile-wallet/src/contexts/walletConnect/WalletConnectSessionRequestModal.tsx @@ -1,4 +1,10 @@ -import { getHumanReadableError, SessionRequestEvent, WALLETCONNECT_ERRORS, WalletConnectError } from '@alephium/shared' +import { + client, + getHumanReadableError, + SessionRequestEvent, + WALLETCONNECT_ERRORS, + WalletConnectError +} from '@alephium/shared' import { ALPH } from '@alephium/token-list' import { binToHex, @@ -212,6 +218,13 @@ const WalletConnectSessionRequestModal = withModal( await getAddressAsymetricKey(signAddress.hash, 'private') ) + if (requestData.submit) { + await client.node.transactions.postTransactionsSubmit({ + unsignedTx: requestData.wcData.unsignedTx, + signature + }) + } + signResult = { ...requestData.unsignedTxData, signature, diff --git a/apps/mobile-wallet/src/types/walletConnect.ts b/apps/mobile-wallet/src/types/walletConnect.ts index 602795716..0dd8006ff 100644 --- a/apps/mobile-wallet/src/types/walletConnect.ts +++ b/apps/mobile-wallet/src/types/walletConnect.ts @@ -38,4 +38,5 @@ export type SessionRequestData = type: 'sign-unsigned-tx' wcData: SignUnsignedTxData unsignedTxData: DecodeUnsignedTxResult + submit: boolean }