aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-02-19 02:52:29 +0100
committerFlorian Dold <florian@dold.me>2024-02-19 02:52:29 +0100
commit54cbb236dd0ca1e2422e8c9810c275b3b540172f (patch)
tree531787c8ad0b6c1729c976b935c2f7205c52c678 /packages/taler-wallet-core
parente9ac87d8a60861d1d9f88fe99fef0e2131aec774 (diff)
downloadwallet-core-54cbb236dd0ca1e2422e8c9810c275b3b540172f.tar.xz
wallet-core: towards fixing scopeInfo filtering in getTransactions
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r--packages/taler-wallet-core/src/operations/transactions.ts43
1 files changed, 24 insertions, 19 deletions
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts
index 10e018d23..671ccd556 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -149,18 +149,20 @@ function shouldSkipCurrency(
exchangesInTransaction: string[],
): boolean {
if (transactionsRequest?.scopeInfo) {
- const sameCurrency =
- transactionsRequest.scopeInfo.currency.toLowerCase() ===
- currency.toLowerCase();
+ const sameCurrency = Amounts.isSameCurrency(
+ currency,
+ transactionsRequest.scopeInfo.currency,
+ );
switch (transactionsRequest.scopeInfo.type) {
case ScopeType.Global: {
return !sameCurrency;
}
case ScopeType.Exchange: {
- const exchangeInvolveInTransaction =
- exchangesInTransaction.indexOf(transactionsRequest.scopeInfo.url) !==
- -1;
- return !sameCurrency || !exchangeInvolveInTransaction;
+ return (
+ !sameCurrency ||
+ (exchangesInTransaction.length > 0 &&
+ !exchangesInTransaction.includes(transactionsRequest.scopeInfo.url))
+ );
}
case ScopeType.Auditor: {
// same currency and same auditor
@@ -674,8 +676,8 @@ function buildTransactionForPeerPushCredit(
txActions: computePeerPushCreditTransactionActions(pushInc),
amountEffective: isUnsuccessfulTransaction(txState)
? Amounts.stringify(Amounts.zeroOfAmount(peerContractTerms.amount))
- // FIXME: This is wrong, needs to consider fees!
- : Amounts.stringify(peerContractTerms.amount),
+ : // FIXME: This is wrong, needs to consider fees!
+ Amounts.stringify(peerContractTerms.amount),
amountRaw: Amounts.stringify(peerContractTerms.amount),
exchangeBaseUrl: pushInc.exchangeBaseUrl,
info: {
@@ -730,11 +732,13 @@ function buildTransactionForBankIntegratedWithdraw(
}
function isUnsuccessfulTransaction(state: TransactionState): boolean {
- return state.major === TransactionMajorState.Aborted ||
+ return (
+ state.major === TransactionMajorState.Aborted ||
state.major === TransactionMajorState.Expired ||
state.major === TransactionMajorState.Aborting ||
state.major === TransactionMajorState.Deleted ||
- state.major === TransactionMajorState.Failed;
+ state.major === TransactionMajorState.Failed
+ );
}
function buildTransactionForManualWithdraw(
@@ -761,7 +765,9 @@ function buildTransactionForManualWithdraw(
txState,
txActions: computeWithdrawalTransactionActions(withdrawalGroup),
amountEffective: isUnsuccessfulTransaction(txState)
- ? Amounts.stringify(Amounts.zeroOfAmount(withdrawalGroup.instructedAmount))
+ ? Amounts.stringify(
+ Amounts.zeroOfAmount(withdrawalGroup.instructedAmount),
+ )
: Amounts.stringify(withdrawalGroup.denomsSel.totalCoinValue),
amountRaw: Amounts.stringify(withdrawalGroup.instructedAmount),
withdrawalDetails: {
@@ -841,9 +847,7 @@ function buildTransactionForRefresh(
refreshReason: refreshGroupRecord.reason,
amountEffective: isUnsuccessfulTransaction(txState)
? Amounts.stringify(Amounts.zeroOfAmount(inputAmount))
- : Amounts.stringify(
- Amounts.sub(outputAmount, inputAmount).amount,
- ),
+ : Amounts.stringify(Amounts.sub(outputAmount, inputAmount).amount),
amountRaw: Amounts.stringify(
Amounts.zeroOfCurrency(refreshGroupRecord.currency),
),
@@ -1258,12 +1262,13 @@ export async function getTransactions(
const p = await tx.purchases.get(refundGroup.proposalId);
if (!p || !p.payInfo) return; //refund with no payment
- p.payInfo.payCoinSelection.coinPubs.forEach(async (cp) => {
+ // FIXME: This is very slow, should become obsolete with materialized transactions.
+ for (const cp of p.payInfo.payCoinSelection.coinPubs) {
const c = await tx.coins.get(cp);
if (c?.exchangeBaseUrl) {
exchangesInTx.push(c.exchangeBaseUrl);
}
- });
+ }
if (shouldSkipCurrency(transactionsRequest, currency, exchangesInTx)) {
return;
@@ -1386,12 +1391,12 @@ export async function getTransactions(
}
const exchangesInTx: string[] = [];
- purchase.payInfo.payCoinSelection.coinPubs.forEach(async (cp) => {
+ for (const cp of purchase.payInfo.payCoinSelection.coinPubs) {
const c = await tx.coins.get(cp);
if (c?.exchangeBaseUrl) {
exchangesInTx.push(c.exchangeBaseUrl);
}
- });
+ }
if (
shouldSkipCurrency(