@subwallet/extension-base 1.1.33-beta.1 → 1.1.33-beta.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.
@@ -11,7 +11,7 @@ const PREDEFINED_STAKING_POOL = {
11
11
  kusama: 80,
12
12
  polkadot: 39,
13
13
  vara_network: 29,
14
- aleph: 55
14
+ aleph: 82
15
15
  };
16
16
  exports.PREDEFINED_STAKING_POOL = PREDEFINED_STAKING_POOL;
17
17
  const MAX_NOMINATIONS = '16';
@@ -263,7 +263,7 @@ const EVM_REFORMAT_DECIMALS = {
263
263
  acala: ['acala_evm', 'karura_evm']
264
264
  };
265
265
  exports.EVM_REFORMAT_DECIMALS = EVM_REFORMAT_DECIMALS;
266
- const LATEST_CHAIN_DATA_FETCHING_INTERVAL = 30000;
266
+ const LATEST_CHAIN_DATA_FETCHING_INTERVAL = 120000;
267
267
 
268
268
  // TODO: review
269
269
  exports.LATEST_CHAIN_DATA_FETCHING_INTERVAL = LATEST_CHAIN_DATA_FETCHING_INTERVAL;
@@ -411,8 +411,10 @@ class ChainService {
411
411
 
412
412
  // TODO: reconsider the flow of initiation
413
413
  this.multiChainAssetMapSubject.next(_chainList.MultiChainAssetMap);
414
- const storedAssetRefMap = await this.dbService.getAssetRefMap();
415
- this.dataMap.assetRefMap = storedAssetRefMap && Object.values(storedAssetRefMap).length > 0 ? storedAssetRefMap : _chainList.AssetRefMap;
414
+ // const storedAssetRefMap = await this.dbService.getAssetRefMap();
415
+ //
416
+ // this.dataMap.assetRefMap = storedAssetRefMap && Object.values(storedAssetRefMap).length > 0 ? storedAssetRefMap : AssetRefMap;
417
+
416
418
  await this.initChains();
417
419
  this.chainInfoMapSubject.next(this.getChainInfoMap());
418
420
  this.updateChainStateMapSubscription();
@@ -420,12 +422,33 @@ class ChainService {
420
422
  this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
421
423
  await this.initApis();
422
424
  await this.initAssetSettings();
425
+ await this.initAssetRefMap();
423
426
  this.checkLatestData();
424
427
  }
428
+ async initAssetRefMap() {
429
+ try {
430
+ const fetchPromise = this.fetchLatestBlockedAssetRef();
431
+ const timeout = new Promise(resolve => {
432
+ const id = setTimeout(() => {
433
+ clearTimeout(id);
434
+ resolve(null);
435
+ }, 1000);
436
+ });
437
+ const disabledAssetRefs = (await Promise.race([timeout, fetchPromise])) || null;
438
+ if (disabledAssetRefs) {
439
+ this.handleLatestBlockedAssetRef(disabledAssetRefs);
440
+ } else {
441
+ this.dataMap.assetRefMap = _chainList.AssetRefMap;
442
+ }
443
+ } catch (e) {
444
+ this.dataMap.assetRefMap = _chainList.AssetRefMap;
445
+ }
446
+ }
425
447
  checkLatestData() {
426
448
  clearInterval(this.refreshLatestChainDataTimeOut);
427
449
  this.handleLatestData();
428
450
  this.handleLatestData();
451
+ this.handleLatestData();
429
452
  this.refreshLatestChainDataTimeOut = setInterval(this.handleLatestData.bind(this), _constants.LATEST_CHAIN_DATA_FETCHING_INTERVAL);
430
453
  }
431
454
  stopCheckLatestChainData() {
@@ -451,14 +474,15 @@ class ChainService {
451
474
  }
452
475
  }
453
476
  handleLatestBlockedAssetRef(latestBlockedAssetRefList) {
454
- if (latestBlockedAssetRefList.length > 0) {
455
- latestBlockedAssetRefList.forEach(blockedAssetRef => {
456
- delete this.dataMap.assetRefMap[blockedAssetRef];
457
- });
458
- } else {
459
- this.dataMap.assetRefMap = _chainList.AssetRefMap;
460
- }
461
- this.dbService.setAssetRef(this.dataMap.assetRefMap).catch(console.error);
477
+ const updatedAssetRefMap = {
478
+ ..._chainList.AssetRefMap
479
+ };
480
+ latestBlockedAssetRefList.forEach(blockedAssetRef => {
481
+ delete updatedAssetRefMap[blockedAssetRef];
482
+ });
483
+ this.dataMap.assetRefMap = updatedAssetRefMap;
484
+
485
+ // this.dbService.setAssetRef(this.dataMap.assetRefMap).catch(console.error);
462
486
  this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
463
487
  this.logger.log('Finished updating latest asset ref');
464
488
  }
@@ -8,7 +8,6 @@ exports.default = exports.DEXIE_BACKUP_TABLES = void 0;
8
8
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
9
9
  var _databases = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/databases"));
10
10
  var _dbStores = require("@subwallet/extension-base/services/storage-service/db-stores");
11
- var _AssetRef2 = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/AssetRef"));
12
11
  var _Campaign = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/Campaign"));
13
12
  var _ChainStakingMetadata = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/ChainStakingMetadata"));
14
13
  var _MantaPay = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/MantaPay"));
@@ -52,10 +51,11 @@ class DatabaseService {
52
51
  chainStakingMetadata: new _ChainStakingMetadata.default(this._db.chainStakingMetadata),
53
52
  nominatorMetadata: new _NominatorMetadata.default(this._db.nominatorMetadata),
54
53
  mantaPay: new _MantaPay.default(this._db.mantaPay),
55
- campaign: new _Campaign.default(this._db.campaign),
56
- assetRef: new _AssetRef2.default(this._db.assetRef)
54
+ campaign: new _Campaign.default(this._db.campaign)
55
+ // assetRef: new AssetRefStore(this._db.assetRef)
57
56
  };
58
57
  }
