diff --git a/src/hooks/common-helpers/sendTxOperations.ts b/src/hooks/common-helpers/signAndSendTxOperations.ts similarity index 90% rename from src/hooks/common-helpers/sendTxOperations.ts rename to src/hooks/common-helpers/signAndSendTxOperations.ts index 0b2fa89..66471db 100644 --- a/src/hooks/common-helpers/sendTxOperations.ts +++ b/src/hooks/common-helpers/signAndSendTxOperations.ts @@ -24,6 +24,14 @@ export interface TransactionCallbackParams { txResult?: ITransactionOnNetwork | null; } +export const preSendTxOperations = (signedTx: Transaction) => { + const sender = signedTx.getSender(); + const currentNonce = signedTx.getNonce().valueOf(); + const senderAccount = new Account(sender); + senderAccount.incrementNonce(); + setAccountState('nonce', currentNonce + 1); +}; + export const postSendTxOperations = async ( signedTx: Transaction, setTransaction: Dispatch>, @@ -47,7 +55,7 @@ export const postSendTxOperations = async ( } }; -export const sendTxOperations = async ( +export const signAndSendTxOperations = async ( dappProvider: DappProvider, tx: Transaction, loginInfoSnap: LoginInfoState, @@ -77,6 +85,7 @@ export const sendTxOperations = async ( signedTx = await dappProvider.signTransaction(tx); } if (loginInfoSnap.loginMethod !== LoginMethodsEnum.wallet) { + preSendTxOperations(signedTx); await apiNetworkProvider.sendTransaction(signedTx); await postSendTxOperations( signedTx, diff --git a/src/hooks/common-helpers/useWebWalletTxSend.tsx b/src/hooks/common-helpers/useWebWalletTxSend.tsx index 3fb66d2..52d4188 100644 --- a/src/hooks/common-helpers/useWebWalletTxSend.tsx +++ b/src/hooks/common-helpers/useWebWalletTxSend.tsx @@ -7,8 +7,9 @@ import { Transaction, ITransactionOnNetwork } from '@multiversx/sdk-core'; import { getParamFromUrl } from '../../utils/getParamFromUrl'; import { postSendTxOperations, + preSendTxOperations, TransactionCallbackParams, -} from './sendTxOperations'; +} from './signAndSendTxOperations'; import { errorParse } from '../../utils/errorParse'; import { ApiNetworkProvider } from '@multiversx/sdk-network-providers/out'; import { useAccount } from '../useAccount'; @@ -59,6 +60,7 @@ export const useWebWalletTxSend = ({ const transaction = Transaction.fromPlainObject(transactionObj); try { + preSendTxOperations(transaction); await networkStateSnap.apiNetworkProvider.sendTransaction( transaction ); diff --git a/src/hooks/useTransaction.tsx b/src/hooks/useTransaction.tsx index 9109743..fc69e90 100644 --- a/src/hooks/useTransaction.tsx +++ b/src/hooks/useTransaction.tsx @@ -7,15 +7,13 @@ import { IGasLimit, ITransactionValue, ITransactionOnNetwork, - Account, } from '@multiversx/sdk-core'; import { useWebWalletTxSend } from './common-helpers/useWebWalletTxSend'; import { TransactionCallbackParams, - sendTxOperations, -} from './common-helpers/sendTxOperations'; + signAndSendTxOperations, +} from './common-helpers/signAndSendTxOperations'; import { DappProvider } from '../types/network'; -import { setAccountState } from '../store/auth'; import { ApiNetworkProvider } from '@multiversx/sdk-network-providers/out'; import { useConfig } from './useConfig'; import { useLoginInfo } from './useLoginInfo'; @@ -85,11 +83,7 @@ export function useTransaction( sender, }); - const senderAccount = new Account(sender); - senderAccount.incrementNonce(); - setAccountState('nonce', currentNonce + 1); - - sendTxOperations( + signAndSendTxOperations( networkStateSnap.dappProvider as DappProvider, tx, loginInfoSnap, diff --git a/src/index.tsx b/src/index.tsx index 3c2e46f..3ecf5e3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -20,6 +20,6 @@ export { useScQuery } from './hooks/useScQuery'; export * from './types/account'; export * from './types/enums'; export * from './types/network'; -export { TransactionCallbackParams } from './hooks/common-helpers/sendTxOperations'; +export { TransactionCallbackParams } from './hooks/common-helpers/signAndSendTxOperations'; export { SCQueryType } from './hooks/useScQuery'; export { PairingTypes } from '@multiversx/sdk-wallet-connect-provider';