From e8f438aea1ae9ea5d3df7b2e98d5a6872b16a6fd Mon Sep 17 00:00:00 2001 From: denviljclarke <60730266+denviljclarke@users.noreply.github.com> Date: Mon, 4 Sep 2023 06:04:16 -0500 Subject: [PATCH 01/10] feat: update config and token select logic for MU03 --- src/components/input/TokenSelectField.tsx | 12 +--- src/config/exchanges.ts | 50 ++++++++++++++++- src/config/tokens.ts | 55 ++++++++++++++++++- src/features/swap/SwapForm.tsx | 67 ++++++++++++++++------- 4 files changed, 151 insertions(+), 33 deletions(-) diff --git a/src/components/input/TokenSelectField.tsx b/src/components/input/TokenSelectField.tsx index dcaba80..c02f7cd 100644 --- a/src/components/input/TokenSelectField.tsx +++ b/src/components/input/TokenSelectField.tsx @@ -1,15 +1,14 @@ import { useField } from 'formik' -import { useMemo } from 'react' import { ChevronIcon } from 'src/components/Chevron' import { Select } from 'src/components/input/Select' -import { TokenId, getTokenById, getTokenOptionsByChainId } from 'src/config/tokens' +import { TokenId, getTokenById } from 'src/config/tokens' import { TokenIcon } from 'src/images/tokens/TokenIcon' -import { useNetwork } from 'wagmi' type Props = { name: string label: string onChange?: (optionValue: string) => void + tokenOptions: TokenId[] } const DEFAULT_VALUE = { @@ -17,14 +16,9 @@ const DEFAULT_VALUE = { value: '', } -export function TokenSelectField({ name, label, onChange }: Props) { +export function TokenSelectField({ name, label, onChange, tokenOptions }: Props) { const [field, , helpers] = useField(name) - const { chain } = useNetwork() - const tokenOptions = useMemo(() => { - return chain ? getTokenOptionsByChainId(chain.id) : Object.values(TokenId) - }, [chain]) - const handleChange = (optionValue: string) => { helpers.setValue(optionValue || '') if (onChange) onChange(optionValue) diff --git a/src/config/exchanges.ts b/src/config/exchanges.ts index 0e2df4d..0d02c5b 100644 --- a/src/config/exchanges.ts +++ b/src/config/exchanges.ts @@ -40,8 +40,31 @@ export const AlfajoresExchanges: Exchange[] = [ '0x87D61dA3d668797786D73BC674F053f87111570d', ], }, + { + providerAddr: '0x9B64E8EaBD1a035b148cE970d3319c5C3Ad53EC3', + id: '0x3e6d9109df536ba3f4c166e598bdfe132dca06573a54ca40c2b6f23ac6bd6cc6', + assets: [ + '0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F', + '0x87D61dA3d668797786D73BC674F053f87111570d', + ], + }, + { + providerAddr: '0x9B64E8EaBD1a035b148cE970d3319c5C3Ad53EC3', + id: '0xcfaa6be9334ee54fda94f2cfdf4c8bc376f24ce008ab9559b2a06b9fc388e78c', + assets: [ + '0xE4D517785D091D3c54818832dB6094bcc2744545', + '0x87D61dA3d668797786D73BC674F053f87111570d', + ], + }, + { + providerAddr: '0x9B64E8EaBD1a035b148cE970d3319c5C3Ad53EC3', + id: '0xe807b1ebe8b57ac4e5c1b8d51fcf8e3b21e919fd788bab807886c4f446a74d37', + assets: [ + '0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F', + '0x6e673502c5b55F3169657C004e5797fFE5be6653', + ], + }, ] - export const BaklavaExchanges: Exchange[] = [ { providerAddr: '0xFF9a3da00F42839CD6D33AD7adf50bCc97B41411', @@ -75,8 +98,31 @@ export const BaklavaExchanges: Exchange[] = [ '0xD4079B322c392D6b196f90AA4c439fC2C16d6770', ], }, + { + providerAddr: '0xFF9a3da00F42839CD6D33AD7adf50bCc97B41411', + id: '0x3e6d9109df536ba3f4c166e598bdfe132dca06573a54ca40c2b6f23ac6bd6cc6', + assets: [ + '0xf9ecE301247aD2CE21894941830A2470f4E774ca', + '0xD4079B322c392D6b196f90AA4c439fC2C16d6770', + ], + }, + { + providerAddr: '0xFF9a3da00F42839CD6D33AD7adf50bCc97B41411', + id: '0xcfaa6be9334ee54fda94f2cfdf4c8bc376f24ce008ab9559b2a06b9fc388e78c', + assets: [ + '0x6a0EEf2bed4C30Dc2CB42fe6c5f01F80f7EF16d1', + '0xD4079B322c392D6b196f90AA4c439fC2C16d6770', + ], + }, + { + providerAddr: '0xFF9a3da00F42839CD6D33AD7adf50bCc97B41411', + id: '0xe807b1ebe8b57ac4e5c1b8d51fcf8e3b21e919fd788bab807886c4f446a74d37', + assets: [ + '0xf9ecE301247aD2CE21894941830A2470f4E774ca', + '0x6f90ac394b1F45290d3023e4Ba0203005cAF2A4B', + ], + }, ] - export const CeloExchanges: Exchange[] = [ { providerAddr: '0x22d9db95E6Ae61c104A7B6F6C78D7993B94ec901', diff --git a/src/config/tokens.ts b/src/config/tokens.ts index 19bf5c3..3f411b9 100644 --- a/src/config/tokens.ts +++ b/src/config/tokens.ts @@ -1,4 +1,5 @@ import { ChainId } from 'src/config/chains' +import { MentoExchanges } from 'src/config/exchanges' import { Color } from 'src/styles/Color' import { areAddressesEqual } from 'src/utils/addresses' @@ -20,6 +21,8 @@ export enum TokenId { cEUR = 'cEUR', cREAL = 'cREAL', axlUSDC = 'axlUSDC', + axlEUROC = 'axlEUROC', + eXOF = 'eXOF', } export const NativeStableTokenIds = [TokenId.cUSD, TokenId.cEUR, TokenId.cREAL] @@ -62,12 +65,31 @@ export const axlUSDC: Token = Object.freeze({ decimals: 6, }) +// TODO: Doulbe check +export const axlEUROC: Token = Object.freeze({ + id: TokenId.axlEUROC, // TODO: Change to EUROC + symbol: TokenId.axlEUROC, // TODO: Change to EUROC + name: 'Axelar EUROC', + color: Color.usdcBlue, // TODO: Change to EUROC + decimals: 6, +}) + +export const eXOF: Token = Object.freeze({ + id: TokenId.eXOF, // TODO: Change to eXOF + symbol: TokenId.eXOF, // TODO: Change to eXOF + name: 'West African Franc', + color: Color.usdcBlue, // TODO: Change to eXOF + decimals: 6, // TODO: Change to eXOF +}) + export const Tokens: Record = { CELO, cUSD, cEUR, cREAL, axlUSDC, + axlEUROC, + eXOF, } export const TokenAddresses: Record> = Object.freeze({ @@ -77,6 +99,8 @@ export const TokenAddresses: Record> = Object. [TokenId.cEUR]: '0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F', [TokenId.cREAL]: '0xE4D517785D091D3c54818832dB6094bcc2744545', [TokenId.axlUSDC]: '0x87D61dA3d668797786D73BC674F053f87111570d', + [TokenId.axlEUROC]: '0x6e673502c5b55F3169657C004e5797fFE5be6653', + [TokenId.eXOF]: '', }, [ChainId.Baklava]: { [TokenId.CELO]: '0xdDc9bE57f553fe75752D61606B94CBD7e0264eF8', @@ -84,6 +108,8 @@ export const TokenAddresses: Record> = Object. [TokenId.cEUR]: '0xf9ecE301247aD2CE21894941830A2470f4E774ca', [TokenId.cREAL]: '0x6a0EEf2bed4C30Dc2CB42fe6c5f01F80f7EF16d1', [TokenId.axlUSDC]: '0xD4079B322c392D6b196f90AA4c439fC2C16d6770', + [TokenId.axlEUROC]: '0x6f90ac394b1F45290d3023e4Ba0203005cAF2A4B', + [TokenId.eXOF]: '', }, [ChainId.Celo]: { [TokenId.CELO]: '0x471EcE3750Da237f93B8E339c536989b8978a438', @@ -91,6 +117,8 @@ export const TokenAddresses: Record> = Object. [TokenId.cEUR]: '0xD8763CBa276a3738E6DE85b4b3bF5FDed6D6cA73', [TokenId.cREAL]: '0xe8537a3d056DA446677B9E9d6c5dB704EaAb4787', [TokenId.axlUSDC]: '0xEB466342C4d449BC9f53A865D5Cb90586f405215', + [TokenId.axlEUROC]: '', + [TokenId.eXOF]: '', }, }) @@ -106,9 +134,34 @@ export function isNativeStableToken(tokenId: string) { return NativeStableTokenIds.includes(tokenId as TokenId) } +export function isSwappable(token_1: string, token_2: string, chainId: ChainId) { + const exchanges = MentoExchanges[chainId] + + if (!exchanges) return false + + if (token_1 === token_2) return false + + return exchanges.some( + (obj) => + obj.assets.includes(getTokenAddress(token_1 as TokenId, chainId)) && + obj.assets.includes(getTokenAddress(token_2 as TokenId, chainId)) + ) +} + +export function getSwappableTokenOptions(token: string, chainId: ChainId) { + return getTokenOptionsByChainId(chainId) + .filter((tkn) => isSwappable(tkn, token, chainId)) + .filter((tkn) => token !== tkn) +} + export function getTokenOptionsByChainId(chainId: ChainId): TokenId[] { const tokensForChain = TokenAddresses[chainId] - return tokensForChain ? (Object.keys(TokenAddresses[chainId]) as TokenId[]) : [] + + return tokensForChain + ? Object.entries(tokensForChain) + .filter(([, tokenAddress]) => tokenAddress !== '') // Allows incomplete 'TokenAddresses' list i.e When tokens are not on all chains + .map(([tokenId]) => tokenId as TokenId) + : [] } export function getTokenById(id: string): Token | null { diff --git a/src/features/swap/SwapForm.tsx b/src/features/swap/SwapForm.tsx index d2b1c5e..93d05af 100644 --- a/src/features/swap/SwapForm.tsx +++ b/src/features/swap/SwapForm.tsx @@ -1,23 +1,33 @@ import { useConnectModal } from '@rainbow-me/rainbowkit' import { Form, Formik, useFormikContext } from 'formik' -import { ReactNode, SVGProps, useEffect } from 'react' +import { ReactNode, SVGProps, useEffect, useMemo } from 'react' import { toast } from 'react-toastify' import { Spinner } from 'src/components/animation/Spinner' import { Button3D } from 'src/components/buttons/3DButton' import { RadioInput } from 'src/components/input/RadioInput' import { TokenSelectField } from 'src/components/input/TokenSelectField' -import { TokenId, Tokens, isNativeStableToken, isUSDCVariant } from 'src/config/tokens' +import { + TokenId, + Tokens, + getSwappableTokenOptions, + getTokenOptionsByChainId, + isSwappable, +} from 'src/config/tokens' +import { reset as accountReset } from 'src/features/accounts/accountSlice' import { AccountBalances } from 'src/features/accounts/fetchBalances' +import { reset as blockReset } from 'src/features/blocks/blockSlice' +import { resetTokenPrices } from 'src/features/chart/tokenPriceSlice' import { useAppDispatch, useAppSelector } from 'src/features/store/hooks' import { SettingsMenu } from 'src/features/swap/SettingsMenu' -import { setFormValues } from 'src/features/swap/swapSlice' +import { setFormValues, reset as swapReset } from 'src/features/swap/swapSlice' import { SwapDirection, SwapFormValues } from 'src/features/swap/types' import { useFormValidator } from 'src/features/swap/useFormValidator' import { useSwapQuote } from 'src/features/swap/useSwapQuote' import { FloatingBox } from 'src/layout/FloatingBox' import { fromWei, fromWeiRounded, toSignificant } from 'src/utils/amount' +import { logger } from 'src/utils/logger' import { escapeRegExp, inputRegex } from 'src/utils/string' -import { useAccount } from 'wagmi' +import { useAccount, useNetwork, useSwitchNetwork } from 'wagmi' const initialValues: SwapFormValues = { fromTokenId: TokenId.CELO, @@ -79,9 +89,18 @@ function SwapForm() { function SwapFormInputs({ balances }: { balances: AccountBalances }) { const { address, isConnected } = useAccount() + const { chain } = useNetwork() + + const tokensForChain = useMemo(() => { + return chain ? getTokenOptionsByChainId(chain?.id) : Object.values(TokenId) + }, [chain]) const { values, setFieldValue } = useFormikContext() + const swappableTokenOptions = useMemo(() => { + return chain ? getSwappableTokenOptions(values.fromTokenId, chain?.id) : Object.values(TokenId) + }, [chain, values]) + const { amount, direction, fromTokenId, toTokenId } = values const { isLoading, quote, rate } = useSwapQuote(amount, direction, fromTokenId, toTokenId) @@ -90,6 +109,15 @@ function SwapFormInputs({ balances }: { balances: AccountBalances }) { setFieldValue('quote', quote) }, [quote, setFieldValue]) + useEffect(() => { + if (!isSwappable(values.fromTokenId, values.toTokenId, chain?.id) && isConnected) { + setFieldValue( + 'toTokenId', + swappableTokenOptions.length < 1 ? TokenId.cUSD : swappableTokenOptions[0] + ) + } + }, [setFieldValue, chain, values, swappableTokenOptions, isConnected]) + const roundedBalance = fromWeiRounded(balances[fromTokenId], Tokens[fromTokenId].decimals) const isRoundedBalanceGreaterThanZero = Boolean(Number.parseInt(roundedBalance) > 0) const onClickUseMax = () => { @@ -101,28 +129,19 @@ function SwapFormInputs({ balances }: { balances: AccountBalances }) { const onChangeToken = (isFromToken: boolean) => (tokenId: string) => { const targetField = isFromToken ? 'fromTokenId' : 'toTokenId' - const otherField = isFromToken ? 'toTokenId' : 'fromTokenId' - if (isUSDCVariant(tokenId)) { - setFieldValue(targetField, tokenId) - setFieldValue(otherField, TokenId.cUSD) - } else if (isNativeStableToken(tokenId)) { - setFieldValue(targetField, tokenId) - setFieldValue(otherField, TokenId.CELO) - } else { - const currentTargetTokenId = values[targetField] - const stableTokenId = isNativeStableToken(currentTargetTokenId) - ? currentTargetTokenId - : TokenId.cUSD - setFieldValue(targetField, tokenId) - setFieldValue(otherField, stableTokenId) - } + setFieldValue(targetField, tokenId) } return (
- +
{address && isConnected && isRoundedBalanceGreaterThanZero && ( @@ -146,7 +165,12 @@ function SwapFormInputs({ balances }: { balances: AccountBalances }) {
- +
@@ -198,6 +222,7 @@ function AmountField({ return ( Date: Mon, 4 Sep 2023 06:06:42 -0500 Subject: [PATCH 02/10] feat: non celo network detection --- src/features/swap/SwapForm.tsx | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/features/swap/SwapForm.tsx b/src/features/swap/SwapForm.tsx index 93d05af..a70ed4b 100644 --- a/src/features/swap/SwapForm.tsx +++ b/src/features/swap/SwapForm.tsx @@ -269,15 +269,42 @@ function SlippageRow() { function SubmitButton() { const { address, isConnected } = useAccount() + const { chain, chains } = useNetwork() + const { switchNetworkAsync } = useSwitchNetwork() const { openConnectModal } = useConnectModal() + const dispatch = useAppDispatch() + const isAccountReady = address && isConnected + const isOnCelo = chains.some((chn) => chn.id === chain.id) + + const switchToNetwork = async () => { + try { + if (!switchNetworkAsync) throw new Error('switchNetworkAsync undefined') + logger.debug('Resetting and switching to Celo') + await switchNetworkAsync(42220) + dispatch(blockReset()) + dispatch(accountReset()) + dispatch(swapReset()) + dispatch(resetTokenPrices()) + } catch (error) { + logger.error('Error updating network', error) + toast.error('Could not switch network, does wallet support switching?') + } + } const { errors, touched } = useFormikContext() const error = touched.amount && (errors.amount || errors.fromTokenId || errors.toTokenId || errors.slippage) - const text = error ? error : isAccountReady ? 'Continue' : 'Connect Wallet' + const text = error + ? error + : !isAccountReady + ? 'Connect Wallet' + : !isOnCelo + ? 'Switch to Celo Network' + : 'Continue' + const type = isAccountReady ? 'submit' : 'button' - const onClick = isAccountReady ? undefined : openConnectModal + const onClick = isAccountReady ? (isOnCelo ? undefined : switchToNetwork) : openConnectModal const showLongError = typeof error === 'string' && error?.length > 50 From beef65e5c816c1a9b4efa784c84f6f898f1b9ef2 Mon Sep 17 00:00:00 2001 From: denviljclarke <60730266+denviljclarke@users.noreply.github.com> Date: Mon, 4 Sep 2023 06:45:31 -0500 Subject: [PATCH 03/10] fix: update swap check logic --- src/config/tokens.ts | 4 ++-- src/features/swap/SwapForm.tsx | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/config/tokens.ts b/src/config/tokens.ts index 3f411b9..7302f34 100644 --- a/src/config/tokens.ts +++ b/src/config/tokens.ts @@ -134,8 +134,8 @@ export function isNativeStableToken(tokenId: string) { return NativeStableTokenIds.includes(tokenId as TokenId) } -export function isSwappable(token_1: string, token_2: string, chainId: ChainId) { - const exchanges = MentoExchanges[chainId] +export function isSwappable(token_1: string, token_2: string, chainId: number) { + const exchanges = MentoExchanges[chainId as ChainId] if (!exchanges) return false diff --git a/src/features/swap/SwapForm.tsx b/src/features/swap/SwapForm.tsx index a70ed4b..02a4761 100644 --- a/src/features/swap/SwapForm.tsx +++ b/src/features/swap/SwapForm.tsx @@ -6,6 +6,7 @@ import { Spinner } from 'src/components/animation/Spinner' import { Button3D } from 'src/components/buttons/3DButton' import { RadioInput } from 'src/components/input/RadioInput' import { TokenSelectField } from 'src/components/input/TokenSelectField' +import { ChainId } from 'src/config/chains' import { TokenId, Tokens, @@ -110,7 +111,7 @@ function SwapFormInputs({ balances }: { balances: AccountBalances }) { }, [quote, setFieldValue]) useEffect(() => { - if (!isSwappable(values.fromTokenId, values.toTokenId, chain?.id) && isConnected) { + if ( chain && isConnected && !isSwappable(values.fromTokenId, values.toTokenId, chain?.id) ) { setFieldValue( 'toTokenId', swappableTokenOptions.length < 1 ? TokenId.cUSD : swappableTokenOptions[0] From ea4ff09caa0c9bba2f06e752274b48eaf502336f Mon Sep 17 00:00:00 2001 From: denviljclarke <60730266+denviljclarke@users.noreply.github.com> Date: Mon, 4 Sep 2023 07:02:04 -0500 Subject: [PATCH 04/10] refactor: add optional chaining --- src/features/swap/SwapForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/swap/SwapForm.tsx b/src/features/swap/SwapForm.tsx index 02a4761..f4afd9d 100644 --- a/src/features/swap/SwapForm.tsx +++ b/src/features/swap/SwapForm.tsx @@ -276,7 +276,7 @@ function SubmitButton() { const dispatch = useAppDispatch() const isAccountReady = address && isConnected - const isOnCelo = chains.some((chn) => chn.id === chain.id) + const isOnCelo = chains.some((chn) => chn.id === chain?.id) const switchToNetwork = async () => { try { From 83219b84e44bc76858ba12a0cfc3e59156c22058 Mon Sep 17 00:00:00 2001 From: denviljclarke <60730266+denviljclarke@users.noreply.github.com> Date: Mon, 4 Sep 2023 07:04:48 -0500 Subject: [PATCH 05/10] refactor: remove unused variable --- src/features/swap/SwapForm.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/features/swap/SwapForm.tsx b/src/features/swap/SwapForm.tsx index f4afd9d..7609262 100644 --- a/src/features/swap/SwapForm.tsx +++ b/src/features/swap/SwapForm.tsx @@ -6,7 +6,6 @@ import { Spinner } from 'src/components/animation/Spinner' import { Button3D } from 'src/components/buttons/3DButton' import { RadioInput } from 'src/components/input/RadioInput' import { TokenSelectField } from 'src/components/input/TokenSelectField' -import { ChainId } from 'src/config/chains' import { TokenId, Tokens, @@ -111,7 +110,7 @@ function SwapFormInputs({ balances }: { balances: AccountBalances }) { }, [quote, setFieldValue]) useEffect(() => { - if ( chain && isConnected && !isSwappable(values.fromTokenId, values.toTokenId, chain?.id) ) { + if (chain && isConnected && !isSwappable(values.fromTokenId, values.toTokenId, chain?.id)) { setFieldValue( 'toTokenId', swappableTokenOptions.length < 1 ? TokenId.cUSD : swappableTokenOptions[0] From 79ed8a430fe40cc37353c8f7e216a9f3a2df54a1 Mon Sep 17 00:00:00 2001 From: denviljclarke <60730266+denviljclarke@users.noreply.github.com> Date: Tue, 5 Sep 2023 23:35:47 -0500 Subject: [PATCH 06/10] feat: remove eXOF & adjust to for testnets only --- src/config/tokens.ts | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/config/tokens.ts b/src/config/tokens.ts index 7302f34..31ac04d 100644 --- a/src/config/tokens.ts +++ b/src/config/tokens.ts @@ -22,7 +22,6 @@ export enum TokenId { cREAL = 'cREAL', axlUSDC = 'axlUSDC', axlEUROC = 'axlEUROC', - eXOF = 'eXOF', } export const NativeStableTokenIds = [TokenId.cUSD, TokenId.cEUR, TokenId.cREAL] @@ -65,23 +64,15 @@ export const axlUSDC: Token = Object.freeze({ decimals: 6, }) -// TODO: Doulbe check + export const axlEUROC: Token = Object.freeze({ - id: TokenId.axlEUROC, // TODO: Change to EUROC - symbol: TokenId.axlEUROC, // TODO: Change to EUROC + id: TokenId.axlEUROC, + symbol: TokenId.axlEUROC, name: 'Axelar EUROC', color: Color.usdcBlue, // TODO: Change to EUROC decimals: 6, }) -export const eXOF: Token = Object.freeze({ - id: TokenId.eXOF, // TODO: Change to eXOF - symbol: TokenId.eXOF, // TODO: Change to eXOF - name: 'West African Franc', - color: Color.usdcBlue, // TODO: Change to eXOF - decimals: 6, // TODO: Change to eXOF -}) - export const Tokens: Record = { CELO, cUSD, @@ -89,7 +80,6 @@ export const Tokens: Record = { cREAL, axlUSDC, axlEUROC, - eXOF, } export const TokenAddresses: Record> = Object.freeze({ @@ -100,7 +90,6 @@ export const TokenAddresses: Record> = Object. [TokenId.cREAL]: '0xE4D517785D091D3c54818832dB6094bcc2744545', [TokenId.axlUSDC]: '0x87D61dA3d668797786D73BC674F053f87111570d', [TokenId.axlEUROC]: '0x6e673502c5b55F3169657C004e5797fFE5be6653', - [TokenId.eXOF]: '', }, [ChainId.Baklava]: { [TokenId.CELO]: '0xdDc9bE57f553fe75752D61606B94CBD7e0264eF8', @@ -109,7 +98,6 @@ export const TokenAddresses: Record> = Object. [TokenId.cREAL]: '0x6a0EEf2bed4C30Dc2CB42fe6c5f01F80f7EF16d1', [TokenId.axlUSDC]: '0xD4079B322c392D6b196f90AA4c439fC2C16d6770', [TokenId.axlEUROC]: '0x6f90ac394b1F45290d3023e4Ba0203005cAF2A4B', - [TokenId.eXOF]: '', }, [ChainId.Celo]: { [TokenId.CELO]: '0x471EcE3750Da237f93B8E339c536989b8978a438', @@ -118,7 +106,6 @@ export const TokenAddresses: Record> = Object. [TokenId.cREAL]: '0xe8537a3d056DA446677B9E9d6c5dB704EaAb4787', [TokenId.axlUSDC]: '0xEB466342C4d449BC9f53A865D5Cb90586f405215', [TokenId.axlEUROC]: '', - [TokenId.eXOF]: '', }, }) From 39b122f99291a7dee4e035d85915465dd7f31b79 Mon Sep 17 00:00:00 2001 From: denviljclarke <60730266+denviljclarke@users.noreply.github.com> Date: Tue, 5 Sep 2023 23:43:11 -0500 Subject: [PATCH 07/10] style: run prettier --- src/config/tokens.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/config/tokens.ts b/src/config/tokens.ts index 31ac04d..4494838 100644 --- a/src/config/tokens.ts +++ b/src/config/tokens.ts @@ -64,7 +64,6 @@ export const axlUSDC: Token = Object.freeze({ decimals: 6, }) - export const axlEUROC: Token = Object.freeze({ id: TokenId.axlEUROC, symbol: TokenId.axlEUROC, From e9f8fb2cda0641bcdb7e15818a057c7492ed728c Mon Sep 17 00:00:00 2001 From: denviljclarke <60730266+denviljclarke@users.noreply.github.com> Date: Thu, 7 Sep 2023 21:55:39 -0500 Subject: [PATCH 08/10] refactor: improve error text logic readability --- src/features/swap/SwapForm.tsx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/features/swap/SwapForm.tsx b/src/features/swap/SwapForm.tsx index 7609262..01d6412 100644 --- a/src/features/swap/SwapForm.tsx +++ b/src/features/swap/SwapForm.tsx @@ -273,6 +273,7 @@ function SubmitButton() { const { switchNetworkAsync } = useSwitchNetwork() const { openConnectModal } = useConnectModal() const dispatch = useAppDispatch() + const { errors, touched } = useFormikContext() const isAccountReady = address && isConnected const isOnCelo = chains.some((chn) => chn.id === chain?.id) @@ -292,17 +293,20 @@ function SubmitButton() { } } - const { errors, touched } = useFormikContext() const error = touched.amount && (errors.amount || errors.fromTokenId || errors.toTokenId || errors.slippage) - const text = error - ? error - : !isAccountReady - ? 'Connect Wallet' - : !isOnCelo - ? 'Switch to Celo Network' - : 'Continue' - + let text; + + if (error) { + text = error; + } else if (!isAccountReady) { + text = 'Connect Wallet'; + } else if (!isOnCelo) { + text = 'Switch to Celo Network'; + } else { + text = 'Continue'; + } + const type = isAccountReady ? 'submit' : 'button' const onClick = isAccountReady ? (isOnCelo ? undefined : switchToNetwork) : openConnectModal From 9197438e3a92c43156448f4764449c3d807f3ceb Mon Sep 17 00:00:00 2001 From: denviljclarke <60730266+denviljclarke@users.noreply.github.com> Date: Thu, 7 Sep 2023 21:57:52 -0500 Subject: [PATCH 09/10] style: run prettier --- src/features/swap/SwapForm.tsx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/features/swap/SwapForm.tsx b/src/features/swap/SwapForm.tsx index 01d6412..d3bc873 100644 --- a/src/features/swap/SwapForm.tsx +++ b/src/features/swap/SwapForm.tsx @@ -295,18 +295,18 @@ function SubmitButton() { const error = touched.amount && (errors.amount || errors.fromTokenId || errors.toTokenId || errors.slippage) - let text; - - if (error) { - text = error; - } else if (!isAccountReady) { - text = 'Connect Wallet'; - } else if (!isOnCelo) { - text = 'Switch to Celo Network'; - } else { - text = 'Continue'; - } - + let text + + if (error) { + text = error + } else if (!isAccountReady) { + text = 'Connect Wallet' + } else if (!isOnCelo) { + text = 'Switch to Celo Network' + } else { + text = 'Continue' + } + const type = isAccountReady ? 'submit' : 'button' const onClick = isAccountReady ? (isOnCelo ? undefined : switchToNetwork) : openConnectModal From dc72fefcc758ee2d99322f5566b6bdb124cb1f9e Mon Sep 17 00:00:00 2001 From: denviljclarke <60730266+denviljclarke@users.noreply.github.com> Date: Thu, 7 Sep 2023 22:14:53 -0500 Subject: [PATCH 10/10] refactor: improve swap onclick assignment readability --- src/features/swap/SwapForm.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/features/swap/SwapForm.tsx b/src/features/swap/SwapForm.tsx index d3bc873..fc79914 100644 --- a/src/features/swap/SwapForm.tsx +++ b/src/features/swap/SwapForm.tsx @@ -308,7 +308,13 @@ function SubmitButton() { } const type = isAccountReady ? 'submit' : 'button' - const onClick = isAccountReady ? (isOnCelo ? undefined : switchToNetwork) : openConnectModal + let onClick + + if (!isAccountReady) { + onClick = openConnectModal + } else if (!isOnCelo) { + onClick = switchToNetwork + } const showLongError = typeof error === 'string' && error?.length > 50