@subwallet/extension-base 1.0.1 → 1.0.2-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 (169) hide show
  1. package/background/KoniTypes.d.ts +10 -3
  2. package/background/KoniTypes.js +6 -0
  3. package/cjs/background/KoniTypes.js +8 -1
  4. package/cjs/constants/index.js +6 -3
  5. package/cjs/koni/api/dotsama/balance.js +11 -0
  6. package/cjs/koni/api/staking/bonding/amplitude.js +6 -2
  7. package/cjs/koni/api/staking/bonding/astar.js +40 -243
  8. package/cjs/koni/api/staking/bonding/index.js +4 -4
  9. package/cjs/koni/api/staking/bonding/paraChain.js +16 -10
  10. package/cjs/koni/api/staking/bonding/relayChain.js +62 -7
  11. package/cjs/koni/api/staking/bonding/utils.js +29 -3
  12. package/cjs/koni/api/xcm/index.js +0 -111
  13. package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
  14. package/cjs/koni/api/xcm/xTokens.js +2 -4
  15. package/cjs/koni/background/cron.js +61 -62
  16. package/cjs/koni/background/handlers/Extension.js +143 -149
  17. package/cjs/koni/background/handlers/State.js +129 -91
  18. package/cjs/koni/background/handlers/Tabs.js +40 -38
  19. package/cjs/koni/background/subscription.js +48 -43
  20. package/cjs/packageInfo.js +1 -1
  21. package/cjs/page/index.js +5 -0
  22. package/cjs/services/chain-service/constants.js +1 -11
  23. package/cjs/services/chain-service/index.js +39 -5
  24. package/cjs/services/chain-service/utils.js +4 -0
  25. package/cjs/services/event-service/index.js +71 -0
  26. package/cjs/services/event-service/types.js +1 -0
  27. package/cjs/services/history-service/index.js +36 -17
  28. package/cjs/services/history-service/subsquid-multi-chain-history.js +7 -2
  29. package/cjs/services/keyring-service/index.js +101 -0
  30. package/cjs/services/migration-service/index.js +13 -10
  31. package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
  32. package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
  33. package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
  34. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
  35. package/cjs/services/migration-service/scripts/index.js +13 -4
  36. package/cjs/services/price-service/coingecko.js +16 -3
  37. package/cjs/services/price-service/index.js +15 -17
  38. package/cjs/services/request-service/constants.js +8 -2
  39. package/cjs/services/request-service/handler/AuthRequestHandler.js +39 -12
  40. package/cjs/services/request-service/index.js +3 -0
  41. package/cjs/services/storage-service/DatabaseService.js +1 -1
  42. package/cjs/services/storage-service/databases/index.js +1 -1
  43. package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  44. package/cjs/services/storage-service/db-stores/Nft.js +4 -1
  45. package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
  46. package/cjs/services/subscan-service/index.js +107 -0
  47. package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
  48. package/cjs/services/subscan-service/types.js +1 -0
  49. package/cjs/services/transaction-service/index.js +45 -10
  50. package/cjs/services/transaction-service/utils.js +4 -6
  51. package/cjs/utils/address.js +9 -1
  52. package/cjs/utils/index.js +24 -13
  53. package/constants/index.d.ts +1 -0
  54. package/constants/index.js +1 -0
  55. package/koni/api/dotsama/balance.js +11 -0
  56. package/koni/api/staking/bonding/amplitude.d.ts +1 -1
  57. package/koni/api/staking/bonding/amplitude.js +8 -4
  58. package/koni/api/staking/bonding/astar.d.ts +2 -11
  59. package/koni/api/staking/bonding/astar.js +35 -229
  60. package/koni/api/staking/bonding/index.d.ts +1 -1
  61. package/koni/api/staking/bonding/index.js +4 -4
  62. package/koni/api/staking/bonding/paraChain.d.ts +1 -1
  63. package/koni/api/staking/bonding/paraChain.js +17 -11
  64. package/koni/api/staking/bonding/relayChain.d.ts +1 -1
  65. package/koni/api/staking/bonding/relayChain.js +63 -8
  66. package/koni/api/staking/bonding/utils.d.ts +13 -1
  67. package/koni/api/staking/bonding/utils.js +27 -3
  68. package/koni/api/xcm/index.js +1 -112
  69. package/koni/api/xcm/polkadotXcm.js +1 -1
  70. package/koni/api/xcm/xTokens.js +3 -5
  71. package/koni/background/cron.js +60 -60
  72. package/koni/background/handlers/Extension.js +71 -76
  73. package/koni/background/handlers/State.d.ts +16 -14
  74. package/koni/background/handlers/State.js +126 -91
  75. package/koni/background/handlers/Tabs.js +22 -19
  76. package/koni/background/subscription.d.ts +1 -1
  77. package/koni/background/subscription.js +49 -44
  78. package/package.json +56 -16
  79. package/packageInfo.js +1 -1
  80. package/page/index.d.ts +2 -0
  81. package/page/index.js +4 -0
  82. package/services/chain-service/constants.d.ts +0 -1
  83. package/services/chain-service/constants.js +0 -9
  84. package/services/chain-service/index.d.ts +6 -4
  85. package/services/chain-service/index.js +39 -7
  86. package/services/chain-service/utils.d.ts +1 -0
  87. package/services/chain-service/utils.js +3 -0
  88. package/services/event-service/index.d.ts +22 -0
  89. package/services/event-service/index.js +59 -0
  90. package/services/event-service/types.d.ts +32 -0
  91. package/services/event-service/types.js +1 -0
  92. package/services/history-service/index.d.ts +5 -3
  93. package/services/history-service/index.js +36 -17
  94. package/services/history-service/subsquid-multi-chain-history.js +7 -2
  95. package/services/keyring-service/index.d.ts +19 -0
  96. package/services/keyring-service/index.js +93 -0
  97. package/services/migration-service/index.js +11 -9
  98. package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
  99. package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
  100. package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
  101. package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
  102. package/services/migration-service/scripts/MigrateSettings.js +23 -0
  103. package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
  104. package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
  105. package/services/migration-service/scripts/index.d.ts +1 -0
  106. package/services/migration-service/scripts/index.js +10 -3
  107. package/services/price-service/coingecko.js +16 -3
  108. package/services/price-service/index.d.ts +5 -3
  109. package/services/price-service/index.js +15 -17
  110. package/services/request-service/constants.d.ts +1 -0
  111. package/services/request-service/constants.js +6 -1
  112. package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
  113. package/services/request-service/handler/AuthRequestHandler.js +40 -13
  114. package/services/request-service/index.d.ts +7 -1
  115. package/services/request-service/index.js +3 -0
  116. package/services/storage-service/DatabaseService.js +1 -1
  117. package/services/storage-service/databases/index.js +1 -1
  118. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
  119. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  120. package/services/storage-service/db-stores/Nft.d.ts +2 -1
  121. package/services/storage-service/db-stores/Nft.js +4 -1
  122. package/services/storage-service/db-stores/Transaction.js +10 -7
  123. package/services/subscan-service/index.d.ts +20 -0
  124. package/services/subscan-service/index.js +99 -0
  125. package/services/subscan-service/subscan-chain-map.d.ts +5 -0
  126. package/services/subscan-service/subscan-chain-map.js +63 -0
  127. package/services/subscan-service/types.d.ts +27 -0
  128. package/services/subscan-service/types.js +1 -0
  129. package/services/transaction-service/event-parser/index.d.ts +2 -2
  130. package/services/transaction-service/index.d.ts +4 -2
  131. package/services/transaction-service/index.js +45 -10
  132. package/services/transaction-service/utils.js +5 -6
  133. package/utils/address.d.ts +1 -0
  134. package/utils/address.js +9 -2
  135. package/utils/index.d.ts +1 -0
  136. package/utils/index.js +21 -12
  137. package/cjs/background/errors/EvmRpcError.js +0 -21
  138. package/cjs/background/errors/SubWalletProviderError.js +0 -17
  139. package/cjs/constants/ethereum.js +0 -19
  140. package/cjs/errors/SubWalletProviderError.js +0 -17
  141. package/cjs/koni/api/xcm/astar.js +0 -160
  142. package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
  143. package/cjs/koni/api/xcm/statemintXcm.js +0 -197
  144. package/cjs/koni/api/xcm/substrateXcm.js +0 -213
  145. package/cjs/koni/migration/Base.js +0 -20
  146. package/cjs/koni/migration/index.js +0 -45
  147. package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
  148. package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
  149. package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
  150. package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
  151. package/cjs/koni/migration/scripts/index.js +0 -22
  152. package/cjs/koni/page/index.js +0 -16
  153. package/cjs/services/asset-service/index.js +0 -91
  154. package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
  155. package/cjs/stores/Balance.js +0 -18
  156. package/cjs/stores/Crowdloan.js +0 -18
  157. package/cjs/stores/CustomEvmToken.js +0 -18
  158. package/cjs/stores/NetworkMap.js +0 -18
  159. package/cjs/stores/Nft.js +0 -18
  160. package/cjs/stores/NftCollection.js +0 -18
  161. package/cjs/stores/Price.js +0 -18
  162. package/cjs/stores/Staking.js +0 -18
  163. package/cjs/stores/StakingReward.js +0 -18
  164. package/cjs/utils/eth/parseTransactionData.js +0 -284
  165. package/koni/page/index.d.ts +0 -2
  166. package/koni/page/index.js +0 -9
  167. /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
  168. /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
  169. /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
