@subwallet/extension-base 1.1.9-0 → 1.1.11-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/defaults.js +3 -1
- package/cjs/koni/api/dotsama/parseTransaction.js +2 -1
- package/cjs/koni/api/nft/config.js +10 -12
- 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 +256 -183
- 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/chain-service/constants.js +3 -2
- package/cjs/services/keyring-service/index.js +4 -0
- package/cjs/services/request-service/handler/AuthRequestHandler.js +4 -4
- package/cjs/services/request-service/handler/EvmRequestHandler.js +24 -11
- package/cjs/services/request-service/handler/SubstrateRequestHandler.js +10 -2
- package/cjs/services/request-service/index.js +1 -1
- package/cjs/services/setting-service/SettingService.js +29 -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/getId.js +1 -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/defaults.d.ts +2 -1
- package/defaults.js +2 -1
- package/koni/api/dotsama/parseTransaction.js +2 -1
- package/koni/api/nft/config.d.ts +1 -1
- package/koni/api/nft/config.js +8 -10
- 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 +135 -63
- 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/chain-service/constants.js +3 -2
- package/services/keyring-service/index.d.ts +1 -0
- package/services/keyring-service/index.js +4 -0
- package/services/request-service/handler/AuthRequestHandler.js +4 -4
- package/services/request-service/handler/EvmRequestHandler.js +24 -11
- package/services/request-service/handler/SubstrateRequestHandler.js +10 -2
- package/services/request-service/index.d.ts +1 -1
- package/services/request-service/index.js +1 -1
- package/services/setting-service/SettingService.d.ts +2 -0
- package/services/setting-service/SettingService.js +26 -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.d.ts +3 -3
- 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/getId.js +2 -2
- 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';
|
|
@@ -67,16 +68,31 @@ export default class KoniExtension {
|
|
|
67
68
|
#koniState;
|
|
68
69
|
#timeAutoLock = DEFAULT_AUTO_LOCK_TIME;
|
|
69
70
|
#skipAutoLock = false;
|
|
71
|
+
#alwaysLock = false;
|
|
72
|
+
#firstTime = true;
|
|
70
73
|
constructor(state) {
|
|
71
74
|
this.#koniState = state;
|
|
72
75
|
const updateTimeAutoLock = rs => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
// Check time auto lock change
|
|
77
|
+
if (this.#timeAutoLock !== rs.timeAutoLock) {
|
|
78
|
+
this.#timeAutoLock = rs.timeAutoLock;
|
|
79
|
+
this.#alwaysLock = !rs.timeAutoLock;
|
|
80
|
+
clearTimeout(this.#lockTimeOut);
|
|
81
|
+
if (this.#timeAutoLock > 0) {
|
|
82
|
+
this.#lockTimeOut = setTimeout(() => {
|
|
83
|
+
if (!this.#skipAutoLock) {
|
|
84
|
+
this.keyringLock();
|
|
85
|
+
}
|
|
86
|
+
}, this.#timeAutoLock * 60 * 1000);
|
|
87
|
+
} else if (this.#alwaysLock) {
|
|
88
|
+
if (!this.#firstTime) {
|
|
89
|
+
this.keyringLock();
|
|
90
|
+
}
|
|
78
91
|
}
|
|
79
|
-
}
|
|
92
|
+
}
|
|
93
|
+
if (this.#firstTime) {
|
|
94
|
+
this.#firstTime = false;
|
|
95
|
+
}
|
|
80
96
|
};
|
|
81
97
|
this.#koniState.settingService.getSettings(updateTimeAutoLock);
|
|
82
98
|
this.#koniState.settingService.getSubject().subscribe({
|
|
@@ -130,14 +146,14 @@ export default class KoniExtension {
|
|
|
130
146
|
oldPass
|
|
131
147
|
}) {
|
|
132
148
|
const pair = keyring.getPair(address);
|
|
133
|
-
assert(pair, 'Unable to find
|
|
149
|
+
assert(pair, t('Unable to find account'));
|
|
134
150
|
try {
|
|
135
151
|
if (!pair.isLocked) {
|
|
136
152
|
pair.lock();
|
|
137
153
|
}
|
|
138
154
|
pair.decodePkcs8(oldPass);
|
|
139
155
|
} catch (error) {
|
|
140
|
-
throw new Error('
|
|
156
|
+
throw new Error(t('Wrong password'));
|
|
141
157
|
}
|
|
142
158
|
keyring.encryptAccount(pair, newPass);
|
|
143
159
|
return true;
|
|
@@ -147,7 +163,7 @@ export default class KoniExtension {
|
|
|
147
163
|
name
|
|
148
164
|
}) {
|
|
149
165
|
const pair = keyring.getPair(address);
|
|
150
|
-
assert(pair, 'Unable to find
|
|
166
|
+
assert(pair, t('Unable to find account'));
|
|
151
167
|
keyring.saveAccountMeta(pair, {
|
|
152
168
|
...pair.meta,
|
|
153
169
|
name
|
|
@@ -167,7 +183,7 @@ export default class KoniExtension {
|
|
|
167
183
|
isShowing
|
|
168
184
|
}) {
|
|
169
185
|
const pair = keyring.getPair(address);
|
|
170
|
-
assert(pair, 'Unable to find
|
|
186
|
+
assert(pair, t('Unable to find account'));
|
|
171
187
|
keyring.saveAccountMeta(pair, {
|
|
172
188
|
...pair.meta,
|
|
173
189
|
isHidden: !isShowing
|
|
@@ -201,7 +217,7 @@ export default class KoniExtension {
|
|
|
201
217
|
id
|
|
202
218
|
}) {
|
|
203
219
|
const queued = this.#koniState.getMetaRequest(id);
|
|
204
|
-
assert(queued, 'Unable to
|
|
220
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
205
221
|
const {
|
|
206
222
|
request,
|
|
207
223
|
resolve
|
|
@@ -220,7 +236,7 @@ export default class KoniExtension {
|
|
|
220
236
|
id
|
|
221
237
|
}) {
|
|
222
238
|
const queued = this.#koniState.getMetaRequest(id);
|
|
223
|
-
assert(queued, 'Unable to
|
|
239
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
224
240
|
const {
|
|
225
241
|
reject
|
|
226
242
|
} = queued;
|
|
@@ -296,11 +312,15 @@ export default class KoniExtension {
|
|
|
296
312
|
phrase
|
|
297
313
|
} = keyExtractSuri(suri);
|
|
298
314
|
if (isHex(phrase)) {
|
|
299
|
-
assert(isHex(phrase, 256), '
|
|
315
|
+
assert(isHex(phrase, 256), t('Invalid seed phrase. Please try again.'));
|
|
300
316
|
} else {
|
|
301
317
|
// sadly isHex detects as string, so we need a cast here
|
|
302
|
-
assert(SEED_LENGTHS.includes(phrase.split(' ').length),
|
|
303
|
-
|
|
318
|
+
assert(SEED_LENGTHS.includes(phrase.split(' ').length), t('Seed phrase needs to contain {{x}} words', {
|
|
319
|
+
replace: {
|
|
320
|
+
x: SEED_LENGTHS.join(', ')
|
|
321
|
+
}
|
|
322
|
+
}));
|
|
323
|
+
assert(mnemonicValidate(phrase), t('Invalid seed phrase. Please try again.'));
|
|
304
324
|
}
|
|
305
325
|
return {
|
|
306
326
|
address: keyring.createFromUri(getSuri(suri, type), {}, type).address,
|
|
@@ -314,7 +334,7 @@ export default class KoniExtension {
|
|
|
314
334
|
signature
|
|
315
335
|
}) {
|
|
316
336
|
const queued = this.#koniState.getSignRequest(id);
|
|
317
|
-
assert(queued, 'Unable to
|
|
337
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
318
338
|
const {
|
|
319
339
|
resolve
|
|
320
340
|
} = queued;
|
|
@@ -330,7 +350,7 @@ export default class KoniExtension {
|
|
|
330
350
|
id
|
|
331
351
|
}) {
|
|
332
352
|
const queued = this.#koniState.getSignRequest(id);
|
|
333
|
-
assert(queued, 'Unable to
|
|
353
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
334
354
|
const {
|
|
335
355
|
reject
|
|
336
356
|
} = queued;
|
|
@@ -379,12 +399,16 @@ export default class KoniExtension {
|
|
|
379
399
|
try {
|
|
380
400
|
parentPair.decodePkcs8(password);
|
|
381
401
|
} catch (e) {
|
|
382
|
-
throw new Error('
|
|
402
|
+
throw new Error(t('Wrong password'));
|
|
383
403
|
}
|
|
384
404
|
try {
|
|
385
405
|
return parentPair.derive(suri, metadata);
|
|
386
406
|
} catch (err) {
|
|
387
|
-
throw new Error(
|
|
407
|
+
throw new Error(t('"{{suri}}" is not a valid derivation path', {
|
|
408
|
+
replace: {
|
|
409
|
+
suri
|
|
410
|
+
}
|
|
411
|
+
}));
|
|
388
412
|
}
|
|
389
413
|
}
|
|
390
414
|
derivationValidate({
|
|
@@ -518,7 +542,7 @@ export default class KoniExtension {
|
|
|
518
542
|
publicKey: decodeAddress(address)
|
|
519
543
|
};
|
|
520
544
|
} else {
|
|
521
|
-
throw Error('
|
|
545
|
+
throw Error(t('This is not an address'));
|
|
522
546
|
}
|
|
523
547
|
}
|
|
524
548
|
editContactAccount({
|
|
@@ -530,7 +554,7 @@ export default class KoniExtension {
|
|
|
530
554
|
keyring.saveAddress(_address, meta);
|
|
531
555
|
return true;
|
|
532
556
|
} else {
|
|
533
|
-
throw Error('
|
|
557
|
+
throw Error(t('This is not an address'));
|
|
534
558
|
}
|
|
535
559
|
}
|
|
536
560
|
deleteContactAccount({
|
|
@@ -541,7 +565,7 @@ export default class KoniExtension {
|
|
|
541
565
|
keyring.forgetAddress(_address);
|
|
542
566
|
return true;
|
|
543
567
|
} else {
|
|
544
|
-
throw Error('
|
|
568
|
+
throw Error(t('This is not an address'));
|
|
545
569
|
}
|
|
546
570
|
}
|
|
547
571
|
_getAuthListV2() {
|
|
@@ -589,7 +613,7 @@ export default class KoniExtension {
|
|
|
589
613
|
id
|
|
590
614
|
}) {
|
|
591
615
|
const queued = this.#koniState.getAuthRequestV2(id);
|
|
592
|
-
assert(queued, 'Unable to
|
|
616
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
593
617
|
const {
|
|
594
618
|
resolve
|
|
595
619
|
} = queued;
|
|
@@ -603,7 +627,7 @@ export default class KoniExtension {
|
|
|
603
627
|
id
|
|
604
628
|
}) {
|
|
605
629
|
const queued = this.#koniState.getAuthRequestV2(id);
|
|
606
|
-
assert(queued, 'Unable to
|
|
630
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
607
631
|
const {
|
|
608
632
|
reject
|
|
609
633
|
} = queued;
|
|
@@ -614,7 +638,7 @@ export default class KoniExtension {
|
|
|
614
638
|
id
|
|
615
639
|
}) {
|
|
616
640
|
const queued = this.#koniState.getAuthRequestV2(id);
|
|
617
|
-
assert(queued, 'Unable to
|
|
641
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
618
642
|
const {
|
|
619
643
|
reject
|
|
620
644
|
} = queued;
|
|
@@ -849,6 +873,12 @@ export default class KoniExtension {
|
|
|
849
873
|
this.#koniState.updateSetting('timeAutoLock', autoLockTime);
|
|
850
874
|
return true;
|
|
851
875
|
}
|
|
876
|
+
setUnlockType({
|
|
877
|
+
unlockType
|
|
878
|
+
}) {
|
|
879
|
+
this.#koniState.updateSetting('unlockType', unlockType);
|
|
880
|
+
return true;
|
|
881
|
+
}
|
|
852
882
|
async subscribeSettings(id, port) {
|
|
853
883
|
const cb = createSubscription(id, port);
|
|
854
884
|
const balancesVisibilitySubscription = this.#koniState.subscribeSettingsSubject().subscribe({
|
|
@@ -1071,7 +1101,7 @@ export default class KoniExtension {
|
|
|
1071
1101
|
const hasMasterPassword = keyring.keyring.hasMasterPassword;
|
|
1072
1102
|
if (!hasMasterPassword) {
|
|
1073
1103
|
if (!password) {
|
|
1074
|
-
throw Error('
|
|
1104
|
+
throw Error(t('The password of each account is needed to set up master password'));
|
|
1075
1105
|
} else {
|
|
1076
1106
|
keyring.changeMasterPassword(password);
|
|
1077
1107
|
this.#koniState.updateKeyringState();
|
|
@@ -1111,6 +1141,9 @@ export default class KoniExtension {
|
|
|
1111
1141
|
resolve();
|
|
1112
1142
|
});
|
|
1113
1143
|
});
|
|
1144
|
+
if (this.#alwaysLock) {
|
|
1145
|
+
this.keyringLock();
|
|
1146
|
+
}
|
|
1114
1147
|
return addressDict;
|
|
1115
1148
|
}
|
|
1116
1149
|
async accountsForgetOverride({
|
|
@@ -1171,11 +1204,15 @@ export default class KoniExtension {
|
|
|
1171
1204
|
phrase
|
|
1172
1205
|
} = keyExtractSuri(suri);
|
|
1173
1206
|
if (isHex(phrase)) {
|
|
1174
|
-
assert(isHex(phrase, 256), '
|
|
1207
|
+
assert(isHex(phrase, 256), t('Invalid seed phrase. Please try again.'));
|
|
1175
1208
|
} else {
|
|
1176
1209
|
// sadly isHex detects as string, so we need a cast here
|
|
1177
|
-
assert(SEED_LENGTHS.includes(phrase.split(' ').length),
|
|
1178
|
-
|
|
1210
|
+
assert(SEED_LENGTHS.includes(phrase.split(' ').length), t('Seed phrase needs to contain {{x}} words', {
|
|
1211
|
+
replace: {
|
|
1212
|
+
x: SEED_LENGTHS.join(', ')
|
|
1213
|
+
}
|
|
1214
|
+
}));
|
|
1215
|
+
assert(mnemonicValidate(phrase), t('Invalid seed phrase. Please try again.'));
|
|
1179
1216
|
}
|
|
1180
1217
|
const rs = {
|
|
1181
1218
|
seed: suri,
|
|
@@ -1207,7 +1244,7 @@ export default class KoniExtension {
|
|
|
1207
1244
|
});
|
|
1208
1245
|
} else {
|
|
1209
1246
|
rs.autoAddPrefix = false;
|
|
1210
|
-
assert(false, '
|
|
1247
|
+
assert(false, t('Invalid private key. Please try again.'));
|
|
1211
1248
|
}
|
|
1212
1249
|
return rs;
|
|
1213
1250
|
}
|
|
@@ -1236,7 +1273,11 @@ export default class KoniExtension {
|
|
|
1236
1273
|
try {
|
|
1237
1274
|
return parentPair.derive(suri, metadata);
|
|
1238
1275
|
} catch (err) {
|
|
1239
|
-
throw new Error(
|
|
1276
|
+
throw new Error(t('"{{suri}}" is not a valid derivation path', {
|
|
1277
|
+
replace: {
|
|
1278
|
+
suri
|
|
1279
|
+
}
|
|
1280
|
+
}));
|
|
1240
1281
|
}
|
|
1241
1282
|
}
|
|
1242
1283
|
derivationCreateV2({
|
|
@@ -1273,11 +1314,14 @@ export default class KoniExtension {
|
|
|
1273
1314
|
keyring.restoreAccount(file, password, withMasterPassword);
|
|
1274
1315
|
this._addAddressToAuthList(address, isAllowed);
|
|
1275
1316
|
});
|
|
1317
|
+
if (this.#alwaysLock) {
|
|
1318
|
+
this.keyringLock();
|
|
1319
|
+
}
|
|
1276
1320
|
} catch (error) {
|
|
1277
1321
|
throw new Error(error.message);
|
|
1278
1322
|
}
|
|
1279
1323
|
} else {
|
|
1280
|
-
throw new Error('
|
|
1324
|
+
throw new Error(t('Wrong password'));
|
|
1281
1325
|
}
|
|
1282
1326
|
}
|
|
1283
1327
|
batchRestoreV2({
|
|
@@ -1294,11 +1338,14 @@ export default class KoniExtension {
|
|
|
1294
1338
|
keyring.restoreAccounts(file, password);
|
|
1295
1339
|
this._addAddressesToAuthList(addressList, isAllowed);
|
|
1296
1340
|
});
|
|
1341
|
+
if (this.#alwaysLock) {
|
|
1342
|
+
this.keyringLock();
|
|
1343
|
+
}
|
|
1297
1344
|
} catch (error) {
|
|
1298
1345
|
throw new Error(error.message);
|
|
1299
1346
|
}
|
|
1300
1347
|
} else {
|
|
1301
|
-
throw new Error('
|
|
1348
|
+
throw new Error(t('Wrong password'));
|
|
1302
1349
|
}
|
|
1303
1350
|
}
|
|
1304
1351
|
getNftCollection() {
|
|
@@ -1405,7 +1452,7 @@ export default class KoniExtension {
|
|
|
1405
1452
|
let transferValue;
|
|
1406
1453
|
if (!transferAll) {
|
|
1407
1454
|
if (value === undefined) {
|
|
1408
|
-
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, '
|
|
1455
|
+
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, t('Transfer amount is required')));
|
|
1409
1456
|
}
|
|
1410
1457
|
if (value) {
|
|
1411
1458
|
transferValue = new BN(value);
|
|
@@ -1413,10 +1460,10 @@ export default class KoniExtension {
|
|
|
1413
1460
|
}
|
|
1414
1461
|
const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
|
|
1415
1462
|
if (!tokenInfo) {
|
|
1416
|
-
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, 'Not found token from registry'));
|
|
1463
|
+
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, t('Not found token from registry')));
|
|
1417
1464
|
}
|
|
1418
1465
|
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'));
|
|
1466
|
+
errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, t('Not found ERC20 address for this token')));
|
|
1420
1467
|
}
|
|
1421
1468
|
return [errors, keypair, transferValue, tokenInfo];
|
|
1422
1469
|
}
|
|
@@ -1484,7 +1531,7 @@ export default class KoniExtension {
|
|
|
1484
1531
|
} catch (e) {
|
|
1485
1532
|
const error = e;
|
|
1486
1533
|
if (error.message.includes('transfer amount exceeds balance')) {
|
|
1487
|
-
error.message = '
|
|
1534
|
+
error.message = t('Insufficient balance');
|
|
1488
1535
|
}
|
|
1489
1536
|
throw error;
|
|
1490
1537
|
}
|
|
@@ -1505,7 +1552,7 @@ export default class KoniExtension {
|
|
|
1505
1552
|
token: tokenSlug
|
|
1506
1553
|
});
|
|
1507
1554
|
if (new BigN(balance).minus(transferAmount.value).lt(minAmount)) {
|
|
1508
|
-
inputTransaction.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT
|
|
1555
|
+
inputTransaction.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT));
|
|
1509
1556
|
}
|
|
1510
1557
|
}
|
|
1511
1558
|
const {
|
|
@@ -1520,7 +1567,12 @@ export default class KoniExtension {
|
|
|
1520
1567
|
if (new BigN(receiverBalance).plus(transferAmount.value).lt(minAmount)) {
|
|
1521
1568
|
const atLeast = new BigN(minAmount).minus(receiverBalance).plus((tokenInfo.decimals || 0) === 0 ? 0 : 1);
|
|
1522
1569
|
const atLeastStr = formatNumber(atLeast, tokenInfo.decimals || 0, balanceFormatter);
|
|
1523
|
-
inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT,
|
|
1570
|
+
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', {
|
|
1571
|
+
replace: {
|
|
1572
|
+
amount: atLeastStr,
|
|
1573
|
+
symbol: tokenInfo.symbol
|
|
1574
|
+
}
|
|
1575
|
+
})));
|
|
1524
1576
|
}
|
|
1525
1577
|
};
|
|
1526
1578
|
return this.#koniState.transactionService.handleTransaction({
|
|
@@ -1546,7 +1598,7 @@ export default class KoniExtension {
|
|
|
1546
1598
|
const originTokenInfo = this.#koniState.getAssetBySlug(sendingTokenSlug);
|
|
1547
1599
|
const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destinationNetworkKey, sendingTokenSlug);
|
|
1548
1600
|
if (!destinationTokenInfo) {
|
|
1549
|
-
errors.push(new TransactionError(TransferTxErrorType.INVALID_TOKEN, 'Not found token from registry'));
|
|
1601
|
+
errors.push(new TransactionError(TransferTxErrorType.INVALID_TOKEN, t('Not found token from registry')));
|
|
1550
1602
|
}
|
|
1551
1603
|
return [errors, keypair, transferValue, originTokenInfo, destinationTokenInfo];
|
|
1552
1604
|
}
|
|
@@ -1584,7 +1636,12 @@ export default class KoniExtension {
|
|
|
1584
1636
|
// Check ed for receiver
|
|
1585
1637
|
if (new BigN(value).lt(atLeast)) {
|
|
1586
1638
|
const atLeastStr = formatNumber(atLeast, destinationTokenInfo.decimals || 0, balanceFormatter);
|
|
1587
|
-
inputTransaction.errors.push(new TransactionError(TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT,
|
|
1639
|
+
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', {
|
|
1640
|
+
replace: {
|
|
1641
|
+
amount: atLeastStr,
|
|
1642
|
+
symbol: originTokenInfo.symbol
|
|
1643
|
+
}
|
|
1644
|
+
})));
|
|
1588
1645
|
}
|
|
1589
1646
|
const srcMinAmount = originTokenInfo.minAmount || '0';
|
|
1590
1647
|
const isTransferNativeToken = originTokenInfo.assetType === _AssetType.NATIVE;
|
|
@@ -1599,7 +1656,7 @@ export default class KoniExtension {
|
|
|
1599
1656
|
token: originTokenInfo.slug
|
|
1600
1657
|
});
|
|
1601
1658
|
if (new BigN(balance).minus(value).lt(srcMinAmount)) {
|
|
1602
|
-
inputTransaction.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT
|
|
1659
|
+
inputTransaction.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT));
|
|
1603
1660
|
}
|
|
1604
1661
|
}
|
|
1605
1662
|
};
|
|
@@ -1811,7 +1868,7 @@ export default class KoniExtension {
|
|
|
1811
1868
|
}
|
|
1812
1869
|
} catch (e) {
|
|
1813
1870
|
estimatedFee = '0';
|
|
1814
|
-
console.warn('
|
|
1871
|
+
console.warn('Unable to estimate fee', e);
|
|
1815
1872
|
}
|
|
1816
1873
|
maxTransferable = maxTransferable.sub(new BN(estimatedFee));
|
|
1817
1874
|
return {
|
|
@@ -1903,7 +1960,7 @@ export default class KoniExtension {
|
|
|
1903
1960
|
address
|
|
1904
1961
|
}) {
|
|
1905
1962
|
const pair = keyring.getPair(address);
|
|
1906
|
-
assert(pair, 'Unable to find
|
|
1963
|
+
assert(pair, t('Unable to find account'));
|
|
1907
1964
|
return {
|
|
1908
1965
|
meta: pair.meta
|
|
1909
1966
|
};
|
|
@@ -1930,7 +1987,7 @@ export default class KoniExtension {
|
|
|
1930
1987
|
if (exists.type === (isEthereum ? 'ethereum' : 'sr25519')) {
|
|
1931
1988
|
return [{
|
|
1932
1989
|
code: AccountExternalErrorCode.INVALID_ADDRESS,
|
|
1933
|
-
message: 'Account exists'
|
|
1990
|
+
message: t('Account exists')
|
|
1934
1991
|
}];
|
|
1935
1992
|
}
|
|
1936
1993
|
}
|
|
@@ -2016,7 +2073,7 @@ export default class KoniExtension {
|
|
|
2016
2073
|
}) {
|
|
2017
2074
|
const addresses = [];
|
|
2018
2075
|
if (!accounts.length) {
|
|
2019
|
-
throw new Error('
|
|
2076
|
+
throw new Error(t("Can't find an account. Please try again"));
|
|
2020
2077
|
}
|
|
2021
2078
|
const slugMap = {};
|
|
2022
2079
|
for (const account of accounts) {
|
|
@@ -2128,7 +2185,7 @@ export default class KoniExtension {
|
|
|
2128
2185
|
success: false,
|
|
2129
2186
|
errors: [{
|
|
2130
2187
|
code: AccountExternalErrorCode.KEYRING_ERROR,
|
|
2131
|
-
message: '
|
|
2188
|
+
message: t('Cannot create account')
|
|
2132
2189
|
}]
|
|
2133
2190
|
};
|
|
2134
2191
|
}
|
|
@@ -2144,6 +2201,9 @@ export default class KoniExtension {
|
|
|
2144
2201
|
resolve();
|
|
2145
2202
|
});
|
|
2146
2203
|
});
|
|
2204
|
+
if (this.#alwaysLock) {
|
|
2205
|
+
this.keyringLock();
|
|
2206
|
+
}
|
|
2147
2207
|
return {
|
|
2148
2208
|
errors: [],
|
|
2149
2209
|
success: true
|
|
@@ -2262,7 +2322,7 @@ export default class KoniExtension {
|
|
|
2262
2322
|
networkKey
|
|
2263
2323
|
}) {
|
|
2264
2324
|
const pair = keyring.getPair(address);
|
|
2265
|
-
assert(pair, 'Unable to find
|
|
2325
|
+
assert(pair, t('Unable to find account'));
|
|
2266
2326
|
if (pair.isLocked) {
|
|
2267
2327
|
keyring.unlockPair(pair.address);
|
|
2268
2328
|
}
|
|
@@ -2286,11 +2346,11 @@ export default class KoniExtension {
|
|
|
2286
2346
|
let signed;
|
|
2287
2347
|
const network = this.getNetworkJsonByChainId(chainId);
|
|
2288
2348
|
if (!network) {
|
|
2289
|
-
throw new Error('Cannot find network');
|
|
2349
|
+
throw new Error(t('Cannot find network'));
|
|
2290
2350
|
}
|
|
2291
2351
|
const pair = keyring.getPair(address);
|
|
2292
2352
|
if (!pair) {
|
|
2293
|
-
throw Error('Unable to find
|
|
2353
|
+
throw Error(t('Unable to find account'));
|
|
2294
2354
|
}
|
|
2295
2355
|
if (pair.isLocked) {
|
|
2296
2356
|
keyring.unlockPair(pair.address);
|
|
@@ -2306,7 +2366,7 @@ export default class KoniExtension {
|
|
|
2306
2366
|
} else {
|
|
2307
2367
|
const tx = createTransactionFromRLP(message);
|
|
2308
2368
|
if (!tx) {
|
|
2309
|
-
throw new Error(
|
|
2369
|
+
throw new Error(t('Failed to decode data. Please use a valid QR code'));
|
|
2310
2370
|
}
|
|
2311
2371
|
const txObject = {
|
|
2312
2372
|
gasPrice: new BigN(tx.gasPrice).toNumber(),
|
|
@@ -2655,11 +2715,14 @@ export default class KoniExtension {
|
|
|
2655
2715
|
} catch (e) {
|
|
2656
2716
|
console.error(e);
|
|
2657
2717
|
return {
|
|
2658
|
-
errors: [e.message],
|
|
2718
|
+
errors: [t(e.message)],
|
|
2659
2719
|
status: false
|
|
2660
2720
|
};
|
|
2661
2721
|
}
|
|
2662
2722
|
this.#koniState.updateKeyringState();
|
|
2723
|
+
if (this.#alwaysLock) {
|
|
2724
|
+
this.keyringLock();
|
|
2725
|
+
}
|
|
2663
2726
|
return {
|
|
2664
2727
|
status: true,
|
|
2665
2728
|
errors: []
|
|
@@ -2711,8 +2774,7 @@ export default class KoniExtension {
|
|
|
2711
2774
|
// Lock wallet
|
|
2712
2775
|
|
|
2713
2776
|
keyringLock() {
|
|
2714
|
-
|
|
2715
|
-
this.#koniState.updateKeyringState();
|
|
2777
|
+
this.#koniState.keyringService.lock();
|
|
2716
2778
|
clearTimeout(this.#lockTimeOut);
|
|
2717
2779
|
}
|
|
2718
2780
|
|
|
@@ -2753,7 +2815,7 @@ export default class KoniExtension {
|
|
|
2753
2815
|
id
|
|
2754
2816
|
}) {
|
|
2755
2817
|
const queued = this.#koniState.getSignRequest(id);
|
|
2756
|
-
assert(queued, 'Unable to
|
|
2818
|
+
assert(queued, t('Unable to proceed. Please try again'));
|
|
2757
2819
|
const {
|
|
2758
2820
|
reject,
|
|
2759
2821
|
request,
|
|
@@ -2768,7 +2830,7 @@ export default class KoniExtension {
|
|
|
2768
2830
|
address
|
|
2769
2831
|
} = pair;
|
|
2770
2832
|
if (!pair) {
|
|
2771
|
-
reject(new Error('Unable to find
|
|
2833
|
+
reject(new Error(t('Unable to find account')));
|
|
2772
2834
|
return false;
|
|
2773
2835
|
}
|
|
2774
2836
|
if (pair.isLocked) {
|
|
@@ -2808,6 +2870,9 @@ export default class KoniExtension {
|
|
|
2808
2870
|
// In case evm chain, must be cut 2 character after 0x
|
|
2809
2871
|
signature: isEvm ? `0x${result.signature.slice(4)}` : result.signature
|
|
2810
2872
|
});
|
|
2873
|
+
if (this.#alwaysLock) {
|
|
2874
|
+
this.keyringLock();
|
|
2875
|
+
}
|
|
2811
2876
|
return true;
|
|
2812
2877
|
}
|
|
2813
2878
|
|
|
@@ -2841,7 +2906,7 @@ export default class KoniExtension {
|
|
|
2841
2906
|
}
|
|
2842
2907
|
} catch (e) {}
|
|
2843
2908
|
if (!index) {
|
|
2844
|
-
throw Error('Invalid derive path');
|
|
2909
|
+
throw Error(t('Invalid derive path'));
|
|
2845
2910
|
}
|
|
2846
2911
|
meta.suri = `//${index}`;
|
|
2847
2912
|
return parentPair.deriveEvm(index, meta);
|
|
@@ -2904,6 +2969,9 @@ export default class KoniExtension {
|
|
|
2904
2969
|
keyring.addPair(childPair, true);
|
|
2905
2970
|
this._addAddressToAuthList(address, true);
|
|
2906
2971
|
});
|
|
2972
|
+
if (this.#alwaysLock) {
|
|
2973
|
+
this.keyringLock();
|
|
2974
|
+
}
|
|
2907
2975
|
return true;
|
|
2908
2976
|
}
|
|
2909
2977
|
validateDerivePath({
|
|
@@ -2929,7 +2997,7 @@ export default class KoniExtension {
|
|
|
2929
2997
|
}
|
|
2930
2998
|
} catch (e) {}
|
|
2931
2999
|
if (!index) {
|
|
2932
|
-
throw Error('Invalid derive path');
|
|
3000
|
+
throw Error(t('Invalid derive path'));
|
|
2933
3001
|
}
|
|
2934
3002
|
meta.suri = `//${index}`;
|
|
2935
3003
|
childPair = parentPair.deriveEvm(index, meta);
|
|
@@ -3409,11 +3477,13 @@ export default class KoniExtension {
|
|
|
3409
3477
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3410
3478
|
async handle(id, type, request, port) {
|
|
3411
3479
|
clearTimeout(this.#lockTimeOut);
|
|
3412
|
-
this.#
|
|
3413
|
-
|
|
3414
|
-
this
|
|
3415
|
-
|
|
3416
|
-
|
|
3480
|
+
if (this.#timeAutoLock > 0) {
|
|
3481
|
+
this.#lockTimeOut = setTimeout(() => {
|
|
3482
|
+
if (!this.#skipAutoLock) {
|
|
3483
|
+
this.keyringLock();
|
|
3484
|
+
}
|
|
3485
|
+
}, this.#timeAutoLock * 60 * 1000);
|
|
3486
|
+
}
|
|
3417
3487
|
switch (type) {
|
|
3418
3488
|
/// Clone from PolkadotJs
|
|
3419
3489
|
case 'pri(accounts.create.external)':
|
|
@@ -3508,6 +3578,8 @@ export default class KoniExtension {
|
|
|
3508
3578
|
return this.saveBrowserConfirmationType(request);
|
|
3509
3579
|
case 'pri(settings.saveAutoLockTime)':
|
|
3510
3580
|
return this.setAutoLockTime(request);
|
|
3581
|
+
case 'pri(settings.saveUnlockType)':
|
|
3582
|
+
return this.setUnlockType(request);
|
|
3511
3583
|
case 'pri(settings.saveEnableChainPatrol)':
|
|
3512
3584
|
return this.setEnableChainPatrol(request);
|
|
3513
3585
|
case 'pri(settings.saveShowZeroBalance)':
|