@subwallet/extension-base 1.2.26-0 → 1.2.28-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/background/KoniTypes.d.ts +7 -8
  2. package/cjs/constants/index.js +6 -3
  3. package/cjs/core/logic-validation/request.js +160 -23
  4. package/cjs/core/substrate/assets-pallet.js +34 -18
  5. package/cjs/core/substrate/foreign-asset-pallet.js +2 -9
  6. package/cjs/core/substrate/xcm-parser.js +2 -1
  7. package/cjs/koni/api/staking/bonding/utils.js +1 -0
  8. package/cjs/koni/background/handlers/State.js +35 -66
  9. package/cjs/koni/background/handlers/Tabs.js +96 -23
  10. package/cjs/packageInfo.js +1 -1
  11. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +21 -1
  12. package/cjs/services/chain-service/index.js +1 -1
  13. package/cjs/services/earning-service/constants/chains.js +1 -3
  14. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +31 -25
  15. package/cjs/services/earning-service/handlers/nomination-pool/index.js +1 -2
  16. package/cjs/services/mkt-campaign-service/index.js +30 -6
  17. package/cjs/services/request-service/handler/EvmRequestHandler.js +0 -1
  18. package/cjs/services/wallet-connect-service/index.js +25 -1
  19. package/constants/index.d.ts +1 -0
  20. package/constants/index.js +1 -0
  21. package/core/logic-validation/request.d.ts +22 -1
  22. package/core/logic-validation/request.js +154 -23
  23. package/core/substrate/assets-pallet.d.ts +7 -3
  24. package/core/substrate/assets-pallet.js +29 -17
  25. package/core/substrate/foreign-asset-pallet.d.ts +3 -3
  26. package/core/substrate/foreign-asset-pallet.js +2 -9
  27. package/core/substrate/types.d.ts +5 -1
  28. package/core/substrate/xcm-parser.js +2 -1
  29. package/koni/api/staking/bonding/utils.js +1 -0
  30. package/koni/background/handlers/State.d.ts +0 -1
  31. package/koni/background/handlers/State.js +19 -49
  32. package/koni/background/handlers/Tabs.d.ts +1 -0
  33. package/koni/background/handlers/Tabs.js +77 -6
  34. package/package.json +13 -11
  35. package/packageInfo.js +1 -1
  36. package/services/balance-service/helpers/subscribe/substrate/index.js +22 -2
  37. package/services/chain-service/index.js +1 -1
  38. package/services/earning-service/constants/chains.d.ts +0 -1
  39. package/services/earning-service/constants/chains.js +0 -1
  40. package/services/earning-service/handlers/native-staking/relay-chain.js +32 -26
  41. package/services/earning-service/handlers/nomination-pool/index.js +1 -2
  42. package/services/mkt-campaign-service/index.js +30 -6
  43. package/services/mkt-campaign-service/types.d.ts +2 -0
  44. package/services/request-service/handler/EvmRequestHandler.js +0 -1
  45. package/services/wallet-connect-service/index.js +24 -1
  46. package/types/yield/info/chain/target.d.ts +4 -0
@@ -1,7 +1,8 @@
1
- import { ConfirmationType } from '@subwallet/extension-base/background/KoniTypes';
1
+ import { ConfirmationType, ErrorValidation } from '@subwallet/extension-base/background/KoniTypes';
2
2
  import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
3
3
  import { AuthUrlInfo } from '@subwallet/extension-base/services/request-service/types';
4
4
  import { KeyringPair } from '@subwallet/keyring/types';
5
+ import Joi from 'joi';
5
6
  export declare type ValidateStepFunction = (koni: KoniState, url: string, payload: PayloadValidated, topic?: string) => Promise<PayloadValidated>;
6
7
  export interface PayloadValidated {
7
8
  networkKey: string;
@@ -14,6 +15,25 @@ export interface PayloadValidated {
14
15
  confirmationType?: ConfirmationType;
15
16
  errors: Error[];
16
17
  }
18
+ export declare type SignTypedDataMessageV3V4 = {
19
+ types: Record<string, unknown>;
20
+ domain: Record<string, unknown>;
21
+ primaryType: string;
22
+ message: unknown;
23
+ };
24
+ export declare type DataMessageParam = Record<string, unknown>[] | string | SignTypedDataMessageV3V4;
25
+ export interface TypedMessageParams {
26
+ from: string;
27
+ data: DataMessageParam;
28
+ }
29
+ export interface PersonalMessageParams {
30
+ data: string;
31
+ from: string;
32
+ }
33
+ export declare const joiValidate: Joi.ObjectSchema<any>;
34
+ export declare function validateSignMessageData(messageData: PersonalMessageParams): string;
35
+ export declare function validateTypedSignMessageDataV1(messageData: TypedMessageParams): Record<string, unknown>[];
36
+ export declare function validateTypedSignMessageDataV3V4(messageData: TypedMessageParams): SignTypedDataMessageV3V4;
17
37
  export declare function generateValidationProcess(koni: KoniState, url: string, payloadValidate: PayloadValidated, validationMiddlewareSteps: ValidateStepFunction[], topic?: string): Promise<PayloadValidated>;
18
38
  export declare function validationAuthMiddleware(koni: KoniState, url: string, payload: PayloadValidated): Promise<PayloadValidated>;
19
39
  export declare function validationConnectMiddleware(koni: KoniState, url: string, payload: PayloadValidated): Promise<PayloadValidated>;
@@ -21,3 +41,4 @@ export declare function validationEvmDataTransactionMiddleware(koni: KoniState,
21
41
  export declare function validationEvmSignMessageMiddleware(koni: KoniState, url: string, payload_: PayloadValidated): Promise<PayloadValidated>;
22
42
  export declare function validationAuthWCMiddleware(koni: KoniState, url: string, payload: PayloadValidated, topic?: string): Promise<PayloadValidated>;
23
43
  export declare function convertErrorMessage(message_: string, name?: string): string[];
44
+ export declare function convertErrorFormat(errors: Error[]): ErrorValidation[];
@@ -1,6 +1,7 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { typedSignatureHash } from '@metamask/eth-sig-util';
4
5
  import { EvmProviderError } from '@subwallet/extension-base/background/errors/EvmProviderError';
5
6
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
6
7
  import { BasicTxErrorType, EvmProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
@@ -12,8 +13,105 @@ import { getSdkError } from '@walletconnect/utils';
12
13
  import BigN from 'bignumber.js';
13
14
  import BN from 'bn.js';
14
15
  import { t } from 'i18next';
16
+ import Joi from 'joi';
15
17
  import { isString } from '@polkadot/util';
16
18
  import { isEthereumAddress } from '@polkadot/util-crypto';
19
+ export const joiValidate = Joi.object({
20
+ types: Joi.object().pattern(Joi.string(),
21
+ // Key của object types
22
+ Joi.array().items(Joi.object({
23
+ name: Joi.string().required(),
24
+ type: Joi.string().required()
25
+ }))).required(),
26
+ primaryType: Joi.string().required(),
27
+ domain: Joi.object().required(),
28
+ message: Joi.object().required()
29
+ });
30
+ function validateAddress(address, propertyName) {
31
+ if (!address || typeof address !== 'string' || !isEthereumAddress(address)) {
32
+ throw new Error(`Invalid "${propertyName}" address: ${address} must be a valid string.`);
33
+ }
34
+ }
35
+ export function validateSignMessageData(messageData) {
36
+ const {
37
+ data,
38
+ from
39
+ } = messageData;
40
+ validateAddress(from, 'from');
41
+ if (!data || typeof data !== 'string') {
42
+ throw new Error(`Invalid message "data": ${data} must be a valid string.`);
43
+ }
44
+ return data;
45
+ }
46
+ export function validateTypedSignMessageDataV1(messageData) {
47
+ validateAddress(messageData.from, 'from');
48
+ if (!messageData.data || !Array.isArray(messageData.data)) {
49
+ throw new Error(
50
+ // TODO: Either fix this lint violation or explain why it's necessary to ignore.
51
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
52
+ `Invalid message "data": ${messageData.data} must be a valid array.`);
53
+ }
54
+ try {
55
+ // typedSignatureHash will throw if the data is invalid.
56
+ // TODO: Replace `any` with type
57
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
+ typedSignatureHash(messageData.data);
59
+ return messageData.data;
60
+ } catch (e) {
61
+ throw new Error('Invalid message "data": Expected EIP712 typed data.');
62
+ }
63
+ }
64
+ export function validateTypedSignMessageDataV3V4(messageData) {
65
+ validateAddress(messageData.from, 'from');
66
+ if (!messageData.data || Array.isArray(messageData.data) || typeof messageData.data !== 'object' && typeof messageData.data !== 'string') {
67
+ throw new Error('Invalid message "data": Must be a valid string or object.');
68
+ }
69
+ let data;
70
+ if (typeof messageData.data === 'object') {
71
+ data = messageData.data;
72
+ } else {
73
+ try {
74
+ data = JSON.parse(messageData.data);
75
+ } catch (e) {
76
+ throw new Error('Invalid message "data" must be passed as a valid JSON string.');
77
+ }
78
+ }
79
+ const validation = joiValidate.validate(data);
80
+ if (validation.error) {
81
+ throw new Error('Invalid message "data" must conform to EIP-712 schema. See https://git.io/fNtcx.');
82
+ }
83
+
84
+ // if (!currentChainId) {
85
+ // throw new Error('Current chainId cannot be null or undefined.');
86
+ // }
87
+
88
+ // let { chainId } = data.domain;
89
+ //
90
+ // if (chainId) {
91
+ // if (typeof chainId === 'string') {
92
+ // chainId = parseInt(chainId, chainId.startsWith('0x') ? 16 : 10);
93
+ // }
94
+ //
95
+ // const activeChainId = parseInt(currentChainId, 16);
96
+ //
97
+ // if (Number.isNaN(activeChainId)) {
98
+ // throw new Error(
99
+ // // TODO: Either fix this lint violation or explain why it's necessary to ignore.
100
+ // // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
101
+ // `Cannot sign messages for chainId "${chainId}", because MetaMask is switching networks.`
102
+ // );
103
+ // }
104
+ //
105
+ // if (chainId !== activeChainId) {
106
+ // throw new Error(
107
+ // // TODO: Either fix this lint violation or explain why it's necessary to ignore.
108
+ // // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
109
+ // `Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`
110
+ // );
111
+ // }
112
+ // }
113
+ return data;
114
+ }
17
115
  export async function generateValidationProcess(koni, url, payloadValidate, validationMiddlewareSteps, topic) {
18
116
  let resultValidated = payloadValidate;
19
117
  for (const step of validationMiddlewareSteps) {
@@ -315,7 +413,7 @@ export async function validationEvmSignMessageMiddleware(koni, url, payload_) {
315
413
  const [message, name] = convertErrorMessage(message_);
316
414
  const error = new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, message, undefined, name);
317
415
  console.error(error);
318
- errors.push(new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, message, undefined, name));
416
+ errors.push(error);
319
417
  };
320
418
  if (address === '' || !payload) {
321
419
  handleError('Not found address or payload to sign');
@@ -329,26 +427,47 @@ export async function validationEvmSignMessageMiddleware(koni, url, payload_) {
329
427
  if (['eth_sign', 'personal_sign', 'eth_signTypedData', 'eth_signTypedData_v1', 'eth_signTypedData_v3', 'eth_signTypedData_v4'].indexOf(method) < 0) {
330
428
  handleError('Unsupported action');
331
429
  }
332
- if (['eth_signTypedData_v3', 'eth_signTypedData_v4'].indexOf(method) > -1) {
333
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-assignment
334
- payload = JSON.parse(payload);
335
- }
336
- switch (method) {
337
- case 'personal_sign':
338
- canSign = true;
339
- hashPayload = payload;
340
- break;
341
- case 'eth_sign':
342
- case 'eth_signTypedData':
343
- case 'eth_signTypedData_v1':
344
- case 'eth_signTypedData_v3':
345
- case 'eth_signTypedData_v4':
346
- if (!account.isExternal) {
430
+ try {
431
+ switch (method) {
432
+ case 'personal_sign':
347
433
  canSign = true;
348
- }
349
- break;
350
- default:
351
- handleError('Unsupported action');
434
+ payload = validateSignMessageData({
435
+ data: payload,
436
+ from: address
437
+ });
438
+ hashPayload = payload;
439
+ break;
440
+ case 'eth_sign':
441
+ if (!account.isExternal) {
442
+ canSign = true;
443
+ }
444
+ break;
445
+ case 'eth_signTypedData':
446
+ case 'eth_signTypedData_v1':
447
+ if (!account.isExternal) {
448
+ canSign = true;
449
+ }
450
+ payload = validateTypedSignMessageDataV1({
451
+ data: payload,
452
+ from: address
453
+ });
454
+ break;
455
+ case 'eth_signTypedData_v3':
456
+ case 'eth_signTypedData_v4':
457
+ if (!account.isExternal) {
458
+ canSign = true;
459
+ }
460
+ payload = validateTypedSignMessageDataV3V4({
461
+ data: payload,
462
+ from: address
463
+ });
464
+ break;
465
+ default:
466
+ throw new Error('Unsupported action');
467
+ }
468
+ } catch (e) {
469
+ console.error(e);
470
+ handleError(e.message);
352
471
  }
353
472
  } else {
354
473
  handleError('Unsupported method');
@@ -429,7 +548,7 @@ export function convertErrorMessage(message_, name) {
429
548
  return [t('Re-enable the network or change RPC on the extension and try again'), t('Unstable network connection')];
430
549
  }
431
550
  if (message.includes('network is currently not supported')) {
432
- return [t('This network is not yet supported on SubWallet. |Import the network|https://docs.subwallet.app/main/extension-user-guide/customize-your-networks#import-networks| on SubWallet and try again'), t('Network not supported')];
551
+ return [t('This network is not yet supported on SubWallet. (Import the network)[https://docs.subwallet.app/main/extension-user-guide/customize-your-networks#import-networks] on SubWallet and try again'), t('Network not supported')];
433
552
  }
434
553
 
435
554
  // Authentication
@@ -466,10 +585,22 @@ export function convertErrorMessage(message_, name) {
466
585
 
467
586
  // Sign Message
468
587
  if (message.includes('not found address or payload to sign')) {
469
- return [t('An error occurred when signing this request. Try again or contact support at agent@subwallet.app'), t('Unable to sign message')];
588
+ return [t('An error occurred when signing this request. Try again or contact support at agent@subwallet.app'), t('Unable to sign')];
470
589
  }
471
590
  if (message.includes('unsupported method') || message.includes('unsupported action')) {
472
591
  return [t('This sign method is not supported by SubWallet. Try again or contact support at agent@subwallet.app'), t('Method not supported')];
473
592
  }
474
- return [message, name || ''];
593
+ if (message.includes('eip712 typed data') || message.includes('invalid message')) {
594
+ return [t('An error occurred when attempting to sign this request. Contact support at email: agent@subwallet.app'), t('Unable to sign')];
595
+ }
596
+ return [message, name || 'Error'];
597
+ }
598
+ export function convertErrorFormat(errors) {
599
+ if (errors.length > 0) {
600
+ return [{
601
+ name: errors[0].name,
602
+ message: errors[0].message
603
+ }];
604
+ }
605
+ return [];
475
606
  }
@@ -1,4 +1,8 @@
1
1
  import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
- import { PalletAssetsAssetAccount } from '@subwallet/extension-base/core/substrate/types';
3
- export declare function _getAssetsPalletTransferable(accountInfo: PalletAssetsAssetAccount | undefined, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
4
- export declare function _getAssetsPalletLockedBalance(accountInfo: PalletAssetsAssetAccount | undefined): bigint;
2
+ import { PalletAssetsAssetAccount, PalletAssetsAssetAccountWithoutStatus, PalletAssetsAssetAccountWithStatus } from '@subwallet/extension-base/core/substrate/types';
3
+ export declare function _getAssetsPalletTransferable(accountInfo: PalletAssetsAssetAccount, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
4
+ export declare function _getAssetsPalletLocked(accountInfo: PalletAssetsAssetAccount): bigint;
5
+ export declare function _getAssetsPalletTransferableWithStatus(accountInfo: PalletAssetsAssetAccountWithStatus, existentialDeposit: string, strictMode?: boolean): bigint;
6
+ export declare function _getAssetsPalletTransferableWithoutStatus(accountInfo: PalletAssetsAssetAccountWithoutStatus, existentialDeposit: string, strictMode?: boolean): bigint;
7
+ export declare function _getAssetsPalletLockedWithStatus(accountInfo: PalletAssetsAssetAccountWithStatus): bigint;
8
+ export declare function _getAssetsPalletLockedWithoutStatus(accountInfo: PalletAssetsAssetAccountWithoutStatus): bigint;
@@ -3,26 +3,38 @@
3
3
 
4
4
  import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
5
5
  import { _getAppliedExistentialDeposit, getStrictMode } from '@subwallet/extension-base/core/utils';
6
+ function isWithStatus(accountInfo) {
7
+ return accountInfo.status !== undefined && accountInfo.isFrozen === undefined;
8
+ }
6
9
  export function _getAssetsPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
7
10
  const strictMode = getStrictMode(BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
8
- const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
9
- let bnTransferable = BigInt(0);
10
- if (!accountInfo) {
11
- return BigInt(0);
12
- }
13
- if (['Liquid'].includes(accountInfo.status)) {
14
- bnTransferable = BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
11
+ if (isWithStatus(accountInfo)) {
12
+ return _getAssetsPalletTransferableWithStatus(accountInfo, existentialDeposit, strictMode);
13
+ } else {
14
+ return _getAssetsPalletTransferableWithoutStatus(accountInfo, existentialDeposit, strictMode);
15
15
  }
16
- return bnTransferable;
17
16
  }
18
- export function _getAssetsPalletLockedBalance(accountInfo) {
19
- let bnLocked = BigInt(0);
20
- if (!accountInfo) {
21
- return bnLocked;
17
+ export function _getAssetsPalletLocked(accountInfo) {
18
+ if (isWithStatus(accountInfo)) {
19
+ return _getAssetsPalletLockedWithStatus(accountInfo);
20
+ } else {
21
+ return _getAssetsPalletLockedWithoutStatus(accountInfo);
22
22
  }
23
- if (!['Liquid'].includes(accountInfo.status)) {
24
- // todo: check case accountInfo has isFrozen?
25
- bnLocked = BigInt(accountInfo.balance);
26
- }
27
- return bnLocked;
23
+ }
24
+
25
+ // ----------------------------------------------------------------------
26
+
27
+ export function _getAssetsPalletTransferableWithStatus(accountInfo, existentialDeposit, strictMode) {
28
+ const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
29
+ return accountInfo.status === 'Liquid' ? BigInt(accountInfo.balance) - bnAppliedExistentialDeposit : BigInt(0);
30
+ }
31
+ export function _getAssetsPalletTransferableWithoutStatus(accountInfo, existentialDeposit, strictMode) {
32
+ const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
33
+ return !accountInfo.isFrozen ? BigInt(accountInfo.balance) - bnAppliedExistentialDeposit : BigInt(0);
34
+ }
35
+ export function _getAssetsPalletLockedWithStatus(accountInfo) {
36
+ return accountInfo.status !== 'Liquid' ? BigInt(accountInfo.balance) : BigInt(0);
37
+ }
38
+ export function _getAssetsPalletLockedWithoutStatus(accountInfo) {
39
+ return accountInfo.isFrozen ? BigInt(accountInfo.balance) : BigInt(0);
28
40
  }
@@ -1,4 +1,4 @@
1
1
  import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
- import { PalletAssetsAssetAccount } from '@subwallet/extension-base/core/substrate/types';
3
- export declare function _getForeignAssetPalletTransferable(accountInfo: PalletAssetsAssetAccount | undefined, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
4
- export declare function _getForeignAssetPalletLockedBalance(accountInfo: PalletAssetsAssetAccount | undefined): bigint;
2
+ import { PalletAssetsAssetAccountWithStatus } from '@subwallet/extension-base/core/substrate/types';
3
+ export declare function _getForeignAssetPalletTransferable(accountInfo: PalletAssetsAssetAccountWithStatus, existentialDeposit: string, extrinsicType?: ExtrinsicType): bigint;
4
+ export declare function _getForeignAssetPalletLockedBalance(accountInfo: PalletAssetsAssetAccountWithStatus): bigint;
@@ -5,15 +5,8 @@ import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/typ
5
5
  import { _getAppliedExistentialDeposit, getStrictMode } from '@subwallet/extension-base/core/utils';
6
6
  export function _getForeignAssetPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
7
7
  const strictMode = getStrictMode(BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
8
- if (!accountInfo || accountInfo.status !== 'Liquid') {
9
- return BigInt(0);
10
- }
11
- const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(existentialDeposit, strictMode);
12
- return BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
8
+ return accountInfo.status === 'Liquid' ? BigInt(accountInfo.balance) - _getAppliedExistentialDeposit(existentialDeposit, strictMode) : BigInt(0);
13
9
  }
14
10
  export function _getForeignAssetPalletLockedBalance(accountInfo) {
15
- if (!accountInfo || accountInfo.status === 'Liquid') {
16
- return BigInt(0);
17
- }
18
- return BigInt(accountInfo.balance);
11
+ return accountInfo.status !== 'Liquid' ? BigInt(accountInfo.balance) : BigInt(0);
19
12
  }
@@ -24,12 +24,16 @@ export declare type OrmlTokensAccountData = {
24
24
  reserved: number;
25
25
  frozen: number;
26
26
  };
27
- export declare type PalletAssetsAssetAccount = {
27
+ export declare type PalletAssetsAssetAccountWithStatus = {
28
28
  balance: number | string;
29
29
  status: 'Frozen' | 'Liquid' | 'Blocked';
30
30
  reason: Record<string, unknown>;
31
31
  extra: unknown;
32
32
  };
33
+ export declare type PalletAssetsAssetAccountWithoutStatus = Omit<PalletAssetsAssetAccountWithStatus, 'status'> & {
34
+ isFrozen: boolean;
35
+ };
36
+ export declare type PalletAssetsAssetAccount = PalletAssetsAssetAccountWithStatus | PalletAssetsAssetAccountWithoutStatus;
33
37
  export declare type PalletNominationPoolsPoolMember = {
34
38
  poolId: number;
35
39
  points: number;
@@ -195,7 +195,8 @@ function _getAssetIdentifier(tokenInfo, version) {
195
195
  if (!_assetIdentifier) {
196
196
  throw new Error('Asset must have multilocation');
197
197
  }
198
- const assetIdentifier = _adaptX1Interior(structuredClone(_assetIdentifier), version);
198
+ const assetIdentifier = ['statemint-LOCAL-KSM'].includes(tokenInfo.slug) // todo: hotfix for ksm statemint recheck all chain
199
+ ? _assetIdentifier : _adaptX1Interior(structuredClone(_assetIdentifier), version);
199
200
  return version >= 4 // from V4, Concrete is removed
200
201
  ? assetIdentifier : {
201
202
  Concrete: assetIdentifier
@@ -103,6 +103,7 @@ export function calculateTernoaValidatorReturn(rewardPerValidator, validatorStak
103
103
  export function calculateValidatorStakedReturn(chainStakedReturn, totalValidatorStake, avgStake, commission) {
104
104
  const bnAdjusted = avgStake.mul(BN_HUNDRED).div(totalValidatorStake);
105
105
  const adjusted = bnAdjusted.toNumber() * chainStakedReturn;
106
+ // todo: should calculated in bignumber instead number?
106
107
  const stakedReturn = (adjusted > Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : adjusted) / 100;
107
108
  return stakedReturn * (100 - commission) / 100; // Deduct commission
108
109
  }
@@ -145,7 +145,6 @@ export default class KoniState {
145
145
  setCurrentAccount(data: CurrentAccountInfo, callback?: () => void, preventOneAccount?: boolean): void;
146
146
  setAccountTie(address: string, genesisHash: string | null): boolean;
147
147
  switchEvmNetworkByUrl(shortenUrl: string, networkKey: string): Promise<void>;
148
- switchNetworkAccount(id: string, url: string, networkKey: string, changeAddress?: string): Promise<boolean>;
149
148
  addNetworkConfirm(id: string, url: string, networkData: _NetworkUpsertParams): Promise<null>;
150
149
  addTokenConfirm(id: string, url: string, tokenInfo: AddTokenRequestExternal): Promise<true>;
151
150
  get metaSubject(): BehaviorSubject<import("@subwallet/extension-base/background/types").MetadataRequest[]>;
@@ -6,7 +6,7 @@ import { withErrorLog } from '@subwallet/extension-base/background/handlers/help
6
6
  import { isSubscriptionRunning, unsubscribe } from '@subwallet/extension-base/background/handlers/subscriptions';
7
7
  import { APIItemState, BasicTxErrorType, ChainType, EvmProviderErrorType, ExternalRequestPromiseStatus, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
8
8
  import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, MANTA_PAY_BALANCE_INTERVAL, REMIND_EXPORT_ACCOUNT } from '@subwallet/extension-base/constants';
9
- import { generateValidationProcess, validationAuthMiddleware, validationAuthWCMiddleware, validationConnectMiddleware, validationEvmDataTransactionMiddleware, validationEvmSignMessageMiddleware } from '@subwallet/extension-base/core/logic-validation';
9
+ import { convertErrorFormat, generateValidationProcess, validationAuthMiddleware, validationAuthWCMiddleware, validationConnectMiddleware, validationEvmDataTransactionMiddleware, validationEvmSignMessageMiddleware } from '@subwallet/extension-base/core/logic-validation';
10
10
  import { BalanceService } from '@subwallet/extension-base/services/balance-service';
11
11
  import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
12
12
  import BuyService from '@subwallet/extension-base/services/buy-service';
@@ -35,7 +35,7 @@ import TransactionService from '@subwallet/extension-base/services/transaction-s
35
35
  import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
36
36
  import { SWStorage } from '@subwallet/extension-base/storage';
37
37
  import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
38
- import { isAccountAll, stripUrl, targetIsWeb } from '@subwallet/extension-base/utils';
38
+ import { isAccountAll, isManifestV3, stripUrl, targetIsWeb } from '@subwallet/extension-base/utils';
39
39
  import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
40
40
  import { decodePair } from '@subwallet/keyring/pair/decode';
41
41
  import { keyring } from '@subwallet/ui-keyring';
@@ -548,44 +548,6 @@ export default class KoniState {
548
548
  }));
549
549
  }
550
550
  }
551
- async switchNetworkAccount(id, url, networkKey, changeAddress) {
552
- const chainInfo = this.chainService.getChainInfoByKey(networkKey);
553
- const chainState = this.chainService.getChainStateByKey(networkKey);
554
- const {
555
- address,
556
- currentGenesisHash
557
- } = this.keyringService.currentAccount;
558
- return this.requestService.addConfirmation(id, url, 'switchNetworkRequest', {
559
- networkKey,
560
- address: changeAddress
561
- }, {
562
- address: changeAddress
563
- }).then(({
564
- isApproved
565
- }) => {
566
- if (isApproved) {
567
- const useAddress = changeAddress || address;
568
- if (chainInfo && !_isChainEnabled(chainState)) {
569
- this.enableChain(networkKey).catch(console.error);
570
- }
571
- if (useAddress !== ALL_ACCOUNT_KEY) {
572
- const pair = keyring.getPair(useAddress);
573
- assert(pair, t('Unable to find account'));
574
- keyring.saveAccountMeta(pair, {
575
- ...pair.meta,
576
- genesisHash: _getSubstrateGenesisHash(chainInfo)
577
- });
578
- }
579
- if (address !== changeAddress || _getSubstrateGenesisHash(chainInfo) !== currentGenesisHash || isApproved) {
580
- this.setCurrentAccount({
581
- address: useAddress,
582
- currentGenesisHash: _getSubstrateGenesisHash(chainInfo)
583
- });
584
- }
585
- }
586
- return isApproved;
587
- });
588
- }
589
551
  async addNetworkConfirm(id, url, networkData) {
590
552
  return this.requestService.addConfirmation(id, url, 'addNetworkRequest', networkData).then(async ({
591
553
  isApproved
@@ -1098,9 +1060,10 @@ export default class KoniState {
1098
1060
  };
1099
1061
  const validationSteps = [topic ? validationAuthWCMiddleware : validationAuthMiddleware, validationEvmSignMessageMiddleware];
1100
1062
  const result = await generateValidationProcess(this, url, payloadValidation, validationSteps, topic);
1063
+ const errorsFormated = convertErrorFormat(result.errors);
1101
1064
  const payloadAfterValidated = {
1102
1065
  ...result.payloadAfterValidated,
1103
- errors: result.errors,
1066
+ errors: errorsFormated,
1104
1067
  id
1105
1068
  };
1106
1069
  return this.requestService.addConfirmation(id, url, 'evmSignatureRequest', payloadAfterValidated, {}).then(({
@@ -1161,9 +1124,13 @@ export default class KoniState {
1161
1124
  errors,
1162
1125
  networkKey: networkKey_
1163
1126
  } = result;
1164
- if (errors && errors.length > 0 && confirmationType) {
1127
+ const errorsFormated = convertErrorFormat(errors);
1128
+ if (errorsFormated && errorsFormated.length > 0 && confirmationType) {
1165
1129
  if (ERROR_CONFIRMATION_TYPE.includes(confirmationType)) {
1166
- return this.requestService.addConfirmation(id, url, confirmationType, result, {}).then(() => {
1130
+ return this.requestService.addConfirmation(id, url, confirmationType, {
1131
+ ...result,
1132
+ errors: errorsFormated
1133
+ }, {}).then(() => {
1167
1134
  throw new EvmProviderError(EvmProviderErrorType.USER_REJECTED_REQUEST);
1168
1135
  });
1169
1136
  }
@@ -1172,7 +1139,7 @@ export default class KoniState {
1172
1139
  const networkKey = networkKey_ || '';
1173
1140
  const requestPayload = {
1174
1141
  ...transactionValidated,
1175
- errors: errors
1142
+ errors: errorsFormated
1176
1143
  };
1177
1144
  const eType = transactionValidated.value ? ExtrinsicType.TRANSFER_BALANCE : ExtrinsicType.EVM_EXECUTE;
1178
1145
  const transactionData = {
@@ -1232,14 +1199,17 @@ export default class KoniState {
1232
1199
  async onMV3Update() {
1233
1200
  const migrationStatus = await SWStorage.instance.getItem('mv3_migration');
1234
1201
  if (!migrationStatus || migrationStatus !== 'done') {
1235
- // Open migration tab
1236
- const url = `${chrome.runtime.getURL('index.html')}#/mv3-migration`;
1237
- await openPopup(url);
1202
+ if (isManifestV3) {
1203
+ // Open migration tab
1204
+ const url = `${chrome.runtime.getURL('index.html')}#/mv3-migration`;
1205
+ await openPopup(url);
1238
1206
 
1239
- // migrateMV3LocalStorage will be called when user open migration tab with data from localStorage on frontend
1207
+ // migrateMV3LocalStorage will be called when user open migration tab with data from localStorage on frontend
1208
+ } else {
1209
+ this.migrateMV3LocalStorage(JSON.stringify(self.localStorage)).catch(console.error);
1210
+ }
1240
1211
  }
1241
1212
  }
1242
-
1243
1213
  async migrateMV3LocalStorage(data) {
1244
1214
  try {
1245
1215
  const parsedData = JSON.parse(data);
@@ -34,6 +34,7 @@ export default class KoniTabs {
34
34
  private getEvmCurrentAccount;
35
35
  private getEvmState;
36
36
  private getEvmPermission;
37
+ private revokePermissions;
37
38
  private switchEvmChain;
38
39
  private addEvmToken;
39
40
  private addEvmChain;