Skip to content

Commit 41cbcef

Browse files
JFrankfurtmatteenmvm
authored
chore: merge main into explore (#3970)
* chore(deps): bump token-lists (#3929) * feat: empty to deploy 628417f (#3962) feat: empty to deploy * feat: fix metamask mobile browser connection (#3964) * fix metamask * forceActivate * remove forceActivate * unused change * feat(risk): cache risk check with ttl (#3965) Co-authored-by: matteenm <105068213+matteenm@users.noreply.github.com> Co-authored-by: Vignesh Mohankumar <vignesh@vigneshmohankumar.com>
1 parent 1006fd6 commit 41cbcef

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

src/components/Web3Provider/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Web3ReactProvider } from '@web3-react/core'
22
import { Connector } from '@web3-react/types'
3-
import { BACKFILLABLE_WALLETS, getConnectorForWallet, gnosisSafe, network, useConnectors } from 'connectors'
3+
import { BACKFILLABLE_WALLETS, getConnectorForWallet, gnosisSafe, injected, network, useConnectors } from 'connectors'
44
import { ReactNode, useEffect } from 'react'
55
import { useAppSelector } from 'state/hooks'
66

7+
import { isMobile } from '../../utils/userAgent'
8+
79
const connect = async (connector: Connector) => {
810
try {
911
if (connector.connectEagerly) {
@@ -22,11 +24,15 @@ export default function Web3Provider({ children }: { children: ReactNode }) {
2224

2325
const connectors = useConnectors(selectedWallet)
2426

27+
const isMetaMask = !!window.ethereum?.isMetaMask
28+
2529
useEffect(() => {
2630
connect(gnosisSafe)
2731
connect(network)
2832

29-
if (selectedWallet) {
33+
if (isMobile && isMetaMask) {
34+
injected.activate()
35+
} else if (selectedWallet) {
3036
connect(getConnectorForWallet(selectedWallet))
3137
} else if (!selectedWalletBackfilled) {
3238
BACKFILLABLE_WALLETS.map(getConnectorForWallet).forEach(connect)

src/hooks/useAccountRiskCheck.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { sendEvent } from 'components/analytics'
2+
import ms from 'ms.macro'
23
import { useEffect } from 'react'
34
import { ApplicationModal, setOpenModal } from 'state/application/reducer'
45
import { useAppDispatch } from 'state/hooks'
@@ -8,26 +9,34 @@ export default function useAccountRiskCheck(account: string | null | undefined)
89

910
useEffect(() => {
1011
if (account) {
11-
const headers = new Headers({ 'Content-Type': 'application/json' })
12-
fetch('https://screening-worker.uniswap.workers.dev', {
13-
method: 'POST',
14-
headers,
15-
body: JSON.stringify({ address: account }),
16-
})
17-
.then((res) => res.json())
18-
.then((data) => {
19-
if (data.block) {
20-
dispatch(setOpenModal(ApplicationModal.BLOCKED_ACCOUNT))
21-
sendEvent({
22-
category: 'Address Screening',
23-
action: 'blocked',
24-
label: account,
12+
const riskCheckLocalStorageKey = `risk-check-${account}`
13+
const now = Date.now()
14+
try {
15+
const storedTime = localStorage.getItem(riskCheckLocalStorageKey)
16+
const checkExpirationTime = storedTime ? parseInt(storedTime) : now - 1
17+
if (checkExpirationTime < Date.now()) {
18+
const headers = new Headers({ 'Content-Type': 'application/json' })
19+
fetch('https://screening-worker.uniswap.workers.dev', {
20+
method: 'POST',
21+
headers,
22+
body: JSON.stringify({ address: account }),
23+
})
24+
.then((res) => res.json())
25+
.then((data) => {
26+
if (data.block) {
27+
dispatch(setOpenModal(ApplicationModal.BLOCKED_ACCOUNT))
28+
sendEvent({
29+
category: 'Address Screening',
30+
action: 'blocked',
31+
label: account,
32+
})
33+
}
2534
})
26-
}
27-
})
28-
.catch(() => {
29-
dispatch(setOpenModal(null))
30-
})
35+
.catch(() => dispatch(setOpenModal(null)))
36+
}
37+
} finally {
38+
localStorage.setItem(riskCheckLocalStorageKey, (now + ms`7 days`).toString())
39+
}
3140
}
3241
}, [account, dispatch])
3342
}

0 commit comments

Comments
 (0)