@subwallet/extension-base 1.0.4-1 → 1.0.5-2

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 (140) hide show
  1. package/background/KoniTypes.d.ts +14 -1
  2. package/background/KoniTypes.js +1 -0
  3. package/background/errors/TransactionError.js +4 -0
  4. package/background/handlers/State.d.ts +1 -1
  5. package/background/handlers/State.js +2 -8
  6. package/background/handlers/subscriptions.js +0 -1
  7. package/background/types.d.ts +2 -2
  8. package/cjs/background/KoniTypes.js +1 -0
  9. package/cjs/background/errors/TransactionError.js +4 -0
  10. package/cjs/background/handlers/State.js +1 -7
  11. package/cjs/background/handlers/subscriptions.js +0 -1
  12. package/cjs/constants/index.js +6 -6
  13. package/cjs/koni/api/coingecko.js +1 -4
  14. package/cjs/koni/api/dotsama/balance.js +7 -5
  15. package/cjs/koni/api/dotsama/crowdloan.js +0 -4
  16. package/cjs/koni/api/dotsama/transfer.js +0 -4
  17. package/cjs/koni/api/nft/acala_nft/index.js +1 -1
  18. package/cjs/koni/api/nft/bit.country/index.js +1 -1
  19. package/cjs/koni/api/nft/evm_nft/index.js +2 -3
  20. package/cjs/koni/api/nft/index.js +1 -2
  21. package/cjs/koni/api/nft/karura_nft/index.js +1 -1
  22. package/cjs/koni/api/nft/quartz_nft/index.js +1 -1
  23. package/cjs/koni/api/nft/rmrk_nft/index.js +2 -3
  24. package/cjs/koni/api/nft/statemine_nft/index.js +1 -1
  25. package/cjs/koni/api/nft/transfer.js +5 -5
  26. package/cjs/koni/api/nft/unique_nft/index.js +1 -1
  27. package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  28. package/cjs/koni/api/nft/wasm_nft/index.js +1 -2
  29. package/cjs/koni/api/staking/bonding/astar.js +28 -12
  30. package/cjs/koni/api/staking/bonding/utils.js +4 -0
  31. package/cjs/koni/api/staking/relayChain.js +0 -1
  32. package/cjs/koni/api/staking/subsquidStaking.js +0 -2
  33. package/cjs/koni/api/tokens/wasm/index.js +0 -1
  34. package/cjs/koni/api/tokens/wasm/utils.js +0 -1
  35. package/cjs/koni/api/xcm/index.js +0 -1
  36. package/cjs/koni/background/cron.js +0 -45
  37. package/cjs/koni/background/handlers/Extension.js +164 -134
  38. package/cjs/koni/background/handlers/State.js +18 -3
  39. package/cjs/koni/background/handlers/Tabs.js +34 -2
  40. package/cjs/koni/background/handlers/index.js +3 -2
  41. package/cjs/koni/background/subscription.js +0 -26
  42. package/cjs/packageInfo.js +1 -1
  43. package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
  44. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +2 -9
  45. package/cjs/services/chain-service/handler/light-client/index.js +9 -6
  46. package/cjs/services/chain-service/index.js +0 -2
  47. package/cjs/services/chain-service/utils.js +3 -0
  48. package/cjs/services/history-service/helpers/recoverHistoryStatus.js +227 -0
  49. package/cjs/services/history-service/index.js +68 -6
  50. package/cjs/services/history-service/subsquid-multi-chain-history.js +3 -2
  51. package/cjs/services/history-service/testChainMap.js +724 -0
  52. package/cjs/services/keyring-service/index.js +0 -2
  53. package/cjs/services/migration-service/index.js +0 -3
  54. package/cjs/services/migration-service/scripts/MigrateAutoLock.js +30 -0
  55. package/cjs/services/migration-service/scripts/MigrateChainPatrol.js +30 -0
  56. package/cjs/services/migration-service/scripts/index.js +5 -1
  57. package/cjs/services/notification-service/NotificationService.js +1 -1
  58. package/cjs/services/price-service/coingecko.js +1 -1
  59. package/cjs/services/price-service/index.js +0 -3
  60. package/cjs/services/request-service/handler/AuthRequestHandler.js +1 -1
  61. package/cjs/services/setting-service/constants.js +8 -2
  62. package/cjs/services/storage-service/DatabaseService.js +3 -45
  63. package/cjs/services/transaction-service/constants.js +11 -0
  64. package/cjs/services/transaction-service/index.js +60 -20
  65. package/cjs/services/transaction-service/utils.js +25 -14
  66. package/cjs/utils/index.js +3 -0
  67. package/constants/index.d.ts +1 -1
  68. package/constants/index.js +1 -1
  69. package/koni/api/coingecko.js +1 -4
  70. package/koni/api/dotsama/balance.js +7 -5
  71. package/koni/api/dotsama/crowdloan.js +0 -4
  72. package/koni/api/dotsama/transfer.js +0 -4
  73. package/koni/api/nft/acala_nft/index.js +1 -1
  74. package/koni/api/nft/bit.country/index.js +1 -1
  75. package/koni/api/nft/evm_nft/index.js +2 -3
  76. package/koni/api/nft/index.js +1 -2
  77. package/koni/api/nft/karura_nft/index.js +1 -1
  78. package/koni/api/nft/quartz_nft/index.js +1 -1
  79. package/koni/api/nft/rmrk_nft/index.js +2 -3
  80. package/koni/api/nft/statemine_nft/index.js +1 -1
  81. package/koni/api/nft/transfer.js +5 -5
  82. package/koni/api/nft/unique_nft/index.js +1 -1
  83. package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  84. package/koni/api/nft/wasm_nft/index.js +1 -2
  85. package/koni/api/staking/bonding/astar.d.ts +2 -1
  86. package/koni/api/staking/bonding/astar.js +27 -12
  87. package/koni/api/staking/bonding/utils.js +4 -0
  88. package/koni/api/staking/relayChain.js +0 -1
  89. package/koni/api/staking/subsquidStaking.js +0 -2
  90. package/koni/api/tokens/wasm/index.js +0 -1
  91. package/koni/api/tokens/wasm/utils.js +0 -1
  92. package/koni/api/xcm/index.js +0 -1
  93. package/koni/background/cron.js +0 -45
  94. package/koni/background/handlers/Extension.d.ts +2 -0
  95. package/koni/background/handlers/Extension.js +79 -51
  96. package/koni/background/handlers/State.d.ts +3 -1
  97. package/koni/background/handlers/State.js +18 -3
  98. package/koni/background/handlers/Tabs.d.ts +1 -0
  99. package/koni/background/handlers/Tabs.js +32 -1
  100. package/koni/background/handlers/index.js +3 -2
  101. package/koni/background/subscription.d.ts +0 -1
  102. package/koni/background/subscription.js +0 -26
  103. package/package.json +55 -34
  104. package/packageInfo.js +1 -1
  105. package/services/chain-service/handler/EvmChainHandler.js +1 -1
  106. package/services/chain-service/handler/SubstrateChainHandler.js +2 -9
  107. package/services/chain-service/handler/light-client/index.js +8 -6
  108. package/services/chain-service/helper/api-helper/spec/acala.d.ts +3 -3
  109. package/services/chain-service/index.js +0 -2
  110. package/services/chain-service/utils.js +3 -0
  111. package/services/history-service/helpers/recoverHistoryStatus.d.ts +17 -0
  112. package/services/history-service/helpers/recoverHistoryStatus.js +214 -0
  113. package/services/history-service/index.d.ts +6 -0
  114. package/services/history-service/index.js +69 -7
  115. package/services/history-service/subsquid-multi-chain-history.js +3 -2
  116. package/services/history-service/testChainMap.d.ts +3 -0
  117. package/services/history-service/testChainMap.js +716 -0
  118. package/services/keyring-service/index.js +0 -2
  119. package/services/migration-service/index.js +0 -3
  120. package/services/migration-service/scripts/MigrateAutoLock.d.ts +4 -0
  121. package/services/migration-service/scripts/MigrateAutoLock.js +22 -0
  122. package/services/migration-service/scripts/MigrateChainPatrol.d.ts +4 -0
  123. package/services/migration-service/scripts/MigrateChainPatrol.js +22 -0
  124. package/services/migration-service/scripts/index.js +5 -1
  125. package/services/notification-service/NotificationService.js +1 -1
  126. package/services/price-service/coingecko.js +1 -1
  127. package/services/price-service/index.js +0 -3
  128. package/services/request-service/handler/AuthRequestHandler.js +1 -1
  129. package/services/setting-service/constants.d.ts +4 -2
  130. package/services/setting-service/constants.js +5 -1
  131. package/services/storage-service/DatabaseService.d.ts +1 -1
  132. package/services/storage-service/DatabaseService.js +3 -45
  133. package/services/transaction-service/constants.d.ts +1 -0
  134. package/services/transaction-service/constants.js +4 -0
  135. package/services/transaction-service/index.d.ts +1 -0
  136. package/services/transaction-service/index.js +61 -21
  137. package/services/transaction-service/types.d.ts +2 -0
  138. package/services/transaction-service/utils.d.ts +1 -1
  139. package/services/transaction-service/utils.js +24 -13
  140. package/utils/index.js +3 -0
