@@ -5,6 +5,7 @@ import { emit } from 'yaob'
5
5
6
6
import { upgradeCurrencyCode } from '../../../types/type-helpers'
7
7
import {
8
+ EdgeConfirmationState ,
8
9
EdgeCurrencyEngineCallbacks ,
9
10
EdgeStakingStatus ,
10
11
EdgeTokenId ,
@@ -215,15 +216,12 @@ export function makeCurrencyWalletCallbacks(
215
216
const { txs } = input . props . walletState
216
217
for ( const txid of Object . keys ( txs ) ) {
217
218
const reduxTx = txs [ txid ]
218
- if (
219
- reduxTx . confirmations !== 'confirmed' &&
220
- reduxTx . confirmations !== 'dropped'
221
- ) {
219
+ if ( shouldCoreDetermineConfirmations ( reduxTx . confirmations ) ) {
222
220
const { requiredConfirmations } =
223
221
input . props . walletState . currencyInfo
224
222
const { height } = input . props . walletState
225
223
226
- reduxTx . confirmations = validateConfirmations (
224
+ reduxTx . confirmations = determineConfirmations (
227
225
reduxTx ,
228
226
height ,
229
227
requiredConfirmations
@@ -318,14 +316,11 @@ export function makeCurrencyWalletCallbacks(
318
316
const { txid } = tx
319
317
320
318
// DEPRECATE: After all currency plugins implement new Confirmations API
321
- if (
322
- tx . confirmations !== 'confirmed' &&
323
- tx . confirmations !== 'dropped'
324
- ) {
319
+ if ( shouldCoreDetermineConfirmations ( tx . confirmations ) ) {
325
320
const { requiredConfirmations } = input . props . walletState . currencyInfo
326
321
const { height } = input . props . walletState
327
322
328
- tx . confirmations = validateConfirmations (
323
+ tx . confirmations = determineConfirmations (
329
324
tx ,
330
325
height ,
331
326
requiredConfirmations
@@ -413,7 +408,23 @@ export function watchCurrencyWallet(input: CurrencyWalletInput): void {
413
408
checkChangesLoop ( )
414
409
}
415
410
416
- export const validateConfirmations = (
411
+ /**
412
+ * Returns true if the core needs to calculate the transaction's confirmation state,
413
+ * because it still depends on the current block height.
414
+ *
415
+ * @deprecated Remove once all currency plugins support the new confirmations API.
416
+ */
417
+ const shouldCoreDetermineConfirmations = (
418
+ confirmations : EdgeConfirmationState | undefined
419
+ ) : boolean => {
420
+ return (
421
+ confirmations !== 'confirmed' &&
422
+ confirmations !== 'dropped' &&
423
+ confirmations !== 'failed'
424
+ )
425
+ }
426
+
427
+ export const determineConfirmations = (
417
428
tx : { blockHeight : number } , // Either EdgeTransaction or MergedTransaction
418
429
blockHeight : number ,
419
430
requiredConfirmations : number = 1 // Default confirmation rule is 1 block
0 commit comments