diff --git a/CHANGELOG.md b/CHANGELOG.md index 40a9661..d3ae892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### [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 + ### [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 - update dependencies diff --git a/package-lock.json b/package-lock.json index 451e37f..98fcc5a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -463,9 +463,9 @@ } }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.8", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", - "integrity": "sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==", + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz", + "integrity": "sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==", "dev": true, "dependencies": { "@humanwhocodes/object-schema": "^1.2.1", @@ -725,15 +725,6 @@ "axios": "^0.27.2" } }, - "node_modules/@multiversx/sdk-native-auth-client/node_modules/axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", - "dependencies": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" - } - }, "node_modules/@multiversx/sdk-network-providers": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/@multiversx/sdk-network-providers/-/sdk-network-providers-1.4.0.tgz", @@ -746,6 +737,14 @@ "json-bigint": "1.0.0" } }, + "node_modules/@multiversx/sdk-network-providers/node_modules/axios": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz", + "integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==", + "dependencies": { + "follow-redirects": "^1.14.4" + } + }, "node_modules/@multiversx/sdk-transaction-decoder": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@multiversx/sdk-transaction-decoder/-/sdk-transaction-decoder-1.0.2.tgz", @@ -1451,6 +1450,17 @@ "tslib": "1.14.1" } }, + "node_modules/@walletconnect/heartbeat": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@walletconnect/heartbeat/-/heartbeat-1.2.1.tgz", + "integrity": "sha512-yVzws616xsDLJxuG/28FqtZ5rzrTA4gUjdEMTbWB5Y8V1XHRmqq4efAxCw5ie7WjbXFSUyBHaWlMR+2/CpQC5Q==", + "extraneous": true, + "dependencies": { + "@walletconnect/events": "^1.0.1", + "@walletconnect/time": "^1.0.2", + "tslib": "1.14.1" + } + }, "node_modules/@walletconnect/iso-crypto": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/@walletconnect/iso-crypto/-/iso-crypto-1.8.0.tgz", @@ -1995,11 +2005,12 @@ } }, "node_modules/axios": { - "version": "0.24.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz", - "integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==", + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", + "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", "dependencies": { - "follow-redirects": "^1.14.4" + "follow-redirects": "^1.14.9", + "form-data": "^4.0.0" } }, "node_modules/backslash": { @@ -3989,9 +4000,9 @@ } }, "node_modules/lru-cache": { - "version": "9.1.1", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-9.1.1.tgz", - "integrity": "sha512-65/Jky17UwSb0BuB9V+MyDpsOtXKmYwzhyl+cOa9XUiI4uV2Ouy/2voFP3+al0BjZbJgMBD8FojMpAf+Z+qn4A==", + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-9.1.2.tgz", + "integrity": "sha512-ERJq3FOzJTxBbFjZ7iDs+NiK4VI9Wz+RdrrAB8dio1oV+YvdPzUEE4QNiT2VD51DkIbCYRUUzCRkssXCHqSnKQ==", "dev": true, "engines": { "node": "14 || >=16.14" @@ -5934,9 +5945,9 @@ "dev": true }, "@humanwhocodes/config-array": { - "version": "0.11.8", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", - "integrity": "sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==", + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz", + "integrity": "sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==", "dev": true, "requires": { "@humanwhocodes/object-schema": "^1.2.1", @@ -6170,17 +6181,6 @@ "integrity": "sha512-2y5XCi09Zfgo5fNuQPaSEfOVJoZB8OrAiEtjQy3RDzm44j83E/bByFWDE2CWHV1aRWsn9JwOSQdYWtMO9RMF/Q==", "requires": { "axios": "^0.27.2" - }, - "dependencies": { - "axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", - "requires": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" - } - } } }, "@multiversx/sdk-network-providers": { @@ -6193,6 +6193,16 @@ "bignumber.js": "9.0.1", "buffer": "6.0.3", "json-bigint": "1.0.0" + }, + "dependencies": { + "axios": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz", + "integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==", + "requires": { + "follow-redirects": "^1.14.4" + } + } } }, "@multiversx/sdk-transaction-decoder": { @@ -6791,6 +6801,16 @@ "tslib": "1.14.1" } }, + "@walletconnect/heartbeat": { + "version": "https://registry.npmjs.org/@walletconnect/heartbeat/-/heartbeat-1.2.1.tgz", + "integrity": "sha512-yVzws616xsDLJxuG/28FqtZ5rzrTA4gUjdEMTbWB5Y8V1XHRmqq4efAxCw5ie7WjbXFSUyBHaWlMR+2/CpQC5Q==", + "extraneous": true, + "requires": { + "@walletconnect/events": "^1.0.1", + "@walletconnect/time": "^1.0.2", + "tslib": "1.14.1" + } + }, "@walletconnect/iso-crypto": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/@walletconnect/iso-crypto/-/iso-crypto-1.8.0.tgz", @@ -7258,11 +7278,12 @@ "dev": true }, "axios": { - "version": "0.24.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz", - "integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==", + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", + "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", "requires": { - "follow-redirects": "^1.14.4" + "follow-redirects": "^1.14.9", + "form-data": "^4.0.0" } }, "backslash": { @@ -8695,9 +8716,9 @@ } }, "lru-cache": { - "version": "9.1.1", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-9.1.1.tgz", - "integrity": "sha512-65/Jky17UwSb0BuB9V+MyDpsOtXKmYwzhyl+cOa9XUiI4uV2Ouy/2voFP3+al0BjZbJgMBD8FojMpAf+Z+qn4A==", + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-9.1.2.tgz", + "integrity": "sha512-ERJq3FOzJTxBbFjZ7iDs+NiK4VI9Wz+RdrrAB8dio1oV+YvdPzUEE4QNiT2VD51DkIbCYRUUzCRkssXCHqSnKQ==", "dev": true }, "make-error": { diff --git a/package.json b/package.json index af52959..dbc0436 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@useelven/core", - "version": "0.5.0", + "version": "0.6.0", "description": "Core hooks for MultiversX React DApps", "license": "MIT", "author": "Julian Ćwirko ", diff --git a/src/hooks/common-helpers/sendTxOperations.ts b/src/hooks/common-helpers/sendTxOperations.ts index 4c5cdbe..0b2fa89 100644 --- a/src/hooks/common-helpers/sendTxOperations.ts +++ b/src/hooks/common-helpers/sendTxOperations.ts @@ -25,24 +25,24 @@ export interface TransactionCallbackParams { } export const postSendTxOperations = async ( - tx: Transaction, + signedTx: Transaction, setTransaction: Dispatch>, setTxResult: Dispatch>, apiNetworkProvider: NetworkState['apiNetworkProvider'], cb?: (params: TransactionCallbackParams) => void ) => { + setTransaction(signedTx); if (apiNetworkProvider) { const transactionWatcher = new TransactionWatcher(apiNetworkProvider); - const txResult = await transactionWatcher.awaitCompleted(tx); - setTransaction(tx); + const txResult = await transactionWatcher.awaitCompleted(signedTx); + setTransaction(signedTx); setTxResult(txResult); - cb?.({ transaction: tx, pending: false, txResult }); - const sender = tx.getSender(); + cb?.({ transaction: signedTx, pending: false, txResult }); + const sender = signedTx.getSender(); const senderAccount = new Account(sender); const userAccountOnNetwork = await apiNetworkProvider.getAccount(sender); senderAccount.update(userAccountOnNetwork); setAccountState('address', senderAccount.address.bech32()); - setAccountState('nonce', senderAccount.getNonceThenIncrement()); setAccountState('balance', senderAccount.balance.toString()); } }; @@ -66,8 +66,6 @@ export const sendTxOperations = async ( await dappProvider.signTransaction(tx, { callbackUrl: webWalletRedirectUrl || currentUrl, }); - // web wallet provider doesn't return signed transaction - signedTx = tx; } if (dappProvider instanceof ExtensionProvider) { signedTx = await dappProvider.signTransaction(tx); @@ -80,7 +78,6 @@ export const sendTxOperations = async ( } if (loginInfoSnap.loginMethod !== LoginMethodsEnum.wallet) { await apiNetworkProvider.sendTransaction(signedTx); - setTransaction(signedTx); await postSendTxOperations( signedTx, setTransaction, diff --git a/src/hooks/common-helpers/useWebWalletTxSend.tsx b/src/hooks/common-helpers/useWebWalletTxSend.tsx index 0e3b0cb..3fb66d2 100644 --- a/src/hooks/common-helpers/useWebWalletTxSend.tsx +++ b/src/hooks/common-helpers/useWebWalletTxSend.tsx @@ -12,6 +12,7 @@ import { import { errorParse } from '../../utils/errorParse'; import { ApiNetworkProvider } from '@multiversx/sdk-network-providers/out'; import { useAccount } from '../useAccount'; +import { setAccountState } from '../../store/auth'; import { useNetwork } from '../useNetwork'; interface UseWebWalletTxSendProps { @@ -56,7 +57,7 @@ export const useWebWalletTxSend = ({ setPending(true); cb?.({ pending: true }); const transaction = Transaction.fromPlainObject(transactionObj); - transaction.setNonce(currentNonce); + try { await networkStateSnap.apiNetworkProvider.sendTransaction( transaction @@ -76,6 +77,7 @@ export const useWebWalletTxSend = ({ } finally { setPending(false); cb?.({ pending: false }); + setAccountState('nonce', currentNonce + 1); } } }; diff --git a/src/hooks/useExtensionLogin.tsx b/src/hooks/useExtensionLogin.tsx index 131855d..265e2a6 100644 --- a/src/hooks/useExtensionLogin.tsx +++ b/src/hooks/useExtensionLogin.tsx @@ -87,7 +87,6 @@ export const useExtensionLogin = (params?: Login) => { userAccountInstance.update(userAccountOnNetwork); setAccountState('address', userAccountInstance.address.bech32()); - setAccountState('nonce', userAccountInstance.nonce.valueOf()); setAccountState('balance', userAccountInstance.balance.toString()); } catch (e) { diff --git a/src/hooks/useTransaction.tsx b/src/hooks/useTransaction.tsx index 3be120f..9109743 100644 --- a/src/hooks/useTransaction.tsx +++ b/src/hooks/useTransaction.tsx @@ -7,6 +7,7 @@ import { IGasLimit, ITransactionValue, ITransactionOnNetwork, + Account, } from '@multiversx/sdk-core'; import { useWebWalletTxSend } from './common-helpers/useWebWalletTxSend'; import { @@ -14,6 +15,7 @@ import { sendTxOperations, } from './common-helpers/sendTxOperations'; 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'; @@ -71,6 +73,8 @@ export function useTransaction( setPending(true); cb?.({ pending: true }); + const sender = new Address(accountSnap.address); + const tx = new Transaction({ nonce: currentNonce, receiver: new Address(address), @@ -78,10 +82,12 @@ export function useTransaction( chainID: configStateSnap.shortId || 'D', data, value: value || 0, - sender: new Address(accountSnap.address), + sender, }); - tx.setNonce(currentNonce); + const senderAccount = new Account(sender); + senderAccount.incrementNonce(); + setAccountState('nonce', currentNonce + 1); sendTxOperations( networkStateSnap.dappProvider as DappProvider,