From 56d134e77e29c05fe286bf98e114feae6a4d6a33 Mon Sep 17 00:00:00 2001 From: Yaroslav Grachev Date: Thu, 28 Nov 2024 11:09:33 +0300 Subject: [PATCH] Feat: Currency selector (#2739) --- .../currency/CurrencyForm/ui/CurrencyForm.tsx | 70 +++++++++---------- .../shared/ui-kit/Select/Select.stories.tsx | 24 ++++++- src/renderer/shared/ui-kit/Select/Select.tsx | 19 ++++- 3 files changed, 72 insertions(+), 41 deletions(-) diff --git a/src/renderer/features/currency/CurrencyForm/ui/CurrencyForm.tsx b/src/renderer/features/currency/CurrencyForm/ui/CurrencyForm.tsx index 0ad2713bb9..f316a9d636 100644 --- a/src/renderer/features/currency/CurrencyForm/ui/CurrencyForm.tsx +++ b/src/renderer/features/currency/CurrencyForm/ui/CurrencyForm.tsx @@ -4,20 +4,18 @@ import { type FormEvent, useEffect } from 'react'; import { type CurrencyItem } from '@/shared/api/price-provider'; import { useI18n } from '@/shared/i18n'; -import { Button, FootnoteText, HelpText, Select, Switch } from '@/shared/ui'; -import { type DropdownOption } from '@/shared/ui/types'; +import { nonNullable } from '@/shared/lib/utils'; +import { Button, FootnoteText, HelpText, Switch } from '@/shared/ui'; +import { Select } from '@/shared/ui-kit'; import { type Callbacks, currencyFormModel } from '../model/currency-form'; -const getCurrencyOption = (currency: CurrencyItem): DropdownOption => ({ - id: currency.id.toString(), - value: currency, - element: [currency.code, currency.symbol, currency.name].filter(Boolean).join(' • '), -}); +const getCurrencyTitle = (currency: CurrencyItem): string => { + return [currency.code, currency.symbol, currency.name].filter(nonNullable).join(' • '); +}; type Props = Callbacks; export const CurrencyForm = ({ onSubmit }: Props) => { const { t } = useI18n(); - const isFormValid = useUnit(currencyFormModel.$isFormValid); useEffect(() => { currencyFormModel.events.callbacksChanged({ onSubmit }); @@ -32,34 +30,11 @@ export const CurrencyForm = ({ onSubmit }: Props) => { fields: { fiatFlag, currency }, } = useForm(currencyFormModel.$currencyForm); + const isFormValid = useUnit(currencyFormModel.$isFormValid); const cryptoCurrencies = useUnit(currencyFormModel.$cryptoCurrencies); const popularFiatCurrencies = useUnit(currencyFormModel.$popularFiatCurrencies); const unpopularFiatCurrencies = useUnit(currencyFormModel.$unpopularFiatCurrencies); - const currenciesOptions: DropdownOption[] = [ - { - id: 'crypto', - element: {t('settings.currency.cryptocurrenciesLabel')}, - value: {} as CurrencyItem, - disabled: true, - }, - ...cryptoCurrencies.map(getCurrencyOption), - { - id: 'popular', - element: {t('settings.currency.popularFiatLabel')}, - value: {} as CurrencyItem, - disabled: true, - }, - ...popularFiatCurrencies.map(getCurrencyOption), - { - id: 'unpopular', - element: {t('settings.currency.unpopularFiatLabel')}, - value: {} as CurrencyItem, - disabled: true, - }, - ...unpopularFiatCurrencies.map(getCurrencyOption), - ]; - const submitForm = (event: FormEvent) => { event.preventDefault(); submit(); @@ -76,11 +51,32 @@ export const CurrencyForm = ({ onSubmit }: Props) => {