@subwallet/extension-base 1.1.11-1 → 1.1.12-1

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 (41) hide show
  1. package/background/KoniTypes.d.ts +16 -6
  2. package/background/types.d.ts +4 -2
  3. package/cjs/koni/api/staking/bonding/utils.js +2 -1
  4. package/cjs/koni/api/tokens/evm/transfer.js +10 -4
  5. package/cjs/koni/background/handlers/Extension.js +33 -11
  6. package/cjs/koni/background/handlers/State.js +1 -1
  7. package/cjs/packageInfo.js +1 -1
  8. package/cjs/services/chain-service/constants.js +10 -2
  9. package/cjs/services/chain-service/handler/EvmApi.js +24 -12
  10. package/cjs/services/keyring-service/index.js +33 -1
  11. package/cjs/services/notification-service/NotificationService.js +2 -1
  12. package/cjs/services/request-service/constants.js +11 -2
  13. package/cjs/services/request-service/handler/AuthRequestHandler.js +20 -1
  14. package/cjs/services/request-service/handler/EvmRequestHandler.js +2 -1
  15. package/cjs/services/setting-service/SettingService.js +5 -1
  16. package/cjs/services/transaction-service/index.js +124 -55
  17. package/cjs/utils/lazy.js +20 -6
  18. package/koni/api/staking/bonding/utils.js +2 -1
  19. package/koni/api/tokens/evm/transfer.d.ts +1 -1
  20. package/koni/api/tokens/evm/transfer.js +11 -5
  21. package/koni/background/handlers/Extension.d.ts +2 -0
  22. package/koni/background/handlers/Extension.js +33 -11
  23. package/koni/background/handlers/State.js +1 -1
  24. package/package.json +10 -8
  25. package/packageInfo.js +1 -1
  26. package/page/SubWalleEvmProvider.d.ts +1 -1
  27. package/services/chain-service/constants.d.ts +6 -0
  28. package/services/chain-service/constants.js +6 -0
  29. package/services/chain-service/handler/EvmApi.js +24 -12
  30. package/services/keyring-service/index.d.ts +4 -1
  31. package/services/keyring-service/index.js +33 -1
  32. package/services/notification-service/NotificationService.js +2 -1
  33. package/services/request-service/constants.d.ts +1 -0
  34. package/services/request-service/constants.js +9 -1
  35. package/services/request-service/handler/AuthRequestHandler.js +21 -2
  36. package/services/request-service/handler/EvmRequestHandler.js +2 -1
  37. package/services/setting-service/SettingService.js +5 -1
  38. package/services/transaction-service/index.d.ts +1 -0
  39. package/services/transaction-service/index.js +116 -48
  40. package/utils/lazy.d.ts +1 -1
  41. package/utils/lazy.js +20 -7
@@ -34,6 +34,7 @@ var _util = require("@polkadot/util");
34
34
 