@@ -96,6 +96,9 @@ export default class RequestService {
96
96
  getAuthRequestV2(id) {
97
97
  return this.#authRequestHandler.getAuthRequestV2(id);
98
98
  }
99
+ getDAppChainInfo(options) {
100
+ return this.#authRequestHandler.getDAppChainInfo(options);
101
+ }
99
102
  get subscribeEvmChainChange() {
100
103
  return this.#authRequestHandler.subscribeEvmChainChange;
101
104
  }
@@ -157,7 +157,7 @@ export default class DatabaseService {
157
157
  });
158
158
  }
159
159
  handleNftTransfer(chain, addresses, nftItem) {
160
- return this.stores.nft.deleteNftByAddresses(chain, addresses, nftItem);
160
+ return this.stores.nft.deleteNftItem(chain, addresses, nftItem);
161
161
  }
162
162
  removeNfts(chain, address, collectionId, nftIds) {
163
163
  this.logger.log(`Remove NFTs [${nftIds.join(', ')}]`);
@@ -4,7 +4,7 @@
4
4
  import Dexie from 'dexie';
5
5
  const DEFAULT_DATABASE = 'SubWalletDB_v2';
6
6
  export default class KoniDatabase extends Dexie {
7
- constructor(name = DEFAULT_DATABASE, schemaVersion = 9) {
7
+ constructor(name = DEFAULT_DATABASE, schemaVersion = 10) {
8
8
  super(name);
9
9
  this.schemaVersion = schemaVersion;
10
10
  this.conditionalVersion(1, {
@@ -2,6 +2,6 @@ import { DefaultDocWithAddressAndChain } from '@subwallet/extension-base/service
2
2
  import BaseStore from '@subwallet/extension-base/services/storage-service/db-stores/BaseStore';
3
3
  export default class BaseStoreWithAddressAndChain<T extends DefaultDocWithAddressAndChain> extends BaseStore<T> {
4
4
  convertToJsonObject(items: T[]): Record<string, T>;
5
- removeAllByAddress(address: string, chain?: string): import("dexie").PromiseExtended<number>;
5
+ removeAllByAddress(address: string): import("dexie").PromiseExtended<number>;
6
6
  getDataByAddressAsObject(address: string): Promise<Record<string, T>>;
7
7
  }
@@ -9,14 +9,8 @@ export default class BaseStoreWithAddressAndChain extends BaseStore {
9
9
  [v.chain]: v
10
10
  }), {});
11
11
  }
12
- removeAllByAddress(address, chain) {
13
- const conditions = {
14
- address
15
- };
16
- if (chain) {
17
- conditions.chain = chain;
18
- }
19
- return this.table.where(conditions).delete();
12
+ removeAllByAddress(address) {
13
+ return this.table.where('address').equalsIgnoreCase(address).delete();
20
14
  }
21
15
  async getDataByAddressAsObject(address) {
22
16
  const data = await this.table.where('address').equals(address).toArray();
@@ -6,7 +6,8 @@ export default class NftStore extends BaseStoreWithAddressAndChain<INft> {
6
6
  subscribeNft(addresses: string[], chainList?: string[]): import("dexie").Observable<INft[]>;
7
7
  deleteRemovedNftsFromCollection(chainHash: string, address: string, collection?: string, nftIds?: string[]): void | import("dexie").PromiseExtended<number>;
8
8
  deleteNftsFromRemovedCollection(chain: string, address: string, collectionIds: string[]): import("dexie").Collection<INft, unknown>;
9
- deleteNftByAddresses(chain: string, addresses: string[], nftItem: NftItem): import("dexie").PromiseExtended<number>;
9
+ deleteNftByAddress(addresses: string[]): import("dexie").PromiseExtended<number>;
10
+ deleteNftItem(chain: string, addresses: string[], nftItem: NftItem): import("dexie").PromiseExtended<number>;
10
11
  deleteNftsByCollection(chain: string, collectionId: string): import("dexie").PromiseExtended<number>;
11
12
  removeNfts(chain: string, address: string, collectionId: string, nftIds: string[]): import("dexie").PromiseExtended<number>;
12
13
  }
@@ -34,7 +34,10 @@ export default class NftStore extends BaseStoreWithAddressAndChain {
34
34
  chain
35
35
  }).and(nft => !collectionIds.some(item => item === nft.collectionId));
36
36
  }
37
- deleteNftByAddresses(chain, addresses, nftItem) {
37
+ deleteNftByAddress(addresses) {
38
+ return this.table.where('address').anyOfIgnoreCase(addresses).delete();
39
+ }
40
+ deleteNftItem(chain, addresses, nftItem) {
38
41
  return this.table.where('address').anyOfIgnoreCase(addresses).filter(storedItem => storedItem.chain === chain && storedItem.collectionId === nftItem.collectionId && storedItem.id === nftItem.id).delete();
39
42
  }
40
43
  deleteNftsByCollection(chain, collectionId) {
@@ -29,13 +29,16 @@ export default class TransactionStore extends BaseStoreWithAddressAndChain {
29
29
  }
30
30
  async bulkUpsert(records) {
31
31
  await this.table.bulkPut(records);
32
- await Promise.all(records.map(record => {
33
- return this.table.where({
34
- chain: record.chain,
35
- address: record.address,
36
- extrinsicHash: record.extrinsicHash
37
- }).filter(item => item.origin === 'app' && record.origin !== 'app').delete();
38
- }));
32
+
33
+ // await Promise.all(records.map((record) => {
34
+ // return this.table.where({
35
+ // chain: record.chain,
36
+ // address: record.address,
37
+ // extrinsicHash: record.extrinsicHash
38
+ // }).filter((item) => (item.origin === 'app' && record.origin !== 'app'))
39
+ // .delete();
40
+ // }));
41
+
39
42
  return true;
40
43
  }
41
44
  }
@@ -0,0 +1,20 @@
1
+ import { IMultiChainBalance } from '@subwallet/extension-base/services/subscan-service/types';
2
+ export declare class SubscanService {
3
+ private limitRate;
4
+ private intervalCheck;
5
+ private maxRetry;
6
+ private requestMap;
7
+ private nextId;
8
+ private isRunning;
9
+ private getId;
10
+ constructor(options?: {
11
+ limitRate?: number;
12
+ intervalCheck?: number;
13
+ maxRetry?: number;
14
+ });
15
+ private getApiUrl;
16
+ private postRequest;
17
+ private addRequest;
18
+ private process;
19
+ getMultiChainBalance(address: string): Promise<IMultiChainBalance[]>;
20
+ }
@@ -0,0 +1,99 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { SWError } from '@subwallet/extension-base/background/errors/SWError';
5
+ import SUBSCAN_CHAIN_MAP from '@subwallet/extension-base/services/subscan-service/subscan-chain-map';
6
+ import fetch from 'cross-fetch';
7
+ export class SubscanService {
8
+ limitRate = 2; // limit per interval check
9
+ intervalCheck = 1000; // interval check in ms
10
+ maxRetry = 9; // interval check in ms
11
+ requestMap = {};
12
+ nextId = 0;
13
+ isRunning = false;
14
+ getId() {
15
+ return this.nextId++;
16
+ }
17
+ constructor(options) {
18
+ this.limitRate = (options === null || options === void 0 ? void 0 : options.limitRate) || this.limitRate;
19
+ this.intervalCheck = (options === null || options === void 0 ? void 0 : options.intervalCheck) || this.intervalCheck;
20
+ this.maxRetry = (options === null || options === void 0 ? void 0 : options.maxRetry) || this.maxRetry;
21
+ }
22
+ getApiUrl(chain, path) {
23
+ const subscanChain = SUBSCAN_CHAIN_MAP[chain];
24
+ if (!subscanChain) {
25
+ throw new SWError('NOT_SUPPORTED', 'Chain is not supported');
26
+ }
27
+ return `https://${chain}.api.subscan.io/${path}`;
28
+ }
29
+ postRequest(url, body) {
30
+ return fetch(url, {
31
+ method: 'POST',
32
+ headers: {
33
+ 'Content-Type': 'application/json'
34
+ },
35
+ body: JSON.stringify(body)
36
+ });
37
+ }
38
+ addRequest(run) {
39
+ const newId = this.getId();
40
+ return new Promise((resolve, reject) => {
41
+ this.requestMap[newId] = {
42
+ id: newId,
43
+ status: 'pending',
44
+ retry: -1,
45
+ run,
46
+ resolve,
47
+ reject
48
+ };
49
+ if (!this.isRunning) {
50
+ this.process();
51
+ }
52
+ });
53
+ }
54
+ process() {
55
+ this.isRunning = true;
56
+ const maxRetry = this.maxRetry;
57
+ const interval = setInterval(() => {
58
+ const remainingRequests = Object.values(this.requestMap);
59
+ if (remainingRequests.length === 0) {
60
+ this.isRunning = false;
61
+ clearInterval(interval);
62
+ return;
63
+ }
64
+
65
+ // Get first this.limit requests base on id
66
+ const requests = remainingRequests.filter(request => request.status !== 'running').sort((a, b) => a.id - b.id).slice(0, this.limitRate);
67
+
68
+ // Start requests
69
+ requests.forEach(request => {
70
+ request.status = 'running';
71
+ request.run().then(rs => {
72
+ request.resolve(rs);
73
+ }).catch(e => {
74
+ if (request.retry < maxRetry) {
75
+ request.status = 'pending';
76
+ request.retry++;
77
+ } else {
78
+ // Reject request
79
+ request.reject(new SWError('MAX_RETRY', String(e)));
80
+ }
81
+ });
82
+ });
83
+ }, this.intervalCheck);
84
+ }
85
+
86
+ // Implement Subscan API
87
+ getMultiChainBalance(address) {
88
+ return this.addRequest(async () => {
89
+ const rs = await this.postRequest(this.getApiUrl('polkadot', 'api/scan/multiChain/account'), {
90
+ address
91
+ });
92
+ if (rs.status !== 200) {
93
+ throw new SWError('SubscanService.getMultiChainBalance', await rs.text());
94
+ }
95
+ const jsonData = await rs.json();
96
+ return jsonData.data;
97
+ });
98
+ }
99
+ }
@@ -0,0 +1,5 @@
1
+ declare const SUBSCAN_CHAIN_MAP: Record<string, string>;
2
+ export declare const SUBSCAN_CHAIN_MAP_REVERSE: {
3
+ [k: string]: string;
4
+ };
5
+ export default SUBSCAN_CHAIN_MAP;
@@ -0,0 +1,63 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ const SUBSCAN_CHAIN_MAP = {
5
+ polkadot: 'polkadot',
6
+ kusama: 'kusama',
7
+ moonbeam: 'moonbeam',
8
+ acala: 'acala',
9
+ astar: 'astar',
10
+ shiden: 'shiden',
11
+ shibuya: 'shibuya',
12
+ westend: 'westend',
13
+ moonbase: 'moonbase',
14
+ moonriver: 'moonriver',
15
+ turing: 'turing',
16
+ bifrost_testnet: 'bifrost-testnet',
17
+ calamari: 'calamari',
18
+ statemint: 'statemint',
19
+ pioneer: 'pioneer',
20
+ parallel: 'parallel',
21
+ clover: 'clover',
22
+ hydradx_main: 'hydradx',
23
+ edgeware: 'edgeware',
24
+ centrifuge: 'centrifuge',
25
+ interlay: 'interlay',
26
+ nodle: 'nodle',
27
+ darwinia: 'darwinia',
28
+ polkadex: 'polkadex',
29
+ aleph: 'alephzero',
30
+ dolphin: 'dolphin',
31
+ efinity: 'efinity',
32
+ composableFinance: 'composable',
33
+ phala: 'phala',
34
+ crust: 'crust',
35
+ statemine: 'statemine',
36
+ karura: 'karura',
37
+ khala: 'khala',
38
+ kilt: 'spiritnet',
39
+ basilisk: 'basilisk',
40
+ altair: 'altair',
41
+ heiko: 'parallel-heiko',
42
+ kintsugi: 'kintsugi',
43
+ picasso: 'picasso',
44
+ quartz: 'quartz',
45
+ unique_network: 'unique',
46
+ genshiro: 'genshiro',
47
+ zeitgeist: 'zeitgeist',
48
+ sakura: 'sakura',
49
+ shadow: 'shadow',
50
+ robonomics: 'robonomics',
51
+ integritee: 'integritee',
52
+ acala_testnet: 'acala-testnet',
53
+ mangatax: 'mangatax',
54
+ encointer: 'encointer',
55
+ subspace_gemini_2a: 'subspace',
56
+ origintrail: 'origintrail',
57
+ bajun: 'bajun',
58
+ snow: 'snow',
59
+ kilt_peregrine: 'kilt-testnet',
60
+ polymesh: 'polymesh'
61
+ };
62
+ export const SUBSCAN_CHAIN_MAP_REVERSE = Object.fromEntries(Object.entries(SUBSCAN_CHAIN_MAP).map(([k, v]) => [v, k]));
63
+ export default SUBSCAN_CHAIN_MAP;
@@ -0,0 +1,27 @@
1
+ export interface SubscanRequest<T> {
2
+ id: number;
3
+ retry: number;
4
+ status: 'pending' | 'running';
5
+ run: () => Promise<any>;
6
+ resolve: (value: any) => T;
7
+ reject: (error?: any) => void;
8
+ }
9
+ export interface SubscanResponse<T = any> {
10
+ code: number;
11
+ message: string;
12
+ data: T;
13
+ }
14
+ export interface IMultiChainBalance {
15
+ network: string;
16
+ symbol: string;
17
+ decimal: number;
18
+ price: string;
19
+ category: string;
20
+ balance: string;
21
+ locked: string;
22
+ reserved: string;
23
+ bonded: string;
24
+ unbonding: string;
25
+ democracy_lock: string;
26
+ election_lock: string;
27
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
2
  import { TransactionHistoryItem } from '@subwallet/extension-base/background/KoniTypes';
3
3
  import { EventRecord } from '@polkadot/types/interfaces';
4
- export declare function parseXcmEventLogs(historyItem: TransactionHistoryItem, eventLogs: EventRecord[], chain: string, sendingTokenInfo: _ChainAsset, chainInfo: _ChainInfo): void;
5
- export declare function parseTransferEventLogs(historyItem: TransactionHistoryItem, eventLogs: EventRecord[], chain: string, sendingTokenInfo: _ChainAsset, chainInfo: _ChainInfo): void;
4
+ export declare function parseXcmEventLogs(historyItem: Partial<TransactionHistoryItem>, eventLogs: EventRecord[], chain: string, sendingTokenInfo: _ChainAsset, chainInfo: _ChainInfo): void;
5
+ export declare function parseTransferEventLogs(historyItem: Partial<TransactionHistoryItem>, eventLogs: EventRecord[], chain: string, sendingTokenInfo: _ChainAsset, chainInfo: _ChainInfo): void;
@@ -1,6 +1,7 @@
1
1
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
2
2
  import { BalanceService } from '@subwallet/extension-base/services/balance-service';
3
3
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
4
+ import { EventService } from '@subwallet/extension-base/services/event-service';
4
5
  import { HistoryService } from '@subwallet/extension-base/services/history-service';
5
6
  import NotificationService from '@subwallet/extension-base/services/notification-service/NotificationService';
6
7
  import RequestService from '@subwallet/extension-base/services/request-service';
@@ -11,6 +12,7 @@ import { TransactionConfig } from 'web3-core';
11
12
  import { HexString } from '@polkadot/util/types';
12
13
  export default class TransactionService {
13
14
  private readonly chainService;
15
+ private readonly eventService;
14
16
  private readonly databaseService;
15
17
  private readonly requestService;
16
18
  private readonly balanceService;
@@ -18,7 +20,7 @@ export default class TransactionService {
18
20
  private readonly notificationService;
19
21
  private readonly transactionSubject;
20
22
  private get transactions();
21
- constructor(chainService: ChainService, requestService: RequestService, balanceService: BalanceService, historyService: HistoryService, notificationService: NotificationService, databaseService: DatabaseService);
23
+ constructor(chainService: ChainService, eventService: EventService, requestService: RequestService, balanceService: BalanceService, historyService: HistoryService, notificationService: NotificationService, databaseService: DatabaseService);
22
24
  private get allTransactions();
23
25
  private get processingTransactions();
24
26
  getTransaction(id: string): SWTransaction;
@@ -33,7 +35,7 @@ export default class TransactionService {
33
35
  private removeTransaction;
34
36
  private updateTransaction;
35
37
  private getTransactionLink;
36
- private transactionToHistory;
38
+ private transactionToHistories;
37
39
  private onHasTransactionHash;
38
40
  private handlePostProcessing;
39
41
  private onSuccess;
@@ -24,8 +24,9 @@ export default class TransactionService {
24
24
  get transactions() {
25
25
  return this.transactionSubject.getValue();
26
26
  }
27
- constructor(chainService, requestService, balanceService, historyService, notificationService, databaseService) {
27
+ constructor(chainService, eventService, requestService, balanceService, historyService, notificationService, databaseService) {
28
28
  this.chainService = chainService;
29
+ this.eventService = eventService;
29
30
  this.requestService = requestService;
30
31
  this.balanceService = balanceService;
31
32
  this.historyService = historyService;
@@ -265,9 +266,10 @@ export default class TransactionService {
265
266
  const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
266
267
  return getTransactionLink(chainInfo, transaction.extrinsicHash);
267
268
  }
268
- transactionToHistory(id, eventLogs) {
269
+ transactionToHistories(id, eventLogs) {
269
270
  const transaction = this.getTransaction(id);
270
271
  const historyItem = {
272
+ origin: 'app',
271
273
  chain: transaction.chain,
272
274
  direction: TransactionDirection.SEND,
273
275
  type: transaction.extrinsicType,
@@ -280,8 +282,8 @@ export default class TransactionService {
280
282
  time: transaction.createdAt.getTime(),
281
283
  fee: transaction.estimateFee,
282
284
  blockNumber: 0,
283
- // TODO: to be added later
284
- blockHash: '' // TODO: to be added later
285
+ // Will be added in next step
286
+ blockHash: '' // Will be added in next step
285
287
  };
286
288
 
287
289
  const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
@@ -330,6 +332,12 @@ export default class TransactionService {
330
332
  decimals: sendingTokenInfo.decimals || 0,
331
333
  symbol: sendingTokenInfo.symbol
332
334
  };
335
+
336
+ // @ts-ignore
337
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
338
+ historyItem.additionalInfo = {
339
+ destinationChain: (inputData === null || inputData === void 0 ? void 0 : inputData.destinationNetworkKey) || ''
340
+ };
333
341
  eventLogs && parseXcmEventLogs(historyItem, eventLogs, transaction.chain, sendingTokenInfo, chainInfo);
334
342
  }
335
343
  break;
@@ -396,15 +404,41 @@ export default class TransactionService {
396
404
  {
397
405
  const data = parseTransactionData(transaction.data);
398
406
  historyItem.to = data.validatorAddress || '';
407
+ historyItem.amount = {
408
+ ...baseNativeAmount,
409
+ value: data.unstakingInfo.claimable || '0'
410
+ };
411
+ break;
412
+ }
413
+ case ExtrinsicType.STAKING_CANCEL_UNSTAKE:
414
+ {
415
+ const data = parseTransactionData(transaction.data);
416
+ historyItem.amount = {
417
+ ...baseNativeAmount,
418
+ value: data.selectedUnstaking.claimable || '0'
419
+ };
420
+ break;
399
421
  }
400
- break;
401
422
  case ExtrinsicType.EVM_EXECUTE:
402
423
  // Todo: Update historyItem.to
403
424
  break;
404
425
  case ExtrinsicType.UNKNOWN:
405
426
  break;
406
427
  }
407
- return historyItem;
428
+ try {
429
+ // Return one more history record if transaction send to account in the wallets
430
+ const toAccount = (historyItem === null || historyItem === void 0 ? void 0 : historyItem.to) && keyring.getAccount(historyItem.to);
431
+ if (toAccount) {
432
+ return [historyItem, {
433
+ ...historyItem,
434
+ address: historyItem.to,
435
+ direction: TransactionDirection.RECEIVED
436
+ }];
437
+ }
438
+ } catch (e) {
439
+ console.warn(e);
440
+ }
441
+ return [historyItem];
408
442
  }
409
443
  onHasTransactionHash({
410
444
  eventLogs,
@@ -416,7 +450,7 @@ export default class TransactionService {
416
450
  extrinsicHash,
417
451
  status: ExtrinsicStatus.PROCESSING
418
452
  });
419
- this.historyService.insertHistory(this.transactionToHistory(id, eventLogs)).catch(console.error);
453
+ this.historyService.insertHistories(this.transactionToHistories(id, eventLogs)).catch(console.error);
420
454
  console.log(`Transaction "${id}" is submitted with hash ${extrinsicHash || ''}`);
421
455
  }
422
456
  handlePostProcessing(id) {
@@ -448,7 +482,7 @@ export default class TransactionService {
448
482
  console.log('Transaction completed', id, transaction.extrinsicHash);
449
483
 
450
484
  // Write success transaction history
451
- this.historyService.updateHistory(transaction.chain, transaction.extrinsicHash, {
485
+ this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
452
486
  status: ExtrinsicStatus.SUCCESS,
453
487
  blockNumber: blockNumber || 0,
454
488
  blockHash: blockHash || ''
@@ -462,6 +496,7 @@ export default class TransactionService {
462
496
  },
463
497
  notifyViaBrowser: true
464
498
  });
499
+ this.eventService.emit('transaction.done', transaction);
465
500
  }
466
501
  onFailed({
467
502
  blockHash,
@@ -478,7 +513,7 @@ export default class TransactionService {
478
513
  console.log('Transaction failed', id, transaction.extrinsicHash);
479
514
 
480
515
  // Write failed transaction history
481
- this.historyService.updateHistory(transaction.chain, transaction.extrinsicHash, {
516
+ this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
482
517
  status: ExtrinsicStatus.FAIL,
483
518
  blockNumber: blockNumber || 0,
484
519
  blockHash: blockHash || ''
@@ -493,7 +528,7 @@ export default class TransactionService {
493
528
  notifyViaBrowser: true
494
529
  });
495
530
  }
496
-
531
+ this.eventService.emit('transaction.failed', transaction);
497
532
  // Log transaction errors
498
533
  console.error(errors);
499
534
  }
@@ -1,22 +1,21 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { _getBlockExplorerFromChain, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
5
+
4
6
  // @ts-ignore
5
7
  export function parseTransactionData(data) {
6
- // @ts-ignore
7
8
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
8
9
  return data;
9
10
  }
10
11
  export function getTransactionLink(chainInfo, extrinsicHash) {
11
- if (chainInfo.evmInfo) {
12
- var _chainInfo$evmInfo;
13
- const explorerLink = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.blockExplorer;
12
+ const explorerLink = _getBlockExplorerFromChain(chainInfo);
13
+ if (_isPureEvmChain(chainInfo)) {
14
14
  if (explorerLink) {
15
15
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}tx/${extrinsicHash}`;
16
16
  }
17
17
  } else {
18
- var _chainInfo$substrateI;
19
- const explorerLink = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI = chainInfo.substrateInfo) === null || _chainInfo$substrateI === void 0 ? void 0 : _chainInfo$substrateI.blockExplorer;
18
+ const explorerLink = _getBlockExplorerFromChain(chainInfo);
20
19
  if (explorerLink) {
21
20
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${extrinsicHash}`;
22
21
  }
@@ -1 +1,2 @@
1
1
  export declare const simpleAddress: (address: string) => string;
2
+ export declare function quickFormatAddressToCompare(address?: string): string | undefined;
package/utils/address.js CHANGED
@@ -1,10 +1,17 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { decodeAddress, encodeAddress, isEthereumAddress } from '@polkadot/util-crypto';
4
+ import { reformatAddress } from '@subwallet/extension-base/utils/index';
5
+ import { decodeAddress, encodeAddress, isAddress, isEthereumAddress } from '@polkadot/util-crypto';
5
6
  export const simpleAddress = address => {
6
7
  if (isEthereumAddress(address)) {
7
8
  return address;
8
9
  }
9
10
  return encodeAddress(decodeAddress(address));
10
- };
11
+ };
12
+ export function quickFormatAddressToCompare(address) {
13
+ if (!isAddress(address)) {
14
+ return address;
15
+ }
16
+ return reformatAddress(address, 42).toLowerCase();
17
+ }
package/utils/index.d.ts CHANGED
@@ -36,3 +36,4 @@ export declare const filterAndSortingAccountByAuthType: (accounts: AccountJson[]
36
36
  export declare function parseRawNumber(value: string): number;
37
37
  export declare function parseNumberToDisplay(amount: BN, decimals: number | undefined): string;
38
38
  export declare function isSameAddress(address1: string, address2: string): boolean;
39
+ export declare function getDomainFromUrl(url: string): string;
package/utils/index.js CHANGED
@@ -15,20 +15,25 @@ export function isAccountAll(address) {
15
15
  return address === ALL_ACCOUNT_KEY;
16
16
  }
17
17
  export function reformatAddress(address, networkPrefix, isEthereum = false) {
18
- if (isEthereumAddress(address)) {
19
- return address;
20
- }
21
- if (isAccountAll(address)) {
22
- return address;
23
- }
24
- const publicKey = decodeAddress(address);
25
- if (isEthereum) {
26
- return ethereumEncode(publicKey);
27
- }
28
- if (networkPrefix < 0) {
18
+ try {
19
+ if (isEthereumAddress(address)) {
20
+ return address;
21
+ }
22
+ if (isAccountAll(address)) {
23
+ return address;
24
+ }
25
+ const publicKey = decodeAddress(address);
26
+ if (isEthereum) {
27
+ return ethereumEncode(publicKey);
28
+ }
29
+ if (networkPrefix < 0) {
30
+ return address;
31
+ }
32
+ return encodeAddress(publicKey, networkPrefix);
33
+ } catch (e) {
34
+ console.warn('Get error while reformat address', address, e);
29
35
  return address;
30
36
  }
31
- return encodeAddress(publicKey, networkPrefix);
32
37
  }
33
38
  export function filterAddressByNetworkKey(addresses, networkKey, isEthereum) {
34
39
  if (isEthereum) {
@@ -272,4 +277,8 @@ export function parseNumberToDisplay(amount, decimals) {
272
277
  }
273
278
  export function isSameAddress(address1, address2) {
274
279
  return reformatAddress(address1, 0) === reformatAddress(address2, 0); // TODO: maybe there's a better way
280
+ }
281
+
282
+ export function getDomainFromUrl(url) {
283
+ return url.replace(/^(https?:\/\/)?(www\.)?/, '').split('/')[0];
275
284
  }
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.EvmRpcError = void 0;
7
- var _ethereum = require("@subwallet/extension-base/constants/ethereum");
8
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
9
- // SPDX-License-Identifier: Apache-2.0
10
-
11
- class EvmRpcError extends Error {
12
- constructor(type, message, data) {
13
- const [code, prefix] = _ethereum.EVM_PROVIDER_RPC_ERRORS_MAP[type];
14
- const finalMessage = message ? `${prefix}: ${message}` : prefix;
15
- super(finalMessage);
16
- this.code = code;
17
- this.message = finalMessage;
18
- this.data = data;
19
- }
20
- }
21
- exports.EvmRpcError = EvmRpcError;
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SubWalletProviderError = void 0;
7
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
8
- // SPDX-License-Identifier: Apache-2.0
9
-
10
- class SubWalletProviderError extends Error {
11
- constructor(message, code, data) {
12
- super(message);
13
- this.code = code;
14
- this.data = data;
15
- }
16
- }
17
- exports.SubWalletProviderError = SubWalletProviderError;