From e1f856e977134df603967d1ad1c4ecf155a2adab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20=C4=86wirko?= Date: Sun, 4 Jun 2023 17:16:27 +0200 Subject: [PATCH] fix web wallet transaction callbackUrl --- CHANGELOG.md | 2 +- src/hooks/common-helpers/signAndSendTxOperations.ts | 7 ++++++- src/hooks/common-helpers/useWebWalletTxSend.tsx | 3 ++- src/hooks/useTransaction.tsx | 1 - 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3ae892..039f505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ### [0.6.0](https://github.com/useElven/core/releases/tag/v0.6.0) (2023-06-04) -- improvements for nonce incrementation to let triggering multiple transactions at the same time. The logic is slightly different, but it shouldn't break anything +- improvements for nonce incrementation to let trigger multiple transactions at the same time. The logic is slightly different, but it shouldn't break anything (you can test it [here](https://useelven-react-vite-demo.netlify.app/). For now, additional steps are required for the Web Wallet to manage the pending states in UI properly. They solution is presented in the [demo here](https://github.com/useElven/react-vite/blob/main/src/components/demo/EgldTx.tsx)). There will be more improvements in that regard. ### [0.5.0](https://github.com/useElven/core/releases/tag/v0.5.0) (2023-05-28) - Breaking: switch to using sdk-native-auth-client instead passing string-based login tokens. There is no fallback or other option, so it is a breaking change. Native Auth is recommended. The old way of doing that will be deprecated. Please freeze the previous version if you are not ready to switch yet diff --git a/src/hooks/common-helpers/signAndSendTxOperations.ts b/src/hooks/common-helpers/signAndSendTxOperations.ts index 66471db..40e85df 100644 --- a/src/hooks/common-helpers/signAndSendTxOperations.ts +++ b/src/hooks/common-helpers/signAndSendTxOperations.ts @@ -72,7 +72,12 @@ export const signAndSendTxOperations = async ( if (dappProvider instanceof WalletProvider) { const currentUrl = window?.location.href; await dappProvider.signTransaction(tx, { - callbackUrl: webWalletRedirectUrl || currentUrl, + callbackUrl: + webWalletRedirectUrl && window + ? encodeURIComponent( + `${window.location.origin}${webWalletRedirectUrl}` + ) + : currentUrl, }); } if (dappProvider instanceof ExtensionProvider) { diff --git a/src/hooks/common-helpers/useWebWalletTxSend.tsx b/src/hooks/common-helpers/useWebWalletTxSend.tsx index 52d4188..64058cf 100644 --- a/src/hooks/common-helpers/useWebWalletTxSend.tsx +++ b/src/hooks/common-helpers/useWebWalletTxSend.tsx @@ -54,7 +54,7 @@ export const useWebWalletTxSend = ({ transactionObj.data = Buffer.from(transactionObj.data).toString( 'base64' ); - window.history.replaceState(null, '', window.location.pathname); + setPending(true); cb?.({ pending: true }); const transaction = Transaction.fromPlainObject(transactionObj); @@ -80,6 +80,7 @@ export const useWebWalletTxSend = ({ setPending(false); cb?.({ pending: false }); setAccountState('nonce', currentNonce + 1); + window.history.replaceState(null, '', window.location.pathname); } } }; diff --git a/src/hooks/useTransaction.tsx b/src/hooks/useTransaction.tsx index fc69e90..4b86562 100644 --- a/src/hooks/useTransaction.tsx +++ b/src/hooks/useTransaction.tsx @@ -65,7 +65,6 @@ export function useTransaction( networkStateSnap.dappProvider && networkStateSnap.apiNetworkProvider && currentNonce !== undefined && - !pending && accountSnap.address ) { setPending(true);