@subwallet/extension-base 1.0.2-1b → 1.0.2-3

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 (78) hide show
  1. package/background/KoniTypes.d.ts +31 -5
  2. package/background/KoniTypes.js +2 -1
  3. package/background/errors/TransactionError.js +4 -0
  4. package/background/types.d.ts +10 -5
  5. package/cjs/background/KoniTypes.js +2 -1
  6. package/cjs/background/errors/TransactionError.js +4 -0
  7. package/cjs/koni/api/dotsama/transfer.js +6 -12
  8. package/cjs/koni/api/nft/acala_nft/index.js +7 -10
  9. package/cjs/koni/api/nft/bit.country/index.js +7 -9
  10. package/cjs/koni/api/nft/evm_nft/index.js +2 -1
  11. package/cjs/koni/api/nft/karura_nft/index.js +7 -9
  12. package/cjs/koni/api/nft/rmrk_nft/index.js +4 -1
  13. package/cjs/koni/api/nft/statemine_nft/index.js +7 -9
  14. package/cjs/koni/api/nft/unique_nft/index.js +5 -6
  15. package/cjs/koni/api/nft/wasm_nft/index.js +2 -1
  16. package/cjs/koni/api/staking/bonding/relayChain.js +3 -0
  17. package/cjs/koni/background/cron.js +53 -46
  18. package/cjs/koni/background/handlers/Extension.js +292 -159
  19. package/cjs/koni/background/handlers/State.js +24 -14
  20. package/cjs/koni/background/handlers/Tabs.js +42 -16
  21. package/cjs/packageInfo.js +1 -1
  22. package/cjs/services/chain-service/handler/light-client/index.js +0 -2
  23. package/cjs/services/chain-service/index.js +53 -38
  24. package/cjs/services/history-service/index.js +3 -3
  25. package/cjs/services/history-service/subsquid-multi-chain-history.js +1 -1
  26. package/cjs/services/keyring-service/index.js +11 -13
  27. package/cjs/services/request-service/handler/AuthRequestHandler.js +7 -5
  28. package/cjs/services/request-service/handler/EvmRequestHandler.js +8 -12
  29. package/cjs/services/request-service/index.js +14 -5
  30. package/cjs/services/storage-service/DatabaseService.js +8 -5
  31. package/cjs/services/storage-service/db-stores/Nft.js +9 -4
  32. package/cjs/services/transaction-service/index.js +3 -1
  33. package/cjs/utils/address.js +10 -1
  34. package/cjs/utils/index.js +2 -1
  35. package/koni/api/dotsama/transfer.js +6 -12
  36. package/koni/api/nft/acala_nft/index.js +7 -9
  37. package/koni/api/nft/bit.country/index.js +7 -8
  38. package/koni/api/nft/evm_nft/index.js +2 -1
  39. package/koni/api/nft/index.d.ts +1 -1
  40. package/koni/api/nft/karura_nft/index.js +7 -8
  41. package/koni/api/nft/nft.d.ts +1 -1
  42. package/koni/api/nft/rmrk_nft/index.js +4 -1
  43. package/koni/api/nft/statemine_nft/index.js +7 -8
  44. package/koni/api/nft/unique_nft/index.js +5 -5
  45. package/koni/api/nft/wasm_nft/index.js +2 -1
  46. package/koni/api/staking/bonding/relayChain.js +3 -0
  47. package/koni/background/cron.js +53 -46
  48. package/koni/background/handlers/Extension.d.ts +6 -1
  49. package/koni/background/handlers/Extension.js +203 -73
  50. package/koni/background/handlers/State.d.ts +1 -1
  51. package/koni/background/handlers/State.js +26 -14
  52. package/koni/background/handlers/Tabs.js +42 -16
  53. package/package.json +13 -13
  54. package/packageInfo.js +1 -1
  55. package/services/chain-service/handler/light-client/index.d.ts +1 -17
  56. package/services/chain-service/handler/light-client/index.js +1 -1
  57. package/services/chain-service/index.d.ts +3 -2
  58. package/services/chain-service/index.js +47 -33
  59. package/services/chain-service/types.d.ts +1 -0
  60. package/services/history-service/index.d.ts +3 -1
  61. package/services/history-service/index.js +3 -3
  62. package/services/history-service/subsquid-multi-chain-history.js +1 -1
  63. package/services/keyring-service/index.d.ts +4 -2
  64. package/services/keyring-service/index.js +11 -13
  65. package/services/request-service/handler/AuthRequestHandler.d.ts +3 -1
  66. package/services/request-service/handler/AuthRequestHandler.js +7 -5
  67. package/services/request-service/handler/EvmRequestHandler.js +8 -12
  68. package/services/request-service/index.d.ts +3 -1
  69. package/services/request-service/index.js +14 -5
  70. package/services/storage-service/DatabaseService.d.ts +1 -1
  71. package/services/storage-service/DatabaseService.js +8 -5
  72. package/services/storage-service/db-stores/Nft.d.ts +2 -1
  73. package/services/storage-service/db-stores/Nft.js +9 -4
  74. package/services/transaction-service/index.js +3 -1
  75. package/utils/address.d.ts +3 -0
  76. package/utils/address.js +8 -1
  77. package/utils/index.d.ts +1 -1
  78. package/utils/index.js +1 -1
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.0.2-1b",
20
+ "version": "1.0.2-3",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -1639,7 +1639,7 @@
1639
1639
  "@polkadot/hw-ledger": "^10.1.9",
