diff --git a/package.json b/package.json index 63a667d83e..b61d31b030 100644 --- a/package.json +++ b/package.json @@ -190,7 +190,7 @@ "@sentry/types": "^7.45.0", "@types/react-window-infinite-loader": "^1.0.6", "@uniswap/analytics": "^1.4.0", - "@uniswap/analytics-events": "^2.22.0", + "@uniswap/analytics-events": "^2.23.0", "@uniswap/governance": "^1.0.2", "@uniswap/liquidity-staker": "^1.0.2", "@uniswap/merkle-distributor": "^1.0.1", diff --git a/src/components/NavBar/ChainSelectorRow.test.tsx b/src/components/NavBar/ChainSelectorRow.test.tsx new file mode 100644 index 0000000000..46c82d6ded --- /dev/null +++ b/src/components/NavBar/ChainSelectorRow.test.tsx @@ -0,0 +1,45 @@ +import { ChainId, SUPPORTED_CHAINS } from '@uniswap/sdk-core' +import { render } from 'test-utils/render' + +import ChainSelectorRow from './ChainSelectorRow' + +describe('ChainSelectorRow', () => { + SUPPORTED_CHAINS.forEach((chainId) => { + it(`should match snapshot for chainId ${chainId}`, () => { + const { container } = render( + + ) + expect(container).toMatchSnapshot() + }) + }) + + it('should be clickable when enabled', () => { + const onSelectChain = jest.fn() + const { getByTestId } = render( + + ) + const button = getByTestId('Optimism-selector') + button.click() + expect(onSelectChain).toHaveBeenCalled() + }) + + it('should not be clickable when disabled', () => { + const onSelectChain = jest.fn() + const { getByTestId } = render( + + ) + const button = getByTestId('Optimism-selector') + button.click() + expect(onSelectChain).not.toHaveBeenCalled() + }) +}) diff --git a/src/components/NavBar/ChainSelectorRow.tsx b/src/components/NavBar/ChainSelectorRow.tsx index 9f9fb400f3..2b14f3004a 100644 --- a/src/components/NavBar/ChainSelectorRow.tsx +++ b/src/components/NavBar/ChainSelectorRow.tsx @@ -1,6 +1,8 @@ import { Trans } from '@lingui/macro' +import { BrowserEvent, SharedEventName } from '@uniswap/analytics-events' import { ChainId } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' +import { TraceEvent } from 'analytics' import Loader from 'components/Icons/LoadingSpinner' import { getChainInfo } from 'constants/chainInfo' import { CheckMarkIcon } from 'nft/components/icons' @@ -78,28 +80,31 @@ export default function ChainSelectorRow({ disabled, targetChain, onSelectChain, const theme = useTheme() return ( - { - if (!disabled) onSelectChain(targetChain) - }} - > - {logoUrl && } - {label && } - {disabled && ( - - Unsupported by your wallet - - )} - {isPending && ( - - Approve in wallet - - )} - - {active && } - {!active && isPending && } - - + + { + if (!disabled) onSelectChain(targetChain) + }} + > + {logoUrl && } + {label && } + {disabled && ( + + Unsupported by your wallet + + )} + {isPending && ( + + Approve in wallet + + )} + + {active && } + {!active && isPending && } + + + ) } diff --git a/src/components/NavBar/__snapshots__/ChainSelectorRow.test.tsx.snap b/src/components/NavBar/__snapshots__/ChainSelectorRow.test.tsx.snap new file mode 100644 index 0000000000..df639228f6 --- /dev/null +++ b/src/components/NavBar/__snapshots__/ChainSelectorRow.test.tsx.snap @@ -0,0 +1,1269 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ChainSelectorRow should match snapshot for chainId 1 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 5 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 10 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 56 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 137 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 420 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 8453 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 42161 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 42220 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 43114 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 44787 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 80001 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 84531 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c1 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 421613 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; + +exports[`ChainSelectorRow should match snapshot for chainId 11155111 1`] = ` +.c0 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + background: none; + border: none; + border-radius: 12px; + color: #222222; + cursor: pointer; + display: grid; + grid-template-columns: min-content 1fr min-content; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + line-height: 20px; + opacity: 1; + padding: 10px 8px; + text-align: left; + -webkit-transition: 250ms ease background-color; + transition: 250ms ease background-color; + width: 240px; +} + +.c0:hover { + background-color: #22222212; +} + +.c2 { + grid-column: 2; + grid-row: 1; + font-size: 16px; + font-weight: 485; +} + +.c3 { + grid-column: 3; + grid-row: 1; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + width: 20px; +} + +.c1 { + height: 20px; + width: 20px; + margin-right: 12px; +} + +@media only screen and (max-width:640px) { + .c0 { + width: 100%; + } +} + +
+ +
+`; diff --git a/src/components/Web3Provider/index.test.tsx b/src/components/Web3Provider/index.test.tsx index 2beab7df02..bfa7c400da 100644 --- a/src/components/Web3Provider/index.test.tsx +++ b/src/components/Web3Provider/index.test.tsx @@ -13,6 +13,7 @@ import { mocked } from 'test-utils/mocked' import Web3Provider from '.' jest.mock('analytics', () => ({ + useTrace: jest.fn(), sendAnalyticsEvent: jest.fn(), user: { set: jest.fn(), postInsert: jest.fn() }, })) diff --git a/src/components/Web3Provider/index.tsx b/src/components/Web3Provider/index.tsx index 231522ce06..1ec68deff5 100644 --- a/src/components/Web3Provider/index.tsx +++ b/src/components/Web3Provider/index.tsx @@ -1,7 +1,7 @@ import { CustomUserProperties, InterfaceEventName, WalletConnectionResult } from '@uniswap/analytics-events' import { useWeb3React, Web3ReactHooks, Web3ReactProvider } from '@web3-react/core' import { Connector } from '@web3-react/types' -import { sendAnalyticsEvent, user } from 'analytics' +import { sendAnalyticsEvent, user, useTrace } from 'analytics' import { connections, getConnection } from 'connection' import { isSupportedChain } from 'constants/chains' import { RPC_PROVIDERS } from 'constants/providers' @@ -29,6 +29,7 @@ function Updater() { const { account, chainId, connector, provider } = useWeb3React() const { pathname } = useLocation() const currentPage = getCurrentPageFromLocation(pathname) + const analyticsContext = useTrace() // Trace RPC calls (for debugging). const networkProvider = isSupportedChain(chainId) ? RPC_PROVIDERS[chainId] : undefined @@ -44,7 +45,22 @@ function Updater() { provider?.off('debug', trace) networkProvider?.off('debug', trace) } - }, [networkProvider, provider, shouldTrace]) + }, [analyticsContext, networkProvider, provider, shouldTrace]) + + const previousConnectedChainId = usePrevious(chainId) + useEffect(() => { + const chainChanged = previousConnectedChainId && previousConnectedChainId !== chainId + if (chainChanged) { + sendAnalyticsEvent(InterfaceEventName.CHAIN_CHANGED, { + result: WalletConnectionResult.SUCCEEDED, + wallet_address: account, + wallet_type: getConnection(connector).getName(), + chain_id: chainId, + previousConnectedChainId, + page: currentPage, + }) + } + }, [account, chainId, connector, currentPage, previousConnectedChainId]) // Send analytics events when the active account changes. const previousAccount = usePrevious(account) diff --git a/yarn.lock b/yarn.lock index 4fdbd911dc..bfd9cad34f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6045,10 +6045,10 @@ "@typescript-eslint/types" "5.59.1" eslint-visitor-keys "^3.3.0" -"@uniswap/analytics-events@^2.22.0": - version "2.22.0" - resolved "https://registry.yarnpkg.com/@uniswap/analytics-events/-/analytics-events-2.22.0.tgz#25600f5f6d9df4ea3aa7328dbc6ec44af4b652d1" - integrity sha512-Q/H4JaxQuEBFZvMWW40J3m51/zUXr2FYkfO2+IA0EJfoZiWE8Yl0xWtNrO5RDc4Q57Q9z0cEzzDLN2L1RQSpJA== +"@uniswap/analytics-events@^2.23.0": + version "2.23.0" + resolved "https://registry.yarnpkg.com/@uniswap/analytics-events/-/analytics-events-2.23.0.tgz#f1a65a9b2926700001c8512564ee5da14e0811f9" + integrity sha512-8UCAVQKSA1bKjNPZnNraYqgicQrQs1ecKfydZ7jHdhjjrLTB239MjSshHTWdnXMfqIA7y2kApKECu+3Ah9hRNg== "@uniswap/analytics@^1.4.0": version "1.4.0"