-type fixes
This commit is contained in:
parent
5a91fbe2b7
commit
0e7a0741c6
@ -4,7 +4,7 @@
|
||||
"composite": true,
|
||||
"target": "ES2018",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "node",
|
||||
"moduleResolution": "Node16",
|
||||
"sourceMap": true,
|
||||
"lib": ["es6", "DOM"],
|
||||
"noImplicitReturns": true,
|
||||
|
@ -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 };
|
||||
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user