1640
1640
  "@polkadot/keyring": "^10.2.1",
1641
1641
  "@polkadot/networks": "^10.2.1",
1642
- "@polkadot/phishing": "^0.20.3",
1642
+ "@polkadot/phishing": "^0.21.1",
1643
1643
  "@polkadot/react-identicon": "^2.9.14",
1644
1644
  "@polkadot/react-qr": "^2.9.14",
1645
1645
  "@polkadot/rpc-provider": "^9.10.3",
@@ -1656,11 +1656,11 @@
1656
1656
  "@sora-substrate/type-definitions": "^1.12.4",
1657
1657
  "@subsocial/types": "^0.6.8",
1658
1658
  "@substrate/connect": "^0.7.18",
1659
- "@subwallet/chain-list": "^0.0.30",
1660
- "@subwallet/extension-base": "^1.0.2-1",
1661
- "@subwallet/extension-chains": "^1.0.2-1",
1662
- "@subwallet/extension-dapp": "^1.0.2-1",
1663
- "@subwallet/extension-inject": "^1.0.2-1",
1659
+ "@subwallet/chain-list": "^0.0.32",
1660
+ "@subwallet/extension-base": "^1.0.2-3",
1661
+ "@subwallet/extension-chains": "^1.0.2-3",
1662
+ "@subwallet/extension-dapp": "^1.0.2-3",
1663
+ "@subwallet/extension-inject": "^1.0.2-3",
1664
1664
  "@subwallet/keyring": "^0.0.5",
1665
1665
  "@subwallet/ui-keyring": "^0.0.3",
1666
1666
  "@unique-nft/types": "^0.6.0-4",
@@ -1692,10 +1692,10 @@
1692
1692
  "protobufjs": "^7.1.2",
1693
1693
  "rlp": "^3.0.0",
1694
1694
  "rxjs": "^7.8.0",
1695
- "web3": "^1.8.1",
1696
- "web3-core": "^1.8.1",
1697
- "web3-core-helpers": "^1.8.1",
1698
- "web3-eth-contract": "^1.8.1",
1699
- "web3-utils": "^1.8.1"
1695
+ "web3": "^1.9.0",
1696
+ "web3-core": "^1.9.0",
1697
+ "web3-core-helpers": "^1.9.0",
1698
+ "web3-eth-contract": "^1.9.0",
1699
+ "web3-utils": "^1.9.0"
1700
1700
  }
1701
- }
1701
+ }
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.0.2-1'
10
+ version: '1.0.2-3'
11
11
  };
