@subwallet/extension-base 1.1.39-0 → 1.1.39-beta.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.
- package/background/KoniTypes.d.ts +1 -0
- package/cjs/koni/api/dotsama/balance.js +464 -0
- package/cjs/koni/background/handlers/Extension.js +16 -1
- package/cjs/services/chain-service/index.js +61 -51
- package/cjs/services/migration-service/scripts/MigrateEthProvider.js +17 -0
- package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +17 -0
- package/cjs/services/migration-service/scripts/MigrateProvider.js +29 -0
- package/cjs/services/storage-service/index.js +241 -0
- package/cjs/types.js +1 -0
- package/cjs/utils/address.js +34 -0
- package/cjs/utils/keyring.js +57 -0
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +16 -1
- package/package.json +2 -2
- package/services/chain-service/index.d.ts +7 -3
- package/services/chain-service/index.js +52 -43
- package/services/chain-service/types.d.ts +4 -0
|
@@ -38,6 +38,7 @@ class ChainService {
|
|
|
38
38
|
// TODO: consider BehaviorSubject
|
|
39
39
|
chainInfoMapSubject = new _rxjs.Subject();
|
|
40
40
|
chainStateMapSubject = new _rxjs.Subject();
|
|
41
|
+
chainStatusMapSubject = new _rxjs.BehaviorSubject({});
|
|
41
42
|
assetRegistrySubject = new _rxjs.Subject();
|
|
42
43
|
multiChainAssetMapSubject = new _rxjs.Subject();
|
|
43
44
|
xcmRefMapSubject = new _rxjs.Subject();
|
|
@@ -111,6 +112,9 @@ class ChainService {
|
|
|
111
112
|
subscribeChainStateMap() {
|
|
112
113
|
return this.chainStateMapSubject;
|
|
113
114
|
}
|
|
115
|
+
subscribeChainStatusMap() {
|
|
116
|
+
return this.chainStatusMapSubject;
|
|
117
|
+
}
|
|
114
118
|
getAssetRegistry() {
|
|
115
119
|
return this.dataMap.assetRegistry;
|
|
116
120
|
}
|
|
@@ -188,6 +192,12 @@ class ChainService {
|
|
|
188
192
|
getChainStateByKey(key) {
|
|
189
193
|
return this.dataMap.chainStateMap[key];
|
|
190
194
|
}
|
|
195
|
+
getChainStatusMap() {
|
|
196
|
+
return this.chainStatusMapSubject.getValue();
|
|
197
|
+
}
|
|
198
|
+
getChainStatusByKey(key) {
|
|
199
|
+
return this.getChainStatusMap()[key];
|
|
200
|
+
}
|
|
191
201
|
getActiveChains() {
|
|
192
202
|
return Object.entries(this.dataMap.chainStateMap).filter(_ref => {
|
|
193
203
|
let [, chainState] = _ref;
|
|
@@ -353,9 +363,32 @@ class ChainService {
|
|
|
353
363
|
this.lockChainInfoMap = false;
|
|
354
364
|
return true;
|
|
355
365
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
366
|
+
connectionStatusQueueMap = {};
|
|
367
|
+
updateChainConnectionStatus(slug, connectionStatus) {
|
|
368
|
+
this.connectionStatusQueueMap[slug] = connectionStatus;
|
|
369
|
+
(0, _utils2.addLazy)('updateChainConnectionStatus', () => {
|
|
370
|
+
const chainStatusMap = this.getChainStatusMap();
|
|
371
|
+
let update = false;
|
|
372
|
+
Object.entries(this.connectionStatusQueueMap).forEach(_ref3 => {
|
|
373
|
+
let [slug, status] = _ref3;
|
|
374
|
+
if (chainStatusMap[slug]) {
|
|
375
|
+
if (chainStatusMap[slug].connectionStatus !== status) {
|
|
376
|
+
chainStatusMap[slug].connectionStatus = status;
|
|
377
|
+
chainStatusMap[slug].lastUpdated = Date.now();
|
|
378
|
+
update = true;
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
chainStatusMap[slug] = {
|
|
382
|
+
slug,
|
|
383
|
+
connectionStatus: status,
|
|
384
|
+
lastUpdated: Date.now()
|
|
385
|
+
};
|
|
386
|
+
update = true;
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
this.connectionStatusQueueMap = {};
|
|
390
|
+
update && this.chainStatusMapSubject.next(chainStatusMap);
|
|
391
|
+
});
|
|
359
392
|
}
|
|
360
393
|
upsertCustomToken(token) {
|
|
361
394
|
if (token.slug.length === 0) {
|
|
@@ -484,8 +517,8 @@ class ChainService {
|
|
|
484
517
|
this.logger.log('Finished updating latest asset ref');
|
|
485
518
|
}
|
|
486
519
|
handleLatestPriceId(latestPriceIds) {
|
|
487
|
-
Object.entries(latestPriceIds).forEach(
|
|
488
|
-
let [slug, priceId] =
|
|
520
|
+
Object.entries(latestPriceIds).forEach(_ref4 => {
|
|
521
|
+
let [slug, priceId] = _ref4;
|
|
489
522
|
if (this.dataMap.assetRegistry[slug]) {
|
|
490
523
|
this.dataMap.assetRegistry[slug].priceId = priceId;
|
|
491
524
|
}
|
|
@@ -510,12 +543,12 @@ class ChainService {
|
|
|
510
543
|
async initApis() {
|
|
511
544
|
const chainInfoMap = this.getChainInfoMap();
|
|
512
545
|
const chainStateMap = this.getChainStateMap();
|
|
513
|
-
await Promise.all(Object.entries(chainInfoMap).filter(
|
|
546
|
+
await Promise.all(Object.entries(chainInfoMap).filter(_ref5 => {
|
|
514
547
|
var _chainStateMap$slug;
|
|
515
|
-
let [slug] =
|
|
548
|
+
let [slug] = _ref5;
|
|
516
549
|
return (_chainStateMap$slug = chainStateMap[slug]) === null || _chainStateMap$slug === void 0 ? void 0 : _chainStateMap$slug.active;
|
|
517
|
-
}).map(
|
|
518
|
-
let [, chainInfo] =
|
|
550
|
+
}).map(_ref6 => {
|
|
551
|
+
let [, chainInfo] = _ref6;
|
|
519
552
|
try {
|
|
520
553
|
return this.initApiForChain(chainInfo);
|
|
521
554
|
} catch (e) {
|
|
@@ -530,13 +563,8 @@ class ChainService {
|
|
|
530
563
|
providerName
|
|
531
564
|
} = this.getChainCurrentProviderByKey(chainInfo.slug);
|
|
532
565
|
const onUpdateStatus = status => {
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
// Avoid unnecessary update in case disable chain
|
|
536
|
-
if (currentStatus !== status) {
|
|
537
|
-
this.setChainConnectionStatus(chainInfo.slug, status);
|
|
538
|
-
this.updateChainStateMapSubscription();
|
|
539
|
-
}
|
|
566
|
+
const slug = chainInfo.slug;
|
|
567
|
+
this.updateChainConnectionStatus(slug, status);
|
|
540
568
|
};
|
|
541
569
|
if (chainInfo.substrateInfo !== null && chainInfo.substrateInfo !== undefined) {
|
|
542
570
|
if (_constants._MANTA_ZK_CHAIN_GROUP.includes(chainInfo.slug) && _utils2.MODULE_SUPPORT.MANTA_ZK && this.mantaChainHandler) {
|
|
@@ -635,7 +663,7 @@ class ChainService {
|
|
|
635
663
|
this.lockChainInfoMap = true;
|
|
636
664
|
chainStateMap[chainSlug].active = false;
|
|
637
665
|
// Set disconnect state for inactive chain
|
|
638
|
-
|
|
666
|
+
this.updateChainConnectionStatus(chainSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
639
667
|
this.destroyApiForChain(chainInfo);
|
|
640
668
|
this.dbService.updateChainStore({
|
|
641
669
|
...chainInfo,
|
|
@@ -728,9 +756,9 @@ class ChainService {
|
|
|
728
756
|
this.dataMap.chainStateMap[chainInfo.slug] = {
|
|
729
757
|
currentProvider: providerKey,
|
|
730
758
|
slug: chainInfo.slug,
|
|
731
|
-
connectionStatus: _types3._ChainConnectionStatus.DISCONNECTED,
|
|
732
759
|
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug)
|
|
733
760
|
};
|
|
761
|
+
this.updateChainConnectionStatus(chainInfo.slug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
734
762
|
|
|
735
763
|
// create data for storage
|
|
736
764
|
newStorageData.push({
|
|
@@ -781,9 +809,9 @@ class ChainService {
|
|
|
781
809
|
this.dataMap.chainStateMap[storedSlug] = {
|
|
782
810
|
currentProvider: selectedProvider,
|
|
783
811
|
slug: storedSlug,
|
|
784
|
-
connectionStatus: _types3._ChainConnectionStatus.DISCONNECTED,
|
|
785
812
|
active: canActive && storedChainInfo.active
|
|
786
813
|
};
|
|
814
|
+
this.updateChainConnectionStatus(storedSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
787
815
|
newStorageData.push({
|
|
788
816
|
...mergedChainInfoMap[storedSlug],
|
|
789
817
|
active: canActive && storedChainInfo.active,
|
|
@@ -803,9 +831,9 @@ class ChainService {
|
|
|
803
831
|
this.dataMap.chainStateMap[duplicatedDefaultSlug] = {
|
|
804
832
|
currentProvider: storedChainInfo.currentProvider,
|
|
805
833
|
slug: duplicatedDefaultSlug,
|
|
806
|
-
connectionStatus: _types3._ChainConnectionStatus.DISCONNECTED,
|
|
807
834
|
active: storedChainInfo.active
|
|
808
835
|
};
|
|
836
|
+
this.updateChainConnectionStatus(duplicatedDefaultSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
809
837
|
newStorageData.push({
|
|
810
838
|
...mergedChainInfoMap[duplicatedDefaultSlug],
|
|
811
839
|
active: storedChainInfo.active,
|
|
@@ -830,9 +858,9 @@ class ChainService {
|
|
|
830
858
|
currentProvider: storedChainInfo.currentProvider,
|
|
831
859
|
// TODO: review
|
|
832
860
|
slug: storedSlug,
|
|
833
|
-
connectionStatus: _types3._ChainConnectionStatus.DISCONNECTED,
|
|
834
861
|
active: storedChainInfo.active
|
|
835
862
|
};
|
|
863
|
+
this.updateChainConnectionStatus(storedSlug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
836
864
|
newStorageData.push({
|
|
837
865
|
...mergedChainInfoMap[storedSlug],
|
|
838
866
|
active: storedChainInfo.active,
|
|
@@ -845,15 +873,15 @@ class ChainService {
|
|
|
845
873
|
}
|
|
846
874
|
|
|
847
875
|
// Fill in the missing chainState and storageData (new chains never before seen)
|
|
848
|
-
Object.entries(mergedChainInfoMap).forEach(
|
|
849
|
-
let [slug, chainInfo] =
|
|
876
|
+
Object.entries(mergedChainInfoMap).forEach(_ref7 => {
|
|
877
|
+
let [slug, chainInfo] = _ref7;
|
|
850
878
|
if (!(slug in this.dataMap.chainStateMap)) {
|
|
851
879
|
this.dataMap.chainStateMap[slug] = {
|
|
852
880
|
currentProvider: Object.keys(chainInfo.providers)[0],
|
|
853
881
|
slug,
|
|
854
|
-
connectionStatus: _types3._ChainConnectionStatus.DISCONNECTED,
|
|
855
882
|
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(slug)
|
|
856
883
|
};
|
|
884
|
+
this.updateChainConnectionStatus(slug, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
857
885
|
newStorageData.push({
|
|
858
886
|
...mergedChainInfoMap[slug],
|
|
859
887
|
active: _constants._DEFAULT_ACTIVE_CHAINS.includes(slug),
|
|
@@ -928,9 +956,7 @@ class ChainService {
|
|
|
928
956
|
}
|
|
929
957
|
}
|
|
930
958
|
updateChainStateMapSubscription() {
|
|
931
|
-
(
|
|
932
|
-
this.chainStateMapSubject.next(this.getChainStateMap());
|
|
933
|
-
}, 300, 900);
|
|
959
|
+
this.chainStateMapSubject.next(this.getChainStateMap());
|
|
934
960
|
}
|
|
935
961
|
updateChainInfoMapSubscription() {
|
|
936
962
|
this.chainInfoMapSubject.next(this.getChainInfoMap());
|
|
@@ -1039,10 +1065,17 @@ class ChainService {
|
|
|
1039
1065
|
const chainStateMap = this.getChainStateMap();
|
|
1040
1066
|
chainStateMap[newChainSlug] = {
|
|
1041
1067
|
active: true,
|
|
1042
|
-
connectionStatus: _types3._ChainConnectionStatus.DISCONNECTED,
|
|
1043
1068
|
currentProvider: params.chainEditInfo.currentProvider,
|
|
1044
1069
|
slug: newChainSlug
|
|
1045
1070
|
};
|
|
1071
|
+
|
|
1072
|
+
// const chainStatusMap = this.getChainStatusMap();
|
|
1073
|
+
// const chainStatusMap[newChainSlug] = {
|
|
1074
|
+
// slug: newChainSlug,
|
|
1075
|
+
// connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
1076
|
+
// lastUpdated: Date.now()
|
|
1077
|
+
// };
|
|
1078
|
+
|
|
1046
1079
|
await this.initApiForChain(chainInfo);
|
|
1047
1080
|
|
|
1048
1081
|
// create a record in assetRegistry for native token and update store/subscription
|
|
@@ -1327,29 +1360,6 @@ class ChainService {
|
|
|
1327
1360
|
await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp()]);
|
|
1328
1361
|
this.checkLatestData();
|
|
1329
1362
|
}
|
|
1330
|
-
checkAndUpdateStatusMapForChain(chainSlug) {
|
|
1331
|
-
const substrateApiMap = this.getSubstrateApiMap();
|
|
1332
|
-
const evmApiMap = this.getEvmApiMap();
|
|
1333
|
-
const chainState = this.getChainStateByKey(chainSlug);
|
|
1334
|
-
let update = false;
|
|
1335
|
-
function updateState(current, status) {
|
|
1336
|
-
if (current.connectionStatus !== status) {
|
|
1337
|
-
current.connectionStatus = status;
|
|
1338
|
-
update = true;
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
if (chainState.active) {
|
|
1342
|
-
const api = substrateApiMap[chainSlug] || evmApiMap[chainSlug];
|
|
1343
|
-
if (api) {
|
|
1344
|
-
updateState(chainState, api.isApiConnected ? _types3._ChainConnectionStatus.CONNECTED : _types3._ChainConnectionStatus.DISCONNECTED);
|
|
1345
|
-
}
|
|
1346
|
-
} else {
|
|
1347
|
-
updateState(chainState, _types3._ChainConnectionStatus.DISCONNECTED);
|
|
1348
|
-
}
|
|
1349
|
-
if (update) {
|
|
1350
|
-
this.dataMap.chainStateMap[chainSlug] = chainState;
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
1363
|
async initAssetSettings() {
|
|
1354
1364
|
const assetSettings = await this.getAssetSettings();
|
|
1355
1365
|
const activeChainSlugs = this.getActiveChainSlugs();
|
|
@@ -0,0 +1,17 @@
|
|
|
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 _MigrateProvider = _interopRequireDefault(require("./MigrateProvider"));
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
class MigrateEthProvider extends _MigrateProvider.default {
|
|
13
|
+
newProvider = 'ethereum';
|
|
14
|
+
oldProvider = 'Cloudflare';
|
|
15
|
+
slug = 'Llamarpc';
|
|
16
|
+
}
|
|
17
|
+
exports.default = MigrateEthProvider;
|
|
@@ -0,0 +1,17 @@
|
|
|
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 _MigrateProvider = _interopRequireDefault(require("./MigrateProvider"));
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
class MigratePioneerProvider extends _MigrateProvider.default {
|
|
13
|
+
slug = 'pioneer';
|
|
14
|
+
oldProvider = 'OnFinality';
|
|
15
|
+
newProvider = 'Pioneer';
|
|
16
|
+
}
|
|
17
|
+
exports.default = MigratePioneerProvider;
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
class MigrateProvider extends _Base.default {
|
|
13
|
+
async run() {
|
|
14
|
+
const state = this.state;
|
|
15
|
+
const chainState = state.getChainStateByKey(this.slug);
|
|
16
|
+
const chainInfo = state.getChainInfo(this.slug);
|
|
17
|
+
if (chainState && chainState.active && chainState.currentProvider === this.oldProvider) {
|
|
18
|
+
await state.upsertChainInfo({
|
|
19
|
+
mode: 'update',
|
|
20
|
+
chainEditInfo: {
|
|
21
|
+
currentProvider: this.newProvider,
|
|
22
|
+
slug: this.slug,
|
|
23
|
+
providers: chainInfo.providers
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.default = MigrateProvider;
|
|
@@ -0,0 +1,241 @@
|
|
|
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;
|
package/cjs/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,34 @@
|
|
|
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;
|
|
@@ -0,0 +1,57 @@
|
|
|
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;
|
|
@@ -185,6 +185,7 @@ export default class KoniExtension {
|
|
|
185
185
|
private getListDeriveAccounts;
|
|
186
186
|
private subscribeChainInfoMap;
|
|
187
187
|
private subscribeChainStateMap;
|
|
188
|
+
private subscribeChainStatusMap;
|
|
188
189
|
private subscribeAssetRegistry;
|
|
189
190
|
private subscribeMultiChainAssetMap;
|
|
190
191
|
private subscribeXcmRefMap;
|
|
@@ -3169,6 +3169,19 @@ export default class KoniExtension {
|
|
|
3169
3169
|
});
|
|
3170
3170
|
return this.#koniState.getChainStateMap();
|
|
3171
3171
|
}
|
|
3172
|
+
subscribeChainStatusMap(id, port) {
|
|
3173
|
+
const cb = createSubscription(id, port);
|
|
3174
|
+
const chainStateMapSubscription = this.#koniState.chainService.subscribeChainStatusMap().subscribe({
|
|
3175
|
+
next: rs => {
|
|
3176
|
+
cb(rs);
|
|
3177
|
+
}
|
|
3178
|
+
});
|
|
3179
|
+
this.createUnsubscriptionHandle(id, chainStateMapSubscription.unsubscribe);
|
|
3180
|
+
port.onDisconnect.addListener(() => {
|
|
3181
|
+
this.cancelSubscription(id);
|
|
3182
|
+
});
|
|
3183
|
+
return this.#koniState.chainService.getChainStatusMap();
|
|
3184
|
+
}
|
|
3172
3185
|
async subscribeAssetRegistry(id, port) {
|
|
3173
3186
|
const cb = createSubscription(id, port);
|
|
3174
3187
|
let ready = false;
|
|
@@ -3458,7 +3471,7 @@ export default class KoniExtension {
|
|
|
3458
3471
|
});
|
|
3459
3472
|
const {
|
|
3460
3473
|
connectionStatus
|
|
3461
|
-
} = this.#koniState.chainService.
|
|
3474
|
+
} = this.#koniState.chainService.getChainStatusByKey(_DEFAULT_MANTA_ZK_CHAIN);
|
|
3462
3475
|
if (connectionStatus !== _ChainConnectionStatus.CONNECTED) {
|
|
3463
3476
|
// TODO: do better
|
|
3464
3477
|
await timeout();
|
|
@@ -4194,6 +4207,8 @@ export default class KoniExtension {
|
|
|
4194
4207
|
return this.subscribeChainInfoMap(id, port);
|
|
4195
4208
|
case 'pri(chainService.subscribeChainStateMap)':
|
|
4196
4209
|
return this.subscribeChainStateMap(id, port);
|
|
4210
|
+
case 'pri(chainService.subscribeChainStatusMap)':
|
|
4211
|
+
return this.subscribeChainStatusMap(id, port);
|
|
4197
4212
|
case 'pri(chainService.subscribeXcmRefMap)':
|
|
4198
4213
|
return this.subscribeXcmRefMap(id, port);
|
|
4199
4214
|
case 'pri(chainService.getSupportedContractTypes)':
|