mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 01:08:27 +00:00
calculate nonce runtime (account.nonce + pending.nonce)
This commit is contained in:
parent
19321dffa9
commit
1e89993727
@ -45,6 +45,7 @@ export type SendTxAction = {
|
||||
amount: string,
|
||||
total: string,
|
||||
tx: any,
|
||||
nonce: number,
|
||||
txid: string,
|
||||
txData: any,
|
||||
};
|
||||
@ -822,7 +823,8 @@ export const onSend = (): AsyncAction => {
|
||||
const {
|
||||
account,
|
||||
network,
|
||||
web3
|
||||
web3,
|
||||
pending
|
||||
} = getState().selectedAccount;
|
||||
if (!account || !web3 || !network) return;
|
||||
|
||||
@ -830,7 +832,7 @@ export const onSend = (): AsyncAction => {
|
||||
|
||||
const isToken: boolean = currentState.currency !== currentState.networkSymbol;
|
||||
const w3 = web3.web3;
|
||||
|
||||
|
||||
const address_n = account.addressPath;
|
||||
|
||||
let data: string = '0x' + currentState.data;
|
||||
@ -852,6 +854,12 @@ export const onSend = (): AsyncAction => {
|
||||
txAddress = token.address;
|
||||
}
|
||||
|
||||
const pendingAmount: BigNumber = stateUtils.getPendingAmount(pending, currentState.currency);
|
||||
const pendingNonce: number = stateUtils.getPendingNonce(pending);
|
||||
const nonce = pendingNonce >= account.nonce ? pendingNonce + 1 : account.nonce;
|
||||
|
||||
console.warn("NONCEE", nonce, account.nonce, stateUtils.getPendingNonce(pending))
|
||||
|
||||
const txData = {
|
||||
address_n,
|
||||
// from: currentAddress.address
|
||||
@ -859,7 +867,7 @@ export const onSend = (): AsyncAction => {
|
||||
value: txAmount,
|
||||
data,
|
||||
chainId: web3.chainId,
|
||||
nonce: w3.toHex(account.nonce),
|
||||
nonce: w3.toHex(nonce),
|
||||
gasLimit: w3.toHex(currentState.gasLimit),
|
||||
gasPrice: w3.toHex( EthereumjsUnits.convert(currentState.gasPrice, 'gwei', 'wei') ),
|
||||
r: '',
|
||||
@ -920,6 +928,7 @@ export const onSend = (): AsyncAction => {
|
||||
amount: currentState.amount,
|
||||
total: currentState.total,
|
||||
tx,
|
||||
nonce,
|
||||
txid,
|
||||
txData,
|
||||
});
|
||||
|
@ -15,6 +15,7 @@ export type PendingTx = {
|
||||
+amount: string;
|
||||
+total: string;
|
||||
+tx: any;
|
||||
+nonce: number;
|
||||
+address: string;
|
||||
}
|
||||
|
||||
@ -31,6 +32,7 @@ const add = (state: State, action: SendTxAction): State => {
|
||||
amount: action.amount,
|
||||
total: action.total,
|
||||
tx: action.tx,
|
||||
nonce: action.nonce,
|
||||
address: action.account.address,
|
||||
});
|
||||
return newState;
|
||||
|
@ -91,6 +91,12 @@ export const getAccountPendingTx = (pending: Array<PendingTx>, account: ?Account
|
||||
return pending.filter(p => p.network === a.network && p.address === a.address);
|
||||
}
|
||||
|
||||
export const getPendingNonce = (pending: Array<PendingTx>): number => {
|
||||
return pending.reduce((value: number, tx: PendingTx) => {
|
||||
return Math.max(value, tx.nonce);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
export const getPendingAmount = (pending: Array<PendingTx>, currency: string): BigNumber => {
|
||||
return pending.reduce((value: BigNumber, tx: PendingTx) => {
|
||||
if (tx.currency === currency) {
|
||||
|
Loading…
Reference in New Issue
Block a user