From bf1f613a4fecdb057d7b86bad0ea88c098684a15 Mon Sep 17 00:00:00 2001 From: eddie <66155195+just-toby@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:29:34 -0700 Subject: [PATCH] fix: network connector fix and lists fix (#7185) --- cypress/e2e/swap/unconnected.test.ts | 27 +++++++++++++++++++++++++++ src/hooks/useEagerlyConnect.ts | 5 +++-- src/state/lists/updater.ts | 8 +++++++- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 cypress/e2e/swap/unconnected.test.ts diff --git a/cypress/e2e/swap/unconnected.test.ts b/cypress/e2e/swap/unconnected.test.ts new file mode 100644 index 0000000000..44bfe93dfd --- /dev/null +++ b/cypress/e2e/swap/unconnected.test.ts @@ -0,0 +1,27 @@ +import { SwapEventName } from '@uniswap/analytics-events' +import { USDC_MAINNET } from 'constants/tokens' + +import { getTestSelector } from '../../utils' + +describe('Swap inputs with no wallet connected', () => { + it('can input and load a quote with no wallet connected', () => { + cy.visit(`/swap?inputCurrency=ETH&outputCurrency=${USDC_MAINNET.address}`) + + cy.get(getTestSelector('web3-status-connected')).click() + // click twice, first time to show confirmation, second to confirm + cy.get(getTestSelector('wallet-disconnect')).click() + cy.get(getTestSelector('wallet-disconnect')).should('contain', 'Disconnect') + cy.get(getTestSelector('wallet-disconnect')).click() + cy.get(getTestSelector('close-account-drawer')).click() + + // Enter amount to swap + cy.get('#swap-currency-output .token-amount-input').type('1').should('have.value', '1') + cy.get('#swap-currency-input .token-amount-input').should('not.have.value', '') + // Verify logging + cy.waitForAmplitudeEvent(SwapEventName.SWAP_QUOTE_RECEIVED).then((event: any) => { + cy.wrap(event.event_properties).should('have.property', 'quote_latency_milliseconds') + cy.wrap(event.event_properties.quote_latency_milliseconds).should('be.a', 'number') + cy.wrap(event.event_properties.quote_latency_milliseconds).should('be.gte', 0) + }) + }) +}) diff --git a/src/hooks/useEagerlyConnect.ts b/src/hooks/useEagerlyConnect.ts index 07bae94486..b7c969b5f1 100644 --- a/src/hooks/useEagerlyConnect.ts +++ b/src/hooks/useEagerlyConnect.ts @@ -24,12 +24,13 @@ export default function useEagerlyConnect() { const rehydrated = useAppSelector((state) => state._persist.rehydrated) useEffect(() => { - if (!selectedWallet) return try { - const selectedConnection = getConnection(selectedWallet) connect(gnosisSafeConnection.connector) connect(networkConnection.connector) + if (!selectedWallet) return + const selectedConnection = getConnection(selectedWallet) + if (selectedConnection) { connect(selectedConnection.connector) } diff --git a/src/state/lists/updater.ts b/src/state/lists/updater.ts index bf53bb980e..b61f93ead7 100644 --- a/src/state/lists/updater.ts +++ b/src/state/lists/updater.ts @@ -1,10 +1,11 @@ import { getVersionUpgrade, VersionUpgrade } from '@uniswap/token-lists' import { useWeb3React } from '@web3-react/core' import { DEFAULT_LIST_OF_LISTS, UNSUPPORTED_LIST_URLS } from 'constants/lists' +import TokenSafetyLookupTable from 'constants/tokenSafetyLookup' import useInterval from 'lib/hooks/useInterval' import ms from 'ms' import { useCallback, useEffect } from 'react' -import { useAppDispatch } from 'state/hooks' +import { useAppDispatch, useAppSelector } from 'state/hooks' import { useAllLists } from 'state/lists/hooks' import { useFetchListCallback } from '../../hooks/useFetchListCallback' @@ -19,6 +20,11 @@ export default function Updater(): null { // get all loaded lists, and the active urls const lists = useAllLists() + const listsState = useAppSelector((state) => state.lists) + + useEffect(() => { + TokenSafetyLookupTable.update(listsState) + }, [listsState]) const fetchList = useFetchListCallback() const fetchAllListsCallback = useCallback(() => {