From 0cbc862a407986a29c6170a3bae65e37b8cc870c Mon Sep 17 00:00:00 2001 From: Sebastian Pape Date: Sat, 4 Dec 2021 08:14:20 +0100 Subject: [PATCH] v6.1.0: adds nonce to sent transaction --- README.md | 2 ++ dist/cjs/index.js | 5 ++++- dist/es/index.js | 5 ++++- dist/umd/index.js | 5 ++++- package.json | 2 +- src/Transaction.js | 3 ++- src/wallets/WalletConnect/transaction.js | 1 + src/wallets/Web3Wallet/transaction.js | 1 + .../wallets/WalletConnect/sendTransaction.spec.js | 10 ++++++++++ tests/units/wallets/Web3Wallet/sendTransaction.spec.js | 10 ++++++++++ 10 files changed, 39 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a64f7f36..b7c9af12 100644 --- a/README.md +++ b/README.md @@ -290,6 +290,8 @@ Returned instances of `Transaction` (e.g. via `sendTransaction`, or `sent`, `con `from: string`: Address the transaction is sent from. +`nonce: Number`: The number of the sent transactions (from the given address). + `to: string`: Address the transaction is interacting with. `api: array`: Api of a contract the transaction is interacting with. diff --git a/dist/cjs/index.js b/dist/cjs/index.js index 41672aab..faa9a7f5 100644 --- a/dist/cjs/index.js +++ b/dist/cjs/index.js @@ -17769,10 +17769,11 @@ function parseUnits(value, unitName) { function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } class Transaction { - constructor({ blockchain, from, to, api, method, params, value, sent, confirmed, ensured, failed }) { + constructor({ blockchain, from, nonce, to, api, method, params, value, sent, confirmed, ensured, failed }) { this.blockchain = blockchain; this.from = from; + this.nonce = nonce; this.to = to; this.api = api; this.method = method; @@ -17880,6 +17881,7 @@ const sendTransaction$1 = async ({ transaction, wallet })=> { await executeSubmit$1({ transaction, provider, signer }).then((sentTransaction)=>{ if (sentTransaction) { transaction.id = sentTransaction.hash; + transaction.nonce = sentTransaction.nonce; transaction.url = web3Blockchains.Blockchain.findByName(transaction.blockchain).explorerUrlFor({ transaction }); if (transaction.sent) transaction.sent(transaction); sentTransaction.wait(1).then(() => { @@ -18080,6 +18082,7 @@ const sendTransaction = async ({ transaction, wallet })=> { transaction.url = blockchain.explorerUrlFor({ transaction }); if (transaction.sent) transaction.sent(transaction); let sentTransaction = await retrieveTransaction(tx, transaction.blockchain); + transaction.nonce = sentTransaction.nonce; if(!sentTransaction) { transaction._failed = true; console.log('Error retrieving transaction'); diff --git a/dist/es/index.js b/dist/es/index.js index 3ed96b74..09b012ca 100644 --- a/dist/es/index.js +++ b/dist/es/index.js @@ -17760,10 +17760,11 @@ function parseUnits(value, unitName) { function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } class Transaction { - constructor({ blockchain, from, to, api, method, params, value, sent, confirmed, ensured, failed }) { + constructor({ blockchain, from, nonce, to, api, method, params, value, sent, confirmed, ensured, failed }) { this.blockchain = blockchain; this.from = from; + this.nonce = nonce; this.to = to; this.api = api; this.method = method; @@ -17871,6 +17872,7 @@ const sendTransaction$1 = async ({ transaction, wallet })=> { await executeSubmit$1({ transaction, provider, signer }).then((sentTransaction)=>{ if (sentTransaction) { transaction.id = sentTransaction.hash; + transaction.nonce = sentTransaction.nonce; transaction.url = Blockchain.findByName(transaction.blockchain).explorerUrlFor({ transaction }); if (transaction.sent) transaction.sent(transaction); sentTransaction.wait(1).then(() => { @@ -18071,6 +18073,7 @@ const sendTransaction = async ({ transaction, wallet })=> { transaction.url = blockchain.explorerUrlFor({ transaction }); if (transaction.sent) transaction.sent(transaction); let sentTransaction = await retrieveTransaction(tx, transaction.blockchain); + transaction.nonce = sentTransaction.nonce; if(!sentTransaction) { transaction._failed = true; console.log('Error retrieving transaction'); diff --git a/dist/umd/index.js b/dist/umd/index.js index af126c46..1dbac05a 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -17764,10 +17764,11 @@ function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } class Transaction { - constructor({ blockchain, from, to, api, method, params, value, sent, confirmed, ensured, failed }) { + constructor({ blockchain, from, nonce, to, api, method, params, value, sent, confirmed, ensured, failed }) { this.blockchain = blockchain; this.from = from; + this.nonce = nonce; this.to = to; this.api = api; this.method = method; @@ -17875,6 +17876,7 @@ await executeSubmit$1({ transaction, provider, signer }).then((sentTransaction)=>{ if (sentTransaction) { transaction.id = sentTransaction.hash; + transaction.nonce = sentTransaction.nonce; transaction.url = web3Blockchains.Blockchain.findByName(transaction.blockchain).explorerUrlFor({ transaction }); if (transaction.sent) transaction.sent(transaction); sentTransaction.wait(1).then(() => { @@ -18075,6 +18077,7 @@ transaction.url = blockchain.explorerUrlFor({ transaction }); if (transaction.sent) transaction.sent(transaction); let sentTransaction = await retrieveTransaction(tx, transaction.blockchain); + transaction.nonce = sentTransaction.nonce; if(!sentTransaction) { transaction._failed = true; console.log('Error retrieving transaction'); diff --git a/package.json b/package.json index 7c871172..cc7151f9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-wallets", "moduleName": "Web3Wallets", - "version": "6.0.0", + "version": "6.1.0", "description": "One-Stop-Shop JavaScript library to integrate various web3 crypto wallets and multiple blockchains at once with a single interface.", "main": "dist/cjs/index.js", "module": "dist/es/index.js", diff --git a/src/Transaction.js b/src/Transaction.js index 201563ef..99b789ed 100644 --- a/src/Transaction.js +++ b/src/Transaction.js @@ -3,10 +3,11 @@ import { CONSTANTS } from '@depay/web3-constants' class Transaction { - constructor({ blockchain, from, to, api, method, params, value, sent, confirmed, ensured, failed }) { + constructor({ blockchain, from, nonce, to, api, method, params, value, sent, confirmed, ensured, failed }) { this.blockchain = blockchain this.from = from + this.nonce = nonce this.to = to this.api = api this.method = method diff --git a/src/wallets/WalletConnect/transaction.js b/src/wallets/WalletConnect/transaction.js index 69bf373f..4d0984ec 100644 --- a/src/wallets/WalletConnect/transaction.js +++ b/src/wallets/WalletConnect/transaction.js @@ -16,6 +16,7 @@ const sendTransaction = async ({ transaction, wallet })=> { transaction.url = blockchain.explorerUrlFor({ transaction }) if (transaction.sent) transaction.sent(transaction) let sentTransaction = await retrieveTransaction(tx, transaction.blockchain) + transaction.nonce = sentTransaction.nonce if(!sentTransaction) { transaction._failed = true console.log('Error retrieving transaction') diff --git a/src/wallets/Web3Wallet/transaction.js b/src/wallets/Web3Wallet/transaction.js index 5631e690..fad16ed1 100644 --- a/src/wallets/Web3Wallet/transaction.js +++ b/src/wallets/Web3Wallet/transaction.js @@ -13,6 +13,7 @@ const sendTransaction = async ({ transaction, wallet })=> { await executeSubmit({ transaction, provider, signer }).then((sentTransaction)=>{ if (sentTransaction) { transaction.id = sentTransaction.hash + transaction.nonce = sentTransaction.nonce transaction.url = Blockchain.findByName(transaction.blockchain).explorerUrlFor({ transaction }) if (transaction.sent) transaction.sent(transaction) sentTransaction.wait(1).then(() => { diff --git a/tests/units/wallets/WalletConnect/sendTransaction.spec.js b/tests/units/wallets/WalletConnect/sendTransaction.spec.js index f5966ace..20c72695 100644 --- a/tests/units/wallets/WalletConnect/sendTransaction.spec.js +++ b/tests/units/wallets/WalletConnect/sendTransaction.spec.js @@ -64,6 +64,7 @@ describe('sendTransaction with wallet connect', () => { expect(submittedTransaction.url).toBeDefined() expect(submittedTransaction.blockchain).toEqual(blockchain) expect(submittedTransaction.from).toEqual(accounts[0]) + expect(submittedTransaction.nonce).toEqual(0) expect(submittedTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(submittedTransaction.api).toEqual(api) expect(submittedTransaction.method).toEqual(method) @@ -135,6 +136,7 @@ describe('sendTransaction with wallet connect', () => { expect(sentCallbackTransaction.url).toBeDefined() expect(sentCallbackTransaction.blockchain).toEqual(blockchain) expect(sentCallbackTransaction.from).toEqual(accounts[0]) + expect(sentCallbackTransaction.nonce).toEqual(0) expect(sentCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(sentCallbackTransaction.api).toEqual(api) expect(sentCallbackTransaction.method).toEqual(method) @@ -151,6 +153,7 @@ describe('sendTransaction with wallet connect', () => { expect(confirmedCallbackTransaction.url).toBeDefined() expect(confirmedCallbackTransaction.blockchain).toEqual(blockchain) expect(confirmedCallbackTransaction.from).toEqual(accounts[0]) + expect(confirmedCallbackTransaction.nonce).toEqual(0) expect(confirmedCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(confirmedCallbackTransaction.api).toEqual(api) expect(confirmedCallbackTransaction.method).toEqual(method) @@ -169,6 +172,7 @@ describe('sendTransaction with wallet connect', () => { expect(ensuredCallbackTransaction.url).toBeDefined() expect(ensuredCallbackTransaction.blockchain).toEqual(blockchain) expect(ensuredCallbackTransaction.from).toEqual(accounts[0]) + expect(ensuredCallbackTransaction.nonce).toEqual(0) expect(ensuredCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(ensuredCallbackTransaction.api).toEqual(api) expect(ensuredCallbackTransaction.method).toEqual(method) @@ -185,6 +189,7 @@ describe('sendTransaction with wallet connect', () => { expect(failedCallbackTransaction.url).toBeDefined() expect(failedCallbackTransaction.blockchain).toEqual(blockchain) expect(failedCallbackTransaction.from).toEqual(accounts[0]) + expect(failedCallbackTransaction.nonce).toEqual(0) expect(failedCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(failedCallbackTransaction.api).toEqual(api) expect(failedCallbackTransaction.method).toEqual(method) @@ -216,6 +221,7 @@ describe('sendTransaction with wallet connect', () => { expect(submittedTransaction.url).toBeDefined() expect(submittedTransaction.blockchain).toEqual(blockchain) expect(submittedTransaction.from).toEqual(accounts[0]) + expect(submittedTransaction.nonce).toEqual(0) expect(submittedTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(submittedTransaction.value.toString()).toEqual('1000000000000000000') expect(mockedTransaction).toHaveBeenCalled() @@ -289,6 +295,7 @@ describe('sendTransaction with wallet connect', () => { expect(sentCallbackTransaction.url).toBeDefined() expect(sentCallbackTransaction.blockchain).toEqual(blockchain) expect(sentCallbackTransaction.from).toEqual(accounts[0]) + expect(sentCallbackTransaction.nonce).toEqual(0) expect(sentCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(sentCallbackTransaction.value.toString()).toEqual('1000000000000000000') }); @@ -303,6 +310,7 @@ describe('sendTransaction with wallet connect', () => { expect(confirmedCallbackTransaction.url).toBeDefined() expect(confirmedCallbackTransaction.blockchain).toEqual(blockchain) expect(confirmedCallbackTransaction.from).toEqual(accounts[0]) + expect(confirmedCallbackTransaction.nonce).toEqual(0) expect(confirmedCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(confirmedCallbackTransaction.value.toString()).toEqual('1000000000000000000') }) @@ -319,6 +327,7 @@ describe('sendTransaction with wallet connect', () => { expect(ensuredCallbackTransaction.url).toBeDefined() expect(ensuredCallbackTransaction.blockchain).toEqual(blockchain) expect(ensuredCallbackTransaction.from).toEqual(accounts[0]) + expect(ensuredCallbackTransaction.nonce).toEqual(0) expect(ensuredCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(ensuredCallbackTransaction.value.toString()).toEqual('1000000000000000000') }) @@ -333,6 +342,7 @@ describe('sendTransaction with wallet connect', () => { expect(failedCallbackTransaction.url).toBeDefined() expect(failedCallbackTransaction.blockchain).toEqual(blockchain) expect(failedCallbackTransaction.from).toEqual(accounts[0]) + expect(failedCallbackTransaction.nonce).toEqual(0) expect(failedCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(failedCallbackTransaction.value.toString()).toEqual('1000000000000000000') }) diff --git a/tests/units/wallets/Web3Wallet/sendTransaction.spec.js b/tests/units/wallets/Web3Wallet/sendTransaction.spec.js index 9d46ba1c..25a86eb2 100644 --- a/tests/units/wallets/Web3Wallet/sendTransaction.spec.js +++ b/tests/units/wallets/Web3Wallet/sendTransaction.spec.js @@ -57,6 +57,7 @@ describe('sendTransaction with web3 wallet', () => { expect(submittedTransaction.url).toBeDefined() expect(submittedTransaction.blockchain).toEqual(blockchain) expect(submittedTransaction.from).toEqual(accounts[0]) + expect(submittedTransaction.nonce).toEqual(0) expect(submittedTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(submittedTransaction.api).toEqual(api) expect(submittedTransaction.method).toEqual(method) @@ -128,6 +129,7 @@ describe('sendTransaction with web3 wallet', () => { expect(sentCallbackTransaction.url).toBeDefined() expect(sentCallbackTransaction.blockchain).toEqual(blockchain) expect(sentCallbackTransaction.from).toEqual(accounts[0]) + expect(sentCallbackTransaction.nonce).toEqual(0) expect(sentCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(sentCallbackTransaction.api).toEqual(api) expect(sentCallbackTransaction.method).toEqual(method) @@ -144,6 +146,7 @@ describe('sendTransaction with web3 wallet', () => { expect(confirmedCallbackTransaction.url).toBeDefined() expect(confirmedCallbackTransaction.blockchain).toEqual(blockchain) expect(confirmedCallbackTransaction.from).toEqual(accounts[0]) + expect(confirmedCallbackTransaction.nonce).toEqual(0) expect(confirmedCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(confirmedCallbackTransaction.api).toEqual(api) expect(confirmedCallbackTransaction.method).toEqual(method) @@ -162,6 +165,7 @@ describe('sendTransaction with web3 wallet', () => { expect(ensuredCallbackTransaction.url).toBeDefined() expect(ensuredCallbackTransaction.blockchain).toEqual(blockchain) expect(ensuredCallbackTransaction.from).toEqual(accounts[0]) + expect(ensuredCallbackTransaction.nonce).toEqual(0) expect(ensuredCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(ensuredCallbackTransaction.api).toEqual(api) expect(ensuredCallbackTransaction.method).toEqual(method) @@ -178,6 +182,7 @@ describe('sendTransaction with web3 wallet', () => { expect(failedCallbackTransaction.url).toBeDefined() expect(failedCallbackTransaction.blockchain).toEqual(blockchain) expect(failedCallbackTransaction.from).toEqual(accounts[0]) + expect(failedCallbackTransaction.nonce).toEqual(0) expect(failedCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(failedCallbackTransaction.api).toEqual(api) expect(failedCallbackTransaction.method).toEqual(method) @@ -209,6 +214,7 @@ describe('sendTransaction with web3 wallet', () => { expect(submittedTransaction.url).toBeDefined() expect(submittedTransaction.blockchain).toEqual(blockchain) expect(submittedTransaction.from).toEqual(accounts[0]) + expect(submittedTransaction.nonce).toEqual(0) expect(submittedTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(submittedTransaction.value.toString()).toEqual('1000000000000000000') expect(mockedTransaction).toHaveBeenCalled() @@ -282,6 +288,7 @@ describe('sendTransaction with web3 wallet', () => { expect(sentCallbackTransaction.url).toBeDefined() expect(sentCallbackTransaction.blockchain).toEqual(blockchain) expect(sentCallbackTransaction.from).toEqual(accounts[0]) + expect(sentCallbackTransaction.nonce).toEqual(0) expect(sentCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(sentCallbackTransaction.value.toString()).toEqual('1000000000000000000') }); @@ -296,6 +303,7 @@ describe('sendTransaction with web3 wallet', () => { expect(confirmedCallbackTransaction.url).toBeDefined() expect(confirmedCallbackTransaction.blockchain).toEqual(blockchain) expect(confirmedCallbackTransaction.from).toEqual(accounts[0]) + expect(confirmedCallbackTransaction.nonce).toEqual(0) expect(confirmedCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(confirmedCallbackTransaction.value.toString()).toEqual('1000000000000000000') }) @@ -312,6 +320,7 @@ describe('sendTransaction with web3 wallet', () => { expect(ensuredCallbackTransaction.url).toBeDefined() expect(ensuredCallbackTransaction.blockchain).toEqual(blockchain) expect(ensuredCallbackTransaction.from).toEqual(accounts[0]) + expect(ensuredCallbackTransaction.nonce).toEqual(0) expect(ensuredCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(ensuredCallbackTransaction.value.toString()).toEqual('1000000000000000000') }) @@ -326,6 +335,7 @@ describe('sendTransaction with web3 wallet', () => { expect(failedCallbackTransaction.url).toBeDefined() expect(failedCallbackTransaction.blockchain).toEqual(blockchain) expect(failedCallbackTransaction.from).toEqual(accounts[0]) + expect(failedCallbackTransaction.nonce).toEqual(0) expect(failedCallbackTransaction.to).toEqual('0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92') expect(failedCallbackTransaction.value.toString()).toEqual('1000000000000000000') })