From bc6b6d524a99f82824449d9fbb5bc9c8934d4835 Mon Sep 17 00:00:00 2001 From: Jan Komarek Date: Wed, 7 Aug 2024 10:38:50 +0200 Subject: [PATCH] refactor(suite): abstract button props in InputError, export InputErrorProps --- packages/suite/src/components/wallet/InputError.tsx | 12 ++++++++---- .../components/Outputs/components/Address/index.tsx | 6 ++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/suite/src/components/wallet/InputError.tsx b/packages/suite/src/components/wallet/InputError.tsx index 5801939b490..ff8f5518272 100644 --- a/packages/suite/src/components/wallet/InputError.tsx +++ b/packages/suite/src/components/wallet/InputError.tsx @@ -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; text: string } | { url: Url }; +type ButtonProps = { onClick: MouseEventHandler; text: string }; +type LinkProps = { url: Url }; + +export type InputErrorProps = { + button?: ButtonProps | LinkProps; message?: string; -} +}; export const InputError = ({ button, message }: InputErrorProps) => ( diff --git a/packages/suite/src/views/wallet/send/components/Outputs/components/Address/index.tsx b/packages/suite/src/views/wallet/send/components/Outputs/components/Address/index.tsx index 3c3d4bd52b7..faa69b21610 100644 --- a/packages/suite/src/views/wallet/send/components/Outputs/components/Address/index.tsx +++ b/packages/suite/src/views/wallet/send/components/Outputs/components/Address/index.tsx @@ -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; @@ -126,10 +127,7 @@ export const Address = ({ output, outputId, outputsCount }: AddressProps) => { } }, [amountInputName, composeTransaction, dispatch, inputName, setValue, symbol]); - const getValidationButtonProps = (): - | { url: (typeof URLS)[NonNullable>] } - | { onClick: () => void; text: string } - | undefined => { + const getValidationButtonProps = (): InputErrorProps['button'] => { switch (addressError?.type) { case 'deprecated': if (addressDeprecatedUrl) {