mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +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,
|
amount: string,
|
||||||
total: string,
|
total: string,
|
||||||
tx: any,
|
tx: any,
|
||||||
|
nonce: number,
|
||||||
txid: string,
|
txid: string,
|
||||||
txData: any,
|
txData: any,
|
||||||
};
|
};
|
||||||
@ -822,7 +823,8 @@ export const onSend = (): AsyncAction => {
|
|||||||
const {
|
const {
|
||||||
account,
|
account,
|
||||||
network,
|
network,
|
||||||
web3
|
web3,
|
||||||
|
pending
|
||||||
} = getState().selectedAccount;
|
} = getState().selectedAccount;
|
||||||
if (!account || !web3 || !network) return;
|
if (!account || !web3 || !network) return;
|
||||||
|
|
||||||
@ -852,6 +854,12 @@ export const onSend = (): AsyncAction => {
|
|||||||
txAddress = token.address;
|
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 = {
|
const txData = {
|
||||||
address_n,
|
address_n,
|
||||||
// from: currentAddress.address
|
// from: currentAddress.address
|
||||||
@ -859,7 +867,7 @@ export const onSend = (): AsyncAction => {
|
|||||||
value: txAmount,
|
value: txAmount,
|
||||||
data,
|
data,
|
||||||
chainId: web3.chainId,
|
chainId: web3.chainId,
|
||||||
nonce: w3.toHex(account.nonce),
|
nonce: w3.toHex(nonce),
|
||||||
gasLimit: w3.toHex(currentState.gasLimit),
|
gasLimit: w3.toHex(currentState.gasLimit),
|
||||||
gasPrice: w3.toHex( EthereumjsUnits.convert(currentState.gasPrice, 'gwei', 'wei') ),
|
gasPrice: w3.toHex( EthereumjsUnits.convert(currentState.gasPrice, 'gwei', 'wei') ),
|
||||||
r: '',
|
r: '',
|
||||||
@ -920,6 +928,7 @@ export const onSend = (): AsyncAction => {
|
|||||||
amount: currentState.amount,
|
amount: currentState.amount,
|
||||||
total: currentState.total,
|
total: currentState.total,
|
||||||
tx,
|
tx,
|
||||||
|
nonce,
|
||||||
txid,
|
txid,
|
||||||
txData,
|
txData,
|
||||||
});
|
});
|
||||||
|
@ -15,6 +15,7 @@ export type PendingTx = {
|
|||||||
+amount: string;
|
+amount: string;
|
||||||
+total: string;
|
+total: string;
|
||||||
+tx: any;
|
+tx: any;
|
||||||
|
+nonce: number;
|
||||||
+address: string;
|
+address: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ const add = (state: State, action: SendTxAction): State => {
|
|||||||
amount: action.amount,
|
amount: action.amount,
|
||||||
total: action.total,
|
total: action.total,
|
||||||
tx: action.tx,
|
tx: action.tx,
|
||||||
|
nonce: action.nonce,
|
||||||
address: action.account.address,
|
address: action.account.address,
|
||||||
});
|
});
|
||||||
return newState;
|
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);
|
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 => {
|
export const getPendingAmount = (pending: Array<PendingTx>, currency: string): BigNumber => {
|
||||||
return pending.reduce((value: BigNumber, tx: PendingTx) => {
|
return pending.reduce((value: BigNumber, tx: PendingTx) => {
|
||||||
if (tx.currency === currency) {
|
if (tx.currency === currency) {
|
||||||
|
Loading…
Reference in New Issue
Block a user