@subwallet/extension-base 1.1.53-beta.0 → 1.1.55-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/background/KoniTypes.d.ts +12 -0
  2. package/background/types.d.ts +2 -0
  3. package/cjs/koni/background/handlers/Extension.js +129 -102
  4. package/cjs/koni/background/handlers/State.js +3 -20
  5. package/cjs/packageInfo.js +1 -1
  6. package/cjs/services/chain-service/index.js +5 -9
  7. package/cjs/services/chain-service/utils/index.js +8 -2
  8. package/cjs/services/chain-service/utils/patch.js +1 -1
  9. package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +4 -17
  10. package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +4 -17
  11. package/cjs/services/migration-service/scripts/index.js +3 -3
  12. package/cjs/services/swap-service/handler/base-handler.js +20 -2
  13. package/cjs/services/swap-service/handler/hydradx-handler.js +106 -19
  14. package/cjs/services/swap-service/index.js +1 -0
  15. package/koni/background/handlers/Extension.d.ts +1 -0
  16. package/koni/background/handlers/Extension.js +26 -0
  17. package/koni/background/handlers/State.js +4 -21
  18. package/package.json +10 -10
  19. package/packageInfo.js +1 -1
  20. package/services/chain-service/index.d.ts +1 -1
  21. package/services/chain-service/index.js +6 -10
  22. package/services/chain-service/utils/index.d.ts +1 -0
  23. package/services/chain-service/utils/index.js +4 -0
  24. package/services/chain-service/utils/patch.js +1 -1
  25. package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +4 -17
  26. package/services/migration-service/scripts/databases/MigrateAssetSetting.js +4 -17
  27. package/services/migration-service/scripts/index.js +3 -3
  28. package/services/swap-service/handler/base-handler.js +20 -2
  29. package/services/swap-service/handler/hydradx-handler.d.ts +2 -2
  30. package/services/swap-service/handler/hydradx-handler.js +106 -19
  31. package/services/swap-service/index.js +1 -0
  32. package/types/swap/index.d.ts +2 -0
  33. package/cjs/koni/api/dotsama/balance.js +0 -464
  34. package/cjs/koni/api/nft/ordinal_nft/utils.js +0 -41
  35. package/cjs/services/balance-service/helpers/subscribe/balance.js +0 -140
  36. package/cjs/services/chain-service/utils.js +0 -506
  37. package/cjs/services/migration-service/scripts/MigrateEthProvider.js +0 -17
  38. package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +0 -17
  39. package/cjs/services/migration-service/scripts/MigrateProvider.js +0 -29
  40. package/cjs/services/storage-service/index.js +0 -241
  41. package/cjs/types/balance.js +0 -1
  42. package/cjs/types.js +0 -1
  43. package/cjs/utils/address.js +0 -34
  44. package/cjs/utils/keyring.js +0 -57
