Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Add waiting time to reconnection (#2526)
Browse files Browse the repository at this point in the history
* Add waiting time to re-connection

* Avoid modifying the original constants file
  • Loading branch information
henrypalacios authored Mar 9, 2022
1 parent d307fb2 commit 81a74ad
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/constants/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ export const SUPPORTED_WALLETS: { [key: string]: WalletInfo } = {
description: 'Use Coinbase Wallet app on mobile device',
href: null,
color: '#315CF5',
},
COINBASE_LINK: {
name: 'Open in Coinbase Wallet',
iconURL: COINBASE_ICON_URL,
description: 'Open in Coinbase Wallet app.',
href: 'https://go.cb-w.com/mtUDhEZPy1',
color: '#315CF5',
mobile: true,
mobileOnly: true,
},
FORTMATIC: {
connector: fortmatic,
Expand Down
9 changes: 8 additions & 1 deletion src/custom/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ export const APP_DATA_HASH = getAppDataHash()
export const PRODUCTION_URL = 'cowswap.exchange'
export const BARN_URL = `barn.${PRODUCTION_URL}`

const DISABLED_WALLETS = /^(?:Portis)$/i
// Allow WALLET_LINK to be activated on mobile
// since COINBASE_LINK is limited to use only 1 deeplink on mobile
SUPPORTED_WALLETS_UNISWAP.WALLET_LINK = {
...SUPPORTED_WALLETS_UNISWAP.WALLET_LINK,
mobile: true,
}
const DISABLED_WALLETS = /^(?:Portis|COINBASE_LINK)$/i

// Re-export only the supported wallets
export const SUPPORTED_WALLETS = Object.keys(SUPPORTED_WALLETS_UNISWAP).reduce((acc, key) => {
Expand Down Expand Up @@ -115,6 +121,7 @@ export const AMOUNT_OF_ORDERS_TO_FETCH = 100

// last wallet provider key used in local storage
export const STORAGE_KEY_LAST_PROVIDER = 'lastProvider'
export const WAITING_TIME_RECONNECT_LAST_PROVIDER = 15000 // 15s

// Default price strategy to use for getting app prices
// COWSWAP = new quote endpoint
Expand Down
13 changes: 11 additions & 2 deletions src/custom/hooks/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AbstractConnector } from '@web3-react/abstract-connector'
import { useEffect, useState, useCallback } from 'react'
import { isMobile } from 'react-device-detect'
import { injected, walletconnect, getProviderType, WalletProvider, fortmatic, walletlink } from 'connectors'
import { STORAGE_KEY_LAST_PROVIDER } from 'constants/index'
import { STORAGE_KEY_LAST_PROVIDER, WAITING_TIME_RECONNECT_LAST_PROVIDER } from 'constants/index'

// exports from the original file
export { useActiveWeb3React, useInactiveListener } from '@src/hooks/web3'
Expand Down Expand Up @@ -58,7 +58,7 @@ export function useEagerConnect() {
setTried(true)
})
},
[activate, setTried]
[activate]
)

useEffect(() => {
Expand All @@ -85,9 +85,18 @@ export function useEagerConnect() {

// if the connection worked, wait until we get confirmation of that to flip the flag
useEffect(() => {
let timeout: NodeJS.Timeout | undefined

if (active) {
setTried(true)
} else {
timeout = setTimeout(() => {
localStorage.removeItem(STORAGE_KEY_LAST_PROVIDER)
setTried(true)
}, WAITING_TIME_RECONNECT_LAST_PROVIDER)
}

return () => timeout && clearTimeout(timeout)
}, [active])

useEffect(() => {
Expand Down

0 comments on commit 81a74ad

Please sign in to comment.