@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.
- package/background/KoniTypes.d.ts +7 -8
- package/cjs/constants/index.js +6 -3
- package/cjs/core/logic-validation/request.js +160 -23
- package/cjs/core/substrate/assets-pallet.js +34 -18
- package/cjs/core/substrate/foreign-asset-pallet.js +2 -9
- package/cjs/core/substrate/xcm-parser.js +2 -1
- package/cjs/koni/api/staking/bonding/utils.js +1 -0
- package/cjs/koni/background/handlers/State.js +35 -66
- package/cjs/koni/background/handlers/Tabs.js +96 -23
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +21 -1
- package/cjs/services/chain-service/index.js +1 -1
- package/cjs/services/earning-service/constants/chains.js +1 -3
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +31 -25
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +1 -2
- package/cjs/services/mkt-campaign-service/index.js +30 -6
- package/cjs/services/request-service/handler/EvmRequestHandler.js +0 -1
- package/cjs/services/wallet-connect-service/index.js +25 -1
- package/constants/index.d.ts +1 -0
- package/constants/index.js +1 -0
- package/core/logic-validation/request.d.ts +22 -1
- package/core/logic-validation/request.js +154 -23
- package/core/substrate/assets-pallet.d.ts +7 -3
- package/core/substrate/assets-pallet.js +29 -17
- package/core/substrate/foreign-asset-pallet.d.ts +3 -3
- package/core/substrate/foreign-asset-pallet.js +2 -9
- package/core/substrate/types.d.ts +5 -1
- package/core/substrate/xcm-parser.js +2 -1
- package/koni/api/staking/bonding/utils.js +1 -0
- package/koni/background/handlers/State.d.ts +0 -1
- package/koni/background/handlers/State.js +19 -49
- package/koni/background/handlers/Tabs.d.ts +1 -0
- package/koni/background/handlers/Tabs.js +77 -6
- package/package.json +13 -11
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +22 -2
- package/services/chain-service/index.js +1 -1
- package/services/earning-service/constants/chains.d.ts +0 -1
- package/services/earning-service/constants/chains.js +0 -1
- package/services/earning-service/handlers/native-staking/relay-chain.js +32 -26
- package/services/earning-service/handlers/nomination-pool/index.js +1 -2
- package/services/mkt-campaign-service/index.js +30 -6
- package/services/mkt-campaign-service/types.d.ts +2 -0
- package/services/request-service/handler/EvmRequestHandler.js +0 -1
- package/services/wallet-connect-service/index.js +24 -1
- package/types/yield/info/chain/target.d.ts +4 -0
|
@@ -958,26 +958,26 @@ export interface EvmSendTransactionParams {
|
|
|
958
958
|
data?: string;
|
|
959
959
|
gas?: string | number;
|
|
960
960
|
}
|
|
961
|
-
export interface SwitchNetworkRequest {
|
|
962
|
-
networkKey: string;
|
|
963
|
-
address?: string;
|
|
964
|
-
}
|
|
965
961
|
export interface EvmSignRequest {
|
|
966
962
|
account: AccountJson;
|
|
967
963
|
hashPayload: string;
|
|
968
964
|
canSign: boolean;
|
|
969
965
|
}
|
|
966
|
+
export interface ErrorValidation {
|
|
967
|
+
message: string;
|
|
968
|
+
name: string;
|
|
969
|
+
}
|
|
970
970
|
export interface EvmSignatureRequest extends EvmSignRequest {
|
|
971
971
|
id: string;
|
|
972
972
|
type: string;
|
|
973
973
|
payload: unknown;
|
|
974
|
-
errors?:
|
|
974
|
+
errors?: ErrorValidation[];
|
|
975
975
|
}
|
|
976
976
|
export interface EvmSendTransactionRequest extends TransactionConfig, EvmSignRequest {
|
|
977
977
|
estimateGas: string;
|
|
978
978
|
parseData: EvmTransactionData;
|
|
979
979
|
isToContract: boolean;
|
|
980
|
-
errors?:
|
|
980
|
+
errors?: ErrorValidation[];
|
|
981
981
|
}
|
|
982
982
|
export declare type EvmWatchTransactionRequest = EvmSendTransactionRequest;
|
|
983
983
|
export interface ConfirmationsQueueItemOptions {
|
|
@@ -1020,12 +1020,11 @@ export interface AddTokenRequestExternal {
|
|
|
1020
1020
|
export interface ErrorNetworkConnection {
|
|
1021
1021
|
networkKey: string;
|
|
1022
1022
|
address: string;
|
|
1023
|
-
errors:
|
|
1023
|
+
errors: ErrorValidation[];
|
|
1024
1024
|
}
|
|
1025
1025
|
export interface ConfirmationDefinitions {
|
|
1026
1026
|
addNetworkRequest: [ConfirmationsQueueItem<_NetworkUpsertParams>, ConfirmationResult<null>];
|
|
1027
1027
|
addTokenRequest: [ConfirmationsQueueItem<AddTokenRequestExternal>, ConfirmationResult<boolean>];
|
|
1028
|
-
switchNetworkRequest: [ConfirmationsQueueItem<SwitchNetworkRequest>, ConfirmationResult<boolean>];
|
|
1029
1028
|
evmSignatureRequest: [ConfirmationsQueueItem<EvmSignatureRequest>, ConfirmationResult<string>];
|
|
1030
1029
|
evmSendTransactionRequest: [ConfirmationsQueueItem<EvmSendTransactionRequest>, ConfirmationResult<string>];
|
|
1031
1030
|
evmWatchTransactionRequest: [ConfirmationsQueueItem<EvmWatchTransactionRequest>, ConfirmationResult<string>];
|
package/cjs/constants/index.js
CHANGED
|
@@ -34,9 +34,10 @@ var _exportNames = {
|
|
|
34
34
|
GAS_PRICE_RATIO: true,
|
|
35
35
|
NETWORK_MULTI_GAS_FEE: true,
|
|
36
36
|
ORDINAL_COLLECTION: true,
|
|
37
|
-
ORDINAL_METHODS: true
|
|
37
|
+
ORDINAL_METHODS: true,
|
|
38
|
+
PERMISSIONS_TO_REVOKE: true
|
|
38
39
|
};
|
|
39
|
-
exports.XCM_MIN_AMOUNT_RATIO = exports.XCM_FEE_RATIO = exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.ORDINAL_METHODS = exports.ORDINAL_COLLECTION = exports.NETWORK_MULTI_GAS_FEE = exports.MANTA_PAY_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.GAS_PRICE_RATIO = exports.CRON_SYNC_MANTA_PAY = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_MKT_CAMPAIGN_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.BASE_SECOND_INTERVAL = exports.BASE_MINUTE_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
|
|
40
|
+
exports.XCM_MIN_AMOUNT_RATIO = exports.XCM_FEE_RATIO = exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.PERMISSIONS_TO_REVOKE = exports.ORDINAL_METHODS = exports.ORDINAL_COLLECTION = exports.NETWORK_MULTI_GAS_FEE = exports.MANTA_PAY_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.GAS_PRICE_RATIO = exports.CRON_SYNC_MANTA_PAY = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_MKT_CAMPAIGN_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.BASE_SECOND_INTERVAL = exports.BASE_MINUTE_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
|
|
40
41
|
var _staking = require("./staking");
|
|
41
42
|
Object.keys(_staking).forEach(function (key) {
|
|
42
43
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -125,4 +126,6 @@ exports.NETWORK_MULTI_GAS_FEE = NETWORK_MULTI_GAS_FEE;
|
|
|
125
126
|
const ORDINAL_COLLECTION = '__Ordinal__';
|
|
126
127
|
exports.ORDINAL_COLLECTION = ORDINAL_COLLECTION;
|
|
127
128
|
const ORDINAL_METHODS = ['drc-20', 'pol-20'];
|
|
128
|
-
exports.ORDINAL_METHODS = ORDINAL_METHODS;
|
|
129
|
+
exports.ORDINAL_METHODS = ORDINAL_METHODS;
|
|
130
|
+
const PERMISSIONS_TO_REVOKE = ['eth_accounts'];
|
|
131
|
+
exports.PERMISSIONS_TO_REVOKE = PERMISSIONS_TO_REVOKE;
|
|
@@ -4,13 +4,19 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
exports.convertErrorFormat = convertErrorFormat;
|
|
7
8
|
exports.convertErrorMessage = convertErrorMessage;
|
|
8
9
|
exports.generateValidationProcess = generateValidationProcess;
|
|
10
|
+
exports.joiValidate = void 0;
|
|
11
|
+
exports.validateSignMessageData = validateSignMessageData;
|
|
12
|
+
exports.validateTypedSignMessageDataV1 = validateTypedSignMessageDataV1;
|
|
13
|
+
exports.validateTypedSignMessageDataV3V4 = validateTypedSignMessageDataV3V4;
|
|
9
14
|
exports.validationAuthMiddleware = validationAuthMiddleware;
|
|
10
15
|
exports.validationAuthWCMiddleware = validationAuthWCMiddleware;
|
|
11
16
|
exports.validationConnectMiddleware = validationConnectMiddleware;
|
|
12
17
|
exports.validationEvmDataTransactionMiddleware = validationEvmDataTransactionMiddleware;
|
|
13
18
|
exports.validationEvmSignMessageMiddleware = validationEvmSignMessageMiddleware;
|
|
19
|
+
var _ethSigUtil = require("@metamask/eth-sig-util");
|
|
14
20
|
var _EvmProviderError = require("@subwallet/extension-base/background/errors/EvmProviderError");
|
|
15
21
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
16
22
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
@@ -22,11 +28,109 @@ var _utils3 = require("@walletconnect/utils");
|
|
|
22
28
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
23
29
|
var _bn = _interopRequireDefault(require("bn.js"));
|
|
24
30
|
var _i18next = require("i18next");
|
|
31
|
+
var _joi = _interopRequireDefault(require("joi"));
|
|
25
32
|
var _util = require("@polkadot/util");
|
|
26
33
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
27
34
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
28
35
|
// SPDX-License-Identifier: Apache-2.0
|
|
29
36
|
|
|
37
|
+
const joiValidate = _joi.default.object({
|
|
38
|
+
types: _joi.default.object().pattern(_joi.default.string(),
|
|
39
|
+
// Key của object types
|
|
40
|
+
_joi.default.array().items(_joi.default.object({
|
|
41
|
+
name: _joi.default.string().required(),
|
|
42
|
+
type: _joi.default.string().required()
|
|
43
|
+
}))).required(),
|
|
44
|
+
primaryType: _joi.default.string().required(),
|
|
45
|
+
domain: _joi.default.object().required(),
|
|
46
|
+
message: _joi.default.object().required()
|
|
47
|
+
});
|
|
48
|
+
exports.joiValidate = joiValidate;
|
|
49
|
+
function validateAddress(address, propertyName) {
|
|
50
|
+
if (!address || typeof address !== 'string' || !(0, _utilCrypto.isEthereumAddress)(address)) {
|
|
51
|
+
throw new Error(`Invalid "${propertyName}" address: ${address} must be a valid string.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function validateSignMessageData(messageData) {
|
|
55
|
+
const {
|
|
56
|
+
data,
|
|
57
|
+
from
|
|
58
|
+
} = messageData;
|
|
59
|
+
validateAddress(from, 'from');
|
|
60
|
+
if (!data || typeof data !== 'string') {
|
|
61
|
+
throw new Error(`Invalid message "data": ${data} must be a valid string.`);
|
|
62
|
+
}
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
function validateTypedSignMessageDataV1(messageData) {
|
|
66
|
+
validateAddress(messageData.from, 'from');
|
|
67
|
+
if (!messageData.data || !Array.isArray(messageData.data)) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
71
|
+
`Invalid message "data": ${messageData.data} must be a valid array.`);
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
// typedSignatureHash will throw if the data is invalid.
|
|
75
|
+
// TODO: Replace `any` with type
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
+
(0, _ethSigUtil.typedSignatureHash)(messageData.data);
|
|
78
|
+
return messageData.data;
|
|
79
|
+
} catch (e) {
|
|
80
|
+
throw new Error('Invalid message "data": Expected EIP712 typed data.');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function validateTypedSignMessageDataV3V4(messageData) {
|
|
84
|
+
validateAddress(messageData.from, 'from');
|
|
85
|
+
if (!messageData.data || Array.isArray(messageData.data) || typeof messageData.data !== 'object' && typeof messageData.data !== 'string') {
|
|
86
|
+
throw new Error('Invalid message "data": Must be a valid string or object.');
|
|
87
|
+
}
|
|
88
|
+
let data;
|
|
89
|
+
if (typeof messageData.data === 'object') {
|
|
90
|
+
data = messageData.data;
|
|
91
|
+
} else {
|
|
92
|
+
try {
|
|
93
|
+
data = JSON.parse(messageData.data);
|
|
94
|
+
} catch (e) {
|
|
95
|
+
throw new Error('Invalid message "data" must be passed as a valid JSON string.');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const validation = joiValidate.validate(data);
|
|
99
|
+
if (validation.error) {
|
|
100
|
+
throw new Error('Invalid message "data" must conform to EIP-712 schema. See https://git.io/fNtcx.');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// if (!currentChainId) {
|
|
104
|
+
// throw new Error('Current chainId cannot be null or undefined.');
|
|
105
|
+
// }
|
|
106
|
+
|
|
107
|
+
// let { chainId } = data.domain;
|
|
108
|
+
//
|
|
109
|
+
// if (chainId) {
|
|
110
|
+
// if (typeof chainId === 'string') {
|
|
111
|
+
// chainId = parseInt(chainId, chainId.startsWith('0x') ? 16 : 10);
|
|
112
|
+
// }
|
|
113
|
+
//
|
|
114
|
+
// const activeChainId = parseInt(currentChainId, 16);
|
|
115
|
+
//
|
|
116
|
+
// if (Number.isNaN(activeChainId)) {
|
|
117
|
+
// throw new Error(
|
|
118
|
+
// // TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
119
|
+
// // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
120
|
+
// `Cannot sign messages for chainId "${chainId}", because MetaMask is switching networks.`
|
|
121
|
+
// );
|
|
122
|
+
// }
|
|
123
|
+
//
|
|
124
|
+
// if (chainId !== activeChainId) {
|
|
125
|
+
// throw new Error(
|
|
126
|
+
// // TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
127
|
+
// // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
128
|
+
// `Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`
|
|
129
|
+
// );
|
|
130
|
+
// }
|
|
131
|
+
// }
|
|
132
|
+
return data;
|
|
133
|
+
}
|
|
30
134
|
async function generateValidationProcess(koni, url, payloadValidate, validationMiddlewareSteps, topic) {
|
|
31
135
|
let resultValidated = payloadValidate;
|
|
32
136
|
for (const step of validationMiddlewareSteps) {
|
|
@@ -328,7 +432,7 @@ async function validationEvmSignMessageMiddleware(koni, url, payload_) {
|
|
|
328
432
|
const [message, name] = convertErrorMessage(message_);
|
|
329
433
|
const error = new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, message, undefined, name);
|
|
330
434
|
console.error(error);
|
|
331
|
-
errors.push(
|
|
435
|
+
errors.push(error);
|
|
332
436
|
};
|
|
333
437
|
if (address === '' || !payload) {
|
|
334
438
|
handleError('Not found address or payload to sign');
|
|
@@ -342,26 +446,47 @@ async function validationEvmSignMessageMiddleware(koni, url, payload_) {
|
|
|
342
446
|
if (['eth_sign', 'personal_sign', 'eth_signTypedData', 'eth_signTypedData_v1', 'eth_signTypedData_v3', 'eth_signTypedData_v4'].indexOf(method) < 0) {
|
|
343
447
|
handleError('Unsupported action');
|
|
344
448
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
switch (method) {
|
|
350
|
-
case 'personal_sign':
|
|
351
|
-
canSign = true;
|
|
352
|
-
hashPayload = payload;
|
|
353
|
-
break;
|
|
354
|
-
case 'eth_sign':
|
|
355
|
-
case 'eth_signTypedData':
|
|
356
|
-
case 'eth_signTypedData_v1':
|
|
357
|
-
case 'eth_signTypedData_v3':
|
|
358
|
-
case 'eth_signTypedData_v4':
|
|
359
|
-
if (!account.isExternal) {
|
|
449
|
+
try {
|
|
450
|
+
switch (method) {
|
|
451
|
+
case 'personal_sign':
|
|
360
452
|
canSign = true;
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
453
|
+
payload = validateSignMessageData({
|
|
454
|
+
data: payload,
|
|
455
|
+
from: address
|
|
456
|
+
});
|
|
457
|
+
hashPayload = payload;
|
|
458
|
+
break;
|
|
459
|
+
case 'eth_sign':
|
|
460
|
+
if (!account.isExternal) {
|
|
461
|
+
canSign = true;
|
|
462
|
+
}
|
|
463
|
+
break;
|
|
464
|
+
case 'eth_signTypedData':
|
|
465
|
+
case 'eth_signTypedData_v1':
|
|
466
|
+
if (!account.isExternal) {
|
|
467
|
+
canSign = true;
|
|
468
|
+
}
|
|
469
|
+
payload = validateTypedSignMessageDataV1({
|
|
470
|
+
data: payload,
|
|
471
|
+
from: address
|
|
472
|
+
});
|
|
473
|
+
break;
|
|
474
|
+
case 'eth_signTypedData_v3':
|
|
475
|
+
case 'eth_signTypedData_v4':
|
|
476
|
+
if (!account.isExternal) {
|
|
477
|
+
canSign = true;
|
|
478
|
+
}
|
|
479
|
+
payload = validateTypedSignMessageDataV3V4({
|
|
480
|
+
data: payload,
|
|
481
|
+
from: address
|
|
482
|
+
});
|
|
483
|
+
break;
|
|
484
|
+
default:
|
|
485
|
+
throw new Error('Unsupported action');
|
|
486
|
+
}
|
|
487
|
+
} catch (e) {
|
|
488
|
+
console.error(e);
|
|
489
|
+
handleError(e.message);
|
|
365
490
|
}
|
|
366
491
|
} else {
|
|
367
492
|
handleError('Unsupported method');
|
|
@@ -442,7 +567,7 @@ function convertErrorMessage(message_, name) {
|
|
|
442
567
|
return [(0, _i18next.t)('Re-enable the network or change RPC on the extension and try again'), (0, _i18next.t)('Unstable network connection')];
|
|
443
568
|
}
|
|
444
569
|
if (message.includes('network is currently not supported')) {
|
|
445
|
-
return [(0, _i18next.t)('This network is not yet supported on SubWallet.
|
|
570
|
+
return [(0, _i18next.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'), (0, _i18next.t)('Network not supported')];
|
|
446
571
|
}
|
|
447
572
|
|
|
448
573
|
// Authentication
|
|
@@ -479,10 +604,22 @@ function convertErrorMessage(message_, name) {
|
|
|
479
604
|
|
|
480
605
|
// Sign Message
|
|
481
606
|
if (message.includes('not found address or payload to sign')) {
|
|
482
|
-
return [(0, _i18next.t)('An error occurred when signing this request. Try again or contact support at agent@subwallet.app'), (0, _i18next.t)('Unable to sign
|
|
607
|
+
return [(0, _i18next.t)('An error occurred when signing this request. Try again or contact support at agent@subwallet.app'), (0, _i18next.t)('Unable to sign')];
|
|
483
608
|
}
|
|
484
609
|
if (message.includes('unsupported method') || message.includes('unsupported action')) {
|
|
485
610
|
return [(0, _i18next.t)('This sign method is not supported by SubWallet. Try again or contact support at agent@subwallet.app'), (0, _i18next.t)('Method not supported')];
|
|
486
611
|
}
|
|
487
|
-
|
|
612
|
+
if (message.includes('eip712 typed data') || message.includes('invalid message')) {
|
|
613
|
+
return [(0, _i18next.t)('An error occurred when attempting to sign this request. Contact support at email: agent@subwallet.app'), (0, _i18next.t)('Unable to sign')];
|
|
614
|
+
}
|
|
615
|
+
return [message, name || 'Error'];
|
|
616
|
+
}
|
|
617
|
+
function convertErrorFormat(errors) {
|
|
618
|
+
if (errors.length > 0) {
|
|
619
|
+
return [{
|
|
620
|
+
name: errors[0].name,
|
|
621
|
+
message: errors[0].message
|
|
622
|
+
}];
|
|
623
|
+
}
|
|
624
|
+
return [];
|
|
488
625
|
}
|
|
@@ -3,33 +3,49 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports._getAssetsPalletLocked = _getAssetsPalletLocked;
|
|
7
|
+
exports._getAssetsPalletLockedWithStatus = _getAssetsPalletLockedWithStatus;
|
|
8
|
+
exports._getAssetsPalletLockedWithoutStatus = _getAssetsPalletLockedWithoutStatus;
|
|
7
9
|
exports._getAssetsPalletTransferable = _getAssetsPalletTransferable;
|
|
10
|
+
exports._getAssetsPalletTransferableWithStatus = _getAssetsPalletTransferableWithStatus;
|
|
11
|
+
exports._getAssetsPalletTransferableWithoutStatus = _getAssetsPalletTransferableWithoutStatus;
|
|
8
12
|
var _types = require("@subwallet/extension-base/core/substrate/types");
|
|
9
13
|
var _utils = require("@subwallet/extension-base/core/utils");
|
|
10
14
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
11
15
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
16
|
|
|
17
|
+
function isWithStatus(accountInfo) {
|
|
18
|
+
return accountInfo.status !== undefined && accountInfo.isFrozen === undefined;
|
|
19
|
+
}
|
|
13
20
|
function _getAssetsPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
|
|
14
21
|
const strictMode = (0, _utils.getStrictMode)(_types.BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
if (['Liquid'].includes(accountInfo.status)) {
|
|
21
|
-
bnTransferable = BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
|
|
22
|
+
if (isWithStatus(accountInfo)) {
|
|
23
|
+
return _getAssetsPalletTransferableWithStatus(accountInfo, existentialDeposit, strictMode);
|
|
24
|
+
} else {
|
|
25
|
+
return _getAssetsPalletTransferableWithoutStatus(accountInfo, existentialDeposit, strictMode);
|
|
22
26
|
}
|
|
23
|
-
return bnTransferable;
|
|
24
27
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
function _getAssetsPalletLocked(accountInfo) {
|
|
29
|
+
if (isWithStatus(accountInfo)) {
|
|
30
|
+
return _getAssetsPalletLockedWithStatus(accountInfo);
|
|
31
|
+
} else {
|
|
32
|
+
return _getAssetsPalletLockedWithoutStatus(accountInfo);
|
|
29
33
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ----------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
function _getAssetsPalletTransferableWithStatus(accountInfo, existentialDeposit, strictMode) {
|
|
39
|
+
const bnAppliedExistentialDeposit = (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode);
|
|
40
|
+
return accountInfo.status === 'Liquid' ? BigInt(accountInfo.balance) - bnAppliedExistentialDeposit : BigInt(0);
|
|
41
|
+
}
|
|
42
|
+
function _getAssetsPalletTransferableWithoutStatus(accountInfo, existentialDeposit, strictMode) {
|
|
43
|
+
const bnAppliedExistentialDeposit = (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode);
|
|
44
|
+
return !accountInfo.isFrozen ? BigInt(accountInfo.balance) - bnAppliedExistentialDeposit : BigInt(0);
|
|
45
|
+
}
|
|
46
|
+
function _getAssetsPalletLockedWithStatus(accountInfo) {
|
|
47
|
+
return accountInfo.status !== 'Liquid' ? BigInt(accountInfo.balance) : BigInt(0);
|
|
48
|
+
}
|
|
49
|
+
function _getAssetsPalletLockedWithoutStatus(accountInfo) {
|
|
50
|
+
return accountInfo.isFrozen ? BigInt(accountInfo.balance) : BigInt(0);
|
|
35
51
|
}
|
|
@@ -12,15 +12,8 @@ var _utils = require("@subwallet/extension-base/core/utils");
|
|
|
12
12
|
|
|
13
13
|
function _getForeignAssetPalletTransferable(accountInfo, existentialDeposit, extrinsicType) {
|
|
14
14
|
const strictMode = (0, _utils.getStrictMode)(_types.BalanceAccountType.PalletAssetsAssetAccount, extrinsicType);
|
|
15
|
-
|
|
16
|
-
return BigInt(0);
|
|
17
|
-
}
|
|
18
|
-
const bnAppliedExistentialDeposit = (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode);
|
|
19
|
-
return BigInt(accountInfo.balance) - bnAppliedExistentialDeposit;
|
|
15
|
+
return accountInfo.status === 'Liquid' ? BigInt(accountInfo.balance) - (0, _utils._getAppliedExistentialDeposit)(existentialDeposit, strictMode) : BigInt(0);
|
|
20
16
|
}
|
|
21
17
|
function _getForeignAssetPalletLockedBalance(accountInfo) {
|
|
22
|
-
|
|
23
|
-
return BigInt(0);
|
|
24
|
-
}
|
|
25
|
-
return BigInt(accountInfo.balance);
|
|
18
|
+
return accountInfo.status !== 'Liquid' ? BigInt(accountInfo.balance) : BigInt(0);
|
|
26
19
|
}
|
|
@@ -209,7 +209,8 @@ function _getAssetIdentifier(tokenInfo, version) {
|
|
|
209
209
|
if (!_assetIdentifier) {
|
|
210
210
|
throw new Error('Asset must have multilocation');
|
|
211
211
|
}
|
|
212
|
-
const assetIdentifier =
|
|
212
|
+
const assetIdentifier = ['statemint-LOCAL-KSM'].includes(tokenInfo.slug) // todo: hotfix for ksm statemint recheck all chain
|
|
213
|
+
? _assetIdentifier : _adaptX1Interior(structuredClone(_assetIdentifier), version);
|
|
213
214
|
return version >= 4 // from V4, Concrete is removed
|
|
214
215
|
? assetIdentifier : {
|
|
215
216
|
Concrete: assetIdentifier
|
|
@@ -144,6 +144,7 @@ function calculateTernoaValidatorReturn(rewardPerValidator, validatorStake, comm
|
|
|
144
144
|
function calculateValidatorStakedReturn(chainStakedReturn, totalValidatorStake, avgStake, commission) {
|
|
145
145
|
const bnAdjusted = avgStake.mul(_util.BN_HUNDRED).div(totalValidatorStake);
|
|
146
146
|
const adjusted = bnAdjusted.toNumber() * chainStakedReturn;
|
|
147
|
+
// todo: should calculated in bignumber instead number?
|
|
147
148
|
const stakedReturn = (adjusted > Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : adjusted) / 100;
|
|
148
149
|
return stakedReturn * (100 - commission) / 100; // Deduct commission
|
|
149
150
|
}
|
|
@@ -559,50 +559,11 @@ class KoniState {
|
|
|
559
559
|
}));
|
|
560
560
|
}
|
|
561
561
|
}
|
|
562
|
-
async switchNetworkAccount(id, url, networkKey, changeAddress) {
|
|
563
|
-
const chainInfo = this.chainService.getChainInfoByKey(networkKey);
|
|
564
|
-
const chainState = this.chainService.getChainStateByKey(networkKey);
|
|
565
|
-
const {
|
|
566
|
-
address,
|
|
567
|
-
currentGenesisHash
|
|
568
|
-
} = this.keyringService.currentAccount;
|
|
569
|
-
return this.requestService.addConfirmation(id, url, 'switchNetworkRequest', {
|
|
570
|
-
networkKey,
|
|
571
|
-
address: changeAddress
|
|
572
|
-
}, {
|
|
573
|
-
address: changeAddress
|
|
574
|
-
}).then(_ref2 => {
|
|
575
|
-
let {
|
|
576
|
-
isApproved
|
|
577
|
-
} = _ref2;
|
|
578
|
-
if (isApproved) {
|
|
579
|
-
const useAddress = changeAddress || address;
|
|
580
|
-
if (chainInfo && !(0, _utils._isChainEnabled)(chainState)) {
|
|
581
|
-
this.enableChain(networkKey).catch(console.error);
|
|
582
|
-
}
|
|
583
|
-
if (useAddress !== _constants.ALL_ACCOUNT_KEY) {
|
|
584
|
-
const pair = _uiKeyring.keyring.getPair(useAddress);
|
|
585
|
-
(0, _util.assert)(pair, (0, _i18next.t)('Unable to find account'));
|
|
586
|
-
_uiKeyring.keyring.saveAccountMeta(pair, {
|
|
587
|
-
...pair.meta,
|
|
588
|
-
genesisHash: (0, _utils._getSubstrateGenesisHash)(chainInfo)
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
if (address !== changeAddress || (0, _utils._getSubstrateGenesisHash)(chainInfo) !== currentGenesisHash || isApproved) {
|
|
592
|
-
this.setCurrentAccount({
|
|
593
|
-
address: useAddress,
|
|
594
|
-
currentGenesisHash: (0, _utils._getSubstrateGenesisHash)(chainInfo)
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
return isApproved;
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
562
|
async addNetworkConfirm(id, url, networkData) {
|
|
602
|
-
return this.requestService.addConfirmation(id, url, 'addNetworkRequest', networkData).then(async
|
|
563
|
+
return this.requestService.addConfirmation(id, url, 'addNetworkRequest', networkData).then(async _ref2 => {
|
|
603
564
|
let {
|
|
604
565
|
isApproved
|
|
605
|
-
} =
|
|
566
|
+
} = _ref2;
|
|
606
567
|
if (isApproved) {
|
|
607
568
|
if (networkData.mode === 'insert') {
|
|
608
569
|
await this.upsertChainInfo(networkData);
|
|
@@ -616,10 +577,10 @@ class KoniState {
|
|
|
616
577
|
});
|
|
617
578
|
}
|
|
618
579
|
async addTokenConfirm(id, url, tokenInfo) {
|
|
619
|
-
return this.requestService.addConfirmation(id, url, 'addTokenRequest', tokenInfo).then(async
|
|
580
|
+
return this.requestService.addConfirmation(id, url, 'addTokenRequest', tokenInfo).then(async _ref3 => {
|
|
620
581
|
let {
|
|
621
582
|
isApproved
|
|
622
|
-
} =
|
|
583
|
+
} = _ref3;
|
|
623
584
|
if (isApproved) {
|
|
624
585
|
await this.upsertCustomToken({
|
|
625
586
|
originChain: tokenInfo.originChain,
|
|
@@ -991,8 +952,8 @@ class KoniState {
|
|
|
991
952
|
if (!genesisHash) {
|
|
992
953
|
return [undefined, undefined];
|
|
993
954
|
}
|
|
994
|
-
const rs = Object.entries(this.chainService.getChainInfoMap()).find(
|
|
995
|
-
let [networkKey, chainInfo] =
|
|
955
|
+
const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref4 => {
|
|
956
|
+
let [networkKey, chainInfo] = _ref4;
|
|
996
957
|
return (0, _utils._getSubstrateGenesisHash)(chainInfo) === genesisHash;
|
|
997
958
|
});
|
|
998
959
|
if (rs) {
|
|
@@ -1009,9 +970,9 @@ class KoniState {
|
|
|
1009
970
|
if (!chainId) {
|
|
1010
971
|
return [undefined, undefined];
|
|
1011
972
|
}
|
|
1012
|
-
const rs = Object.entries(this.chainService.getChainInfoMap()).find(
|
|
973
|
+
const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref5 => {
|
|
1013
974
|
var _chainInfo$evmInfo;
|
|
1014
|
-
let [networkKey, chainInfo] =
|
|
975
|
+
let [networkKey, chainInfo] = _ref5;
|
|
1015
976
|
return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId) === chainId;
|
|
1016
977
|
});
|
|
1017
978
|
if (rs) {
|
|
@@ -1027,11 +988,11 @@ class KoniState {
|
|
|
1027
988
|
}
|
|
1028
989
|
return Object.values(_constants2._PREDEFINED_SINGLE_MODES).find(item => item.networkKeys.includes(networkKey));
|
|
1029
990
|
}
|
|
1030
|
-
accountExportPrivateKey(
|
|
991
|
+
accountExportPrivateKey(_ref6) {
|
|
1031
992
|
let {
|
|
1032
993
|
address,
|
|
1033
994
|
password
|
|
1034
|
-
} =
|
|
995
|
+
} = _ref6;
|
|
1035
996
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1036
997
|
const exportedJson = _uiKeyring.keyring.backupAccount(_uiKeyring.keyring.getPair(address), password);
|
|
1037
998
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
@@ -1041,11 +1002,11 @@ class KoniState {
|
|
|
1041
1002
|
publicKey: (0, _util.u8aToHex)(decoded.publicKey)
|
|
1042
1003
|
};
|
|
1043
1004
|
}
|
|
1044
|
-
checkPublicAndSecretKey(
|
|
1005
|
+
checkPublicAndSecretKey(_ref7) {
|
|
1045
1006
|
let {
|
|
1046
1007
|
publicKey,
|
|
1047
1008
|
secretKey
|
|
1048
|
-
} =
|
|
1009
|
+
} = _ref7;
|
|
1049
1010
|
try {
|
|
1050
1011
|
const _secret = (0, _util.hexStripPrefix)(secretKey);
|
|
1051
1012
|
if (_secret.length === 64) {
|
|
@@ -1119,16 +1080,17 @@ class KoniState {
|
|
|
1119
1080
|
};
|
|
1120
1081
|
const validationSteps = [topic ? _logicValidation.validationAuthWCMiddleware : _logicValidation.validationAuthMiddleware, _logicValidation.validationEvmSignMessageMiddleware];
|
|
1121
1082
|
const result = await (0, _logicValidation.generateValidationProcess)(this, url, payloadValidation, validationSteps, topic);
|
|
1083
|
+
const errorsFormated = (0, _logicValidation.convertErrorFormat)(result.errors);
|
|
1122
1084
|
const payloadAfterValidated = {
|
|
1123
1085
|
...result.payloadAfterValidated,
|
|
1124
|
-
errors:
|
|
1086
|
+
errors: errorsFormated,
|
|
1125
1087
|
id
|
|
1126
1088
|
};
|
|
1127
|
-
return this.requestService.addConfirmation(id, url, 'evmSignatureRequest', payloadAfterValidated, {}).then(
|
|
1089
|
+
return this.requestService.addConfirmation(id, url, 'evmSignatureRequest', payloadAfterValidated, {}).then(_ref8 => {
|
|
1128
1090
|
let {
|
|
1129
1091
|
isApproved,
|
|
1130
1092
|
payload
|
|
1131
|
-
} =
|
|
1093
|
+
} = _ref8;
|
|
1132
1094
|
if (isApproved) {
|
|
1133
1095
|
if (payload) {
|
|
1134
1096
|
return payload;
|
|
@@ -1184,9 +1146,13 @@ class KoniState {
|
|
|
1184
1146
|
errors,
|
|
1185
1147
|
networkKey: networkKey_
|
|
1186
1148
|
} = result;
|
|
1187
|
-
|
|
1149
|
+
const errorsFormated = (0, _logicValidation.convertErrorFormat)(errors);
|
|
1150
|
+
if (errorsFormated && errorsFormated.length > 0 && confirmationType) {
|
|
1188
1151
|
if (ERROR_CONFIRMATION_TYPE.includes(confirmationType)) {
|
|
1189
|
-
return this.requestService.addConfirmation(id, url, confirmationType,
|
|
1152
|
+
return this.requestService.addConfirmation(id, url, confirmationType, {
|
|
1153
|
+
...result,
|
|
1154
|
+
errors: errorsFormated
|
|
1155
|
+
}, {}).then(() => {
|
|
1190
1156
|
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.USER_REJECTED_REQUEST);
|
|
1191
1157
|
});
|
|
1192
1158
|
}
|
|
@@ -1195,7 +1161,7 @@ class KoniState {
|
|
|
1195
1161
|
const networkKey = networkKey_ || '';
|
|
1196
1162
|
const requestPayload = {
|
|
1197
1163
|
...transactionValidated,
|
|
1198
|
-
errors:
|
|
1164
|
+
errors: errorsFormated
|
|
1199
1165
|
};
|
|
1200
1166
|
const eType = transactionValidated.value ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.EVM_EXECUTE;
|
|
1201
1167
|
const transactionData = {
|
|
@@ -1255,14 +1221,17 @@ class KoniState {
|
|
|
1255
1221
|
async onMV3Update() {
|
|
1256
1222
|
const migrationStatus = await _storage.SWStorage.instance.getItem('mv3_migration');
|
|
1257
1223
|
if (!migrationStatus || migrationStatus !== 'done') {
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1224
|
+
if (_utils3.isManifestV3) {
|
|
1225
|
+
// Open migration tab
|
|
1226
|
+
const url = `${chrome.runtime.getURL('index.html')}#/mv3-migration`;
|
|
1227
|
+
await (0, _PopupHandler.openPopup)(url);
|
|
1261
1228
|
|
|
1262
|
-
|
|
1229
|
+
// migrateMV3LocalStorage will be called when user open migration tab with data from localStorage on frontend
|
|
1230
|
+
} else {
|
|
1231
|
+
this.migrateMV3LocalStorage(JSON.stringify(self.localStorage)).catch(console.error);
|
|
1232
|
+
}
|
|
1263
1233
|
}
|
|
1264
1234
|
}
|
|
1265
|
-
|
|
1266
1235
|
async migrateMV3LocalStorage(data) {
|
|
1267
1236
|
try {
|
|
1268
1237
|
const parsedData = JSON.parse(data);
|
|
@@ -1312,11 +1281,11 @@ class KoniState {
|
|
|
1312
1281
|
const subscription = this.keyringService.currentAccountSubject.subscribe(handleRemind);
|
|
1313
1282
|
}
|
|
1314
1283
|
}
|
|
1315
|
-
async setStorageFromWS(
|
|
1284
|
+
async setStorageFromWS(_ref9) {
|
|
1316
1285
|
let {
|
|
1317
1286
|
key,
|
|
1318
1287
|
value
|
|
1319
|
-
} =
|
|
1288
|
+
} = _ref9;
|
|
1320
1289
|
try {
|
|
1321
1290
|
const jsonData = JSON.stringify(value);
|
|
1322
1291
|
await _storage.SWStorage.instance.setItem(key, jsonData);
|
|
@@ -1717,12 +1686,12 @@ class KoniState {
|
|
|
1717
1686
|
|
|
1718
1687
|
/* Metadata */
|
|
1719
1688
|
|
|
1720
|
-
getCrowdloanContributions(
|
|
1689
|
+
getCrowdloanContributions(_ref10) {
|
|
1721
1690
|
let {
|
|
1722
1691
|
address,
|
|
1723
1692
|
page,
|
|
1724
1693
|
relayChain
|
|
1725
|
-
} =
|
|
1694
|
+
} = _ref10;
|
|
1726
1695
|
return this.subscanService.getCrowdloanContributions(relayChain, address, page);
|
|
1727
1696
|
}
|
|
1728
1697
|
}
|