Skip to content

Commit 96075b0

Browse files
feat: implement server-side control for withdraw and claim on Earn pages (#7519)
* feat: enable local address label in history list OK-38806 (#7509) * feat: replace address with local address label in history list * feat: query address with cache * feat: update address label when wallet/account/addressbook changed * fix: lint * fix: prevent Android reset from freezing. (#7515) * feat: implement server-side control for withdraw and claim on Earn pages * Revert "fix: prevent Android reset from freezing. (#7515)" This reverts commit 8c8f2f4. * Revert "feat: enable local address label in history list OK-38806 (#7509)" This reverts commit 184746b. * Update EarnHome.tsx * Update byte-test-web.yml --------- Co-authored-by: weatherstar <[email protected]>
1 parent f6c7bd2 commit 96075b0

File tree

8 files changed

+144
-47
lines changed

8 files changed

+144
-47
lines changed

packages/kit/src/views/Earn/EarnHome.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ import { ListItem } from '../../components/ListItem';
6060
import { TabPageHeader } from '../../components/TabPageHeader';
6161
import useAppNavigation from '../../hooks/useAppNavigation';
6262
import { usePromiseResult } from '../../hooks/usePromiseResult';
63-
import { useActiveAccount } from '../../states/jotai/contexts/accountSelector';
63+
import {
64+
useAccountSelectorActions,
65+
useActiveAccount,
66+
} from '../../states/jotai/contexts/accountSelector';
6467
import { useEarnActions, useEarnAtom } from '../../states/jotai/contexts/earn';
6568

6669
import { EARN_PAGE_MAX_WIDTH, EARN_RIGHT_PANEL_WIDTH } from './EarnConfig';
@@ -847,6 +850,7 @@ function BasicEarnHome() {
847850
];
848851

849852
const navigation = useAppNavigation();
853+
const accountSelectorActions = useAccountSelectorActions();
850854

851855
const onBannerPress = useCallback(
852856
async ({
@@ -896,9 +900,16 @@ function BasicEarnHome() {
896900
} else {
897901
openUrlInApp(href);
898902
}
903+
} else {
904+
await accountSelectorActions.current.showAccountSelector({
905+
navigation,
906+
activeWallet: undefined,
907+
num: 0,
908+
sceneName: EAccountSelectorSceneName.home,
909+
});
899910
}
900911
},
901-
[account, indexedAccount, navigation],
912+
[account, accountSelectorActions, indexedAccount, navigation],
902913
);
903914

904915
const banners = useMemo(() => {

packages/kit/src/views/Earn/earnUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export const EarnNavigation = {
3333
params: {
3434
accountId: earnAccount?.accountId || accountId || '',
3535
networkId,
36-
indexedAccountId: earnAccount?.account.indexedAccountId,
36+
indexedAccountId:
37+
earnAccount?.account.indexedAccountId || indexedAccountId,
3738
symbol,
3839
provider,
3940
vault,

packages/kit/src/views/Staking/components/ProtocolDetails/EarnActionIcon.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { memo, useCallback } from 'react';
1+
import { memo, useCallback, useState } from 'react';
22

33
import { StyleSheet } from 'react-native';
44

@@ -197,12 +197,18 @@ function BasicClaimActionIcon({
197197
accountId: protocolInfo?.earnAccount?.accountId || '',
198198
networkId: tokenInfo?.networkId || '',
199199
});
200+
const [loading, setLoading] = useState(false);
200201
return (
201202
<Button
202203
size="small"
203204
variant="primary"
204-
disabled={actionIcon?.disabled}
205+
loading={loading}
206+
disabled={loading || actionIcon?.disabled}
205207
onPress={async () => {
208+
setLoading(true);
209+
setTimeout(() => {
210+
setLoading(false);
211+
}, 10 * 1000);
206212
const claimAmount =
207213
protocolInfo?.claimable || actionIcon.data?.balance || '0';
208214
const isMorphoClaim = !!(
@@ -212,6 +218,7 @@ function BasicClaimActionIcon({
212218
})
213219
);
214220
await handleClaim({
221+
claimType: actionIcon.type,
215222
symbol: protocolInfo?.symbol || '',
216223
protocolInfo,
217224
tokenInfo: tokenInfo
@@ -236,6 +243,7 @@ function BasicClaimActionIcon({
236243
tags: protocolInfo?.stakeTag ? [protocolInfo.stakeTag] : [],
237244
},
238245
});
246+
setLoading(false);
239247
}}
240248
>
241249
{typeof actionIcon.text === 'string'

packages/kit/src/views/Staking/pages/HistoryList/index.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type IHistoryItemProps = {
4747
networks?: IStakeHistoriesResponse['networks'];
4848
token?: IToken;
4949
provider?: string;
50+
tokenMap?: IStakeHistoriesResponse['tokenMap'];
5051
};
5152

5253
const HistoryItem = ({
@@ -55,22 +56,37 @@ const HistoryItem = ({
5556
token,
5657
network,
5758
networks,
59+
tokenMap,
5860
}: IHistoryItemProps) => {
5961
const navigation = useAppNavigation();
6062
const route = useAppRoute<
6163
IModalStakingParamList,
6264
EModalStakingRoutes.HistoryList
6365
>();
64-
const { accountId, networkId } = route.params;
66+
const { accountId } = route.params;
6567
const logoURI = useMemo(() => {
6668
if (token?.logoURI) {
6769
return token.logoURI;
6870
}
6971
if (networks?.length) {
7072
return networks.find((o) => o.networkId === item.networkId)?.logoURI;
7173
}
74+
if (tokenMap && item.type === 'stake') {
75+
const uri = tokenMap[item.tokenAddress]?.logoURI;
76+
if (uri) {
77+
return uri;
78+
}
79+
}
7280
return network?.logoURI;
73-
}, [token?.logoURI, networks, network?.logoURI, item.networkId]);
81+
}, [
82+
item.type,
83+
item.tokenAddress,
84+
item.networkId,
85+
token?.logoURI,
86+
networks,
87+
network?.logoURI,
88+
tokenMap,
89+
]);
7490
const onPress = useCallback(() => {
7591
navigation.push(EModalAssetDetailRoutes.HistoryDetails, {
7692
networkId: item.networkId,
@@ -121,6 +137,7 @@ type IHistoryContentProps = {
121137
onFilterTypeChange: (type: string) => void;
122138
network?: { networkId: string; name: string; logoURI: string };
123139
networks?: IStakeHistoriesResponse['networks'];
140+
tokenMap?: IStakeHistoriesResponse['tokenMap'];
124141
provider?: string;
125142
};
126143

@@ -136,6 +153,7 @@ const HistoryContent = ({
136153
filter,
137154
filterType,
138155
networks,
156+
tokenMap,
139157
onFilterTypeChange,
140158
}: IHistoryContentProps) => {
141159
const renderItem = useCallback(
@@ -144,11 +162,12 @@ const HistoryContent = ({
144162
item={item}
145163
network={network}
146164
token={item.token?.info}
165+
tokenMap={tokenMap}
147166
provider={provider}
148167
networks={networks}
149168
/>
150169
),
151-
[network, networks, provider],
170+
[network, networks, provider, tokenMap],
152171
);
153172

154173
const renderSectionHeader = useCallback(
@@ -327,6 +346,7 @@ function HistoryList() {
327346
return {
328347
network: historyResp.network,
329348
networks: historyResp.networks,
349+
tokenMap: historyResp.tokenMap,
330350
sections,
331351
filter: historyResp.filter || {},
332352
};
@@ -362,6 +382,7 @@ function HistoryList() {
362382
sections={result.sections}
363383
network={result.network}
364384
networks={result.networks}
385+
tokenMap={result.tokenMap}
365386
filter={result.filter}
366387
provider={provider}
367388
onFilterTypeChange={setFilterType}

packages/kit/src/views/Staking/pages/ProtocolDetails/useHandleActions.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import useAppNavigation from '@onekeyhq/kit/src/hooks/useAppNavigation';
55
import { MorphoBundlerContract } from '@onekeyhq/shared/src/consts/addresses';
66
import { EModalStakingRoutes } from '@onekeyhq/shared/src/routes';
77
import accountUtils from '@onekeyhq/shared/src/utils/accountUtils';
8-
import { EApproveType } from '@onekeyhq/shared/types/staking';
8+
import { EApproveType, EWithdrawType } from '@onekeyhq/shared/types/staking';
99
import type {
1010
IEarnTokenInfo,
1111
IProtocolInfo,
@@ -15,6 +15,7 @@ export const useHandleWithdraw = () => {
1515
const appNavigation = useAppNavigation();
1616
return useCallback(
1717
async ({
18+
withdrawType,
1819
tokenInfo,
1920
protocolInfo,
2021
accountId,
@@ -23,6 +24,7 @@ export const useHandleWithdraw = () => {
2324
provider,
2425
onSuccess,
2526
}: {
27+
withdrawType: EWithdrawType;
2628
protocolInfo?: IProtocolInfo;
2729
tokenInfo?: IEarnTokenInfo;
2830
accountId?: string;
@@ -41,7 +43,10 @@ export const useHandleWithdraw = () => {
4143
if (!stakingConfig) {
4244
throw new Error('Staking config not found');
4345
}
44-
if (stakingConfig.withdrawWithTx) {
46+
if (
47+
withdrawType === EWithdrawType.WithdrawOrder ||
48+
stakingConfig.withdrawWithTx
49+
) {
4550
appNavigation.push(EModalStakingRoutes.WithdrawOptions, {
4651
accountId,
4752
networkId,

packages/kit/src/views/Staking/pages/ProtocolDetails/useHandleClaim.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
IProtocolInfo,
1313
IStakingInfo,
1414
} from '@onekeyhq/shared/types/staking';
15+
import { EClaimType } from '@onekeyhq/shared/types/staking';
1516

1617
import { useUniversalClaim } from '../../hooks/useUniversalHooks';
1718

@@ -32,6 +33,7 @@ export const useHandleClaim = ({
3233
});
3334
return useCallback(
3435
async ({
36+
claimType,
3537
protocolInfo,
3638
tokenInfo,
3739
symbol,
@@ -42,6 +44,7 @@ export const useHandleClaim = ({
4244
stakingInfo,
4345
onSuccess,
4446
}: {
47+
claimType: EClaimType;
4548
protocolInfo?: IProtocolInfo;
4649
tokenInfo?: IEarnTokenInfo;
4750
symbol: string;
@@ -71,7 +74,7 @@ export const useHandleClaim = ({
7174
provider,
7275
stakingInfo,
7376
claimTokenAddress,
74-
vault: protocolInfo?.approve?.approveTarget || '',
77+
vault,
7578
});
7679
return;
7780
}
@@ -102,7 +105,22 @@ export const useHandleClaim = ({
102105
});
103106
return;
104107
}
105-
if (stakingConfig.claimWithTx) {
108+
if (
109+
provider.toLowerCase() === 'everstake' &&
110+
symbol.toLowerCase() === 'apt'
111+
) {
112+
appNavigation.push(EModalStakingRoutes.Claim, {
113+
accountId,
114+
networkId,
115+
protocolInfo,
116+
tokenInfo,
117+
onSuccess,
118+
amount: stakingConfig.claimWithAmount ? claimAmount : undefined,
119+
});
120+
return;
121+
}
122+
123+
if (claimType === EClaimType.ClaimOrder) {
106124
appNavigation.push(EModalStakingRoutes.ClaimOptions, {
107125
accountId,
108126
networkId,
@@ -114,16 +132,29 @@ export const useHandleClaim = ({
114132
return;
115133
}
116134
if (
117-
provider.toLowerCase() === 'everstake' &&
118-
symbol.toLowerCase() === 'apt'
135+
claimType === EClaimType.Claim &&
136+
claimAmount &&
137+
Number(claimAmount) > 0
119138
) {
120-
appNavigation.push(EModalStakingRoutes.Claim, {
139+
await handleUniversalClaim({
140+
amount: claimAmount,
141+
symbol,
142+
provider,
143+
claimTokenAddress,
144+
stakingInfo,
145+
vault,
146+
});
147+
return;
148+
}
149+
150+
if (stakingConfig.claimWithTx) {
151+
appNavigation.push(EModalStakingRoutes.ClaimOptions, {
121152
accountId,
122153
networkId,
123154
protocolInfo,
124155
tokenInfo,
125-
onSuccess,
126-
amount: stakingConfig.claimWithAmount ? claimAmount : undefined,
156+
symbol,
157+
provider,
127158
});
128159
return;
129160
}

0 commit comments

Comments
 (0)