@@ -1,241 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.DatabaseService = void 0;
8
- var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
9
- var _databases = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/databases"));
10
- var _dbStores = require("@subwallet/extension-base/services/storage-service/db-stores");
11
- var _ChainStakingMetadata = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/ChainStakingMetadata"));
12
- var _NominatorMetadata = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/NominatorMetadata"));
13
- var _utils = require("@subwallet/extension-base/utils");
14
- var _util = require("@polkadot/util");
15
- // Copyright 2019-2022 @subwallet/extension-base authors & contributors
16
- // SPDX-License-Identifier: Apache-2.0
17
-
18
- class DatabaseService {
19
- // TODO: might remove this
20
-
21
- constructor(eventService) {
22
- this.eventService = eventService;
23
- this.logger = (0, _util.logger)('DB-Service');
24
- this._db = new _databases.default();
25
- this._db.on('ready', () => {
26
- this.eventService.emit('database.ready', true);
27
- });
28
- this.stores = {
29
- price: new _dbStores.PriceStore(this._db.price),
30
- balance: new _dbStores.BalanceStore(this._db.balances),
31
- nft: new _dbStores.NftStore(this._db.nfts),
32
- nftCollection: new _dbStores.NftCollectionStore(this._db.nftCollections),
33
- crowdloan: new _dbStores.CrowdloanStore(this._db.crowdloans),
34
- staking: new _dbStores.StakingStore(this._db.stakings),
35
- transaction: new _dbStores.TransactionStore(this._db.transactions),
36
- migration: new _dbStores.MigrationStore(this._db.migrations),
37
- metadata: new _dbStores.MetadataStore(this._db.metadata),
38
- chain: new _dbStores.ChainStore(this._db.chain),
39
- asset: new _dbStores.AssetStore(this._db.asset),
40
- // staking
41
- chainStakingMetadata: new _ChainStakingMetadata.default(this._db.chainStakingMetadata),
42
- nominatorMetadata: new _NominatorMetadata.default(this._db.nominatorMetadata)
43
- };
44
- }
45
- async updatePriceStore(priceData) {
46
- await this.stores.price.table.put(priceData);
47
- }
48
- async getPriceStore() {
49
- try {
50
- const rs = await this.stores.price.table.get('usd');
51
- return rs;
52
- } catch (e) {
53
- this.logger.error(e);
54
- return undefined;
55
- }
56
- }
57
-
58
- // Balance
59
- async getStoredBalance() {
60
- return this.stores.balance.table.toArray();
61
- }
62
- async updateBalanceStore(address, item) {
63
- if (item.state === _KoniTypes.APIItemState.READY) {
64
- return this.stores.balance.upsert({
65
- address,
66
- ...item
67
- });
68
- }
69
- }
70
- async removeFromBalanceStore(assets) {
71
- return this.stores.balance.removeBySlugs(assets);
72
- }
73
-
74
- // Crowdloan
75
- async updateCrowdloanStore(chain, address, item) {
76
- if (item.state === _KoniTypes.APIItemState.READY && item.contribute !== '0') {
77
- return this.stores.crowdloan.upsert({
78
- chain,
79
- address,
80
- ...item
81
- });
82
- } else {
83
- return this.stores.crowdloan.deleteByChainAndAddress(chain, address);
84
- }
85
- }
86
-
87
- // Staking
88
- async updateStaking(chain, address, item) {
89
- if (item.state === _KoniTypes.APIItemState.READY) {
90
- return this.stores.staking.upsert(item);
91
- }
92
- }
93
- async getStakings(addresses, chains) {
94
- return this.stores.staking.getStakings(addresses, chains);
95
- }
96
- async getStakingsByChains(chains) {
97
- return this.stores.staking.getStakingsByChains(chains);
98
- }
99
- async getPooledStakings(addresses, chainHashes) {
100
- return this.stores.staking.getPooledStakings(addresses, chainHashes);
101
- }
102
- subscribeStaking(addresses, chainList, callback) {
103
- this.stakingSubscription && this.stakingSubscription.unsubscribe();
104
- this.stakingSubscription = this.stores.staking.subscribeStaking(addresses, chainList).subscribe({
105
- next: stakings => callback && callback(stakings)
106
- });
107
- return this.stakingSubscription;
108
- }
109
- subscribeChainStakingMetadata(chains, callback) {
110
- this.stores.chainStakingMetadata.subscribeByChain(chains).subscribe({
111
- next: data => callback && callback(data)
112
- });
113
- }
114
- subscribeNominatorMetadata(addresses, callback) {
115
- return this.stores.nominatorMetadata.subscribeByAddresses(addresses).subscribe({
116
- next: data => callback && callback(data)
117
- });
118
- }
119
-
120
- // Transaction histories
121
- async getHistories(query) {
122
- return this.stores.transaction.queryHistory(query);
123
- }
124
- async upsertHistory(histories) {
125
- const cleanedHistory = histories.filter(x => x && x.address && x.chain && x.extrinsicHash);
126
- return this.stores.transaction.bulkUpsert(cleanedHistory);
127
- }
128
- async updateHistoryByExtrinsicHash(extrinsicHash, updateData) {
129
- const canUpdate = updateData && extrinsicHash;
130
- if (!canUpdate) {
131
- return;
132
- }
133
- return this.stores.transaction.updateWithQuery({
134
- extrinsicHash
135
- }, updateData);
136
- }
137
-
138
- // NFT Collection
139
- async addNftCollection(collection) {
140
- return this.stores.nftCollection.upsert(collection);
141
- }
142
- async deleteNftCollection(chain, collectionId) {
143
- await this.stores.nftCollection.removeCollection(chain, collectionId);
144
- await this.stores.nft.deleteNftsByCollection(chain, collectionId);
145
- }
146
- getAllNftCollection(chainHashes) {
147
- return this.stores.nftCollection.getNftCollection(chainHashes);
148
- }
149
-
150
- // NFT
151
- subscribeNft(addresses, chainHashes, callback) {
152
- this.nftSubscription && this.nftSubscription.unsubscribe();
153
- this.nftSubscription = this.stores.nft.subscribeNft(addresses, chainHashes).subscribe({
154
- next: nfts => callback && callback(nfts)
155
- });
156
- return this.nftSubscription;
157
- }
158
- async cleanUpNft(chain, owner, collectionIds, nftIds, ownNothing) {
159
- if (ownNothing) {
160
- return this.stores.nft.deleteNftsByChainAndOwner(chain, (0, _utils.reformatAddress)(owner, 42), collectionIds);
161
- }
162
- return this.stores.nft.cleanUpNfts(chain, (0, _utils.reformatAddress)(owner, 42), collectionIds, nftIds);
163
- }
164
- async getNft(addresses, chainHashes) {
165
- return this.stores.nft.getNft(addresses, chainHashes);
166
- }
167
- async addNft(address, nft) {
168
- return this.stores.nft.upsert({
169
- ...nft,
170
- address
171
- });
172
- }
173
- handleNftTransfer(chain, addresses, nftItem) {
174
- return this.stores.nft.deleteNftItem(chain, addresses, nftItem);
175
- }
176
- removeNfts(chain, address, collectionId, nftIds) {
177
- return this.stores.nft.removeNfts(chain, address, collectionId, nftIds);
178
- }
179
-
180
- // Chain
181
- async updateChainStore(item) {
182
- return this.stores.chain.upsert(item);
183
- }
184
- async bulkUpdateChainStore(data) {
185
- return this.stores.chain.bulkUpsert(data);
186
- }
187
- async removeFromChainStore(chains) {
188
- return this.stores.chain.removeChains(chains);
189
- }
190
- async getAllChainStore() {
191
- return this.stores.chain.getAll();
192
- }
193
-
194
- // Asset
195
- async updateAssetStore(item) {
196
- return this.stores.asset.upsert(item);
197
- }
198
- async getAllAssetStore() {
199
- return this.stores.asset.getAll();
200
- }
201
- async removeFromAssetStore(items) {
202
- return this.stores.asset.removeAssets(items);
203
- }
204
-
205
- // Staking
206
- async updateChainStakingMetadata(item, changes) {
207
- const existingRecord = await this.stores.chainStakingMetadata.getByChainAndType(item.chain, item.type);
208
- if (existingRecord && changes) {
209
- return this.stores.chainStakingMetadata.updateByChainAndType(item.chain, item.type, changes);
210
- }
211
- return this.stores.chainStakingMetadata.upsert(item);
212
- }
213
- async getChainStakingMetadata() {
214
- return this.stores.chainStakingMetadata.getAll();
215
- }
216
- async getStakingMetadataByChain(chain) {
217
- let type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _KoniTypes.StakingType.NOMINATED;
218
- return this.stores.chainStakingMetadata.getByChainAndType(chain, type);
219
- }
220
- async updateNominatorMetadata(item) {
221
- return this.stores.nominatorMetadata.upsert(item);
222
- }
223
- async getNominatorMetadata() {
224
- return this.stores.nominatorMetadata.getAll();
225
- }
226
- async resetWallet(resetAll) {
227
- return new Promise((resolve, reject) => {
228
- const stores = [this.stores.balance, this.stores.nft, this.stores.nftCollection, this.stores.crowdloan, this.stores.staking, this.stores.transaction, this.stores.nominatorMetadata];
229
- if (resetAll) {
230
- stores.push(this.stores.chain, this.stores.asset);
231
- }
232
- const promises = stores.map(store => store.clear());
233
- Promise.all(promises).then(() => {
234
- resolve();
235
- }).catch(e => {
236
- reject(e);
237
- });
238
- });
239
- }
240
- }
241
- exports.DatabaseService = DatabaseService;
@@ -1 +0,0 @@
1
- "use strict";
package/cjs/types.js DELETED
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.convertSubjectInfoToAddresses = void 0;
7
- exports.quickFormatAddressToCompare = quickFormatAddressToCompare;
8
- exports.simpleAddress = void 0;
9
- var _index = require("@subwallet/extension-base/utils/index");
10
- var _utilCrypto = require("@polkadot/util-crypto");
11
- // Copyright 2019-2022 @subwallet/extension-base authors & contributors
12
- // SPDX-License-Identifier: Apache-2.0
13
-
14
- const simpleAddress = address => {
15
- if ((0, _utilCrypto.isEthereumAddress)(address)) {
16
- return address;
17
- }
18
- return (0, _utilCrypto.encodeAddress)((0, _utilCrypto.decodeAddress)(address));
19
- };
20
- exports.simpleAddress = simpleAddress;
21
- function quickFormatAddressToCompare(address) {
22
- if (!(0, _utilCrypto.isAddress)(address)) {
23
- return address;
24
- }
25
- return (0, _index.reformatAddress)(address, 42).toLowerCase();
26
- }
27
- const convertSubjectInfoToAddresses = subjectInfo => {
28
- return Object.values(subjectInfo).map(info => ({
29
- address: info.json.address,
30
- type: info.type,
31
- ...info.json.meta
32
- }));
33
- };
34
- exports.convertSubjectInfoToAddresses = convertSubjectInfoToAddresses;
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.extractPrivateKey = extractPrivateKey;
7
- exports.unlockAccount = exports.lockAccount = void 0;
8
- var _uiKeyring = require("@subwallet/ui-keyring");
9
- // Copyright 2019-2022 @subwallet/extension-base
10
- // SPDX-License-Identifier: Apache-2.0
11
-
12
- // import _decode from '@polkadot/keyring/pair/decode';
13
-
14
- function extract(address) {
15
- // @ts-ignore
16
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
17
- const rs = this.getPair(address);
18
-
19
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
20
- console.log(rs.publicKey);
21
- }
22
- function extractPrivateKey(keyring, address, password) {
23
- extract.call(keyring, address);
24
- }
25
- const unlockAccount = signAddress => {
26
- let publicKey;
27
- try {
28
- publicKey = _uiKeyring.keyring.decodeAddress(signAddress);
29
- } catch (error) {
30
- console.error(error);
31
- return 'Unable to decode address';
32
- }
33
- const pair = _uiKeyring.keyring.getPair(publicKey);
34
- if (!pair) {
35
- return 'Unable to find pair';
36
- }
37
- if (pair.isLocked) {
38
- try {
39
- _uiKeyring.keyring.unlockPair(pair.address);
40
- } catch (e) {
41
- return e.message;
42
- }
43
- }
44
- return null;
45
- };
46
- exports.unlockAccount = unlockAccount;
47
- const lockAccount = address => {
48
- try {
49
- const pair = _uiKeyring.keyring.getPair(address);
50
- if (pair) {
51
- pair.lock();
52
- }
53
- } catch (error) {
54
- console.error('Unable to lock account', error);
55
- }
56
- };
57
- exports.lockAccount = lockAccount;