Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
ee001f86
Unverified
Commit
ee001f86
authored
Aug 29, 2022
by
Vignesh Mohankumar
Committed by
GitHub
Aug 29, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: remove isChainAllowed (#4494)
parent
87d6975b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
25 deletions
+18
-25
NetworkSelector.tsx
src/components/Header/NetworkSelector.tsx
+10
-13
useCurrency.ts
src/lib/hooks/useCurrency.ts
+6
-6
switchChain.ts
src/utils/switchChain.ts
+2
-6
No files found.
src/components/Header/NetworkSelector.tsx
View file @
ee001f86
...
@@ -11,7 +11,6 @@ import { useCloseModal, useModalIsOpen, useOpenModal, useToggleModal } from 'sta
...
@@ -11,7 +11,6 @@ import { useCloseModal, useModalIsOpen, useOpenModal, useToggleModal } from 'sta
import
{
ApplicationModal
}
from
'
state/application/reducer
'
import
{
ApplicationModal
}
from
'
state/application/reducer
'
import
styled
from
'
styled-components/macro
'
import
styled
from
'
styled-components/macro
'
import
{
ExternalLink
,
MEDIA_WIDTHS
}
from
'
theme
'
import
{
ExternalLink
,
MEDIA_WIDTHS
}
from
'
theme
'
import
{
isChainAllowed
}
from
'
utils/switchChain
'
import
{
isMobile
}
from
'
utils/userAgent
'
import
{
isMobile
}
from
'
utils/userAgent
'
const
ActiveRowLinkList
=
styled
.
div
`
const
ActiveRowLinkList
=
styled
.
div
`
...
@@ -328,18 +327,16 @@ export default function NetworkSelector() {
...
@@ -328,18 +327,16 @@ export default function NetworkSelector() {
<
FlyoutHeader
>
<
FlyoutHeader
>
<
Trans
>
Select a
{
!
onSupportedChain
?
'
supported
'
:
''
}
network
</
Trans
>
<
Trans
>
Select a
{
!
onSupportedChain
?
'
supported
'
:
''
}
network
</
Trans
>
</
FlyoutHeader
>
</
FlyoutHeader
>
{
NETWORK_SELECTOR_CHAINS
.
map
((
chainId
:
SupportedChainId
)
=>
{
NETWORK_SELECTOR_CHAINS
.
map
((
chainId
:
SupportedChainId
)
=>
(
isChainAllowed
(
chainId
)
?
(
<
Row
<
Row
onSelectChain=
{
async
(
targetChainId
:
SupportedChainId
)
=>
{
onSelectChain=
{
async
(
targetChainId
:
SupportedChainId
)
=>
{
await
selectChain
(
targetChainId
)
await
selectChain
(
targetChainId
)
closeModal
()
closeModal
()
}
}
}
}
targetChain=
{
chainId
}
targetChain=
{
chainId
}
key=
{
chainId
}
key=
{
chainId
}
/>
/>
))
}
)
:
null
)
}
</
FlyoutMenuContents
>
</
FlyoutMenuContents
>
</
FlyoutMenu
>
</
FlyoutMenu
>
)
}
)
}
...
...
src/lib/hooks/useCurrency.ts
View file @
ee001f86
...
@@ -2,11 +2,11 @@ import { arrayify } from '@ethersproject/bytes'
...
@@ -2,11 +2,11 @@ import { arrayify } from '@ethersproject/bytes'
import
{
parseBytes32String
}
from
'
@ethersproject/strings
'
import
{
parseBytes32String
}
from
'
@ethersproject/strings
'
import
{
Currency
,
Token
}
from
'
@uniswap/sdk-core
'
import
{
Currency
,
Token
}
from
'
@uniswap/sdk-core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
isSupportedChain
}
from
'
constants/chains
'
import
{
useBytes32TokenContract
,
useTokenContract
}
from
'
hooks/useContract
'
import
{
useBytes32TokenContract
,
useTokenContract
}
from
'
hooks/useContract
'
import
{
NEVER_RELOAD
,
useSingleCallResult
}
from
'
lib/hooks/multicall
'
import
{
NEVER_RELOAD
,
useSingleCallResult
}
from
'
lib/hooks/multicall
'
import
useNativeCurrency
from
'
lib/hooks/useNativeCurrency
'
import
useNativeCurrency
from
'
lib/hooks/useNativeCurrency
'
import
{
useMemo
}
from
'
react
'
import
{
useMemo
}
from
'
react
'
import
{
isChainAllowed
}
from
'
utils/switchChain
'
import
{
TOKEN_SHORTHANDS
}
from
'
../../constants/tokens
'
import
{
TOKEN_SHORTHANDS
}
from
'
../../constants/tokens
'
import
{
isAddress
}
from
'
../../utils
'
import
{
isAddress
}
from
'
../../utils
'
...
@@ -31,7 +31,7 @@ function parseStringOrBytes32(str: string | undefined, bytes32: string | undefin
...
@@ -31,7 +31,7 @@ function parseStringOrBytes32(str: string | undefined, bytes32: string | undefin
*/
*/
export
function
useTokenFromNetwork
(
tokenAddress
:
string
|
null
|
undefined
):
Token
|
null
|
undefined
{
export
function
useTokenFromNetwork
(
tokenAddress
:
string
|
null
|
undefined
):
Token
|
null
|
undefined
{
const
{
chainId
}
=
useWeb3React
()
const
{
chainId
}
=
useWeb3React
()
const
chainAllowed
=
chainId
&&
isChainAllowed
(
chainId
)
const
supportedChain
=
isSupportedChain
(
chainId
)
const
formattedAddress
=
isAddress
(
tokenAddress
)
const
formattedAddress
=
isAddress
(
tokenAddress
)
...
@@ -45,7 +45,7 @@ export function useTokenFromNetwork(tokenAddress: string | null | undefined): To
...
@@ -45,7 +45,7 @@ export function useTokenFromNetwork(tokenAddress: string | null | undefined): To
const
decimals
=
useSingleCallResult
(
tokenContract
,
'
decimals
'
,
undefined
,
NEVER_RELOAD
)
const
decimals
=
useSingleCallResult
(
tokenContract
,
'
decimals
'
,
undefined
,
NEVER_RELOAD
)
return
useMemo
(()
=>
{
return
useMemo
(()
=>
{
if
(
typeof
tokenAddress
!==
'
string
'
||
!
chainAllowed
||
!
formattedAddress
)
return
undefined
if
(
typeof
tokenAddress
!==
'
string
'
||
!
supportedChain
||
!
formattedAddress
)
return
undefined
if
(
decimals
.
loading
||
symbol
.
loading
||
tokenName
.
loading
)
return
null
if
(
decimals
.
loading
||
symbol
.
loading
||
tokenName
.
loading
)
return
null
if
(
decimals
.
result
)
{
if
(
decimals
.
result
)
{
return
new
Token
(
return
new
Token
(
...
@@ -60,7 +60,7 @@ export function useTokenFromNetwork(tokenAddress: string | null | undefined): To
...
@@ -60,7 +60,7 @@ export function useTokenFromNetwork(tokenAddress: string | null | undefined): To
},
[
},
[
formattedAddress
,
formattedAddress
,
chainId
,
chainId
,
chainAllowed
,
supportedChain
,
decimals
.
loading
,
decimals
.
loading
,
decimals
.
result
,
decimals
.
result
,
symbol
.
loading
,
symbol
.
loading
,
...
@@ -105,8 +105,8 @@ export function useCurrencyFromMap(tokens: TokenMap, currencyId?: string | null)
...
@@ -105,8 +105,8 @@ export function useCurrencyFromMap(tokens: TokenMap, currencyId?: string | null)
const
token
=
useTokenFromMapOrNetwork
(
tokens
,
isNative
?
undefined
:
shorthandMatchAddress
??
currencyId
)
const
token
=
useTokenFromMapOrNetwork
(
tokens
,
isNative
?
undefined
:
shorthandMatchAddress
??
currencyId
)
const
chainAllowed
=
chainId
&&
isChainAllowed
(
chainId
)
const
supportedChain
=
isSupportedChain
(
chainId
)
if
(
currencyId
===
null
||
currencyId
===
undefined
||
!
chainAllowed
)
return
null
if
(
currencyId
===
null
||
currencyId
===
undefined
||
!
supportedChain
)
return
null
// this case so we use our builtin wrapped token instead of wrapped tokens on token lists
// this case so we use our builtin wrapped token instead of wrapped tokens on token lists
const
wrappedNative
=
nativeCurrency
?.
wrapped
const
wrappedNative
=
nativeCurrency
?.
wrapped
...
...
src/utils/switchChain.ts
View file @
ee001f86
import
{
Connector
}
from
'
@web3-react/types
'
import
{
Connector
}
from
'
@web3-react/types
'
import
{
networkConnection
,
walletConnectConnection
}
from
'
connection
'
import
{
networkConnection
,
walletConnectConnection
}
from
'
connection
'
import
{
getChainInfo
}
from
'
constants/chainInfo
'
import
{
getChainInfo
}
from
'
constants/chainInfo
'
import
{
ALL_SUPPORTED_CHAIN_IDS
,
SupportedChainId
}
from
'
constants/chains
'
import
{
isSupportedChain
,
SupportedChainId
}
from
'
constants/chains
'
import
{
RPC_URLS
}
from
'
constants/networks
'
import
{
RPC_URLS
}
from
'
constants/networks
'
function
getRpcUrls
(
chainId
:
SupportedChainId
):
[
string
]
{
function
getRpcUrls
(
chainId
:
SupportedChainId
):
[
string
]
{
...
@@ -34,12 +34,8 @@ function getRpcUrls(chainId: SupportedChainId): [string] {
...
@@ -34,12 +34,8 @@ function getRpcUrls(chainId: SupportedChainId): [string] {
throw
new
Error
(
'
RPC URLs must use public endpoints
'
)
throw
new
Error
(
'
RPC URLs must use public endpoints
'
)
}
}
export
function
isChainAllowed
(
chainId
:
number
)
{
return
ALL_SUPPORTED_CHAIN_IDS
.
includes
(
chainId
)
}
export
const
switchChain
=
async
(
connector
:
Connector
,
chainId
:
SupportedChainId
)
=>
{
export
const
switchChain
=
async
(
connector
:
Connector
,
chainId
:
SupportedChainId
)
=>
{
if
(
!
is
ChainAllowed
(
chainId
))
{
if
(
!
is
SupportedChain
(
chainId
))
{
throw
new
Error
(
`Chain
${
chainId
}
not supported for connector (
${
typeof
connector
}
)`
)
throw
new
Error
(
`Chain
${
chainId
}
not supported for connector (
${
typeof
connector
}
)`
)
}
else
if
(
connector
===
walletConnectConnection
.
connector
||
connector
===
networkConnection
.
connector
)
{
}
else
if
(
connector
===
walletConnectConnection
.
connector
||
connector
===
networkConnection
.
connector
)
{
await
connector
.
activate
(
chainId
)
await
connector
.
activate
(
chainId
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment