diff options
author | Sebastian <sebasjm@gmail.com> | 2021-11-15 11:18:58 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-11-15 11:18:58 -0300 |
commit | 1d4815c66c395f4fcc86c30e20f3d005e3cb9ff5 (patch) | |
tree | 99e8241a5eb5af4d752be93a460004bc0c6255aa /packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx | |
parent | 9692f589c687a2ba39a705ca4238cf123f444c61 (diff) | |
download | wallet-core-1d4815c66c395f4fcc86c30e20f3d005e3cb9ff5.tar.xz |
prettier
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx')
-rw-r--r-- | packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx | 92 |
1 files changed, 54 insertions, 38 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx index dcc0002e6..102978f9e 100644 --- a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx @@ -14,68 +14,84 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - -import { VNode } from "preact"; -import { useEffect, useRef, useState } from "preact/hooks"; +import { VNode, h } from "preact"; +import { useState } from "preact/hooks"; import { CreateManualWithdraw } from "./CreateManualWithdraw"; -import * as wxApi from '../wxApi' -import { AcceptManualWithdrawalResult, AmountJson, Amounts } from "@gnu-taler/taler-util"; +import * as wxApi from "../wxApi"; +import { + AcceptManualWithdrawalResult, + AmountJson, + Amounts, +} from "@gnu-taler/taler-util"; import { ReserveCreated } from "./ReserveCreated.js"; -import { route } from 'preact-router'; +import { route } from "preact-router"; import { Pages } from "../NavigationBar.js"; -interface Props { - -} +interface Props {} -export function ManualWithdrawPage({ }: Props): VNode { - const [success, setSuccess] = useState<AcceptManualWithdrawalResult | undefined>(undefined) - const [currency, setCurrency] = useState<string | undefined>(undefined) - const [error, setError] = useState<string | undefined>(undefined) +export function ManualWithdrawPage({}: Props): VNode { + const [success, setSuccess] = useState< + AcceptManualWithdrawalResult | undefined + >(undefined); + const [currency, setCurrency] = useState<string | undefined>(undefined); + const [error, setError] = useState<string | undefined>(undefined); - async function onExchangeChange(exchange: string | undefined) { - if (!exchange) return + async function onExchangeChange(exchange: string | undefined): Promise<void> { + if (!exchange) return; try { - const r = await fetch(`${exchange}/keys`) - const j = await r.json() + const r = await fetch(`${exchange}/keys`); + const j = await r.json(); if (j.currency) { await wxApi.addExchange({ exchangeBaseUrl: `${exchange}/`, - forceUpdate: true - }) - setCurrency(j.currency) + forceUpdate: true, + }); + setCurrency(j.currency); } } catch (e) { - setError('The exchange url seems invalid') - setCurrency(undefined) + setError("The exchange url seems invalid"); + setCurrency(undefined); } } - async function doCreate(exchangeBaseUrl: string, amount: AmountJson) { + async function doCreate( + exchangeBaseUrl: string, + amount: AmountJson, + ): Promise<void> { try { - const resp = await wxApi.acceptManualWithdrawal(exchangeBaseUrl, Amounts.stringify(amount)) - setSuccess(resp) + const resp = await wxApi.acceptManualWithdrawal( + exchangeBaseUrl, + Amounts.stringify(amount), + ); + setSuccess(resp); } catch (e) { if (e instanceof Error) { - setError(e.message) + setError(e.message); } else { - setError('unexpected error') + setError("unexpected error"); } - setSuccess(undefined) + setSuccess(undefined); } } if (success) { - return <ReserveCreated reservePub={success.reservePub} paytos={success.exchangePaytoUris} onBack={() => { - route(Pages.balance) - }}/> + return ( + <ReserveCreated + reservePub={success.reservePub} + paytos={success.exchangePaytoUris} + onBack={() => { + route(Pages.balance); + }} + /> + ); } - return <CreateManualWithdraw - error={error} currency={currency} - onCreate={doCreate} onExchangeChange={onExchangeChange} - />; + return ( + <CreateManualWithdraw + error={error} + currency={currency} + onCreate={doCreate} + onExchangeChange={onExchangeChange} + /> + ); } - - - |