feat: log chain changed (#7350)
This commit is contained in:
parent
60593df077
commit
d4f19e42f8
@ -190,7 +190,7 @@
|
|||||||
"@sentry/types": "^7.45.0",
|
"@sentry/types": "^7.45.0",
|
||||||
"@types/react-window-infinite-loader": "^1.0.6",
|
"@types/react-window-infinite-loader": "^1.0.6",
|
||||||
"@uniswap/analytics": "^1.4.0",
|
"@uniswap/analytics": "^1.4.0",
|
||||||
"@uniswap/analytics-events": "^2.22.0",
|
"@uniswap/analytics-events": "^2.23.0",
|
||||||
"@uniswap/governance": "^1.0.2",
|
"@uniswap/governance": "^1.0.2",
|
||||||
"@uniswap/liquidity-staker": "^1.0.2",
|
"@uniswap/liquidity-staker": "^1.0.2",
|
||||||
"@uniswap/merkle-distributor": "^1.0.1",
|
"@uniswap/merkle-distributor": "^1.0.1",
|
||||||
|
45
src/components/NavBar/ChainSelectorRow.test.tsx
Normal file
45
src/components/NavBar/ChainSelectorRow.test.tsx
Normal file
@ -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(
|
||||||
|
<ChainSelectorRow targetChain={chainId} onSelectChain={jest.fn()} isPending={false} disabled={false} />
|
||||||
|
)
|
||||||
|
expect(container).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should be clickable when enabled', () => {
|
||||||
|
const onSelectChain = jest.fn()
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<ChainSelectorRow
|
||||||
|
targetChain={ChainId.OPTIMISM}
|
||||||
|
onSelectChain={onSelectChain}
|
||||||
|
isPending={false}
|
||||||
|
disabled={false}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
const button = getByTestId('Optimism-selector')
|
||||||
|
button.click()
|
||||||
|
expect(onSelectChain).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not be clickable when disabled', () => {
|
||||||
|
const onSelectChain = jest.fn()
|
||||||
|
const { getByTestId } = render(
|
||||||
|
<ChainSelectorRow
|
||||||
|
targetChain={ChainId.OPTIMISM}
|
||||||
|
onSelectChain={onSelectChain}
|
||||||
|
isPending={false}
|
||||||
|
disabled={true}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
const button = getByTestId('Optimism-selector')
|
||||||
|
button.click()
|
||||||
|
expect(onSelectChain).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
})
|
@ -1,6 +1,8 @@
|
|||||||
import { Trans } from '@lingui/macro'
|
import { Trans } from '@lingui/macro'
|
||||||
|
import { BrowserEvent, SharedEventName } from '@uniswap/analytics-events'
|
||||||
import { ChainId } from '@uniswap/sdk-core'
|
import { ChainId } from '@uniswap/sdk-core'
|
||||||
import { useWeb3React } from '@web3-react/core'
|
import { useWeb3React } from '@web3-react/core'
|
||||||
|
import { TraceEvent } from 'analytics'
|
||||||
import Loader from 'components/Icons/LoadingSpinner'
|
import Loader from 'components/Icons/LoadingSpinner'
|
||||||
import { getChainInfo } from 'constants/chainInfo'
|
import { getChainInfo } from 'constants/chainInfo'
|
||||||
import { CheckMarkIcon } from 'nft/components/icons'
|
import { CheckMarkIcon } from 'nft/components/icons'
|
||||||
@ -78,28 +80,31 @@ export default function ChainSelectorRow({ disabled, targetChain, onSelectChain,
|
|||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container
|
<TraceEvent events={[BrowserEvent.onClick]} name={SharedEventName.ELEMENT_CLICKED} element={`${label}-selector`}>
|
||||||
disabled={!!disabled}
|
<Container
|
||||||
onClick={() => {
|
data-testid={`${label}-selector`}
|
||||||
if (!disabled) onSelectChain(targetChain)
|
disabled={!!disabled}
|
||||||
}}
|
onClick={() => {
|
||||||
>
|
if (!disabled) onSelectChain(targetChain)
|
||||||
{logoUrl && <Logo src={logoUrl} alt={label} />}
|
}}
|
||||||
{label && <Label>{label}</Label>}
|
>
|
||||||
{disabled && (
|
{logoUrl && <Logo src={logoUrl} alt={label} />}
|
||||||
<CaptionText>
|
{label && <Label>{label}</Label>}
|
||||||
<Trans>Unsupported by your wallet</Trans>
|
{disabled && (
|
||||||
</CaptionText>
|
<CaptionText>
|
||||||
)}
|
<Trans>Unsupported by your wallet</Trans>
|
||||||
{isPending && (
|
</CaptionText>
|
||||||
<CaptionText>
|
)}
|
||||||
<Trans>Approve in wallet</Trans>
|
{isPending && (
|
||||||
</CaptionText>
|
<CaptionText>
|
||||||
)}
|
<Trans>Approve in wallet</Trans>
|
||||||
<Status>
|
</CaptionText>
|
||||||
{active && <CheckMarkIcon width={LOGO_SIZE} height={LOGO_SIZE} color={theme.accent1} />}
|
)}
|
||||||
{!active && isPending && <Loader width={LOGO_SIZE} height={LOGO_SIZE} />}
|
<Status>
|
||||||
</Status>
|
{active && <CheckMarkIcon width={LOGO_SIZE} height={LOGO_SIZE} color={theme.accent1} />}
|
||||||
</Container>
|
{!active && isPending && <Loader width={LOGO_SIZE} height={LOGO_SIZE} />}
|
||||||
|
</Status>
|
||||||
|
</Container>
|
||||||
|
</TraceEvent>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
1269
src/components/NavBar/__snapshots__/ChainSelectorRow.test.tsx.snap
Normal file
1269
src/components/NavBar/__snapshots__/ChainSelectorRow.test.tsx.snap
Normal file
File diff suppressed because it is too large
Load Diff
@ -13,6 +13,7 @@ import { mocked } from 'test-utils/mocked'
|
|||||||
import Web3Provider from '.'
|
import Web3Provider from '.'
|
||||||
|
|
||||||
jest.mock('analytics', () => ({
|
jest.mock('analytics', () => ({
|
||||||
|
useTrace: jest.fn(),
|
||||||
sendAnalyticsEvent: jest.fn(),
|
sendAnalyticsEvent: jest.fn(),
|
||||||
user: { set: jest.fn(), postInsert: jest.fn() },
|
user: { set: jest.fn(), postInsert: jest.fn() },
|
||||||
}))
|
}))
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { CustomUserProperties, InterfaceEventName, WalletConnectionResult } from '@uniswap/analytics-events'
|
import { CustomUserProperties, InterfaceEventName, WalletConnectionResult } from '@uniswap/analytics-events'
|
||||||
import { useWeb3React, Web3ReactHooks, Web3ReactProvider } from '@web3-react/core'
|
import { useWeb3React, Web3ReactHooks, Web3ReactProvider } from '@web3-react/core'
|
||||||
import { Connector } from '@web3-react/types'
|
import { Connector } from '@web3-react/types'
|
||||||
import { sendAnalyticsEvent, user } from 'analytics'
|
import { sendAnalyticsEvent, user, useTrace } from 'analytics'
|
||||||
import { connections, getConnection } from 'connection'
|
import { connections, getConnection } from 'connection'
|
||||||
import { isSupportedChain } from 'constants/chains'
|
import { isSupportedChain } from 'constants/chains'
|
||||||
import { RPC_PROVIDERS } from 'constants/providers'
|
import { RPC_PROVIDERS } from 'constants/providers'
|
||||||
@ -29,6 +29,7 @@ function Updater() {
|
|||||||
const { account, chainId, connector, provider } = useWeb3React()
|
const { account, chainId, connector, provider } = useWeb3React()
|
||||||
const { pathname } = useLocation()
|
const { pathname } = useLocation()
|
||||||
const currentPage = getCurrentPageFromLocation(pathname)
|
const currentPage = getCurrentPageFromLocation(pathname)
|
||||||
|
const analyticsContext = useTrace()
|
||||||
|
|
||||||
// Trace RPC calls (for debugging).
|
// Trace RPC calls (for debugging).
|
||||||
const networkProvider = isSupportedChain(chainId) ? RPC_PROVIDERS[chainId] : undefined
|
const networkProvider = isSupportedChain(chainId) ? RPC_PROVIDERS[chainId] : undefined
|
||||||
@ -44,7 +45,22 @@ function Updater() {
|
|||||||
provider?.off('debug', trace)
|
provider?.off('debug', trace)
|
||||||
networkProvider?.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.
|
// Send analytics events when the active account changes.
|
||||||
const previousAccount = usePrevious(account)
|
const previousAccount = usePrevious(account)
|
||||||
|
@ -6045,10 +6045,10 @@
|
|||||||
"@typescript-eslint/types" "5.59.1"
|
"@typescript-eslint/types" "5.59.1"
|
||||||
eslint-visitor-keys "^3.3.0"
|
eslint-visitor-keys "^3.3.0"
|
||||||
|
|
||||||
"@uniswap/analytics-events@^2.22.0":
|
"@uniswap/analytics-events@^2.23.0":
|
||||||
version "2.22.0"
|
version "2.23.0"
|
||||||
resolved "https://registry.yarnpkg.com/@uniswap/analytics-events/-/analytics-events-2.22.0.tgz#25600f5f6d9df4ea3aa7328dbc6ec44af4b652d1"
|
resolved "https://registry.yarnpkg.com/@uniswap/analytics-events/-/analytics-events-2.23.0.tgz#f1a65a9b2926700001c8512564ee5da14e0811f9"
|
||||||
integrity sha512-Q/H4JaxQuEBFZvMWW40J3m51/zUXr2FYkfO2+IA0EJfoZiWE8Yl0xWtNrO5RDc4Q57Q9z0cEzzDLN2L1RQSpJA==
|
integrity sha512-8UCAVQKSA1bKjNPZnNraYqgicQrQs1ecKfydZ7jHdhjjrLTB239MjSshHTWdnXMfqIA7y2kApKECu+3Ah9hRNg==
|
||||||
|
|
||||||
"@uniswap/analytics@^1.4.0":
|
"@uniswap/analytics@^1.4.0":
|
||||||
version "1.4.0"
|
version "1.4.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user