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 /packages/demobank-ui/src | |
parent | 074d5986c5ba2d0fd181046f27ba0f2ffce5840f (diff) | |
download | wallet-core-9ba6a59d18c9ab7d7690e556d7f9aedf0c370e52.tar.xz |
using monitor api
Diffstat (limited to 'packages/demobank-ui/src')
-rw-r--r-- | packages/demobank-ui/src/hooks/circuit.ts | 48 | ||||
-rw-r--r-- | packages/demobank-ui/src/pages/RegistrationPage.tsx | 17 | ||||
-rw-r--r-- | packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx | 2 |
3 files changed, 18 insertions, 49 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, |