diff options
Diffstat (limited to 'packages/taler-wallet-core/src/operations/transactions.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/transactions.ts | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index 908aa540a..d93396ca5 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -41,7 +41,9 @@ import { TransactionsResponse, TransactionState, TransactionType, + TransactionWithdrawal, WalletContractData, + WithdrawalTransactionByURIRequest, WithdrawalType, } from "@gnu-taler/taler-util"; import { @@ -520,7 +522,7 @@ function buildTransactionForPeerPullCredit( const silentWithdrawalErrorForInvoice = wsrOrt?.lastError && wsrOrt.lastError.code === - TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE && + TalerErrorCode.WALLET_WITHDRAWAL_GROUP_INCOMPLETE && Object.values(wsrOrt.lastError.errorsPerCoin ?? {}).every((e) => { return ( e.code === TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR && @@ -550,10 +552,10 @@ function buildTransactionForPeerPullCredit( kycUrl: pullCredit.kycUrl, ...(wsrOrt?.lastError ? { - error: silentWithdrawalErrorForInvoice - ? undefined - : wsrOrt.lastError, - } + error: silentWithdrawalErrorForInvoice + ? undefined + : wsrOrt.lastError, + } : {}), }; } @@ -641,7 +643,7 @@ function buildTransactionForPeerPushCredit( function buildTransactionForBankIntegratedWithdraw( wgRecord: WithdrawalGroupRecord, ort?: OperationRetryRecord, -): Transaction { +): TransactionWithdrawal { if (wgRecord.wgInfo.withdrawalType !== WithdrawalRecordType.BankIntegrated) throw Error(""); @@ -676,7 +678,7 @@ function buildTransactionForManualWithdraw( withdrawalGroup: WithdrawalGroupRecord, exchangeDetails: ExchangeWireDetails, ort?: OperationRetryRecord, -): Transaction { +): TransactionWithdrawal { if (withdrawalGroup.wgInfo.withdrawalType !== WithdrawalRecordType.BankManual) throw Error(""); @@ -948,6 +950,52 @@ async function buildTransactionForPurchase( }; } +export async function getWithdrawalTransactionByUri( + ws: InternalWalletState, + request: WithdrawalTransactionByURIRequest, +): Promise<TransactionWithdrawal | undefined> { + return await ws.db + .mktx((x) => [ + x.withdrawalGroups, + x.exchangeDetails, + x.exchanges, + x.operationRetries, + ]) + .runReadWrite(async (tx) => { + const withdrawalGroupRecord = await tx.withdrawalGroups.indexes.byTalerWithdrawUri.get( + request.talerWithdrawUri, + ); + + if (!withdrawalGroupRecord) { + return undefined; + } + + const opId = TaskIdentifiers.forWithdrawal(withdrawalGroupRecord); + const ort = await tx.operationRetries.get(opId); + + if ( + withdrawalGroupRecord.wgInfo.withdrawalType === + WithdrawalRecordType.BankIntegrated + ) { + return buildTransactionForBankIntegratedWithdraw( + withdrawalGroupRecord, + ort, + ); + } + const exchangeDetails = await getExchangeWireDetailsInTx( + tx, + withdrawalGroupRecord.exchangeBaseUrl, + ); + if (!exchangeDetails) throw Error("not exchange details"); + + return buildTransactionForManualWithdraw( + withdrawalGroupRecord, + exchangeDetails, + ort, + ); + }); +} + /** * Retrieve the full event history for this wallet. */ |