From 5e160a2d4d1d77c87600f28f806bc94c086267c7 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 22 Oct 2023 14:47:50 -0300 Subject: update the amountString definition --- .../anastasis-core/src/policy-suggestion.test.ts | 6 +- packages/anastasis-core/src/reducer-types.ts | 2 +- .../pages/home/ChallengeOverviewScreen.stories.tsx | 3 +- .../authMethod/AuthMethodQuestionSolve.stories.tsx | 3 +- packages/taler-harness/src/bench1.ts | 5 +- packages/taler-harness/src/bench2.ts | 9 +- packages/taler-harness/src/bench3.ts | 5 +- packages/taler-harness/src/harness/helpers.ts | 2 +- packages/taler-harness/src/index.ts | 9 +- .../test-age-restrictions-merchant.ts | 13 +- .../test-age-restrictions-mixed-merchant.ts | 11 +- .../integrationtests/test-age-restrictions-peer.ts | 3 +- .../src/integrationtests/test-deposit.ts | 3 +- .../src/integrationtests/test-exchange-deposit.ts | 11 +- .../src/integrationtests/test-exchange-purse.ts | 7 +- .../src/integrationtests/test-forced-selection.ts | 20 +-- .../src/integrationtests/test-peer-repair.ts | 5 +- .../src/integrationtests/test-peer-to-peer-pull.ts | 3 +- .../src/integrationtests/test-peer-to-peer-push.ts | 7 +- .../src/integrationtests/test-tipping.ts | 5 +- .../src/integrationtests/test-wallet-dbless.ts | 13 +- .../src/integrationtests/test-wallet-gendb.ts | 3 +- .../src/integrationtests/test-wallettesting.ts | 16 +-- .../integrationtests/test-withdrawal-fakebank.ts | 4 +- .../src/integrationtests/test-withdrawal-huge.ts | 3 +- .../src/integrationtests/test-withdrawal-manual.ts | 3 +- packages/taler-util/src/amounts.test.ts | 29 ++-- packages/taler-util/src/amounts.ts | 6 +- packages/taler-util/src/clk.ts | 6 +- packages/taler-util/src/wallet-types.ts | 32 ++--- packages/taler-wallet-cli/src/index.ts | 23 ++-- .../taler-wallet-core/src/operations/testing.ts | 4 +- .../src/operations/withdraw.test.ts | 12 +- .../src/util/coinSelection.test.ts | 22 +-- .../src/util/denominations.test.ts | 2 +- packages/taler-wallet-core/src/wallet.ts | 11 +- .../src/components/Amount.stories.tsx | 5 +- .../ShowFullContractTermPopup.stories.tsx | 8 +- .../src/cta/Deposit/test.ts | 14 +- .../src/cta/InvoiceCreate/index.ts | 4 +- .../src/cta/Payment/stories.tsx | 129 +++++++++--------- .../src/cta/Payment/test.ts | 43 +++--- .../src/cta/Reward/test.ts | 18 +-- .../src/cta/TransferCreate/index.ts | 4 +- .../src/cta/TransferCreate/state.ts | 3 +- .../src/cta/Withdraw/test.ts | 17 +-- .../src/popup/Balance.stories.tsx | 86 ++++++------ .../src/wallet/AddBackupProvider/stories.tsx | 5 +- .../src/wallet/Application.tsx | 7 +- .../src/wallet/Backup.stories.tsx | 23 ++-- .../src/wallet/DepositPage/test.ts | 39 +++--- .../src/wallet/History.stories.tsx | 147 +++++++++++---------- .../src/wallet/ProviderDetail.stories.tsx | 23 ++-- .../src/wallet/Transaction.stories.tsx | 57 ++++---- .../src/wallet/Transaction.tsx | 3 +- 55 files changed, 497 insertions(+), 459 deletions(-) (limited to 'packages') diff --git a/packages/anastasis-core/src/policy-suggestion.test.ts b/packages/anastasis-core/src/policy-suggestion.test.ts index 6370825da..fd42b708f 100644 --- a/packages/anastasis-core/src/policy-suggestion.test.ts +++ b/packages/anastasis-core/src/policy-suggestion.test.ts @@ -1,4 +1,4 @@ -import { j2s } from "@gnu-taler/taler-util"; +import { AmountString, j2s } from "@gnu-taler/taler-util"; import test from "ava"; import { ProviderInfo, suggestPolicies } from "./policy-suggestion.js"; @@ -23,13 +23,13 @@ test("policy suggestion", async (t) => { const providers: ProviderInfo[] = [ { methodCost: { - sms: "KUDOS:1", + sms: "KUDOS:1" as AmountString, }, url: "prov1", }, { methodCost: { - question: "KUDOS:1", + question: "KUDOS:1" as AmountString, }, url: "prov2", }, diff --git a/packages/anastasis-core/src/reducer-types.ts b/packages/anastasis-core/src/reducer-types.ts index 4b87d3ae6..ad88f40ed 100644 --- a/packages/anastasis-core/src/reducer-types.ts +++ b/packages/anastasis-core/src/reducer-types.ts @@ -295,7 +295,7 @@ export enum RecoveryStates { export interface MethodSpec { type: string; - usage_fee: string; + usage_fee: AmountString; } export type AuthenticationProviderStatusNotContacted = { diff --git a/packages/anastasis-webui/src/pages/home/ChallengeOverviewScreen.stories.tsx b/packages/anastasis-webui/src/pages/home/ChallengeOverviewScreen.stories.tsx index 1d35c0e91..84df615f3 100644 --- a/packages/anastasis-webui/src/pages/home/ChallengeOverviewScreen.stories.tsx +++ b/packages/anastasis-webui/src/pages/home/ChallengeOverviewScreen.stories.tsx @@ -27,6 +27,7 @@ import { import { reducerStatesExample } from "../../utils/index.js"; import { ChallengeOverviewScreen as TestedComponent } from "./ChallengeOverviewScreen.js"; import * as tests from "@gnu-taler/web-util/testing"; +import { AmountString } from "@gnu-taler/taler-util"; export default { title: "Challenge overview", @@ -256,7 +257,7 @@ export const OnePolicyWithAllTheChallengesInDifferentState = "uuid-8": { state: ChallengeFeedbackStatus.RateLimitExceeded.toString() }, "uuid-9": { state: ChallengeFeedbackStatus.IbanInstructions.toString(), - challenge_amount: "EUR:1", + challenge_amount: "EUR:1" as AmountString, target_iban: "DE12345789000", target_business_name: "Data Loss Incorporated", wire_transfer_subject: "Anastasis 987654321", diff --git a/packages/anastasis-webui/src/pages/home/authMethod/AuthMethodQuestionSolve.stories.tsx b/packages/anastasis-webui/src/pages/home/authMethod/AuthMethodQuestionSolve.stories.tsx index fe2cfbebb..dbb17ddab 100644 --- a/packages/anastasis-webui/src/pages/home/authMethod/AuthMethodQuestionSolve.stories.tsx +++ b/packages/anastasis-webui/src/pages/home/authMethod/AuthMethodQuestionSolve.stories.tsx @@ -26,6 +26,7 @@ import { import { reducerStatesExample } from "../../../utils/index.js"; import { authMethods as TestedComponent, KnownAuthMethods } from "./index.js"; import * as tests from "@gnu-taler/web-util/testing"; +import { AmountString } from "@gnu-taler/taler-util"; export default { title: "Auth method: Question solve", @@ -212,7 +213,7 @@ export const IbanInstructionsFeedback = tests.createExample( challenge_feedback: { "ASDASDSAD!1": { state: ChallengeFeedbackStatus.IbanInstructions, - challenge_amount: "EUR:1", + challenge_amount: "EUR:1" as AmountString, target_iban: "DE12345789000", target_business_name: "Data Loss Incorporated", wire_transfer_subject: "Anastasis 987654321", diff --git a/packages/taler-harness/src/bench1.ts b/packages/taler-harness/src/bench1.ts index efe162320..b78fadf0b 100644 --- a/packages/taler-harness/src/bench1.ts +++ b/packages/taler-harness/src/bench1.ts @@ -18,6 +18,7 @@ * Imports. */ import { + AmountString, buildCodecForObject, codecForBoolean, codecForNumber, @@ -97,7 +98,7 @@ export async function runBench1(configJson: any): Promise { let start = Date.now(); await wallet.client.call(WalletApiOperation.WithdrawTestBalance, { - amount: b1conf.currency + ":" + withdrawAmount, + amount: b1conf.currency + ":" + withdrawAmount as AmountString, corebankApiBaseUrl: b1conf.bank, exchangeBaseUrl: b1conf.exchange, }); @@ -116,7 +117,7 @@ export async function runBench1(configJson: any): Promise { start = Date.now(); await wallet.client.call(WalletApiOperation.CreateDepositGroup, { - amount: b1conf.currency + ":10", + amount: b1conf.currency + ":10" as AmountString, depositPaytoUri: b1conf.payto, }); diff --git a/packages/taler-harness/src/bench2.ts b/packages/taler-harness/src/bench2.ts index 53db6f6c1..87bc2ff7f 100644 --- a/packages/taler-harness/src/bench2.ts +++ b/packages/taler-harness/src/bench2.ts @@ -18,6 +18,7 @@ * Imports. */ import { + AmountString, buildCodecForObject, codecForNumber, codecForString, @@ -85,7 +86,7 @@ export async function runBench2(configJson: any): Promise { console.log("reserve found"); - const d1 = findDenomOrThrow(exchangeInfo, `${curr}:8`, { + const d1 = findDenomOrThrow(exchangeInfo, `${curr}:8` as AmountString, { denomselAllowLate: Wallet.defaultConfig.testing.denomselAllowLate, }); @@ -105,7 +106,7 @@ export async function runBench2(configJson: any): Promise { console.log("depositing coin"); await depositCoin({ - amount: `${curr}:4`, + amount: `${curr}:4` as AmountString, coin: coin, cryptoApi, exchangeBaseUrl: benchConf.exchange, @@ -114,10 +115,10 @@ export async function runBench2(configJson: any): Promise { }); const refreshDenoms = [ - findDenomOrThrow(exchangeInfo, `${curr}:1`, { + findDenomOrThrow(exchangeInfo, `${curr}:1` as AmountString, { denomselAllowLate: Wallet.defaultConfig.testing.denomselAllowLate, }), - findDenomOrThrow(exchangeInfo, `${curr}:1`, { + findDenomOrThrow(exchangeInfo, `${curr}:1` as AmountString, { denomselAllowLate: Wallet.defaultConfig.testing.denomselAllowLate, }), ]; diff --git a/packages/taler-harness/src/bench3.ts b/packages/taler-harness/src/bench3.ts index bc345aa9e..c810f6804 100644 --- a/packages/taler-harness/src/bench3.ts +++ b/packages/taler-harness/src/bench3.ts @@ -18,6 +18,7 @@ * Imports. */ import { + AmountString, buildCodecForObject, codecForNumber, codecForString, @@ -108,7 +109,7 @@ export async function runBench3(configJson: any): Promise { let start = Date.now(); await wallet.client.call(WalletApiOperation.WithdrawTestBalance, { - amount: b3conf.currency + ":" + withdrawAmount, + amount: b3conf.currency + ":" + withdrawAmount as AmountString, corebankApiBaseUrl: b3conf.bank, exchangeBaseUrl: b3conf.exchange, }); @@ -129,7 +130,7 @@ export async function runBench3(configJson: any): Promise { let payto = b3conf.paytoTemplate.replace("${id}", merchID.toString()); await wallet.client.call(WalletApiOperation.CreateDepositGroup, { - amount: b3conf.currency + ":10", + amount: b3conf.currency + ":10" as AmountString, depositPaytoUri: payto, }); diff --git a/packages/taler-harness/src/harness/helpers.ts b/packages/taler-harness/src/harness/helpers.ts index 8c1612457..adf43f6d0 100644 --- a/packages/taler-harness/src/harness/helpers.ts +++ b/packages/taler-harness/src/harness/helpers.ts @@ -554,7 +554,7 @@ export async function withdrawViaBankV2( walletClient: WalletClient; bank: BankService; exchange: ExchangeServiceInterface; - amount: AmountString; + amount: AmountString | string; restrictAge?: number; }, ): Promise { diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts index 076f71355..09b953a22 100644 --- a/packages/taler-harness/src/index.ts +++ b/packages/taler-harness/src/index.ts @@ -33,6 +33,7 @@ import { MerchantInstanceConfig, Duration, generateIban, + AmountString, } from "@gnu-taler/taler-util"; import { clk } from "@gnu-taler/taler-util/clk"; import { @@ -225,7 +226,7 @@ deploymentCli .requiredOption("bankAccount", ["--bank-account"], clk.STRING) .requiredOption("bankPassword", ["--bank-password"], clk.STRING) .requiredOption("wireMethod", ["--wire-method"], clk.STRING) - .requiredOption("amount", ["--amount"], clk.STRING) + .requiredOption("amount", ["--amount"], clk.AMOUNT) .action(async (args) => { const amount = args.tipTopup.amount; @@ -323,7 +324,7 @@ deploymentCli const exchangeBaseUrl = "https://exchange.demo.taler.net/"; const exchangeInfo = await downloadExchangeInfo(exchangeBaseUrl, http); await topupReserveWithDemobank({ - amount: "KUDOS:10", + amount: "KUDOS:10" as AmountString, corebankApiBaseUrl: "https://bank.demo.taler.net/", exchangeInfo, http, @@ -351,7 +352,7 @@ deploymentCli const exchangeBaseUrl = "https://exchange.test.taler.net/"; const exchangeInfo = await downloadExchangeInfo(exchangeBaseUrl, http); await topupReserveWithDemobank({ - amount: "TESTKUDOS:10", + amount: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: "https://bank.test.taler.net/", exchangeInfo, http, @@ -380,7 +381,7 @@ deploymentCli const exchangeBaseUrl = "http://localhost:8081/"; const exchangeInfo = await downloadExchangeInfo(exchangeBaseUrl, http); await topupReserveWithDemobank({ - amount: "TESTKUDOS:10", + amount: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: "http://localhost:8082/taler-bank-access/", exchangeInfo, http, diff --git a/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts b/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts index 5653e22e2..bd4318498 100644 --- a/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts +++ b/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts @@ -30,6 +30,7 @@ import { TalerCorebankApiClient, MerchantApiClient, WireGatewayApiClient, + AmountString, } from "@gnu-taler/taler-util"; /** @@ -78,7 +79,7 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { walletClient: walletClientZero, bank, exchange, - amount: "TESTKUDOS:20", + amount: "TESTKUDOS:20" as AmountString, restrictAge: 13, }); await wres.withdrawalFinishedCond; @@ -108,7 +109,7 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { walletClient, bank, exchange, - amount: "TESTKUDOS:20", + amount: "TESTKUDOS:20" as AmountString, restrictAge: 13, }); await wres.withdrawalFinishedCond; @@ -134,7 +135,7 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { walletClient, bank, exchange, - amount: "TESTKUDOS:20", + amount: "TESTKUDOS:20" as AmountString, restrictAge: 13, }); await wres.withdrawalFinishedCond; @@ -159,7 +160,7 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { walletClient, bank, exchange, - amount: "TESTKUDOS:20", + amount: "TESTKUDOS:20" as AmountString, }); await wres.withdrawalFinishedCond; @@ -183,7 +184,7 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { const mbu = await bankClient.createRandomBankUser(); const tipReserveResp = await merchantClient.createTippingReserve({ exchange_url: exchange.baseUrl, - initial_balance: "TESTKUDOS:10", + initial_balance: "TESTKUDOS:10" as AmountString, wire_method: getWireMethodForTest(), }); @@ -211,7 +212,7 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { await exchange.runWirewatchOnce(); const tip = await merchantClient.giveTip({ - amount: "TESTKUDOS:5", + amount: "TESTKUDOS:5" as AmountString, justification: "why not?", next_url: "https://example.com/after-tip", }); diff --git a/packages/taler-harness/src/integrationtests/test-age-restrictions-mixed-merchant.ts b/packages/taler-harness/src/integrationtests/test-age-restrictions-mixed-merchant.ts index af90ef1c5..244de1972 100644 --- a/packages/taler-harness/src/integrationtests/test-age-restrictions-mixed-merchant.ts +++ b/packages/taler-harness/src/integrationtests/test-age-restrictions-mixed-merchant.ts @@ -26,6 +26,7 @@ import { makeTestPaymentV2, withdrawViaBankV2, } from "../harness/helpers.js"; +import { AmountString } from "@gnu-taler/taler-util"; /** * Run test for basic, bank-integrated withdrawal and payment. @@ -62,7 +63,7 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) { walletClient, bank, exchange, - amount: "TESTKUDOS:20", + amount: "TESTKUDOS:20" as AmountString, restrictAge: 13, }); @@ -70,7 +71,7 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) { const order = { summary: "Buy me!", - amount: "TESTKUDOS:5", + amount: "TESTKUDOS:5" as AmountString, fulfillment_url: "taler://fulfillment-success/thx", minimum_age: 9, }; @@ -87,7 +88,7 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) { walletClient: walletTwo, bank, exchange, - amount: "TESTKUDOS:20", + amount: "TESTKUDOS:20" as AmountString, restrictAge: 13, }); @@ -96,7 +97,7 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) { const order = { summary: "Buy me!", - amount: "TESTKUDOS:5", + amount: "TESTKUDOS:5" as AmountString, fulfillment_url: "taler://fulfillment-success/thx", }; @@ -109,7 +110,7 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) { walletClient: walletThree, bank, exchange, - amount: "TESTKUDOS:20", + amount: "TESTKUDOS:20" as AmountString, }); diff --git a/packages/taler-harness/src/integrationtests/test-age-restrictions-peer.ts b/packages/taler-harness/src/integrationtests/test-age-restrictions-peer.ts index 45a4391cb..7506d48b3 100644 --- a/packages/taler-harness/src/integrationtests/test-age-restrictions-peer.ts +++ b/packages/taler-harness/src/integrationtests/test-age-restrictions-peer.ts @@ -19,6 +19,7 @@ */ import { AbsoluteTime, + AmountString, Duration, NotificationType, TransactionMajorState, @@ -82,7 +83,7 @@ export async function runAgeRestrictionsPeerTest(t: GlobalTestState) { { partialContractTerms: { summary: "Hello, World", - amount: "TESTKUDOS:1", + amount: "TESTKUDOS:1" as AmountString, purse_expiration, }, }, diff --git a/packages/taler-harness/src/integrationtests/test-deposit.ts b/packages/taler-harness/src/integrationtests/test-deposit.ts index d4bfa3da5..1f50377f2 100644 --- a/packages/taler-harness/src/integrationtests/test-deposit.ts +++ b/packages/taler-harness/src/integrationtests/test-deposit.ts @@ -18,6 +18,7 @@ * Imports. */ import { + AmountString, NotificationType, TransactionMajorState, TransactionMinorState, @@ -74,7 +75,7 @@ export async function runDepositTest(t: GlobalTestState) { const depositGroupResult = await walletClient.client.call( WalletApiOperation.CreateDepositGroup, { - amount: "TESTKUDOS:10", + amount: "TESTKUDOS:10" as AmountString, depositPaytoUri: generateRandomPayto("foo"), transactionId: depositTxId, }, diff --git a/packages/taler-harness/src/integrationtests/test-exchange-deposit.ts b/packages/taler-harness/src/integrationtests/test-exchange-deposit.ts index 8ad7daa63..8e1726aba 100644 --- a/packages/taler-harness/src/integrationtests/test-exchange-deposit.ts +++ b/packages/taler-harness/src/integrationtests/test-exchange-deposit.ts @@ -18,6 +18,7 @@ * Imports. */ import { + AmountString, encodeCrock, getRandomBytes, j2s, @@ -65,7 +66,7 @@ export async function runExchangeDepositTest(t: GlobalTestState) { await topupReserveWithDemobank({ http, - amount: "TESTKUDOS:10", + amount: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: bank.corebankApiBaseUrl, exchangeInfo, reservePub: reserveKeyPair.pub, @@ -75,7 +76,7 @@ export async function runExchangeDepositTest(t: GlobalTestState) { await checkReserve(http, exchange.baseUrl, reserveKeyPair.pub); - const d1 = findDenomOrThrow(exchangeInfo, "TESTKUDOS:8", { + const d1 = findDenomOrThrow(exchangeInfo, "TESTKUDOS:8" as AmountString, { denomselAllowLate: Wallet.defaultConfig.testing.denomselAllowLate, }); @@ -98,7 +99,7 @@ export async function runExchangeDepositTest(t: GlobalTestState) { contractTermsHash, merchantPub, wireSalt, - amount: "TESTKUDOS:4", + amount: "TESTKUDOS:4" as AmountString, coin: coin, cryptoApi, exchangeBaseUrl: exchange.baseUrl, @@ -110,7 +111,7 @@ export async function runExchangeDepositTest(t: GlobalTestState) { contractTermsHash, merchantPub, wireSalt, - amount: "TESTKUDOS:4", + amount: "TESTKUDOS:4" as AmountString, coin: coin, cryptoApi, exchangeBaseUrl: exchange.baseUrl, @@ -123,7 +124,7 @@ export async function runExchangeDepositTest(t: GlobalTestState) { contractTermsHash, merchantPub, wireSalt, - amount: "TESTKUDOS:3.5", + amount: "TESTKUDOS:3.5" as AmountString, coin: coin, cryptoApi, exchangeBaseUrl: exchange.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-exchange-purse.ts b/packages/taler-harness/src/integrationtests/test-exchange-purse.ts index 33a09ed16..c3815e1de 100644 --- a/packages/taler-harness/src/integrationtests/test-exchange-purse.ts +++ b/packages/taler-harness/src/integrationtests/test-exchange-purse.ts @@ -19,6 +19,7 @@ */ import { AbsoluteTime, + AmountString, ContractTermsUtil, decodeCrock, Duration, @@ -76,7 +77,7 @@ export async function runExchangePurseTest(t: GlobalTestState) { }); await topupReserveWithDemobank({ - amount: "TESTKUDOS:10", + amount: "TESTKUDOS:10" as AmountString, http, reservePub: reserveKeyPair.pub, corebankApiBaseUrl: bank.corebankApiBaseUrl, @@ -91,7 +92,7 @@ export async function runExchangePurseTest(t: GlobalTestState) { await checkReserve(http, exchange.baseUrl, reserveKeyPair.pub); - const d1 = findDenomOrThrow(exchangeInfo, "TESTKUDOS:8", { + const d1 = findDenomOrThrow(exchangeInfo, "TESTKUDOS:8" as AmountString, { denomselAllowLate: Wallet.defaultConfig.testing.denomselAllowLate, }); @@ -106,7 +107,7 @@ export async function runExchangePurseTest(t: GlobalTestState) { exchangeBaseUrl: exchange.baseUrl, }); - const amount = "TESTKUDOS:5"; + const amount = "TESTKUDOS:5" as AmountString; const purseFee = "TESTKUDOS:0"; const mergeTimestamp = TalerPreciseTimestamp.now(); diff --git a/packages/taler-harness/src/integrationtests/test-forced-selection.ts b/packages/taler-harness/src/integrationtests/test-forced-selection.ts index 917ad2025..752810703 100644 --- a/packages/taler-harness/src/integrationtests/test-forced-selection.ts +++ b/packages/taler-harness/src/integrationtests/test-forced-selection.ts @@ -17,7 +17,7 @@ /** * Imports. */ -import { j2s } from "@gnu-taler/taler-util"; +import { AmountString, j2s } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { GlobalTestState } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2 } from "../harness/helpers.js"; @@ -37,12 +37,12 @@ export async function runForcedSelectionTest(t: GlobalTestState) { await walletClient.call(WalletApiOperation.WithdrawTestBalance, { exchangeBaseUrl: exchange.baseUrl, - amount: "TESTKUDOS:10", + amount: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: bank.corebankApiBaseUrl, forcedDenomSel: { denoms: [ { - value: "TESTKUDOS:2", + value: "TESTKUDOS:2" as AmountString, count: 3, }, ], @@ -56,22 +56,22 @@ export async function runForcedSelectionTest(t: GlobalTestState) { t.assertDeepEqual(coinDump.coins.length, 3); const payResp = await walletClient.call(WalletApiOperation.TestPay, { - amount: "TESTKUDOS:3", + amount: "TESTKUDOS:3" as AmountString, merchantBaseUrl: merchant.makeInstanceBaseUrl(), summary: "bla", forcedCoinSel: { coins: [ { - value: "TESTKUDOS:2", - contribution: "TESTKUDOS:1", + value: "TESTKUDOS:2" as AmountString, + contribution: "TESTKUDOS:1" as AmountString, }, { - value: "TESTKUDOS:2", - contribution: "TESTKUDOS:1", + value: "TESTKUDOS:2" as AmountString, + contribution: "TESTKUDOS:1" as AmountString, }, { - value: "TESTKUDOS:2", - contribution: "TESTKUDOS:1", + value: "TESTKUDOS:2" as AmountString, + contribution: "TESTKUDOS:1" as AmountString, }, ], }, diff --git a/packages/taler-harness/src/integrationtests/test-peer-repair.ts b/packages/taler-harness/src/integrationtests/test-peer-repair.ts index d457ce1e5..977316174 100644 --- a/packages/taler-harness/src/integrationtests/test-peer-repair.ts +++ b/packages/taler-harness/src/integrationtests/test-peer-repair.ts @@ -19,6 +19,7 @@ */ import { AbsoluteTime, + AmountString, Duration, NotificationType, TransactionMajorState, @@ -92,7 +93,7 @@ export async function runPeerRepairTest(t: GlobalTestState) { exchangeBaseUrl: exchange.baseUrl, partialContractTerms: { summary: "Hello World", - amount: "TESTKUDOS:3", + amount: "TESTKUDOS:3" as AmountString, purse_expiration, }, }, @@ -160,7 +161,7 @@ export async function runPeerRepairTest(t: GlobalTestState) { exchangeBaseUrl: exchange.baseUrl, partialContractTerms: { summary: "Hello World", - amount: "TESTKUDOS:3", + amount: "TESTKUDOS:3" as AmountString, purse_expiration, }, }, diff --git a/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts b/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts index 6d9f44fb5..7ed716bc1 100644 --- a/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts +++ b/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts @@ -19,6 +19,7 @@ */ import { AbsoluteTime, + AmountString, Duration, j2s, NotificationType, @@ -86,7 +87,7 @@ export async function runPeerToPeerPullTest(t: GlobalTestState) { exchangeBaseUrl: exchange.baseUrl, partialContractTerms: { summary: "Hello World", - amount: "TESTKUDOS:5", + amount: "TESTKUDOS:5" as AmountString, purse_expiration: purseExpiration, }, }, diff --git a/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts b/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts index 018fa2020..44c7bf399 100644 --- a/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts +++ b/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts @@ -19,6 +19,7 @@ */ import { AbsoluteTime, + AmountString, Duration, NotificationType, TransactionMajorState, @@ -80,7 +81,7 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) { { partialContractTerms: { summary: "Hello World 😁😇", - amount: "TESTKUDOS:5", + amount: "TESTKUDOS:5" as AmountString, purse_expiration, }, }, @@ -96,7 +97,7 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) { { partialContractTerms: { summary: "Hello World 🥺", - amount: "TESTKUDOS:5", + amount: "TESTKUDOS:5" as AmountString, purse_expiration, }, }, @@ -148,7 +149,7 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) { await w1.walletClient.call(WalletApiOperation.InitiatePeerPushDebit, { partialContractTerms: { summary: "(this will fail)", - amount: "TESTKUDOS:15", + amount: "TESTKUDOS:15" as AmountString, purse_expiration, }, }); diff --git a/packages/taler-harness/src/integrationtests/test-tipping.ts b/packages/taler-harness/src/integrationtests/test-tipping.ts index 12cdbae53..16859f98c 100644 --- a/packages/taler-harness/src/integrationtests/test-tipping.ts +++ b/packages/taler-harness/src/integrationtests/test-tipping.ts @@ -22,6 +22,7 @@ import { MerchantApiClient, TransactionMajorState, WireGatewayApiClient, + AmountString, } from "@gnu-taler/taler-util"; import { WalletApiOperation, @@ -47,7 +48,7 @@ export async function runTippingTest(t: GlobalTestState) { const tipReserveResp = await merchantClient.createTippingReserve({ exchange_url: exchange.baseUrl, - initial_balance: "TESTKUDOS:10", + initial_balance: "TESTKUDOS:10" as AmountString, wire_method: getWireMethodForTest(), }); @@ -90,7 +91,7 @@ export async function runTippingTest(t: GlobalTestState) { ); const tip = await merchantClient.giveTip({ - amount: "TESTKUDOS:5", + amount: "TESTKUDOS:5" as AmountString, justification: "why not?", next_url: "https://example.com/after-tip", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts b/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts index 5e6539654..32534f2c8 100644 --- a/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts +++ b/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts @@ -18,6 +18,7 @@ * Imports. */ import { + AmountString, encodeCrock, getRandomBytes, j2s, @@ -69,7 +70,7 @@ export async function runWalletDblessTest(t: GlobalTestState) { }); await topupReserveWithDemobank({ - amount: "TESTKUDOS:10", + amount: "TESTKUDOS:10" as AmountString, http, reservePub: reserveKeyPair.pub, corebankApiBaseUrl: bank.corebankApiBaseUrl, @@ -84,7 +85,7 @@ export async function runWalletDblessTest(t: GlobalTestState) { await checkReserve(http, exchange.baseUrl, reserveKeyPair.pub); - const d1 = findDenomOrThrow(exchangeInfo, "TESTKUDOS:8", { + const d1 = findDenomOrThrow(exchangeInfo, "TESTKUDOS:8" as AmountString, { denomselAllowLate: Wallet.defaultConfig.testing.denomselAllowLate, }); @@ -107,7 +108,7 @@ export async function runWalletDblessTest(t: GlobalTestState) { contractTermsHash, merchantPub, wireSalt, - amount: "TESTKUDOS:4", + amount: "TESTKUDOS:4" as AmountString, coin: coin, cryptoApi, exchangeBaseUrl: exchange.baseUrl, @@ -119,7 +120,7 @@ export async function runWalletDblessTest(t: GlobalTestState) { contractTermsHash, merchantPub, wireSalt, - amount: "TESTKUDOS:4", + amount: "TESTKUDOS:4" as AmountString, coin: coin, cryptoApi, exchangeBaseUrl: exchange.baseUrl, @@ -127,10 +128,10 @@ export async function runWalletDblessTest(t: GlobalTestState) { }); const refreshDenoms = [ - findDenomOrThrow(exchangeInfo, "TESTKUDOS:1", { + findDenomOrThrow(exchangeInfo, "TESTKUDOS:1" as AmountString, { denomselAllowLate: Wallet.defaultConfig.testing.denomselAllowLate, }), - findDenomOrThrow(exchangeInfo, "TESTKUDOS:1", { + findDenomOrThrow(exchangeInfo, "TESTKUDOS:1" as AmountString, { denomselAllowLate: Wallet.defaultConfig.testing.denomselAllowLate, }), ]; diff --git a/packages/taler-harness/src/integrationtests/test-wallet-gendb.ts b/packages/taler-harness/src/integrationtests/test-wallet-gendb.ts index ff6ed9959..9e3b60899 100644 --- a/packages/taler-harness/src/integrationtests/test-wallet-gendb.ts +++ b/packages/taler-harness/src/integrationtests/test-wallet-gendb.ts @@ -26,6 +26,7 @@ import { } from "../harness/helpers.js"; import { AbsoluteTime, + AmountString, Duration, NotificationType, TransactionMajorState, @@ -77,7 +78,7 @@ export async function runWalletGenDbTest(t: GlobalTestState) { exchangeBaseUrl: exchange.baseUrl, partialContractTerms: { summary: "Hello World", - amount: "TESTKUDOS:5", + amount: "TESTKUDOS:5" as AmountString, purse_expiration: purseExpiration, }, }, diff --git a/packages/taler-harness/src/integrationtests/test-wallettesting.ts b/packages/taler-harness/src/integrationtests/test-wallettesting.ts index e5191aa5b..69637b875 100644 --- a/packages/taler-harness/src/integrationtests/test-wallettesting.ts +++ b/packages/taler-harness/src/integrationtests/test-wallettesting.ts @@ -22,7 +22,7 @@ /** * Imports. */ -import { Amounts, CoinStatus } from "@gnu-taler/taler-util"; +import { AmountString, Amounts, CoinStatus } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; import { @@ -118,8 +118,8 @@ export async function runWallettestingTest(t: GlobalTestState) { const { wallet, bank, exchange, merchant } = await createMyEnvironment(t); await wallet.client.call(WalletApiOperation.RunIntegrationTest, { - amountToSpend: "TESTKUDOS:5", - amountToWithdraw: "TESTKUDOS:10", + amountToSpend: "TESTKUDOS:5" as AmountString, + amountToWithdraw: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: bank.corebankApiBaseUrl, exchangeBaseUrl: exchange.baseUrl, merchantAuthToken: merchantAuthToken, @@ -142,7 +142,7 @@ export async function runWallettestingTest(t: GlobalTestState) { wallet.deleteDatabase(); await wallet.client.call(WalletApiOperation.WithdrawTestBalance, { - amount: "TESTKUDOS:10", + amount: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: bank.corebankApiBaseUrl, exchangeBaseUrl: exchange.baseUrl, }); @@ -150,7 +150,7 @@ export async function runWallettestingTest(t: GlobalTestState) { await wallet.runUntilDone(); await wallet.client.call(WalletApiOperation.TestPay, { - amount: "TESTKUDOS:5", + amount: "TESTKUDOS:5" as AmountString, merchantAuthToken: merchantAuthToken, merchantBaseUrl: merchant.makeInstanceBaseUrl(), summary: "foo", @@ -167,7 +167,7 @@ export async function runWallettestingTest(t: GlobalTestState) { wallet.deleteDatabase(); await wallet.client.call(WalletApiOperation.WithdrawTestBalance, { - amount: "TESTKUDOS:10", + amount: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: bank.corebankApiBaseUrl, exchangeBaseUrl: exchange.baseUrl, }); @@ -203,7 +203,7 @@ export async function runWallettestingTest(t: GlobalTestState) { // to pay. await t.assertThrowsAsync(async () => { await wallet.client.call(WalletApiOperation.TestPay, { - amount: "TESTKUDOS:5", + amount: "TESTKUDOS:5" as AmountString, merchantAuthToken: merchantAuthToken, merchantBaseUrl: merchant.makeInstanceBaseUrl(), summary: "foo", @@ -218,7 +218,7 @@ export async function runWallettestingTest(t: GlobalTestState) { }); await wallet.client.call(WalletApiOperation.TestPay, { - amount: "TESTKUDOS:5", + amount: "TESTKUDOS:5" as AmountString, merchantAuthToken: merchantAuthToken, merchantBaseUrl: merchant.makeInstanceBaseUrl(), summary: "foo", diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-fakebank.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-fakebank.ts index e26d9f964..afce2f776 100644 --- a/packages/taler-harness/src/integrationtests/test-withdrawal-fakebank.ts +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-fakebank.ts @@ -26,7 +26,7 @@ import { } from "../harness/harness.js"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; -import { URL } from "@gnu-taler/taler-util"; +import { AmountString, URL } from "@gnu-taler/taler-util"; /** * Run test for basic, bank-integrated withdrawal. @@ -84,7 +84,7 @@ export async function runWithdrawalFakebankTest(t: GlobalTestState) { await wallet.client.call(WalletApiOperation.WithdrawTestBalance, { corebankApiBaseUrl: bank.corebankApiBaseUrl, exchangeBaseUrl: exchange.baseUrl, - amount: "TESTKUDOS:10", + amount: "TESTKUDOS:10" as AmountString, }); await exchange.runWirewatchOnce(); diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-huge.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-huge.ts index 893d870e5..0ad60bcdd 100644 --- a/packages/taler-harness/src/integrationtests/test-withdrawal-huge.ts +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-huge.ts @@ -28,6 +28,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; import { + AmountString, NotificationType, TransactionMajorState, URL, @@ -101,7 +102,7 @@ export async function runWithdrawalHugeTest(t: GlobalTestState) { // Results in about 1K coins withdrawn await wallet.client.call(WalletApiOperation.WithdrawTestBalance, { exchangeBaseUrl: exchange.baseUrl, - amount: "TESTKUDOS:10000", + amount: "TESTKUDOS:10000" as AmountString, corebankApiBaseUrl: bank.baseUrl, }); diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-manual.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-manual.ts index fa483aa28..8ab029acc 100644 --- a/packages/taler-harness/src/integrationtests/test-withdrawal-manual.ts +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-manual.ts @@ -23,6 +23,7 @@ import { Logger, WireGatewayApiClient, j2s, + AmountString, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { GlobalTestState } from "../harness/harness.js"; @@ -60,7 +61,7 @@ export async function runWithdrawalManualTest(t: GlobalTestState) { WalletApiOperation.AcceptManualWithdrawal, { exchangeBaseUrl: exchange.baseUrl, - amount: "TESTKUDOS:10", + amount: "TESTKUDOS:10" as AmountString, }, ); diff --git a/packages/taler-util/src/amounts.test.ts b/packages/taler-util/src/amounts.test.ts index 644b8bdb4..e592d965c 100644 --- a/packages/taler-util/src/amounts.test.ts +++ b/packages/taler-util/src/amounts.test.ts @@ -17,6 +17,7 @@ import test from "ava"; import { Amounts, AmountJson, amountMaxValue } from "./amounts.js"; +import { AmountString } from "./taler-types.js"; const jAmt = ( value: number, @@ -120,31 +121,31 @@ test("amount parsing", (t) => { }); test("amount stringification", (t) => { - t.is(Amounts.stringify(jAmt(0, 0, "TESTKUDOS")), "TESTKUDOS:0"); - t.is(Amounts.stringify(jAmt(4, 94000000, "TESTKUDOS")), "TESTKUDOS:4.94"); - t.is(Amounts.stringify(jAmt(0, 10000000, "TESTKUDOS")), "TESTKUDOS:0.1"); - t.is(Amounts.stringify(jAmt(0, 1, "TESTKUDOS")), "TESTKUDOS:0.00000001"); - t.is(Amounts.stringify(jAmt(5, 0, "TESTKUDOS")), "TESTKUDOS:5"); + t.is(Amounts.stringify(jAmt(0, 0, "TESTKUDOS")), "TESTKUDOS:0" as AmountString); + t.is(Amounts.stringify(jAmt(4, 94000000, "TESTKUDOS")), "TESTKUDOS:4.94" as AmountString); + t.is(Amounts.stringify(jAmt(0, 10000000, "TESTKUDOS")), "TESTKUDOS:0.1" as AmountString); + t.is(Amounts.stringify(jAmt(0, 1, "TESTKUDOS")), "TESTKUDOS:0.00000001" as AmountString); + t.is(Amounts.stringify(jAmt(5, 0, "TESTKUDOS")), "TESTKUDOS:5" as AmountString); // denormalized - t.is(Amounts.stringify(jAmt(1, 100000000, "TESTKUDOS")), "TESTKUDOS:2"); + t.is(Amounts.stringify(jAmt(1, 100000000, "TESTKUDOS")), "TESTKUDOS:2" as AmountString); t.pass(); }); test("amount multiplication", (t) => { - t.is(Amounts.stringify(Amounts.mult(sAmt("EUR:1.11"), 0).amount), "EUR:0"); - t.is(Amounts.stringify(Amounts.mult(sAmt("EUR:1.11"), 1).amount), "EUR:1.11"); - t.is(Amounts.stringify(Amounts.mult(sAmt("EUR:1.11"), 2).amount), "EUR:2.22"); - t.is(Amounts.stringify(Amounts.mult(sAmt("EUR:1.11"), 3).amount), "EUR:3.33"); - t.is(Amounts.stringify(Amounts.mult(sAmt("EUR:1.11"), 4).amount), "EUR:4.44"); - t.is(Amounts.stringify(Amounts.mult(sAmt("EUR:1.11"), 5).amount), "EUR:5.55"); + t.is(Amounts.stringify(Amounts.mult(sAmt("EUR:1.11"), 0).amount), "EUR:0" as AmountString); + t.is(Amounts.stringify(Amounts.mult(sAmt("EUR:1.11"), 1).amount), "EUR:1.11" as AmountString); + t.is(Amounts.stringify(Amounts.mult(sAmt("EUR:1.11"), 2).amount), "EUR:2.22" as AmountString); + t.is(Amounts.stringify(Amounts.mult(sAmt("EUR:1.11"), 3).amount), "EUR:3.33" as AmountString); + t.is(Amounts.stringify(Amounts.mult(sAmt("EUR:1.11"), 4).amount), "EUR:4.44" as AmountString); + t.is(Amounts.stringify(Amounts.mult(sAmt("EUR:1.11"), 5).amount), "EUR:5.55" as AmountString); }); test("amount division", (t) => { t.is(Amounts.divmod("EUR:5", "EUR:1").quotient, 5); - t.is(Amounts.stringify(Amounts.divmod("EUR:5", "EUR:1").remainder), "EUR:0"); + t.is(Amounts.stringify(Amounts.divmod("EUR:5", "EUR:1").remainder), "EUR:0" as AmountString); t.is(Amounts.divmod("EUR:5", "EUR:2").quotient, 2); - t.is(Amounts.stringify(Amounts.divmod("EUR:5", "EUR:2").remainder), "EUR:1"); + t.is(Amounts.stringify(Amounts.divmod("EUR:5", "EUR:2").remainder), "EUR:1" as AmountString); }); diff --git a/packages/taler-util/src/amounts.ts b/packages/taler-util/src/amounts.ts index ee35a6bbe..082a8168e 100644 --- a/packages/taler-util/src/amounts.ts +++ b/packages/taler-util/src/amounts.ts @@ -74,7 +74,7 @@ export const codecForAmountJson = (): Codec => .property("fraction", codecForNumber()) .build("AmountJson"); -export const codecForAmountString = (): Codec => codecForAmountString(); +export const codecForAmountString = (): Codec => codecForString() as Codec; /** * Result of a possibly overflowing operation. @@ -469,11 +469,11 @@ export class Amounts { * Convert to standard human-readable string representation that's * also used in JSON formats. */ - static stringify(a: AmountLike): string { + static stringify(a: AmountLike): AmountString { a = Amounts.jsonifyAmount(a); const s = this.stringifyValue(a); - return `${a.currency}:${s}`; + return `${a.currency}:${s}` as AmountString; } static isSameCurrency(a1: AmountLike, a2: AmountLike): boolean { diff --git a/packages/taler-util/src/clk.ts b/packages/taler-util/src/clk.ts index 7bcd19b04..f9f260f83 100644 --- a/packages/taler-util/src/clk.ts +++ b/packages/taler-util/src/clk.ts @@ -23,12 +23,14 @@ import { readlinePrompt, pathBasename, } from "#compat-impl"; +import { AmountString } from "./taler-types.js"; export namespace clk { - class Converter {} + class Converter { } export const INT = new Converter(); export const STRING: Converter = new Converter(); + export const AMOUNT: Converter = new Converter(); export interface OptionArgs { help?: string; @@ -119,7 +121,7 @@ export namespace clk { private argKey: string, private name: string | null, private scArgs: SubcommandArgs, - ) {} + ) { } action(f: ActionFn): void { if (this.myAction) { diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index 11567b624..7503a4665 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -559,7 +559,7 @@ export interface CoinDumpJson { spend_allocation: | { id: string; - amount: string; + amount: AmountString; } | undefined; /** @@ -890,8 +890,8 @@ export interface PreparePayResultPaymentPossible { proposalId: string; contractTerms: MerchantContractTerms; contractTermsHash: string; - amountRaw: string; - amountEffective: string; + amountRaw: AmountString; + amountEffective: AmountString; talerUri: string; } @@ -903,7 +903,7 @@ export interface PreparePayResultInsufficientBalance { */ proposalId: string; contractTerms: MerchantContractTerms; - amountRaw: string; + amountRaw: AmountString; talerUri: string; balanceDetails: PayMerchantInsufficientBalanceDetails; } @@ -913,8 +913,8 @@ export interface PreparePayResultAlreadyConfirmed { transactionId: TransactionIdStr; contractTerms: MerchantContractTerms; paid: boolean; - amountRaw: string; - amountEffective: string | undefined; + amountRaw: AmountString; + amountEffective: AmountString | undefined; contractTermsHash: string; /** * @deprecated use transactionId @@ -1553,7 +1553,7 @@ export interface GetExchangeTosResult { export interface TestPayArgs { merchantBaseUrl: string; merchantAuthToken?: string; - amount: string; + amount: AmountString; summary: string; forcedCoinSel?: ForcedCoinSel; } @@ -1562,7 +1562,7 @@ export const codecForTestPayArgs = (): Codec => buildCodecForObject() .property("merchantBaseUrl", codecForString()) .property("merchantAuthToken", codecOptional(codecForString())) - .property("amount", codecForString()) + .property("amount", codecForAmountString()) .property("summary", codecForString()) .property("forcedCoinSel", codecForAny()) .build("TestPayArgs"); @@ -1572,8 +1572,8 @@ export interface IntegrationTestArgs { corebankApiBaseUrl: string; merchantBaseUrl: string; merchantAuthToken?: string; - amountToWithdraw: string; - amountToSpend: string; + amountToWithdraw: AmountString; + amountToSpend: AmountString; } export const codecForIntegrationTestArgs = (): Codec => @@ -1647,7 +1647,7 @@ export const codecForGetExchangeTosRequest = (): Codec => export interface AcceptManualWithdrawalRequest { exchangeBaseUrl: string; - amount: string; + amount: AmountString; restrictAge?: number; } @@ -1655,13 +1655,13 @@ export const codecForAcceptManualWithdrawalRequet = (): Codec => buildCodecForObject() .property("exchangeBaseUrl", codecForString()) - .property("amount", codecForString()) + .property("amount", codecForAmountString()) .property("restrictAge", codecOptional(codecForNumber())) .build("AcceptManualWithdrawalRequest"); export interface GetWithdrawalDetailsForAmountRequest { exchangeBaseUrl: string; - amount: string; + amount: AmountString; restrictAge?: number; } @@ -1685,7 +1685,7 @@ export const codecForGetWithdrawalDetailsForAmountRequest = (): Codec => buildCodecForObject() .property("exchangeBaseUrl", codecForString()) - .property("amount", codecForString()) + .property("amount", codecForAmountString()) .property("restrictAge", codecOptional(codecForNumber())) .build("GetWithdrawalDetailsForAmountRequest"); @@ -1873,7 +1873,7 @@ export interface CoreApiResponseError { } export interface WithdrawTestBalanceRequest { - amount: string; + amount: AmountString; /** * Corebank API base URL. */ @@ -1947,7 +1947,7 @@ export interface RecoveryLoadRequest { export const codecForWithdrawTestBalance = (): Codec => buildCodecForObject() - .property("amount", codecForString()) + .property("amount", codecForAmountString()) .property("exchangeBaseUrl", codecForString()) .property("forcedDenomSel", codecForAny()) .property("corebankApiBaseUrl", codecForString()) diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts index f3b205211..ee6b93381 100644 --- a/packages/taler-wallet-cli/src/index.ts +++ b/packages/taler-wallet-cli/src/index.ts @@ -21,6 +21,7 @@ import { AbsoluteTime, addPaytoQueryParams, AgeRestriction, + AmountString, codecForList, codecForString, CoreApiResponse, @@ -592,7 +593,7 @@ withdrawCli withdrawCli .subcommand("withdrawCheckAmount", "check-amount") .requiredArgument("exchange", clk.STRING) - .requiredArgument("amount", clk.STRING) + .requiredArgument("amount", clk.AMOUNT) .maybeOption("restrictAge", ["--restrict-age"], clk.INT) .action(async (args) => { const restrictAge = args.withdrawCheckAmount.restrictAge; @@ -728,7 +729,7 @@ withdrawCli .requiredOption("exchange", ["--exchange"], clk.STRING, { help: "Base URL of the exchange.", }) - .requiredOption("amount", ["--amount"], clk.STRING, { + .requiredOption("amount", ["--amount"], clk.AMOUNT, { help: "Amount to withdraw", }) .maybeOption("restrictAge", ["--restrict-age"], clk.INT) @@ -960,7 +961,7 @@ const depositCli = walletCli.subcommand("depositArgs", "deposit", { depositCli .subcommand("createDepositArgs", "create") - .requiredArgument("amount", clk.STRING) + .requiredArgument("amount", clk.AMOUNT) .requiredArgument("targetPayto", clk.STRING) .action(async (args) => { await withLocalWallet(args, async (wallet) => { @@ -984,7 +985,7 @@ peerCli .subcommand("checkPayPush", "check-push-debit", { help: "Check fees for starting a peer-push debit transaction.", }) - .requiredArgument("amount", clk.STRING, { + .requiredArgument("amount", clk.AMOUNT, { help: "Amount to pay", }) .action(async (args) => { @@ -1003,7 +1004,7 @@ peerCli .subcommand("checkPayPull", "check-pull-credit", { help: "Check fees for a starting peer-pull credit transaction.", }) - .requiredArgument("amount", clk.STRING, { + .requiredArgument("amount", clk.AMOUNT, { help: "Amount to request", }) .action(async (args) => { @@ -1067,7 +1068,7 @@ peerCli .subcommand("initiatePayPull", "initiate-pull-credit", { help: "Initiate a peer-pull payment.", }) - .requiredArgument("amount", clk.STRING, { + .requiredArgument("amount", clk.AMOUNT, { help: "Amount to request", }) .maybeOption("summary", ["--summary"], clk.STRING, { @@ -1125,7 +1126,7 @@ peerCli .subcommand("payPush", "initiate-push-debit", { help: "Initiate a peer-push payment.", }) - .requiredArgument("amount", clk.STRING, { + .requiredArgument("amount", clk.AMOUNT, { help: "Amount to pay", }) .maybeOption("summary", ["--summary"], clk.STRING, { @@ -1239,7 +1240,7 @@ advancedCli help: "Initialize the wallet (with DB) and exit.", }) .action(async (args) => { - await withWallet(args, async () => {}); + await withWallet(args, async () => { }); }); advancedCli @@ -1278,8 +1279,8 @@ advancedCli const wallet = res.wallet; await wallet.client.call(WalletApiOperation.InitWallet, {}); await wallet.client.call(WalletApiOperation.RunIntegrationTest, { - amountToSpend: "TESTKUDOS:1", - amountToWithdraw: "TESTKUDOS:3", + amountToSpend: "TESTKUDOS:1" as AmountString, + amountToWithdraw: "TESTKUDOS:3" as AmountString, corebankApiBaseUrl: "http://localhost:8082/taler-bank-access/", exchangeBaseUrl: "http://localhost:8081/", merchantBaseUrl: "http://localhost:8083/", @@ -1506,7 +1507,7 @@ testCli testCli.subcommand("withdrawKudos", "withdraw-kudos").action(async (args) => { await withWallet(args, async (wallet) => { await wallet.client.call(WalletApiOperation.WithdrawTestBalance, { - amount: "KUDOS:50", + amount: "KUDOS:50" as AmountString, corebankApiBaseUrl: "https://bank.demo.taler.net/", exchangeBaseUrl: "https://exchange.demo.taler.net/", diff --git a/packages/taler-wallet-core/src/operations/testing.ts b/packages/taler-wallet-core/src/operations/testing.ts index f5bed13dd..3fff9ccaa 100644 --- a/packages/taler-wallet-core/src/operations/testing.ts +++ b/packages/taler-wallet-core/src/operations/testing.ts @@ -680,7 +680,7 @@ export async function runIntegrationTest2( const peerPushInit = await initiatePeerPushDebit(ws, { partialContractTerms: { - amount: `${currency}:1`, + amount: `${currency}:1` as AmountString, summary: "Payment Peer Push Test", purse_expiration: AbsoluteTime.toProtocolTimestamp( AbsoluteTime.addDuration( @@ -703,7 +703,7 @@ export async function runIntegrationTest2( const peerPullInit = await initiatePeerPullPayment(ws, { partialContractTerms: { - amount: `${currency}:1`, + amount: `${currency}:1` as AmountString, summary: "Payment Peer Pull Test", purse_expiration: AbsoluteTime.toProtocolTimestamp( AbsoluteTime.addDuration( diff --git a/packages/taler-wallet-core/src/operations/withdraw.test.ts b/packages/taler-wallet-core/src/operations/withdraw.test.ts index cb8aa5e81..97a80ec26 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.test.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.test.ts @@ -14,7 +14,7 @@ GNU Taler; see the file COPYING. If not, see */ -import { Amounts, DenomKeyType } from "@gnu-taler/taler-util"; +import { AmountString, Amounts, DenomKeyType } from "@gnu-taler/taler-util"; import test from "ava"; import { DenominationRecord, @@ -82,7 +82,7 @@ test("withdrawal selection bug repro", (t) => { }), verificationStatus: DenominationVerificationStatus.Unverified, currency: "KUDOS", - value: "KUDOS:1000", + value: "KUDOS:1000" as AmountString, listIssueDate: timestampProtocolToDb({ t_s: 0 }), }, { @@ -136,7 +136,7 @@ test("withdrawal selection bug repro", (t) => { t_s: 1585229388, }), verificationStatus: DenominationVerificationStatus.Unverified, - value: "KUDOS:10", + value: "KUDOS:10" as AmountString, currency: "KUDOS", listIssueDate: timestampProtocolToDb({ t_s: 0 }), }, @@ -190,7 +190,7 @@ test("withdrawal selection bug repro", (t) => { t_s: 1585229388, }), verificationStatus: DenominationVerificationStatus.Unverified, - value: "KUDOS:5", + value: "KUDOS:5" as AmountString, currency: "KUDOS", listIssueDate: timestampProtocolToDb({ t_s: 0 }), }, @@ -245,7 +245,7 @@ test("withdrawal selection bug repro", (t) => { t_s: 1585229388, }), verificationStatus: DenominationVerificationStatus.Unverified, - value: "KUDOS:1", + value: "KUDOS:1" as AmountString, currency: "KUDOS", listIssueDate: timestampProtocolToDb({ t_s: 0 }), }, @@ -357,7 +357,7 @@ test("withdrawal selection bug repro", (t) => { t_s: 1585229388, }), verificationStatus: DenominationVerificationStatus.Unverified, - value: "KUDOS:2", + value: "KUDOS:2" as AmountString, currency: "KUDOS", listIssueDate: timestampProtocolToDb({ t_s: 0 }), }, diff --git a/packages/taler-wallet-core/src/util/coinSelection.test.ts b/packages/taler-wallet-core/src/util/coinSelection.test.ts index 81a656f8a..69c25a2fa 100644 --- a/packages/taler-wallet-core/src/util/coinSelection.test.ts +++ b/packages/taler-wallet-core/src/util/coinSelection.test.ts @@ -48,9 +48,9 @@ test("p2p: should select the coin", (t) => { const coins = testing_greedySelectPeer( createCandidates([ { - amount: "LOCAL:10", + amount: "LOCAL:10" as AmountString, numAvailable: 5, - depositFee: "LOCAL:0.1", + depositFee: "LOCAL:0.1" as AmountString, fromExchange: "http://exchange.localhost/", }, ]), @@ -86,9 +86,9 @@ test("p2p: should select 3 coins", (t) => { const coins = testing_greedySelectPeer( createCandidates([ { - amount: "LOCAL:10", + amount: "LOCAL:10" as AmountString, numAvailable: 5, - depositFee: "LOCAL:0.1", + depositFee: "LOCAL:0.1" as AmountString, fromExchange: "http://exchange.localhost/", }, ]), @@ -126,9 +126,9 @@ test("p2p: can't select since the instructed amount is too high", (t) => { const coins = testing_greedySelectPeer( createCandidates([ { - amount: "LOCAL:10", + amount: "LOCAL:10" as AmountString, numAvailable: 5, - depositFee: "LOCAL:0.1", + depositFee: "LOCAL:0.1" as AmountString, fromExchange: "http://exchange.localhost/", }, ]), @@ -176,9 +176,9 @@ test("pay: select one coin to pay with fee", (t) => { }, createCandidates([ { - amount: "LOCAL:10", + amount: "LOCAL:10" as AmountString, numAvailable: 5, - depositFee: "LOCAL:0.1", + depositFee: "LOCAL:0.1" as AmountString, fromExchange: "http://exchange.localhost/", }, ]), @@ -224,9 +224,9 @@ function createCandidates( denomPubHash: `hash${idx}`, value: r.amount, feeDeposit: r.depositFee, - feeRefresh: "LOCAL:0", - feeRefund: "LOCAL:0", - feeWithdraw: "LOCAL:0", + feeRefresh: "LOCAL:0" as AmountString, + feeRefund: "LOCAL:0" as AmountString, + feeWithdraw: "LOCAL:0" as AmountString, stampExpireDeposit: inTheDistantFuture, stampExpireLegal: inTheDistantFuture, stampExpireWithdraw: inTheDistantFuture, diff --git a/packages/taler-wallet-core/src/util/denominations.test.ts b/packages/taler-wallet-core/src/util/denominations.test.ts index 25dbda081..98af5d1a4 100644 --- a/packages/taler-wallet-core/src/util/denominations.test.ts +++ b/packages/taler-wallet-core/src/util/denominations.test.ts @@ -39,7 +39,7 @@ import test, { ExecutionContext } from "ava"; * Create some constants to be used as reference in the tests */ const VALUES: AmountString[] = Array.from({ length: 10 }).map( - (undef, t) => `USD:${t}`, + (undef, t) => `USD:${t}` as AmountString, ); const TIMESTAMPS = Array.from({ length: 20 }).map((undef, t_s) => ({ t_s })); const ABS_TIME = TIMESTAMPS.map((m) => AbsoluteTime.fromProtocolTimestamp(m)); diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 6600aa799..fe77fecc1 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -132,6 +132,7 @@ import { codecForListExchangesForScopedCurrencyRequest, ListExchangesForScopedCurrencyRequest, ExchangesShortListResponse, + AmountString, } from "@gnu-taler/taler-util"; import type { HttpRequestLibrary } from "@gnu-taler/taler-util/http"; import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http"; @@ -931,9 +932,9 @@ async function dumpCoins(ws: InternalWalletState): Promise { ageCommitmentProof: c.ageCommitmentProof, spend_allocation: c.spendAllocation ? { - amount: c.spendAllocation.amount, - id: c.spendAllocation.id, - } + amount: c.spendAllocation.amount, + id: c.spendAllocation.id, + } : undefined, }); } @@ -1076,7 +1077,7 @@ async function dispatchRequestInternal( } case WalletApiOperation.WithdrawTestkudos: { await withdrawTestBalance(ws, { - amount: "TESTKUDOS:10", + amount: "TESTKUDOS:10" as AmountString, corebankApiBaseUrl: "https://bank.test.taler.net/", exchangeBaseUrl: "https://exchange.test.taler.net/", }); @@ -1278,7 +1279,7 @@ async function dispatchRequestInternal( typeof url.templateParams.amount === "string" ) { templateDetails.amount = - req.templateParams.amount ?? url.templateParams.amount; + (req.templateParams.amount ?? url.templateParams.amount) as AmountString | undefined; } if ( url.templateParams.summary !== undefined && diff --git a/packages/taler-wallet-webextension/src/components/Amount.stories.tsx b/packages/taler-wallet-webextension/src/components/Amount.stories.tsx index 095c9be24..fa28088eb 100644 --- a/packages/taler-wallet-webextension/src/components/Amount.stories.tsx +++ b/packages/taler-wallet-webextension/src/components/Amount.stories.tsx @@ -22,6 +22,7 @@ import { styled } from "@linaria/react"; import { Fragment, h, VNode } from "preact"; import { Amount } from "./Amount.js"; +import { AmountString } from "@gnu-taler/taler-util"; export default { title: "amount", @@ -39,7 +40,7 @@ const Table = styled.table` function ProductTable( prods: string[], - AmountRender: (p: { value: string; index: number }) => VNode = Amount, + AmountRender: (p: { value: AmountString; index: number }) => VNode = Amount, ): VNode { return ( @@ -52,7 +53,7 @@ function ProductTable( diff --git a/packages/taler-wallet-webextension/src/components/ShowFullContractTermPopup.stories.tsx b/packages/taler-wallet-webextension/src/components/ShowFullContractTermPopup.stories.tsx index 1b1802b8c..555b300c2 100644 --- a/packages/taler-wallet-webextension/src/components/ShowFullContractTermPopup.stories.tsx +++ b/packages/taler-wallet-webextension/src/components/ShowFullContractTermPopup.stories.tsx @@ -25,14 +25,14 @@ import { LoadingView, ShowView, } from "./ShowFullContractTermPopup.js"; -import { WalletContractData } from "@gnu-taler/taler-util"; +import { AmountString, WalletContractData } from "@gnu-taler/taler-util"; export default { title: "ShowFullContractTermPopup", }; const cd: WalletContractData = { - amount: "ARS:2", + amount: "ARS:2" as AmountString, contractTermsHash: "92X0KSJPZ8XS2XECCGFWTCGW8XMFCXTT2S6WHZDP6H9Y3TSKMTHY94WXEWDERTNN5XWCYGW4VN5CF2D4846HXTW7P06J4CZMHCWKC9G", fulfillmentUrl: "", @@ -42,7 +42,7 @@ const cd: WalletContractData = { "0YA1WETV15R6K8QKS79QA3QMT16010F42Q49VSKYQ71HVQKAG0A4ZJCA4YTKHE9EA5SP156TJSKZEJJJ87305N6PS80PC48RNKYZE08", orderId: "2022.220-0281XKKB8W7YE", summary: "w", - maxWireFee: "ARS:1", + maxWireFee: "ARS:1" as AmountString, payDeadline: { t_s: 1660002673, }, @@ -62,7 +62,7 @@ const cd: WalletContractData = { wireMethod: "x-taler-bank", wireInfoHash: "QDT28374ZHYJ59WQFZ3TW1D5WKJVDYHQT86VHED3TNMB15ANJSKXDYPPNX01348KDYCX6T4WXA5A8FJJ8YWNEB1JW726C1JPKHM89DR", - maxDepositFee: "ARS:1", + maxDepositFee: "ARS:1" as AmountString, merchant: { name: "Default", address: { diff --git a/packages/taler-wallet-webextension/src/cta/Deposit/test.ts b/packages/taler-wallet-webextension/src/cta/Deposit/test.ts index 144bdccf4..100929918 100644 --- a/packages/taler-wallet-webextension/src/cta/Deposit/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Deposit/test.ts @@ -19,7 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { Amounts } from "@gnu-taler/taler-util"; +import { AmountString, Amounts } from "@gnu-taler/taler-util"; import { expect } from "chai"; import { createWalletApiMock } from "../../test-utils.js"; import { useComponentState } from "./state.js"; @@ -72,19 +72,19 @@ describe("Deposit CTA states", () => { WalletApiOperation.PrepareDeposit, undefined, { - effectiveDepositAmount: "EUR:1", - totalDepositCost: "EUR:1.2", + effectiveDepositAmount: "EUR:1" as AmountString, + totalDepositCost: "EUR:1.2" as AmountString, fees: { - coin: "EUR:0", - refresh: "EUR:0.2", - wire: "EUR:0", + coin: "EUR:0" as AmountString, + refresh: "EUR:0.2" as AmountString, + wire: "EUR:0" as AmountString, }, }, ); const props = { talerDepositUri: "payto://refund/asdasdas", - amountStr: "EUR:1", + amountStr: "EUR:1" as AmountString, cancel: async () => { null; }, diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/index.ts b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/index.ts index b8aaed3f2..fd3fb52f8 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/index.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/index.ts @@ -14,7 +14,7 @@ GNU Taler; see the file COPYING. If not, see */ -import { AmountJson } from "@gnu-taler/taler-util"; +import { AmountJson, AmountString } from "@gnu-taler/taler-util"; import { ErrorAlertView } from "../../components/CurrentAlerts.js"; import { Loading } from "../../components/Loading.js"; import { ErrorAlert } from "../../context/alert.js"; @@ -27,7 +27,7 @@ import { useComponentState } from "./state.js"; import { ReadyView } from "./views.js"; export interface Props { - amount: string; + amount: AmountString; onClose: () => Promise; onSuccess: (tx: string) => Promise; } diff --git a/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx b/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx index f030fa219..eee5fb684 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx +++ b/packages/taler-wallet-webextension/src/cta/Payment/stories.tsx @@ -20,6 +20,7 @@ */ import { + AmountString, Amounts, MerchantContractTerms as ContractTerms, PreparePayResultType, @@ -52,13 +53,13 @@ export const NoEnoughBalanceAvailable = tests.createExample(BaseView, { transactionId: " " as TransactionIdStr, status: PreparePayResultType.InsufficientBalance, balanceDetails: { - amountRequested: "USD:10", - balanceAvailable: "USD:9", - balanceMaterial: "USD:9", - balanceAgeAcceptable: "USD:9", - balanceMerchantAcceptable: "USD:9", - balanceMerchantDepositable: "USD:9", - feeGapEstimate: "USD:1", + amountRequested: "USD:10" as AmountString, + balanceAvailable: "USD:9" as AmountString, + balanceMaterial: "USD:9" as AmountString, + balanceAgeAcceptable: "USD:9" as AmountString, + balanceMerchantAcceptable: "USD:9" as AmountString, + balanceMerchantDepositable: "USD:9" as AmountString, + feeGapEstimate: "USD:1" as AmountString, }, talerUri: "taler://pay/..", @@ -73,7 +74,7 @@ export const NoEnoughBalanceAvailable = tests.createExample(BaseView, { summary: "some beers", amount: "USD:10", } as Partial as any, - amountRaw: "USD:10", + amountRaw: "USD:10" as AmountString, }, }); @@ -92,13 +93,13 @@ export const NoEnoughBalanceMaterial = tests.createExample(BaseView, { transactionId: " " as TransactionIdStr, status: PreparePayResultType.InsufficientBalance, balanceDetails: { - amountRequested: "USD:10", - balanceAvailable: "USD:10", - balanceMaterial: "USD:9", - balanceAgeAcceptable: "USD:9", - balanceMerchantAcceptable: "USD:9", - balanceMerchantDepositable: "USD:0", - feeGapEstimate: "USD:1", + amountRequested: "USD:10" as AmountString, + balanceAvailable: "USD:10" as AmountString, + balanceMaterial: "USD:9" as AmountString, + balanceAgeAcceptable: "USD:9" as AmountString, + balanceMerchantAcceptable: "USD:9" as AmountString, + balanceMerchantDepositable: "USD:0" as AmountString, + feeGapEstimate: "USD:1" as AmountString, }, talerUri: "taler://pay/..", @@ -111,9 +112,9 @@ export const NoEnoughBalanceMaterial = tests.createExample(BaseView, { email: "contact@merchant.taler", }, summary: "some beers", - amount: "USD:10", + amount: "USD:10" as AmountString, } as Partial as any, - amountRaw: "USD:10", + amountRaw: "USD:10" as AmountString, }, }); @@ -132,13 +133,13 @@ export const NoEnoughBalanceAgeAcceptable = tests.createExample(BaseView, { transactionId: " " as TransactionIdStr, status: PreparePayResultType.InsufficientBalance, balanceDetails: { - amountRequested: "USD:10", - balanceAvailable: "USD:10", - balanceMaterial: "USD:10", - balanceAgeAcceptable: "USD:9", - balanceMerchantAcceptable: "USD:9", - balanceMerchantDepositable: "USD:9", - feeGapEstimate: "USD:1", + amountRequested: "USD:10" as AmountString, + balanceAvailable: "USD:10" as AmountString, + balanceMaterial: "USD:10" as AmountString, + balanceAgeAcceptable: "USD:9" as AmountString, + balanceMerchantAcceptable: "USD:9" as AmountString, + balanceMerchantDepositable: "USD:9" as AmountString, + feeGapEstimate: "USD:1" as AmountString, }, talerUri: "taler://pay/..", @@ -154,7 +155,7 @@ export const NoEnoughBalanceAgeAcceptable = tests.createExample(BaseView, { summary: "some beers", amount: "USD:10", } as Partial as any, - amountRaw: "USD:10", + amountRaw: "USD:10" as AmountString, }, }); @@ -173,13 +174,13 @@ export const NoEnoughBalanceMerchantAcceptable = tests.createExample(BaseView, { transactionId: " " as TransactionIdStr, status: PreparePayResultType.InsufficientBalance, balanceDetails: { - amountRequested: "USD:10", - balanceAvailable: "USD:10", - balanceMaterial: "USD:10", - balanceAgeAcceptable: "USD:10", - balanceMerchantAcceptable: "USD:9", - balanceMerchantDepositable: "USD:9", - feeGapEstimate: "USD:1", + amountRequested: "USD:10" as AmountString, + balanceAvailable: "USD:10" as AmountString, + balanceMaterial: "USD:10" as AmountString, + balanceAgeAcceptable: "USD:10" as AmountString, + balanceMerchantAcceptable: "USD:9" as AmountString, + balanceMerchantDepositable: "USD:9" as AmountString, + feeGapEstimate: "USD:1" as AmountString, }, talerUri: "taler://pay/..", @@ -192,9 +193,9 @@ export const NoEnoughBalanceMerchantAcceptable = tests.createExample(BaseView, { email: "contact@merchant.taler", }, summary: "some beers", - amount: "USD:10", + amount: "USD:10" as AmountString, } as Partial as any, - amountRaw: "USD:10", + amountRaw: "USD:10" as AmountString, }, }); @@ -215,13 +216,13 @@ export const NoEnoughBalanceMerchantDepositable = tests.createExample( transactionId: " " as TransactionIdStr, status: PreparePayResultType.InsufficientBalance, balanceDetails: { - amountRequested: "USD:10", - balanceAvailable: "USD:10", - balanceMaterial: "USD:10", - balanceAgeAcceptable: "USD:10", - balanceMerchantAcceptable: "USD:10", - balanceMerchantDepositable: "USD:9", - feeGapEstimate: "USD:1", + amountRequested: "USD:10" as AmountString, + balanceAvailable: "USD:10" as AmountString, + balanceMaterial: "USD:10" as AmountString, + balanceAgeAcceptable: "USD:10" as AmountString, + balanceMerchantAcceptable: "USD:10" as AmountString, + balanceMerchantDepositable: "USD:9" as AmountString, + feeGapEstimate: "USD:1" as AmountString, }, talerUri: "taler://pay/..", @@ -234,9 +235,9 @@ export const NoEnoughBalanceMerchantDepositable = tests.createExample( email: "contact@merchant.taler", }, summary: "some beers", - amount: "USD:10", + amount: "USD:10" as AmountString, } as Partial as any, - amountRaw: "USD:10", + amountRaw: "USD:10" as AmountString, }, }, ); @@ -256,13 +257,13 @@ export const NoEnoughBalanceFeeGap = tests.createExample(BaseView, { transactionId: " " as TransactionIdStr, status: PreparePayResultType.InsufficientBalance, balanceDetails: { - amountRequested: "USD:10", - balanceAvailable: "USD:10", - balanceMaterial: "USD:10", - balanceAgeAcceptable: "USD:10", - balanceMerchantAcceptable: "USD:10", - balanceMerchantDepositable: "USD:10", - feeGapEstimate: "USD:1", + amountRequested: "USD:10" as AmountString, + balanceAvailable: "USD:10" as AmountString, + balanceMaterial: "USD:10" as AmountString, + balanceAgeAcceptable: "USD:10" as AmountString, + balanceMerchantAcceptable: "USD:10" as AmountString, + balanceMerchantDepositable: "USD:10" as AmountString, + feeGapEstimate: "USD:1" as AmountString, }, talerUri: "taler://pay/..", @@ -276,9 +277,9 @@ export const NoEnoughBalanceFeeGap = tests.createExample(BaseView, { }, minimum_age: 18, summary: "some beers", - amount: "USD:10", + amount: "USD:10" as AmountString, } as Partial as any, - amountRaw: "USD:10", + amountRaw: "USD:10" as AmountString, }, }); @@ -300,8 +301,8 @@ export const PaymentPossible = tests.createExample(BaseView, { transactionId: " " as TransactionIdStr, status: PreparePayResultType.PaymentPossible, talerUri: "taler://pay/..", - amountEffective: "USD:10", - amountRaw: "USD:10", + amountEffective: "USD:10" as AmountString, + amountRaw: "USD:10" as AmountString, contractTerms: { nonce: "123213123", @@ -314,7 +315,7 @@ export const PaymentPossible = tests.createExample(BaseView, { pay_deadline: { t_s: new Date().getTime() / 1000 + 60 * 60 * 3, }, - amount: "USD:10", + amount: "USD:10" as AmountString, summary: "some beers", } as Partial as any, contractTermsHash: "123456", @@ -340,8 +341,8 @@ export const PaymentPossibleWithFee = tests.createExample(BaseView, { transactionId: " " as TransactionIdStr, status: PreparePayResultType.PaymentPossible, talerUri: "taler://pay/..", - amountEffective: "USD:10.20", - amountRaw: "USD:10", + amountEffective: "USD:10.20" as AmountString, + amountRaw: "USD:10" as AmountString, contractTerms: { nonce: "123213123", @@ -351,7 +352,7 @@ export const PaymentPossibleWithFee = tests.createExample(BaseView, { website: "https://www.themerchant.taler", email: "contact@merchant.taler", }, - amount: "USD:10", + amount: "USD:10" as AmountString, summary: "some beers", } as Partial as any, contractTermsHash: "123456", @@ -377,8 +378,8 @@ export const TicketWithAProductList = tests.createExample(BaseView, { transactionId: " " as TransactionIdStr, status: PreparePayResultType.PaymentPossible, talerUri: "taler://pay/..", - amountEffective: "USD:10.20", - amountRaw: "USD:10", + amountEffective: "USD:10.20" as AmountString, + amountRaw: "USD:10" as AmountString, contractTerms: { nonce: "123213123", @@ -433,8 +434,8 @@ export const TicketWithShipping = tests.createExample(BaseView, { transactionId: " " as TransactionIdStr, status: PreparePayResultType.PaymentPossible, talerUri: "taler://pay/..", - amountEffective: "USD:10.20", - amountRaw: "USD:10", + amountEffective: "USD:10.20" as AmountString, + amountRaw: "USD:10" as AmountString, contractTerms: { nonce: "123213123", @@ -481,8 +482,8 @@ export const AlreadyConfirmedByOther = tests.createExample(BaseView, { transactionId: " " as TransactionIdStr, status: PreparePayResultType.AlreadyConfirmed, talerUri: "taler://pay/..", - amountEffective: "USD:10", - amountRaw: "USD:10", + amountEffective: "USD:10" as AmountString, + amountRaw: "USD:10" as AmountString, contractTerms: { merchant: { name: "the merchant", diff --git a/packages/taler-wallet-webextension/src/cta/Payment/test.ts b/packages/taler-wallet-webextension/src/cta/Payment/test.ts index e2935fc4e..213382efc 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/test.ts @@ -20,6 +20,7 @@ */ import { + AmountString, Amounts, ConfirmPayResult, ConfirmPayResultType, @@ -139,10 +140,10 @@ describe("Payment CTA states", () => { { balances: [ { - available: "USD:5", + available: "USD:5" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "USD", @@ -199,10 +200,10 @@ describe("Payment CTA states", () => { { balances: [ { - available: "USD:15", + available: "USD:15" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "USD", @@ -262,10 +263,10 @@ describe("Payment CTA states", () => { { balances: [ { - available: "USD:15", + available: "USD:15" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "USD", @@ -323,10 +324,10 @@ describe("Payment CTA states", () => { { balances: [ { - available: "USD:15", + available: "USD:15" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "USD", @@ -392,10 +393,10 @@ describe("Payment CTA states", () => { { balances: [ { - available: "USD:15", + available: "USD:15" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "USD", @@ -480,10 +481,10 @@ describe("Payment CTA states", () => { { balances: [ { - available: "USD:10", + available: "USD:10" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "USD", @@ -511,10 +512,10 @@ describe("Payment CTA states", () => { { balances: [ { - available: "USD:15", + available: "USD:15" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "USD", diff --git a/packages/taler-wallet-webextension/src/cta/Reward/test.ts b/packages/taler-wallet-webextension/src/cta/Reward/test.ts index 6d7bad0c8..0e378f366 100644 --- a/packages/taler-wallet-webextension/src/cta/Reward/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Reward/test.ts @@ -19,7 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { Amounts } from "@gnu-taler/taler-util"; +import { AmountString, Amounts } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { expect } from "chai"; import * as tests from "@gnu-taler/web-util/testing"; @@ -66,13 +66,13 @@ describe("Tip CTA states", () => { accepted: false, exchangeBaseUrl: "exchange url", merchantBaseUrl: "merchant url", - rewardAmountEffective: "EUR:1", + rewardAmountEffective: "EUR:1" as AmountString, walletRewardId: "tip_id", transactionId: "txn:tip:ABC1234", expirationTimestamp: { t_s: 1, }, - rewardAmountRaw: "", + rewardAmountRaw: "EUR:0" as AmountString, }); const props: Props = { @@ -110,13 +110,13 @@ describe("Tip CTA states", () => { accepted: true, exchangeBaseUrl: "exchange url", merchantBaseUrl: "merchant url", - rewardAmountEffective: "EUR:1", + rewardAmountEffective: "EUR:1" as AmountString, walletRewardId: "tip_id", transactionId: "txn:tip:ABC1234", expirationTimestamp: { t_s: 1, }, - rewardAmountRaw: "", + rewardAmountRaw: "EUR:0" as AmountString, }, ); }, @@ -140,14 +140,14 @@ describe("Tip CTA states", () => { handler.addWalletCallResponse(WalletApiOperation.PrepareReward, undefined, { exchangeBaseUrl: "exchange url", merchantBaseUrl: "merchant url", - rewardAmountEffective: "EUR:1", + rewardAmountEffective: "EUR:1" as AmountString, walletRewardId: "tip_id", transactionId: "txn:tip:ABC1234", accepted: false, expirationTimestamp: { t_s: 1, }, - rewardAmountRaw: "", + rewardAmountRaw: "EUR:0" as AmountString, }); const props: Props = { @@ -188,13 +188,13 @@ describe("Tip CTA states", () => { accepted: true, exchangeBaseUrl: "exchange url", merchantBaseUrl: "merchant url", - rewardAmountEffective: "EUR:1", + rewardAmountEffective: "EUR:1" as AmountString, walletRewardId: "tip_id", transactionId: "txn:tip:ABC1234", expirationTimestamp: { t_s: 1, }, - rewardAmountRaw: "", + rewardAmountRaw: "EUR:0" as AmountString, }); const props: Props = { diff --git a/packages/taler-wallet-webextension/src/cta/TransferCreate/index.ts b/packages/taler-wallet-webextension/src/cta/TransferCreate/index.ts index 654b03b7f..794d2ad1c 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferCreate/index.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferCreate/index.ts @@ -14,7 +14,7 @@ GNU Taler; see the file COPYING. If not, see */ -import { AmountJson, TalerErrorDetail } from "@gnu-taler/taler-util"; +import { AmountJson, AmountString, TalerErrorDetail } from "@gnu-taler/taler-util"; import { ErrorAlertView } from "../../components/CurrentAlerts.js"; import { Loading } from "../../components/Loading.js"; import { ErrorAlert } from "../../context/alert.js"; @@ -24,7 +24,7 @@ import { useComponentState } from "./state.js"; import { ReadyView } from "./views.js"; export interface Props { - amount: string; + amount: AmountString; onClose: () => Promise; onSuccess: (tx: string) => Promise; } diff --git a/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts b/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts index 77333e15c..297e8a56b 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts @@ -15,6 +15,7 @@ */ import { + AmountString, Amounts, TalerError, TalerErrorCode, @@ -141,7 +142,7 @@ export function useComponentState({ async function checkPeerPushDebitAndCheckMax( api: WxApiType, - amountState: string, + amountState: AmountString, ) { // FIXME : https://bugs.gnunet.org/view.php?id=7872 try { diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts index ab3b2e316..e5eaa3c14 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts @@ -20,6 +20,7 @@ */ import { + AmountString, Amounts, ExchangeEntryStatus, ExchangeListItem, @@ -109,7 +110,7 @@ describe("Withdraw CTA states", () => { WalletApiOperation.GetWithdrawalDetailsForUri, undefined, { - amount: "EUR:2", + amount: "EUR:2" as AmountString, possibleExchanges: [], }, ); @@ -145,7 +146,7 @@ describe("Withdraw CTA states", () => { WalletApiOperation.GetWithdrawalDetailsForUri, undefined, { - amount: "ARS:2", + amount: "ARS:2" as AmountString, possibleExchanges: exchanges, defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl, }, @@ -154,8 +155,8 @@ describe("Withdraw CTA states", () => { WalletApiOperation.GetWithdrawalDetailsForAmount, undefined, { - amountRaw: "ARS:2", - amountEffective: "ARS:2", + amountRaw: "ARS:2" as AmountString, + amountEffective: "ARS:2" as AmountString, paytoUris: ["payto://"], tosAccepted: true, ageRestrictionOptions: [], @@ -209,7 +210,7 @@ describe("Withdraw CTA states", () => { WalletApiOperation.GetWithdrawalDetailsForUri, undefined, { - amount: "ARS:2", + amount: "ARS:2" as AmountString, possibleExchanges: exchangeWithNewTos, defaultExchangeBaseUrl: exchangeWithNewTos[0].exchangeBaseUrl, }, @@ -218,8 +219,8 @@ describe("Withdraw CTA states", () => { WalletApiOperation.GetWithdrawalDetailsForAmount, undefined, { - amountRaw: "ARS:2", - amountEffective: "ARS:2", + amountRaw: "ARS:2" as AmountString, + amountEffective: "ARS:2" as AmountString, paytoUris: ["payto://"], tosAccepted: false, ageRestrictionOptions: [], @@ -231,7 +232,7 @@ describe("Withdraw CTA states", () => { WalletApiOperation.GetWithdrawalDetailsForUri, undefined, { - amount: "ARS:2", + amount: "ARS:2" as AmountString, possibleExchanges: exchanges, defaultExchangeBaseUrl: exchanges[0].exchangeBaseUrl, }, diff --git a/packages/taler-wallet-webextension/src/popup/Balance.stories.tsx b/packages/taler-wallet-webextension/src/popup/Balance.stories.tsx index d2c074d32..dd8142b68 100644 --- a/packages/taler-wallet-webextension/src/popup/Balance.stories.tsx +++ b/packages/taler-wallet-webextension/src/popup/Balance.stories.tsx @@ -19,7 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { ScopeType } from "@gnu-taler/taler-util"; +import { AmountString, ScopeType } from "@gnu-taler/taler-util"; import * as tests from "@gnu-taler/web-util/testing"; import { BalanceView as TestedComponent } from "./BalancePage.js"; @@ -35,10 +35,10 @@ export const EmptyBalance = tests.createExample(TestedComponent, { export const SomeCoins = tests.createExample(TestedComponent, { balances: [ { - available: "USD:10.5", + available: "USD:10.5" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -54,10 +54,10 @@ export const SomeCoins = tests.createExample(TestedComponent, { export const SomeCoinsInTreeCurrencies = tests.createExample(TestedComponent, { balances: [ { - available: "EUR:1", + available: "EUR:1" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -66,10 +66,10 @@ export const SomeCoinsInTreeCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "TESTKUDOS:2000", + available: "TESTKUDOS:2000" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -78,10 +78,10 @@ export const SomeCoinsInTreeCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "JPY:4", + available: "JPY:4" as AmountString, hasPendingTransactions: false, - pendingIncoming: "EUR:15", - pendingOutgoing: "EUR:0", + pendingIncoming: "EUR:15" as AmountString, + pendingOutgoing: "EUR:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -97,10 +97,10 @@ export const SomeCoinsInTreeCurrencies = tests.createExample(TestedComponent, { export const NoCoinsInTreeCurrencies = tests.createExample(TestedComponent, { balances: [ { - available: "EUR:3", + available: "EUR:3" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -109,10 +109,10 @@ export const NoCoinsInTreeCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "USD:2", + available: "USD:2" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -121,10 +121,10 @@ export const NoCoinsInTreeCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "ARS:1", + available: "ARS:1" as AmountString, hasPendingTransactions: false, - pendingIncoming: "EUR:15", - pendingOutgoing: "EUR:0", + pendingIncoming: "EUR:15" as AmountString, + pendingOutgoing: "EUR:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -140,10 +140,10 @@ export const NoCoinsInTreeCurrencies = tests.createExample(TestedComponent, { export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { balances: [ { - available: "USD:0", + available: "USD:0" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -152,10 +152,10 @@ export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "ARS:13451", + available: "ARS:13451" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -164,10 +164,10 @@ export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "EUR:202.02", + available: "EUR:202.02" as AmountString, hasPendingTransactions: false, - pendingIncoming: "EUR:0", - pendingOutgoing: "EUR:0", + pendingIncoming: "EUR:0" as AmountString, + pendingOutgoing: "EUR:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -176,10 +176,10 @@ export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "JPY:0", + available: "JPY:0" as AmountString, hasPendingTransactions: false, - pendingIncoming: "EUR:0", - pendingOutgoing: "EUR:0", + pendingIncoming: "EUR:0" as AmountString, + pendingOutgoing: "EUR:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -188,10 +188,10 @@ export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "JPY:51223233", + available: "JPY:51223233" as AmountString, hasPendingTransactions: false, - pendingIncoming: "EUR:0", - pendingOutgoing: "EUR:0", + pendingIncoming: "EUR:0" as AmountString, + pendingOutgoing: "EUR:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -200,10 +200,10 @@ export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "DEMOKUDOS:6", + available: "DEMOKUDOS:6" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", @@ -212,10 +212,10 @@ export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "TESTKUDOS:6", + available: "TESTKUDOS:6" as AmountString, hasPendingTransactions: false, - pendingIncoming: "USD:5", - pendingOutgoing: "USD:0", + pendingIncoming: "USD:5" as AmountString, + pendingOutgoing: "USD:0" as AmountString, requiresUserInput: false, scopeInfo: { currency: "TESTKUDOS", diff --git a/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/stories.tsx b/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/stories.tsx index 736de11f4..7ac92c6c9 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/stories.tsx @@ -21,6 +21,7 @@ import * as tests from "@gnu-taler/web-util/testing"; import { ConfirmProviderView, SelectProviderView } from "./views.js"; +import { AmountString } from "@gnu-taler/taler-util"; export default { title: "add backup provider", @@ -29,7 +30,7 @@ export default { export const DemoService = tests.createExample(ConfirmProviderView, { url: "https://sync.demo.taler.net/", provider: { - annual_fee: "KUDOS:0.1", + annual_fee: "KUDOS:0.1" as AmountString, storage_limit_in_megabytes: 20, version: "1", }, @@ -43,7 +44,7 @@ export const DemoService = tests.createExample(ConfirmProviderView, { export const FreeService = tests.createExample(ConfirmProviderView, { url: "https://sync.taler:9667/", provider: { - annual_fee: "ARS:0", + annual_fee: "ARS:0" as AmountString, storage_limit_in_megabytes: 20, version: "1", }, diff --git a/packages/taler-wallet-webextension/src/wallet/Application.tsx b/packages/taler-wallet-webextension/src/wallet/Application.tsx index 18291a25a..4c4ba1855 100644 --- a/packages/taler-wallet-webextension/src/wallet/Application.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Application.tsx @@ -21,6 +21,7 @@ */ import { + Amounts, TalerUri, TranslatedString, stringifyTalerUri, @@ -426,7 +427,7 @@ export function Application(): VNode { }) => ( redirectTo(Pages.balance)} onSuccess={(tid: string) => @@ -441,7 +442,7 @@ export function Application(): VNode { component={({ amount }: { amount: string }) => ( redirectTo(Pages.balance)} onSuccess={(tid: string) => redirectTo(Pages.balanceTransaction({ tid })) @@ -455,7 +456,7 @@ export function Application(): VNode { component={({ amount }: { amount: string }) => ( redirectTo(Pages.balance)} onSuccess={(tid: string) => redirectTo(Pages.balanceTransaction({ tid })) diff --git a/packages/taler-wallet-webextension/src/wallet/Backup.stories.tsx b/packages/taler-wallet-webextension/src/wallet/Backup.stories.tsx index 59bcd5ce9..ae160a30c 100644 --- a/packages/taler-wallet-webextension/src/wallet/Backup.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Backup.stories.tsx @@ -28,6 +28,7 @@ import { import * as tests from "@gnu-taler/web-util/testing"; import { AbsoluteTime, + AmountString, TalerPreciseTimestamp, TalerProtocolTimestamp, } from "@gnu-taler/taler-util"; @@ -52,7 +53,7 @@ export const LotOfProviders = tests.createExample(TestedComponent, { paidUntil: AbsoluteTime.fromMilliseconds(1656599921000), }, terms: { - annualFee: "ARS:1", + annualFee: "ARS:1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -73,7 +74,7 @@ export const LotOfProviders = tests.createExample(TestedComponent, { ), }, terms: { - annualFee: "ARS:1", + annualFee: "ARS:1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -88,7 +89,7 @@ export const LotOfProviders = tests.createExample(TestedComponent, { talerUri: "taler://", }, terms: { - annualFee: "KUDOS:0.1", + annualFee: "KUDOS:0.1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -100,10 +101,10 @@ export const LotOfProviders = tests.createExample(TestedComponent, { paymentProposalIds: [], paymentStatus: { type: ProviderPaymentType.InsufficientBalance, - amount: "KUDOS:10", + amount: "KUDOS:10" as AmountString, }, terms: { - annualFee: "KUDOS:0.1", + annualFee: "KUDOS:0.1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -116,19 +117,19 @@ export const LotOfProviders = tests.createExample(TestedComponent, { paymentStatus: { type: ProviderPaymentType.TermsChanged, newTerms: { - annualFee: "USD:2", + annualFee: "USD:2" as AmountString, storageLimitInMegabytes: 8, supportedProtocolVersion: "2", }, oldTerms: { - annualFee: "USD:1", + annualFee: "USD:1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "1", }, paidUntil: AbsoluteTime.never(), }, terms: { - annualFee: "KUDOS:0.1", + annualFee: "KUDOS:0.1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -142,7 +143,7 @@ export const LotOfProviders = tests.createExample(TestedComponent, { type: ProviderPaymentType.Unpaid, }, terms: { - annualFee: "KUDOS:0.1", + annualFee: "KUDOS:0.1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -156,7 +157,7 @@ export const LotOfProviders = tests.createExample(TestedComponent, { type: ProviderPaymentType.Unpaid, }, terms: { - annualFee: "KUDOS:0.1", + annualFee: "KUDOS:0.1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -180,7 +181,7 @@ export const OneProvider = tests.createExample(TestedComponent, { paidUntil: AbsoluteTime.fromMilliseconds(1656599921000), }, terms: { - annualFee: "ARS:1", + annualFee: "ARS:1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage/test.ts b/packages/taler-wallet-webextension/src/wallet/DepositPage/test.ts index 4d09d2549..5384fe4c5 100644 --- a/packages/taler-wallet-webextension/src/wallet/DepositPage/test.ts +++ b/packages/taler-wallet-webextension/src/wallet/DepositPage/test.ts @@ -21,6 +21,7 @@ import { Amounts, + AmountString, DepositGroupFees, parsePaytoUri, PrepareDepositResponse, @@ -38,8 +39,8 @@ import { useComponentState } from "./state.js"; const currency = "EUR"; const amount = `${currency}:0`; const withoutFee = (): PrepareDepositResponse => ({ - effectiveDepositAmount: `${currency}:5`, - totalDepositCost: `${currency}:5`, + effectiveDepositAmount: `${currency}:5` as AmountString, + totalDepositCost: `${currency}:5` as AmountString, fees: { coin: Amounts.stringify(`${currency}:0`), wire: Amounts.stringify(`${currency}:0`), @@ -48,8 +49,8 @@ const withoutFee = (): PrepareDepositResponse => ({ }); const withSomeFee = (): PrepareDepositResponse => ({ - effectiveDepositAmount: `${currency}:5`, - totalDepositCost: `${currency}:5`, + effectiveDepositAmount: `${currency}:5` as AmountString, + totalDepositCost: `${currency}:5` as AmountString, fees: { coin: Amounts.stringify(`${currency}:1`), wire: Amounts.stringify(`${currency}:1`), @@ -65,10 +66,10 @@ describe("DepositPage states", () => { handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, { balances: [ { - available: `${currency}:0`, + available: `${currency}:0` as AmountString, hasPendingTransactions: false, - pendingIncoming: `${currency}:0`, - pendingOutgoing: `${currency}:0`, + pendingIncoming: `${currency}:0` as AmountString, + pendingOutgoing: `${currency}:0` as AmountString, requiresUserInput: false, scopeInfo: { currency, @@ -111,10 +112,10 @@ describe("DepositPage states", () => { handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, { balances: [ { - available: `${currency}:1`, + available: `${currency}:1` as AmountString, hasPendingTransactions: false, - pendingIncoming: `${currency}:0`, - pendingOutgoing: `${currency}:0`, + pendingIncoming: `${currency}:0` as AmountString, + pendingOutgoing: `${currency}:0` as AmountString, requiresUserInput: false, scopeInfo: { currency, @@ -170,10 +171,10 @@ describe("DepositPage states", () => { handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, { balances: [ { - available: `${currency}:1`, + available: `${currency}:1` as AmountString, hasPendingTransactions: false, - pendingIncoming: `${currency}:0`, - pendingOutgoing: `${currency}:0`, + pendingIncoming: `${currency}:0` as AmountString, + pendingOutgoing: `${currency}:0` as AmountString, requiresUserInput: false, scopeInfo: { currency, @@ -229,10 +230,10 @@ describe("DepositPage states", () => { handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, { balances: [ { - available: `${currency}:5`, + available: `${currency}:5` as AmountString, hasPendingTransactions: false, - pendingIncoming: `${currency}:0`, - pendingOutgoing: `${currency}:0`, + pendingIncoming: `${currency}:0` as AmountString, + pendingOutgoing: `${currency}:0` as AmountString, requiresUserInput: false, scopeInfo: { currency, @@ -318,10 +319,10 @@ describe("DepositPage states", () => { handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, { balances: [ { - available: `${currency}:10`, + available: `${currency}:10` as AmountString, hasPendingTransactions: false, - pendingIncoming: `${currency}:0`, - pendingOutgoing: `${currency}:0`, + pendingIncoming: `${currency}:0` as AmountString, + pendingOutgoing: `${currency}:0` as AmountString, requiresUserInput: false, scopeInfo: { currency, diff --git a/packages/taler-wallet-webextension/src/wallet/History.stories.tsx b/packages/taler-wallet-webextension/src/wallet/History.stories.tsx index 1ddb24b02..9bf39b8ae 100644 --- a/packages/taler-wallet-webextension/src/wallet/History.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/History.stories.tsx @@ -20,6 +20,7 @@ */ import { + AmountString, PaymentStatus, RefreshReason, ScopeType, @@ -49,17 +50,17 @@ export default { let count = 0; const commonTransaction = (): TransactionCommon => - ({ - amountRaw: "USD:10", - amountEffective: "USD:9", - txState: { - major: TransactionMajorState.Done, - }, - timestamp: TalerProtocolTimestamp.fromSeconds( - new Date().getTime() / 1000 - count++ * 60 * 60 * 7, - ), - transactionId: String(count), - } as TransactionCommon); +({ + amountRaw: "USD:10", + amountEffective: "USD:9", + txState: { + major: TransactionMajorState.Done, + }, + timestamp: TalerProtocolTimestamp.fromSeconds( + new Date().getTime() / 1000 - count++ * 60 * 60 * 7, + ), + transactionId: String(count), +} as TransactionCommon); const exampleData = { withdraw: { @@ -76,7 +77,7 @@ const exampleData = { } as TransactionWithdrawal, payment: { ...commonTransaction(), - amountEffective: "USD:11", + amountEffective: "USD:11" as AmountString, type: TransactionType.Payment, posConfirmation: undefined, info: { @@ -91,8 +92,8 @@ const exampleData = { }, refunds: [], refundPending: undefined, - totalRefundEffective: "USD:0", - totalRefundRaw: "USD:0", + totalRefundEffective: "USD:0" as AmountString, + totalRefundRaw: "USD:0" as AmountString, proposalId: "1EMJJH8EP1NX3XF7733NCYS2DBEJW4Q2KA5KEB37MCQJQ8Q5HMC0", status: PaymentStatus.Accepted, refundQueryActive: false, @@ -106,8 +107,8 @@ const exampleData = { refresh: { ...commonTransaction(), type: TransactionType.Refresh, - refreshInputAmount: "USD:1", - refreshOutputAmount: "USD:0.5", + refreshInputAmount: "USD:1" as AmountString, + refreshOutputAmount: "USD:0.5" as AmountString, exchangeBaseUrl: "http://exchange.taler", refreshReason: RefreshReason.PayMerchant, } as TransactionRefresh, @@ -178,9 +179,9 @@ export const SomeBalanceWithNoTransactions = tests.createExample( transactions: [], balances: [ { - available: "TESTKUDOS:10", - pendingIncoming: "TESTKUDOS:0", - pendingOutgoing: "TESTKUDOS:0", + available: "TESTKUDOS:10" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -197,9 +198,9 @@ export const OneSimpleTransaction = tests.createExample(TestedComponent, { transactions: [exampleData.withdraw], balances: [ { - available: "USD:10", - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + available: "USD:10" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -217,9 +218,9 @@ export const TwoTransactionsAndZeroBalance = tests.createExample( transactions: [exampleData.withdraw, exampleData.deposit], balances: [ { - available: "USD:0", - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + available: "USD:0" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -243,9 +244,9 @@ export const OneTransactionPending = tests.createExample(TestedComponent, { ], balances: [ { - available: "USD:10", - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + available: "USD:10" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -277,9 +278,9 @@ export const SomeTransactions = tests.createExample(TestedComponent, { ], balances: [ { - available: "USD:10", - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + available: "USD:10" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -370,9 +371,9 @@ export const SomeTransactionsInDifferentStates = tests.createExample( ], balances: [ { - available: "USD:10", - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + available: "USD:10" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -400,9 +401,9 @@ export const SomeTransactionsWithTwoCurrencies = tests.createExample( ], balances: [ { - available: "USD:0", - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + available: "USD:0" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -412,9 +413,9 @@ export const SomeTransactionsWithTwoCurrencies = tests.createExample( }, }, { - available: "TESTKUDOS:10", - pendingIncoming: "TESTKUDOS:0", - pendingOutgoing: "TESTKUDOS:0", + available: "TESTKUDOS:10" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -431,9 +432,9 @@ export const FiveOfficialCurrencies = tests.createExample(TestedComponent, { transactions: [exampleData.withdraw], balances: [ { - available: "USD:1000", - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + available: "USD:1000" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -443,9 +444,9 @@ export const FiveOfficialCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "EUR:881", - pendingIncoming: "TESTKUDOS:0", - pendingOutgoing: "TESTKUDOS:0", + available: "EUR:881" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -455,9 +456,9 @@ export const FiveOfficialCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "COL:4043000.5", - pendingIncoming: "TESTKUDOS:0", - pendingOutgoing: "TESTKUDOS:0", + available: "COL:4043000.5" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -467,9 +468,9 @@ export const FiveOfficialCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "JPY:11564450.6", - pendingIncoming: "TESTKUDOS:0", - pendingOutgoing: "TESTKUDOS:0", + available: "JPY:11564450.6" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -479,9 +480,9 @@ export const FiveOfficialCurrencies = tests.createExample(TestedComponent, { }, }, { - available: "GBP:736", - pendingIncoming: "TESTKUDOS:0", - pendingOutgoing: "TESTKUDOS:0", + available: "GBP:736" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -499,9 +500,9 @@ export const FiveOfficialCurrenciesWithHighValue = tests.createExample( transactions: [exampleData.withdraw], balances: [ { - available: "USD:881001321230000", - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + available: "USD:881001321230000" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -511,9 +512,9 @@ export const FiveOfficialCurrenciesWithHighValue = tests.createExample( }, }, { - available: "EUR:10", - pendingIncoming: "TESTKUDOS:0", - pendingOutgoing: "TESTKUDOS:0", + available: "EUR:10" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -523,9 +524,9 @@ export const FiveOfficialCurrenciesWithHighValue = tests.createExample( }, }, { - available: "COL:443000123123000.5123123", - pendingIncoming: "TESTKUDOS:0", - pendingOutgoing: "TESTKUDOS:0", + available: "COL:443000123123000.5123123" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, hasPendingTransactions: false, scopeInfo: { currency: "Ásd", @@ -535,9 +536,9 @@ export const FiveOfficialCurrenciesWithHighValue = tests.createExample( requiresUserInput: false, }, { - available: "JPY:1564450000000.6123123", - pendingIncoming: "TESTKUDOS:0", - pendingOutgoing: "TESTKUDOS:0", + available: "JPY:1564450000000.6123123" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -547,9 +548,9 @@ export const FiveOfficialCurrenciesWithHighValue = tests.createExample( }, }, { - available: "GBP:736001231231200.23123", - pendingIncoming: "TESTKUDOS:0", - pendingOutgoing: "TESTKUDOS:0", + available: "GBP:736001231231200.23123" as AmountString, + pendingIncoming: "TESTKUDOS:0" as AmountString, + pendingOutgoing: "TESTKUDOS:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { @@ -571,9 +572,9 @@ export const PeerToPeer = tests.createExample(TestedComponent, { ], balances: [ { - available: "USD:10", - pendingIncoming: "USD:0", - pendingOutgoing: "USD:0", + available: "USD:10" as AmountString, + pendingIncoming: "USD:0" as AmountString, + pendingOutgoing: "USD:0" as AmountString, hasPendingTransactions: false, requiresUserInput: false, scopeInfo: { diff --git a/packages/taler-wallet-webextension/src/wallet/ProviderDetail.stories.tsx b/packages/taler-wallet-webextension/src/wallet/ProviderDetail.stories.tsx index fbaa0b0ea..f81a86b9d 100644 --- a/packages/taler-wallet-webextension/src/wallet/ProviderDetail.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ProviderDetail.stories.tsx @@ -21,6 +21,7 @@ import { AbsoluteTime, + AmountString, TalerPreciseTimestamp, TalerProtocolTimestamp, } from "@gnu-taler/taler-util"; @@ -53,7 +54,7 @@ export const Active = tests.createExample(TestedComponent, { paidUntil: AbsoluteTime.fromMilliseconds(1656599921000), }, terms: { - annualFee: "EUR:1", + annualFee: "EUR:1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -84,7 +85,7 @@ export const ActiveErrorSync = tests.createExample(TestedComponent, { message: "message", }, terms: { - annualFee: "EUR:1", + annualFee: "EUR:1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -111,7 +112,7 @@ export const ActiveBackupProblemUnreadable = tests.createExample( type: "backup-unreadable", }, terms: { - annualFee: "EUR:1", + annualFee: "EUR:1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -140,7 +141,7 @@ export const ActiveBackupProblemDevice = tests.createExample(TestedComponent, { backupTimestamp: AbsoluteTime.fromMilliseconds(1656599921000), }, terms: { - annualFee: "EUR:1", + annualFee: "EUR:1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -157,7 +158,7 @@ export const InactiveUnpaid = tests.createExample(TestedComponent, { type: ProviderPaymentType.Unpaid, }, terms: { - annualFee: "EUR:0.1", + annualFee: "EUR:0.1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -174,10 +175,10 @@ export const InactiveInsufficientBalance = tests.createExample( paymentProposalIds: [], paymentStatus: { type: ProviderPaymentType.InsufficientBalance, - amount: "EUR:123", + amount: "EUR:123" as AmountString, }, terms: { - annualFee: "EUR:0.1", + annualFee: "EUR:0.1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -196,7 +197,7 @@ export const InactivePending = tests.createExample(TestedComponent, { talerUri: "taler://pay/sad", }, terms: { - annualFee: "EUR:0.1", + annualFee: "EUR:0.1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, @@ -213,18 +214,18 @@ export const ActiveTermsChanged = tests.createExample(TestedComponent, { type: ProviderPaymentType.TermsChanged, paidUntil: AbsoluteTime.fromMilliseconds(1656599921000), newTerms: { - annualFee: "EUR:10", + annualFee: "EUR:10" as AmountString, storageLimitInMegabytes: 8, supportedProtocolVersion: "0.0", }, oldTerms: { - annualFee: "EUR:0.1", + annualFee: "EUR:0.1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, }, terms: { - annualFee: "EUR:0.1", + annualFee: "EUR:0.1" as AmountString, storageLimitInMegabytes: 16, supportedProtocolVersion: "0.0", }, diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx index f1ae84ed3..09f7c4dc1 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.stories.tsx @@ -21,6 +21,7 @@ import { AbsoluteTime, + AmountString, PaymentStatus, RefreshReason, TalerPreciseTimestamp, @@ -60,8 +61,8 @@ export default { const commonTransaction: TransactionCommon = { error: undefined, - amountRaw: "KUDOS:11", - amountEffective: "KUDOS:9.2", + amountRaw: "KUDOS:11" as AmountString, + amountEffective: "KUDOS:9.2" as AmountString, txState: { major: TransactionMajorState.Done, }, @@ -91,7 +92,7 @@ const exampleData = { } as TransactionWithdrawal, payment: { ...commonTransaction, - amountEffective: "KUDOS:12", + amountEffective: "KUDOS:12" as AmountString, type: TransactionType.Payment, posConfirmation: undefined, info: { @@ -113,8 +114,8 @@ const exampleData = { }, refunds: [], refundPending: undefined, - totalRefundEffective: "KUDOS:0", - totalRefundRaw: "KUDOS:0", + totalRefundEffective: "KUDOS:0" as AmountString, + totalRefundRaw: "KUDOS:0" as AmountString, proposalId: "1EMJJH8EP1NX3XF7733NCYS2DBEJW4Q2KA5KEB37MCQJQ8Q5HMC0", status: PaymentStatus.Accepted, refundQueryActive: false, @@ -131,8 +132,8 @@ const exampleData = { refresh: { ...commonTransaction, type: TransactionType.Refresh, - refreshInputAmount: "KUDOS:1", - refreshOutputAmount: "KUDOS:0.5", + refreshInputAmount: "KUDOS:1" as AmountString, + refreshOutputAmount: "KUDOS:0.5" as AmountString, exchangeBaseUrl: "http://exchange.taler", refreshReason: RefreshReason.Manual, } as TransactionRefresh, @@ -358,14 +359,14 @@ export const PaymentError = tests.createExample(TestedComponent, { export const PaymentWithRefund = tests.createExample(TestedComponent, { transaction: { ...exampleData.payment, - amountRaw: "KUDOS:12", - totalRefundEffective: "KUDOS:1", - totalRefundRaw: "KUDOS:1", + amountRaw: "KUDOS:12" as AmountString, + totalRefundEffective: "KUDOS:1" as AmountString, + totalRefundRaw: "KUDOS:1" as AmountString, refunds: [ { transactionId: "1123123", - amountRaw: "KUDOS:1", - amountEffective: "KUDOS:1", + amountRaw: "KUDOS:1" as AmountString, + amountEffective: "KUDOS:1" as AmountString, timestamp: TalerProtocolTimestamp.fromSeconds(1546546544), }, ], @@ -375,7 +376,7 @@ export const PaymentWithRefund = tests.createExample(TestedComponent, { export const PaymentWithDeliveryDate = tests.createExample(TestedComponent, { transaction: { ...exampleData.payment, - amountRaw: "KUDOS:12", + amountRaw: "KUDOS:12" as AmountString, info: { ...exampleData.payment.info, // delivery_date: { @@ -388,7 +389,7 @@ export const PaymentWithDeliveryDate = tests.createExample(TestedComponent, { export const PaymentWithDeliveryAddr = tests.createExample(TestedComponent, { transaction: { ...exampleData.payment, - amountRaw: "KUDOS:12", + amountRaw: "KUDOS:12" as AmountString, info: { ...exampleData.payment.info, // delivery_location: { @@ -404,7 +405,7 @@ export const PaymentWithDeliveryAddr = tests.createExample(TestedComponent, { export const PaymentWithDeliveryFull = tests.createExample(TestedComponent, { transaction: { ...exampleData.payment, - amountRaw: "KUDOS:12", + amountRaw: "KUDOS:12" as AmountString, info: { ...exampleData.payment.info, // delivery_date: { @@ -423,35 +424,35 @@ export const PaymentWithDeliveryFull = tests.createExample(TestedComponent, { export const PaymentWithRefundPending = tests.createExample(TestedComponent, { transaction: { ...exampleData.payment, - amountRaw: "KUDOS:12", - refundPending: "KUDOS:3", - totalRefundEffective: "KUDOS:1", - totalRefundRaw: "KUDOS:1", + amountRaw: "KUDOS:12" as AmountString, + refundPending: "KUDOS:3" as AmountString, + totalRefundEffective: "KUDOS:1" as AmountString, + totalRefundRaw: "KUDOS:1" as AmountString, }, }); export const PaymentWithFeeAndRefund = tests.createExample(TestedComponent, { transaction: { ...exampleData.payment, - amountRaw: "KUDOS:11", - totalRefundEffective: "KUDOS:1", - totalRefundRaw: "KUDOS:1", + amountRaw: "KUDOS:11" as AmountString, + totalRefundEffective: "KUDOS:1" as AmountString, + totalRefundRaw: "KUDOS:1" as AmountString, }, }); export const PaymentWithFeeAndRefundFee = tests.createExample(TestedComponent, { transaction: { ...exampleData.payment, - amountRaw: "KUDOS:11", - totalRefundEffective: "KUDOS:1", - totalRefundRaw: "KUDOS:2", + amountRaw: "KUDOS:11" as AmountString, + totalRefundEffective: "KUDOS:1" as AmountString, + totalRefundRaw: "KUDOS:2" as AmountString, }, }); export const PaymentWithoutFee = tests.createExample(TestedComponent, { transaction: { ...exampleData.payment, - amountRaw: "KUDOS:12", + amountRaw: "KUDOS:12" as AmountString, }, }); @@ -537,8 +538,8 @@ export const DepositTalerBank = tests.createExample(TestedComponent, { export const DepositBitcoin = tests.createExample(TestedComponent, { transaction: { ...exampleData.deposit, - amountRaw: "BITCOINBTC:0.0000011", - amountEffective: "BITCOINBTC:0.00000092", + amountRaw: "BITCOINBTC:0.0000011" as AmountString, + amountEffective: "BITCOINBTC:0.00000092" as AmountString, targetPaytoUri: "payto://bitcoin/bcrt1q6ps8qs6v8tkqrnru4xqqqa6rfwcx5ufpdfqht4?amount=BTC:0.1&subject=0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00", }, diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx index 3b76558ce..422695367 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx @@ -18,6 +18,7 @@ import { AbsoluteTime, AmountJson, Amounts, + AmountString, Location, MerchantInfo, NotificationType, @@ -1655,7 +1656,7 @@ function RefundDetails({ amount }: { amount: AmountWithFee }): VNode { type AmountAmountByWireTransferByWire = { id: string; - amount: string; + amount: AmountString; }[]; function calculateAmountByWireTransfer( -- cgit v1.2.3
p{i} - + {/* */}