From d04285dbf87eed3f9d72d0b6e6a34144b7dd323e Mon Sep 17 00:00:00 2001 From: Eugene Chybisov Date: Thu, 11 Aug 2022 14:43:16 +0100 Subject: [PATCH] feat: set wallet chain as default if config option is not provided --- .../src/pages/SelectTokenPage/ChainSelect.tsx | 14 ++++++--- .../SwapFormProvider/SwapFormProvider.tsx | 29 +++++++++++++++++-- .../WidgetProvider/WidgetProvider.tsx | 18 +++--------- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/packages/widget/src/pages/SelectTokenPage/ChainSelect.tsx b/packages/widget/src/pages/SelectTokenPage/ChainSelect.tsx index a0a8dc87f..b2aa5aa6b 100644 --- a/packages/widget/src/pages/SelectTokenPage/ChainSelect.tsx +++ b/packages/widget/src/pages/SelectTokenPage/ChainSelect.tsx @@ -21,15 +21,18 @@ import { useWidgetConfig } from '../../providers/WidgetProvider'; export const ChainSelect = ({ formType }: SwapFormTypeProps) => { const { t } = useTranslation(); - const { setValue } = useFormContext(); + const { setValue, register } = useFormContext(); const { fromChain, toChain } = useWidgetConfig(); const { chains, isLoading } = useChains(); + const chainKey = SwapFormKeyHelper.getChainKey(formType); const [chainId] = useWatch({ - name: [SwapFormKeyHelper.getChainKey(formType)], + name: [chainKey], }); + const { onChange, onBlur, name, ref } = register(chainKey); + const handleChain = (event: SelectChangeEvent) => { - setValue(SwapFormKeyHelper.getChainKey(formType), event.target.value); + onChange(event); setValue(SwapFormKeyHelper.getTokenKey(formType), ''); setValue(SwapFormKeyHelper.getAmountKey(formType), ''); setValue(SwapFormKey.TokenSearchFilter, ''); @@ -40,11 +43,14 @@ export const ChainSelect = ({ formType }: SwapFormTypeProps) => { {t(`swap.selectChain`)}