@subwallet/extension-base 1.1.9-0 → 1.1.10-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 +13 -1
- package/background/KoniTypes.js +5 -0
- package/background/errors/BalanceError.js +7 -5
- package/background/errors/EvmProviderError.js +10 -8
- package/background/errors/ProviderError.js +5 -4
- package/background/errors/TransactionError.js +22 -17
- package/background/handlers/Extension.js +18 -18
- package/background/handlers/State.js +5 -5
- package/background/handlers/Tabs.js +1 -1
- package/background/warnings/TransactionWarning.js +4 -2
- package/cjs/background/KoniTypes.js +7 -1
- package/cjs/background/errors/BalanceError.js +7 -5
- package/cjs/background/errors/EvmProviderError.js +10 -8
- package/cjs/background/errors/ProviderError.js +5 -4
- package/cjs/background/errors/TransactionError.js +22 -17
- package/cjs/background/handlers/Extension.js +18 -18
- package/cjs/background/handlers/State.js +5 -5
- package/cjs/background/handlers/Tabs.js +1 -1
- package/cjs/background/warnings/TransactionWarning.js +4 -2
- package/cjs/constants/i18n.js +4 -1
- package/cjs/constants/index.js +12 -0
- package/cjs/constants/storage.js +11 -0
- package/cjs/koni/api/dotsama/parseTransaction.js +2 -1
- package/cjs/koni/api/staking/bonding/paraChain.js +10 -6
- package/cjs/koni/api/staking/bonding/relayChain.js +16 -7
- package/cjs/koni/api/staking/bonding/utils.js +80 -7
- package/cjs/koni/background/handlers/Extension.js +206 -170
- package/cjs/koni/background/handlers/State.js +19 -14
- package/cjs/koni/background/handlers/Tabs.js +15 -14
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/index.js +12 -3
- package/cjs/services/request-service/handler/AuthRequestHandler.js +4 -4
- package/cjs/services/request-service/handler/EvmRequestHandler.js +11 -10
- package/cjs/services/setting-service/SettingService.js +20 -7
- package/cjs/services/setting-service/constants.js +5 -1
- package/cjs/services/setting-service/i18n/Backend.js +42 -0
- package/cjs/services/setting-service/i18n/cache.js +12 -0
- package/cjs/services/setting-service/i18n/extend.js +16 -0
- package/cjs/services/setting-service/i18n/i18n.js +29 -0
- package/cjs/services/transaction-service/index.js +25 -16
- package/cjs/services/wallet-connect-service/handler/PolkadotRequestHandler.js +0 -1
- package/cjs/utils/eth/parseTransaction/base.js +1 -1
- package/cjs/utils/eth/parseTransaction/index.js +2 -1
- package/cjs/utils/index.js +2 -1
- package/constants/i18n.js +4 -1
- package/constants/index.d.ts +1 -0
- package/constants/index.js +2 -1
- package/constants/storage.d.ts +1 -0
- package/constants/storage.js +4 -0
- package/koni/api/dotsama/parseTransaction.js +2 -1
- package/koni/api/staking/bonding/paraChain.js +11 -7
- package/koni/api/staking/bonding/relayChain.js +17 -8
- package/koni/api/staking/bonding/utils.d.ts +4 -0
- package/koni/api/staking/bonding/utils.js +70 -2
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +85 -50
- package/koni/background/handlers/State.js +19 -14
- package/koni/background/handlers/Tabs.js +15 -14
- package/package.json +31 -11
- package/packageInfo.js +1 -1
- package/services/balance-service/index.js +12 -3
- package/services/request-service/handler/AuthRequestHandler.js +4 -4
- package/services/request-service/handler/EvmRequestHandler.js +11 -10
- package/services/setting-service/SettingService.d.ts +1 -0
- package/services/setting-service/SettingService.js +17 -5
- package/services/setting-service/constants.d.ts +2 -1
- package/services/setting-service/constants.js +4 -1
- package/services/setting-service/i18n/Backend.d.ts +9 -0
- package/services/setting-service/i18n/Backend.js +34 -0
- package/services/setting-service/i18n/cache.d.ts +2 -0
- package/services/setting-service/i18n/cache.js +5 -0
- package/services/setting-service/i18n/extend.d.ts +2 -0
- package/services/setting-service/i18n/extend.js +8 -0
- package/services/setting-service/i18n/i18n.d.ts +2 -0
- package/services/setting-service/i18n/i18n.js +21 -0
- package/services/transaction-service/index.js +25 -16
- package/services/wallet-connect-service/handler/PolkadotRequestHandler.js +0 -1
- package/utils/eth/parseTransaction/base.js +1 -1
- package/utils/eth/parseTransaction/index.js +2 -1
- package/utils/index.js +2 -1
- package/cjs/utils/keyring.js +0 -57
- package/utils/keyring.d.ts +0 -4
- package/utils/keyring.js +0 -49
|
@@ -5,24 +5,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ProviderError = void 0;
|
|
7
7
|
var _SWError = require("@subwallet/extension-base/background/errors/SWError");
|
|
8
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
8
9
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
9
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
10
11
|
|
|
11
12
|
const defaultErrorMap = {
|
|
12
13
|
CHAIN_DISCONNECTED: {
|
|
13
|
-
message: '
|
|
14
|
+
message: (0, _utils.detectTranslate)('Network is disconnected'),
|
|
14
15
|
code: undefined
|
|
15
16
|
},
|
|
16
17
|
INVALID_PARAMS: {
|
|
17
|
-
message: '
|
|
18
|
+
message: (0, _utils.detectTranslate)('Undefined error. Please contact SubWallet support'),
|
|
18
19
|
code: undefined
|
|
19
20
|
},
|
|
20
21
|
INTERNAL_ERROR: {
|
|
21
|
-
message: '
|
|
22
|
+
message: (0, _utils.detectTranslate)('Undefined error. Please contact SubWallet support'),
|
|
22
23
|
code: undefined
|
|
23
24
|
},
|
|
24
25
|
USER_REJECT: {
|
|
25
|
-
message: '
|
|
26
|
+
message: (0, _utils.detectTranslate)('Rejected by user'),
|
|
26
27
|
code: undefined
|
|
27
28
|
}
|
|
28
29
|
};
|
|
@@ -6,92 +6,97 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.TransactionError = void 0;
|
|
7
7
|
var _SWError = require("@subwallet/extension-base/background/errors/SWError");
|
|
8
8
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
10
|
+
var _i18next = require("i18next");
|
|
9
11
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
10
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
13
|
|
|
12
14
|
// Todo: finish this map in the future
|
|
13
15
|
const defaultErrorMap = {
|
|
14
16
|
NOT_ENOUGH_BALANCE: {
|
|
15
|
-
message: '
|
|
17
|
+
message: (0, _utils.detectTranslate)('Insufficient balance'),
|
|
16
18
|
code: undefined
|
|
17
19
|
},
|
|
18
20
|
CHAIN_DISCONNECTED: {
|
|
19
|
-
message: '
|
|
21
|
+
message: (0, _utils.detectTranslate)('Network is disconnected'),
|
|
20
22
|
code: undefined
|
|
21
23
|
},
|
|
22
24
|
INVALID_PARAMS: {
|
|
23
|
-
message: '
|
|
25
|
+
message: (0, _utils.detectTranslate)('Undefined error. Please contact SubWallet support'),
|
|
24
26
|
code: undefined
|
|
25
27
|
},
|
|
26
28
|
INTERNAL_ERROR: {
|
|
27
|
-
message: '
|
|
29
|
+
message: (0, _utils.detectTranslate)('Undefined error. Please contact SubWallet support'),
|
|
28
30
|
code: undefined
|
|
29
31
|
},
|
|
30
32
|
DUPLICATE_TRANSACTION: {
|
|
31
|
-
message: '
|
|
33
|
+
message: (0, _utils.detectTranslate)('Another transaction is in queue. Please try again later'),
|
|
32
34
|
code: undefined
|
|
33
35
|
},
|
|
34
36
|
UNABLE_TO_SIGN: {
|
|
35
|
-
message: 'Unable to sign',
|
|
37
|
+
message: (0, _utils.detectTranslate)('Unable to sign'),
|
|
36
38
|
code: undefined
|
|
37
39
|
},
|
|
38
40
|
USER_REJECT_REQUEST: {
|
|
39
|
-
message: '
|
|
41
|
+
message: (0, _utils.detectTranslate)('Rejected by user'),
|
|
40
42
|
code: undefined
|
|
41
43
|
},
|
|
42
44
|
UNABLE_TO_SEND: {
|
|
43
|
-
message: 'Unable to send',
|
|
45
|
+
message: (0, _utils.detectTranslate)('Unable to send'),
|
|
44
46
|
code: undefined
|
|
45
47
|
},
|
|
46
48
|
SEND_TRANSACTION_FAILED: {
|
|
47
|
-
message: 'Send transaction failed',
|
|
49
|
+
message: (0, _utils.detectTranslate)('Send transaction failed'),
|
|
48
50
|
code: undefined
|
|
49
51
|
},
|
|
50
52
|
NOT_ENOUGH_EXISTENTIAL_DEPOSIT: {
|
|
51
|
-
message: '
|
|
53
|
+
message: (0, _utils.detectTranslate)('Insufficient balance to cover existential deposit. Please decrease the transaction amount or increase your current balance'),
|
|
52
54
|
code: undefined
|
|
53
55
|
},
|
|
54
56
|
[_KoniTypes.BasicTxErrorType.UNSUPPORTED]: {
|
|
55
|
-
message: 'This
|
|
57
|
+
message: (0, _utils.detectTranslate)('This feature is not available with this token'),
|
|
56
58
|
code: undefined
|
|
57
59
|
},
|
|
58
60
|
[_KoniTypes.BasicTxErrorType.TIMEOUT]: {
|
|
59
|
-
message: 'Transaction timeout',
|
|
61
|
+
message: (0, _utils.detectTranslate)('Transaction timeout'),
|
|
60
62
|
code: undefined
|
|
61
63
|
},
|
|
62
64
|
[_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE]: {
|
|
63
65
|
message: 'Not enough min stake',
|
|
66
|
+
// Message specific to each case
|
|
64
67
|
code: undefined
|
|
65
68
|
},
|
|
66
69
|
[_KoniTypes.StakingTxErrorType.EXCEED_MAX_NOMINATIONS]: {
|
|
67
70
|
message: 'Exceed max nominations',
|
|
71
|
+
// Message specific to each case
|
|
68
72
|
code: undefined
|
|
69
73
|
},
|
|
70
74
|
[_KoniTypes.StakingTxErrorType.EXIST_UNSTAKING_REQUEST]: {
|
|
71
75
|
message: 'Exist unstaking request',
|
|
76
|
+
// Message specific to each case
|
|
72
77
|
code: undefined
|
|
73
78
|
},
|
|
74
79
|
[_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE]: {
|
|
75
|
-
message: 'Invalid active stake',
|
|
80
|
+
message: (0, _utils.detectTranslate)('Invalid. If you unstake this amount your active stake would fall below minimum active threshold'),
|
|
76
81
|
code: undefined
|
|
77
82
|
},
|
|
78
83
|
[_KoniTypes.StakingTxErrorType.EXCEED_MAX_UNSTAKING]: {
|
|
79
|
-
message: '
|
|
84
|
+
message: (0, _utils.detectTranslate)('You reached the maximum number of unstake requests'),
|
|
80
85
|
code: undefined
|
|
81
86
|
},
|
|
82
87
|
[_KoniTypes.StakingTxErrorType.INACTIVE_NOMINATION_POOL]: {
|
|
83
|
-
message: '
|
|
88
|
+
message: (0, _utils.detectTranslate)('Invalid. Inactive nomination pool'),
|
|
84
89
|
code: undefined
|
|
85
90
|
},
|
|
86
91
|
[_KoniTypes.TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT]: {
|
|
87
|
-
message: 'Receiver is not enough existential deposit',
|
|
92
|
+
message: (0, _utils.detectTranslate)('Receiver is not enough existential deposit'),
|
|
88
93
|
code: undefined
|
|
89
94
|
}
|
|
90
95
|
};
|
|
91
96
|
class TransactionError extends _SWError.SWError {
|
|
92
97
|
constructor(errorType, errMessage, data) {
|
|
93
98
|
const defaultErr = defaultErrorMap[errorType];
|
|
94
|
-
const message = errMessage || (defaultErr === null || defaultErr === void 0 ? void 0 : defaultErr.message) || errorType;
|
|
99
|
+
const message = errMessage || (0, _i18next.t)((defaultErr === null || defaultErr === void 0 ? void 0 : defaultErr.message) || '') || errorType;
|
|
95
100
|
super(errorType, message, defaultErr === null || defaultErr === void 0 ? void 0 : defaultErr.code, data);
|
|
96
101
|
this.errorType = errorType;
|
|
97
102
|
}
|
|
@@ -104,14 +104,14 @@ class Extension {
|
|
|
104
104
|
oldPass
|
|
105
105
|
} = _ref5;
|
|
106
106
|
const pair = _uiKeyring.default.getPair(address);
|
|
107
|
-
(0, _util.assert)(pair, 'Unable to find
|
|
107
|
+
(0, _util.assert)(pair, 'Unable to find account');
|
|
108
108
|
try {
|
|
109
109
|
if (!pair.isLocked) {
|
|
110
110
|
pair.lock();
|
|
111
111
|
}
|
|
112
112
|
pair.decodePkcs8(oldPass);
|
|
113
113
|
} catch (error) {
|
|
114
|
-
throw new Error('
|
|
114
|
+
throw new Error('Wrong password');
|
|
115
115
|
}
|
|
116
116
|
_uiKeyring.default.encryptAccount(pair, newPass);
|
|
117
117
|
return true;
|
|
@@ -122,7 +122,7 @@ class Extension {
|
|
|
122
122
|
name
|
|
123
123
|
} = _ref6;
|
|
124
124
|
const pair = _uiKeyring.default.getPair(address);
|
|
125
|
-
(0, _util.assert)(pair, 'Unable to find
|
|
125
|
+
(0, _util.assert)(pair, 'Unable to find account');
|
|
126
126
|
_uiKeyring.default.saveAccountMeta(pair, {
|
|
127
127
|
...pair.meta,
|
|
128
128
|
name
|
|
@@ -171,7 +171,7 @@ class Extension {
|
|
|
171
171
|
isShowing
|
|
172
172
|
} = _ref9;
|
|
173
173
|
const pair = _uiKeyring.default.getPair(address);
|
|
174
|
-
(0, _util.assert)(pair, 'Unable to find
|
|
174
|
+
(0, _util.assert)(pair, 'Unable to find account');
|
|
175
175
|
_uiKeyring.default.saveAccountMeta(pair, {
|
|
176
176
|
...pair.meta,
|
|
177
177
|
isHidden: !isShowing
|
|
@@ -184,7 +184,7 @@ class Extension {
|
|
|
184
184
|
genesisHash
|
|
185
185
|
} = _ref10;
|
|
186
186
|
const pair = _uiKeyring.default.getPair(address);
|
|
187
|
-
(0, _util.assert)(pair, 'Unable to find
|
|
187
|
+
(0, _util.assert)(pair, 'Unable to find account');
|
|
188
188
|
_uiKeyring.default.saveAccountMeta(pair, {
|
|
189
189
|
...pair.meta,
|
|
190
190
|
genesisHash
|
|
@@ -219,7 +219,7 @@ class Extension {
|
|
|
219
219
|
id
|
|
220
220
|
} = _ref12;
|
|
221
221
|
const queued = this.#state.getAuthRequest(id);
|
|
222
|
-
(0, _util.assert)(queued, 'Unable to
|
|
222
|
+
(0, _util.assert)(queued, 'Unable to proceed. Please try again');
|
|
223
223
|
const {
|
|
224
224
|
resolve
|
|
225
225
|
} = queued;
|
|
@@ -236,7 +236,7 @@ class Extension {
|
|
|
236
236
|
id
|
|
237
237
|
} = _ref13;
|
|
238
238
|
const queued = this.#state.getAuthRequest(id);
|
|
239
|
-
(0, _util.assert)(queued, 'Unable to
|
|
239
|
+
(0, _util.assert)(queued, 'Unable to proceed. Please try again');
|
|
240
240
|
const {
|
|
241
241
|
reject
|
|
242
242
|
} = queued;
|
|
@@ -259,7 +259,7 @@ class Extension {
|
|
|
259
259
|
id
|
|
260
260
|
} = _ref14;
|
|
261
261
|
const queued = this.#state.getMetaRequest(id);
|
|
262
|
-
(0, _util.assert)(queued, 'Unable to
|
|
262
|
+
(0, _util.assert)(queued, 'Unable to proceed. Please try again');
|
|
263
263
|
const {
|
|
264
264
|
request,
|
|
265
265
|
resolve
|
|
@@ -279,7 +279,7 @@ class Extension {
|
|
|
279
279
|
id
|
|
280
280
|
} = _ref15;
|
|
281
281
|
const queued = this.#state.getMetaRequest(id);
|
|
282
|
-
(0, _util.assert)(queued, 'Unable to
|
|
282
|
+
(0, _util.assert)(queued, 'Unable to proceed. Please try again');
|
|
283
283
|
const {
|
|
284
284
|
reject
|
|
285
285
|
} = queued;
|
|
@@ -359,11 +359,11 @@ class Extension {
|
|
|
359
359
|
phrase
|
|
360
360
|
} = (0, _utilCrypto.keyExtractSuri)(suri);
|
|
361
361
|
if ((0, _util.isHex)(phrase)) {
|
|
362
|
-
(0, _util.assert)((0, _util.isHex)(phrase, 256), '
|
|
362
|
+
(0, _util.assert)((0, _util.isHex)(phrase, 256), 'Invalid seed phrase. Please try again.');
|
|
363
363
|
} else {
|
|
364
364
|
// sadly isHex detects as string, so we need a cast here
|
|
365
365
|
(0, _util.assert)(SEED_LENGTHS.includes(phrase.split(' ').length), `Mnemonic needs to contain ${SEED_LENGTHS.join(', ')} words`);
|
|
366
|
-
(0, _util.assert)((0, _utilCrypto.mnemonicValidate)(phrase), '
|
|
366
|
+
(0, _util.assert)((0, _utilCrypto.mnemonicValidate)(phrase), 'Invalid seed phrase. Please try again.');
|
|
367
367
|
}
|
|
368
368
|
return {
|
|
369
369
|
address: _uiKeyring.default.createFromUri(getSuri(suri, type), {}, type).address,
|
|
@@ -377,7 +377,7 @@ class Extension {
|
|
|
377
377
|
savePass
|
|
378
378
|
} = _ref20;
|
|
379
379
|
const queued = this.#state.getSignRequest(id);
|
|
380
|
-
(0, _util.assert)(queued, 'Unable to
|
|
380
|
+
(0, _util.assert)(queued, 'Unable to proceed. Please try again');
|
|
381
381
|
const {
|
|
382
382
|
reject,
|
|
383
383
|
request,
|
|
@@ -392,7 +392,7 @@ class Extension {
|
|
|
392
392
|
address
|
|
393
393
|
} = pair;
|
|
394
394
|
if (!pair) {
|
|
395
|
-
reject(new Error('Unable to find
|
|
395
|
+
reject(new Error('Unable to find account'));
|
|
396
396
|
return false;
|
|
397
397
|
}
|
|
398
398
|
this.refreshAccountPasswordCache(pair);
|
|
@@ -435,7 +435,7 @@ class Extension {
|
|
|
435
435
|
signature
|
|
436
436
|
} = _ref21;
|
|
437
437
|
const queued = this.#state.getSignRequest(id);
|
|
438
|
-
(0, _util.assert)(queued, 'Unable to
|
|
438
|
+
(0, _util.assert)(queued, 'Unable to proceed. Please try again');
|
|
439
439
|
const {
|
|
440
440
|
resolve
|
|
441
441
|
} = queued;
|
|
@@ -450,7 +450,7 @@ class Extension {
|
|
|
450
450
|
id
|
|
451
451
|
} = _ref22;
|
|
452
452
|
const queued = this.#state.getSignRequest(id);
|
|
453
|
-
(0, _util.assert)(queued, 'Unable to
|
|
453
|
+
(0, _util.assert)(queued, 'Unable to proceed. Please try again');
|
|
454
454
|
const {
|
|
455
455
|
reject
|
|
456
456
|
} = queued;
|
|
@@ -462,10 +462,10 @@ class Extension {
|
|
|
462
462
|
id
|
|
463
463
|
} = _ref23;
|
|
464
464
|
const queued = this.#state.getSignRequest(id);
|
|
465
|
-
(0, _util.assert)(queued, 'Unable to
|
|
465
|
+
(0, _util.assert)(queued, 'Unable to proceed. Please try again');
|
|
466
466
|
const address = queued.request.payload.address;
|
|
467
467
|
const pair = _uiKeyring.default.getPair(address);
|
|
468
|
-
(0, _util.assert)(pair, 'Unable to find
|
|
468
|
+
(0, _util.assert)(pair, 'Unable to find account');
|
|
469
469
|
const remainingTime = this.refreshAccountPasswordCache(pair);
|
|
470
470
|
return {
|
|
471
471
|
isLocked: pair.isLocked,
|
|
@@ -515,7 +515,7 @@ class Extension {
|
|
|
515
515
|
try {
|
|
516
516
|
parentPair.decodePkcs8(password);
|
|
517
517
|
} catch (e) {
|
|
518
|
-
throw new Error('
|
|
518
|
+
throw new Error('Wrong password');
|
|
519
519
|
}
|
|
520
520
|
try {
|
|
521
521
|
return parentPair.derive(suri, metadata);
|
|
@@ -330,10 +330,10 @@ class State {
|
|
|
330
330
|
|
|
331
331
|
// Do not enqueue duplicate authorization requests.
|
|
332
332
|
const isDuplicate = Object.values(this.#authRequests).some(request => request.idStr === idStr);
|
|
333
|
-
(0, _util.assert)(!isDuplicate,
|
|
333
|
+
(0, _util.assert)(!isDuplicate, 'The source {{url}} has a pending authorization request'.replace('{{url}}', url));
|
|
334
334
|
if (this.#authUrls[idStr]) {
|
|
335
335
|
// this url was seen in the past
|
|
336
|
-
(0, _util.assert)(this.#authUrls[idStr].isAllowed,
|
|
336
|
+
(0, _util.assert)(this.#authUrls[idStr].isAllowed, 'The source {{url}} is not allowed to interact with this extension'.replace('{{url}}', url));
|
|
337
337
|
return false;
|
|
338
338
|
}
|
|
339
339
|
return new Promise((resolve, reject) => {
|
|
@@ -351,8 +351,8 @@ class State {
|
|
|
351
351
|
}
|
|
352
352
|
ensureUrlAuthorized(url) {
|
|
353
353
|
const entry = this.#authUrls[(0, _utils.stripUrl)(url)];
|
|
354
|
-
(0, _util.assert)(entry,
|
|
355
|
-
(0, _util.assert)(entry.isAllowed,
|
|
354
|
+
(0, _util.assert)(entry, 'The source {{url}} has not been authorized yet'.replace('{{url}}', url));
|
|
355
|
+
(0, _util.assert)(entry.isAllowed, 'The source {{url}} is not allowed to interact with this extension'.replace('{{url}}', url));
|
|
356
356
|
return true;
|
|
357
357
|
}
|
|
358
358
|
injectMetadata(url, request) {
|
|
@@ -393,7 +393,7 @@ class State {
|
|
|
393
393
|
|
|
394
394
|
// Start a provider, return its meta
|
|
395
395
|
rpcStartProvider(key, port) {
|
|
396
|
-
(0, _util.assert)(Object.keys(this.#providers).includes(key),
|
|
396
|
+
(0, _util.assert)(Object.keys(this.#providers).includes(key), 'Provider cannot be found.');
|
|
397
397
|
if (this.#injectedProviders.get(port)) {
|
|
398
398
|
return Promise.resolve(this.#providers[key].meta);
|
|
399
399
|
}
|
|
@@ -6,19 +6,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.TransactionWarning = void 0;
|
|
7
7
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
8
8
|
var _SWWarning = require("@subwallet/extension-base/background/warnings/SWWarning");
|
|
9
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
10
|
+
var _i18next = require("i18next");
|
|
9
11
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
10
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
13
|
|
|
12
14
|
const defaultWarningMap = {
|
|
13
15
|
[_KoniTypes.BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT]: {
|
|
14
|
-
message: '
|
|
16
|
+
message: (0, _utils.detectTranslate)('Insufficient balance to cover existential deposit. Please decrease the transaction amount or increase your current balance'),
|
|
15
17
|
code: undefined
|
|
16
18
|
}
|
|
17
19
|
};
|
|
18
20
|
class TransactionWarning extends _SWWarning.SWWarning {
|
|
19
21
|
constructor(warningType, message, code, data) {
|
|
20
22
|
var _defaultWarningMap$wa, _defaultWarningMap$wa2;
|
|
21
|
-
const warningMessage = message || ((_defaultWarningMap$wa = defaultWarningMap[warningType]) === null || _defaultWarningMap$wa === void 0 ? void 0 : _defaultWarningMap$wa.message) || warningType;
|
|
23
|
+
const warningMessage = message || (0, _i18next.t)(((_defaultWarningMap$wa = defaultWarningMap[warningType]) === null || _defaultWarningMap$wa === void 0 ? void 0 : _defaultWarningMap$wa.message) || '') || warningType;
|
|
22
24
|
super(warningType, warningMessage, (_defaultWarningMap$wa2 = defaultWarningMap[warningType]) === null || _defaultWarningMap$wa2 === void 0 ? void 0 : _defaultWarningMap$wa2.code, data);
|
|
23
25
|
this.warningType = warningType;
|
|
24
26
|
}
|
package/cjs/constants/i18n.js
CHANGED
|
@@ -19,6 +19,9 @@ const languageOptions = [{
|
|
|
19
19
|
}, {
|
|
20
20
|
text: '日本語',
|
|
21
21
|
value: 'ja'
|
|
22
|
+
}, {
|
|
23
|
+
text: 'Русский',
|
|
24
|
+
value: 'ru'
|
|
22
25
|
}, {
|
|
23
26
|
text: 'Français',
|
|
24
27
|
value: 'fr'
|
|
@@ -36,5 +39,5 @@ const languageOptions = [{
|
|
|
36
39
|
value: 'ur'
|
|
37
40
|
}];
|
|
38
41
|
exports.languageOptions = languageOptions;
|
|
39
|
-
const ENABLE_LANGUAGES = ['en', 'vi', 'zh'];
|
|
42
|
+
const ENABLE_LANGUAGES = ['en', 'vi', 'zh', 'ja'];
|
|
40
43
|
exports.ENABLE_LANGUAGES = ENABLE_LANGUAGES;
|
package/cjs/constants/index.js
CHANGED
|
@@ -40,6 +40,18 @@ Object.keys(_staking).forEach(function (key) {
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
|
+
var _storage = require("./storage");
|
|
44
|
+
Object.keys(_storage).forEach(function (key) {
|
|
45
|
+
if (key === "default" || key === "__esModule") return;
|
|
46
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
47
|
+
if (key in exports && exports[key] === _storage[key]) return;
|
|
48
|
+
Object.defineProperty(exports, key, {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _storage[key];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
43
55
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
44
56
|
// SPDX-License-Identifier: Apache-2.0
|
|
45
57
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LANGUAGE = void 0;
|
|
7
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
10
|
+
const LANGUAGE = 'current-language';
|
|
11
|
+
exports.LANGUAGE = LANGUAGE;
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.parseSubstrateTransaction = void 0;
|
|
7
|
+
var _i18next = require("i18next");
|
|
7
8
|
var _util = require("@polkadot/util");
|
|
8
9
|
// Copyright 2019-2022 @polkadot/extension-koni-base authors & contributors
|
|
9
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -86,7 +87,7 @@ const parseSubstrateTransaction = (data, apiPromise) => {
|
|
|
86
87
|
} catch (e) {
|
|
87
88
|
return {
|
|
88
89
|
...baseInfo,
|
|
89
|
-
message: 'Unable to decode
|
|
90
|
+
message: (0, _i18next.t)('Unable to decode the information'),
|
|
90
91
|
method: _method
|
|
91
92
|
};
|
|
92
93
|
}
|
|
@@ -45,8 +45,9 @@ function validateParaChainUnbondingCondition(amount, nominatorMetadata, chainSta
|
|
|
45
45
|
const bnChainMinStake = new _util.BN(chainStakingMetadata.minStake || '0');
|
|
46
46
|
const bnCollatorMinStake = new _util.BN(targetNomination.validatorMinStake || '0');
|
|
47
47
|
const bnMinStake = _util.BN.max(bnCollatorMinStake, bnChainMinStake);
|
|
48
|
+
const existUnstakeErrorMessage = (0, _utils.getExistUnstakeErrorMessage)(chainStakingMetadata.chain);
|
|
48
49
|
if (targetNomination.hasUnstaking) {
|
|
49
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXIST_UNSTAKING_REQUEST));
|
|
50
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXIST_UNSTAKING_REQUEST, existUnstakeErrorMessage));
|
|
50
51
|
}
|
|
51
52
|
if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(bnMinStake))) {
|
|
52
53
|
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE));
|
|
@@ -60,9 +61,12 @@ function validateParaChainBondingCondition(chainInfo, amount, selectedCollators,
|
|
|
60
61
|
const bnChainMinStake = new _util.BN(chainStakingMetadata.minStake || '0');
|
|
61
62
|
const bnCollatorMinStake = new _util.BN(selectedCollator.minBond || '0');
|
|
62
63
|
const bnMinStake = bnCollatorMinStake > bnChainMinStake ? bnCollatorMinStake : bnChainMinStake;
|
|
64
|
+
const minStakeErrorMessage = (0, _utils.getMinStakeErrorMessage)(chainInfo, bnMinStake);
|
|
65
|
+
const maxValidatorErrorMessage = (0, _utils.getMaxValidatorErrorMessage)(chainInfo, chainStakingMetadata.maxValidatorPerNominator);
|
|
66
|
+
const existUnstakeErrorMessage = (0, _utils.getExistUnstakeErrorMessage)(chainInfo.slug, true);
|
|
63
67
|
if (!nominatorMetadata || nominatorMetadata.status === _KoniTypes.StakingStatus.NOT_STAKING) {
|
|
64
68
|
if (!bnTotalStake.gte(bnMinStake)) {
|
|
65
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
69
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE, minStakeErrorMessage));
|
|
66
70
|
}
|
|
67
71
|
return errors;
|
|
68
72
|
}
|
|
@@ -73,11 +77,11 @@ function validateParaChainBondingCondition(chainInfo, amount, selectedCollators,
|
|
|
73
77
|
if (!bondedValidators.includes(parsedSelectedCollatorAddress)) {
|
|
74
78
|
// new delegation
|
|
75
79
|
if (!bnTotalStake.gte(bnMinStake)) {
|
|
76
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
80
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE, minStakeErrorMessage));
|
|
77
81
|
}
|
|
78
82
|
const delegationCount = nominatorMetadata.nominations.length + 1;
|
|
79
83
|
if (delegationCount > chainStakingMetadata.maxValidatorPerNominator) {
|
|
80
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_NOMINATIONS));
|
|
84
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_NOMINATIONS, maxValidatorErrorMessage));
|
|
81
85
|
}
|
|
82
86
|
} else {
|
|
83
87
|
let currentDelegationAmount = '0';
|
|
@@ -91,10 +95,10 @@ function validateParaChainBondingCondition(chainInfo, amount, selectedCollators,
|
|
|
91
95
|
}
|
|
92
96
|
bnTotalStake = bnTotalStake.add(new _util.BN(currentDelegationAmount));
|
|
93
97
|
if (!bnTotalStake.gte(bnMinStake)) {
|
|
94
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
98
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE, minStakeErrorMessage));
|
|
95
99
|
}
|
|
96
100
|
if (hasUnstaking) {
|
|
97
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXIST_UNSTAKING_REQUEST));
|
|
101
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXIST_UNSTAKING_REQUEST, existUnstakeErrorMessage));
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
104
|
return errors;
|
|
@@ -28,6 +28,7 @@ var _utils = require("@subwallet/extension-base/koni/api/staking/bonding/utils")
|
|
|
28
28
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
29
29
|
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
30
30
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
31
|
+
var _i18next = require("i18next");
|
|
31
32
|
var _util = require("@polkadot/util");
|
|
32
33
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
33
34
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
@@ -42,7 +43,11 @@ function validateRelayUnbondingCondition(amount, chainStakingMetadata, nominator
|
|
|
42
43
|
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INVALID_ACTIVE_STAKE));
|
|
43
44
|
}
|
|
44
45
|
if (nominatorMetadata.unstakings.length > chainStakingMetadata.maxWithdrawalRequestPerValidator) {
|
|
45
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_UNSTAKING)
|
|
46
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_UNSTAKING, (0, _i18next.t)('You cannot unstake more than {{number}} times', {
|
|
47
|
+
replace: {
|
|
48
|
+
number: chainStakingMetadata.maxWithdrawalRequestPerValidator
|
|
49
|
+
}
|
|
50
|
+
})));
|
|
46
51
|
}
|
|
47
52
|
return errors;
|
|
48
53
|
}
|
|
@@ -52,6 +57,8 @@ function validatePoolBondingCondition(chainInfo, amount, selectedPool, address,
|
|
|
52
57
|
const errors = [];
|
|
53
58
|
let bnTotalStake = new _util.BN(amount);
|
|
54
59
|
const bnMinStake = new _util.BN(chainStakingMetadata.minJoinNominationPool || '0');
|
|
60
|
+
const minStakeErrorMessage = (0, _utils.getMinStakeErrorMessage)(chainInfo, bnMinStake);
|
|
61
|
+
const existUnstakeErrorMessage = (0, _utils.getExistUnstakeErrorMessage)(chainInfo.slug, true);
|
|
55
62
|
if (selectedPool.state !== 'Open') {
|
|
56
63
|
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.INACTIVE_NOMINATION_POOL));
|
|
57
64
|
}
|
|
@@ -59,11 +66,11 @@ function validatePoolBondingCondition(chainInfo, amount, selectedPool, address,
|
|
|
59
66
|
const bnCurrentActiveStake = new _util.BN(nominatorMetadata.activeStake);
|
|
60
67
|
bnTotalStake = bnTotalStake.add(bnCurrentActiveStake);
|
|
61
68
|
if (nominatorMetadata.unstakings.length > 0 && bnCurrentActiveStake.isZero()) {
|
|
62
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXIST_UNSTAKING_REQUEST));
|
|
69
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXIST_UNSTAKING_REQUEST, existUnstakeErrorMessage));
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
72
|
if (!bnTotalStake.gte(bnMinStake)) {
|
|
66
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
73
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE, minStakeErrorMessage));
|
|
67
74
|
}
|
|
68
75
|
return errors;
|
|
69
76
|
}
|
|
@@ -71,22 +78,24 @@ function validateRelayBondingCondition(chainInfo, amount, selectedValidators, ad
|
|
|
71
78
|
const errors = [];
|
|
72
79
|
let bnTotalStake = new _util.BN(amount);
|
|
73
80
|
const bnMinStake = new _util.BN(chainStakingMetadata.minStake);
|
|
81
|
+
const minStakeErrorMessage = (0, _utils.getMinStakeErrorMessage)(chainInfo, bnMinStake);
|
|
82
|
+
const maxValidatorErrorMessage = (0, _utils.getMaxValidatorErrorMessage)(chainInfo, chainStakingMetadata.maxValidatorPerNominator);
|
|
74
83
|
if (!nominatorMetadata || nominatorMetadata.status === _KoniTypes.StakingStatus.NOT_STAKING) {
|
|
75
84
|
if (!bnTotalStake.gte(bnMinStake)) {
|
|
76
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
85
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE, minStakeErrorMessage));
|
|
77
86
|
}
|
|
78
87
|
if (selectedValidators.length > chainStakingMetadata.maxValidatorPerNominator) {
|
|
79
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_NOMINATIONS));
|
|
88
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_NOMINATIONS, maxValidatorErrorMessage));
|
|
80
89
|
}
|
|
81
90
|
return errors;
|
|
82
91
|
}
|
|
83
92
|
const bnCurrentActiveStake = new _util.BN(nominatorMetadata.activeStake);
|
|
84
93
|
bnTotalStake = bnTotalStake.add(bnCurrentActiveStake);
|
|
85
94
|
if (!bnTotalStake.gte(bnMinStake)) {
|
|
86
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE));
|
|
95
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.NOT_ENOUGH_MIN_STAKE, minStakeErrorMessage));
|
|
87
96
|
}
|
|
88
97
|
if (selectedValidators.length > chainStakingMetadata.maxValidatorPerNominator) {
|
|
89
|
-
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_NOMINATIONS));
|
|
98
|
+
errors.push(new _TransactionError.TransactionError(_KoniTypes.StakingTxErrorType.EXCEED_MAX_NOMINATIONS, maxValidatorErrorMessage));
|
|
90
99
|
}
|
|
91
100
|
return errors;
|
|
92
101
|
}
|