35
35
  class TransactionService {
36
36
  transactionSubject = new _rxjs.BehaviorSubject({});
37
+ watchTransactionSubscribes = {};
37
38
  get transactions() {
38
39
  return this.transactionSubject.getValue();
39
40
  }
@@ -716,6 +717,7 @@ class TransactionService {
716
717
  payload.from = address;
717
718
  }
718
719
  const isExternal = !!account.isExternal;
720
+ const isInjected = !!account.isInjected;
719
721
 
720
722
  // generate hashPayload for EVM transaction
721
723
  payload.hashPayload = this.generateHashPayload(chain, payload);
@@ -736,73 +738,140 @@ class TransactionService {
736
738
  warnings: [],
737
739
  extrinsicHash: id
738
740
  };
739
- this.requestService.addConfirmation(id, url || _constants3.EXTENSION_REQUEST_URL, 'evmSendTransactionRequest', payload, {}).then(async _ref7 => {
740
- let {
741
- isApproved,
742
- payload
743
- } = _ref7;
744
- if (isApproved) {
745
- let signedTransaction;
746
- if (!payload) {
747
- throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.UNAUTHORIZED, (0, _i18next.t)('Failed to sign'));
748
- }
749
- const web3Api = this.chainService.getEvmApi(chain).api;
750
- if (!isExternal) {
751
- signedTransaction = payload;
752
- } else {
753
- const signed = (0, _mergeTransactionAndSignature.mergeTransactionAndSignature)(txObject, payload);
754
- const recover = web3Api.eth.accounts.recoverTransaction(signed);
755
- if (recover.toLowerCase() !== account.address.toLowerCase()) {
756
- throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.UNAUTHORIZED, (0, _i18next.t)('Wrong signature. Please sign with the account you use in dApp'));
741
+ if (isInjected) {
742
+ this.requestService.addConfirmation(id, url || _constants3.EXTENSION_REQUEST_URL, 'evmWatchTransactionRequest', payload, {}).then(async _ref7 => {
743
+ let {
744
+ isApproved,
745
+ payload
746
+ } = _ref7;
747
+ if (isApproved) {
748
+ if (!payload) {
749
+ throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.UNAUTHORIZED, 'Bad signature');
757
750
  }
758
- signedTransaction = signed;
759
- }
751
+ const web3Api = this.chainService.getEvmApi(chain).api;
760
752
 
761
- // Emit signed event
762
- emitter.emit('signed', eventData);
753
+ // Emit signed event
754
+ emitter.emit('signed', eventData);
755
+ eventData.nonce = txObject.nonce;
756
+ eventData.startBlock = (await web3Api.eth.getBlockNumber()) - 3;
757
+ // Add start info
758
+ emitter.emit('send', eventData); // This event is needed after sending transaction with queue
763
759
 
764
- // Send transaction
765
- this.handleTransactionTimeout(emitter, eventData);
766
-
767
- // Add start info
768
- eventData.nonce = txObject.nonce;
769
- eventData.startBlock = await web3Api.eth.getBlockNumber();
770
- emitter.emit('send', eventData); // This event is needed after sending transaction with queue
771
- signedTransaction && web3Api.eth.sendSignedTransaction(signedTransaction).once('transactionHash', hash => {
772
- eventData.extrinsicHash = hash;
760
+ const txHash = payload;
761
+ eventData.extrinsicHash = txHash;
773
762
  emitter.emit('extrinsicHash', eventData);
774
- }).once('receipt', rs => {
775
- eventData.extrinsicHash = rs.transactionHash;
776
- eventData.blockHash = rs.blockHash;
777
- eventData.blockNumber = rs.blockNumber;
778
- emitter.emit('success', eventData);
779
- }).once('error', e => {
780
- eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.SEND_TRANSACTION_FAILED, (0, _i18next.t)(e.message)));
763
+ this.watchTransactionSubscribes[id] = new Promise((resolve, reject) => {
764
+ // eslint-disable-next-line prefer-const
765
+ let subscribe;
766
+ const onComplete = () => {
767
+ var _subscribe, _subscribe$unsubscrib, _subscribe$unsubscrib2;
768
+ (_subscribe = subscribe) === null || _subscribe === void 0 ? void 0 : (_subscribe$unsubscrib = _subscribe.unsubscribe) === null || _subscribe$unsubscrib === void 0 ? void 0 : (_subscribe$unsubscrib2 = _subscribe$unsubscrib.call(_subscribe)) === null || _subscribe$unsubscrib2 === void 0 ? void 0 : _subscribe$unsubscrib2.then(console.debug).catch(console.debug);
769
+ delete this.watchTransactionSubscribes[id];
770
+ };
771
+ const onSuccess = rs => {
772
+ if (rs) {
773
+ eventData.extrinsicHash = rs.transactionHash;
774
+ eventData.blockHash = rs.blockHash;
775
+ eventData.blockNumber = rs.blockNumber;
776
+ emitter.emit('success', eventData);
777
+ onComplete();
778
+ resolve();
779
+ }
780
+ };
781
+ const onError = error => {
782
+ if (error) {
783
+ // TODO: Change type and message
784
+ eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNABLE_TO_SEND, error.message));
785
+ emitter.emit('error', eventData);
786
+ onComplete();
787
+ reject(error);
788
+ }
789
+ };
790
+ const onCheck = () => {
791
+ web3Api.eth.getTransactionReceipt(txHash).then(onSuccess).catch(onError);
792
+ };
793
+ subscribe = web3Api.eth.subscribe('newBlockHeaders', onCheck);
794
+ });
795
+ } else {
796
+ this.removeTransaction(id);
797
+ eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.USER_REJECT_REQUEST));
781
798
  emitter.emit('error', eventData);
782
- }).catch(e => {
783
- eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNABLE_TO_SEND, (0, _i18next.t)(e.message)));
799
+ }
800
+ }).catch(e => {
801
+ this.removeTransaction(id);
802
+ // TODO: Change type
803
+ eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNABLE_TO_SIGN, e.message));
804
+ emitter.emit('error', eventData);
805
+ });
806
+ } else {
807
+ this.requestService.addConfirmation(id, url || _constants3.EXTENSION_REQUEST_URL, 'evmSendTransactionRequest', payload, {}).then(async _ref8 => {
808
+ let {
809
+ isApproved,
810
+ payload
811
+ } = _ref8;
812
+ if (isApproved) {
813
+ let signedTransaction;
814
+ if (!payload) {
815
+ throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.UNAUTHORIZED, (0, _i18next.t)('Failed to sign'));
816
+ }
817
+ const web3Api = this.chainService.getEvmApi(chain).api;
818
+ if (!isExternal) {
819
+ signedTransaction = payload;
820
+ } else {
821
+ const signed = (0, _mergeTransactionAndSignature.mergeTransactionAndSignature)(txObject, payload);
822
+ const recover = web3Api.eth.accounts.recoverTransaction(signed);
823
+ if (recover.toLowerCase() !== account.address.toLowerCase()) {
824
+ throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.UNAUTHORIZED, (0, _i18next.t)('Wrong signature. Please sign with the account you use in dApp'));
825
+ }
826
+ signedTransaction = signed;
827
+ }
828
+
829
+ // Emit signed event
830
+ emitter.emit('signed', eventData);
831
+
832
+ // Send transaction
833
+ this.handleTransactionTimeout(emitter, eventData);
834
+
835
+ // Add start info
836
+ eventData.nonce = txObject.nonce;
837
+ eventData.startBlock = await web3Api.eth.getBlockNumber();
838
+ emitter.emit('send', eventData); // This event is needed after sending transaction with queue
839
+ signedTransaction && web3Api.eth.sendSignedTransaction(signedTransaction).once('transactionHash', hash => {
840
+ eventData.extrinsicHash = hash;
841
+ emitter.emit('extrinsicHash', eventData);
842
+ }).once('receipt', rs => {
843
+ eventData.extrinsicHash = rs.transactionHash;
844
+ eventData.blockHash = rs.blockHash;
845
+ eventData.blockNumber = rs.blockNumber;
846
+ emitter.emit('success', eventData);
847
+ }).once('error', e => {
848
+ eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.SEND_TRANSACTION_FAILED, (0, _i18next.t)(e.message)));
849
+ emitter.emit('error', eventData);
850
+ }).catch(e => {
851
+ eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNABLE_TO_SEND, (0, _i18next.t)(e.message)));
852
+ emitter.emit('error', eventData);
853
+ });
854
+ } else {
855
+ this.removeTransaction(id);
856
+ eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.USER_REJECT_REQUEST));
784
857
  emitter.emit('error', eventData);
