Skip to content

Commit

Permalink
HubDeposit: prune old pending txs if one with same nonce is confirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
shrpne committed Dec 10, 2021
1 parent 4b631d7 commit e5a00fe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/HubDepositAccountMinter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default {
}
return undefined;
},
// @TODO get gasPrice from eth_fee.fast
gasPriceGwei() {
const priceItem = this.priceList.find((item) => item.name === `${this.selectedHubNetwork}/gas`);
let gasPriceGwei;
Expand Down
3 changes: 3 additions & 0 deletions components/HubDepositForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ export default {
}
},
},
// @TODO isUnwrapRequired may not change, because native token balance will be less than expected, because it will be spent on tx gas
// @TODO including gas fee to unwrap amount should fix it
// @TODO unwrap errors will not stop loader
isUnwrapRequired: {
handler(newVal) {
// stop form sending loader after unwrap tx confirmed
Expand Down
16 changes: 15 additions & 1 deletion store/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export const mutations = {
setEthAddress(state, address) {
state.ethAddress = address.toLowerCase();
},
//@TODO check txs with same nonce and filter out pending if another is confirmed
saveDeposit(state, tx) {
if (!tx.from) {
console.warn('hub/saveDeposit: can\'t save because `tx.from` not specified');
Expand All @@ -71,6 +70,7 @@ export const mutations = {
const ethAddress = tx.from.toLowerCase();
let depositList = state.ethList[ethAddress] || [];
const index = depositList.findIndex((item) => item.hash === tx.hash);
// update list
if (index >= 0) {
depositList[index] = {
...depositList[index],
Expand All @@ -79,6 +79,20 @@ export const mutations = {
} else {
depositList.unshift(tx);
}
// check txs with same nonce and filter out pending if another is confirmed
let currentNonce = typeof tx.nonce !== 'undefined' ? tx.nonce : depositList[index]?.nonce;
const isConfirmed = depositList.some((item) => item.nonce === currentNonce && item.blockHash);
if (isConfirmed) {
// find unconfirmed with same nonce
const txsToPrune = depositList.filter((item) => {
return !item.blockHash && item.nonce === currentNonce;
});
depositList = depositList.filter((item) => {
const shouldPrune = txsToPrune.some((toPrune) => toPrune.hash === item.hash);
return !shouldPrune;
});
}
// preserve list length
if (depositList.length > 5) {
depositList = depositList.slice(0, 5);
}
Expand Down

0 comments on commit e5a00fe

Please sign in to comment.