@@ -47,7 +47,6 @@ class KeyringService {
47
47
 
48
48
  // Remove account
49
49
  removedAddresses.forEach(address => {
50
- console.log('account.remove', address);
51
50
  this.eventService.emit('account.remove', address);
52
51
  });
53
52
  } else if (beforeAddresses.length < afterAddresses.length) {
@@ -55,7 +54,6 @@ class KeyringService {
55
54
 
56
55
  // Add account
57
56
  addedAddresses.forEach(address => {
58
- console.log('account.add', address);
59
57
  this.eventService.emit('account.add', address);
60
58
  });
61
59
  } else {
@@ -17,7 +17,6 @@ class MigrationService {
17
17
  this.logger = (0, _util.logger)('Migration');
18
18
  }
19
19
  async run() {
20
- this.logger.log('Migrating...');
21
20
  const keys = Object.keys(_scripts.default).sort((a, b) => a.localeCompare(b));
22
21
 
23
22
  // Await timeout 2s
@@ -32,7 +31,6 @@ class MigrationService {
32
31
  key
33
32
  }).first();
34
33
  if (!check || key.startsWith(_scripts.EVERYTIME)) {
35
- this.logger.log('Running script: ', JobClass.name);
36
34
  const job = new JobClass(this.state);
37
35
  await job.run();
38
36
  await this.state.dbService.stores.migration.table.put({
@@ -45,7 +43,6 @@ class MigrationService {
45
43
  this.logger.error('Migration error: ', _scripts.default[keys[i]].name, error);
46
44
  }
47
45
  }
48
- this.logger.log('Migration done.');
49
46
  }
50
47
  }
51
48
  exports.default = MigrationService;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _Base = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/Base"));
9
+ var _constants = require("@subwallet/extension-base/services/setting-service/constants");
10
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ class MigrateAutoLock extends _Base.default {
14
+ async run() {
15
+ try {
16
+ return new Promise(resolve => {
17
+ this.state.settingService.getSettings(currentSettings => {
18
+ this.state.settingService.setSettings({
19
+ ...currentSettings,
20
+ timeAutoLock: _constants.DEFAULT_AUTO_LOCK_TIME
21
+ });
22
+ resolve();
23
+ });
24
+ });
25
+ } catch (e) {
26
+ console.error(e);
27
+ }
28
+ }
29
+ }
30
+ exports.default = MigrateAutoLock;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _Base = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/Base"));
9
+ var _constants = require("@subwallet/extension-base/services/setting-service/constants");
10
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ class MigrateChainPatrol extends _Base.default {
14
+ async run() {
15
+ try {
16
+ return new Promise(resolve => {
17
+ this.state.settingService.getSettings(currentSettings => {
18
+ this.state.settingService.setSettings({
19
+ ...currentSettings,
20
+ enableChainPatrol: _constants.DEFAULT_CHAIN_PATROL_ENABLE
21
+ });
22
+ resolve();
23
+ });
24
+ });
25
+ } catch (e) {
26
+ console.error(e);
27
+ }
28
+ }
29
+ }
30
+ exports.default = MigrateChainPatrol;
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = exports.EVERYTIME = void 0;
8
8
  var _AutoEnableChainsTokens = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/AutoEnableChainsTokens"));
9
9
  var _MigrateAuthUrls = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/MigrateAuthUrls"));
10
+ var _MigrateAutoLock = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/MigrateAutoLock"));
11
+ var _MigrateChainPatrol = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/MigrateChainPatrol"));
10
12
  var _MigrateImportedToken = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/MigrateImportedToken"));
11
13
  var _MigrateNetworkSettings = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/MigrateNetworkSettings"));
12
14
  var _MigrateSettings = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/scripts/MigrateSettings"));
@@ -22,7 +24,9 @@ var _default = {
22
24
  '1.0.1-30': _MigrateTransactionHistory.default,
23
25
  '1.0.1-40': _AutoEnableChainsTokens.default,
24
26
  '1.0.1-50': _MigrateSettings.default,
25
- '1.0.1-60': _MigrateAuthUrls.default
27
+ '1.0.1-60': _MigrateAuthUrls.default,
28
+ '1.0.3-01': _MigrateAutoLock.default,
29
+ '1.0.3-02': _MigrateChainPatrol.default
26
30
  // [`${EVERYTIME}-1`]: AutoEnableChainsTokens
27
31
  };
28
32
  exports.default = _default;
@@ -36,7 +36,7 @@ class NotificationService {
36
36
  type: 'basic',
37
37
  title,
38
38
  message,
39
- iconUrl: 'https://subwallet.app/assets/images/favicon/favicon-192x192.png',
39
+ iconUrl: './images/icon-128.png',
40
40
  priority: 2,
41
41
  isClickable: !!link
42
42
  }, notificationId => {
@@ -45,7 +45,7 @@ const getTokenPrice = async function (priceIds) {
45
45
  price24hMap
46
46
  };
47
47
  } catch (err) {
48
- console.error('Failed to get token price', err);
48
+ console.error(err);
49
49
  throw err;
50
50
  }
51
51
  };
@@ -40,7 +40,6 @@ class PriceService {
40
40
  }
41
41
  refreshPriceData(priceIds) {
42
42
  clearTimeout(this.refreshTimeout);
43
- console.log('Refresh Price Data');
44
43
  this.priceIds = priceIds || this.getPriceIds();
45
44
 
46
45
  // Update for tokens price
@@ -79,7 +78,6 @@ class PriceService {
79
78
  }
80
79
  startPromiseHandler = (0, _promise.createPromiseHandler)();
81
80
  async start() {
82
- console.debug('Start price service');
83
81
  try {
84
82
  this.startPromiseHandler = (0, _promise.createPromiseHandler)();
85
83
  this.status = _types.ServiceStatus.STARTING;
@@ -96,7 +94,6 @@ class PriceService {
96
94
  }
97
95
  stopPromiseHandler = (0, _promise.createPromiseHandler)();
98
96
  async stop() {
99
- console.debug('Stop price service');
100
97
  try {
101
98
  this.status = _types.ServiceStatus.STOPPING;
102
99
  this.stopPromiseHandler = (0, _promise.createPromiseHandler)();
@@ -79,7 +79,7 @@ class AuthRequestHandler {
79
79
  update(this.authorizeCached);
80
80
  } else {
81
81
  this.authorizeStore.get('authUrls', data => {
82
- this.authorizeCached = data;
82
+ this.authorizeCached = data || {};
83
83
  update(this.authorizeCached);
84
84
  });
85
85
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.DEFAULT_THEME = exports.DEFAULT_SETTING = exports.DEFAULT_NOTIFICATION_TYPE = void 0;
6
+ exports.DEFAULT_THEME = exports.DEFAULT_SETTING = exports.DEFAULT_NOTIFICATION_TYPE = exports.DEFAULT_CHAIN_PATROL_ENABLE = exports.DEFAULT_AUTO_LOCK_TIME = void 0;
7
7
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
8
8
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
9
9
  // SPDX-License-Identifier: Apache-2.0
@@ -12,6 +12,10 @@ const DEFAULT_THEME = _KoniTypes.ThemeNames.DARK;
12
12
  exports.DEFAULT_THEME = DEFAULT_THEME;
13
13
  const DEFAULT_NOTIFICATION_TYPE = 'popup';
14
14
  exports.DEFAULT_NOTIFICATION_TYPE = DEFAULT_NOTIFICATION_TYPE;
15
+ const DEFAULT_AUTO_LOCK_TIME = 15;
16
+ exports.DEFAULT_AUTO_LOCK_TIME = DEFAULT_AUTO_LOCK_TIME;
17
+ const DEFAULT_CHAIN_PATROL_ENABLE = false;
18
+ exports.DEFAULT_CHAIN_PATROL_ENABLE = DEFAULT_CHAIN_PATROL_ENABLE;
15
19
  const DEFAULT_SETTING = {
16
20
  // language: 'en',
17
21
  browserConfirmationType: DEFAULT_NOTIFICATION_TYPE,
@@ -19,6 +23,8 @@ const DEFAULT_SETTING = {
19
23
  isShowBalance: false,
20
24
  accountAllLogo: '',
21
25
  theme: DEFAULT_THEME,
22
- camera: false
26
+ camera: false,
27
+ timeAutoLock: DEFAULT_AUTO_LOCK_TIME,
28
+ enableChainPatrol: DEFAULT_CHAIN_PATROL_ENABLE
23
29
  };
24
30
  exports.DEFAULT_SETTING = DEFAULT_SETTING;
@@ -45,6 +45,7 @@ class DatabaseService {
45
45
  const rs = await this.stores.price.table.get('usd');
46
46
  return rs;
47
47
  } catch (e) {
48
+ this.logger.error(e);
48
49
  return undefined;
49
50
  }
50
51
  }
@@ -55,8 +56,6 @@ class DatabaseService {
55
56
  }
56
57
  async updateBalanceStore(address, item) {
57
58
  if (item.state === _KoniTypes.APIItemState.READY) {
58
- // this.logger.log(`Updating balance for [${item.tokenSlug}]`);
59
-
60
59
  return this.stores.balance.upsert({
61
60
  address,
62
61
  ...item
@@ -64,23 +63,18 @@ class DatabaseService {
64
63
  }
65
64
  }
66
65
  async removeFromBalanceStore(assets) {
67
- this.logger.log('Bulk removing AssetStore');
68
66
  return this.stores.balance.removeBySlugs(assets);
69
67
  }
70
68
 
71
69
  // Crowdloan
72
70
  async updateCrowdloanStore(chain, address, item) {
73
71
  if (item.state === _KoniTypes.APIItemState.READY && item.contribute !== '0') {
74
- // this.logger.log(`Updating crowdloan for [${chain}]`);
75
-
76
72
  return this.stores.crowdloan.upsert({
77
73
  chain,
78
74
  address,
79
75
  ...item
80
76
  });
81
77
  } else {
82
- // this.logger.debug(`Removing crowdloan for [${chain}]`);
83
-
84
78
  return this.stores.crowdloan.deleteByChainAndAddress(chain, address);
85
79
  }
86
80
  }
@@ -88,22 +82,16 @@ class DatabaseService {
88
82
  // Staking
89
83
  async updateStaking(chain, address, item) {
90
84
  if (item.state === _KoniTypes.APIItemState.READY) {
91
- // this.logger.log(`Updating staking for [${chain}]`);
92
-
93
85
  return this.stores.staking.upsert(item);
94
86
  }
95
87
  }
96
88
  async getStakings(addresses, chains) {
97
- // this.logger.log('Get Stakings: ', stakings);
98
-
99
89
  return this.stores.staking.getStakings(addresses, chains);
100
90
  }
101
91
  async getStakingsByChains(chains) {
102
92
  return this.stores.staking.getStakingsByChains(chains);
103
93
  }
104
94
  async getPooledStakings(addresses, chainHashes) {
105
- // this.logger.log('Get Pooled Stakings: ', stakings);
106
-
107
95
  return this.stores.staking.getPooledStakings(addresses, chainHashes);
108
96
  }
109
97
  subscribeStaking(addresses, chainList, callback) {
@@ -129,12 +117,10 @@ class DatabaseService {
129
117
  return this.stores.transaction.queryHistory(query);
130
118
  }
131
119
  async upsertHistory(histories) {
132
- // this.logger.log('Updating transaction histories');
133
120
  const cleanedHistory = histories.filter(x => x && x.address && x.chain && x.extrinsicHash);
134
121
  return this.stores.transaction.bulkUpsert(cleanedHistory);
135
122
  }
136
- async updateHistoryByNewExtrinsicHash(extrinsicHash, updateData) {
137
- // this.logger.log('Updating transaction histories');
123
+ async updateHistoryByExtrinsicHash(extrinsicHash, updateData) {
138
124
  const canUpdate = updateData && extrinsicHash;
139
125
  if (!canUpdate) {
140
126
  return;
@@ -146,8 +132,6 @@ class DatabaseService {
146
132
 
147
133
  // NFT Collection
148
134
  async addNftCollection(collection) {
149
- // this.logger.log(`Updating NFT collection for [${collection.chain}]`);
150
-
151
135
  return this.stores.nftCollection.upsert(collection);
152
136
  }
153
137
  async deleteNftCollection(chain, collectionId) {
@@ -170,18 +154,12 @@ class DatabaseService {
170
154
  if (ownNothing) {
171
155
  return this.stores.nft.deleteNftsByChainAndOwner(chain, (0, _utils.reformatAddress)(owner, 42));
172
156
  }
173
- const result = await this.stores.nft.cleanUpNfts(chain, (0, _utils.reformatAddress)(owner, 42), collectionIds, nftIds);
174
- result > 0 && console.debug(`Cleaned up ${result} NFTs on chain ${chain} for owner ${(0, _utils.reformatAddress)(owner, 42)}`, collectionIds, nftIds);
175
- return result;
157
+ return this.stores.nft.cleanUpNfts(chain, (0, _utils.reformatAddress)(owner, 42), collectionIds, nftIds);
176
158
  }
177
159
  async getNft(addresses, chainHashes) {
178
- // this.logger.log('Get NFTs: ', nfts);
179
-
180
160
  return this.stores.nft.getNft(addresses, chainHashes);
181
161
  }
182
162
  async addNft(address, nft) {
183
- // this.logger.log(`Updating NFT for [${nft.chain}]`);
184
-
185
163
  return this.stores.nft.upsert({
186
164
  ...nft,
187
165
  address
@@ -191,54 +169,36 @@ class DatabaseService {
191
169
  return this.stores.nft.deleteNftItem(chain, addresses, nftItem);
192
170
  }
193
171
  removeNfts(chain, address, collectionId, nftIds) {
194
- // this.logger.log(`Remove NFTs [${nftIds.join(', ')}]`);
195
-
196
172
  return this.stores.nft.removeNfts(chain, address, collectionId, nftIds);
197
173
  }
198
174
 
199
175
  // Chain
200
176
  async updateChainStore(item) {
201
- // this.logger.log(`Updating storageInfo for chain [${item.slug}]`);
202
-
203
177
  return this.stores.chain.upsert(item);
204
178
  }
205
179
  async bulkUpdateChainStore(data) {
206
- // this.logger.log('Bulk updating ChainStore');
207
-
208
180
  return this.stores.chain.bulkUpsert(data);
209
181
  }
210
182
  async removeFromChainStore(chains) {
211
- // this.logger.log('Bulk removing ChainStore');
212
-
213
183
  return this.stores.chain.removeChains(chains);
214
184
  }
215
185
  async getAllChainStore() {
216
- // this.logger.log('Get all chains: ', allChains);
217
-
218
186
  return this.stores.chain.getAll();
219
187
  }
220
188
 
221
189
  // Asset
222
190
  async updateAssetStore(item) {
223
- // this.logger.log(`Updating storageInfo for chainAsset [${item.originChain}]`);
224
-
225
191
  return this.stores.asset.upsert(item);
226
192
  }
227
193
  async getAllAssetStore() {
228
- // this.logger.log('Get all stored assets: ', allAssets);
229
-
230
194
  return this.stores.asset.getAll();
231
195
  }
232
196
  async removeFromAssetStore(items) {
233
- // this.logger.log('Bulk removing AssetStore');
234
-
235
197
  return this.stores.asset.removeAssets(items);
236
198
  }
237
199
 
238
200
  // Staking
239
201
  async updateChainStakingMetadata(item) {
240
- // this.logger.log('Update ChainStakingMetadata: ', item.chain);
241
-
242
202
  return this.stores.chainStakingMetadata.upsert(item);
243
203
  }
244
204
  async getChainStakingMetadata() {
@@ -249,8 +209,6 @@ class DatabaseService {
249
209
  return this.stores.chainStakingMetadata.getByChainAndType(chain, type);
250
210
  }
251
211
  async updateNominatorMetadata(item) {
252
- // this.logger.log('Update NominatorMetadata: ', item.address, item.chain);
253
-
254
212
  return this.stores.nominatorMetadata.upsert(item);
255
213
  }
256
214
  async getNominatorMetadata() {
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TRANSACTION_TIMEOUT = void 0;
7
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
8
+ // SPDX-License-Identifier: Apache-2.0
9
+
10
+ const TRANSACTION_TIMEOUT = 2 * 60 * 1000;
11
+ exports.TRANSACTION_TIMEOUT = TRANSACTION_TIMEOUT;
@@ -12,6 +12,7 @@ var _TransactionWarning = require("@subwallet/extension-base/background/warnings
12
12
  var _constants = require("@subwallet/extension-base/constants");
13
13
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
14
14
  var _constants2 = require("@subwallet/extension-base/services/request-service/constants");
15
+ var _constants3 = require("@subwallet/extension-base/services/transaction-service/constants");
15
16
  var _eventParser = require("@subwallet/extension-base/services/transaction-service/event-parser");
16
17
  var _helpers = require("@subwallet/extension-base/services/transaction-service/helpers");
17
18
  var _utils2 = require("@subwallet/extension-base/services/transaction-service/utils");
@@ -276,9 +277,9 @@ class TransactionService {
276
277
  getTransactionLink(id) {
277
278
  const transaction = this.getTransaction(id);
278
279
  const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
279
- return (0, _utils2.getTransactionLink)(chainInfo, transaction.extrinsicHash);
280
+ return (0, _utils2.getExplorerLink)(chainInfo, transaction.extrinsicHash, 'tx');
280
281
  }
281
- transactionToHistories(id, eventLogs) {
282
+ transactionToHistories(id, startBlock, nonce, eventLogs) {
282
283
  const transaction = this.getTransaction(id);
283
284
  const historyItem = {
284
285
  origin: 'app',
@@ -296,9 +297,12 @@ class TransactionService {
296
297
  fee: transaction.estimateFee,
297
298
  blockNumber: 0,
298
299
  // Will be added in next step
299
- blockHash: '' // Will be added in next step
300
+ blockHash: '',
301
+ // Will be added in next step
302
+ nonce: nonce || 0,
303
+ startBlock: startBlock || 0
300
304
  };
301
-
305
+ console.log('historyItem', historyItem);
302
306
  const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
303
307
  const nativeAsset = (0, _utils._getChainNativeTokenBasicInfo)(chainInfo);
304
308
  const baseNativeAmount = {
@@ -463,11 +467,13 @@ class TransactionService {
463
467
  let {
464
468
  id
465
469
  } = _ref;
466
- console.log(`Transaction "${id}" is signed`);
470
+ console.debug(`Transaction "${id}" is signed`);
467
471
  }
468
472
  onSend(_ref2) {
469
473
  let {
470
- id
474
+ id,
475
+ nonce,
476
+ startBlock
471
477
  } = _ref2;
472
478
  // Update transaction status
473
479
  this.updateTransaction(id, {
@@ -475,24 +481,26 @@ class TransactionService {
475
481
  });
476
482
 
477
483
  // Create Input History Transaction History
478
- this.historyService.insertHistories(this.transactionToHistories(id)).catch(console.error);
479
- console.log(`Transaction "${id}" is sent`);
484
+ this.historyService.insertHistories(this.transactionToHistories(id, startBlock, nonce)).catch(console.error);
485
+ console.debug(`Transaction "${id}" is sent`);
480
486
  }
481
487
  onHasTransactionHash(_ref3) {
482
488
  let {
489
+ blockHash,
483
490
  extrinsicHash,
484
491
  id
485
492
  } = _ref3;
486
493
  // Write processing transaction history
487
494
  const updateData = {
488
495
  extrinsicHash,
489
- status: _KoniTypes.ExtrinsicStatus.PROCESSING
496
+ status: _KoniTypes.ExtrinsicStatus.PROCESSING,
497
+ blockHash: blockHash || ''
490
498
  };
491
499
  this.updateTransaction(id, updateData);
492
500
 
493
501
  // In this case transaction id is the same as extrinsic hash and will change after below update
494
502
  this.historyService.updateHistoryByExtrinsicHash(id, updateData).catch(console.error);
495
- console.log(`Transaction "${id}" is submitted with hash ${extrinsicHash || ''}`);
503
+ console.debug(`Transaction "${id}" is submitted with hash ${extrinsicHash || ''}`);
496
504
  }
497
505
  handlePostProcessing(id) {
498
506
  // must be done after success/failure to make sure the transaction is finalized
@@ -524,16 +532,18 @@ class TransactionService {
524
532
  let {
525
533
  blockHash,
526
534
  blockNumber,
535
+ extrinsicHash,
527
536
  id
528
537
  } = _ref4;
529
538
  const transaction = this.getTransaction(id);
530
539
  this.updateTransaction(id, {
531
- status: _KoniTypes.ExtrinsicStatus.SUCCESS
540
+ status: _KoniTypes.ExtrinsicStatus.SUCCESS,
541
+ extrinsicHash
532
542
  });
533
- console.log('Transaction completed', id, transaction.extrinsicHash);
534
543
 
535
544
  // Write success transaction history
536
- this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
545
+ this.historyService.updateHistoryByExtrinsicHash(transaction.extrinsicHash, {
546
+ extrinsicHash,
537
547
  status: _KoniTypes.ExtrinsicStatus.SUCCESS,
538
548
  blockNumber: blockNumber || 0,
539
549
  blockHash: blockHash || ''
@@ -554,6 +564,7 @@ class TransactionService {
554
564
  blockHash,
555
565
  blockNumber,
556
566
  errors,
567
+ extrinsicHash,
557
568
  id
558
569
  } = _ref5;
559
570
  const transaction = this.getTransaction(id);
@@ -561,12 +572,13 @@ class TransactionService {
561
572
  if (transaction) {
562
573
  this.updateTransaction(id, {
563
574
  status: nextStatus,
564
- errors
575
+ errors,
576
+ extrinsicHash
565
577
  });
566
- console.log('Transaction failed', id, transaction.extrinsicHash);
567
578
 
568
579
  // Write failed transaction history
569
- this.historyService.updateHistories(transaction.chain, transaction.extrinsicHash, {
580
+ this.historyService.updateHistoryByExtrinsicHash(transaction.extrinsicHash, {
581
+ extrinsicHash: extrinsicHash || transaction.extrinsicHash,
570
582
  status: nextStatus,
571
583
  blockNumber: blockNumber || 0,
572
584
  blockHash: blockHash || ''
@@ -582,8 +594,6 @@ class TransactionService {
582
594
  });
583
595
  }
584
596
  this.eventService.emit('transaction.failed', transaction);
585
- // Log transaction errors
586
- console.error(errors);
587
597
  }
588
598
  generateHashPayload(chain, transaction) {
589
599
  const chainInfo = this.chainService.getChainInfoByKey(chain);
@@ -668,7 +678,7 @@ class TransactionService {
668
678
  errors: [],
669
679
  warnings: []
670
680
  };
671
- this.requestService.addConfirmation(id, url || _constants2.EXTENSION_REQUEST_URL, 'evmSendTransactionRequest', payload, {}).then(_ref7 => {
681
+ this.requestService.addConfirmation(id, url || _constants2.EXTENSION_REQUEST_URL, 'evmSendTransactionRequest', payload, {}).then(async _ref7 => {
672
682
  let {
673
683
  isApproved,
674
684
  payload
@@ -694,11 +704,17 @@ class TransactionService {
694
704
  emitter.emit('signed', eventData);
695
705
 
696
706
  // Send transaction
707
+ this.handleTransactionTimeout(emitter, eventData);
708
+
709
+ // Add start info
710
+ eventData.nonce = txObject.nonce;
711
+ eventData.startBlock = await web3Api.eth.getBlockNumber();
697
712
  emitter.emit('send', eventData); // This event is needed after sending transaction with queue
698
713
  signedTransaction && web3Api.eth.sendSignedTransaction(signedTransaction).once('transactionHash', hash => {
699
714
  eventData.extrinsicHash = hash;
700
715
  emitter.emit('extrinsicHash', eventData);
701
716
  }).once('receipt', rs => {
717
+ eventData.extrinsicHash = rs.transactionHash;
702
718
  eventData.blockHash = rs.blockHash;
703
719
  eventData.blockNumber = rs.blockNumber;
704
720
  emitter.emit('success', eventData);
@@ -724,6 +740,7 @@ class TransactionService {
724
740
  signAndSendSubstrateTransaction(_ref8) {
725
741
  let {
726
742
  address,
743
+ chain,
727
744
  id,
728
745
  transaction,
729
746
  url
@@ -744,12 +761,17 @@ class TransactionService {
744
761
  };
745
762
  }
746
763
  }
747
- }).then(rs => {
764
+ }).then(async rs => {
748
765
  // Emit signed event
749
766
  emitter.emit('signed', eventData);
750
767
 
751
768
  // Send transaction
769
+ const api = this.chainService.getSubstrateApi(chain);
770
+ eventData.nonce = rs.nonce.toNumber();
771
+ eventData.startBlock = (await api.api.query.system.number()).toPrimitive();
772
+ this.handleTransactionTimeout(emitter, eventData);
752
773
  emitter.emit('send', eventData); // This event is needed after sending transaction with queue
774
+
753
775
  rs.send(txState => {
754
776
  // handle events, logs, history
755
777
  if (!txState || !txState.status) {
@@ -759,10 +781,12 @@ class TransactionService {
759
781
  eventData.eventLogs = txState.events;
760
782
  if (!eventData.extrinsicHash || eventData.extrinsicHash === '') {
761
783
  eventData.extrinsicHash = txState.txHash.toHex();
784
+ eventData.blockHash = txState.status.asInBlock.toHex();
762
785
  emitter.emit('extrinsicHash', eventData);
763
786
  }
764
787
  }
765
788
  if (txState.status.isFinalized) {
789
+ eventData.extrinsicHash = txState.txHash.toHex();
766
790
  eventData.eventLogs = txState.events;
767
791
  // TODO: push block hash and block number into eventData
768
792
  txState.events.filter(_ref9 => {
@@ -798,6 +822,22 @@ class TransactionService {
798
822
  });
799
823
  return emitter;
800
824
  }
825
+ handleTransactionTimeout(emitter, eventData) {
826
+ const timeout = setTimeout(() => {
827
+ const transaction = this.getTransaction(eventData.id);
828
+ if (transaction.status !== _KoniTypes.ExtrinsicStatus.SUCCESS && transaction.status !== _KoniTypes.ExtrinsicStatus.FAIL) {
829
+ eventData.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.TIMEOUT, 'Transaction timeout'));
830
+ emitter.emit('error', eventData);
831
+ clearTimeout(timeout);
832
+ }
833
+ }, _constants3.TRANSACTION_TIMEOUT);
834
+ emitter.once('success', () => {
835
+ clearTimeout(timeout);
836
+ });
837
+ emitter.once('error', () => {
838
+ clearTimeout(timeout);
839
+ });
840
+ }
801
841
  resetWallet() {
802
842
  this.transactionSubject.next({});
803
843
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getTransactionLink = getTransactionLink;
6
+ exports.getExplorerLink = getExplorerLink;
7
7
  exports.parseTransactionData = parseTransactionData;
8
8
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
9
9
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
@@ -14,19 +14,30 @@ function parseTransactionData(data) {
14
14
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
15
15
  return data;
16
16
  }
17
- function getTransactionLink(chainInfo, extrinsicHash) {
18
- if (extrinsicHash.startsWith('0x')) {
19
- const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
20
- if ((0, _utils._isPureEvmChain)(chainInfo)) {
21
- if (explorerLink) {
22
- return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}tx/${extrinsicHash}`;
23
- }
24
- } else {
25
- const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
26
- if (explorerLink) {
27
- return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${extrinsicHash}`;
28
- }
29
- }
17
+ function getBlockExplorerAccountRoute(explorerLink) {
18
+ if (explorerLink.includes('explorer.subspace.network')) {
19
+ return 'accounts';
20
+ }
21
+ if (explorerLink.includes('subscan.io')) {
22
+ return 'account';
23
+ }
24
+ return 'address';
25
+ }
26
+ function getBlockExplorerTxRoute(chainInfo) {
27
+ if ((0, _utils._isPureEvmChain)(chainInfo)) {
28
+ return 'tx';
29
+ }
30
+ return 'extrinsic';
31
+ }
32
+ function getExplorerLink(chainInfo, value, type) {
33
+ const explorerLink = (0, _utils._getBlockExplorerFromChain)(chainInfo);
34
+ if (explorerLink && type === 'account') {
35
+ const route = getBlockExplorerAccountRoute(explorerLink);
36
+ return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
37
+ }
38
+ if (explorerLink && value.startsWith('0x')) {
39
+ const route = getBlockExplorerTxRoute(chainInfo);
40
+ return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
30
41
  }
31
42
  return undefined;
32
43
  }
@@ -56,6 +56,9 @@ function reformatAddress(address) {
56
56
  let networkPrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 42;
57
57
  let isEthereum = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
58
58
  try {
59
+ if (!address || address === '') {
60
+ return '';
61
+ }
59
62
  if ((0, _utilCrypto.isEthereumAddress)(address)) {
60
63
  return address;
61
64
  }