diff options
Diffstat (limited to 'packages/demobank-ui/src/hooks/circuit.ts')
-rw-r--r-- | packages/demobank-ui/src/hooks/circuit.ts | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/packages/demobank-ui/src/hooks/circuit.ts b/packages/demobank-ui/src/hooks/circuit.ts index c0164d60a..01c62c409 100644 --- a/packages/demobank-ui/src/hooks/circuit.ts +++ b/packages/demobank-ui/src/hooks/circuit.ts @@ -83,7 +83,7 @@ export function useEstimator(): CashoutEstimators { } const credit = Amounts.parseOrThrow(resp.body.amount_credit); const debit = Amounts.parseOrThrow(resp.body.amount_debit); - const beforeFee = Amounts.add(credit, fee).amount; + const beforeFee = Amounts.sub(credit, fee).amount; return { debit, @@ -92,8 +92,8 @@ export function useEstimator(): CashoutEstimators { }; }, estimateByDebit: async (regionalAmount, fee) => { - const resp = await api.getConversionInfoAPI().getCashoutRate({ - debit: regionalAmount + const resp = await api.getConversionInfoAPI().getCashoutRate({ + debit: regionalAmount }); if (resp.type === "fail") { // can't happen @@ -170,7 +170,7 @@ export function useBusinessAccounts() { return undefined; } -type CashoutWithId = TalerCorebankApi.CashoutStatusResponse & { id: string } +type CashoutWithId = TalerCorebankApi.CashoutStatusResponse & { id: number } function notUndefined(c: CashoutWithId | undefined): c is CashoutWithId { return c !== undefined } @@ -182,11 +182,15 @@ export function useCashouts(account: string) { async function fetcher([username, token]: [string, AccessToken]) { const list = await api.getAccountCashouts({ username, token }) if (list.type !== "ok") { + console.error(list) return list; } const all: Array<CashoutWithId | undefined> = await Promise.all(list.body.cashouts.map(c => { return api.getCashoutById({ username, token }, c.cashout_id).then(r => { - if (r.type === "fail") return undefined + if (r.type === "fail") { + console.error("failed", r) + return undefined + } return { ...r.body, id: c.cashout_id } }) })) @@ -196,7 +200,7 @@ export function useCashouts(account: string) { } const { data, error } = useSWR<OperationOk<{ cashouts: CashoutWithId[] }> | TalerCoreBankErrorsByMethod<"getAccountCashouts">, TalerHttpError>( - !config.allow_conversion ? false : [account, token, "getAccountCashouts"], fetcher, { + !config.allow_conversion ? undefined : [account, token, "getAccountCashouts"], fetcher, { refreshInterval: 0, refreshWhenHidden: false, revalidateOnFocus: false, @@ -213,17 +217,17 @@ export function useCashouts(account: string) { return undefined; } -export function useCashoutDetails(cashoutId: string) { +export function useCashoutDetails(cashoutId: number | undefined) { const { state: credentials } = useBackendState(); const creds = credentials.status !== "loggedIn" ? undefined : credentials const { api } = useBankCoreApiContext(); - async function fetcher([username, token, id]: [string, AccessToken, string]) { + async function fetcher([username, token, id]: [string, AccessToken, number]) { return api.getCashoutById({ username, token }, id) } const { data, error } = useSWR<TalerCoreBankResultByMethod<"getCashoutById">, TalerHttpError>( - [creds?.username, creds?.token, cashoutId, "getCashoutById"], fetcher, { + cashoutId === undefined ? undefined : [creds?.username, creds?.token, cashoutId, "getCashoutById"], fetcher, { refreshInterval: 0, refreshWhenHidden: false, revalidateOnFocus: false, |