diff options
author | Sebastian <sebasjm@gmail.com> | 2023-11-24 11:36:56 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-11-24 11:36:56 -0300 |
commit | 9ba6a59d18c9ab7d7690e556d7f9aedf0c370e52 (patch) | |
tree | f9b6a45cf2afd3b07c977a21241116758a1fe4c2 | |
parent | 074d5986c5ba2d0fd181046f27ba0f2ffce5840f (diff) | |
download | wallet-core-9ba6a59d18c9ab7d7690e556d7f9aedf0c370e52.tar.xz |
using monitor api
8 files changed, 64 insertions, 50 deletions
diff --git a/packages/demobank-ui/src/hooks/circuit.ts b/packages/demobank-ui/src/hooks/circuit.ts index 01c62c409..b483a5420 100644 --- a/packages/demobank-ui/src/hooks/circuit.ts +++ b/packages/demobank-ui/src/hooks/circuit.ts @@ -278,47 +278,15 @@ function getTimeframesForDate(time: Date, timeframe: TalerCorebankApi.MonitorTim export type LastMonitor = { current: TalerCoreBankResultByMethod<"getMonitor">, previous: TalerCoreBankResultByMethod<"getMonitor"> } export function useLastMonitorInfo(time: Date, timeframe: TalerCorebankApi.MonitorTimeframeParam) { const { api, config } = useBankCoreApiContext(); + const { state: credentials } = useBackendState(); + const token = credentials.status !== "loggedIn" ? undefined : credentials.token - async function fetcher() { + async function fetcher([token]: [AccessToken]) { const params = getTimeframesForDate(time, timeframe) - // const resp = await Promise.all([ - // api.getMonitor({ timeframe, which: params.current }), - // api.getMonitor({ timeframe, which: params.previous }), - // ]) - const current: TalerCoreBankResultByMethod<"getMonitor"> = { - type: "ok" as const, - body: { - type: "with-conversions" as const, - cashinCount: 1, - cashinFiatVolume: "LOCAL:2345" as AmountString, - cashinRegionalVolume: "LOCAL:2345" as AmountString, - cashoutCount: 2, - cashoutFiatVolume: "LOCAL:2345" as AmountString, - cashoutRegionalVolume: "LOCAL:2345" as AmountString, - talerInCount: 1, - talerInVolume: "LOCAL:2345" as AmountString, - talerOutCount: 2, - talerOutVolume: "LOCAL:2345" as AmountString, - } - } - - const previous: TalerCoreBankResultByMethod<"getMonitor"> = { - type: "ok" as const, - body: { - type: "with-conversions" as const, - cashinCount: 1, - cashinFiatVolume: "LOCAL:2345" as AmountString, - cashinRegionalVolume: "LOCAL:2345" as AmountString, - cashoutCount: 2, - cashoutFiatVolume: "LOCAL:2345" as AmountString, - cashoutRegionalVolume: "LOCAL:2345" as AmountString, - talerInCount: 1, - talerInVolume: "LOCAL:2345" as AmountString, - talerOutCount: 2, - talerOutVolume: "LOCAL:2345" as AmountString, - } - - } + const [current, previous] = await Promise.all([ + api.getMonitor(token, { timeframe, which: params.current }), + api.getMonitor(token, { timeframe, which: params.previous }), + ]) return { current, previous, @@ -326,7 +294,7 @@ export function useLastMonitorInfo(time: Date, timeframe: TalerCorebankApi.Monit } const { data, error } = useSWR<LastMonitor, TalerHttpError>( - config.allow_conversion || true ? ["useLastMonitorInfo"] : false, fetcher, { + !config.allow_conversion || !token ? undefined : [token, "useLastMonitorInfo"], fetcher, { refreshInterval: 0, refreshWhenHidden: false, revalidateOnFocus: false, diff --git a/packages/demobank-ui/src/pages/RegistrationPage.tsx b/packages/demobank-ui/src/pages/RegistrationPage.tsx index 9c3b21097..2de6de373 100644 --- a/packages/demobank-ui/src/pages/RegistrationPage.tsx +++ b/packages/demobank-ui/src/pages/RegistrationPage.tsx @@ -38,7 +38,7 @@ export function RegistrationPage({ onCancel: () => void; }): VNode { const { i18n } = useTranslationContext(); - const {config} = useBankCoreApiContext(); + const { config } = useBankCoreApiContext(); if (!config.allow_registrations) { return ( <p>{i18n.str`Currently, the bank is not accepting new registrations!`}</p> @@ -70,9 +70,9 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on const { i18n } = useTranslationContext(); const errors = undefinedIfEmpty({ - // name: !name - // ? i18n.str`Missing name` - // : undefined, + name: !name + ? i18n.str`Missing name` + : undefined, username: !username ? i18n.str`Missing username` : !USERNAME_REGEX.test(username) @@ -96,9 +96,9 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on : undefined, }); - async function doRegistrationAndLogin(name: string | undefined, username: string, password: string) { + async function doRegistrationAndLogin(name: string, username: string, password: string) { await handleError(async () => { - const creationResponse = await api.createAccount("" as AccessToken, { name: name ?? "", username, password }); + const creationResponse = await api.createAccount("" as AccessToken, { name, username, password }); if (creationResponse.type === "fail") { switch (creationResponse.case) { case "invalid-phone-or-email": return notify({ @@ -169,7 +169,7 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on } async function doRegistrationStep() { - if (!username || !password) return; + if (!username || !password || !name) return; await doRegistrationAndLogin(name, username, password) setUsername(undefined); setPassword(undefined); @@ -179,9 +179,10 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on async function doRandomRegistration(tries: number = 3) { const user = getRandomUsername(); - + const pass = settings.simplePasswordForRandomAccounts ? "123" : getRandomPassword(); const username = `_${user.first}-${user.second}_` + const name = `${user.first}, ${user.second}` await doRegistrationAndLogin(name, username, pass) onComplete(); } diff --git a/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx b/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx index ab5ceb8d5..3ef3f568c 100644 --- a/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx +++ b/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx @@ -56,7 +56,7 @@ export function ShowAccountDetails({ token: creds.token, username: account, }, { - cashout_address: submitAccount.cashout_payto_uri, + cashout_payto_uri: submitAccount.cashout_payto_uri, challenge_contact_data: undefinedIfEmpty({ email: submitAccount.contact_data?.email, phone: submitAccount.contact_data?.phone, diff --git a/packages/taler-util/src/http-client/types.ts b/packages/taler-util/src/http-client/types.ts index 4c8a146a6..797861998 100644 --- a/packages/taler-util/src/http-client/types.ts +++ b/packages/taler-util/src/http-client/types.ts @@ -1343,7 +1343,7 @@ export namespace TalerCorebankApi { // Payments will be sent to this bank account // when the user wants to convert the local currency // back to fiat currency outside libeufin-bank. - cashout_address?: PaytoString; + cashout_payto_uri?: PaytoString; // Legal name associated with $username. // When missing, the old name is kept. diff --git a/packages/taler-wallet-webextension/src/cta/Payment/test.ts b/packages/taler-wallet-webextension/src/cta/Payment/test.ts index 213382efc..5e009b3de 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/test.ts @@ -140,6 +140,7 @@ describe("Payment CTA states", () => { { balances: [ { + flags: [], available: "USD:5" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -200,6 +201,7 @@ describe("Payment CTA states", () => { { balances: [ { + flags: [], available: "USD:15" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -263,6 +265,7 @@ describe("Payment CTA states", () => { { balances: [ { + flags: [], available: "USD:15" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -324,6 +327,7 @@ describe("Payment CTA states", () => { { balances: [ { + flags: [], available: "USD:15" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -393,6 +397,7 @@ describe("Payment CTA states", () => { { balances: [ { + flags: [], available: "USD:15" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -481,6 +486,7 @@ describe("Payment CTA states", () => { { balances: [ { + flags: [], available: "USD:10" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -512,6 +518,7 @@ describe("Payment CTA states", () => { { balances: [ { + flags: [], available: "USD:15" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, diff --git a/packages/taler-wallet-webextension/src/popup/Balance.stories.tsx b/packages/taler-wallet-webextension/src/popup/Balance.stories.tsx index dd8142b68..626ad4977 100644 --- a/packages/taler-wallet-webextension/src/popup/Balance.stories.tsx +++ b/packages/taler-wallet-webextension/src/popup/Balance.stories.tsx @@ -35,6 +35,7 @@ export const EmptyBalance = tests.createExample(TestedComponent, { export const SomeCoins = tests.createExample(TestedComponent, { balances: [ { + flags: [], available: "USD:10.5" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -54,6 +55,7 @@ export const SomeCoins = tests.createExample(TestedComponent, { export const SomeCoinsInTreeCurrencies = tests.createExample(TestedComponent, { balances: [ { + flags: [], available: "EUR:1" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -66,6 +68,7 @@ export const SomeCoinsInTreeCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "TESTKUDOS:2000" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -78,6 +81,7 @@ export const SomeCoinsInTreeCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "JPY:4" as AmountString, hasPendingTransactions: false, pendingIncoming: "EUR:15" as AmountString, @@ -97,6 +101,7 @@ export const SomeCoinsInTreeCurrencies = tests.createExample(TestedComponent, { export const NoCoinsInTreeCurrencies = tests.createExample(TestedComponent, { balances: [ { + flags: [], available: "EUR:3" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -109,6 +114,7 @@ export const NoCoinsInTreeCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "USD:2" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -121,6 +127,7 @@ export const NoCoinsInTreeCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "ARS:1" as AmountString, hasPendingTransactions: false, pendingIncoming: "EUR:15" as AmountString, @@ -140,6 +147,7 @@ export const NoCoinsInTreeCurrencies = tests.createExample(TestedComponent, { export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { balances: [ { + flags: [], available: "USD:0" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -152,6 +160,7 @@ export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "ARS:13451" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -164,6 +173,7 @@ export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "EUR:202.02" as AmountString, hasPendingTransactions: false, pendingIncoming: "EUR:0" as AmountString, @@ -176,6 +186,7 @@ export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "JPY:0" as AmountString, hasPendingTransactions: false, pendingIncoming: "EUR:0" as AmountString, @@ -188,6 +199,7 @@ export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "JPY:51223233" as AmountString, hasPendingTransactions: false, pendingIncoming: "EUR:0" as AmountString, @@ -200,6 +212,7 @@ export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "DEMOKUDOS:6" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:0" as AmountString, @@ -212,6 +225,7 @@ export const SomeCoinsInFiveCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "TESTKUDOS:6" as AmountString, hasPendingTransactions: false, pendingIncoming: "USD:5" as AmountString, diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage/test.ts b/packages/taler-wallet-webextension/src/wallet/DepositPage/test.ts index 5384fe4c5..157cb868a 100644 --- a/packages/taler-wallet-webextension/src/wallet/DepositPage/test.ts +++ b/packages/taler-wallet-webextension/src/wallet/DepositPage/test.ts @@ -66,6 +66,7 @@ describe("DepositPage states", () => { handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, { balances: [ { + flags: [], available: `${currency}:0` as AmountString, hasPendingTransactions: false, pendingIncoming: `${currency}:0` as AmountString, @@ -112,6 +113,7 @@ describe("DepositPage states", () => { handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, { balances: [ { + flags: [], available: `${currency}:1` as AmountString, hasPendingTransactions: false, pendingIncoming: `${currency}:0` as AmountString, @@ -171,6 +173,7 @@ describe("DepositPage states", () => { handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, { balances: [ { + flags: [], available: `${currency}:1` as AmountString, hasPendingTransactions: false, pendingIncoming: `${currency}:0` as AmountString, @@ -230,6 +233,7 @@ describe("DepositPage states", () => { handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, { balances: [ { + flags: [], available: `${currency}:5` as AmountString, hasPendingTransactions: false, pendingIncoming: `${currency}:0` as AmountString, @@ -319,6 +323,7 @@ describe("DepositPage states", () => { handler.addWalletCallResponse(WalletApiOperation.GetBalances, undefined, { balances: [ { + flags: [], available: `${currency}:10` as AmountString, hasPendingTransactions: false, pendingIncoming: `${currency}:0` as AmountString, diff --git a/packages/taler-wallet-webextension/src/wallet/History.stories.tsx b/packages/taler-wallet-webextension/src/wallet/History.stories.tsx index 9bf39b8ae..8b4f64a93 100644 --- a/packages/taler-wallet-webextension/src/wallet/History.stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/History.stories.tsx @@ -180,6 +180,7 @@ export const SomeBalanceWithNoTransactions = tests.createExample( balances: [ { available: "TESTKUDOS:10" as AmountString, + flags: [], pendingIncoming: "TESTKUDOS:0" as AmountString, pendingOutgoing: "TESTKUDOS:0" as AmountString, hasPendingTransactions: false, @@ -198,6 +199,7 @@ export const OneSimpleTransaction = tests.createExample(TestedComponent, { transactions: [exampleData.withdraw], balances: [ { + flags: [], available: "USD:10" as AmountString, pendingIncoming: "USD:0" as AmountString, pendingOutgoing: "USD:0" as AmountString, @@ -218,6 +220,7 @@ export const TwoTransactionsAndZeroBalance = tests.createExample( transactions: [exampleData.withdraw, exampleData.deposit], balances: [ { + flags: [], available: "USD:0" as AmountString, pendingIncoming: "USD:0" as AmountString, pendingOutgoing: "USD:0" as AmountString, @@ -244,6 +247,7 @@ export const OneTransactionPending = tests.createExample(TestedComponent, { ], balances: [ { + flags: [], available: "USD:10" as AmountString, pendingIncoming: "USD:0" as AmountString, pendingOutgoing: "USD:0" as AmountString, @@ -278,6 +282,7 @@ export const SomeTransactions = tests.createExample(TestedComponent, { ], balances: [ { + flags: [], available: "USD:10" as AmountString, pendingIncoming: "USD:0" as AmountString, pendingOutgoing: "USD:0" as AmountString, @@ -371,6 +376,7 @@ export const SomeTransactionsInDifferentStates = tests.createExample( ], balances: [ { + flags: [], available: "USD:10" as AmountString, pendingIncoming: "USD:0" as AmountString, pendingOutgoing: "USD:0" as AmountString, @@ -401,6 +407,7 @@ export const SomeTransactionsWithTwoCurrencies = tests.createExample( ], balances: [ { + flags: [], available: "USD:0" as AmountString, pendingIncoming: "USD:0" as AmountString, pendingOutgoing: "USD:0" as AmountString, @@ -413,6 +420,7 @@ export const SomeTransactionsWithTwoCurrencies = tests.createExample( }, }, { + flags: [], available: "TESTKUDOS:10" as AmountString, pendingIncoming: "TESTKUDOS:0" as AmountString, pendingOutgoing: "TESTKUDOS:0" as AmountString, @@ -432,6 +440,7 @@ export const FiveOfficialCurrencies = tests.createExample(TestedComponent, { transactions: [exampleData.withdraw], balances: [ { + flags: [], available: "USD:1000" as AmountString, pendingIncoming: "USD:0" as AmountString, pendingOutgoing: "USD:0" as AmountString, @@ -444,6 +453,7 @@ export const FiveOfficialCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "EUR:881" as AmountString, pendingIncoming: "TESTKUDOS:0" as AmountString, pendingOutgoing: "TESTKUDOS:0" as AmountString, @@ -456,6 +466,7 @@ export const FiveOfficialCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "COL:4043000.5" as AmountString, pendingIncoming: "TESTKUDOS:0" as AmountString, pendingOutgoing: "TESTKUDOS:0" as AmountString, @@ -468,6 +479,7 @@ export const FiveOfficialCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "JPY:11564450.6" as AmountString, pendingIncoming: "TESTKUDOS:0" as AmountString, pendingOutgoing: "TESTKUDOS:0" as AmountString, @@ -480,6 +492,7 @@ export const FiveOfficialCurrencies = tests.createExample(TestedComponent, { }, }, { + flags: [], available: "GBP:736" as AmountString, pendingIncoming: "TESTKUDOS:0" as AmountString, pendingOutgoing: "TESTKUDOS:0" as AmountString, @@ -500,6 +513,7 @@ export const FiveOfficialCurrenciesWithHighValue = tests.createExample( transactions: [exampleData.withdraw], balances: [ { + flags: [], available: "USD:881001321230000" as AmountString, pendingIncoming: "USD:0" as AmountString, pendingOutgoing: "USD:0" as AmountString, @@ -512,6 +526,7 @@ export const FiveOfficialCurrenciesWithHighValue = tests.createExample( }, }, { + flags: [], available: "EUR:10" as AmountString, pendingIncoming: "TESTKUDOS:0" as AmountString, pendingOutgoing: "TESTKUDOS:0" as AmountString, @@ -524,6 +539,7 @@ export const FiveOfficialCurrenciesWithHighValue = tests.createExample( }, }, { + flags: [], available: "COL:443000123123000.5123123" as AmountString, pendingIncoming: "TESTKUDOS:0" as AmountString, pendingOutgoing: "TESTKUDOS:0" as AmountString, @@ -536,6 +552,7 @@ export const FiveOfficialCurrenciesWithHighValue = tests.createExample( requiresUserInput: false, }, { + flags: [], available: "JPY:1564450000000.6123123" as AmountString, pendingIncoming: "TESTKUDOS:0" as AmountString, pendingOutgoing: "TESTKUDOS:0" as AmountString, @@ -548,6 +565,7 @@ export const FiveOfficialCurrenciesWithHighValue = tests.createExample( }, }, { + flags: [], available: "GBP:736001231231200.23123" as AmountString, pendingIncoming: "TESTKUDOS:0" as AmountString, pendingOutgoing: "TESTKUDOS:0" as AmountString, @@ -572,6 +590,7 @@ export const PeerToPeer = tests.createExample(TestedComponent, { ], balances: [ { + flags: [], available: "USD:10" as AmountString, pendingIncoming: "USD:0" as AmountString, pendingOutgoing: "USD:0" as AmountString, |