@@ -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