aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/anastasis-core/tsconfig.json2
-rw-r--r--packages/taler-util/src/amounts.ts24
-rw-r--r--packages/taler-wallet-webextension/src/cta/Deposit/state.ts4
-rw-r--r--packages/taler-wallet-webextension/src/cta/Deposit/test.ts26
4 files changed, 29 insertions, 27 deletions
diff --git a/packages/anastasis-core/tsconfig.json b/packages/anastasis-core/tsconfig.json
index b5476273c..7cab21017 100644
--- a/packages/anastasis-core/tsconfig.json
+++ b/packages/anastasis-core/tsconfig.json
@@ -4,7 +4,7 @@
"composite": true,
"target": "ES2018",
"module": "ESNext",
- "moduleResolution": "node",
+ "moduleResolution": "Node16",
"sourceMap": true,
"lib": ["es6", "DOM"],
"noImplicitReturns": true,
diff --git a/packages/taler-util/src/amounts.ts b/packages/taler-util/src/amounts.ts
index 337f342a3..c9a78356e 100644
--- a/packages/taler-util/src/amounts.ts
+++ b/packages/taler-util/src/amounts.ts
@@ -192,16 +192,18 @@ export class Amounts {
*
* Throws when currencies don't match.
*/
- static sub(a: AmountJson, ...rest: AmountJson[]): Result {
- const currency = a.currency;
- let value = a.value;
- let fraction = a.fraction;
+ static sub(a: AmountLike, ...rest: AmountLike[]): Result {
+ const aJ = Amounts.jsonifyAmount(a);
+ const currency = aJ.currency;
+ let value = aJ.value;
+ let fraction = aJ.fraction;
for (const b of rest) {
- if (b.currency.toUpperCase() !== a.currency.toUpperCase()) {
- throw Error(`Mismatched currency: ${b.currency} and ${currency}`);
+ const bJ = Amounts.jsonifyAmount(b);
+ if (bJ.currency.toUpperCase() !== aJ.currency.toUpperCase()) {
+ throw Error(`Mismatched currency: ${bJ.currency} and ${currency}`);
}
- if (fraction < b.fraction) {
+ if (fraction < bJ.fraction) {
if (value < 1) {
return {
amount: { currency, value: 0, fraction: 0 },
@@ -211,12 +213,12 @@ export class Amounts {
value--;
fraction += amountFractionalBase;
}
- console.assert(fraction >= b.fraction);
- fraction -= b.fraction;
- if (value < b.value) {
+ console.assert(fraction >= bJ.fraction);
+ fraction -= bJ.fraction;
+ if (value < bJ.value) {
return { amount: { currency, value: 0, fraction: 0 }, saturated: true };
}
- value -= b.value;
+ value -= bJ.value;
}
return { amount: { currency, value, fraction }, saturated: false };
diff --git a/packages/taler-wallet-webextension/src/cta/Deposit/state.ts b/packages/taler-wallet-webextension/src/cta/Deposit/state.ts
index ba7bd147b..77e918ca9 100644
--- a/packages/taler-wallet-webextension/src/cta/Deposit/state.ts
+++ b/packages/taler-wallet-webextension/src/cta/Deposit/state.ts
@@ -61,8 +61,8 @@ export function useComponentState(
},
fee: Amounts.sub(deposit.totalDepositCost, deposit.effectiveDepositAmount)
.amount,
- cost: deposit.totalDepositCost,
- effective: deposit.effectiveDepositAmount,
+ cost: Amounts.parseOrThrow(deposit.totalDepositCost),
+ effective: Amounts.parseOrThrow(deposit.effectiveDepositAmount),
cancel,
};
}
diff --git a/packages/taler-wallet-webextension/src/cta/Deposit/test.ts b/packages/taler-wallet-webextension/src/cta/Deposit/test.ts
index f628b3287..a5bfed4a8 100644
--- a/packages/taler-wallet-webextension/src/cta/Deposit/test.ts
+++ b/packages/taler-wallet-webextension/src/cta/Deposit/test.ts
@@ -38,11 +38,9 @@ describe("Deposit CTA states", () => {
onSuccess: async () => {
null;
},
- }
+ };
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
- mountHook(() =>
- useComponentState(props, mock),
- );
+ mountHook(() => useComponentState(props, mock));
{
const { status } = pullLastResultOrThrow();
@@ -62,15 +60,19 @@ describe("Deposit CTA states", () => {
expect(error.message).eq("ERROR_NO-URI-FOR-DEPOSIT");
}
await assertNoPendingUpdate();
- expect(handler.getCallingQueueState()).eq("empty")
+ expect(handler.getCallingQueueState()).eq("empty");
});
it("should be ready after loading", async () => {
const { handler, mock } = createWalletApiMock();
- handler.addWalletCallResponse(WalletApiOperation.PrepareDeposit, undefined, {
- effectiveDepositAmount: Amounts.parseOrThrow("EUR:1"),
- totalDepositCost: Amounts.parseOrThrow("EUR:1.2"),
- });
+ handler.addWalletCallResponse(
+ WalletApiOperation.PrepareDeposit,
+ undefined,
+ {
+ effectiveDepositAmount: "EUR:1",
+ totalDepositCost: "EUR:1.2",
+ },
+ );
const props = {
talerDepositUri: "payto://refund/asdasdas",
amountStr: "EUR:1",
@@ -80,12 +82,10 @@ describe("Deposit CTA states", () => {
onSuccess: async () => {
null;
},
- }
+ };
const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } =
- mountHook(() =>
- useComponentState(props, mock),
- );
+ mountHook(() => useComponentState(props, mock));
{
const { status } = pullLastResultOrThrow();