Skip to content

Commit 0f88a9d

Browse files
author
Jon Tzeng
committed
Merge pull request #696 from EdgeApp/jon/fix/xmr-confs
2 parents 0a913ee + 33a16b3 commit 0f88a9d

3 files changed

Lines changed: 28 additions & 39 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
- added: Add `appVersion`, `osType`, and `osVersion` to `EdgeContextOptions` for v2 coreRollup endpoint support.
1010
- changed: Use `/v2/coreRollup` endpoint when device info is available, with `/v1/coreRollup` as fallback.
11+
- fixed: Fixed confirmations bug in `shouldCoreDetermineConfirmations`
1112

1213
## 2.38.4 (2026-01-12)
1314

src/core/currency/wallet/currency-wallet-api.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ import { makeMetaTokens } from '../../account/custom-tokens'
4343
import { toApiInput } from '../../root-pixie'
4444
import { makeStorageWalletApi } from '../../storage/storage-api'
4545
import { getCurrencyMultiplier } from '../currency-selectors'
46-
import { makeCurrencyWalletCallbacks } from './currency-wallet-callbacks'
46+
import {
47+
determineConfirmations,
48+
makeCurrencyWalletCallbacks,
49+
shouldCoreDetermineConfirmations
50+
} from './currency-wallet-callbacks'
4751
import {
4852
asEdgeAssetAction,
4953
asEdgeTxAction,
@@ -763,7 +767,8 @@ export function combineTxWithFile(
763767
input: CurrencyWalletInput,
764768
tx: MergedTransaction,
765769
file: TransactionFile | undefined,
766-
tokenId: EdgeTokenId
770+
tokenId: EdgeTokenId,
771+
blockHeight?: number
767772
): EdgeTransaction {
768773
const walletId = input.props.walletId
769774
const { accountId, currencyInfo, pluginId } = input.props.walletState
@@ -772,12 +777,20 @@ export function combineTxWithFile(
772777
const { currencyCode } = tokenId == null ? currencyInfo : allTokens[tokenId]
773778
const walletCurrency = currencyInfo.currencyCode
774779

780+
// Use provided blockHeight or fall back to state (for callers outside onBlockHeightChanged):
781+
const height = blockHeight ?? input.props.walletState.height
782+
783+
// Calculate confirmations on-the-fly if engine didn't provide valid value:
784+
const confirmations = shouldCoreDetermineConfirmations(tx.confirmations)
785+
? determineConfirmations(tx, height, currencyInfo.requiredConfirmations)
786+
: tx.confirmations
787+
775788
// Copy the tx properties to the output:
776789
const out: EdgeTransaction = {
777790
chainAction: tx.chainAction,
778791
chainAssetAction: tx.chainAssetAction.get(tokenId),
779792
blockHeight: tx.blockHeight,
780-
confirmations: tx.confirmations,
793+
confirmations,
781794
currencyCode,
782795
feeRateUsed: tx.feeRateUsed,
783796
date: tx.date,

src/core/currency/wallet/currency-wallet-callbacks.ts

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -227,45 +227,32 @@ export function makeCurrencyWalletCallbacks(
227227
id: walletId,
228228
action: 'onBlockHeightChanged',
229229
updateFunc: () => {
230-
// Update transaction confirmation status
231-
const { txs } = input.props.walletState
230+
// Notify GUI of transactions whose confirmations may have changed.
231+
const { txs, files } = input.props.walletState
232+
const changedTxs: EdgeTransaction[] = []
232233
for (const txid of Object.keys(txs)) {
233234
const reduxTx = txs[txid]
234235
if (shouldCoreDetermineConfirmations(reduxTx.confirmations)) {
235-
const { requiredConfirmations } =
236-
input.props.walletState.currencyInfo
237-
const { height } = input.props.walletState
238-
239-
reduxTx.confirmations = determineConfirmations(
240-
reduxTx,
241-
height,
242-
requiredConfirmations
243-
)
244-
245-
// Recreate the EdgeTransaction object
246236
const txidHash = hashStorageWalletFilename(
247237
input.props.state,
248238
walletId,
249239
reduxTx.txid
250240
)
251-
const { files } = input.props.walletState
252241
const changedTx = combineTxWithFile(
253242
input,
254243
reduxTx,
255244
files[txidHash],
256-
null
245+
null,
246+
height
257247
)
258-
259-
// Dispatch event to update the redux transaction object
260-
input.props.dispatch({
261-
type: 'CHANGE_MERGE_TX',
262-
payload: { tx: reduxTx }
263-
})
264-
// Dispatch event to update the EdgeTransaction object
265-
throttledOnTxChanged([changedTx])
248+
changedTxs.push(changedTx)
266249
}
267250
}
251+
if (changedTxs.length > 0) {
252+
throttledOnTxChanged(changedTxs)
253+
}
268254

255+
// Update redux state for other consumers:
269256
input.props.dispatch({
270257
type: 'CURRENCY_ENGINE_CHANGED_HEIGHT',
271258
payload: { height, walletId }
@@ -380,18 +367,6 @@ export function makeCurrencyWalletCallbacks(
380367
const { isNew, transaction: tx } = txEvent
381368
const { txid } = tx
382369

383-
// DEPRECATE: After all currency plugins implement new Confirmations API
384-
if (shouldCoreDetermineConfirmations(tx.confirmations)) {
385-
const { requiredConfirmations } = input.props.walletState.currencyInfo
386-
const { height } = input.props.walletState
387-
388-
tx.confirmations = determineConfirmations(
389-
tx,
390-
height,
391-
requiredConfirmations
392-
)
393-
}
394-
395370
// Verify that something has changed:
396371
const reduxTx = mergeTx(tx, reduxTxs[txid])
397372
if (compare(reduxTx, reduxTxs[txid]) && tx.metadata == null) continue
@@ -492,7 +467,7 @@ export function watchCurrencyWallet(input: CurrencyWalletInput): void {
492467
*
493468
* @deprecated Remove once all currency plugins support the new confirmations API.
494469
*/
495-
const shouldCoreDetermineConfirmations = (
470+
export const shouldCoreDetermineConfirmations = (
496471
confirmations: EdgeConfirmationState | undefined
497472
): boolean => {
498473
return (

0 commit comments

Comments
 (0)