@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
|
@@ -38,6 +38,7 @@ import { keyring } from '@subwallet/ui-keyring';
|
|
|
38
38
|
import { getSdkError } from '@walletconnect/utils';
|
|
39
39
|
import BigN from 'bignumber.js';
|
|
40
40
|
import { Transaction } from 'ethereumjs-tx';
|
|
41
|
+
import { t } from 'i18next';
|
|
41
42
|
import { TypeRegistry } from '@polkadot/types';
|
|
42
43
|
import { assert, BN, BN_ZERO, hexStripPrefix, hexToU8a, isAscii, isHex, u8aToHex, u8aToString } from '@polkadot/util';
|
|
43
44
|
import { addressToEvm, base64Decode, decodeAddress, isAddress, isEthereumAddress, jsonDecrypt, keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
|
|
@@ -130,14 +131,14 @@ export default class KoniExtension {
|
|
|
130
131
|
oldPass
|
|
131
132
|
}) {
|
|
132
133
|
const pair = keyring.getPair(address);
|
|
133
|
-
assert(pair, 'Unable to find
|
|
134
|
+
assert(pair, t('Unable to find account'));
|
|
134
135
|
try {
|
|
135
136
|
if (!pair.isLocked) {
|
|
136
137
|
pair.lock();
|
|
137
138
|
}
|
|
138
139
|
pair.decodePkcs8(oldPass);
|
|
139
140
|
} catch (error) {
|
|
140
|
-
throw new Error('
|
|
141
|
+
throw new Error(t('Wrong password'));
|
|
141
142
|
}
|
|
142
143
|
keyring.encryptAccount(pair, newPass);
|
|
143
144
|
return true;
|
|
@@ -147,7 +148,7 @@ export default class KoniExtension {
|
|
|
147
148
|
name
|
|
148
149
|
}) {
|
|
149
150
|
const pair = keyring.getPair(address);
|
|
150
|
-
assert(pair, 'Unable to find
|
|
151
|
+
assert(pair, t('Unable to find account'));
|
|
151
152
|
keyring.saveAccountMeta(pair, {
|
|
152
153
|
...pair.meta,
|
|
153
154
|
name
|
|
@@ -167,7 +168,7 @@ export default class KoniExtension {
|
|
|
167
168
|
isShowing
|
|
168
169
|
}) {
|
|
169
170
|
const pair = keyring.getPair(address);
|
|
170
|
-
assert(pair, 'Unable to find
|
|
171
|
+
assert(pair, t('Unable to find account'));
|
|
171
172
|
keyring.saveAccountMeta(pair, {
|
|
172
173
|
...pair.meta,
|
|
173
174
|
isHidden: !isShowing
|
|
@@ -201,7 +202,7 @@ export default class KoniExtension {
|
|
|
201
202
|
id
|
|
202
203
|
}) {
|
|
203
204
|
const queued = this.#koniState.getMetaRequest(id);
|
|
204
|
-
assert(queued, 'Unable to
|
|
205
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
205
206
|
const {
|
|
206
207
|
request,
|
|
207
208
|
resolve
|
|
@@ -220,7 +221,7 @@ export default class KoniExtension {
|
|
|
220
221
|
id
|
|
221
222
|
}) {
|
|
222
223
|
const queued = this.#koniState.getMetaRequest(id);
|
|
223
|
-
assert(queued, 'Unable to
|
|
224
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
224
225
|
const {
|
|
225
226
|
reject
|
|
226
227
|
} = queued;
|
|
@@ -296,11 +297,15 @@ export default class KoniExtension {
|
|
|
296
297
|
phrase
|
|
297
298
|
} = keyExtractSuri(suri);
|
|
298
299
|
if (isHex(phrase)) {
|
|
299
|
-
assert(isHex(phrase, 256), '
|
|
300
|
+
assert(isHex(phrase, 256), t('Invalid seed phrase. Please try again.'));
|
|
300
301
|
} else {
|
|
301
302
|
// sadly isHex detects as string, so we need a cast here
|
|
302
|
-
assert(SEED_LENGTHS.includes(phrase.split(' ').length),
|
|
303
|
-
|
|
303
|
+
assert(SEED_LENGTHS.includes(phrase.split(' ').length), t('Seed phrase needs to contain {{x}} words', {
|
|
304
|
+
replace: {
|
|
305
|
+
x: SEED_LENGTHS.join(', ')
|
|
306
|
+
}
|
|
307
|
+
}));
|
|
308
|
+
assert(mnemonicValidate(phrase), t('Invalid seed phrase. Please try again.'));
|
|
304
309
|
}
|
|
305
310
|
return {
|
|
306
311
|
address: keyring.createFromUri(getSuri(suri, type), {}, type).address,
|
|
@@ -314,7 +319,7 @@ export default class KoniExtension {
|
|
|
314
319
|
signature
|
|
315
320
|
}) {
|
|
316
321
|
const queued = this.#koniState.getSignRequest(id);
|
|
317
|
-
assert(queued, 'Unable to
|
|
322
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
318
323
|
const {
|
|
319
324
|
resolve
|
|
320
325
|
} = queued;
|
|
@@ -330,7 +335,7 @@ export default class KoniExtension {
|
|
|
330
335
|
id
|
|
331
336
|
}) {
|
|
332
337
|
const queued = this.#koniState.getSignRequest(id);
|
|
333
|
-
assert(queued, 'Unable to
|
|
338
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
334
339
|
const {
|
|
335
340
|
reject
|
|
336
341
|
} = queued;
|
|
@@ -379,12 +384,16 @@ export default class KoniExtension {
|
|
|
379
384
|
try {
|
|
380
385
|
parentPair.decodePkcs8(password);
|
|
381
386
|
} catch (e) {
|
|
382
|
-
throw new Error('
|
|
387
|
+
throw new Error(t('Wrong password'));
|
|
383
388
|
}
|
|
384
389
|
try {
|
|
385
390
|
return parentPair.derive(suri, metadata);
|
|
386
391
|
} catch (err) {
|
|
387
|
-
throw new Error(
|
|
392
|
+
throw new Error(t('"{{suri}}" is not a valid derivation path', {
|
|
393
|
+
replace: {
|
|
394
|
+
suri
|
|
395
|
+
}
|
|
396
|
+
}));
|
|
388
397
|
}
|
|
389
398
|
}
|
|
390
399
|
derivationValidate({
|
|
@@ -518,7 +527,7 @@ export default class KoniExtension {
|
|
|
518
527
|
publicKey: decodeAddress(address)
|
|
519
528
|
};
|
|
520
529
|
} else {
|
|
521
|
-
throw Error('
|
|
530
|
+
throw Error(t('This is not an address'));
|
|
522
531
|
}
|
|
523
532
|
}
|
|
524
533
|
editContactAccount({
|
|
@@ -530,7 +539,7 @@ export default class KoniExtension {
|
|
|
530
539
|
keyring.saveAddress(_address, meta);
|
|
531
540
|
return true;
|
|
532
541
|
} else {
|
|
533
|
-
throw Error('
|
|
542
|
+
throw Error(t('This is not an address'));
|
|
534
543
|
}
|
|
535
544
|
}
|
|
536
545
|
deleteContactAccount({
|
|
@@ -541,7 +550,7 @@ export default class KoniExtension {
|
|
|
541
550
|
keyring.forgetAddress(_address);
|
|
542
551
|
return true;
|
|
543
552
|
} else {
|
|
544
|
-
throw Error('
|
|
553
|
+
throw Error(t('This is not an address'));
|
|
545
554
|
}
|
|
546
555
|
}
|
|
547
556
|
_getAuthListV2() {
|
|
@@ -589,7 +598,7 @@ export default class KoniExtension {
|
|
|
589
598
|
id
|
|
590
599
|
}) {
|
|
591
600
|
const queued = this.#koniState.getAuthRequestV2(id);
|
|
592
|
-
assert(queued, 'Unable to
|
|
601
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
593
602
|
const {
|
|
594
603
|
resolve
|
|
595
604
|
} = queued;
|
|
@@ -603,7 +612,7 @@ export default class KoniExtension {
|
|
|
603
612
|
id
|
|
604
613
|
}) {
|
|
605
614
|
const queued = this.#koniState.getAuthRequestV2(id);
|
|
606
|
-
assert(queued, 'Unable to
|
|
615
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
607
616
|
const {
|
|
608
617
|
reject
|
|
609
618
|
} = queued;
|
|
@@ -614,7 +623,7 @@ export default class KoniExtension {
|
|
|
614
623
|
id
|
|
615
624
|
}) {
|
|
616
625
|
const queued = this.#koniState.getAuthRequestV2(id);
|
|
617
|
-
assert(queued, 'Unable to
|
|
626
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
618
627
|
const {
|
|
619
628
|
reject
|
|
620
629
|
} = queued;
|
|
@@ -849,6 +858,12 @@ export default class KoniExtension {
|
|
|
849
858
|
this.#koniState.updateSetting('timeAutoLock', autoLockTime);
|
|
850
859
|
return true;
|
|
851
860
|
}
|
|
861
|
+
setUnlockType({
|
|
862
|
+
unlockType
|
|
863
|
+
}) {
|
|
864
|
+
this.#koniState.updateSetting('unlockType', unlockType);
|
|
865
|
+
return true;
|
|
866
|
+
}
|
|
852
867
|
async subscribeSettings(id, port) {
|
|
853
868
|
const cb = createSubscription(id, port);
|
|
854
869
|
const balancesVisibilitySubscription = this.#koniState.subscribeSettingsSubject().subscribe({
|
|
@@ -1071,7 +1086,7 @@ export default class KoniExtension {
|
|
|
1071
1086
|
const hasMasterPassword = keyring.keyring.hasMasterPassword;
|
|
1072
1087
|
if (!hasMasterPassword) {
|
|
1073
1088
|
if (!password) {
|
|
1074
|
-
throw Error('
|
|
1089
|
+
throw Error(t('The password of each account is needed to set up master password'));
|
|
1075
1090
|
} else {
|
|
1076
1091
|
keyring.changeMasterPassword(password);
|
|
1077
1092
|
this.#koniState.updateKeyringState();
|
|
@@ -1171,11 +1186,15 @@ export default class KoniExtension {
|
|
|
1171
1186
|
phrase
|
|
1172
1187
|
} = keyExtractSuri(suri);
|
|
1173
1188
|
if (isHex(phrase)) {
|
|
1174
|
-
assert(isHex(phrase, 256), '
|
|
1189
|
+
assert(isHex(phrase, 256), t('Invalid seed phrase. Please try again.'));
|
|
1175
1190
|
} else {
|
|
1176
1191
|
// sadly isHex detects as string, so we need a cast here
|
|
1177
|
-
assert(SEED_LENGTHS.includes(phrase.split(' ').length),
|
|
1178
|
-
|
|
1192
|
+
assert(SEED_LENGTHS.includes(phrase.split(' ').length), t('Seed phrase needs to contain {{x}} words', {
|
|
1193
|
+
replace: {
|
|
1194
|
+
x: SEED_LENGTHS.join(', ')
|
|
1195
|
+
}
|
|
1196
|
+
}));
|
|
1197
|
+
assert(mnemonicValidate(phrase), t('Invalid seed phrase. Please try again.'));
|
|
1179
1198
|
}
|
|
1180
1199
|
const rs = {
|
|
1181
1200
|
seed: suri,
|
|
@@ -1207,7 +1226,7 @@ export default class KoniExtension {
|
|
|
1207
1226
|
});
|
|
1208
1227
|
} else {
|
|
1209
1228
|
rs.autoAddPrefix = false;
|
|
1210
|
-
assert(false, '
|
|
1229
|
+
assert(false, t('Invalid private key. Please try again.'));
|
|
1211
1230
|
}
|
|
1212
1231
|
return rs;
|
|
1213
1232
|
}
|
|
@@ -1236,7 +1255,11 @@ export default class KoniExtension {
|
|
|
1236
1255
|
try {
|
|
1237
1256
|
return parentPair.derive(suri, metadata);
|
|
1238
1257
|
} catch (err) {
|
|
1239
|
-
throw new Error(
|
|
1258
|
+
throw new Error(t('"{{suri}}" is not a valid derivation path', {
|
|
1259
|
+
replace: {
|
|
1260
|
+
suri
|
|
1261
|
+
}
|
|
1262
|
+
}));
|
|
1240
1263
|
}
|
|
1241
1264
|
}
|
|
1242
1265
|
derivationCreateV2({
|
|
@@ -1277,7 +1300,7 @@ export default class KoniExtension {
|
|
|
1277
1300
|
throw new Error(error.message);
|
|
1278
1301
|
}
|
|
1279
1302
|
} else {
|
|
1280
|
-
throw new Error('
|
|
1303
|
+
throw new Error(t('Wrong password'));
|
|
1281
1304
|
}
|
|
1282
1305
|
}
|
|
1283
1306
|
batchRestoreV2({
|
|
@@ -1298,7 +1321,7 @@ export default class KoniExtension {
|
|
|
1298
1321
|
throw new Error(error.message);
|
|
1299
1322
|
}
|
|
1300
1323
|
} else {
|
|
1301
|
-
throw new Error('
|
|
1324
|
+
throw new Error(t('Wrong password'));
|
|
1302
1325
|
}
|
|
1303
1326
|
}
|
|
1304
1327
|
getNftCollection() {
|
|
@@ -1405,7 +1428,7 @@ export default class KoniExtension {
|
|
|
1405
1428
|
let transferValue;
|
|
1406
1429
|
if (!transferAll) {
|
|
1407
1430
|
if (value === undefined) {
|
|
1408
|
-
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, '
|
|
1431
|
+
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, t('Transfer amount is required')));
|
|
1409
1432
|
}
|
|
1410
1433
|
if (value) {
|
|
1411
1434
|
transferValue = new BN(value);
|
|
@@ -1413,10 +1436,10 @@ export default class KoniExtension {
|
|
|
1413
1436
|
}
|
|
1414
1437
|
const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
|
|
1415
1438
|
if (!tokenInfo) {
|
|
1416
|
-
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, 'Not found token from registry'));
|
|
1439
|
+
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, t('Not found token from registry')));
|
|
1417
1440
|
}
|
|
1418
1441
|
if (isEthereumAddress(from) && isEthereumAddress(to) && _isTokenEvmSmartContract(tokenInfo) && _getContractAddressOfToken(tokenInfo).length === 0) {
|
|
1419
|
-
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, 'Not found ERC20 address for this token'));
|
|
1442
|
+
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, t('Not found ERC20 address for this token')));
|
|
1420
1443
|
}
|
|
1421
1444
|
return [errors, keypair, transferValue, tokenInfo];
|
|
1422
1445
|
}
|
|
@@ -1484,7 +1507,7 @@ export default class KoniExtension {
|
|
|
1484
1507
|
} catch (e) {
|
|
1485
1508
|
const error = e;
|
|
1486
1509
|
if (error.message.includes('transfer amount exceeds balance')) {
|
|
1487
|
-
error.message = '
|
|
1510
|
+
error.message = t('Insufficient balance');
|
|
1488
1511
|
}
|
|
1489
1512
|
throw error;
|
|
1490
1513
|
}
|
|
@@ -1505,7 +1528,7 @@ export default class KoniExtension {
|
|
|
1505
1528
|
token: tokenSlug
|
|
1506
1529
|
});
|
|
1507
1530
|
if (new BigN(balance).minus(transferAmount.value).lt(minAmount)) {
|
|
1508
|
-
inputTransaction.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT
|
|
1531
|
+
inputTransaction.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT));
|
|
1509
1532
|
}
|
|
1510
1533
|
}
|
|
1511
1534
|
const {
|
|
@@ -1520,7 +1543,12 @@ export default class KoniExtension {
|
|
|
1520
1543
|
if (new BigN(receiverBalance).plus(transferAmount.value).lt(minAmount)) {
|
|
1521
1544
|
const atLeast = new BigN(minAmount).minus(receiverBalance).plus((tokenInfo.decimals || 0) === 0 ? 0 : 1);
|
|
1522
1545
|
const atLeastStr = formatNumber(atLeast, tokenInfo.decimals || 0, balanceFormatter);
|
|
1523
|
-
inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT,
|
|
1546
|
+
inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, t('You must transfer at least {{amount}}{{symbol}} to keep the destination account alive', {
|
|
1547
|
+
replace: {
|
|
1548
|
+
amount: atLeastStr,
|
|
1549
|
+
symbol: tokenInfo.symbol
|
|
1550
|
+
}
|
|
1551
|
+
})));
|
|
1524
1552
|
}
|
|
1525
1553
|
};
|
|
1526
1554
|
return this.#koniState.transactionService.handleTransaction({
|
|
@@ -1546,7 +1574,7 @@ export default class KoniExtension {
|
|
|
1546
1574
|
const originTokenInfo = this.#koniState.getAssetBySlug(sendingTokenSlug);
|
|
1547
1575
|
const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destinationNetworkKey, sendingTokenSlug);
|
|
1548
1576
|
if (!destinationTokenInfo) {
|
|
1549
|
-
errors.push(new TransactionError(TransferTxErrorType.INVALID_TOKEN, 'Not found token from registry'));
|
|
1577
|
+
errors.push(new TransactionError(TransferTxErrorType.INVALID_TOKEN, t('Not found token from registry')));
|
|
1550
1578
|
}
|
|
1551
1579
|
return [errors, keypair, transferValue, originTokenInfo, destinationTokenInfo];
|
|
1552
1580
|
}
|
|
@@ -1584,7 +1612,12 @@ export default class KoniExtension {
|
|
|
1584
1612
|
// Check ed for receiver
|
|
1585
1613
|
if (new BigN(value).lt(atLeast)) {
|
|
1586
1614
|
const atLeastStr = formatNumber(atLeast, destinationTokenInfo.decimals || 0, balanceFormatter);
|
|
1587
|
-
inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT,
|
|
1615
|
+
inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, t('You must transfer at least {{amount}}{{symbol}} to keep the destination account alive', {
|
|
1616
|
+
replace: {
|
|
1617
|
+
amount: atLeastStr,
|
|
1618
|
+
symbol: originTokenInfo.symbol
|
|
1619
|
+
}
|
|
1620
|
+
})));
|
|
1588
1621
|
}
|
|
1589
1622
|
const srcMinAmount = originTokenInfo.minAmount || '0';
|
|
1590
1623
|
const isTransferNativeToken = originTokenInfo.assetType === _AssetType.NATIVE;
|
|
@@ -1599,7 +1632,7 @@ export default class KoniExtension {
|
|
|
1599
1632
|
token: originTokenInfo.slug
|
|
1600
1633
|
});
|
|
1601
1634
|
if (new BigN(balance).minus(value).lt(srcMinAmount)) {
|
|
1602
|
-
inputTransaction.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT
|
|
1635
|
+
inputTransaction.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT));
|
|
1603
1636
|
}
|
|
1604
1637
|
}
|
|
1605
1638
|
};
|
|
@@ -1811,7 +1844,7 @@ export default class KoniExtension {
|
|
|
1811
1844
|
}
|
|
1812
1845
|
} catch (e) {
|
|
1813
1846
|
estimatedFee = '0';
|
|
1814
|
-
console.warn('
|
|
1847
|
+
console.warn('Unable to estimate fee', e);
|
|
1815
1848
|
}
|
|
1816
1849
|
maxTransferable = maxTransferable.sub(new BN(estimatedFee));
|
|
1817
1850
|
return {
|
|
@@ -1903,7 +1936,7 @@ export default class KoniExtension {
|
|
|
1903
1936
|
address
|
|
1904
1937
|
}) {
|
|
1905
1938
|
const pair = keyring.getPair(address);
|
|
1906
|
-
assert(pair, 'Unable to find
|
|
1939
|
+
assert(pair, t('Unable to find account'));
|
|
1907
1940
|
return {
|
|
1908
1941
|
meta: pair.meta
|
|
1909
1942
|
};
|
|
@@ -1930,7 +1963,7 @@ export default class KoniExtension {
|
|
|
1930
1963
|
if (exists.type === (isEthereum ? 'ethereum' : 'sr25519')) {
|
|
1931
1964
|
return [{
|
|
1932
1965
|
code: AccountExternalErrorCode.INVALID_ADDRESS,
|
|
1933
|
-
message: 'Account exists'
|
|
1966
|
+
message: t('Account exists')
|
|
1934
1967
|
}];
|
|
1935
1968
|
}
|
|
1936
1969
|
}
|
|
@@ -2016,7 +2049,7 @@ export default class KoniExtension {
|
|
|
2016
2049
|
}) {
|
|
2017
2050
|
const addresses = [];
|
|
2018
2051
|
if (!accounts.length) {
|
|
2019
|
-
throw new Error('
|
|
2052
|
+
throw new Error(t("Can't find an account. Please try again"));
|
|
2020
2053
|
}
|
|
2021
2054
|
const slugMap = {};
|
|
2022
2055
|
for (const account of accounts) {
|
|
@@ -2128,7 +2161,7 @@ export default class KoniExtension {
|
|
|
2128
2161
|
success: false,
|
|
2129
2162
|
errors: [{
|
|
2130
2163
|
code: AccountExternalErrorCode.KEYRING_ERROR,
|
|
2131
|
-
message: '
|
|
2164
|
+
message: t('Cannot create account')
|
|
2132
2165
|
}]
|
|
2133
2166
|
};
|
|
2134
2167
|
}
|
|
@@ -2262,7 +2295,7 @@ export default class KoniExtension {
|
|
|
2262
2295
|
networkKey
|
|
2263
2296
|
}) {
|
|
2264
2297
|
const pair = keyring.getPair(address);
|
|
2265
|
-
assert(pair, 'Unable to find
|
|
2298
|
+
assert(pair, t('Unable to find account'));
|
|
2266
2299
|
if (pair.isLocked) {
|
|
2267
2300
|
keyring.unlockPair(pair.address);
|
|
2268
2301
|
}
|
|
@@ -2286,11 +2319,11 @@ export default class KoniExtension {
|
|
|
2286
2319
|
let signed;
|
|
2287
2320
|
const network = this.getNetworkJsonByChainId(chainId);
|
|
2288
2321
|
if (!network) {
|
|
2289
|
-
throw new Error('Cannot find network');
|
|
2322
|
+
throw new Error(t('Cannot find network'));
|
|
2290
2323
|
}
|
|
2291
2324
|
const pair = keyring.getPair(address);
|
|
2292
2325
|
if (!pair) {
|
|
2293
|
-
throw Error('Unable to find
|
|
2326
|
+
throw Error(t('Unable to find account'));
|
|
2294
2327
|
}
|
|
2295
2328
|
if (pair.isLocked) {
|
|
2296
2329
|
keyring.unlockPair(pair.address);
|
|
@@ -2306,7 +2339,7 @@ export default class KoniExtension {
|
|
|
2306
2339
|
} else {
|
|
2307
2340
|
const tx = createTransactionFromRLP(message);
|
|
2308
2341
|
if (!tx) {
|
|
2309
|
-
throw new Error(
|
|
2342
|
+
throw new Error(t('Failed to decode data. Please use a valid QR code'));
|
|
2310
2343
|
}
|
|
2311
2344
|
const txObject = {
|
|
2312
2345
|
gasPrice: new BigN(tx.gasPrice).toNumber(),
|
|
@@ -2655,7 +2688,7 @@ export default class KoniExtension {
|
|
|
2655
2688
|
} catch (e) {
|
|
2656
2689
|
console.error(e);
|
|
2657
2690
|
return {
|
|
2658
|
-
errors: [e.message],
|
|
2691
|
+
errors: [t(e.message)],
|
|
2659
2692
|
status: false
|
|
2660
2693
|
};
|
|
2661
2694
|
}
|
|
@@ -2753,7 +2786,7 @@ export default class KoniExtension {
|
|
|
2753
2786
|
id
|
|
2754
2787
|
}) {
|
|
2755
2788
|
const queued = this.#koniState.getSignRequest(id);
|
|
2756
|
-
assert(queued, 'Unable to
|
|
2789
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
2757
2790
|
const {
|
|
2758
2791
|
reject,
|
|
2759
2792
|
request,
|
|
@@ -2768,7 +2801,7 @@ export default class KoniExtension {
|
|
|
2768
2801
|
address
|
|
2769
2802
|
} = pair;
|
|
2770
2803
|
if (!pair) {
|
|
2771
|
-
reject(new Error('Unable to find
|
|
2804
|
+
reject(new Error(t('Unable to find account')));
|
|
2772
2805
|
return false;
|
|
2773
2806
|
}
|
|
2774
2807
|
if (pair.isLocked) {
|
|
@@ -2841,7 +2874,7 @@ export default class KoniExtension {
|
|
|
2841
2874
|
}
|
|
2842
2875
|
} catch (e) {}
|
|
2843
2876
|
if (!index) {
|
|
2844
|
-
throw Error('Invalid derive path');
|
|
2877
|
+
throw Error(t('Invalid derive path'));
|
|
2845
2878
|
}
|
|
2846
2879
|
meta.suri = `//${index}`;
|
|
2847
2880
|
return parentPair.deriveEvm(index, meta);
|
|
@@ -2929,7 +2962,7 @@ export default class KoniExtension {
|
|
|
2929
2962
|
}
|
|
2930
2963
|
} catch (e) {}
|
|
2931
2964
|
if (!index) {
|
|
2932
|
-
throw Error('Invalid derive path');
|
|
2965
|
+
throw Error(t('Invalid derive path'));
|
|
2933
2966
|
}
|
|
2934
2967
|
meta.suri = `//${index}`;
|
|
2935
2968
|
childPair = parentPair.deriveEvm(index, meta);
|
|
@@ -3508,6 +3541,8 @@ export default class KoniExtension {
|
|
|
3508
3541
|
return this.saveBrowserConfirmationType(request);
|
|
3509
3542
|
case 'pri(settings.saveAutoLockTime)':
|
|
3510
3543
|
return this.setAutoLockTime(request);
|
|
3544
|
+
case 'pri(settings.saveUnlockType)':
|
|
3545
|
+
return this.setUnlockType(request);
|
|
3511
3546
|
case 'pri(settings.saveEnableChainPatrol)':
|
|
3512
3547
|
return this.setEnableChainPatrol(request);
|
|
3513
3548
|
case 'pri(settings.saveShowZeroBalance)':
|
|
@@ -32,6 +32,7 @@ import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
|
32
32
|
import { decodePair } from '@subwallet/keyring/pair/decode';
|
|
33
33
|
import { keyring } from '@subwallet/ui-keyring';
|
|
34
34
|
import SimpleKeyring from 'eth-simple-keyring';
|
|
35
|
+
import { t } from 'i18next';
|
|
35
36
|
import { Subject } from 'rxjs';
|
|
36
37
|
import { assert, BN, hexStripPrefix, hexToU8a, isHex, logger as createLogger, u8aToHex } from '@polkadot/util';
|
|
37
38
|
import { base64Decode, isEthereumAddress, keyExtractSuri } from '@polkadot/util-crypto';
|
|
@@ -138,7 +139,7 @@ export default class KoniState {
|
|
|
138
139
|
|
|
139
140
|
// Start a provider, return its meta
|
|
140
141
|
rpcStartProvider(key, port) {
|
|
141
|
-
assert(Object.keys(this.providers).includes(key),
|
|
142
|
+
assert(Object.keys(this.providers).includes(key), 'Provider cannot be found.');
|
|
142
143
|
if (this.injectedProviders.get(port)) {
|
|
143
144
|
return Promise.resolve(this.providers[key].meta);
|
|
144
145
|
}
|
|
@@ -488,7 +489,7 @@ export default class KoniState {
|
|
|
488
489
|
setAccountTie(address, genesisHash) {
|
|
489
490
|
if (address !== ALL_ACCOUNT_KEY) {
|
|
490
491
|
const pair = keyring.getPair(address);
|
|
491
|
-
assert(pair, 'Unable to find
|
|
492
|
+
assert(pair, t('Unable to find account'));
|
|
492
493
|
keyring.saveAccountMeta(pair, {
|
|
493
494
|
...pair.meta,
|
|
494
495
|
genesisHash
|
|
@@ -512,7 +513,11 @@ export default class KoniState {
|
|
|
512
513
|
authUrls[shortenUrl].currentEvmNetworkKey = networkKey;
|
|
513
514
|
this.setAuthorize(authUrls);
|
|
514
515
|
} else {
|
|
515
|
-
throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR,
|
|
516
|
+
throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, t('Not found {{shortenUrl}} in auth list', {
|
|
517
|
+
replace: {
|
|
518
|
+
shortenUrl
|
|
519
|
+
}
|
|
520
|
+
}));
|
|
516
521
|
}
|
|
517
522
|
}
|
|
518
523
|
async switchNetworkAccount(id, url, networkKey, changeAddress) {
|
|
@@ -537,7 +542,7 @@ export default class KoniState {
|
|
|
537
542
|
}
|
|
538
543
|
if (useAddress !== ALL_ACCOUNT_KEY) {
|
|
539
544
|
const pair = keyring.getPair(useAddress);
|
|
540
|
-
assert(pair, 'Unable to find
|
|
545
|
+
assert(pair, t('Unable to find account'));
|
|
541
546
|
keyring.saveAccountMeta(pair, {
|
|
542
547
|
...pair.meta,
|
|
543
548
|
genesisHash: _getSubstrateGenesisHash(chainInfo)
|
|
@@ -1114,10 +1119,10 @@ export default class KoniState {
|
|
|
1114
1119
|
payload = p1;
|
|
1115
1120
|
}
|
|
1116
1121
|
if (address === '' || !payload) {
|
|
1117
|
-
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, 'Not found address or payload to sign');
|
|
1122
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Not found address or payload to sign'));
|
|
1118
1123
|
}
|
|
1119
1124
|
if (['eth_sign', 'personal_sign', 'eth_signTypedData', 'eth_signTypedData_v1', 'eth_signTypedData_v3', 'eth_signTypedData_v4'].indexOf(method) < 0) {
|
|
1120
|
-
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, '
|
|
1125
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Unsupported action'));
|
|
1121
1126
|
}
|
|
1122
1127
|
if (['eth_signTypedData_v3', 'eth_signTypedData_v4'].indexOf(method) > -1) {
|
|
1123
1128
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-assignment
|
|
@@ -1126,11 +1131,11 @@ export default class KoniState {
|
|
|
1126
1131
|
|
|
1127
1132
|
// Check sign abiblity
|
|
1128
1133
|
if (!allowedAccounts.find(acc => acc.toLowerCase() === address.toLowerCase())) {
|
|
1129
|
-
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, '
|
|
1134
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('You have rescinded allowance for this account in wallet'));
|
|
1130
1135
|
}
|
|
1131
1136
|
const pair = keyring.getPair(address);
|
|
1132
1137
|
if (!pair) {
|
|
1133
|
-
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, '
|
|
1138
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Unable to find account'));
|
|
1134
1139
|
}
|
|
1135
1140
|
const account = {
|
|
1136
1141
|
address: pair.address,
|
|
@@ -1153,7 +1158,7 @@ export default class KoniState {
|
|
|
1153
1158
|
}
|
|
1154
1159
|
break;
|
|
1155
1160
|
default:
|
|
1156
|
-
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, '
|
|
1161
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Unsupported action'));
|
|
1157
1162
|
}
|
|
1158
1163
|
const signPayload = {
|
|
1159
1164
|
account: account,
|
|
@@ -1174,7 +1179,7 @@ export default class KoniState {
|
|
|
1174
1179
|
if (payload) {
|
|
1175
1180
|
return payload;
|
|
1176
1181
|
} else {
|
|
1177
|
-
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, 'Not found signature');
|
|
1182
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Not found signature'));
|
|
1178
1183
|
}
|
|
1179
1184
|
} else {
|
|
1180
1185
|
throw new EvmProviderError(EvmProviderErrorType.USER_REJECTED_REQUEST);
|
|
@@ -1194,7 +1199,7 @@ export default class KoniState {
|
|
|
1194
1199
|
return val;
|
|
1195
1200
|
};
|
|
1196
1201
|
if (transactionParams.from === transactionParams.to) {
|
|
1197
|
-
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, '
|
|
1202
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Receiving address must be different from sending address'));
|
|
1198
1203
|
}
|
|
1199
1204
|
const transaction = {
|
|
1200
1205
|
from: transactionParams.from,
|
|
@@ -1223,11 +1228,11 @@ export default class KoniState {
|
|
|
1223
1228
|
// Address is validated in before step
|
|
1224
1229
|
const fromAddress = allowedAccounts.find(account => account.toLowerCase() === transaction.from.toLowerCase());
|
|
1225
1230
|
if (!fromAddress) {
|
|
1226
|
-
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, '
|
|
1231
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('You have rescinded allowance for this account in wallet'));
|
|
1227
1232
|
}
|
|
1228
1233
|
const pair = keyring.getPair(fromAddress);
|
|
1229
1234
|
if (!pair) {
|
|
1230
|
-
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, '
|
|
1235
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Unable to find account'));
|
|
1231
1236
|
}
|
|
1232
1237
|
const account = {
|
|
1233
1238
|
address: pair.address,
|
|
@@ -1237,7 +1242,7 @@ export default class KoniState {
|
|
|
1237
1242
|
// Validate balance
|
|
1238
1243
|
const balance = new BN((await web3.eth.getBalance(fromAddress)) || 0);
|
|
1239
1244
|
if (balance.lt(new BN(gasPrice.toString()).mul(new BN(transaction.gas)).add(new BN(autoFormatNumber(transactionParams.value) || '0')))) {
|
|
1240
|
-
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, '
|
|
1245
|
+
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Insufficient balance'));
|
|
1241
1246
|
}
|
|
1242
1247
|
transaction.nonce = await web3.eth.getTransactionCount(fromAddress);
|
|
1243
1248
|
const hashPayload = this.transactionService.generateHashPayload(networkKey, transaction);
|