@subwallet/extension-base 1.1.8-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.
Files changed (106) hide show
  1. package/background/KoniTypes.d.ts +13 -1
  2. package/background/KoniTypes.js +5 -0
  3. package/background/errors/BalanceError.js +7 -5
  4. package/background/errors/EvmProviderError.js +10 -8
  5. package/background/errors/ProviderError.js +5 -4
  6. package/background/errors/TransactionError.js +22 -17
  7. package/background/handlers/Extension.js +18 -18
  8. package/background/handlers/State.js +5 -5
  9. package/background/handlers/Tabs.js +1 -1
  10. package/background/warnings/TransactionWarning.js +4 -2
  11. package/cjs/background/KoniTypes.js +7 -1
  12. package/cjs/background/errors/BalanceError.js +7 -5
  13. package/cjs/background/errors/EvmProviderError.js +10 -8
  14. package/cjs/background/errors/ProviderError.js +5 -4
  15. package/cjs/background/errors/TransactionError.js +22 -17
  16. package/cjs/background/handlers/Extension.js +18 -18
  17. package/cjs/background/handlers/State.js +5 -5
  18. package/cjs/background/handlers/Tabs.js +1 -1
  19. package/cjs/background/warnings/TransactionWarning.js +4 -2
  20. package/cjs/constants/i18n.js +4 -1
  21. package/cjs/constants/index.js +12 -0
  22. package/cjs/constants/storage.js +11 -0
  23. package/cjs/koni/api/dotsama/domain.js +3 -1
  24. package/cjs/koni/api/dotsama/parseTransaction.js +2 -1
  25. package/cjs/koni/api/nft/acala_nft/index.js +1 -1
  26. package/cjs/koni/api/nft/karura_nft/index.js +1 -1
  27. package/cjs/koni/api/nft/nft.js +3 -0
  28. package/cjs/koni/api/nft/wasm_nft/index.js +25 -7
  29. package/cjs/koni/api/staking/bonding/paraChain.js +10 -6
  30. package/cjs/koni/api/staking/bonding/relayChain.js +16 -7
  31. package/cjs/koni/api/staking/bonding/utils.js +80 -7
  32. package/cjs/koni/api/tokens/wasm/index.js +14 -0
  33. package/cjs/koni/background/cron.js +1 -1
  34. package/cjs/koni/background/handlers/Extension.js +206 -170
  35. package/cjs/koni/background/handlers/State.js +19 -14
  36. package/cjs/koni/background/handlers/Tabs.js +15 -14
  37. package/cjs/packageInfo.js +1 -1
  38. package/cjs/services/balance-service/index.js +12 -3
  39. package/cjs/services/chain-service/helper/index.js +8 -2
  40. package/cjs/services/request-service/handler/AuthRequestHandler.js +4 -4
  41. package/cjs/services/request-service/handler/EvmRequestHandler.js +11 -10
  42. package/cjs/services/setting-service/SettingService.js +20 -7
  43. package/cjs/services/setting-service/constants.js +5 -1
  44. package/cjs/services/setting-service/i18n/Backend.js +42 -0
  45. package/cjs/services/setting-service/i18n/cache.js +12 -0
  46. package/cjs/services/setting-service/i18n/extend.js +16 -0
  47. package/cjs/services/setting-service/i18n/i18n.js +29 -0
  48. package/cjs/services/transaction-service/index.js +25 -16
  49. package/cjs/services/wallet-connect-service/handler/PolkadotRequestHandler.js +0 -1
  50. package/cjs/services/wallet-connect-service/index.js +18 -10
  51. package/cjs/utils/eth/parseTransaction/base.js +1 -1
  52. package/cjs/utils/eth/parseTransaction/index.js +2 -1
  53. package/cjs/utils/index.js +2 -1
  54. package/constants/i18n.js +4 -1
  55. package/constants/index.d.ts +1 -0
  56. package/constants/index.js +2 -1
  57. package/constants/storage.d.ts +1 -0
  58. package/constants/storage.js +4 -0
  59. package/koni/api/dotsama/domain.d.ts +1 -0
  60. package/koni/api/dotsama/domain.js +1 -0
  61. package/koni/api/dotsama/parseTransaction.js +2 -1
  62. package/koni/api/nft/acala_nft/index.js +1 -1
  63. package/koni/api/nft/karura_nft/index.js +1 -1
  64. package/koni/api/nft/nft.js +3 -0
  65. package/koni/api/nft/wasm_nft/index.js +26 -8
  66. package/koni/api/staking/bonding/paraChain.js +11 -7
  67. package/koni/api/staking/bonding/relayChain.js +17 -8
  68. package/koni/api/staking/bonding/utils.d.ts +4 -0
  69. package/koni/api/staking/bonding/utils.js +70 -2
  70. package/koni/api/tokens/wasm/index.d.ts +2 -0
  71. package/koni/api/tokens/wasm/index.js +13 -1
  72. package/koni/background/cron.js +1 -1
  73. package/koni/background/handlers/Extension.d.ts +1 -0
  74. package/koni/background/handlers/Extension.js +85 -50
  75. package/koni/background/handlers/State.js +19 -14
  76. package/koni/background/handlers/Tabs.js +15 -14
  77. package/package.json +34 -12
  78. package/packageInfo.js +1 -1
  79. package/services/balance-service/index.js +12 -3
  80. package/services/chain-service/helper/azero_domain_registry_abi.json +5428 -0
  81. package/services/chain-service/helper/index.d.ts +2 -0
  82. package/services/chain-service/helper/index.js +5 -1
  83. package/services/chain-service/helper/pink_psp34_abi.json +2758 -0
  84. package/services/request-service/handler/AuthRequestHandler.js +4 -4
  85. package/services/request-service/handler/EvmRequestHandler.js +11 -10
  86. package/services/setting-service/SettingService.d.ts +1 -0
  87. package/services/setting-service/SettingService.js +17 -5
  88. package/services/setting-service/constants.d.ts +2 -1
  89. package/services/setting-service/constants.js +4 -1
  90. package/services/setting-service/i18n/Backend.d.ts +9 -0
  91. package/services/setting-service/i18n/Backend.js +34 -0
  92. package/services/setting-service/i18n/cache.d.ts +2 -0
  93. package/services/setting-service/i18n/cache.js +5 -0
  94. package/services/setting-service/i18n/extend.d.ts +2 -0
  95. package/services/setting-service/i18n/extend.js +8 -0
  96. package/services/setting-service/i18n/i18n.d.ts +2 -0
  97. package/services/setting-service/i18n/i18n.js +21 -0
  98. package/services/transaction-service/index.js +25 -16
  99. package/services/wallet-connect-service/handler/PolkadotRequestHandler.js +0 -1
  100. package/services/wallet-connect-service/index.js +18 -10
  101. package/utils/eth/parseTransaction/base.js +1 -1
  102. package/utils/eth/parseTransaction/index.js +2 -1
  103. package/utils/index.js +2 -1
  104. package/cjs/utils/keyring.js +0 -57
  105. package/utils/keyring.d.ts +0 -4
  106. package/utils/keyring.js +0 -49