58
+
59
59
  async updatePriceStore(priceData) {
60
60
  await this.stores.price.table.put(priceData);
61
61
  }
@@ -389,31 +389,37 @@ class DatabaseService {
389
389
  async getExportJson() {
390
390
  return JSON.parse(await this.exportDB());
391
391
  }
392
- setAssetRef(assetRef) {
393
- const assetRefList = Object.entries(assetRef).map(_ref => {
394
- let [slug, item] = _ref;
395
- return {
396
- slug,
397
- ...item
398
- };
399
- });
400
- return this.stores.assetRef.bulkUpsert(assetRefList);
401
- }
402
- getAssetRef(slug) {
403
- return this.stores.assetRef.getAssetRef(slug);
404
- }
405
- async getAssetRefMap() {
406
- const assetRefList = await this.stores.assetRef.getAll();
407
- const assetRefObj = {};
408
- assetRefList.forEach(item => {
409
- assetRefObj[item.slug] = {
410
- ...item
411
- };
412
- });
413
- return assetRefObj;
414
- }
415
- subscribeAssetRef() {
416
- return this.stores.assetRef.subscribeAssetRef();
417
- }
392
+
393
+ // public setAssetRef (assetRef: Record<string, _AssetRef>) {
394
+ // const assetRefList = Object.entries(assetRef).map(([slug, item]) => {
395
+ // return {
396
+ // slug,
397
+ // ...item
398
+ // } as IAssetRef;
399
+ // });
400
+ //
401
+ // return this.stores.assetRef.bulkUpsert(assetRefList);
402
+ // }
403
+ //
404
+ // public getAssetRef (slug: string) {
405
+ // return this.stores.assetRef.getAssetRef(slug);
406
+ // }
407
+ //
408
+ // public async getAssetRefMap (): Promise<Record<string, _AssetRef>> {
409
+ // const assetRefList = await this.stores.assetRef.getAll();
410
+ // const assetRefObj: Record<string, _AssetRef> = {};
411
+ //
412
+ // assetRefList.forEach((item) => {
413
+ // assetRefObj[item.slug] = {
414
+ // ...item
415
+ // };
416
+ // });
417
+ //
418
+ // return assetRefObj;
419
+ // }
420
+ //
421
+ // public subscribeAssetRef () {
422
+ // return this.stores.assetRef.subscribeAssetRef();
423
+ // }
418
424
  }
419
425
  exports.default = DatabaseService;
@@ -46,9 +46,6 @@ class KoniDatabase extends _dexie.default {
46
46
  this.conditionalVersion(5, {
47
47
  campaign: 'slug'
48
48
  });
49
- this.conditionalVersion(5, {
50
- assetRef: 'slug'
51
- });
52
49
  }
