diff --git a/CHANGELOG.md b/CHANGELOG.md index 378f8aa..a69f60b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### [0.15.1](https://github.com/useElven/core/releases/tag/v0.15.1) (2023-12-29) +- add missing transaction id logic for guardian 2FA hooks + ### [0.15.0](https://github.com/useElven/core/releases/tag/v0.15.0) (2023-12-28) - change the way we're getting the smart contract address in the useScDeploy hook - add optional id for all hooks that use useTransaction. It helps with signing providers' logic based on redirections to diferentiate and track which hook triggered the redirection diff --git a/package.json b/package.json index 27594ee..47c83da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@useelven/core", - "version": "0.15.0", + "version": "0.15.1", "description": "Core React hooks for MultiversX DApps", "license": "MIT", "author": "Julian Ćwirko ", diff --git a/src/hooks/common-helpers/signAndSendTxOperations.ts b/src/hooks/common-helpers/signAndSendTxOperations.ts index 55d38d7..9a6f70f 100644 --- a/src/hooks/common-helpers/signAndSendTxOperations.ts +++ b/src/hooks/common-helpers/signAndSendTxOperations.ts @@ -100,21 +100,36 @@ export const checkNeedsGuardianSigning = ( return true; }; +const getCallbackUrl = ( + ongoingTxId?: string, + webWalletRedirectUrl?: string +) => { + const currentUrl = window?.location?.href; + const clbck = + webWalletRedirectUrl && window + ? `${window.location.origin}${webWalletRedirectUrl}` + : currentUrl; + if (!ongoingTxId) return clbck; + + const alteredCallbackUrl = new URL(clbck); + alteredCallbackUrl.searchParams.set('ongoingTx', ongoingTxId); + + return alteredCallbackUrl.toString(); +}; + export const sendTxToGuardian = async ( signedTx: Transaction, walletAddress?: string, - webWalletRedirectUrl?: string + webWalletRedirectUrl?: string, + ongoingTxId?: string ) => { const webWalletProvider = new WalletProvider( `${walletAddress}${DAPP_INIT_ROUTE}` ); - const currentUrl = window?.location.href; - const callbackUrl = - webWalletRedirectUrl && window - ? `${window.location.origin}${webWalletRedirectUrl}` - : currentUrl; - const alteredCallbackUrl = new URL(callbackUrl); + const clbck = getCallbackUrl(ongoingTxId, webWalletRedirectUrl); + + const alteredCallbackUrl = new URL(clbck); alteredCallbackUrl.searchParams.set( WebWalletUrlParamsEnum.hasWebWalletGuardianSign, 'true' @@ -148,21 +163,10 @@ export const signAndSendTxOperations = async ( try { if (dappProvider instanceof WalletProvider) { - const currentUrl = window?.location?.href; - const getCallback = () => { - const clbck = - webWalletRedirectUrl && window - ? `${window.location.origin}${webWalletRedirectUrl}` - : currentUrl; - if (!ongoingTxId) return clbck; - if (webWalletRedirectUrl?.includes('?')) { - return `${clbck}&ongoingTx=${ongoingTxId}`; - } - return `${clbck}?ongoingTx=${ongoingTxId}`; - }; - await dappProvider.signTransaction(tx, { - callbackUrl: encodeURIComponent(getCallback()), + callbackUrl: encodeURIComponent( + getCallbackUrl(ongoingTxId, webWalletRedirectUrl) + ), }); } if (dappProvider instanceof ExtensionProvider) { @@ -185,7 +189,12 @@ export const signAndSendTxOperations = async ( ); if (needsGuardianSign) { - await sendTxToGuardian(signedTx, walletAddress, webWalletRedirectUrl); + await sendTxToGuardian( + signedTx, + walletAddress, + webWalletRedirectUrl, + ongoingTxId + ); return; }