@@ -210,7 +210,7 @@ export default class AuthRequestHandler {
210
210
  const idStr = stripUrl(url);
211
211
  // Do not enqueue duplicate authorization requests.
212
212
  const isDuplicate = Object.values(this.#authRequestsV2).some(request => request.idStr === idStr);
213
- assert(!isDuplicate, `The source ${url} has a pending authorization request`);
213
+ assert(!isDuplicate, 'The source {{url}} has a pending authorization request'.replace('{{url}}', url));
214
214
  const existedAuth = authList[idStr];
215
215
  const existedAccountAuthType = existedAuth === null || existedAuth === void 0 ? void 0 : existedAuth.accountAuthType;
216
216
  const confirmAnotherType = existedAccountAuthType !== 'both' && existedAccountAuthType !== request.accountAuthType;
@@ -222,7 +222,7 @@ export default class AuthRequestHandler {
222
222
  if (existedAuth) {
223
223
  const inBlackList = existedAuth && !existedAuth.isAllowed;
224
224
  if (inBlackList) {
225
- throw new Error(`The source ${url} is not allowed to interact with this extension`);
225
+ throw new Error('The source {{url}} is not allowed to interact with this extension'.replace('{{url}}', url));
226
226
  }
227
227
  request.allowedAccounts = Object.entries(existedAuth.isAllowedMap).map(([address, allowed]) => allowed ? address : '').filter(item => item !== '');
228
228
  let allowedListByRequestType = [...request.allowedAccounts];
@@ -270,11 +270,11 @@ export default class AuthRequestHandler {
270
270
  }
271
271
  const entry = Object.keys(value).includes(idStr);
272
272
  if (!entry) {
273
- reject(new Error(`The source ${url} has not been enabled yet`));
273
+ reject(new Error('The source {{url}} has not been authorized yet'.replace('{{url}}', url)));
274
274
  }
275
275
  const isConnected = value[idStr] && Object.keys(value[idStr].isAllowedMap).some(address => value[idStr].isAllowedMap[address]);
276
276
  if (!isConnected) {
277
- reject(new Error(`The source ${url} is not allowed to interact with this extension`));
277
+ reject(new Error('The source {{url}} is not allowed to interact with this extension'.replace('{{url}}', url)));
278
278
  }
279
279
  resolve(true);
280
280
  });
@@ -10,6 +10,7 @@ import keyring from '@subwallet/ui-keyring';
10
10
  import BN from 'bn.js';
11
11
  import { Transaction } from 'ethereumjs-tx';
12
12
  import { toBuffer } from 'ethereumjs-util';
13
+ import { t } from 'i18next';
13
14
  import { BehaviorSubject } from 'rxjs';
14
15
  import { logger as createLogger } from '@polkadot/util';
15
16
  export default class EvmRequestHandler {
@@ -46,7 +47,7 @@ export default class EvmRequestHandler {
46
47
  // Check duplicate request
47
48
  const duplicated = Object.values(confirmationType).find(c => c.url === url && c.payloadJson === payloadJson);
48
49
  if (duplicated) {
49
- throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, 'Duplicate request information');
50
+ throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Duplicate request'));
50
51
  }
51
52
  confirmationType[id] = {
52
53
  id,
@@ -79,7 +80,7 @@ export default class EvmRequestHandler {
79
80
  // Check duplicate request
80
81
  const exists = confirmationType[id];
81
82
  if (!exists) {
82
- throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, 'Request does not exist');
83
+ throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Request does not exist'));
83
84
  }
84
85
  const payloadJson = JSON.stringify(payload);
85
86
  confirmationType[id] = {
@@ -113,7 +114,7 @@ export default class EvmRequestHandler {
113
114
  case 'eth_signTypedData_v4':
114
115
  return await pair.evmSigner.signMessage(payload, type);
115
116
  default:
116
- throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, 'Not found sign method');
117
+ throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Unsupported action'));
117
118
  }
118
119
  }
119
120
  configToTransaction(config) {
@@ -186,8 +187,8 @@ export default class EvmRequestHandler {
186
187
  async completeConfirmation(request) {
187
188
  const confirmations = this.confirmationsQueueSubject.getValue();
188
189
  for (const ct in request) {
189
- const t = ct;
190
- const result = request[t];
190
+ const type = ct;
191
+ const result = request[type];
191
192
  const {
192
193
  id
193
194
  } = result;
@@ -195,14 +196,14 @@ export default class EvmRequestHandler {
195
196
  resolver,
196
197
  validator
197
198
  } = this.confirmationsPromiseMap[id];
198
- const confirmation = confirmations[t][id];
199
+ const confirmation = confirmations[type][id];
199
200
  if (!resolver || !confirmation) {
200
- this.#logger.error('Not found confirmation', t, id);
201
- throw new Error('Not found promise for confirmation');
201
+ this.#logger.error(t('Unable to proceed. Please try again'), type, id);
202
+ throw new Error(t('Unable to proceed. Please try again'));
202
203
  }
203
204
 
204
205
  // Fill signature for some special type
205
- await this.decorateResult(t, confirmation, result);
206
+ await this.decorateResult(type, confirmation, result);
206
207
 
207
208
  // Validate response from confirmation popup some info like password, response format....
208
209
  const error = validator && validator(result);
@@ -212,7 +213,7 @@ export default class EvmRequestHandler {
212
213
 
213
214
  // Delete confirmations from queue
214
215
  delete this.confirmationsPromiseMap[id];
215
- delete confirmations[t][id];
216
+ delete confirmations[type][id];
216
217
  this.confirmationsQueueSubject.next(confirmations);
217
218
 
218
219
  // Update icon, and close queue
@@ -3,6 +3,7 @@ import { Subject } from 'rxjs';
3
3
  export default class SettingService {
4
4
  private readonly settingsStore;
5
5
  private readonly passPhishingStore;
6
+ constructor();
6
7
  getSubject(): Subject<RequestSettingsType>;
7
8
  getSettings(update: (value: RequestSettingsType) => void): void;
8
9
  setSettings(data: RequestSettingsType, callback?: () => void): void;
@@ -1,22 +1,34 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { LANGUAGE } from '@subwallet/extension-base/constants';
4
5
  import PassPhishingStore from '@subwallet/extension-base/stores/PassPhishingStore';
5
6
  import SettingsStore from '@subwallet/extension-base/stores/Settings';
7
+ import i18n from "./i18n/i18n.js";
6
8
  import { DEFAULT_SETTING } from "./constants.js";
7
9
  export default class SettingService {
8
10
  settingsStore = new SettingsStore();
9
11
  passPhishingStore = new PassPhishingStore();
12
+ constructor() {
13
+ let old = localStorage.getItem(LANGUAGE) || 'en';
14
+ this.settingsStore.getSubject().subscribe(({
15
+ language
16
+ }) => {
17
+ if (language !== old) {
18
+ old = language;
19
+ i18n.changeLanguage(language).catch(console.error);
20
+ }
21
+ });
22
+ }
10
23
  getSubject() {
11
24
  return this.settingsStore.getSubject();
12
25
  }
13
26
  getSettings(update) {
14
27
  this.settingsStore.get('Settings', value => {
15
- if (!value) {
16
- update(DEFAULT_SETTING);
17
- } else {
18
- update(value);
19
- }
28
+ update({
29
+ ...DEFAULT_SETTING,
30
+ ...(value || {})
31
+ });
20
32
  });
21
33
  }
22
34
  setSettings(data, callback) {
@@ -1,7 +1,8 @@
1
- import { BrowserConfirmationType, LanguageType, ThemeNames, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
1
+ import { BrowserConfirmationType, LanguageType, ThemeNames, UiSettings, WalletUnlockType } from '@subwallet/extension-base/background/KoniTypes';
2
2
  export declare const DEFAULT_THEME: ThemeNames;
3
3
  export declare const DEFAULT_NOTIFICATION_TYPE: BrowserConfirmationType;
4
4
  export declare const DEFAULT_AUTO_LOCK_TIME = 15;
5
+ export declare const DEFAULT_UNLOCK_TYPE: WalletUnlockType;
5
6
  export declare const DEFAULT_CHAIN_PATROL_ENABLE = false;
6
7
  export declare const DEFAULT_LANGUAGE: LanguageType;
7
8
  export declare const DEFAULT_SHOW_ZERO_BALANCE = true;
@@ -1,10 +1,12 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { ThemeNames } from '@subwallet/extension-base/background/KoniTypes';
4
+ import { ThemeNames, WalletUnlockType } from '@subwallet/extension-base/background/KoniTypes';
5
+ import { TARGET_ENV } from '@subwallet/extension-base/utils';
5
6
  export const DEFAULT_THEME = ThemeNames.DARK;
6
7
  export const DEFAULT_NOTIFICATION_TYPE = 'popup';
7
8
  export const DEFAULT_AUTO_LOCK_TIME = 15;
9
+ export const DEFAULT_UNLOCK_TYPE = TARGET_ENV === 'extension' ? WalletUnlockType.ALWAYS_REQUIRED : WalletUnlockType.WHEN_NEEDED;
8
10
  export const DEFAULT_CHAIN_PATROL_ENABLE = false;
9
11
  export const DEFAULT_LANGUAGE = 'en';
10
12
  export const DEFAULT_SHOW_ZERO_BALANCE = true;
@@ -18,6 +20,7 @@ export const DEFAULT_SETTING = {
18
20
  isShowBalance: DEFAULT_SHOW_BALANCE,
19
21
  accountAllLogo: DEFAULT_ALL_LOGO,
20
22
  theme: DEFAULT_THEME,
23
+ unlockType: DEFAULT_UNLOCK_TYPE,
21
24
  camera: DEFAULT_CAMERA_ENABLE,
22
25
  timeAutoLock: DEFAULT_AUTO_LOCK_TIME,
23
26
  enableChainPatrol: DEFAULT_CHAIN_PATROL_ENABLE,
@@ -0,0 +1,9 @@
1
+ declare type Callback = (error: string | null, data: unknown) => void;
2
+ declare type LoadResult = [string | null, Record<string, string> | boolean];
3
+ export default class Backend {
4
+ type: string;
5
+ static type: 'backend';
6
+ read(lng: string, _namespace: string, responder: Callback): Promise<void>;
7
+ createLoader(lng: string): Promise<LoadResult>;
8
+ }
9
+ export {};
@@ -0,0 +1,34 @@
1
+ // Copyright 2017-2022 @polkadot/react-components authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import languageCache from "./cache.js";
5
+ const loaders = {};
6
+ export default class Backend {
7
+ type = 'backend';
8
+ static type = 'backend';
9
+ async read(lng, _namespace, responder) {
10
+ if (languageCache[lng]) {
11
+ return responder(null, languageCache[lng]);
12
+ }
13
+
14
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
15
+ if (!loaders[lng]) {
16
+ loaders[lng] = this.createLoader(lng);
17
+ }
18
+ const [error, data] = await loaders[lng];
19
+ return responder(error, data);
20
+ }
21
+ async createLoader(lng) {
22
+ try {
23
+ const response = await fetch(`locales/${lng}/translation.json`, {});
24
+ if (!response.ok) {
25
+ return [`i18n: failed loading ${lng}`, response.status >= 500 && response.status < 600];
26
+ } else {
27
+ languageCache[lng] = await response.json();
28
+ return [null, languageCache[lng]];
29
+ }
30
+ } catch (error) {
31
+ return [error.message, false];
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,2 @@
1
+ declare const languageCache: Record<string, Record<string, string>>;
2
+ export default languageCache;
@@ -0,0 +1,5 @@
1
+ // Copyright 2017-2022 @polkadot/react-components authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ const languageCache = {};
5
+ export default languageCache;
@@ -0,0 +1,2 @@
1
+ export declare const ExternalTranslation: string[];
2
+ export declare const InternalTranslation: string[];
@@ -0,0 +1,8 @@
1
+ // Copyright 2017-2022 @subwallet/extension-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { detectTranslate } from '@subwallet/extension-base/utils';
5
+ export const ExternalTranslation = [
6
+ // Case change password
7
+ detectTranslate('Invalid master password')];
8
+ export const InternalTranslation = [];
@@ -0,0 +1,2 @@
1
+ import i18next from 'i18next';
2
+ export default i18next;
@@ -0,0 +1,21 @@
1
+ // Copyright 2019-2022 @polkadot/extension-ui authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { LANGUAGE } from '@subwallet/extension-base/constants';
5
+ import i18next from 'i18next';
6
+ import Backend from "./Backend.js";
7
+ i18next.use(Backend).init({
8
+ backend: {},
9
+ debug: false,
10
+ fallbackLng: 'en',
11
+ interpolation: {
12
+ escapeValue: false
13
+ },
14
+ keySeparator: false,
15
+ lng: localStorage.getItem(LANGUAGE) || 'en',
16
+ load: 'languageOnly',
17
+ nsSeparator: false,
18
+ returnEmptyString: false,
19
+ returnNull: false
20
+ }).catch(error => console.log('i18n: failure', error));
21
+ export default i18next;
@@ -22,6 +22,7 @@ import BigN from 'bignumber.js';
22
22
  import { addHexPrefix } from 'ethereumjs-util';
23
23
  import { ethers } from 'ethers';
24
24
  import EventEmitter from 'eventemitter3';
25
+ import { t } from 'i18next';
25
26
  import { BehaviorSubject } from 'rxjs';
26
27
  import { isHex } from '@polkadot/util';
27
28
  export default class TransactionService {
@@ -90,7 +91,7 @@ export default class TransactionService {
90
91
  };
91
92
  const chainInfo = this.chainService.getChainInfoByKey(chain);
92
93
  if (!chainInfo) {
93
- validationResponse.errors.push(new TransactionError(BasicTxErrorType.INTERNAL_ERROR, "Can't find network"));
94
+ validationResponse.errors.push(new TransactionError(BasicTxErrorType.INTERNAL_ERROR, t('Cannot find network')));
94
95
  } else {
95
96
  const {
96
97
  decimals,
@@ -105,7 +106,7 @@ export default class TransactionService {
105
106
  } else {
106
107
  const web3 = this.chainService.getEvmApi(chain);
107
108
  if (!web3) {
108
- validationResponse.errors.push(new TransactionError(BasicTxErrorType.CHAIN_DISCONNECTED));
109
+ validationResponse.errors.push(new TransactionError(BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
109
110
  } else {
110
111
  const gasPrice = await web3.api.eth.getGasPrice();
111
112
  const gasLimit = await web3.api.eth.estimateGas(transaction);
@@ -126,11 +127,11 @@ export default class TransactionService {
126
127
  // Read-only account
127
128
  const pair = keyring.getPair(address);
128
129
  if (!pair) {
129
- validationResponse.errors.push(new TransactionError(BasicTxErrorType.INTERNAL_ERROR, 'Can\'t find account'));
130
+ validationResponse.errors.push(new TransactionError(BasicTxErrorType.INTERNAL_ERROR, t('Unable to find account')));
130
131
  } else {
131
132
  var _pair$meta;
132
133
  if ((_pair$meta = pair.meta) !== null && _pair$meta !== void 0 && _pair$meta.isReadOnly) {
133
- validationResponse.errors.push(new TransactionError(BasicTxErrorType.INTERNAL_ERROR, 'This is watch-only account'));
134
+ validationResponse.errors.push(new TransactionError(BasicTxErrorType.INTERNAL_ERROR, t('This account is watch-only')));
134
135
  }
135
136
  }
136
137
 
@@ -159,9 +160,9 @@ export default class TransactionService {
159
160
  if (!isTransferAll) {
160
161
  if (balanceNum - (transferNativeNum + feeNum) < edNum) {
161
162
  if (edAsWarning) {
162
- validationResponse.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT, ''));
163
+ validationResponse.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT));
163
164
  } else {
164
- validationResponse.errors.push(new TransactionError(BasicTxErrorType.NOT_ENOUGH_EXISTENTIAL_DEPOSIT, ''));
165
+ validationResponse.errors.push(new TransactionError(BasicTxErrorType.NOT_ENOUGH_EXISTENTIAL_DEPOSIT));
165
166
  }
166
167
  }
167
168
  }
@@ -582,8 +583,12 @@ export default class TransactionService {
582
583
  const info = isHex(extrinsicHash) ? extrinsicHash : getBaseTransactionInfo(transaction, this.chainService.getChainInfoMap());
583
584
  this.notificationService.notify({
584
585
  type: NotificationType.SUCCESS,
585
- title: 'Transaction completed',
586
- message: `Transaction ${info} completed`,
586
+ title: t('Transaction completed'),
587
+ message: t('Transaction {{info}} completed', {
588
+ replace: {
589
+ info
590
+ }
591
+ }),
587
592
  action: {
588
593
  url: this.getTransactionLink(id)
589
594
  },
@@ -617,8 +622,12 @@ export default class TransactionService {
617
622
  const info = isHex(transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash) ? transaction === null || transaction === void 0 ? void 0 : transaction.extrinsicHash : getBaseTransactionInfo(transaction, this.chainService.getChainInfoMap());
618
623
  this.notificationService.notify({
619
624
  type: NotificationType.ERROR,
620
- title: 'Transaction failed',
621
- message: `Transaction ${info} failed`,
625
+ title: t('Transaction failed'),
626
+ message: t('Transaction {{info}} failed', {
627
+ replace: {
628
+ info
629
+ }
630
+ }),
622
631
  action: {
623
632
  url: this.getTransactionLink(id)
624
633
  },
@@ -721,7 +730,7 @@ export default class TransactionService {
721
730
  if (isApproved) {
722
731
  let signedTransaction;
723
732
  if (!payload) {
724
- throw new EvmProviderError(EvmProviderErrorType.UNAUTHORIZED, 'Bad signature');
733
+ throw new EvmProviderError(EvmProviderErrorType.UNAUTHORIZED, t('Failed to sign'));
725
734
  }
726
735
  const web3Api = this.chainService.getEvmApi(chain).api;
727
736
  if (!isExternal) {
@@ -730,7 +739,7 @@ export default class TransactionService {
730
739
  const signed = mergeTransactionAndSignature(txObject, payload);
731
740
  const recover = web3Api.eth.accounts.recoverTransaction(signed);
732
741
  if (recover.toLowerCase() !== account.address.toLowerCase()) {
733
- throw new EvmProviderError(EvmProviderErrorType.UNAUTHORIZED, 'Bad signature');
742
+ throw new EvmProviderError(EvmProviderErrorType.UNAUTHORIZED, t('Wrong signature. Please sign with the account you use in dApp'));
734
743
  }
735
744
  signedTransaction = signed;
736
745
  }
@@ -754,10 +763,10 @@ export default class TransactionService {
754
763
  eventData.blockNumber = rs.blockNumber;
755
764
  emitter.emit('success', eventData);
756
765
  }).once('error', e => {
757
- eventData.errors.push(new TransactionError(BasicTxErrorType.SEND_TRANSACTION_FAILED, e.message));
766
+ eventData.errors.push(new TransactionError(BasicTxErrorType.SEND_TRANSACTION_FAILED, t(e.message)));
758
767
  emitter.emit('error', eventData);
759
768
  }).catch(e => {
760
- eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, e.message));
769
+ eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, t(e.message)));
761
770
  emitter.emit('error', eventData);
762
771
  });
763
772
  } else {
@@ -767,7 +776,7 @@ export default class TransactionService {
767
776
  }
768
777
  }).catch(e => {
769
778
  this.removeTransaction(id);
770
- eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SIGN, e.message));
779
+ eventData.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SIGN, t(e.message)));
771
780
  emitter.emit('error', eventData);
772
781
  });
773
782
  return emitter;
@@ -857,7 +866,7 @@ export default class TransactionService {
857
866
  const timeout = setTimeout(() => {
858
867
  const transaction = this.getTransaction(eventData.id);
859
868
  if (transaction.status !== ExtrinsicStatus.SUCCESS && transaction.status !== ExtrinsicStatus.FAIL) {
860
- eventData.errors.push(new TransactionError(BasicTxErrorType.TIMEOUT, 'Transaction timeout'));
869
+ eventData.errors.push(new TransactionError(BasicTxErrorType.TIMEOUT, t('Transaction timeout')));
861
870
  emitter.emit('error', eventData);
862
871
  clearTimeout(timeout);
863
872
  }
@@ -102,7 +102,6 @@ function _checkAccount2(address, accounts) {
102
102
  }
103
103
  }
104
104
  function _handleError2(topic, id, e) {
105
- console.log(e);
106
105
  let message = e.message;
107
106
  if (message.includes('User Rejected Request')) {
108
107
  message = getSdkError('USER_REJECTED').message;
@@ -138,21 +138,29 @@ export default class WalletConnectService {
138
138
  // Disconnect session
139
139
  const sessions = ((_classPrivateFieldLoo7 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo7 === void 0 ? void 0 : _classPrivateFieldLoo7.session.values) || [];
140
140
  for (const session of sessions) {
141
- var _classPrivateFieldLoo8;
142
- (_classPrivateFieldLoo8 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo8 === void 0 ? void 0 : _classPrivateFieldLoo8.disconnect({
143
- topic: session.topic,
144
- reason: getSdkError('USER_DISCONNECTED')
145
- }).catch(console.error);
141
+ try {
142
+ var _classPrivateFieldLoo8;
143
+ await ((_classPrivateFieldLoo8 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo8 === void 0 ? void 0 : _classPrivateFieldLoo8.disconnect({
144
+ topic: session.topic,
145
+ reason: getSdkError('USER_DISCONNECTED')
146
+ }));
147
+ } catch (e) {
148
+ console.error(e);
149
+ }
146
150
  }
147
151
 
148
152
  // Disconnect pair
149
153
  const pairs = ((_classPrivateFieldLoo9 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo9 === void 0 ? void 0 : _classPrivateFieldLoo9.pairing.values) || [];
150
154
  for (const pair of pairs) {
151
- var _classPrivateFieldLoo10;
152
- (_classPrivateFieldLoo10 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo10 === void 0 ? void 0 : _classPrivateFieldLoo10.disconnect({
153
- topic: pair.topic,
154
- reason: getSdkError('USER_DISCONNECTED')
155
- }).catch(console.error);
155
+ try {
156
+ var _classPrivateFieldLoo10;
157
+ await ((_classPrivateFieldLoo10 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo10 === void 0 ? void 0 : _classPrivateFieldLoo10.disconnect({
158
+ topic: pair.topic,
159
+ reason: getSdkError('USER_DISCONNECTED')
160
+ }));
161
+ } catch (e) {
162
+ console.error(e);
163
+ }
156
164
  }
157
165
  const keys = (await ((_classPrivateFieldLoo11 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo11 === void 0 ? void 0 : _classPrivateFieldLoo11.core.storage.getKeys())) || [];
158
166
  const deleteKeys = resetAll ? keys : keys.filter(key => key.startsWith('wc@'));
@@ -87,7 +87,7 @@ export class InputDataDecoder {
87
87
  try {
88
88
  this.abi = JSON.parse(prop);
89
89
  } catch (err) {
90
- throw new Error(`Invalid ABI: ${err.message}`);
90
+ throw new Error('Invalid ABI: ' + err.message);
91
91
  }
92
92
  } else if (checkArrayAbiItems(prop)) {
93
93
  this.abi = prop;
@@ -7,6 +7,7 @@ import { createTransactionFromRLP } from '@subwallet/extension-base/utils/eth';
7
7
  import { InputDataDecoder } from '@subwallet/extension-base/utils/eth/parseTransaction/base';
8
8
  import axios from 'axios';
9
9
  import BigN from 'bignumber.js';
10
+ import { t } from 'i18next';
10
11
 
11
12
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
12
13
  const ABIs = [_ERC20_ABI, _ERC721_ABI];
@@ -181,7 +182,7 @@ const getChainInfoByChainId = (networkMap, chainId) => {
181
182
  export const parseEvmRlp = async (data, networkMap, evmApiMap) => {
182
183
  const tx = createTransactionFromRLP(data);
183
184
  if (!tx) {
184
- throw new Error(`Cannot create tx from ${data}`);
185
+ throw new Error(t('Failed to decode data. Please use a valid QR code'));
185
186
  }
186
187
  const result = {
187
188
  input: tx.data,
package/utils/index.js CHANGED
@@ -4,6 +4,7 @@
4
4
  import { CrowdloanParaState, MobileOS } from '@subwallet/extension-base/background/KoniTypes';
5
5
  import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
6
6
  import { getOS } from '@subwallet/extension-base/utils/environment';
7
+ import { t } from 'i18next';
7
8
  import { assert, BN, hexToU8a, isHex } from '@polkadot/util';
8
9
  import { decodeAddress, encodeAddress, ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
9
10
  export { canDerive } from "./canDerive.js";
@@ -282,7 +283,7 @@ export async function waitTimeout(ms) {
282
283
  return new Promise(resolve => setTimeout(resolve, ms));
283
284
  }
284
285
  export const stripUrl = url => {
285
- assert(url && (url.startsWith('http:') || url.startsWith('https:') || url.startsWith('ipfs:') || url.startsWith('ipns:')), `Invalid url ${url}, expected to start with http: or https: or ipfs: or ipns:`);
286
+ assert(url && (url.startsWith('http:') || url.startsWith('https:') || url.startsWith('ipfs:') || url.startsWith('ipns:')), t('Invalid URL for provider'));
286
287
  const parts = url.split('/');
287
288
  return parts[2];
288
289
  };
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.extractPrivateKey = extractPrivateKey;
7
- exports.unlockAccount = exports.lockAccount = void 0;
8
- var _uiKeyring = require("@subwallet/ui-keyring");
9
- // Copyright 2019-2022 @subwallet/extension-base
10
- // SPDX-License-Identifier: Apache-2.0
11
-
12
- // import _decode from '@polkadot/keyring/pair/decode';
13
-
14
- function extract(address) {
15
- // @ts-ignore
16
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
17
- const rs = this.getPair(address);
18
-
19
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
20
- console.log(rs.publicKey);
21
- }
22
- function extractPrivateKey(keyring, address, password) {
23
- extract.call(keyring, address);
24
- }
25
- const unlockAccount = signAddress => {
26
- let publicKey;
27
- try {
28
- publicKey = _uiKeyring.keyring.decodeAddress(signAddress);
29
- } catch (error) {
30
- console.error(error);
31
- return 'Unable to decode address';
32
- }
33
- const pair = _uiKeyring.keyring.getPair(publicKey);
34
- if (!pair) {
35
- return 'Unable to find pair';
36
- }
37
- if (pair.isLocked) {
38
- try {
39
- _uiKeyring.keyring.unlockPair(pair.address);
40
- } catch (e) {
41
- return e.message;
42
- }
43
- }
44
- return null;
45
- };
46
- exports.unlockAccount = unlockAccount;
47
- const lockAccount = address => {
48
- try {
49
- const pair = _uiKeyring.keyring.getPair(address);
50
- if (pair) {
51
- pair.lock();
52
- }
53
- } catch (error) {
54
- console.error('Unable to lock account', error);
55
- }
56
- };
57
- exports.lockAccount = lockAccount;
@@ -1,4 +0,0 @@
1
- import { Keyring } from '@subwallet/keyring';
2
- export declare function extractPrivateKey(keyring: Keyring, address: string, password: string): void;
3
- export declare const unlockAccount: (signAddress: string) => string | null;
4
- export declare const lockAccount: (address: string) => void;
package/utils/keyring.js DELETED
@@ -1,49 +0,0 @@
1
- // Copyright 2019-2022 @subwallet/extension-base
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { keyring } from '@subwallet/ui-keyring';
5
-
6
- // import _decode from '@polkadot/keyring/pair/decode';
7
-
8
- function extract(address) {
9
- // @ts-ignore
10
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
11
- const rs = this.getPair(address);
12
-
13
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
14
- console.log(rs.publicKey);
15
- }
16
- export function extractPrivateKey(keyring, address, password) {
17
- extract.call(keyring, address);
18
- }
19
- export const unlockAccount = signAddress => {
20
- let publicKey;
21
- try {
22
- publicKey = keyring.decodeAddress(signAddress);
23
- } catch (error) {
24
- console.error(error);
25
- return 'Unable to decode address';
26
- }
27
- const pair = keyring.getPair(publicKey);
28
- if (!pair) {
29
- return 'Unable to find pair';
30
- }
31
- if (pair.isLocked) {
32
- try {
33
- keyring.unlockPair(pair.address);
34
- } catch (e) {
35
- return e.message;
36
- }
37
- }
38
- return null;
39
- };
40
- export const lockAccount = address => {
41
- try {
42
- const pair = keyring.getPair(address);
43
- if (pair) {
44
- pair.lock();
45
- }
46
- } catch (error) {
47
- console.error('Unable to lock account', error);
48
- }
49
- };