un-uglyfy, fix: 7442

This commit is contained in:
Sebastian 2022-11-07 19:29:47 -03:00
parent 0249f57b46
commit 43c7cff750
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
15 changed files with 149 additions and 107 deletions

View File

@ -45,14 +45,13 @@ export function AmountField({
return handler.value; return handler.value;
} }
return ( return (
<Fragment>
<TextField <TextField
label={label} label={label}
type="number" type="number"
min="0" min="0"
step="0.1" step="0.1"
variant="filled" variant="filled"
error={!!handler.error} error={handler.error}
required={required} required={required}
startAdornment={ startAdornment={
<div style={{ padding: "25px 12px 8px 12px" }}>{currency}</div> <div style={{ padding: "25px 12px 8px 12px" }}>{currency}</div>
@ -61,7 +60,5 @@ export function AmountField({
disabled={!handler.onInput} disabled={!handler.onInput}
onInput={positiveAmount} onInput={positiveAmount}
/> />
{handler.error && <ErrorText>{handler.error}</ErrorText>}
</Fragment>
); );
} }

View File

@ -78,7 +78,7 @@ export function ReadyView({
<TextField <TextField
label="Subject" label="Subject"
variant="filled" variant="filled"
error={!!subject.error} error={subject.error}
required required
fullWidth fullWidth
value={subject.value} value={subject.value}

View File

@ -68,7 +68,7 @@ export function ReadyView({
<TextField <TextField
label="Subject" label="Subject"
variant="filled" variant="filled"
error={!!subject.error} error={subject.error}
required required
fullWidth fullWidth
value={subject.value} value={subject.value}

View File

@ -56,13 +56,13 @@ const Input = (variant: Props["variant"]): VNode => {
value="disabled" value="disabled"
/> />
<TextField <TextField
error error={"Error"}
variant={variant} variant={variant}
label="Something" label="Something"
{...{ value, onChange }} {...{ value, onChange }}
/> />
<TextField <TextField
error error={"Error"}
disabled disabled
variant={variant} variant={variant}
label="Disabled and Error" label="Disabled and Error"

View File

@ -30,7 +30,7 @@ export interface Props {
autoFocus?: boolean; autoFocus?: boolean;
color?: Colors; color?: Colors;
disabled?: boolean; disabled?: boolean;
error?: boolean; error?: string;
fullWidth?: boolean; fullWidth?: boolean;
helperText?: VNode | string; helperText?: VNode | string;
id?: string; id?: string;
@ -85,7 +85,12 @@ export function TextField({
<FormControl {...props}> <FormControl {...props}>
{label && <InputLabel>{label}</InputLabel>} {label && <InputLabel>{label}</InputLabel>}
<Input {...props}>{children}</Input> <Input {...props}>{children}</Input>
{helperText && <FormHelperText>{helperText}</FormHelperText>} {helperText && (
<FormHelperText error={props.error}>{helperText}</FormHelperText>
)}
{props.error ? (
<FormHelperText error="true">{props.error}</FormHelperText>
) : undefined}
</FormControl> </FormControl>
); );
} }

View File

@ -22,7 +22,7 @@ import { Colors } from "../style";
export interface Props { export interface Props {
color: Colors; color: Colors;
disabled: boolean; disabled: boolean;
error: boolean; error?: string;
focused: boolean; focused: boolean;
fullWidth: boolean; fullWidth: boolean;
hiddenLabel: boolean; hiddenLabel: boolean;
@ -64,7 +64,7 @@ export const FormControlContext = createContext<FCCProps | null>(null);
export function FormControl({ export function FormControl({
color = "primary", color = "primary",
disabled = false, disabled = false,
error = false, error = undefined,
focused: visuallyFocused, focused: visuallyFocused,
fullWidth = false, fullWidth = false,
hiddenLabel = false, hiddenLabel = false,
@ -75,9 +75,9 @@ export function FormControl({
children, children,
}: Partial<Props>): VNode { }: Partial<Props>): VNode {
const [filled, setFilled] = useState(false); const [filled, setFilled] = useState(false);
const [focusedState, setFocused] = useState(false); const [focusedState, setFocused] = useState(visuallyFocused);
const focused = const focused =
visuallyFocused !== undefined && !disabled ? visuallyFocused : focusedState; focusedState !== undefined && !disabled ? focusedState : false;
const value: FCCProps = { const value: FCCProps = {
color, color,
@ -124,7 +124,7 @@ export interface FCCProps {
// setAdornedStart, // setAdornedStart,
color: Colors; color: Colors;
disabled: boolean; disabled: boolean;
error: boolean; error: string | undefined;
filled: boolean; filled: boolean;
focused: boolean; focused: boolean;
fullWidth: boolean; fullWidth: boolean;
@ -142,7 +142,7 @@ export interface FCCProps {
const defaultContextValue: FCCProps = { const defaultContextValue: FCCProps = {
color: "primary", color: "primary",
disabled: false, disabled: false,
error: false, error: undefined,
filled: false, filled: false,
focused: false, focused: false,
fullWidth: false, fullWidth: false,
@ -159,7 +159,7 @@ const defaultContextValue: FCCProps = {
function withoutUndefinedProperties(obj: any): any { function withoutUndefinedProperties(obj: any): any {
return Object.keys(obj).reduce((acc, key) => { return Object.keys(obj).reduce((acc, key) => {
const _acc: any = acc; const _acc: any = acc;
if (obj[key] !== undefined) _acc[key] = obj[key]; if (obj[key] !== undefined && obj[key] !== false) _acc[key] = obj[key];
return _acc; return _acc;
}, {}); }, {});
} }

View File

@ -43,7 +43,7 @@ const containedStyle = css`
interface Props { interface Props {
disabled?: boolean; disabled?: boolean;
error?: boolean; error?: string;
filled?: boolean; filled?: boolean;
focused?: boolean; focused?: boolean;
margin?: "dense"; margin?: "dense";

View File

@ -22,7 +22,7 @@ import { useFormControl } from "./FormControl.js";
export interface Props { export interface Props {
class?: string; class?: string;
disabled?: boolean; disabled?: boolean;
error?: boolean; error?: string;
filled?: boolean; filled?: boolean;
focused?: boolean; focused?: boolean;
required?: boolean; required?: boolean;
@ -67,9 +67,9 @@ export function FormLabel({
}); });
return ( return (
<label <label
data-focused={fcs.focused} data-focused={!fcs.focused ? undefined : true}
data-error={!fcs.error ? undefined : true} data-error={!fcs.error ? undefined : true}
data-disabled={fcs.disabled} data-disabled={!fcs.disabled ? undefined : true}
class={[_class, root, theme.typography.body1].join(" ")} class={[_class, root, theme.typography.body1].join(" ")}
{...rest} {...rest}
style={{ style={{

View File

@ -60,8 +60,8 @@ export function InputBaseRoot({
const fcs = useFormControl({}); const fcs = useFormControl({});
return ( return (
<div <div
data-disabled={disabled} data-disabled={!disabled ? undefined : true}
data-focused={focused} data-focused={!focused ? undefined : true}
data-multiline={multiline} data-multiline={multiline}
data-hasStart={!!startAdornment} data-hasStart={!!startAdornment}
data-hasEnd={!!endAdornment} data-hasEnd={!!endAdornment}
@ -116,6 +116,12 @@ const componentStyle = css`
duration: theme.transitions.duration.shorter, duration: theme.transitions.duration.shorter,
})}; })};
} }
&:not(focus)::placeholder {
opacity: 0;
}
&:focus::placeholder {
opacity: ${theme.palette.mode === "light" ? 0.42 : 0.5};
}
&:focus { &:focus {
outline: 0; outline: 0;
} }
@ -292,11 +298,11 @@ export function InputBase({
<Root {...fcs} onClick={handleClick}> <Root {...fcs} onClick={handleClick}>
<FormControlContext.Provider value={null}> <FormControlContext.Provider value={null}>
<Input <Input
aria-invalid={fcs.error} aria-invalid={fcs.error ? true : undefined}
// aria-describedby={} // aria-describedby={}
disabled={fcs.disabled} disabled={fcs.disabled ? true : undefined}
name={name} name={name}
placeholder={placeholder} placeholder={!placeholder ? undefined : placeholder}
readOnly={readOnly} readOnly={readOnly}
required={fcs.required} required={fcs.required}
rows={rows} rows={rows}

View File

@ -27,7 +27,7 @@ export interface Props {
defaultValue?: string; defaultValue?: string;
disabled?: boolean; disabled?: boolean;
disableUnderline?: boolean; disableUnderline?: boolean;
error?: boolean; error?: string;
fullWidth?: boolean; fullWidth?: boolean;
id?: string; id?: string;
margin?: "dense" | "normal" | "none"; margin?: "dense" | "normal" | "none";
@ -176,7 +176,7 @@ function Root({
return ( return (
<InputBaseRoot <InputBaseRoot
disabled={disabled} disabled={disabled}
focused={focused} focused={focused ? true : undefined}
fullWidth={fullWidth} fullWidth={fullWidth}
multiline={multiline} multiline={multiline}
error={error} error={error}

View File

@ -90,7 +90,7 @@ interface InputLabelProps {
color: Colors; color: Colors;
disableAnimation: boolean; disableAnimation: boolean;
disabled: boolean; disabled: boolean;
error: boolean; error?: string;
focused: boolean; focused: boolean;
margin: boolean; margin: boolean;
required: boolean; required: boolean;
@ -104,8 +104,8 @@ export function InputLabel(props: Partial<InputLabelProps>): VNode {
<FormLabel <FormLabel
data-form-control={!!fcs} data-form-control={!!fcs}
data-size={fcs.size} data-size={fcs.size}
data-shrink={props.shrink || fcs.filled || fcs.focused} data-shrink={props.shrink || fcs.filled || fcs.focused ? true : undefined}
data-disable-animation={props.disableAnimation} data-disable-animation={props.disableAnimation ? true : undefined}
data-variant={fcs.variant} data-variant={fcs.variant}
class={root} class={root}
{...props} {...props}

View File

@ -28,7 +28,7 @@ export interface Props {
disabled?: boolean; disabled?: boolean;
disableUnderline?: boolean; disableUnderline?: boolean;
endAdornment?: VNode; endAdornment?: VNode;
error?: boolean; error?: string;
fullWidth?: boolean; fullWidth?: boolean;
id?: string; id?: string;
margin?: "dense" | "normal" | "none"; margin?: "dense" | "normal" | "none";
@ -128,7 +128,7 @@ function Root({ fullWidth, disabled, focused, error, children }: any): VNode {
return ( return (
<InputBaseRoot <InputBaseRoot
disabled={disabled} disabled={disabled}
focused={focused} focused={focused ? true : undefined}
fullWidth={fullWidth} fullWidth={fullWidth}
error={error} error={error}
class={[rootStyle, formControlStyle, underlineStyle].join(" ")} class={[rootStyle, formControlStyle, underlineStyle].join(" ")}

View File

@ -194,8 +194,9 @@ export const AddingIbanAccount = createExample(ReadyView, {
uri: { uri: {
targetType: "iban", targetType: "iban",
iban: "ASDQWEQWE", iban: "ASDQWEQWE",
bic: "SANDBOX",
isKnown: true, isKnown: true,
targetPath: "/ASDQWEQWE", targetPath: "SANDBOX/ASDQWEQWE",
params: {}, params: {},
}, },
}, },

View File

@ -23,7 +23,6 @@ import {
import { styled } from "@linaria/react"; import { styled } from "@linaria/react";
import { Fragment, h, VNode } from "preact"; import { Fragment, h, VNode } from "preact";
import { useState } from "preact/hooks"; import { useState } from "preact/hooks";
import { ErrorMessage } from "../../components/ErrorMessage.js";
import { LoadingError } from "../../components/LoadingError.js"; import { LoadingError } from "../../components/LoadingError.js";
import { SelectList } from "../../components/SelectList.js"; import { SelectList } from "../../components/SelectList.js";
import { import {
@ -41,6 +40,7 @@ import checkIcon from "../../svg/check_24px.svg";
import warningIcon from "../../svg/warning_24px.svg"; import warningIcon from "../../svg/warning_24px.svg";
import deleteIcon from "../../svg/delete_24px.svg"; import deleteIcon from "../../svg/delete_24px.svg";
import { State } from "./index.js"; import { State } from "./index.js";
import { ErrorMessage } from "../../components/ErrorMessage.js";
type AccountType = "bitcoin" | "x-taler-bank" | "iban"; type AccountType = "bitcoin" | "x-taler-bank" | "iban";
type ComponentFormByAccountType = { type ComponentFormByAccountType = {
@ -143,9 +143,9 @@ export function ReadyView({
</p> </p>
<p> <p>
<TextField <TextField
label="Account alias" label="Alias"
variant="standard" variant="filled"
required placeholder="Easy to remember description"
fullWidth fullWidth
disabled={accountType.value === ""} disabled={accountType.value === ""}
value={alias.value} value={alias.value}
@ -201,6 +201,9 @@ function IbanTable({
<th> <th>
<i18n.Translate>Alias</i18n.Translate> <i18n.Translate>Alias</i18n.Translate>
</th> </th>
<th>
<i18n.Translate>Bank Id</i18n.Translate>
</th>
<th> <th>
<i18n.Translate>Int. Account Number</i18n.Translate> <i18n.Translate>Int. Account Number</i18n.Translate>
</th> </th>
@ -219,7 +222,8 @@ function IbanTable({
return ( return (
<tr key={account.alias}> <tr key={account.alias}>
<td>{account.alias}</td> <td>{account.alias}</td>
<td>{p.targetPath}</td> <td>{p.bic}</td>
<td>{p.iban}</td>
<td>{p.params["receiver-name"]}</td> <td>{p.params["receiver-name"]}</td>
<td class="kyc"> <td class="kyc">
{account.kyc_completed ? ( {account.kyc_completed ? (
@ -415,7 +419,7 @@ function BitcoinAddressAccount({ field }: { field: TextFieldHandler }): VNode {
variant="standard" variant="standard"
fullWidth fullWidth
value={value} value={value}
error={value !== undefined && !!errors?.value} error={value !== undefined ? errors?.value : undefined}
disabled={!field.onInput} disabled={!field.onInput}
onChange={(v) => { onChange={(v) => {
setValue(v); setValue(v);
@ -424,9 +428,6 @@ function BitcoinAddressAccount({ field }: { field: TextFieldHandler }): VNode {
} }
}} }}
/> />
{value !== undefined && errors?.value && (
<ErrorMessage title={<span>{errors?.value}</span>} />
)}
</Fragment> </Fragment>
); );
} }
@ -456,7 +457,7 @@ function TalerBankAddressAccount({
variant="standard" variant="standard"
fullWidth fullWidth
value={host} value={host}
error={host !== undefined && !!errors?.host} error={host !== undefined ? errors?.host : undefined}
disabled={!field.onInput} disabled={!field.onInput}
onChange={(v) => { onChange={(v) => {
setHost(v); setHost(v);
@ -464,77 +465,109 @@ function TalerBankAddressAccount({
field.onInput(`payto://x-taler-bank/${v}/${account}`); field.onInput(`payto://x-taler-bank/${v}/${account}`);
} }
}} }}
/>{" "} />
{host !== undefined && errors?.host && (
<ErrorMessage title={<span>{errors?.host}</span>} />
)}
<TextField <TextField
label="Bank account" label="Bank account"
variant="standard" variant="standard"
fullWidth fullWidth
disabled={!field.onInput} disabled={!field.onInput}
value={account} value={account}
error={account !== undefined && !!errors?.account} error={account !== undefined ? errors?.account : undefined}
onChange={(v) => { onChange={(v) => {
setAccount(v || ""); setAccount(v || "");
if (!errors && field.onInput) { if (!errors && field.onInput) {
field.onInput(`payto://x-taler-bank/${host}/${v}`); field.onInput(`payto://x-taler-bank/${host}/${v}`);
} }
}} }}
/>{" "} />
{account !== undefined && errors?.account && (
<ErrorMessage title={<span>{errors?.account}</span>} />
)}
</Fragment> </Fragment>
); );
} }
//Taken from libeufin and libeufin took it from the ISO20022 XSD schema
const bicRegex = /^[A-Z]{6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3})?$/;
const ibanRegex = /^[A-Z]{2}[0-9]{2}[a-zA-Z0-9]{1,30}$/;
function IbanAddressAccount({ field }: { field: TextFieldHandler }): VNode { function IbanAddressAccount({ field }: { field: TextFieldHandler }): VNode {
const { i18n } = useTranslationContext(); const { i18n } = useTranslationContext();
const [number, setNumber] = useState<string | undefined>(undefined); const [bic, setBic] = useState<string | undefined>(undefined);
const [iban, setIban] = useState<string | undefined>(undefined);
const [name, setName] = useState<string | undefined>(undefined); const [name, setName] = useState<string | undefined>(undefined);
const errors = undefinedIfEmpty({ const errors = undefinedIfEmpty({
number: !number ? i18n.str`Can't be empty` : undefined, bic: !bic
? undefined
: !bicRegex.test(bic)
? i18n.str`Invalid bic`
: undefined,
iban: !iban
? i18n.str`Can't be empty`
: !ibanRegex.test(iban)
? i18n.str`Invalid iban`
: undefined,
name: !name ? i18n.str`Can't be empty` : undefined, name: !name ? i18n.str`Can't be empty` : undefined,
}); });
function sendUpdateIfNoErrors(
bic: string | undefined,
iban: string,
name: string,
): void {
if (!errors && field.onInput) {
const path = bic === undefined ? iban : `${bic}/${iban}`;
field.onInput(
`payto://iban/${path}?receiver-name=${encodeURIComponent(name)}`,
);
}
}
return ( return (
<Fragment> <Fragment>
<p>
<TextField <TextField
label="IBAN number" label="BIC"
variant="standard" variant="filled"
placeholder="BANKID"
fullWidth fullWidth
value={number} value={bic}
error={number !== undefined && !!errors?.number} error={bic !== undefined ? errors?.bic : undefined}
disabled={!field.onInput} disabled={!field.onInput}
onChange={(v) => { onChange={(v) => {
setNumber(v); setBic(v);
if (!errors && field.onInput) { sendUpdateIfNoErrors(v, iban || "", name || "");
field.onInput(`payto://iban/${v}?receiver-name=${name}`);
}
}} }}
/> />
{number !== undefined && errors?.number && ( </p>
<ErrorMessage title={<span>{errors?.number}</span>} /> <p>
)}
<TextField <TextField
label="Account name" label="IBAN"
variant="standard" variant="filled"
placeholder="XX123456"
fullWidth fullWidth
required
value={iban}
error={iban !== undefined ? errors?.iban : undefined}
disabled={!field.onInput}
onChange={(v) => {
setIban(v);
sendUpdateIfNoErrors(bic, v, name || "");
}}
/>
</p>
<p>
<TextField
label="Receiver name"
variant="filled"
placeholder="Name of the target bank account owner"
fullWidth
required
value={name} value={name}
error={name !== undefined && !!errors?.name} error={name !== undefined ? errors?.name : undefined}
disabled={!field.onInput} disabled={!field.onInput}
onChange={(v) => { onChange={(v) => {
setName(v); setName(v);
if (!errors && field.onInput) { sendUpdateIfNoErrors(bic, iban || "", v);
field.onInput(
`payto://iban/${number}?receiver-name=${encodeURIComponent(v)}`,
);
}
}} }}
/> />
{name !== undefined && errors?.name && ( </p>
<ErrorMessage title={<span>{errors?.name}</span>} />
)}
</Fragment> </Fragment>
); );
} }

View File

@ -1343,7 +1343,7 @@ function DepositDetails({
const { i18n } = useTranslationContext(); const { i18n } = useTranslationContext();
const r = Amounts.parseOrThrow(transaction.amountRaw); const r = Amounts.parseOrThrow(transaction.amountRaw);
const e = Amounts.parseOrThrow(transaction.amountEffective); const e = Amounts.parseOrThrow(transaction.amountEffective);
const fee = Amounts.sub(r, e).amount; const fee = Amounts.sub(e, r).amount;
const maxFrac = [r, e, fee] const maxFrac = [r, e, fee]
.map((a) => Amounts.maxFractionalDigits(a)) .map((a) => Amounts.maxFractionalDigits(a))
@ -1366,7 +1366,7 @@ function DepositDetails({
<i18n.Translate>Transaction fees</i18n.Translate> <i18n.Translate>Transaction fees</i18n.Translate>
</td> </td>
<td> <td>
<Amount value={fee} negative maxFracSize={maxFrac} /> <Amount value={fee} maxFracSize={maxFrac} />
</td> </td>
</tr> </tr>
)} )}