Skip to content

Commit e5a00fe

Browse files
committed
HubDeposit: prune old pending txs if one with same nonce is confirmed
1 parent 4b631d7 commit e5a00fe

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

components/HubDepositAccountMinter.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export default {
5757
}
5858
return undefined;
5959
},
60+
// @TODO get gasPrice from eth_fee.fast
6061
gasPriceGwei() {
6162
const priceItem = this.priceList.find((item) => item.name === `${this.selectedHubNetwork}/gas`);
6263
let gasPriceGwei;

components/HubDepositForm.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ export default {
305305
}
306306
},
307307
},
308+
// @TODO isUnwrapRequired may not change, because native token balance will be less than expected, because it will be spent on tx gas
309+
// @TODO including gas fee to unwrap amount should fix it
310+
// @TODO unwrap errors will not stop loader
308311
isUnwrapRequired: {
309312
handler(newVal) {
310313
// stop form sending loader after unwrap tx confirmed

store/hub.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export const mutations = {
6262
setEthAddress(state, address) {
6363
state.ethAddress = address.toLowerCase();
6464
},
65-
//@TODO check txs with same nonce and filter out pending if another is confirmed
6665
saveDeposit(state, tx) {
6766
if (!tx.from) {
6867
console.warn('hub/saveDeposit: can\'t save because `tx.from` not specified');
@@ -71,6 +70,7 @@ export const mutations = {
7170
const ethAddress = tx.from.toLowerCase();
7271
let depositList = state.ethList[ethAddress] || [];
7372
const index = depositList.findIndex((item) => item.hash === tx.hash);
73+
// update list
7474
if (index >= 0) {
7575
depositList[index] = {
7676
...depositList[index],
@@ -79,6 +79,20 @@ export const mutations = {
7979
} else {
8080
depositList.unshift(tx);
8181
}
82+
// check txs with same nonce and filter out pending if another is confirmed
83+
let currentNonce = typeof tx.nonce !== 'undefined' ? tx.nonce : depositList[index]?.nonce;
84+
const isConfirmed = depositList.some((item) => item.nonce === currentNonce && item.blockHash);
85+
if (isConfirmed) {
86+
// find unconfirmed with same nonce
87+
const txsToPrune = depositList.filter((item) => {
88+
return !item.blockHash && item.nonce === currentNonce;
89+
});
90+
depositList = depositList.filter((item) => {
91+
const shouldPrune = txsToPrune.some((toPrune) => toPrune.hash === item.hash);
92+
return !shouldPrune;
93+
});
94+
}
95+
// preserve list length
8296
if (depositList.length > 5) {
8397
depositList = depositList.slice(0, 5);
8498
}

0 commit comments

Comments
 (0)