Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/eoa dev1.0.0 #3576

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/api/api-did/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class DidService extends ServiceInit {
send = async (base: BaseConfig, config?: RequestConfig, reCount = 0): Promise<any> => {
try {
const result = await this.sendOrigin(base, config, reCount);
console.log('this.transformCallbackList.length', this.transformCallbackList.length);
if (this.transformCallbackList.length > 0) {
const i = this.transformCallbackList.reduce((prevResult, callback) => {
return callback(prevResult);
Expand Down
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;
1 change: 1 addition & 0 deletions packages/api/api-eoa/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class DidService extends ServiceInit {
...fetchConfig,
method,
});
console.log('sendOrigin====', JSON.stringify(fetchResult), URL);
return fetchResult;
};
setLockCallBack = (callBack: (expired?: boolean) => void) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ import { ChainId } from '@portkey-wallet/types';
import { useAppEOASelector } from '../index';
import { useCurrentNetworkInfo, useIsMainnet } from '../network';
import {
showLocalShowTokenInfo,
fetchNFTAsync,
fetchNFTCollectionsAsync,
fetchTokenListAsync,
INIT_ACCOUNT_NFT_INFO,
INIT_ACCOUNT_TOKEN_INFO,
hideLocalShowTokenInfo,
} from '@portkey-wallet/store/store-eoa/assets/slice';
import { useAppCommonDispatch } from '../..';
import { useCurrentAddressInfos, useUniqueIdentify } from '../wallet';
import {
ITokenSectionResponse,
IUserTokenItem,
IUserTokenItemResponse,
TokenItemShowType,
} from '@portkey-wallet/types/types-eoa/token';

export const useAssets = () => useAppEOASelector(state => state.assets);

Expand Down Expand Up @@ -97,6 +105,45 @@ export const useAccountTokenInfo = () => {
() => assetsState?.accountToken?.accountTokenInfoV2?.[identify] || INIT_ACCOUNT_TOKEN_INFO,
[assetsState?.accountToken?.accountTokenInfoV2, identify],
);
const updatedAccountTokenList = useMemo(() => {
const originAccountTokenList = accountTokenInfo.accountTokenList;
const localShowTokenInfo = assetsState.accountToken.localShowTokenInfo?.[identify];
const mergedTokens = localShowTokenInfo
?.filter(item => item.isAdded)
?.reduce((acc: ITokenSectionResponse[], token: IUserTokenItem) => {
const existingToken = acc.find(item => item.symbol === token.symbol);
if (existingToken) {
existingToken?.tokens?.push(token);
} else {
acc.push({
symbol: token.symbol,
price: Number(token.price) || 0,
balance: token.balance || '0',
decimals: Number(token.decimals) || 0,
balanceInUsd: token.balanceInUsd || '0',
// tokenContractAddress: '',
imageUrl: token.imageUrl,
label: token.label || '',
tokens: [token],
});
}
return acc;
}, []);
let updatedOriginAccountTokenList: ITokenSectionResponse[] = [];
if (originAccountTokenList) {
updatedOriginAccountTokenList = [...originAccountTokenList];
mergedTokens?.forEach(mergedToken => {
const existsInOrigin = updatedOriginAccountTokenList?.some(
originToken => originToken.symbol === mergedToken.symbol,
);
if (!existsInOrigin) {
updatedOriginAccountTokenList?.push(mergedToken);
}
});
}

return updatedOriginAccountTokenList.length > 0 ? updatedOriginAccountTokenList : mergedTokens;
}, [accountTokenInfo.accountTokenList, assetsState.accountToken.localShowTokenInfo, identify]);
const fetchAccountTokenInfoList = useCallback(
(params: {
addressInfos: { chainId: ChainId; address: string }[];
Expand All @@ -114,7 +161,12 @@ export const useAccountTokenInfo = () => {
[identify, dispatch],
);

return { ...accountTokenInfo, fetchAccountTokenInfoList, isFetching: assetsState?.accountToken?.isFetching };
return {
...accountTokenInfo,
accountTokenList: updatedAccountTokenList,
fetchAccountTokenInfoList,
isFetching: assetsState?.accountToken?.isFetching,
};
};
export const useAccountBalanceUSD = () => {
const identify = useUniqueIdentify();
Expand Down Expand Up @@ -197,3 +249,50 @@ export function useFetchTokenAllowanceList() {
// [addressInfos],
// );
}

export function useManagerTokenInfo() {
const dispatch = useAppCommonDispatch();
const identify = useUniqueIdentify();
const { accountToken } = useAssets();
console.log('accountToken===1233', accountToken);
const showToken = useCallback(
(token: IUserTokenItem) => {
dispatch(
showLocalShowTokenInfo({
identify,
token,
}),
);
},
[dispatch, identify],
);

const hideToken = useCallback(
(token: IUserTokenItem) => {
dispatch(
hideLocalShowTokenInfo({
identify,
token,
}),
);
},
[dispatch, identify],
);
const switchToken = useCallback(
(item: TokenItemShowType, isDisplay: boolean) => {
console.log('item is::', item, 'isDisplay', isDisplay);
if (isDisplay) {
showToken(item as IUserTokenItem);
} else {
hideToken(item as IUserTokenItem);
}
},
[hideToken, showToken],
);
return {
showToken,
hideToken,
switchToken,
localToken: accountToken?.localShowTokenInfo?.[identify],
};
}
7 changes: 4 additions & 3 deletions packages/hooks/hooks-eoa/awaken/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { DEFAULT_EXPIRATION, DEFAULT_SLIPPAGE_TOLERANCE } from '@portkey-wallet/constants/awaken';
import { useDAppChain, useDAppChainId } from '../network/chain';
import { request } from '@portkey-wallet/api/api-eoa';
import { useCurrentAccount } from '../wallet';
import { useCurrentAccount, useUniqueIdentify } from '../wallet';

export const useAwakenState = () => useAppEOASelector(state => state.awaken);

Expand Down Expand Up @@ -179,6 +179,7 @@ export const useAwakenTokenList = (isInit = false) => {

const list = useMemo(() => awakenTokenListState[network] || [], [awakenTokenListState, network]);
const account = useCurrentAccount();
const key = useUniqueIdentify();

const refresh = useCallback(async () => {
try {
Expand All @@ -193,14 +194,14 @@ export const useAwakenTokenList = (isInit = false) => {
});
dispatch(
updateAwakenTokenList({
key: network,
key,
list: rst.data,
}),
);
} catch (error) {
console.log('useAwakenTokenList refresh error', error);
}
}, [account?.address, chainId, dispatch, network]);
}, [account?.address, chainId, dispatch, key]);

useEffect(() => {
if (!isInit) return;
Expand Down
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
Loading