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/CreateManualWithdraw.tsx | 89 +++++++++++++++------- 1 file changed, 63 insertions(+), 26 deletions(-) (limited to 'packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.tsx') diff --git a/packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.tsx b/packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.tsx index b48dcbaf2..140ac2d40 100644 --- a/packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.tsx +++ b/packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.tsx @@ -20,9 +20,10 @@ */ import { AmountJson, Amounts } from "@gnu-taler/taler-util"; -import { VNode, h } from "preact"; -import { useEffect, useRef, useState } from "preact/hooks"; +import { h, VNode } from "preact"; +import { useState } from "preact/hooks"; import { ErrorMessage } from "../components/ErrorMessage"; +import { SelectList } from "../components/SelectList"; import { ButtonPrimary, Input, @@ -33,32 +34,56 @@ import { export interface Props { error: string | undefined; - currency: string | undefined; - initialExchange?: string; initialAmount?: string; - onExchangeChange: (exchange: string) => void; + exchangeList: Record; onCreate: (exchangeBaseUrl: string, amount: AmountJson) => Promise; } export function CreateManualWithdraw({ - onExchangeChange, - initialExchange, initialAmount, + exchangeList, error, - currency, onCreate, }: Props): VNode { + const exchangeSelectList = Object.keys(exchangeList); + const currencySelectList = Object.values(exchangeList); + const exchangeMap = exchangeSelectList.reduce( + (p, c) => ({ ...p, [c]: `${c} (${exchangeList[c]})` }), + {} as Record, + ); + const currencyMap = currencySelectList.reduce( + (p, c) => ({ ...p, [c]: c }), + {} as Record, + ); + + const initialExchange = + exchangeSelectList.length > 0 ? exchangeSelectList[0] : ""; + const [exchange, setExchange] = useState(initialExchange || ""); + const [currency, setCurrency] = useState(exchangeList[initialExchange] ?? ""); + const [amount, setAmount] = useState(initialAmount || ""); const parsedAmount = Amounts.parse(`${currency}:${amount}`); - let timeout = useRef(undefined); - useEffect(() => { - if (timeout) window.clearTimeout(timeout.current); - timeout.current = window.setTimeout(async () => { - onExchangeChange(exchange); - }, 1000); - }, [exchange]); + function changeExchange(exchange: string): void { + setExchange(exchange); + setCurrency(exchangeList[exchange]); + } + + function changeCurrency(currency: string): void { + setCurrency(currency); + const found = Object.entries(exchangeList).find((e) => e[1] === currency); + + if (found) { + setExchange(found[0]); + } else { + setExchange(""); + } + } + + if (!initialExchange) { + return
There is no known exchange where to withdraw, add one
; + } return ( @@ -73,26 +98,38 @@ export function CreateManualWithdraw({ withdraw the coins

- - - + + + + setExchange(e.currentTarget.value)} + onChange={changeExchange} /> - http://exchange.taler:8081 + {/*

+ + Add new exchange + +

*/} {currency && (
-
{currency}
+ {currency} setAmount(e.currentTarget.value)} + onInput={(e) => setAmount(e.currentTarget.value)} />
@@ -105,7 +142,7 @@ export function CreateManualWithdraw({ disabled={!parsedAmount || !exchange} onClick={() => onCreate(exchange, parsedAmount!)} > - Create + Start withdrawal
-- cgit v1.2.3