785
- });
786
- } else {
858
+ }
859
+ }).catch(e => {
787
860
  this.removeTransaction(id);
788
- eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.USER_REJECT_REQUEST));
861
+ eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNABLE_TO_SIGN, (0, _i18next.t)(e.message)));
789
862
  emitter.emit('error', eventData);
790
- }
791
- }).catch(e => {
792
- this.removeTransaction(id);
793
- eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.UNABLE_TO_SIGN, (0, _i18next.t)(e.message)));
794
- emitter.emit('error', eventData);
795
- });
863
+ });
864
+ }
796
865
  return emitter;
797
866
  }
798
- signAndSendSubstrateTransaction(_ref8) {
867
+ signAndSendSubstrateTransaction(_ref9) {
799
868
  let {
800
869
  address,
801
870
  chain,
802
871
  id,
803
872
  transaction,
804
873
  url
805
- } = _ref8;
874
+ } = _ref9;
806
875
  const emitter = new _eventemitter.default();
807
876
  const eventData = {
808
877
  id,
@@ -848,20 +917,20 @@ class TransactionService {
848
917
  eventData.extrinsicHash = txState.txHash.toHex();
849
918
  eventData.eventLogs = txState.events;
850
919
  // TODO: push block hash and block number into eventData
851
- txState.events.filter(_ref9 => {
920
+ txState.events.filter(_ref10 => {
852
921
  let {
853
922
  event: {
854
923
  section
855
924
  }
856
- } = _ref9;
925
+ } = _ref10;
857
926
  return section === 'system';
858
- }).forEach(_ref10 => {
927
+ }).forEach(_ref11 => {
859
928
  let {
860
929
  event: {
861
930
  method,
862
931
  data: [error]
863
932
  }
864
- } = _ref10;
933
+ } = _ref11;
865
934
  if (method === 'ExtrinsicFailed') {
866
935
  eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.SEND_TRANSACTION_FAILED, error.toString()));
867
936
  emitter.emit('error', eventData);
package/cjs/utils/lazy.js CHANGED
@@ -20,6 +20,7 @@ function removeLazy(key) {
20
20
  function addLazy(key, callback) {
21
21
  let lazyTime = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 300;
22
22
  let maxLazyTime = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 3000;
23
+ let fireOnFirst = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
23
24
  const existed = lazyMap[key];
24
25
  const now = new Date().getTime();
25
26
  if (existed) {
@@ -42,11 +43,24 @@ function addLazy(key, callback) {
42
43
  }, lazyTime);
43
44
  }
44
45
  } else {
45
- // Fire callback immediately in the first time
46
- callback();
47
- lazyMap[key] = {
48
- callback,
49
- lastFire: now
50
- };
46
+ if (fireOnFirst) {
47
+ // Fire callback immediately in the first time
48
+ callback();
49
+ lazyMap[key] = {
50
+ callback,
51
+ lastFire: now
52
+ };
53
+ } else {
54
+ lazyMap[key] = {
55
+ callback,
56
+ lastFire: now
57
+ };
58
+ lazyMap[key].timeout = setTimeout(() => {
59
+ // This will be fire in the last call of lazy thread
60
+ callback();
61
+ lazyMap[key].lastFire = new Date().getTime();
62
+ removeLazy(key);
63
+ }, lazyTime);
64
+ }
51
65
  }
52
66
  }
@@ -6,6 +6,7 @@ import { getAstarWithdrawable } from '@subwallet/extension-base/koni/api/staking
6
6
  import { _KNOWN_CHAIN_INFLATION_PARAMS, _STAKING_CHAIN_GROUP, _SUBSTRATE_DEFAULT_INFLATION_PARAMS } from '@subwallet/extension-base/services/chain-service/constants';
7
7
  import { _getChainNativeTokenBasicInfo } from '@subwallet/extension-base/services/chain-service/utils';
8
8
  import { detectTranslate, parseRawNumber, reformatAddress } from '@subwallet/extension-base/utils';
9
+ import { balanceFormatter, formatNumber } from '@subwallet/extension-base/utils/number';
9
10
  import { t } from 'i18next';
10
11
  import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_THOUSAND, BN_ZERO, bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
11
12
  export let PalletParachainStakingRequestType;
@@ -254,7 +255,7 @@ export function getValidatorLabel(chain) {
254
255
  }
255
256
  export const getMinStakeErrorMessage = (chainInfo, bnMinStake) => {
256
257
  const tokenInfo = _getChainNativeTokenBasicInfo(chainInfo);
257
- const number = bnMinStake.div(new BN(10).pow(new BN(tokenInfo.decimals))).toString();
258
+ const number = formatNumber(bnMinStake.toString(), tokenInfo.decimals || 0, balanceFormatter);
258
259
  return t('Insufficient stake. Please stake at least {{number}} {{tokenSymbol}} to get rewards', {
259
260
  replace: {
260
261
  tokenSymbol: tokenInfo.symbol,
@@ -11,7 +11,7 @@ interface HandleTransferBalanceResultProps {
11
11
  updateState?: (promise: Partial<ExternalRequestPromise>) => void;
12
12
  }
13
13
  export declare const handleTransferBalanceResult: ({ callback, changeValue, networkKey, receipt, response, updateState }: HandleTransferBalanceResultProps) => void;
14
- export declare function getEVMTransactionObject(chainInfo: _ChainInfo, to: string, value: string, transferAll: boolean, evmApiMap: Record<string, _EvmApi>): Promise<[TransactionConfig, string]>;
14
+ export declare function getEVMTransactionObject(chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, evmApiMap: Record<string, _EvmApi>): Promise<[TransactionConfig, string]>;
15
15
  export declare function getERC20TransactionObject(assetAddress: string, chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, evmApiMap: Record<string, _EvmApi>): Promise<[TransactionConfig, string]>;
16
16
  export declare function getERC721Transaction(web3Api: _EvmApi, contractAddress: string, senderAddress: string, recipientAddress: string, tokenId: string): Promise<TransactionConfig>;
17
17
  export {};
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { ExternalRequestPromiseStatus } from '@subwallet/extension-base/background/KoniTypes';
5
5
  import { getERC20Contract } from '@subwallet/extension-base/koni/api/tokens/evm/web3';
6
- import { _BALANCE_PARSING_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
6
+ import { _BALANCE_PARSING_CHAIN_GROUP, EVM_REFORMAT_DECIMALS } from '@subwallet/extension-base/services/chain-service/constants';
7
7
  import { _ERC721_ABI } from '@subwallet/extension-base/services/chain-service/helper';
8
8
  import { BN, hexToBn } from '@polkadot/util';
9
9
  export const handleTransferBalanceResult = ({
@@ -32,18 +32,24 @@ export const handleTransferBalanceResult = ({
32
32
  });
33
33
  callback(response);
34
34
  };
35
- export async function getEVMTransactionObject(chainInfo, to, value, transferAll, evmApiMap) {
35
+ export async function getEVMTransactionObject(chainInfo, from, to, value, transferAll, evmApiMap) {
36
36
  const networkKey = chainInfo.slug;
37
37
  const web3Api = evmApiMap[networkKey];
38
38
  const gasPrice = await web3Api.api.eth.getGasPrice();
39
39
  const transactionObject = {
40
40
  gasPrice: gasPrice,
41
- to: to
41
+ to: to,
42
+ value: value,
43
+ from: from
42
44
  };
43
45
  const gasLimit = await web3Api.api.eth.estimateGas(transactionObject);
44
46
  transactionObject.gas = gasLimit;
45
- const estimateFee = parseInt(gasPrice) * gasLimit;
46
- transactionObject.value = transferAll ? new BN(value).add(new BN(estimateFee).neg()) : value;
47
+ const estimateFee = new BN(gasLimit).mul(new BN(gasPrice));
48
+ transactionObject.value = transferAll ? new BN(value).sub(estimateFee).toString() : value;
49
+ if (EVM_REFORMAT_DECIMALS.acala.includes(networkKey)) {
50
+ const numberReplace = 18 - 12;
51
+ transactionObject.value = transactionObject.value.substring(0, transactionObject.value.length - 6) + new Array(numberReplace).fill('0').join('');
52
+ }
47
53
  return [transactionObject, transactionObject.value.toString()];
48
54
  }
49
55
  export async function getERC20TransactionObject(assetAddress, chainInfo, from, to, value, transferAll, evmApiMap) {
@@ -210,5 +210,7 @@ export default class KoniExtension {
210
210
  private findRawMetadata;
211
211
  private resolveDomainByAddress;
212
212
  private resolveAddressByDomain;
213
+ private addInjects;
214
+ private removeInjects;
213
215
  handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
214
216
  }
@@ -1510,7 +1510,7 @@ export default class KoniExtension {
1510
1510
  if (_isTokenEvmSmartContract(tokenInfo) || _isLocalToken(tokenInfo)) {
1511
1511
  [transaction, transferAmount.value] = await getERC20TransactionObject(_getContractAddressOfToken(tokenInfo), chainInfo, from, to, txVal, !!transferAll, evmApiMap);
1512
1512
  } else {
1513
- [transaction, transferAmount.value] = await getEVMTransactionObject(chainInfo, to, txVal, !!transferAll, evmApiMap);
1513
+ [transaction, transferAmount.value] = await getEVMTransactionObject(chainInfo, from, to, txVal, !!transferAll, evmApiMap);
1514
1514
  }
1515
1515
  } else if (_isMantaZkAsset(tokenInfo)) {
1516
1516
  // TODO
@@ -2700,15 +2700,19 @@ export default class KoniExtension {
2700
2700
  if (createNew) {
2701
2701
  const pairs = keyring.getPairs();
2702
2702
  for (const pair of pairs) {
2703
- const meta = {
2704
- ...pair.meta,
2705
- isMasterPassword: false
2706
- };
2707
- if (!meta.originGenesisHash) {
2708
- meta.genesisHash = '';
2703
+ if (pair.meta.isInjected) {
2704
+ // Empty
2705
+ } else {
2706
+ const meta = {
2707
+ ...pair.meta,
2708
+ isMasterPassword: false
2709
+ };
2710
+ if (!meta.originGenesisHash) {
2711
+ meta.genesisHash = '';
2712
+ }
2713
+ pair.setMeta(meta);
2714
+ keyring.saveAccountMeta(pair, pair.meta);
2709
2715
  }
2710
- pair.setMeta(meta);
2711
- keyring.saveAccountMeta(pair, pair.meta);
2712
2716
  }
2713
2717
  }
2714
2718
  keyring.changeMasterPassword(newPassword, oldPassword);
@@ -2810,7 +2814,7 @@ export default class KoniExtension {
2810
2814
  }
2811
2815
  }
2812
2816
 
2813
- /// Signing external request
2817
+ /// Signing substrate request
2814
2818
  signingApprovePasswordV2({
2815
2819
  id
2816
2820
  }) {
@@ -3473,6 +3477,16 @@ export default class KoniExtension {
3473
3477
  return await resolveAzeroAddressToDomain(request.address, request.chain, chainApi.api);
3474
3478
  }
3475
3479
 
3480
+ /// Inject account
3481
+ addInjects(request) {
3482
+ this.#koniState.keyringService.addInjectAccounts(request.accounts);
3483
+ return true;
3484
+ }
3485
+ removeInjects(request) {
3486
+ this.#koniState.keyringService.removeInjectAccounts(request.addresses);
3487
+ return true;
3488
+ }
3489
+
3476
3490
  // --------------------------------------------------------------
3477
3491
  // eslint-disable-next-line @typescript-eslint/require-await
3478
3492
  async handle(id, type, request, port) {
@@ -3625,7 +3639,7 @@ export default class KoniExtension {
3625
3639
  case 'pri(transaction.history.getSubscription)':
3626
3640
  return await this.subscribeHistory(id, port);
3627
3641
 
3628
- /// Account management
3642
+ /* Account management */
3629
3643
  // Add account
3630
3644
  case 'pri(accounts.create.suriV2)':
3631
3645
  return await this.accountsCreateSuriV2(request);
@@ -3688,6 +3702,14 @@ export default class KoniExtension {
3688
3702
  case 'pri(accounts.resolveAddressToDomain)':
3689
3703
  return await this.resolveAddressByDomain(request);
3690
3704
 
3705
+ // Inject account
3706
+ case 'pri(accounts.inject.add)':
3707
+ return this.addInjects(request);
3708
+ case 'pri(accounts.inject.remove)':
3709
+ return this.removeInjects(request);
3710
+
3711
+ /* Account management */
3712
+
3691
3713
  // ChainService
3692
3714
  case 'pri(chainService.subscribeChainInfoMap)':
3693
3715
  return this.subscribeChainInfoMap(id, port);
@@ -1539,7 +1539,7 @@ export default class KoniState {
1539
1539
  });
1540
1540
  }
1541
1541
  async resetWallet(resetAll) {
1542
- this.keyringService.resetWallet(resetAll);
1542
+ await this.keyringService.resetWallet(resetAll);
1543
1543
  this.requestService.resetWallet();
1544
1544
  this.transactionService.resetWallet();
1545
1545
  await this.dbService.resetWallet(resetAll);
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.1.11-1",
20
+ "version": "1.1.12-1",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -1221,13 +1221,13 @@
1221
1221
  "@reduxjs/toolkit": "^1.9.1",
1222
1222
  "@sora-substrate/type-definitions": "^1.17.7",
1223
1223
  "@substrate/connect": "^0.7.26",
1224
- "@subwallet/chain-list": "0.2.13",
1225
- "@subwallet/extension-base": "^1.1.11-1",
1226
- "@subwallet/extension-chains": "^1.1.11-1",
1227
- "@subwallet/extension-dapp": "^1.1.11-1",
1228
- "@subwallet/extension-inject": "^1.1.11-1",
1229
- "@subwallet/keyring": "^0.0.10",
1230
- "@subwallet/ui-keyring": "^0.0.10",
1224
+ "@subwallet/chain-list": "^0.2.14",
1225
+ "@subwallet/extension-base": "^1.1.12-1",
1226
+ "@subwallet/extension-chains": "^1.1.12-1",
1227
+ "@subwallet/extension-dapp": "^1.1.12-1",
1228
+ "@subwallet/extension-inject": "^1.1.12-1",
1229
+ "@subwallet/keyring": "^0.1.1",
1230
+ "@subwallet/ui-keyring": "^0.1.1",
1231
1231
  "@walletconnect/sign-client": "^2.8.4",
1232
1232
  "@walletconnect/types": "^2.8.4",
1233
1233
  "@walletconnect/utils": "^2.8.4",
@@ -1256,6 +1256,8 @@
1256
1256
  "web3": "^1.10.0",
1257
1257
  "web3-core": "^1.10.0",
1258
1258
  "web3-core-helpers": "^1.10.0",
1259
+ "web3-core-subscriptions": "1.10.0",
1260
+ "web3-eth": "1.10.0",
1259
1261
  "web3-eth-contract": "^1.10.0",
1260
1262
  "web3-utils": "^1.10.0"
1261
1263
  }
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.1.11-1'
10
+ version: '1.1.12-1'
11
11
  };
@@ -16,7 +16,7 @@ export declare class SubWalletEvmProvider extends SafeEventEmitter implements Ev
16
16
  get connected(): boolean;
17
17
  isConnected(): boolean;
18
18
  protected subscribeExtensionEvents(): void;
19
- enable(): Promise<unknown>;
19
+ enable(): Promise<string[]>;
20
20
  on(eventName: string | symbol, listener: (...args: any[]) => void): this;
21
21
  once(eventName: string | symbol, listener: (...args: any[]) => void): this;
22
22
  request<T>({ method, params }: RequestArguments): Promise<T>;
@@ -85,6 +85,12 @@ export declare const _XCM_TYPE: {
85
85
  PR: string;
86
86
  };
87
87
  export declare const _DEFAULT_ACTIVE_CHAINS: string[];
88
+ export declare const EVM_PASS_CONNECT_STATUS: {
89
+ acala: string[];
90
+ };
91
+ export declare const EVM_REFORMAT_DECIMALS: {
92
+ acala: string[];
93
+ };
88
94
  export declare const _CHAIN_INFO_SRC: string;
89
95
  export declare const _CHAIN_ASSET_SRC: string;
90
96
  export declare const _ASSET_REF_SRC: string;
@@ -216,6 +216,12 @@ export const _XCM_TYPE = {
216
216
  };
217
217
 
218
218
  export const _DEFAULT_ACTIVE_CHAINS = [..._DEFAULT_CHAINS];
219
+ export const EVM_PASS_CONNECT_STATUS = {
220
+ acala: ['acala_evm', 'karura_evm']
221
+ };
222
+ export const EVM_REFORMAT_DECIMALS = {
223
+ acala: ['acala_evm', 'karura_evm']
224
+ };
219
225
 
220
226
  // TODO: review
221
227
  const TARGET_BRANCH = process.env.NODE_ENV !== 'production' ? 'koni-dev' : 'master';
@@ -2,10 +2,12 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import '@polkadot/types-augment';
5
+ import { EVM_PASS_CONNECT_STATUS } from '@subwallet/extension-base/services/chain-service/constants';
5
6
  import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
6
7
  import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
7
8
  import { BehaviorSubject } from 'rxjs';
8
9
  import Web3 from 'web3';
10
+ const acalaEvmNetworks = EVM_PASS_CONNECT_STATUS.acala;
9
11
  export class EvmApi {
10
12
  apiRetry = 0;
11
13
  isApiConnectedSubject = new BehaviorSubject(false);
@@ -67,11 +69,15 @@ export class EvmApi {
67
69
  createIntervalCheckApi() {
68
70
  this.clearIntervalCheckApi();
69
71
  return setInterval(() => {
70
- this.api.eth.net.isListening().then(() => {
72
+ if (!acalaEvmNetworks.includes(this.chainSlug)) {
73
+ this.api.eth.net.isListening().then(() => {
74
+ this.onConnect();
75
+ }).catch(() => {
76
+ this.onDisconnect();
77
+ });
78
+ } else {
71
79
  this.onConnect();
72
- }).catch(() => {
73
- this.onDisconnect();
74
- });
80
+ }
75
81
  }, 10000);
76
82
  }
77
83
  clearIntervalCheckApi() {
@@ -82,17 +88,23 @@ export class EvmApi {
82
88
  const wsProvider = this.provider;
83
89
  wsProvider.connect && wsProvider.connect();
84
90
  this.updateConnectionStatus(_ChainConnectionStatus.CONNECTING);
91
+
85
92
  // Check if api is ready
86
- this.api.eth.net.isListening().then(() => {
93
+ if (!acalaEvmNetworks.includes(this.chainSlug)) {
94
+ this.api.eth.net.isListening().then(() => {
95
+ this.isApiReadyOnce = true;
96
+ this.onConnect();
97
+ }).catch(error => {
98
+ this.isApiReadyOnce = false;
99
+ this.isApiReady = false;
100
+ this.isReadyHandler.reject(error);
101
+ this.updateConnectionStatus(_ChainConnectionStatus.DISCONNECTED);
102
+ console.warn(`Can not connect to ${this.chainSlug} (EVM) at ${this.apiUrl}`);
103
+ });
104
+ } else {
87
105
  this.isApiReadyOnce = true;
88
106
  this.onConnect();
89
- }).catch(error => {
90
- this.isApiReadyOnce = false;
91
- this.isApiReady = false;
92
- this.isReadyHandler.reject(error);
93
- this.updateConnectionStatus(_ChainConnectionStatus.DISCONNECTED);
94
- console.warn(`Can not connect to ${this.chainSlug} (EVM) at ${this.apiUrl}`);
95
- });
107
+ }
96
108
 
97
109
  // Interval to check connecting status
98
110
  this.intervalCheckApi = this.createIntervalCheckApi();
@@ -1,5 +1,6 @@
1
1
  import { CurrentAccountInfo, KeyringState } from '@subwallet/extension-base/background/KoniTypes';
2
2
  import { EventService } from '@subwallet/extension-base/services/event-service';
3
+ import { InjectedAccountWithMeta } from '@subwallet/extension-inject/types';
3
4
  import { SubjectInfo } from '@subwallet/ui-keyring/observable/types';
4
5
  import { BehaviorSubject } from 'rxjs';
5
6
  export declare class KeyringService {
@@ -19,5 +20,7 @@ export declare class KeyringService {
19
20
  get currentAccount(): CurrentAccountInfo;
20
21
  setCurrentAccount(currentAccountData: CurrentAccountInfo): void;
21
22
  lock(): void;
22
- resetWallet(resetAll: boolean): void;
23
+ addInjectAccounts(accounts: InjectedAccountWithMeta[]): void;
24
+ removeInjectAccounts(addresses: string[]): void;
25
+ resetWallet(resetAll: boolean): Promise<void>;
23
26
  }
@@ -5,6 +5,7 @@ import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
5
5
  import { CurrentAccountStore } from '@subwallet/extension-base/stores';
6
6
  import { keyring } from '@subwallet/ui-keyring';
7
7
  import { BehaviorSubject } from 'rxjs';
8
+ import { stringShorten } from '@polkadot/util';
8
9
  export class KeyringService {
9
10
  currentAccountStore = new CurrentAccountStore();
10
11
  currentAccountSubject = new BehaviorSubject({
@@ -91,8 +92,39 @@ export class KeyringService {
91
92
  keyring.lockAll();
92
93
  this.updateKeyringState();
93
94
  }
94
- resetWallet(resetAll) {
95
+
96
+ /* Inject */
97
+
98
+ addInjectAccounts(accounts) {
99
+ keyring.addInjects(accounts.map(account => {
100
+ const name = account.meta.name || stringShorten(account.address);
101
+
102
+ // TODO: Add if need
103
+ // name = name.concat(' (', account.meta.source, ')');
104
+
105
+ return {
106
+ ...account,
107
+ meta: {
108
+ ...account.meta,
109
+ name: name
110
+ }
111
+ };
112
+ }));
113
+ }
114
+ removeInjectAccounts(addresses) {
115
+ keyring.removeInjects(addresses);
116
+ }
117
+
118
+ /* Inject */
119
+
120
+ /* Reset */
121
+ async resetWallet(resetAll) {
95
122
  keyring.resetWallet(resetAll);
123
+ await new Promise(resolve => {
124
+ setTimeout(() => {
125
+ resolve();
126
+ }, 500);
127
+ });
96
128
  this.updateKeyringState();
97
129
  this.currentAccountSubject.next({
98
130
  address: ALL_ACCOUNT_KEY,