From 8eebce10bf5fe228186a6fa258be0a93c781c727 Mon Sep 17 00:00:00 2001 From: kris Date: Mon, 5 Feb 2024 11:59:38 +0500 Subject: [PATCH 1/2] app no longer crashes on non-celo network change at donate screen --- packages/app/src/hooks/useSwapRoute.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/app/src/hooks/useSwapRoute.tsx b/packages/app/src/hooks/useSwapRoute.tsx index 8da3c913..f4697dc7 100644 --- a/packages/app/src/hooks/useSwapRoute.tsx +++ b/packages/app/src/hooks/useSwapRoute.tsx @@ -1,7 +1,7 @@ import { AlphaRouter, SwapRoute, SwapType, V3Route } from '@uniswap/smart-order-router'; import { CurrencyAmount, Percent, TradeType } from '@uniswap/sdk-core'; import { useAccount, useNetwork } from 'wagmi'; -import { GDToken } from '../models/constants'; +import { GDToken, SupportedNetwork } from '../models/constants'; import { useEthersSigner } from './useEthersSigner'; import { calculateRawTotalDonation } from '../lib/calculateRawTotalDonation'; import Decimal from 'decimal.js'; @@ -37,13 +37,13 @@ export function useSwapRoute( const [route, setRoute] = useState(undefined); useEffect(() => { - if (!address || !chain?.id || !signer?.provider || tokenIn.symbol === 'G$') { + if (!address || !chain?.id || chain.id !== SupportedNetwork.CELO || !signer?.provider || tokenIn.symbol === 'G$') { setRoute(undefined); return; } const router = new AlphaRouter({ - chainId: chain.id, + chainId: chain.id as number, provider: signer.provider, }); From 62bd3158bc4c2353127c3366abe33808f6b84cf8 Mon Sep 17 00:00:00 2001 From: LewisB Date: Tue, 6 Feb 2024 01:33:11 +0800 Subject: [PATCH 2/2] fix: show unsupported network instead of None --- .../src/components/Header/ConnectedAccountDisplay.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/app/src/components/Header/ConnectedAccountDisplay.tsx b/packages/app/src/components/Header/ConnectedAccountDisplay.tsx index 9584294b..9f65613d 100644 --- a/packages/app/src/components/Header/ConnectedAccountDisplay.tsx +++ b/packages/app/src/components/Header/ConnectedAccountDisplay.tsx @@ -1,11 +1,13 @@ import { Image, StyleSheet, Text, View } from 'react-native'; +import { useEnsName, useNetwork } from 'wagmi'; + import { InterRegular } from '../../utils/webFonts'; import { formatAddress } from '../../lib/formatAddress'; -import { useEnsName, useNetwork } from 'wagmi'; import { Colors } from '../../utils/colors'; import { PlaceholderAvatar } from '../../assets'; import { useGetTokenBalance } from '../../hooks/useGetTokenBalance'; import { formatNumberWithCommas } from '../../lib/formatFiatCurrency'; +import { SupportedNetwork } from '../../models/constants'; interface ConnectedAccountDisplayProps { isDesktopResolution: boolean; @@ -17,8 +19,9 @@ export const ConnectedAccountDisplay = (props: ConnectedAccountDisplayProps) => const { chain } = useNetwork(); let chainName = chain?.name.replace(/\d+|\s/g, ''); - if (chainName !== 'Celo') { - chainName = 'None'; + console.log('chainName', { chainName, chain: chain }); + if (!(chainName && chainName.toUpperCase() in SupportedNetwork)) { + chainName = 'Unsupported Network'; } const tokenBalance = useGetTokenBalance('G$', address, chain?.id, true); @@ -33,7 +36,7 @@ export const ConnectedAccountDisplay = (props: ConnectedAccountDisplayProps) => {chainName}