diff options
author | Sebastian <sebasjm@gmail.com> | 2022-11-22 15:43:39 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-11-22 15:43:39 -0300 |
commit | 88618df7b870732f4f29a80686dd4f4cf20887f8 (patch) | |
tree | 07eb8deb17cbd430c3f1f6a5767980cf67ddf296 /packages/taler-wallet-webextension/src/wallet/DestinationSelection.tsx | |
parent | dc08d7d20eb805d95e7a74b1b6d5275e9e790953 (diff) |
amount field
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/DestinationSelection.tsx')
-rw-r--r-- | packages/taler-wallet-webextension/src/wallet/DestinationSelection.tsx | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection.tsx b/packages/taler-wallet-webextension/src/wallet/DestinationSelection.tsx index ba1a560ef..7e4c775e6 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection.tsx @@ -33,9 +33,7 @@ import { useTranslationContext } from "../context/translation.js"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; import { Button } from "../mui/Button.js"; import { Grid } from "../mui/Grid.js"; -import { TextFieldHandler } from "../mui/handlers.js"; import { Paper } from "../mui/Paper.js"; -import { TextField } from "../mui/TextField.js"; import { Pages } from "../NavigationBar.js"; import arrowIcon from "../svg/chevron-down.svg"; import bankIcon from "../svg/ri-bank-line.svg"; @@ -279,12 +277,13 @@ export function DestinationSelectionGetCash({ const parsedInitialAmount = !initialAmount ? undefined : Amounts.parse(initialAmount); - const parsedInitialAmountValue = !parsedInitialAmount - ? "0" - : Amounts.stringifyValue(parsedInitialAmount); + const [currency, setCurrency] = useState(parsedInitialAmount?.currency); - const [amount, setAmount] = useState(parsedInitialAmountValue); + const [amount, setAmount] = useState( + parsedInitialAmount ?? Amounts.zeroOfCurrency(currency ?? "KUDOS"), + ); + const { i18n } = useTranslationContext(); const previous1: Contact[] = []; const previous2: Contact[] = [ @@ -313,10 +312,8 @@ export function DestinationSelectionGetCash({ </div> ); } - const currencyAndAmount = `${currency}:${amount}`; - const parsedAmount = Amounts.parse(currencyAndAmount); - // const dirty = parsedInitialAmountValue !== amount; - const invalid = !parsedAmount || Amounts.isZero(parsedAmount); + const currencyAndAmount = Amounts.stringify(amount); + const invalid = Amounts.isZero(amount); return ( <Container> <h1> @@ -325,7 +322,6 @@ export function DestinationSelectionGetCash({ <Grid container columns={2} justifyContent="space-between"> <AmountField label={<i18n.Translate>Amount</i18n.Translate>} - currency={currency} required handler={{ onInput: async (s) => setAmount(s), @@ -416,12 +412,12 @@ export function DestinationSelectionSendCash({ const parsedInitialAmount = !initialAmount ? undefined : Amounts.parse(initialAmount); - const parsedInitialAmountValue = !parsedInitialAmount - ? "" - : Amounts.stringifyValue(parsedInitialAmount); + const currency = parsedInitialAmount?.currency; - const [amount, setAmount] = useState(parsedInitialAmountValue); + const [amount, setAmount] = useState( + parsedInitialAmount ?? Amounts.zeroOfCurrency(currency ?? "KUDOS"), + ); const { i18n } = useTranslationContext(); const previous1: Contact[] = []; const previous2: Contact[] = [ @@ -450,9 +446,9 @@ export function DestinationSelectionSendCash({ </div> ); } - const currencyAndAmount = `${currency}:${amount}`; - const parsedAmount = Amounts.parse(currencyAndAmount); - const invalid = !parsedAmount || Amounts.isZero(parsedAmount); + const currencyAndAmount = Amounts.stringify(amount); + //const parsedAmount = Amounts.parse(currencyAndAmount); + const invalid = Amounts.isZero(amount); return ( <Container> <h1> @@ -462,7 +458,6 @@ export function DestinationSelectionSendCash({ <div> <AmountField label={<i18n.Translate>Amount</i18n.Translate>} - currency={currency} required handler={{ onInput: async (s) => setAmount(s), |