@@ -1,20 +1,4 @@
1
- import { ScProvider } from '@polkadot/rpc-provider';
2
- import { ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
1
+ import { ProviderInterface } from '@polkadot/rpc-provider/types';
3
2
  export declare const relayChainSpecs: Record<string, string>;
4
3
  export declare const paraChainSpecs: Record<string, string>;
5
- export declare class ProviderPlaceholder implements ProviderInterface {
6
- private readonly providerPromise;
7
- private provider?;
8
- constructor(providerPromise: Promise<ScProvider>);
9
- get hasSubscriptions(): boolean;
10
- get isClonable(): boolean;
11
- get isConnected(): boolean;
12
- clone(): ProviderInterface;
13
- connect(): Promise<void>;
14
- disconnect(): Promise<void>;
15
- on(type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): () => void;
16
- send<T = any>(method: string, params: unknown[], isCacheable?: boolean): Promise<T>;
17
- subscribe(type: string, method: string, params: unknown[], cb: ProviderInterfaceCallback): Promise<number | string>;
18
- unsubscribe(type: string, method: string, id: number | string): Promise<boolean>;
19
- }
20
4
  export declare function getSubstrateConnectProvider(specLink: string): ProviderInterface;
@@ -16,7 +16,7 @@ export const paraChainSpecs = {
16
16
  'kusama/tinkernet': `${sourceFolderUrl}kusama/tinkernet.json`,
17
17
  'polkadot/astar': `${sourceFolderUrl}polkadot/astar.json`
18
18
  };
19
- export class ProviderPlaceholder {
19
+ class ProviderPlaceholder {
20
20
  constructor(providerPromise) {
21
21
  this.providerPromise = providerPromise;
22
22
  providerPromise.then(provider => {
@@ -19,7 +19,6 @@ export declare class ChainService {
19
19
  private store;
20
20
  private assetSettingSubject;
21
21
  private logger;
22
- private refreshChainStateTimeout;
23
22
  constructor(dbService: DatabaseService, eventService: EventService);
24
23
  getXcmRefMap(): Record<string, _AssetRef>;
25
24
  getEvmApi(slug: string): _EvmApi;
@@ -92,8 +91,10 @@ export declare class ChainService {
92
91
  refreshEvmApi(slug: string): void;
93
92
  stopAllChainApis(): Promise<void[]>;
94
93
  resumeAllChainApis(): Promise<void[]>;
94
+ private refreshChainStateTimeout;
95
+ private refreshChainStateTimes;
95
96
  private refreshChainStateInterval;
96
- private updateApiMapStatus;
97
+ updateApiMapStatus(): Promise<void>;
97
98
  initAssetSettings(): Promise<void>;
98
99
  setAssetSettings(assetSettings: Record<string, AssetSetting>, emitEvent?: boolean): void;
99
100
  getStoreAssetSettings(): Promise<Record<string, AssetSetting>>;
@@ -3,7 +3,6 @@
3
3
 
4
4
  import { AssetRefMap, ChainAssetMap, ChainInfoMap, MultiChainAssetMap } from '@subwallet/chain-list';
5
5
  import { _AssetRefPath, _AssetType, _ChainStatus, _SubstrateChainType } from '@subwallet/chain-list/types';
6
- import { CRON_GET_API_MAP_STATUS } from '@subwallet/extension-base/constants';
7
6
  import { _DEFAULT_ACTIVE_CHAINS } from '@subwallet/extension-base/services/chain-service/constants';
8
7
  import { EvmChainHandler } from '@subwallet/extension-base/services/chain-service/handler/EvmChainHandler';
9
8
  import { SubstrateChainHandler } from '@subwallet/extension-base/services/chain-service/handler/SubstrateChainHandler';
@@ -44,7 +43,7 @@ export class ChainService {
44
43
  this.multiChainAssetMapSubject.next(MultiChainAssetMap);
45
44
  this.xcmRefMapSubject.next(this.getXcmRefMap());
46
45
  this.logger = createLogger('chain-service');
47
- this.refreshChainStateInterval(3000);
46
+ this.refreshChainStateInterval(3000, 6);
48
47
  }
49
48
 
50
49
  // Getter
@@ -407,7 +406,7 @@ export class ChainService {
407
406
  this.lockChainInfoMap = true;
408
407
  chainStateMap[chainSlug].active = true;
409
408
  this.initApiForChain(chainInfo);
410
- this.refreshChainStateInterval(1000);
409
+ this.refreshChainStateInterval(3000, 6);
411
410
  this.dbService.updateChainStore({
412
411
  ...chainInfo,
413
412
  active: true,
@@ -961,21 +960,23 @@ export class ChainService {
961
960
  }
962
961
  async validateCustomToken(data) {
963
962
  const assetRegistry = this.getSmartContractTokens();
964
- let isExist = false;
963
+ let existedToken;
965
964
  for (const token of Object.values(assetRegistry)) {
966
965
  var _token$metadata2;
967
966
  const contractAddress = token === null || token === void 0 ? void 0 : (_token$metadata2 = token.metadata) === null || _token$metadata2 === void 0 ? void 0 : _token$metadata2.contractAddress;
968
967
  if (_isEqualContractAddress(contractAddress, data.contractAddress) && token.assetType === data.type && token.originChain === data.originChain) {
969
- isExist = true;
968
+ existedToken = token;
970
969
  break;
971
970
  }
972
971
  }
973
- if (isExist) {
972
+ if (existedToken) {
973
+ var _existedToken;
974
974
  return {
975
- decimals: -1,
976
- name: '',
977
- symbol: '',
978
- isExist,
975
+ decimals: existedToken.decimals || 0,
976
+ name: existedToken.name,
977
+ symbol: existedToken.symbol,
978
+ isExist: !!existedToken,
979
+ existedSlug: (_existedToken = existedToken) === null || _existedToken === void 0 ? void 0 : _existedToken.slug,
979
980
  contractError: false
980
981
  };
981
982
  }
@@ -989,7 +990,7 @@ export class ChainService {
989
990
  name,
990
991
  decimals,
991
992
  symbol,
992
- isExist,
993
+ isExist: !!existedToken,
993
994
  contractError
994
995
  };
995
996
  }
@@ -1039,19 +1040,26 @@ export class ChainService {
1039
1040
 
1040
1041
  return this.substrateChainHandler.resumeAllApis();
1041
1042
  }
1042
-
1043
- // Interval update api status
1044
- refreshChainStateInterval(delay = 0) {
1043
+ refreshChainStateTimeout = undefined;
1044
+ refreshChainStateTimes = 0;
1045
+ refreshChainStateInterval(delay = 0, times) {
1045
1046
  clearTimeout(this.refreshChainStateTimeout);
1046
1047
  setTimeout(() => {
1047
- this.updateApiMapStatus();
1048
+ if (times) {
1049
+ this.refreshChainStateTimes = times;
1050
+ }
1051
+ this.refreshChainStateTimes -= 1;
1052
+ if (this.refreshChainStateTimes < 0) {
1053
+ return;
1054
+ }
1055
+ this.updateApiMapStatus().catch(console.error);
1048
1056
  this.refreshChainStateTimeout = setTimeout(() => {
1049
- this.updateApiMapStatus();
1050
- this.refreshChainStateInterval();
1051
- }, CRON_GET_API_MAP_STATUS);
1057
+ this.updateApiMapStatus().catch(console.error);
1058
+ this.refreshChainStateInterval(0);
1059
+ }, 3000);
1052
1060
  }, delay);
1053
1061
  }
1054
- updateApiMapStatus() {
1062
+ async updateApiMapStatus() {
1055
1063
  const substrateApiMap = this.getSubstrateApiMap();
1056
1064
  const evmApiMap = this.getEvmApiMap();
1057
1065
  const chainStateMap = this.getChainStateMap();
@@ -1062,24 +1070,30 @@ export class ChainService {
1062
1070
  update = true;
1063
1071
  }
1064
1072
  }
1065
- Object.entries(chainStateMap).forEach(([chain, chainState]) => {
1066
- if (chainState.active) {
1067
- if (substrateApiMap[chain]) {
1068
- const api = substrateApiMap[chain];
1069
- if (api) {
1070
- updateState(chainState, _ChainConnectionStatus.CONNECTED);
1071
- return;
1072
- }
1073
- } else if (evmApiMap[chain]) {
1074
- const api = evmApiMap[chain];
1075
- if (api) {
1076
- updateState(chainState, _ChainConnectionStatus.CONNECTED);
1077
- return;
1073
+ const promiseList = Object.entries(chainStateMap).map(async ([chain, chainState]) => {
1074
+ try {
1075
+ if (chainState.active) {
1076
+ if (substrateApiMap[chain]) {
1077
+ const api = substrateApiMap[chain];
1078
+ if (api.isApiConnected) {
1079
+ updateState(chainState, _ChainConnectionStatus.CONNECTED);
1080
+ return;
1081
+ }
1082
+ } else if (evmApiMap[chain]) {
1083
+ var _api$api;
1084
+ const api = evmApiMap[chain];
1085
+ if (await (api === null || api === void 0 ? void 0 : (_api$api = api.api) === null || _api$api === void 0 ? void 0 : _api$api.eth.net.isListening())) {
1086
+ updateState(chainState, _ChainConnectionStatus.CONNECTED);
1087
+ return;
1088
+ }
1078
1089
  }
1079
1090
  }
1091
+ updateState(chainState, _ChainConnectionStatus.DISCONNECTED);
1092
+ } catch (e) {
1093
+ updateState(chainState, _ChainConnectionStatus.DISCONNECTED);
1080
1094
  }
1081
- updateState(chainState, _ChainConnectionStatus.DISCONNECTED);
1082
1095
  });
1096
+ await Promise.all(promiseList);
1083
1097
  if (update) {
1084
1098
  console.log('Update chain connection state');
1085
1099
  this.chainStateMapSubject.next(chainStateMap);
@@ -104,6 +104,7 @@ export interface _SmartContractTokenInfo {
104
104
  }
105
105
  export interface _ValidateCustomAssetResponse extends _SmartContractTokenInfo {
106
106
  isExist: boolean;
107
+ existedSlug?: string;
107
108
  }
108
109
  export declare const _FUNGIBLE_CONTRACT_STANDARDS: _AssetType[];
109
110
  export declare const _NFT_CONTRACT_STANDARDS: _AssetType[];
@@ -1,14 +1,16 @@
1
1
  import { TransactionHistoryItem } from '@subwallet/extension-base/background/KoniTypes';
2
2
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
3
3
  import { EventService } from '@subwallet/extension-base/services/event-service';
4
+ import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
4
5
  import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
5
6
  import { BehaviorSubject } from 'rxjs';
6
7
  export declare class HistoryService {
7
8
  private dbService;
8
9
  private chainService;
9
10
  private eventService;
11
+ private keyringService;
10
12
  private historySubject;
11
- constructor(dbService: DatabaseService, chainService: ChainService, eventService: EventService);
13
+ constructor(dbService: DatabaseService, chainService: ChainService, eventService: EventService, keyringService: KeyringService);
12
14
  private fetchPromise;
13
15
  private nextFetch;
14
16
  private fetchAndLoadHistories;
@@ -3,15 +3,15 @@
3
3
 
4
4
  import { CRON_REFRESH_HISTORY_INTERVAL } from '@subwallet/extension-base/constants';
5
5
  import { keyring } from '@subwallet/ui-keyring';
6
- import { accounts } from '@subwallet/ui-keyring/observable/accounts';
7
6
  import { BehaviorSubject } from 'rxjs';
8
7
  import { fetchMultiChainHistories } from "./subsquid-multi-chain-history.js";
9
8
  export class HistoryService {
10
9
  historySubject = new BehaviorSubject([]);
11
- constructor(dbService, chainService, eventService) {
10
+ constructor(dbService, chainService, eventService, keyringService) {
12
11
  this.dbService = dbService;
13
12
  this.chainService = chainService;
14
13
  this.eventService = eventService;
14
+ this.keyringService = keyringService;
15
15
  // Load history from database
16
16
  this.dbService.getHistories().then(histories => {
17
17
  this.historySubject.next(histories);
@@ -40,7 +40,7 @@ export class HistoryService {
40
40
  const historyRecords = await fetchMultiChainHistories(addresses, chainMap);
41
41
 
42
42
  // Fill additional info
43
- const accountMap = Object.entries(accounts.subject.value).reduce((map, [address, account]) => {
43
+ const accountMap = Object.entries(this.keyringService.accounts).reduce((map, [address, account]) => {
44
44
  map[address.toLowerCase()] = account.json.meta.name || address;
45
45
  return map;
46
46
  }, {});
@@ -111,7 +111,7 @@ export function parseSubsquidTransactionData(address, type, historyItem, chainIn
111
111
  const transaction = data.call.data.args.transaction.value;
112
112
  to = autoFormatAddress(parsedArgs.to);
113
113
  from = autoFormatAddress(parsedArgs.from);
114
- extrinsicHash = parsedArgs.transactionHash;
114
+ extrinsicHash = parsedArgs.transactionHash || extrinsic.hash;
115
115
  amount = transaction.value || '0';
116
116
  fee = (parseInt(transaction.gasPrice) * parseInt(transaction.gasLimit)).toString();
117
117
  signature = generateSignature(transaction.signature);
@@ -3,17 +3,19 @@ import { EventService } from '@subwallet/extension-base/services/event-service';
3
3
  import { SubjectInfo } from '@subwallet/ui-keyring/observable/types';
4
4
  import { BehaviorSubject } from 'rxjs';
5
5
  export declare class KeyringService {
6
+ private eventService;
6
7
  private readonly currentAccountStore;
7
8
  readonly currentAccountSubject: BehaviorSubject<CurrentAccountInfo>;
8
- readonly accountsSubject: BehaviorSubject<SubjectInfo>;
9
+ readonly addressesSubject: BehaviorSubject<SubjectInfo>;
10
+ readonly accountSubject: BehaviorSubject<SubjectInfo>;
9
11
  private beforeAccount;
10
12
  readonly keyringStateSubject: BehaviorSubject<KeyringState>;
11
- private eventService;
12
13
  constructor(eventService: EventService);
13
14
  private subscribeAccounts;
14
15
  get keyringState(): KeyringState;
15
16
  updateKeyringState(isReady?: boolean): void;
16
17
  get accounts(): SubjectInfo;
18
+ get addresses(): SubjectInfo;
17
19
  get currentAccount(): CurrentAccountInfo;
18
20
  setCurrentAccount(currentAccountData: CurrentAccountInfo): void;
19
21
  }
@@ -10,8 +10,9 @@ export class KeyringService {
10
10
  address: '',
11
11
  currentGenesisHash: null
12
12
  });
13
- accountsSubject = keyring.accounts.subject;
14
- beforeAccount = keyring.accounts.subject.value;
13
+ addressesSubject = keyring.addresses.subject;
14
+ accountSubject = keyring.accounts.subject;
15
+ beforeAccount = this.accountSubject.value;
15
16
  keyringStateSubject = new BehaviorSubject({
16
17
  isReady: false,
17
18
  hasMasterPassword: false,
@@ -20,23 +21,17 @@ export class KeyringService {
20
21
  constructor(eventService) {
21
22
  this.eventService = eventService;
22
23
  this.currentAccountStore.get('CurrentAccountInfo', rs => {
23
- this.currentAccountSubject.next(rs);
24
+ rs && this.currentAccountSubject.next(rs);
24
25
  });
25
26
  this.subscribeAccounts().catch(console.error);
26
27
  }
27
28
  async subscribeAccounts() {
28
29
  // Wait until account ready
29
- await new Promise(resolve => {
30
- const onReady = () => {
31
- this.eventService.off('account.ready', onReady);
32
- resolve(true);
33
- };
34
- this.eventService.on('account.ready', onReady);
35
- });
30
+ await this.eventService.waitAccountReady;
36
31
  this.beforeAccount = {
37
- ...this.accountsSubject.value
32
+ ...this.accountSubject.value
38
33
  };
39
- this.accountsSubject.subscribe(subjectInfo => {
34
+ this.accountSubject.subscribe(subjectInfo => {
40
35
  // Check if accounts changed
41
36
  const beforeAddresses = Object.keys(this.beforeAccount);
42
37
  const afterAddresses = Object.keys(subjectInfo);
@@ -80,7 +75,10 @@ export class KeyringService {
80
75
  });
81
76
  }
82
77
  get accounts() {
83
- return this.accountsSubject.value;
78
+ return this.accountSubject.value;
79
+ }
80
+ get addresses() {
81
+ return this.addressesSubject.value;
84
82
  }
85
83
  get currentAccount() {
86
84
  return this.currentAccountSubject.value;
@@ -2,17 +2,19 @@ import { _ChainInfo } from '@subwallet/chain-list/types';
2
2
  import { AuthRequestV2 } from '@subwallet/extension-base/background/KoniTypes';
3
3
  import { AccountAuthType, AuthorizeRequest, RequestAuthorizeTab } from '@subwallet/extension-base/background/types';
4
4
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
5
+ import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
5
6
  import RequestService from '@subwallet/extension-base/services/request-service';
6
7
  import { AuthUrls } from '@subwallet/extension-base/services/request-service/types';
7
8
  import { BehaviorSubject, Subject } from 'rxjs';
8
9
  export default class AuthRequestHandler {
9
10
  #private;
11
+ private keyringService;
10
12
  private readonly authorizeStore;
11
13
  private authorizeCached;
12
14
  private readonly authorizeUrlSubject;
13
15
  private readonly evmChainSubject;
14
16
  readonly authSubjectV2: BehaviorSubject<AuthorizeRequest[]>;
15
- constructor(requestService: RequestService, chainService: ChainService);
17
+ constructor(requestService: RequestService, chainService: ChainService, keyringService: KeyringService);
16
18
  private stripUrl;
17
19
  private getAddressList;
18
20
  get numAuthRequestsV2(): number;
@@ -6,7 +6,6 @@ import { PREDEFINED_CHAIN_DAPP_CHAIN_MAP } from '@subwallet/extension-base/servi
6
6
  import AuthorizeStore from '@subwallet/extension-base/stores/Authorize';
7
7
  import { getDomainFromUrl } from '@subwallet/extension-base/utils';
8
8
  import { getId } from '@subwallet/extension-base/utils/getId';
9
- import { accounts } from '@subwallet/ui-keyring/observable/accounts';
10
9
  import { BehaviorSubject, Subject } from 'rxjs';
11
10
  import { assert } from '@polkadot/util';
12
11
  import { isEthereumAddress } from '@polkadot/util-crypto';
@@ -20,7 +19,8 @@ export default class AuthRequestHandler {
20
19
  authorizeUrlSubject = new Subject();
21
20
  evmChainSubject = new Subject();
22
21
  authSubjectV2 = new BehaviorSubject([]);
23
- constructor(requestService, chainService) {
22
+ constructor(requestService, chainService, keyringService) {
23
+ this.keyringService = keyringService;
24
24
  this.#requestService = requestService;
25
25
  this.#chainService = chainService;
26
26
  }
@@ -30,7 +30,7 @@ export default class AuthRequestHandler {
30
30
  return parts[2];
31
31
  }
32
32
  getAddressList(value = false) {
33
- const addressList = Object.keys(accounts.subject.value);
33
+ const addressList = Object.keys(this.keyringService.accounts);
34
34
  return addressList.reduce((addressList, v) => ({
35
35
  ...addressList,
36
36
  [v]: value
@@ -101,8 +101,10 @@ export default class AuthRequestHandler {
101
101
  return (_chainStateMap$chain$ = chainStateMap[chain.slug]) === null || _chainStateMap$chain$ === void 0 ? void 0 : _chainStateMap$chain$.active;
102
102
  })) || evmChains[0];
103
103
  if (options.autoActive) {
104
- if (!needEnableChains.includes(chainInfo.slug)) {
105
- needEnableChains.push(chainInfo.slug);
104
+ var _chainInfo;
105
+ if (!needEnableChains.includes((_chainInfo = chainInfo) === null || _chainInfo === void 0 ? void 0 : _chainInfo.slug)) {
106
+ var _chainInfo2;
107
+ needEnableChains.push((_chainInfo2 = chainInfo) === null || _chainInfo2 === void 0 ? void 0 : _chainInfo2.slug);
106
108
  }
107
109
  }
108
110
  }
@@ -67,16 +67,7 @@ export default class EvmRequestHandler {
67
67
  });
68
68
  this.confirmationsQueueSubject.next(confirmations);
69
69
  if (!isInternal) {
70
- // Not open new popup and use existed
71
- const popupList = this.#requestService.popup;
72
- if (this.#requestService.popup.length > 0) {
73
- // eslint-disable-next-line no-void
74
- void chrome.windows.update(popupList[0], {
75
- focused: true
76
- });
77
- } else {
78
- this.#requestService.popupOpen();
79
- }
70
+ this.#requestService.popupOpen();
80
71
  }
81
72
  this.#requestService.updateIconV2();
82
73
  return promise;
@@ -127,7 +118,8 @@ export default class EvmRequestHandler {
127
118
  data: toBuffer(config.data)
128
119
  };
129
120
  const common = Common.custom({
130
- chainId: config.chainId
121
+ chainId: config.chainId,
122
+ defaultHardfork: 'petersburg'
131
123
  });
132
124
 
133
125
  // @ts-ignore
@@ -140,11 +132,15 @@ export default class EvmRequestHandler {
140
132
  const {
141
133
  estimateGas,
142
134
  from,
143
- gasPrice
135
+ gas,
136
+ gasPrice,
137
+ value
144
138
  } = transaction;
145
139
  const pair = keyring.getPair(from);
146
140
  const params = {
147
141
  ...transaction,
142
+ gas: anyNumberToBN(gas).toNumber(),
143
+ value: anyNumberToBN(value).toNumber(),
148
144
  gasPrice: anyNumberToBN(gasPrice).toNumber(),
149
145
  gasLimit: anyNumberToBN(estimateGas).toNumber()
150
146
  // nonce: await web3.eth.getTransactionCount(from) // Todo: fill this value from transaction service
@@ -1,6 +1,7 @@
1
1
  import { AuthRequestV2, ConfirmationDefinitions, ConfirmationsQueue, ConfirmationsQueueItemOptions, ConfirmationType, RequestConfirmationComplete } from '@subwallet/extension-base/background/KoniTypes';
2
2
  import { AccountAuthType, AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestSign, ResponseSigning, SigningRequest } from '@subwallet/extension-base/background/types';
3
3
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
4
+ import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
4
5
  import { AuthUrls, MetaRequest } from '@subwallet/extension-base/services/request-service/types';
5
6
  import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
6
7
  import { MetadataDef } from '@subwallet/extension-inject/types';
@@ -8,8 +9,9 @@ import { BehaviorSubject, Subject } from 'rxjs';
8
9
  import { SignerPayloadJSON } from '@polkadot/types/types/extrinsic';
9
10
  export default class RequestService {
10
11
  #private;
12
+ private keyringService;
11
13
  readonly settingService: SettingService;
12
- constructor(chainService: ChainService, settingService: SettingService);
14
+ constructor(chainService: ChainService, settingService: SettingService, keyringService: KeyringService);
13
15
  get numAllRequests(): number;
14
16
  updateIconV2(shouldClose?: boolean): void;
15
17
  getAddressList(value?: boolean): Record<string, boolean>;
@@ -6,7 +6,6 @@ import EvmRequestHandler from '@subwallet/extension-base/services/request-servic
6
6
  import MetadataRequestHandler from '@subwallet/extension-base/services/request-service/handler/MetadataRequestHandler';
7
7
  import PopupHandler from '@subwallet/extension-base/services/request-service/handler/PopupHandler';
8
8
  import SubstrateRequestHandler from '@subwallet/extension-base/services/request-service/handler/SubstrateRequestHandler';
9
- import { accounts } from '@subwallet/ui-keyring/observable/accounts';
10
9
  export default class RequestService {
11
10
  // Common
12
11
  #chainService;
@@ -17,12 +16,13 @@ export default class RequestService {
17
16
  #evmRequestHandler;
18
17
 
19
18
  // Common
20
- constructor(chainService, settingService) {
19
+ constructor(chainService, settingService, keyringService) {
20
+ this.keyringService = keyringService;
21
21
  this.#chainService = chainService;
22
22
  this.settingService = settingService;
23
23
  this.#popupHandler = new PopupHandler(this);
24
24
  this.#metadataRequestHandler = new MetadataRequestHandler(this);
25
- this.#authRequestHandler = new AuthRequestHandler(this, this.#chainService);
25
+ this.#authRequestHandler = new AuthRequestHandler(this, this.#chainService, this.keyringService);
26
26
  this.#substrateRequestHandler = new SubstrateRequestHandler(this);
27
27
  this.#evmRequestHandler = new EvmRequestHandler(this);
28
28
 
@@ -36,7 +36,7 @@ export default class RequestService {
36
36
  this.#popupHandler.updateIconV2(shouldClose);
37
37
  }
38
38
  getAddressList(value = false) {
39
- const addressList = Object.keys(accounts.subject.value);
39
+ const addressList = Object.keys(this.keyringService.accounts);
40
40
  return addressList.reduce((addressList, v) => ({
41
41
  ...addressList,
42
42
  [v]: value
@@ -51,7 +51,16 @@ export default class RequestService {
51
51
  this.#popupHandler.popupClose();
52
52
  }
53
53
  popupOpen() {
54
- this.#popupHandler.popupOpen();
54
+ // Not open new popup and use existed
55
+ const popupList = this.#popupHandler.popup;
56
+ if (popupList && popupList.length > 0) {
57
+ var _chrome$windows$updat;
58
+ (_chrome$windows$updat = chrome.windows.update(popupList[0], {
59
+ focused: true
60
+ })) === null || _chrome$windows$updat === void 0 ? void 0 : _chrome$windows$updat.catch(console.error);
61
+ } else {
62
+ this.#popupHandler.popupOpen();
63
+ }
55
64
  }
56
65
 
57
66
  // Metadata
@@ -45,7 +45,7 @@ export default class DatabaseService {
45
45
  deleteNftCollection(chain: string, collectionId: string): Promise<void>;
46
46
  getAllNftCollection(chainHashes?: string[]): import("dexie").PromiseExtended<NftCollection[]>;
47
47
  subscribeNft(addresses: string[], chainHashes?: string[], callback?: (nfts: INft[]) => void): Subscription;
48
- cleanUpNft(chain: string, owner: string, collectionId: string, nftIds: string[]): Promise<number>;
48
+ cleanUpNft(chain: string, owner: string, collectionIds: string[], nftIds: string[], ownNothing?: boolean): Promise<number>;
49
49
  getNft(addresses: string[], chainHashes?: string[]): Promise<INft[]>;
50
50
  addNft(address: string, nft: NftItem): Promise<unknown>;
51
51
  handleNftTransfer(chain: string, addresses: string[], nftItem: NftItem): import("dexie").PromiseExtended<number>;
@@ -123,8 +123,8 @@ export default class DatabaseService {
123
123
  }
124
124
  async upsertHistory(histories) {
125
125
  // this.logger.log('Updating transaction histories');
126
-
127
- return this.stores.transaction.bulkUpsert(histories);
126
+ const cleanedHistory = histories.filter(x => x && x.address && x.chain && x.extrinsicHash);
127
+ return this.stores.transaction.bulkUpsert(cleanedHistory);
128
128
  }
129
129
 
130
130
  // NFT Collection
@@ -149,9 +149,12 @@ export default class DatabaseService {
149
149
  });
150
150
  return this.nftSubscription;
151
151
  }
152
- async cleanUpNft(chain, owner, collectionId, nftIds) {
153
- const result = await this.stores.nft.cleanUpNfts(chain, reformatAddress(owner, 42), collectionId, nftIds);
154
- result > 0 && console.debug(`Clean up ${result} NFTs from collection ${collectionId} on chain ${chain} for owner ${owner}`);
152
+ async cleanUpNft(chain, owner, collectionIds, nftIds, ownNothing) {
153
+ if (ownNothing) {
154
+ return this.stores.nft.deleteNftsByChainAndOwner(chain, reformatAddress(owner, 42));
155
+ }
156
+ const result = await this.stores.nft.cleanUpNfts(chain, reformatAddress(owner, 42), collectionIds, nftIds);
157
+ result > 0 && console.debug(`Cleaned up ${result} NFTs on chain ${chain} for owner ${reformatAddress(owner, 42)}`, collectionIds, nftIds);
155
158
  return result;
156
159
  }
157
160
  async getNft(addresses, chainHashes) {
@@ -4,7 +4,8 @@ import { INft } from '../databases';
4
4
  export default class NftStore extends BaseStoreWithAddressAndChain<INft> {
5
5
  getNft(addresses: string[], chainList?: string[]): import("dexie").PromiseExtended<INft[]>;
6
6
  subscribeNft(addresses: string[], chainList?: string[]): import("dexie").Observable<INft[]>;
7
- cleanUpNfts(chain: string, address: string, collectionId: string, nftIds: string[]): import("dexie").PromiseExtended<number>;
7
+ cleanUpNfts(chain: string, address: string, collectionIds: string[], nftIds: string[]): import("dexie").PromiseExtended<number>;
8
+ deleteNftsByChainAndOwner(chain: string, address: string): import("dexie").PromiseExtended<number>;
8
9
  deleteNftByAddress(addresses: string[]): import("dexie").PromiseExtended<number>;
9
10
  deleteNftItem(chain: string, addresses: string[], nftItem: NftItem): import("dexie").PromiseExtended<number>;
10
11
  deleteNftsByCollection(chain: string, collectionId: string): import("dexie").PromiseExtended<number>;
@@ -15,12 +15,17 @@ export default class NftStore extends BaseStoreWithAddressAndChain {
15
15
  subscribeNft(addresses, chainList = []) {
16
16
  return liveQuery(() => this.getNft(addresses, chainList));
17
17
  }
18
- cleanUpNfts(chain, address, collectionId, nftIds) {
18
+ cleanUpNfts(chain, address, collectionIds, nftIds) {
19
19
  return this.table.where({
20
20
  address,
21
- chain,
22
- collectionId
23
- }).and(nft => !nftIds.includes(nft.id)).delete();
21
+ chain
22
+ }).and(nft => !collectionIds.includes(nft.collectionId) || collectionIds.includes(nft.collectionId) && !nftIds.includes(nft.id)).delete();
23
+ }
24
+ deleteNftsByChainAndOwner(chain, address) {
25
+ return this.table.where({
26
+ address,
27
+ chain
28
+ }).delete();
24
29
  }
25
30
  deleteNftByAddress(addresses) {
26
31
  return this.table.where('address').anyOfIgnoreCase(addresses).delete();