Skip to content

Commit

Permalink
Merge branch 'feat/assets-search' into tmp/20250107
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016x committed Jan 7, 2025
2 parents 995917f + 0b60a0a commit a97d582
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 53 deletions.
81 changes: 57 additions & 24 deletions apps/mobile/src/core/services/preference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ export type IManageToken = {
tokenId: string;
};

function makeManageTokenKey(x: IManageToken): `${string}-${string}` {
return `${x.chainId}-${x.tokenId}`;
function makeManageTokenKey(x: IManageToken) {
// return `${x.chainId}-${x.tokenId}`;
return JSON.stringify(x);
}

function decodeManageTokenKey(x: string): IManageToken {
const [chainId, tokenId] = JSON.parse(x);
return { chainId, tokenId };
}

export type IDefiOrToken = {
Expand All @@ -69,8 +75,14 @@ export type IDefiOrToken = {
type: 'token' | 'defi';
};

function makeDefiOrTokenKey(x: IDefiOrToken): `${string}-${string}-${string}` {
return `${x.chainid}-${x.id}-${x.type}`;
function makeDefiOrTokenKey(x: IDefiOrToken) {
// return `${x.chainid}-${x.id}-${x.type}`;
return JSON.stringify(x);
}

function decodeDefiOrTokenKey(x: string): IDefiOrToken {
const [chainid, id, type] = JSON.parse(x);
return { chainid, id, type };
}

export type ITokenSetting = {
Expand Down Expand Up @@ -250,14 +262,11 @@ export class PreferenceService {
),
};

Object.entries(tokenManageSettingMap).forEach(([eoaAddr, setting]) => {
Object.values(tokenManageSettingMap).forEach(setting => {
(['pinedQueue', 'foldTokens', 'unfoldTokens'] as const).forEach(key => {
setting[key]?.forEach(item => {
const k = makeManageTokenKey(item);
if (!sets.pinedQueue.has(k)) {
lists[key].push(item);
sets[key].add(k);
}
if (!sets[key].has(k)) sets[key].add(k);
});

if (!__DEV__) delete setting[key];
Expand All @@ -267,28 +276,52 @@ export class PreferenceService {
key => {
setting[key]?.forEach(item => {
const k = makeDefiOrTokenKey(item);
if (!sets[key].has(k)) {
lists[key].push(item);
sets[key].add(k);
}
if (!sets[key].has(k)) sets[key].add(k);
});

if (!__DEV__) delete setting[key];
},
);
});

this.store.pinedQueue = lists.pinedQueue;
// console.debug(
// '[preference::_migrate] this.store.pinedQueue',
// this.store.pinedQueue,
// );
this.store.foldTokens = lists.foldTokens;
this.store.unfoldTokens = lists.unfoldTokens;
this.store.includeDefiAndTokens = lists.includeDefiAndTokens;
this.store.excludeDefiAndTokens = lists.excludeDefiAndTokens;

this.store.tokenManageSettingMap = tokenManageSettingMap;
priority_process: {
// pinedQueue > foldTokens > unfoldTokens
sets.pinedQueue.forEach(k => {
sets.foldTokens.delete(k);
sets.unfoldTokens.delete(k);
});
sets.foldTokens.forEach(k => {
sets.unfoldTokens.delete(k);
});

lists.pinedQueue = [...sets.pinedQueue].map(k => decodeManageTokenKey(k));
lists.foldTokens = [...sets.foldTokens].map(k => decodeManageTokenKey(k));
lists.unfoldTokens = [...sets.unfoldTokens].map(k =>
decodeManageTokenKey(k),
);

// excludeDefiAndTokens > includeDefiAndTokens
sets.excludeDefiAndTokens.forEach(k => {
sets.includeDefiAndTokens.delete(k);
});

lists.excludeDefiAndTokens = [...sets.excludeDefiAndTokens].map(k =>
decodeDefiOrTokenKey(k),
);
lists.includeDefiAndTokens = [...sets.includeDefiAndTokens].map(k =>
decodeDefiOrTokenKey(k),
);
}

flush_back: {
this.store.pinedQueue = lists.pinedQueue;
this.store.foldTokens = lists.foldTokens;
this.store.unfoldTokens = lists.unfoldTokens;
this.store.includeDefiAndTokens = lists.includeDefiAndTokens;
this.store.excludeDefiAndTokens = lists.excludeDefiAndTokens;

this.store.tokenManageSettingMap = tokenManageSettingMap;
}
}

/* eslint-disable no-dupe-class-members */
Expand Down
9 changes: 5 additions & 4 deletions apps/mobile/src/screens/Home/hooks/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import { formatNetworth } from '@/utils/math';
import { AbstractPortfolioToken } from '../types';
import { getDisplayedPortfolioUsdValue } from '../utils/converAssets';
import { DisplayedProject } from '../utils/project';
import { formatAmount } from '@/utils/number';

export type CombineTokensItem = AbstractPortfolioToken & {
totalAmount: BigNumber;
totalUsdValue?: BigNumber;
fromAddress: Array<{
address: string;
amount: string;
amount: number;
}>;
};

Expand Down Expand Up @@ -185,7 +186,7 @@ export const combinedTokensAtom = atom(async get => {
fromAddress: [
{
address,
amount: token._amountStr || '',
amount: token.amount,
},
],
};
Expand All @@ -199,7 +200,7 @@ export const combinedTokensAtom = atom(async get => {
);
existingToken.fromAddress.push({
address,
amount: token._amountStr || '',
amount: token.amount,
});
}
});
Expand All @@ -209,7 +210,7 @@ export const combinedTokensAtom = atom(async get => {
...i,
_usdValue: i.totalUsdValue?.toNumber(),
_usdValueStr: formatNetworth(i.totalUsdValue?.toNumber()),
_amountStr: formatNetworth(i.totalAmount.toNumber()),
_amountStr: formatAmount(i.totalAmount.toNumber()),
}));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const TokenArea: React.FC<Props> = ({
<View style={styles.tokenBox}>
<Text style={styles.tokenAmount} numberOfLines={1}>
{formatTokenAmount(item.amount)}
{' '}
{token.symbol}
</Text>
<View style={styles.accountBox}>
Expand Down
3 changes: 1 addition & 2 deletions apps/mobile/src/screens/TokenDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ export const TokenDetailScreen = () => {
},
});
});

const tokenFromAddress = useMemo(() => {
const res = [] as TokenFromAddressItem[];

Expand All @@ -350,7 +349,7 @@ export const TokenDetailScreen = () => {
if (idx > -1) {
res.push({
address: item.address,
amount: item.amount,
amount: formatTokenAmount(item.amount),
aliasName:
actionsAccounts[idx].aliasName || ellipsisAddress(item.address),
type: actionsAccounts[idx].type,
Expand Down
49 changes: 26 additions & 23 deletions apps/mobile/src/screens/Transaction/components/TokenLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react';
import React, { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';

import TouchableText from '@/components/Touchable/TouchableText';
Expand Down Expand Up @@ -47,38 +47,41 @@ export default function TokenLabel({
: symbol;
}, [t, isNft, token]);

const { openTokenDetailPopup, setTokenDetailAddress } =
useGeneralTokenDetailSheetModal();
const { handlePressNftToken } = useNFTDetailSheetModalOnHistory();

const disableClickToken = propDisableClick || (isNft && !isMyOwn);

if (disableClickToken)
const handlePress = useCallback(() => {
if (disableClickToken) {
return;
}

if (isNft) {
naviPush(RootNames.NftDetail, {
token: { ...token },
});
} else {
// if (address) {
// setTokenDetailAddress(address);
// }
// openTokenDetailPopup(token as TokenItem);
naviPush(RootNames.TokenDetail, {
token: ensureAbstractPortfolioToken(token),
// account: address,
needUseCacheToken: true,
});
}
}, [token, disableClickToken, isNft]);

if (disableClickToken) {
return (
<Text style={style} numberOfLines={1} ellipsizeMode="tail">
{symbolName}
</Text>
);
}

return (
<TouchableText
onPress={() => {
if (disableClickToken) return;

if (isNft) {
handlePressNftToken(token, { needSendButton: isMyOwn });
} else {
// if (address) {
// setTokenDetailAddress(address);
// }
// openTokenDetailPopup(token as TokenItem);
naviPush(RootNames.TokenDetail, {
token: ensureAbstractPortfolioToken(token),
// account: address,
needUseCacheToken: true,
});
}
}}
onPress={handlePress}
disabled={disableClickToken}
style={[!disableClickToken && styles.clickable, style]}
numberOfLines={1}
Expand Down

0 comments on commit a97d582

Please sign in to comment.