File tree Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Original file line number Diff line number Diff line change 1- import { isEvm } from '@pancakeswap/chains'
21import { useAtomValue } from 'jotai'
32import { useEffect , useRef } from 'react'
43
54import { accountActiveChainAtom } from 'wallet/atoms/accountStateAtoms'
65
76export const useActiveChainId = ( checkChainId ?: number ) => {
8- const { isNotMatched, isWrongNetwork, chainId } = useAccountActiveChain ( )
7+ const result = useAtomValue ( accountActiveChainAtom )
8+
9+ if ( ! checkChainId ) return result
10+
11+ const { chainId, isWrongNetwork } = result
912 return {
10- chainId,
11- isNotMatched,
12- isWrongNetwork : checkChainId ? isWrongNetwork && checkChainId !== chainId : isWrongNetwork ,
13+ ...result ,
14+ isWrongNetwork : isWrongNetwork && checkChainId !== chainId ,
1315 }
1416}
1517
@@ -24,10 +26,7 @@ export const useActiveChainIdRef = () => {
2426}
2527
2628export const useAccountActiveChain = ( ) => {
27- const result = useAtomValue ( accountActiveChainAtom )
28- const { chainId, account, solanaAccount } = result
29- const unifiedAccount = isEvm ( chainId ) ? account : solanaAccount
30- return { ...result , unifiedAccount }
29+ return useAtomValue ( accountActiveChainAtom )
3130}
3231
3332export default useAccountActiveChain
Original file line number Diff line number Diff line change 1- import { ChainId } from '@pancakeswap/chains'
1+ import { ChainId , isEvm } from '@pancakeswap/chains'
22import { atom } from 'jotai'
33import { getHashKey } from 'utils/hash'
44import { Connector } from 'wagmi'
@@ -7,6 +7,7 @@ import { getQueryChainId } from 'wallet/util/getQueryChainId'
77export interface AccountChainState {
88 account ?: `0x${string } `
99 solanaAccount ?: string | null
10+ unifiedAccount ?: string | null
1011 chainId : number
1112 isWrongNetwork : boolean
1213 isNotMatched : boolean
@@ -20,14 +21,18 @@ const _accountActiveChainAtom = atom<AccountChainState>({
2021 isWrongNetwork : false ,
2122 status : null ,
2223 solanaAccount : null ,
24+ unifiedAccount : null ,
2325 isNotMatched : false ,
2426} )
2527
2628type Updater = AccountChainState | ( ( prev : AccountChainState ) => AccountChainState )
2729
2830export const accountActiveChainAtom = atom (
2931 ( get ) => {
30- return get ( _accountActiveChainAtom )
32+ const state = get ( _accountActiveChainAtom )
33+ const { chainId, account, solanaAccount } = state
34+ const unifiedAccount = isEvm ( chainId ) ? account : solanaAccount
35+ return { ...state , unifiedAccount }
3136 } ,
3237 ( _get , set , updater : Updater ) => {
3338 const prev = _get ( _accountActiveChainAtom )
You can’t perform that action at this time.
0 commit comments