53
50
  conditionalVersion(version, schema, upgrade) {
54
51
  if (this.schemaVersion != null && this.schemaVersion < version) {
@@ -5,6 +5,6 @@ export const PREDEFINED_STAKING_POOL = {
5
5
  kusama: 80,
6
6
  polkadot: 39,
7
7
  vara_network: 29,
8
- aleph: 55
8
+ aleph: 82
9
9
  };
10
10
  export const MAX_NOMINATIONS = '16';
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.1.33-beta.1",
20
+ "version": "1.1.33-beta.2",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -84,7 +84,7 @@ export declare const EVM_PASS_CONNECT_STATUS: Record<string, string[]>;
84
84
  export declare const EVM_REFORMAT_DECIMALS: {
85
85
  acala: string[];
86
86
  };
87
- export declare const LATEST_CHAIN_DATA_FETCHING_INTERVAL = 30000;
87
+ export declare const LATEST_CHAIN_DATA_FETCHING_INTERVAL = 120000;
88
88
  export declare const _CHAIN_INFO_SRC: string;
89
89
  export declare const _CHAIN_ASSET_SRC: string;
90
90
  export declare const _ASSET_REF_SRC: string;
@@ -238,7 +238,7 @@ export const EVM_PASS_CONNECT_STATUS = {
238
238
  export const EVM_REFORMAT_DECIMALS = {
239
239
  acala: ['acala_evm', 'karura_evm']
240
240
  };
241
- export const LATEST_CHAIN_DATA_FETCHING_INTERVAL = 30000;
241
+ export const LATEST_CHAIN_DATA_FETCHING_INTERVAL = 120000;
242
242
 
243
243
  // TODO: review
244
244
  const TARGET_BRANCH = process.env.NODE_ENV !== 'production' ? 'koni-dev' : 'master';
@@ -71,6 +71,7 @@ export declare class ChainService {
71
71
  deleteAssetsByChain(chainSlug: string): void;
72
72
  deleteCustomAssets(targetAssets: string[]): void;
73
73
  init(): Promise<void>;
74
+ initAssetRefMap(): Promise<void>;
74
75
  checkLatestData(): void;
75
76
  stopCheckLatestChainData(): void;
76
77
  handleLatestProviderData(latestChainInfo: _ChainInfo[]): void;
@@ -397,8 +397,10 @@ export class ChainService {
397
397
 
398
398
  // TODO: reconsider the flow of initiation
399
399
  this.multiChainAssetMapSubject.next(MultiChainAssetMap);
400
- const storedAssetRefMap = await this.dbService.getAssetRefMap();
401
- this.dataMap.assetRefMap = storedAssetRefMap && Object.values(storedAssetRefMap).length > 0 ? storedAssetRefMap : AssetRefMap;
400
+ // const storedAssetRefMap = await this.dbService.getAssetRefMap();
401
+ //
402
+ // this.dataMap.assetRefMap = storedAssetRefMap && Object.values(storedAssetRefMap).length > 0 ? storedAssetRefMap : AssetRefMap;
403
+
402
404
  await this.initChains();
403
405
  this.chainInfoMapSubject.next(this.getChainInfoMap());
404
406
  this.updateChainStateMapSubscription();
@@ -406,12 +408,33 @@ export class ChainService {
406
408
  this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
407
409
  await this.initApis();
408
410
  await this.initAssetSettings();
411
+ await this.initAssetRefMap();
409
412
  this.checkLatestData();
410
413
  }
414
+ async initAssetRefMap() {
415
+ try {
416
+ const fetchPromise = this.fetchLatestBlockedAssetRef();
417
+ const timeout = new Promise(resolve => {
418
+ const id = setTimeout(() => {
419
+ clearTimeout(id);
420
+ resolve(null);
421
+ }, 1000);
422
+ });
423
+ const disabledAssetRefs = (await Promise.race([timeout, fetchPromise])) || null;
424
+ if (disabledAssetRefs) {
425
+ this.handleLatestBlockedAssetRef(disabledAssetRefs);
426
+ } else {
427
+ this.dataMap.assetRefMap = AssetRefMap;
428
+ }
429
+ } catch (e) {
430
+ this.dataMap.assetRefMap = AssetRefMap;
431
+ }
432
+ }
411
433
  checkLatestData() {
412
434
  clearInterval(this.refreshLatestChainDataTimeOut);
413
435
  this.handleLatestData();
414
436
  this.handleLatestData();
437
+ this.handleLatestData();
415
438
  this.refreshLatestChainDataTimeOut = setInterval(this.handleLatestData.bind(this), LATEST_CHAIN_DATA_FETCHING_INTERVAL);
416
439
  }
417
440
  stopCheckLatestChainData() {
@@ -437,14 +460,15 @@ export class ChainService {
437
460
  }
438
461
  }
439
462
  handleLatestBlockedAssetRef(latestBlockedAssetRefList) {
440
- if (latestBlockedAssetRefList.length > 0) {
441
- latestBlockedAssetRefList.forEach(blockedAssetRef => {
442
- delete this.dataMap.assetRefMap[blockedAssetRef];
443
- });
444
- } else {
445
- this.dataMap.assetRefMap = AssetRefMap;
446
- }
447
- this.dbService.setAssetRef(this.dataMap.assetRefMap).catch(console.error);
463
+ const updatedAssetRefMap = {
464
+ ...AssetRefMap
465
+ };
466
+ latestBlockedAssetRefList.forEach(blockedAssetRef => {
467
+ delete updatedAssetRefMap[blockedAssetRef];
468
+ });
469
+ this.dataMap.assetRefMap = updatedAssetRefMap;
470
+
471
+ // this.dbService.setAssetRef(this.dataMap.assetRefMap).catch(console.error);
448
472
  this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
449
473
  this.logger.log('Finished updating latest asset ref');
450
474
  }
@@ -1,9 +1,8 @@
1
- import { _AssetRef, _ChainAsset } from '@subwallet/chain-list/types';
1
+ import { _ChainAsset } from '@subwallet/chain-list/types';
2
2
  import { ChainStakingMetadata, CrowdloanItem, MantaPayConfig, NftCollection, NftItem, NominatorMetadata, PriceJson, StakingItem, StakingType, TransactionHistoryItem } from '@subwallet/extension-base/background/KoniTypes';
3
3
  import { EventService } from '@subwallet/extension-base/services/event-service';
4
- import { IAssetRef, IBalance, ICampaign, IChain, INft } from '@subwallet/extension-base/services/storage-service/databases';
4
+ import { IBalance, ICampaign, IChain, INft } from '@subwallet/extension-base/services/storage-service/databases';
5
5
  import { AssetStore, BalanceStore, ChainStore, CrowdloanStore, MetadataStore, MigrationStore, NftCollectionStore, NftStore, PriceStore, StakingStore, TransactionStore } from '@subwallet/extension-base/services/storage-service/db-stores';
6
- import AssetRefStore from '@subwallet/extension-base/services/storage-service/db-stores/AssetRef';
7
6
  import CampaignStore from '@subwallet/extension-base/services/storage-service/db-stores/Campaign';
8
7
  import ChainStakingMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/ChainStakingMetadata';
9
8
  import MantaPayStore from '@subwallet/extension-base/services/storage-service/db-stores/MantaPay';
@@ -36,7 +35,6 @@ export default class DatabaseService {
36
35
  nominatorMetadata: NominatorMetadataStore;
37
36
  mantaPay: MantaPayStore;
38
37
  campaign: CampaignStore;
39
- assetRef: AssetRefStore;
40
38
  };
41
39
  private logger;
42
40
  private nftSubscription;
@@ -114,8 +112,4 @@ export default class DatabaseService {
114
112
  exportDB(): Promise<string>;
115
113
  importDB(data: string): Promise<boolean>;
116
114
  getExportJson(): Promise<DexieExportJsonStructure>;
117
- setAssetRef(assetRef: Record<string, _AssetRef>): Promise<unknown>;
118
- getAssetRef(slug: string): Promise<IAssetRef | undefined>;
119
- getAssetRefMap(): Promise<Record<string, _AssetRef>>;
120
- subscribeAssetRef(): import("dexie").Observable<IAssetRef[]>;
121
115
  }
@@ -4,7 +4,6 @@
4
4
  import { APIItemState, StakingType } from '@subwallet/extension-base/background/KoniTypes';
5
5
  import KoniDatabase from '@subwallet/extension-base/services/storage-service/databases';
6
6
  import { AssetStore, BalanceStore, ChainStore, CrowdloanStore, MetadataStore, MigrationStore, NftCollectionStore, NftStore, PriceStore, StakingStore, TransactionStore } from '@subwallet/extension-base/services/storage-service/db-stores';
7
- import AssetRefStore from '@subwallet/extension-base/services/storage-service/db-stores/AssetRef';
8
7
  import CampaignStore from '@subwallet/extension-base/services/storage-service/db-stores/Campaign';
9
8
  import ChainStakingMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/ChainStakingMetadata';
10
9
  import MantaPayStore from '@subwallet/extension-base/services/storage-service/db-stores/MantaPay';
@@ -44,10 +43,11 @@ export default class DatabaseService {
44
43
  chainStakingMetadata: new ChainStakingMetadataStore(this._db.chainStakingMetadata),
45
44
  nominatorMetadata: new NominatorMetadataStore(this._db.nominatorMetadata),
46
45
  mantaPay: new MantaPayStore(this._db.mantaPay),
47
- campaign: new CampaignStore(this._db.campaign),
48
- assetRef: new AssetRefStore(this._db.assetRef)
46
+ campaign: new CampaignStore(this._db.campaign)
47
+ // assetRef: new AssetRefStore(this._db.assetRef)
49
48
  };
50
49
  }
50
+
51
51
  async updatePriceStore(priceData) {
52
52
  await this.stores.price.table.put(priceData);
53
53
  }
@@ -380,29 +380,36 @@ export default class DatabaseService {
380
380
  async getExportJson() {
381
381
  return JSON.parse(await this.exportDB());
382
382
  }
383
- setAssetRef(assetRef) {
384
- const assetRefList = Object.entries(assetRef).map(([slug, item]) => {
385
- return {
386
- slug,
387
- ...item
388
- };
389
- });
390
- return this.stores.assetRef.bulkUpsert(assetRefList);
391
- }
392
- getAssetRef(slug) {
393
- return this.stores.assetRef.getAssetRef(slug);
394
- }
395
- async getAssetRefMap() {
396
- const assetRefList = await this.stores.assetRef.getAll();
397
- const assetRefObj = {};
398
- assetRefList.forEach(item => {
399
- assetRefObj[item.slug] = {
400
- ...item
401
- };
402
- });
403
- return assetRefObj;
404
- }
405
- subscribeAssetRef() {
406
- return this.stores.assetRef.subscribeAssetRef();
407
- }
383
+
384
+ // public setAssetRef (assetRef: Record<string, _AssetRef>) {
385
+ // const assetRefList = Object.entries(assetRef).map(([slug, item]) => {
386
+ // return {
387
+ // slug,
388
+ // ...item
389
+ // } as IAssetRef;
390
+ // });
391
+ //
392
+ // return this.stores.assetRef.bulkUpsert(assetRefList);
393
+ // }
394
+ //
395
+ // public getAssetRef (slug: string) {
396
+ // return this.stores.assetRef.getAssetRef(slug);
397
+ // }
398
+ //
399
+ // public async getAssetRefMap (): Promise<Record<string, _AssetRef>> {
400
+ // const assetRefList = await this.stores.assetRef.getAll();
401
+ // const assetRefObj: Record<string, _AssetRef> = {};
402
+ //
403
+ // assetRefList.forEach((item) => {
404
+ // assetRefObj[item.slug] = {
405
+ // ...item
406
+ // };
407
+ // });
408
+ //
409
+ // return assetRefObj;
410
+ // }
411
+ //
412
+ // public subscribeAssetRef () {
413
+ // return this.stores.assetRef.subscribeAssetRef();
414
+ // }
408
415
  }
@@ -52,7 +52,6 @@ export default class KoniDatabase extends Dexie {
52
52
  yieldPosition: Table<YieldPositionInfo, object>;
53
53
  mantaPay: Table<IMantaPayLedger, object>;
54
54
  campaign: Table<ICampaign, object>;
55
- assetRef: Table<IAssetRef, object>;
56
55
  private schemaVersion;
57
56
  constructor(name?: string, schemaVersion?: number);
58
57
  private conditionalVersion;
@@ -37,9 +37,6 @@ export default class KoniDatabase extends Dexie {
37
37
  this.conditionalVersion(5, {
38
38
  campaign: 'slug'
39
39
  });
40
- this.conditionalVersion(5, {
41
- assetRef: 'slug'
42
- });
43
40
  }
44
41
  conditionalVersion(version, schema, upgrade) {
45
42
  if (this.schemaVersion != null && this.schemaVersion < version) {