From df6f50028339c033982b94662e8ab465383095b3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 20 Feb 2024 02:19:41 +0100 Subject: wallet-core: count deposits towards pendingOutgoing --- packages/taler-wallet-core/src/deposits.ts | 46 +++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'packages/taler-wallet-core/src/deposits.ts') diff --git a/packages/taler-wallet-core/src/deposits.ts b/packages/taler-wallet-core/src/deposits.ts index 6f247501e..b327632d3 100644 --- a/packages/taler-wallet-core/src/deposits.ts +++ b/packages/taler-wallet-core/src/deposits.ts @@ -81,6 +81,7 @@ import { import { DepositElementStatus, DepositGroupRecord, + DepositInfoPerExchange, DepositOperationStatus, DepositTrackingInfo, KycPendingInfo, @@ -226,6 +227,10 @@ export class DepositTransactionContext implements TransactionContext { ws.taskScheduler.stopShepherdTask(retryTag); notifyTransition(ws, transactionId, transitionInfo); ws.taskScheduler.startShepherdTask(retryTag); + ws.notify({ + type: NotificationType.BalanceChange, + hintTransactionId: transactionId, + }); } async resumeTransaction(): Promise { @@ -300,6 +305,10 @@ export class DepositTransactionContext implements TransactionContext { ); ws.taskScheduler.stopShepherdTask(retryTag); notifyTransition(ws, transactionId, transitionInfo); + ws.notify({ + type: NotificationType.BalanceChange, + hintTransactionId: transactionId, + }); } } @@ -458,6 +467,10 @@ async function waitForRefreshOnDepositGroup( ); notifyTransition(ws, transactionId, transitionInfo); + ws.notify({ + type: NotificationType.BalanceChange, + hintTransactionId: transactionId, + }); return TaskRunResult.backoff(); } @@ -610,10 +623,6 @@ async function processDepositGroupPendingKyc( tag: TransactionType.Deposit, depositGroupId, }); - const retryTag = constructTaskIdentifier({ - tag: PendingTaskType.Deposit, - depositGroupId, - }); const kycInfo = depositGroup.kycInfo; const userType = "individual"; @@ -873,6 +882,10 @@ async function processDepositGroupPendingTrack( }); notifyTransition(ws, transactionId, transitionInfo); if (allWired) { + ws.notify({ + type: NotificationType.BalanceChange, + hintTransactionId: transactionId, + }); return TaskRunResult.finished(); } else { // FIXME: Use long-polling. @@ -1365,6 +1378,30 @@ export async function createDepositGroup( depositGroupId = encodeCrock(getRandomBytes(32)); } + const infoPerExchange: Record = {}; + + await ws.db.runReadOnlyTx(["coins"], async (tx) => { + for (let i = 0; i < payCoinSel.coinSel.coinPubs.length; i++) { + const coin = await tx.coins.get(payCoinSel.coinSel.coinPubs[i]); + if (!coin) { + logger.error("coin not found anymore"); + continue; + } + let depPerExchange = infoPerExchange[coin.exchangeBaseUrl]; + if (!depPerExchange) { + infoPerExchange[coin.exchangeBaseUrl] = depPerExchange = { + amountEffective: Amounts.stringify( + Amounts.zeroOfAmount(totalDepositCost), + ), + }; + } + const contrib = payCoinSel.coinSel.coinContributions[i]; + depPerExchange.amountEffective = Amounts.stringify( + Amounts.add(depPerExchange.amountEffective, contrib).amount, + ); + } + }); + const counterpartyEffectiveDepositAmount = await getCounterpartyEffectiveDepositAmount( ws, @@ -1402,6 +1439,7 @@ export async function createDepositGroup( salt: wireSalt, }, operationStatus: DepositOperationStatus.PendingDeposit, + infoPerExchange, }; const ctx = new DepositTransactionContext(ws, depositGroupId); -- cgit v1.2.3