-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3573 from Portkey-Wallet/feature/eoa-contact
Feature/eoa contact
- Loading branch information
Showing
44 changed files
with
1,008 additions
and
841 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { useContactNetworkConfig, useTransferNetworkConfig } from './networkList'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { useCurrentNetwork, useNetworkList } from '@portkey-wallet/hooks/hooks-eoa/network'; | ||
import { useCallback, useEffect, useMemo } from 'react'; | ||
import { ChainId } from '@portkey-wallet/types'; | ||
import { | ||
fetchTransferSupportNetworkList, | ||
fetchContactSupportNetworkList, | ||
} from '@portkey-wallet/store/store-eoa/config/slice'; | ||
import { useAppEOASelector, useAppCommonDispatch } from '../../index'; | ||
|
||
export const useConfig = () => useAppEOASelector(state => state.config); | ||
|
||
export const useTransferNetworkConfig = (isInit = false) => { | ||
const { sendAssetSupportNetworkMap } = useConfig(); | ||
const dispatch = useAppCommonDispatch(); | ||
const currentNetwork = useCurrentNetwork(); | ||
const networkList = useNetworkList(); | ||
|
||
const targetMap = sendAssetSupportNetworkMap[currentNetwork]; | ||
|
||
const getTargetChainSymbolConfigList = useCallback( | ||
(fromChainId: ChainId, symbol: string) => { | ||
return targetMap?.[fromChainId]?.[symbol]; | ||
}, | ||
[targetMap], | ||
); | ||
|
||
const checkIsSupportTargetChain = useCallback( | ||
({ fromChainId, symbol, network }: { fromChainId: ChainId; symbol: string; network: string }) => { | ||
return targetMap?.[fromChainId]?.[symbol]?.find(ele => ele.network === network); | ||
}, | ||
[targetMap], | ||
); | ||
|
||
const fetchAssetSupportConfig = useCallback(() => { | ||
dispatch(fetchTransferSupportNetworkList(networkList)); | ||
}, [dispatch, networkList]); | ||
|
||
useEffect(() => { | ||
if (!isInit) return; | ||
fetchAssetSupportConfig(); | ||
}, [fetchAssetSupportConfig, isInit]); | ||
|
||
return { | ||
fetchAssetSupportConfig, | ||
checkIsSupportTargetChain, | ||
getTargetChainSymbolConfigList, | ||
}; | ||
}; | ||
|
||
export const useContactNetworkConfig = (isInit = false) => { | ||
const { contactSupportNetworkMap } = useConfig(); | ||
const dispatch = useAppCommonDispatch(); | ||
const currentNetwork = useCurrentNetwork(); | ||
const networkList = useNetworkList(); | ||
|
||
const supportNetworkList = useMemo( | ||
() => contactSupportNetworkMap[currentNetwork], | ||
[contactSupportNetworkMap, currentNetwork], | ||
); | ||
|
||
const fetchContactSupportConfig = useCallback(() => { | ||
dispatch(fetchContactSupportNetworkList(networkList)); | ||
}, [dispatch, networkList]); | ||
|
||
useEffect(() => { | ||
if (!isInit) return; | ||
fetchContactSupportConfig(); | ||
}, [fetchContactSupportConfig, isInit]); | ||
|
||
return { | ||
supportNetworkList, | ||
fetchContactSupportConfig, | ||
}; | ||
}; |
Oops, something went wrong.