summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-02-04 17:01:46 -0300
committerSebastian <sebasjm@gmail.com>2024-02-04 17:01:46 -0300
commit1b0b40fee2b15dd8847bf91c01630492ced93750 (patch)
tree51e37bb8eec2101f142ed6de26b14ff42df7346b /packages/taler-wallet-core/src/operations
parentb30c7dcf667e3d94a8a3ad170d53ede70e1f0be1 (diff)
downloadwallet-core-1b0b40fee2b15dd8847bf91c01630492ced93750.tar.gz
wallet-core-1b0b40fee2b15dd8847bf91c01630492ced93750.tar.bz2
wallet-core-1b0b40fee2b15dd8847bf91c01630492ced93750.zip
backward compatible change to acceptReward with txId
Diffstat (limited to 'packages/taler-wallet-core/src/operations')
-rw-r--r--packages/taler-wallet-core/src/operations/reward.ts40
-rw-r--r--packages/taler-wallet-core/src/operations/transactions.ts10
2 files changed, 35 insertions, 15 deletions
diff --git a/packages/taler-wallet-core/src/operations/reward.ts b/packages/taler-wallet-core/src/operations/reward.ts
index 62ac81d7f..369c1f40d 100644
--- a/packages/taler-wallet-core/src/operations/reward.ts
+++ b/packages/taler-wallet-core/src/operations/reward.ts
@@ -37,6 +37,7 @@ import {
TalerPreciseTimestamp,
TipPlanchetDetail,
TransactionAction,
+ TransactionIdStr,
TransactionMajorState,
TransactionMinorState,
TransactionState,
@@ -81,6 +82,7 @@ import { selectWithdrawalDenominations } from "../util/coinSelection.js";
import {
constructTransactionIdentifier,
notifyTransition,
+ parseTransactionIdentifier,
stopLongpolling,
} from "./transactions.js";
import { PendingTaskType } from "../pending-types.js";
@@ -643,18 +645,39 @@ export async function processTip(
return TaskRunResult.finished();
}
+export async function acceptTipBackwardCompat(
+ ws: InternalWalletState,
+ walletTipId: string | undefined,
+ transactionIdParam: TransactionIdStr | undefined,
+): Promise<AcceptTipResponse> {
+ if (transactionIdParam) {
+ return acceptTip(ws, transactionIdParam)
+ }
+ if (walletTipId) {
+ /**
+ * old clients use still use tipId
+ */
+ const transactionId = constructTransactionIdentifier({
+ tag: TransactionType.Reward,
+ walletRewardId: walletTipId,
+ });
+ return acceptTip(ws, transactionId)
+ }
+ throw Error("Unable to accept tip: neither tipId (deprecated) nor transactionId was specified")
+}
+
export async function acceptTip(
ws: InternalWalletState,
- walletTipId: string,
+ transactionId: TransactionIdStr,
): Promise<AcceptTipResponse> {
- const transactionId = constructTransactionIdentifier({
- tag: TransactionType.Reward,
- walletRewardId: walletTipId,
- });
+ const pTxId = parseTransactionIdentifier(transactionId)
+ if (!pTxId) throw Error(`Unable to accept tip: invalid tx tag "${transactionId}"`)
+ const rewardId = pTxId.tag === TransactionType.Reward ? pTxId.walletRewardId : undefined;
+ if (!rewardId) throw Error(`Unable to accept tip: txId is not a reward tag "${pTxId.tag}"`)
const dbRes = await ws.db
.mktx((x) => [x.rewards])
.runReadWrite(async (tx) => {
- const tipRecord = await tx.rewards.get(walletTipId);
+ const tipRecord = await tx.rewards.get(rewardId);
if (!tipRecord) {
logger.error("tip not found");
return;
@@ -682,10 +705,7 @@ export async function acceptTip(
const tipRecord = dbRes.tipRecord;
return {
- transactionId: constructTransactionIdentifier({
- tag: TransactionType.Reward,
- walletRewardId: walletTipId,
- }),
+ transactionId,
next_url: tipRecord.next_url,
};
}
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts
index 8fd7afae6..f64d3d21d 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -539,7 +539,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 &&
@@ -569,10 +569,10 @@ function buildTransactionForPeerPullCredit(
kycUrl: pullCredit.kycUrl,
...(wsrOrt?.lastError
? {
- error: silentWithdrawalErrorForInvoice
- ? undefined
- : wsrOrt.lastError,
- }
+ error: silentWithdrawalErrorForInvoice
+ ? undefined
+ : wsrOrt.lastError,
+ }
: {}),
};
}