Skip to content

Commit d66d72e

Browse files
Fix/swap limit OK-48308 OK-48314 (#9547)
* fix: swap limit * fix: aptos detect * fix: stellar networkPassphrase params lint
1 parent 973f7d6 commit d66d72e

File tree

11 files changed

+100
-50
lines changed

11 files changed

+100
-50
lines changed

packages/core/src/chains/stellar/CoreChainSoftware.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import { hashMessage } from './utils/message';
2424
import { assembleSignedTransaction } from './utils/signing';
2525
import { extractTransactionHash } from './utils/transaction';
2626

27-
import type { IEncodedTxStellar, IUnsignedMessageStellar } from './types';
27+
import type { IEncodedTxStellar } from './types';
28+
import type { IUnsignedMessageStellar } from '../../types/coreTypesMessage';
2829

2930
const curve: ICurveName = 'ed25519';
3031

@@ -105,10 +106,11 @@ export default class CoreChainSoftware extends CoreChainApiBase {
105106
});
106107

107108
const unsignedMsg = payload.unsignedMsg as IUnsignedMessageStellar;
109+
108110
const messageHash: Buffer = hashMessage({
109111
messageType: unsignedMsg.type,
110112
message: unsignedMsg.message,
111-
networkPassphrase: unsignedMsg.networkPassphrase ?? '',
113+
networkPassphrase: unsignedMsg.payload?.networkPassphrase ?? '',
112114
});
113115
const [signature] = await signer.sign(messageHash);
114116

packages/core/src/chains/stellar/types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,3 @@ export type IEncodedTxStellar = {
3535
// Indicates if transaction is from dApp (should not be modified)
3636
isFromDapp?: boolean;
3737
};
38-
39-
export type IUnsignedMessageStellar = {
40-
type: EMessageTypesStellar;
41-
message: string;
42-
networkPassphrase?: string;
43-
};

