Skip to content

Commit

Permalink
Merge pull request #3573 from Portkey-Wallet/feature/eoa-contact
Browse files Browse the repository at this point in the history
Feature/eoa contact
  • Loading branch information
thomas-portkey authored Feb 5, 2025
2 parents 2bb2412 + db64410 commit 0e86096
Show file tree
Hide file tree
Showing 44 changed files with 1,008 additions and 841 deletions.
2 changes: 1 addition & 1 deletion packages/api/api-eoa/contact/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const ApiObjectV2: Record<(typeof KeyListV2)[number], BaseConfig> = {
config: { method: 'GET' },
},
getSupportNetworkList: {
target: `${BASE_URL_V2}/network`,
target: `/api/app/proxy/api/app/address-book/network`,
config: { method: 'GET' },
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/api/api-eoa/send/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
config: { method: 'GET' },
},
getTransferSupportNetworkMap: {
target: '/api/app/transfer/support',
target: '/api/app/proxy/api/app/transfer/support',
config: { method: 'GET' },
},
} as const;
24 changes: 5 additions & 19 deletions packages/hooks/hooks-eoa/chainList.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import { useEffect, useMemo, useCallback } from 'react';
import { useAppCommonDispatch } from '../index';
import { getChainListAsync } from '@portkey-wallet/store/store-eoa/wallet/actions';
// import { useCurrentWallet, useOriginChainId, useWallet } from './wallet';
import { useMemo } from 'react';
import { ChainId } from '@portkey-wallet/types';
import { DEFAULT_TOKEN } from '@portkey-wallet/constants/constants-ca/wallet';
import { MAIN_CHAIN_ID } from '@portkey-wallet/constants/constants-ca/activity';
import { useCurrentNetwork, useIsMainnet } from './network';
import { useWalletListState, useWalletState } from './wallet';
import { useIsMainnet } from './network';
import { useChainList } from './network/chain';

export function useChainListFetch() {
const currentNetwork = useCurrentNetwork();
const dispatch = useAppCommonDispatch();
useEffect(() => {
dispatch(getChainListAsync());
}, [dispatch, currentNetwork]);
}
export const useCurrentChainList = useChainList;

export function useCurrentChainList() {
const currentNetwork = useCurrentNetwork();
const { chainInfo } = useWalletState();
return useMemo(() => chainInfo?.[currentNetwork], [chainInfo, currentNetwork]);
}
export const useOriginChainId = () => {
return 'AELF';
};
Expand All @@ -31,6 +16,7 @@ export function useCurrentChain(_chainId?: ChainId) {
const currentChainList = useCurrentChainList();
return useMemo(() => currentChainList?.find(chain => chain.chainId === chainId), [currentChainList, chainId]);
}

export function useExplorerUrl(chainId: ChainId) {
const isMainNet = useIsMainnet();
const exploreUrl = useMemo(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/hooks/hooks-eoa/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useContactNetworkConfig, useTransferNetworkConfig } from './networkList';
74 changes: 74 additions & 0 deletions packages/hooks/hooks-eoa/config/networkList.ts
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,
};
};
Loading

0 comments on commit 0e86096

Please sign in to comment.