aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-06-21 17:35:13 +0200
committerFlorian Dold <florian@dold.me>2024-06-21 17:35:13 +0200
commit043b7aefa91234f73209e810c85cf0d1ee7ca8d0 (patch)
tree0d3a2817f6f5b4b05f1dbf960cfbe78adc0ec84d /packages
parente2ddbdb6c6abf115ec4c1d7c9fe7296d80325b74 (diff)
downloadwallet-core-043b7aefa91234f73209e810c85cf0d1ee7ca8d0.tar.xz
wallet-core: fix check for withdrawal amount selection, refactor
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-harness/src/index.ts5
-rw-r--r--packages/taler-wallet-core/src/withdraw.ts50
2 files changed, 32 insertions, 23 deletions
diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts
index 99b5502d8..c38b0cd08 100644
--- a/packages/taler-harness/src/index.ts
+++ b/packages/taler-harness/src/index.ts
@@ -761,7 +761,7 @@ deploymentCli
"admin",
bankAdminPassword,
{
- scope: "write",
+ scope: "readwrite",
duration: {
d_us: 1000 * 1000 * 10, //10 secs
},
@@ -782,6 +782,7 @@ deploymentCli
*/
let accountPayto: PaytoString;
{
+ logger.info(`token: ${j2s(bankAdminToken)}`);
const resp = await bank.createAccount(bankAdminToken, {
name: name,
password: password,
@@ -799,6 +800,7 @@ deploymentCli
logger.error(
`unable to provision bank account, HTTP response status ${resp.case}`,
);
+ logger.error(j2s(resp));
process.exit(2);
}
logger.info(`account ${id} successfully provisioned`);
@@ -1141,6 +1143,7 @@ deploymentCli
logger.error(
`unable to provision bank account, HTTP response status ${resp.case}`,
);
+ logger.error(j2s(resp));
process.exit(2);
});
diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts
index dbe1cf207..b10c454f0 100644
--- a/packages/taler-wallet-core/src/withdraw.ts
+++ b/packages/taler-wallet-core/src/withdraw.ts
@@ -2349,20 +2349,10 @@ export interface GetWithdrawalDetailsForUriOpts {
notifyChangeFromPendingTimeoutMs?: number;
}
-/**
- * Get more information about a taler://withdraw URI.
- *
- * As side effects, the bank (via the bank integration API) is queried
- * and the exchange suggested by the bank is ephemerally added
- * to the wallet's list of known exchanges.
- */
-export async function getWithdrawalDetailsForUri(
+async function getWithdrawalDetailsForBankInfo(
wex: WalletExecutionContext,
- talerWithdrawUri: string,
+ info: BankWithdrawDetails,
): Promise<WithdrawUriInfoResponse> {
- logger.trace(`getting withdrawal details for URI ${talerWithdrawUri}`);
- const info = await getBankWithdrawalInfo(wex.http, talerWithdrawUri);
- logger.trace(`got bank info`);
if (info.exchange) {
try {
// If the exchange entry doesn't exist yet,
@@ -2412,6 +2402,23 @@ export async function getWithdrawalDetailsForUri(
};
}
+/**
+ * Get more information about a taler://withdraw URI.
+ *
+ * As side effects, the bank (via the bank integration API) is queried
+ * and the exchange suggested by the bank is ephemerally added
+ * to the wallet's list of known exchanges.
+ */
+export async function getWithdrawalDetailsForUri(
+ wex: WalletExecutionContext,
+ talerWithdrawUri: string,
+): Promise<WithdrawUriInfoResponse> {
+ logger.trace(`getting withdrawal details for URI ${talerWithdrawUri}`);
+ const info = await getBankWithdrawalInfo(wex.http, talerWithdrawUri);
+ logger.trace(`got bank info`);
+ return getWithdrawalDetailsForBankInfo(wex, info);
+}
+
export function augmentPaytoUrisForWithdrawal(
plainPaytoUris: string[],
reservePub: string,
@@ -3048,8 +3055,14 @@ export async function prepareBankIntegratedWithdrawal(
},
);
+ const withdrawInfo = await getBankWithdrawalInfo(
+ wex.http,
+ req.talerWithdrawUri,
+ );
+
+ const info = await getWithdrawalDetailsForBankInfo(wex, withdrawInfo);
+
if (existingWithdrawalGroup) {
- const info = await getWithdrawalDetailsForUri(wex, req.talerWithdrawUri);
return {
transactionId: constructTransactionIdentifier({
tag: TransactionType.Withdrawal,
@@ -3058,12 +3071,6 @@ export async function prepareBankIntegratedWithdrawal(
info,
};
}
- const withdrawInfo = await getBankWithdrawalInfo(
- wex.http,
- req.talerWithdrawUri,
- );
-
- const info = await getWithdrawalDetailsForUri(wex, req.talerWithdrawUri);
/**
* Withdrawal group without exchange and amount
@@ -3089,7 +3096,6 @@ export async function prepareBankIntegratedWithdrawal(
});
const withdrawalGroupId = withdrawalGroup.withdrawalGroupId;
-
const ctx = new WithdrawTransactionContext(wex, withdrawalGroupId);
wex.taskScheduler.startShepherdTask(ctx.taskId);
@@ -3299,9 +3305,9 @@ export async function acceptWithdrawalFromUri(
}
amount = req.amount as AmountString;
} else {
- if (req.amount != null && Amounts.cmp(req.amount, p.info.amount) != 0) {
+ if (req.amount != null && !p.info.editableAmount) {
throw Error(
- "mismatched amount, amount is fixed by bank but client provided different amount",
+ `mismatched amount, amount is fixed by bank (${p.info.amount}) but client provided different amount (${req.amount})`,
);
}
amount = p.info.amount;