From a994009d2f094c4d9c12da68dac3abb28bdef4b3 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 16 Nov 2021 13:59:53 -0300 Subject: reserveCreated new design --- .../src/wallet/ManualWithdrawPage.tsx | 55 +++++++++++----------- 1 file changed, 27 insertions(+), 28 deletions(-) (limited to 'packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx') diff --git a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx index 102978f9e..1af4e8d8d 100644 --- a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx @@ -26,44 +26,31 @@ import { import { ReserveCreated } from "./ReserveCreated.js"; import { route } from "preact-router"; import { Pages } from "../NavigationBar.js"; +import { useAsyncAsHook } from "../hooks/useAsyncAsHook"; -interface Props {} - -export function ManualWithdrawPage({}: Props): VNode { +export function ManualWithdrawPage(): VNode { const [success, setSuccess] = useState< - AcceptManualWithdrawalResult | undefined + | { + response: AcceptManualWithdrawalResult; + exchangeBaseUrl: string; + amount: AmountJson; + } + | undefined >(undefined); - const [currency, setCurrency] = useState(undefined); const [error, setError] = useState(undefined); - async function onExchangeChange(exchange: string | undefined): Promise { - if (!exchange) return; - try { - const r = await fetch(`${exchange}/keys`); - const j = await r.json(); - if (j.currency) { - await wxApi.addExchange({ - exchangeBaseUrl: `${exchange}/`, - forceUpdate: true, - }); - setCurrency(j.currency); - } - } catch (e) { - setError("The exchange url seems invalid"); - setCurrency(undefined); - } - } + const knownExchangesHook = useAsyncAsHook(() => wxApi.listExchanges()); async function doCreate( exchangeBaseUrl: string, amount: AmountJson, ): Promise { try { - const resp = await wxApi.acceptManualWithdrawal( + const response = await wxApi.acceptManualWithdrawal( exchangeBaseUrl, Amounts.stringify(amount), ); - setSuccess(resp); + setSuccess({ exchangeBaseUrl, response, amount }); } catch (e) { if (e instanceof Error) { setError(e.message); @@ -77,8 +64,10 @@ export function ManualWithdrawPage({}: Props): VNode { if (success) { return ( { route(Pages.balance); }} @@ -86,12 +75,22 @@ export function ManualWithdrawPage({}: Props): VNode { ); } + if (!knownExchangesHook || knownExchangesHook.hasError) { + return
No Known exchanges
; + } + const exchangeList = knownExchangesHook.response.exchanges.reduce( + (p, c) => ({ + ...p, + [c.exchangeBaseUrl]: c.currency, + }), + {} as Record, + ); + return ( ); } -- cgit v1.2.3