diff --git a/src/components/transactions/AmountInput.tsx b/src/components/transactions/AmountInput.tsx new file mode 100644 index 0000000..5f5e3f4 --- /dev/null +++ b/src/components/transactions/AmountInput.tsx @@ -0,0 +1,100 @@ +// Copyright (c) 2020-2021 Drew Lemmy +// This file is part of KristWeb 2 under AGPL-3.0. +// Full details: https://github.com/tmpim/KristWeb2/blob/master/LICENSE.txt +import { Form, Input, InputNumber, Button } from "antd"; + +import { useTranslation } from "react-i18next"; + +import { useWallets } from "@wallets"; +import { useCurrency } from "@utils/krist"; + +import { KristSymbol } from "@comp/krist/KristSymbol"; + +interface Props { + from?: string; + setAmount: (amount: number) => void; + tabIndex?: number; +} + +export function AmountInput({ + from, + setAmount, + tabIndex, + ...props +}: Props): JSX.Element { + const { t } = useTranslation(); + + // Used to populate 'Max' + const { walletAddressMap } = useWallets(); + + // Used to format the currency prefix/suffix + const { currency_symbol } = useCurrency(); + + function onClickMax() { + if (!from) return; + const currentWallet = walletAddressMap[from]; + setAmount(currentWallet?.balance || 0); + } + + return + + {/* Prepend the Krist symbol if possible. Note that ant's InputNumber + * doesn't support addons, so this has to be done manually. */} + {(currency_symbol || "KST") === "KST" && ( + + + + )} + + {/* Amount number input */} + { + if (value < 1) + throw t("sendTransaction.errorAmountTooLow"); + + // Nothing to validate if there's no `from` field (request screen) + if (!from) return; + + const currentWallet = walletAddressMap[from]; + if (!currentWallet) return; + if (value > (currentWallet.balance || 0)) + throw t("sendTransaction.errorAmountTooHigh"); + } + }, + ]} + > + + + + {/* Currency suffix */} + + {currency_symbol || "KST"} + + + {/* Max value button */} + {from && } + + ; +} diff --git a/src/pages/transactions/request/RequestTransactionForm.tsx b/src/pages/transactions/request/RequestTransactionForm.tsx new file mode 100644 index 0000000..380923c --- /dev/null +++ b/src/pages/transactions/request/RequestTransactionForm.tsx @@ -0,0 +1,18 @@ +// Copyright (c) 2020-2021 Drew Lemmy +// This file is part of KristWeb 2 under AGPL-3.0. +// Full details: https://github.com/tmpim/KristWeb2/blob/master/LICENSE.txt +import { Form, Input } from "antd"; + +interface FormValues { + to: string; + + hasAmount: boolean; + amount?: number; + + hasMetadata: boolean; + metadata?: string; +} + +export function RequestTransactionForm(): JSX.Element { + return ; +} diff --git a/src/pages/transactions/send/AmountInput.tsx b/src/pages/transactions/send/AmountInput.tsx deleted file mode 100644 index afb1aee..0000000 --- a/src/pages/transactions/send/AmountInput.tsx +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) 2020-2021 Drew Lemmy -// This file is part of KristWeb 2 under AGPL-3.0. -// Full details: https://github.com/tmpim/KristWeb2/blob/master/LICENSE.txt -import { Form, Input, InputNumber, Button } from "antd"; - -import { useTranslation } from "react-i18next"; - -import { useWallets } from "@wallets"; -import { useCurrency } from "@utils/krist"; - -import { KristSymbol } from "@comp/krist/KristSymbol"; - -interface Props { - from: string; - setAmount: (amount: number) => void; - tabIndex?: number; -} - -export function AmountInput({ - from, - setAmount, - tabIndex, - ...props -}: Props): JSX.Element { - const { t } = useTranslation(); - - // Used to populate 'Max' - const { walletAddressMap } = useWallets(); - - // Used to format the currency prefix/suffix - const { currency_symbol } = useCurrency(); - - function onClickMax() { - const currentWallet = walletAddressMap[from]; - setAmount(currentWallet?.balance || 0); - } - - return - - {/* Prepend the Krist symbol if possible. Note that ant's InputNumber - * doesn't support addons, so this has to be done manually. */} - {(currency_symbol || "KST") === "KST" && ( - - - - )} - - {/* Amount number input */} - { - if (value < 1) - throw t("sendTransaction.errorAmountTooLow"); - - const currentWallet = walletAddressMap[from]; - if (!currentWallet) return; - if (value > (currentWallet.balance || 0)) - throw t("sendTransaction.errorAmountTooHigh"); - } - }, - ]} - > - - - - {/* Currency suffix */} - - {currency_symbol || "KST"} - - - {/* Max value button */} - - - ; -} diff --git a/src/pages/transactions/send/SendTransactionForm.tsx b/src/pages/transactions/send/SendTransactionForm.tsx index e96dc22..1436b01 100644 --- a/src/pages/transactions/send/SendTransactionForm.tsx +++ b/src/pages/transactions/send/SendTransactionForm.tsx @@ -25,7 +25,7 @@ import { useAuthFailedModal } from "@api/AuthFailed"; import { AddressPicker } from "@comp/addresses/picker/AddressPicker"; -import { AmountInput } from "./AmountInput"; +import { AmountInput } from "../../../components/transactions/AmountInput"; import { SendTransactionConfirmModalContents } from "./SendTransactionConfirmModal"; import awaitTo from "await-to-js";