refactor: use array destructuring instead of indexing

This commit is contained in:
André Sá 2022-02-18 20:31:35 +00:00
parent ac20f05dd4
commit 0ff73687eb

View file

@ -1,5 +1,6 @@
'use strict'
const _ = require('lodash/fp')
const Web3 = require('web3')
const web3 = new Web3()
const hdkey = require('ethereumjs-wallet/hdkey')
@ -113,20 +114,19 @@ function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) {
]
return Promise.all(promises)
.then(arr => {
const gas = arr[0]
const gasPrice = arr[1]
const txCount = arr[2] <= lastUsedNonces[fromAddress]
? lastUsedNonces[fromAddress] + 1
: arr[2]
.then(([gas, gasPrice, txCount]) => [
gas,
gasPrice,
_.max([txCount, lastUsedNonces[fromAddress] + 1])
])
.then(([gas, gasPrice, txCount]) => {
lastUsedNonces[fromAddress] = txCount
const toSend = includesFee
? amount.minus(gasPrice.times(gas))
: amount
const contract = web3.eth.contract(ABI.ERC20).at(coins.utils.getErc20Token(cryptoCode).contractAddress)
const contract = web3.eth.contract(ABI.ERC20).at(toAddress)
const rawTx = {
chainId: 1,