packages/kit-bg/src/providers/ProviderApiStellar.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,18 @@ class ProviderApiStellar extends ProviderApiBase {
241241
// const { accountInfo: { accountId, networkId, address } = {} } = (
242242
// await this.getAccountsInfo(request)
243243
// )[0];
244+
// let resolvedNetworkPassphrase = networkPassphrase;
245+
// if (!resolvedNetworkPassphrase) {
246+
// resolvedNetworkPassphrase = getNetworkPassphrase(networkId ?? '');
247+
// }
244248
// const result = (await this.backgroundApi.serviceDApp.openSignMessageModal({
245249
// request,
246250
// unsignedMessage: {
247251
// type: EMessageTypesStellar.SIGN_AUTH_ENTRY,
248252
// message: authEntry,
249-
// networkPassphrase: networkPassphrase ?? '',
253+
// payload: {
254+
// networkPassphrase: resolvedNetworkPassphrase,
255+
// },
250256
// },
251257
// accountId: accountId ?? '',
252258
// networkId: networkId ?? '',
@@ -264,7 +270,7 @@ class ProviderApiStellar extends ProviderApiBase {
264270
): Promise<ISignMessageResult> {
265271
defaultLogger.discovery.dapp.dappRequest({ request });
266272

267-
const { message, networkPassphrase } = params;
273+
const { message } = params;
268274

269275
if (!message) {
270276
throw web3Errors.rpc.invalidParams('Message is required');
@@ -279,9 +285,6 @@ class ProviderApiStellar extends ProviderApiBase {
279285
unsignedMessage: {
280286
type: EMessageTypesStellar.SIGN_MESSAGE,
281287
message,
282-
payload: {
283-
networkPassphrase,
284-
},
285288
},
286289
accountId: accountId ?? '',
287290
networkId: networkId ?? '',

packages/kit-bg/src/services/ServiceAccount/ServiceAccount.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5488,12 +5488,18 @@ class ServiceAccount extends ServiceBase {
54885488
accountImpl,
54895489
featuresInfoCache,
54905490
activeNetworkId,
5491+
limitOptions = {
5492+
allowWatchingWallet: true,
5493+
},
54915494
}: {
54925495
accountId?: string;
54935496
walletId?: string;
54945497
accountImpl?: string;
54955498
featuresInfoCache?: IOneKeyDeviceFeatures;
54965499
activeNetworkId: string;
5500+
limitOptions?: {
5501+
allowWatchingWallet?: boolean;
5502+
};
54975503
}): Promise<
54985504
| {
54995505
networkImpl: string;
@@ -5513,15 +5519,21 @@ class ServiceAccount extends ServiceBase {
55135519
finalWalletId = accountUtils.getWalletIdFromAccountId({ accountId });
55145520
}
55155521

5516-
// Early returns for watching wallet
5517-
if (finalWalletId === WALLET_TYPE_WATCHING) {
5518-
return undefined;
5519-
}
5520-
55215522
const { impl: activeNetworkImpl } = networkUtils.parseNetworkId({
55225523
networkId: activeNetworkId ?? '',
55235524
});
55245525

5526+
// Early returns for watching wallet
5527+
if (accountUtils.isWatchingWallet({ walletId: finalWalletId })) {
5528+
if (limitOptions?.allowWatchingWallet) {
5529+
return undefined;
5530+
}
5531+
5532+
return {
5533+
networkImpl: activeNetworkImpl,
5534+
};
5535+
}
5536+
55255537
// other account maybe not have accountId only have walletId
55265538
if (accountId && accountUtils.isOthersAccount({ accountId })) {
55275539
let currentAccountImpl = accountImpl;

packages/kit-bg/src/vaults/impls/stellar/Vault.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
import BigNumber from 'bignumber.js';
33
import { md5 } from 'js-md5';
44
import { isEmpty, isNaN, orderBy } from 'lodash';
5+
6+
import type {
7+
IEncodedTxStellar,
8+
IStellarAsset,
9+
} from '@onekeyhq/core/src/chains/stellar/types';
510
import coreChainApi from '@onekeyhq/core/src/instance/coreChainApi';
611
import {
712
decodeSensitiveTextAsync,
@@ -21,11 +26,6 @@ import { ETranslations } from '@onekeyhq/shared/src/locale';
2126
import bufferUtils from '@onekeyhq/shared/src/utils/bufferUtils';
2227
import { memoizee } from '@onekeyhq/shared/src/utils/cacheUtils';
2328
import timerUtils from '@onekeyhq/shared/src/utils/timerUtils';
24-
25-
import type {
26-
IEncodedTxStellar,
27-
IStellarAsset,
28-
} from '@onekeyhq/core/src/chains/stellar/types';
2929
import type {
3030
IAddressValidation,
3131
IFetchServerAccountDetailsParams,
@@ -41,8 +41,8 @@ import type {
4141
IMeasureRpcStatusResult,
4242
} from '@onekeyhq/shared/types/customRpc';
4343
import type {
44-
IServerEstimateFeeResponse,
4544
IFeeInfoUnit,
45+
IServerEstimateFeeResponse,
4646
} from '@onekeyhq/shared/types/fee';
4747
import type {
4848
IFetchServerTokenDetailParams,

packages/kit/src/components/AccountSelector/hooks/useAutoSelectAccount.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import {
1010
EAccountSelectorSceneName,
1111
} from '@onekeyhq/shared/types';
1212

13-
import { deferHeavyWorkUntilUIIdle } from '../../../utils/deferHeavyWork';
1413
import {
1514
useAccountSelectorActions,
1615
useAccountSelectorSceneInfo,
1716
useAccountSelectorStorageReadyAtom,
1817
useActiveAccount,
1918
} from '../../../states/jotai/contexts/accountSelector';
19+
import { deferHeavyWorkUntilUIIdle } from '../../../utils/deferHeavyWork';
2020

2121
export function useAutoSelectAccount({ num }: { num: number }) {
2222
const {

packages/kit/src/states/jotai/contexts/swap/actions.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,30 @@ class ContentJotaiActionsSwap extends ContextJotaiActionsBase {
11501150
return;
11511151
}
11521152

1153+
if (
1154+
fromToken &&
1155+
!swapFromAddressInfo.address &&
1156+
!accountUtils.isHdWallet({
1157+
walletId: swapFromAddressInfo.accountInfo?.wallet?.id,
1158+
}) &&
1159+
!accountUtils.isHwWallet({
1160+
walletId: swapFromAddressInfo.accountInfo?.wallet?.id,
1161+
}) &&
1162+
!accountUtils.isQrWallet({
1163+
walletId: swapFromAddressInfo.accountInfo?.wallet?.id,
1164+
})
1165+
) {
1166+
alertsRes = [
1167+
...alertsRes,
1168+
{
1169+
message: appLocale.intl.formatMessage({
1170+
id: ETranslations.swap_page_alert_account_does_not_support_swap,
1171+
}),
1172+
alertLevel: ESwapAlertLevel.ERROR,
1173+
},
1174+
];
1175+
}
1176+
11531177
if (fromToken && swapFromAddressInfo.accountInfo?.wallet?.id) {
11541178
const needCheck =
11551179
!swapFromAddressInfo.address ||

packages/kit/src/views/Home/pages/HomePageView.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
22

3-
import { useIntl } from 'react-intl';
4-
53
import { CanceledError } from 'axios';
4+
import { useIntl } from 'react-intl';
65

76
import type { ITabContainerRef } from '@onekeyhq/components';
87
import {
@@ -203,17 +202,18 @@ export function HomePageView({
203202
if (cancelled) return;
204203

205204
try {
206-
const resp = await backgroundApiProxy.serviceApproval.fetchAccountApprovals(
207-
{
205+
const resp =
206+
await backgroundApiProxy.serviceApproval.fetchAccountApprovals({
208207
networkId: network.id,
209208
accountId: account.id,
210209
indexedAccountId: indexedAccount?.id,
211210
accountAddress: account.address,
212-
},
213-
);
211+
});
214212
if (cancelled) return;
215213
updateApprovalsInfo({
216-
hasRiskApprovals: resp.contractApprovals.some((i) => i.isRiskContract),
214+
hasRiskApprovals: resp.contractApprovals.some(
215+
(i) => i.isRiskContract,
216+
),
217217
});
218218
} catch (error) {
219219
if (error instanceof CanceledError) {

packages/kit/src/views/Home/pages/TokenListContainer.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,24 +1932,24 @@ function TokenListContainer({
19321932
]);
19331933

19341934
return (
1935-
<TokenListView
1936-
withHeader
1937-
withFooter
1938-
withPrice
1939-
inTabList
1940-
hideValue
1941-
withSwapAction
1942-
accountId={account?.id ?? ''}
1943-
networkId={network?.id ?? ''}
1944-
indexedAccountId={indexedAccount?.id ?? ''}
1945-
allAggregateTokenMap={allAggregateTokenMap}
1946-
showNetworkIcon={!!network?.isAllNetworks}
1947-
hideZeroBalanceTokens={!!network?.isAllNetworks}
1948-
deferTokenManagement={!!network?.isAllNetworks}
1949-
onRefresh={onHomePageRefresh}
1950-
manageTokenEnabled={manageTokenEnabled}
1951-
onManageToken={handleOnManageToken}
1952-
onPressToken={handleOnPressToken}
1935+
<TokenListView
1936+
withHeader
1937+
withFooter
1938+
withPrice
1939+
inTabList
1940+
hideValue
1941+
withSwapAction
1942+
accountId={account?.id ?? ''}
1943+
networkId={network?.id ?? ''}
1944+
indexedAccountId={indexedAccount?.id ?? ''}
1945+
allAggregateTokenMap={allAggregateTokenMap}
1946+
showNetworkIcon={!!network?.isAllNetworks}
1947+
hideZeroBalanceTokens={!!network?.isAllNetworks}
1948+
deferTokenManagement={!!network?.isAllNetworks}
1949+
onRefresh={onHomePageRefresh}
1950+
manageTokenEnabled={manageTokenEnabled}
1951+
onManageToken={handleOnManageToken}
1952+
onPressToken={handleOnPressToken}
19531953
isAllNetworks={network?.isAllNetworks}
19541954
homeDefaultTokenMap={homeDefaultTokenMap}
19551955
{...(media.gtLg && {

packages/shared/src/utils/networkDetectUtils.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,17 @@ describe('Network Detection by Private Key', () => {
234234
);
235235
});
236236

237+
test('detects Aptos (ed25519-priv-0x-prefixed)', async () => {
238+
const privateKey =
239+
'ed25519-priv-0x25cb5c737d8bff654fc62a6af4b00224f3a4b5c963a898a7e8ea9f08cbda5b2a';
240+
const result = await networkDetectUtils.detectNetworkByPrivateKey({
241+
privateKey,
242+
});
243+
expect(result.networks).toContainEqual(
244+
networkDetectUtils.buildDetectedNetwork(presetNetworksMap.aptos),
245+
);
246+
});
247+
237248
test('detects Sui (0x-prefixed)', async () => {
238249
const privateKey =
239250
'0x644fedb8ebfec83d4a1cc983beb499048f8199bf72c8e8e57d5775603b8c5dd1';

0 commit comments

Comments
 (0)