Skip to content

Commit

Permalink
v6.1.0: adds nonce to sent transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Dec 4, 2021
1 parent a42898d commit 0cbc862
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion dist/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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');
Expand Down
5 changes: 4 additions & 1 deletion dist/es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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');
Expand Down
5 changes: 4 additions & 1 deletion dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/wallets/WalletConnect/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions src/wallets/Web3Wallet/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
10 changes: 10 additions & 0 deletions tests/units/wallets/WalletConnect/sendTransaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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')
});
Expand All @@ -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')
})
Expand All @@ -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')
})
Expand All @@ -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')
})
Expand Down
10 changes: 10 additions & 0 deletions tests/units/wallets/Web3Wallet/sendTransaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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')
});
Expand All @@ -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')
})
Expand All @@ -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')
})
Expand All @@ -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')
})
Expand Down

0 comments on commit 0cbc862

Please sign in to comment.