Skip to content

Commit

Permalink
refactor(suite): abstract button props in InputError, export InputErr…
Browse files Browse the repository at this point in the history
…orProps
  • Loading branch information
komret committed Aug 7, 2024
1 parent 767a7d4 commit bc6b6d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 8 additions & 4 deletions packages/suite/src/components/wallet/InputError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import styled from 'styled-components';
import { Button } from '@trezor/components';
import { LearnMoreButton } from '../suite/LearnMoreButton';
import { Url } from '@trezor/urls';
import { spacingsPx } from '@trezor/theme';

const Wrapper = styled.div`
display: flex;
align-items: center;
gap: 8px;
gap: ${spacingsPx.xs};
`;

interface InputErrorProps {
button?: { onClick: MouseEventHandler<HTMLButtonElement>; text: string } | { url: Url };
type ButtonProps = { onClick: MouseEventHandler<HTMLButtonElement>; text: string };
type LinkProps = { url: Url };

export type InputErrorProps = {
button?: ButtonProps | LinkProps;
message?: string;
}
};

export const InputError = ({ button, message }: InputErrorProps) => (
<Wrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useSendFormContext } from 'src/hooks/wallet';
import { getProtocolInfo } from 'src/utils/suite/protocol';
import { PROTOCOL_TO_NETWORK } from 'src/constants/suite/protocol';
import { InputError } from 'src/components/wallet';
import { InputErrorProps } from 'src/components/wallet/InputError';

const Container = styled.div`
position: relative;
Expand Down Expand Up @@ -126,10 +127,7 @@ export const Address = ({ output, outputId, outputsCount }: AddressProps) => {
}
}, [amountInputName, composeTransaction, dispatch, inputName, setValue, symbol]);

const getValidationButtonProps = ():
| { url: (typeof URLS)[NonNullable<ReturnType<typeof isAddressDeprecated>>] }
| { onClick: () => void; text: string }
| undefined => {
const getValidationButtonProps = (): InputErrorProps['button'] => {
switch (addressError?.type) {
case 'deprecated':
if (addressDeprecatedUrl) {
Expand Down

0 comments on commit bc6b6d5

Please sign in to comment.