min 0 for amount

This commit is contained in:
Sebastian 2022-11-04 15:38:58 -03:00
parent 8af72c6036
commit cd6321d303
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
3 changed files with 22 additions and 9 deletions

View File

@ -40,6 +40,7 @@ export interface Props {
minRows?: number;
multiline?: boolean;
onChange?: (s: string) => void;
min?: string;
placeholder?: string;
required?: boolean;

View File

@ -283,6 +283,11 @@ export function DestinationSelectionGetCash({
const [currency, setCurrency] = useState(parsedInitialAmount?.currency);
const [amount, setAmount] = useState(parsedInitialAmountValue);
function positiveSetAmount(e: string):void {
const value = Number.parseInt(e, 10);
if (value < 0) return
setAmount(String(value))
}
const { i18n } = useTranslationContext();
const previous1: Contact[] = [];
const previous2: Contact[] = [
@ -324,6 +329,7 @@ export function DestinationSelectionGetCash({
<TextField
label="Amount"
type="number"
min="0"
variant="filled"
error={invalid}
required
@ -425,6 +431,11 @@ export function DestinationSelectionSendCash({
const currency = parsedInitialAmount?.currency;
const [amount, setAmount] = useState(parsedInitialAmountValue);
function positiveSetAmount(e: string):void {
const value = Number.parseInt(e, 10);
if (value < 0) return
setAmount(String(value))
}
const { i18n } = useTranslationContext();
const previous1: Contact[] = [];
const previous2: Contact[] = [
@ -466,6 +477,7 @@ export function DestinationSelectionSendCash({
<TextField
label="Amount"
type="number"
min="0"
variant="filled"
required
error={invalid}
@ -474,7 +486,7 @@ export function DestinationSelectionSendCash({
}
value={amount}
onChange={(e) => {
setAmount(e);
positiveSetAmount(e);
}}
/>
</div>

View File

@ -19,6 +19,7 @@ import { styled } from "@linaria/react";
import { Fragment, h, VNode } from "preact";
import { useState } from "preact/hooks";
import { Amount } from "../../components/Amount.js";
import { ErrorMessage } from "../../components/ErrorMessage.js";
import { LoadingError } from "../../components/LoadingError.js";
import { SelectList } from "../../components/SelectList.js";
import { Input, SvgIcon } from "../../components/styled/index.js";
@ -156,17 +157,16 @@ export function NoExchangesView({
const { i18n } = useTranslationContext();
if (!currency) {
return (
<div>
<i18n.Translate>could not find any exchange</i18n.Translate>
</div>
<ErrorMessage
title={<i18n.Translate>Could not find any exchange</i18n.Translate>}
/>
);
}
return (
<div>
<i18n.Translate>
could not find any exchange for the currency {currency}
</i18n.Translate>
</div>
<ErrorMessage
title={<i18n.Translate>Could not find any exchange for the currency {currency}</i18n.Translate>}
/>
);
}