-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add error state for RBF when previous transaction gets mined be…
…for user sends the modal
- Loading branch information
1 parent
2e71d93
commit 6d7a742
Showing
11 changed files
with
192 additions
and
81 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/suite/src/actions/wallet/send/replaceByFeeErrorThunk.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createThunk } from '@suite-common/redux-utils'; | ||
import TrezorConnect from '@trezor/connect'; | ||
|
||
import { MODULE_PREFIX } from './sendThunksConsts'; | ||
import { openModal } from '../../suite/modalActions'; | ||
|
||
export const RBF_ERROR_ALREADY_MINED = 'replace-by-fee-error-transaction-already-mined'; | ||
|
||
export const replaceByFeeErrorThunk = createThunk( | ||
`${MODULE_PREFIX}/replaceByFeeErrorThunk`, | ||
(_, { dispatch }) => { | ||
TrezorConnect.cancel(RBF_ERROR_ALREADY_MINED); | ||
|
||
dispatch( | ||
openModal({ | ||
type: 'review-transaction-rbf-previous-transaction-mined-error', | ||
}), | ||
); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const MODULE_PREFIX = '@send'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/suite/src/middlewares/wallet/replaceByFeeErrorMiddleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { MiddlewareAPI } from 'redux'; | ||
|
||
import { transactionsActions } from '@suite-common/wallet-core/'; | ||
import { isRbfTransaction } from '@suite-common/wallet-utils'; | ||
|
||
import { Action, AppState, Dispatch } from 'src/types/suite'; | ||
|
||
import { replaceByFeeErrorThunk } from '../../actions/wallet/send/replaceByFeeErrorThunk'; | ||
|
||
export const replaceByFeeErrorMiddleware = | ||
(api: MiddlewareAPI<Dispatch, AppState>) => | ||
(next: Dispatch) => | ||
(action: Action): Action => { | ||
next(action); | ||
|
||
if (transactionsActions.addTransaction.match(action)) { | ||
const { transactions } = action.payload; | ||
|
||
const precomposedTx = api.getState().wallet.send?.precomposedTx; | ||
|
||
if (precomposedTx !== undefined && isRbfTransaction(precomposedTx)) { | ||
const addedTransaction = transactions.find( | ||
tx => tx.txid === precomposedTx.prevTxid, | ||
); | ||
|
||
if (addedTransaction !== undefined && addedTransaction.blockHeight !== undefined) { | ||
api.dispatch(replaceByFeeErrorThunk()); | ||
} | ||
} | ||
} | ||
|
||
return action; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.