Skip to content

Commit

Permalink
Merge pull request #11969 from gabrielbazan7/fix/nonce1
Browse files Browse the repository at this point in the history
[FIX] nonce fix
  • Loading branch information
Gamboster authored Nov 26, 2021
2 parents 2743da6 + 2c64166 commit d11a820
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
14 changes: 14 additions & 0 deletions src/pages/send/confirm/confirm.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,20 @@
</ion-note>
</ion-item>

<label-tip type="warn" *ngIf="suggestedNonce < customNonce">
<span label-tip-title translate>Warning</span>
<div label-tip-body translate>
Nonce is higher than suggested nonce of {{suggestedNonce}}
</div>
</label-tip>

<label-tip type="warn" *ngIf="pendingTxsNonce && pendingTxsNonce.length > 0 && !isSpeedUpTx">
<span label-tip-title translate>Waiting for confirmation</span>
<div label-tip-body translate>
There is a pending transaction with a lower account nonce. This next transaction can only be executed after confirmation of the earlier transaction.
</div>
</label-tip>

<div class="line-divider"></div>

<button ion-item detail-none (click)="showWallets()" [ngClass]="{'not-clickable': fromWalletDetails || walletConnectRequestId}">
Expand Down
28 changes: 20 additions & 8 deletions src/pages/send/confirm/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class ConfirmPage {
public merchantFeeLabel: string;
public totalAmountStr: string;
public totalAmount;
public pendingConfirmationEthTxs: number;
public pendingTxsNonce: number[];
public showEnableRBF: boolean;
public enableRBF: boolean = false;

Expand Down Expand Up @@ -127,6 +127,7 @@ export class ConfirmPage {
public customGasPrice: number;
public customGasLimit: number;
public customNonce: number;
public suggestedNonce: number;

public merchantName: string;
public itemizedDetails;
Expand Down Expand Up @@ -1434,22 +1435,33 @@ export class ConfirmPage {
txp.chain ? txp.chain.toLowerCase() : txp.coin,
txp.from
);

this.pendingConfirmationEthTxs = 0;
this.pendingTxsNonce = [];
for (let tx of nonceWallet.completeHistory) {
if (
tx.confirmations === 0 &&
(tx.action === 'sent' || tx.action === 'moved') &&
tx.nonce < nonce // ignore transactions waiting for lower nonce
(tx.action === 'sent' || tx.action === 'moved')
) {
this.pendingConfirmationEthTxs = this.pendingConfirmationEthTxs + 1;
this.pendingTxsNonce.push(tx.nonce);
} else break;
}

if (this.pendingTxsNonce.length > 0) {
this.pendingTxsNonce.sort((a, b) => a - b);
for (let i = 0; i < this.pendingTxsNonce.length; i++) {
if (this.pendingTxsNonce[i] + 1 != this.pendingTxsNonce[i + 1]) {
this.suggestedNonce = this.pendingTxsNonce[i] + 1;
break;
}
}
} else this.suggestedNonce = nonce;

this.logger.debug(
`Using web3 nonce: ${nonce} - pending txs: ${this.pendingConfirmationEthTxs}`
`Using web3 nonce: ${nonce} - Suggested Nonce: ${
this.suggestedNonce
} - pending txs: ${this.suggestedNonce - nonce}`
);
txp.nonce = this.tx.nonce = nonce + this.pendingConfirmationEthTxs;

txp.nonce = this.tx.nonce = this.suggestedNonce;
};

const opts = {
Expand Down

0 comments on commit d11a820

Please sign in to comment.