@subwallet/extension-base 1.1.17-0 → 1.1.18-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 (48) hide show
  1. package/background/KoniTypes.d.ts +67 -1
  2. package/background/KoniTypes.js +5 -0
  3. package/cjs/background/KoniTypes.js +7 -1
  4. package/cjs/constants/index.js +6 -3
  5. package/cjs/koni/api/dotsama/crowdloan.js +106 -60
  6. package/cjs/koni/background/handlers/Extension.js +48 -0
  7. package/cjs/koni/background/handlers/State.js +25 -33
  8. package/cjs/koni/background/subscription.js +6 -2
  9. package/cjs/packageInfo.js +1 -1
  10. package/cjs/services/campaign-service/helpers.js +61 -0
  11. package/cjs/services/campaign-service/index.js +142 -0
  12. package/cjs/services/campaign-service/types.js +1 -0
  13. package/cjs/services/event-service/index.js +2 -0
  14. package/cjs/services/migration-service/index.js +4 -1
  15. package/cjs/services/notification-service/NotificationService.js +20 -6
  16. package/cjs/services/storage-service/DatabaseService.js +18 -1
  17. package/cjs/services/storage-service/databases/index.js +3 -0
  18. package/cjs/services/storage-service/db-stores/Campaign.js +35 -0
  19. package/constants/index.d.ts +1 -0
  20. package/constants/index.js +1 -0
  21. package/koni/api/dotsama/crowdloan.d.ts +7 -6
  22. package/koni/api/dotsama/crowdloan.js +103 -51
  23. package/koni/background/handlers/Extension.d.ts +2 -0
  24. package/koni/background/handlers/Extension.js +48 -1
  25. package/koni/background/handlers/State.d.ts +2 -0
  26. package/koni/background/handlers/State.js +4 -11
  27. package/koni/background/subscription.js +6 -2
  28. package/package.json +26 -6
  29. package/packageInfo.js +1 -1
  30. package/services/campaign-service/helpers.d.ts +3 -0
  31. package/services/campaign-service/helpers.js +54 -0
  32. package/services/campaign-service/index.d.ts +11 -0
  33. package/services/campaign-service/index.js +134 -0
  34. package/services/campaign-service/types.d.ts +34 -0
  35. package/services/campaign-service/types.js +1 -0
  36. package/services/event-service/index.d.ts +2 -0
  37. package/services/event-service/index.js +2 -0
  38. package/services/event-service/types.d.ts +2 -0
  39. package/services/migration-service/index.d.ts +3 -1
  40. package/services/migration-service/index.js +4 -1
  41. package/services/notification-service/NotificationService.d.ts +2 -2
  42. package/services/notification-service/NotificationService.js +20 -6
  43. package/services/storage-service/DatabaseService.d.ts +7 -1
  44. package/services/storage-service/DatabaseService.js +18 -1
  45. package/services/storage-service/databases/index.d.ts +3 -1
  46. package/services/storage-service/databases/index.js +3 -0
  47. package/services/storage-service/db-stores/Campaign.d.ts +9 -0
  48. package/services/storage-service/db-stores/Campaign.js +27 -0
@@ -1,5 +1,5 @@
1
1
  /// <reference types="bn.js" />
2
- import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
2
+ import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _FundStatus, _MultiChainAsset } from '@subwallet/chain-list/types';
3
3
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
4
4
  import { AuthUrls, Resolver } from '@subwallet/extension-base/background/handlers/State';
5
5
  import { AccountAuthType, AccountJson, AddressJson, AuthorizeRequest, ConfirmationRequestBase, RequestAccountList, RequestAccountSubscribe, RequestAccountUnsubscribe, RequestAuthorizeCancel, RequestAuthorizeReject, RequestAuthorizeSubscribe, RequestAuthorizeTab, RequestCurrentAccountAddress, ResponseAuthorizeList, ResponseJsonGetAccountInfo, SeedLengths } from '@subwallet/extension-base/background/types';
@@ -220,6 +220,14 @@ export interface CrowdloanItem {
220
220
  state: APIItemState;
221
221
  paraState?: CrowdloanParaState;
222
222
  contribute: string;
223
+ fundId: string;
224
+ paraId: number;
225
+ status: _FundStatus;
226
+ startTime: Date;
227
+ endTime: Date;
228
+ auctionIndex: number;
229
+ firstPeriod: number;
230
+ lastPeriod: number;
223
231
  }
224
232
  export interface CrowdloanJson {
225
233
  reset?: boolean;
@@ -1435,6 +1443,9 @@ export declare enum NotificationType {
1435
1443
  WARNING = "warning",
1436
1444
  ERROR = "error"
1437
1445
  }
1446
+ export interface NotificationButton {
1447
+ title: string;
1448
+ }
1438
1449
  export interface Notification {
1439
1450
  id: number;
1440
1451
  type: NotificationType;
@@ -1443,7 +1454,10 @@ export interface Notification {
1443
1454
  notifyViaBrowser?: boolean;
1444
1455
  action?: {
1445
1456
  url?: string;
1457
+ buttonClick?: (btnIndex: number) => void;
1458
+ click?: () => void;
1446
1459
  };
1460
+ buttons?: NotificationButton[];
1447
1461
  }
1448
1462
  export declare type NotificationParams = Omit<Notification, 'id'>;
1449
1463
  export interface CronReloadRequest {
@@ -1538,6 +1552,56 @@ export interface ResolveAddressToDomainRequest {
1538
1552
  chain: string;
1539
1553
  address: string;
1540
1554
  }
1555
+ export declare type CampaignAction = 'open_view' | 'open_url' | null;
1556
+ export interface CampaignButton {
1557
+ id: number;
1558
+ color: string;
1559
+ icon: string | null;
1560
+ name: string;
1561
+ type: CampaignAction;
1562
+ metadata: Record<string, any> | null;
1563
+ }
1564
+ export declare enum CampaignDataType {
1565
+ NOTIFICATION = "notification",
1566
+ BANNER = "banner"
1567
+ }
1568
+ export interface BaseCampaignData {
1569
+ slug: string;
1570
+ campaignId: number;
1571
+ isDone: boolean;
1572
+ type: CampaignDataType;
1573
+ data: Record<string, any>;
1574
+ buttons: CampaignButton[];
1575
+ startTime: number;
1576
+ endTime: number;
1577
+ condition: Record<string, any> | null;
1578
+ }
1579
+ export interface CampaignBanner extends BaseCampaignData {
1580
+ type: CampaignDataType.BANNER;
1581
+ data: {
1582
+ media: string;
1583
+ alt: string;
1584
+ action: CampaignAction;
1585
+ metadata: Record<string, any> | null;
1586
+ environments: string[];
1587
+ position: string[];
1588
+ };
1589
+ }
1590
+ export interface CampaignNotification extends BaseCampaignData {
1591
+ type: CampaignDataType.NOTIFICATION;
1592
+ data: {
1593
+ title: string;
1594
+ message: string;
1595
+ repeat: number;
1596
+ repeatAfter: number;
1597
+ action: CampaignAction;
1598
+ metadata: Record<string, any> | null;
1599
+ };
1600
+ }
1601
+ export declare type CampaignData = CampaignBanner | CampaignNotification;
1602
+ export interface RequestCampaignBannerComplete {
1603
+ slug: string;
1604
+ }
1541
1605
  export interface KoniRequestSignatures {
1542
1606
  'pri(staking.submitTuringCancelCompound)': [RequestTuringCancelStakeCompound, SWTransactionResponse];
1543
1607
  'pri(staking.submitTuringCompound)': [RequestTuringStakeCompound, SWTransactionResponse];
@@ -1720,6 +1784,8 @@ export interface KoniRequestSignatures {
1720
1784
  'pri(walletConnect.notSupport.approve)': [RequestApproveWalletConnectNotSupport, boolean];
1721
1785
  'pri(walletConnect.notSupport.reject)': [RequestRejectWalletConnectNotSupport, boolean];
1722
1786
  'pri(metadata.find)': [RequestFindRawMetadata, ResponseFindRawMetadata];
1787
+ 'pri(campaign.banner.subscribe)': [null, CampaignBanner[], CampaignBanner[]];
1788
+ 'pri(campaign.banner.complete)': [RequestCampaignBannerComplete, boolean];
1723
1789
  }
1724
1790
  export interface ApplicationMetadataType {
1725
1791
  version: string;
@@ -236,4 +236,9 @@ export let MantaPayEnableMessage;
236
236
  MantaPayEnableMessage["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
237
237
  MantaPayEnableMessage["SUCCESS"] = "SUCCESS";
238
238
  })(MantaPayEnableMessage || (MantaPayEnableMessage = {}));
239
+ export let CampaignDataType;
240
+ (function (CampaignDataType) {
241
+ CampaignDataType["NOTIFICATION"] = "notification";
242
+ CampaignDataType["BANNER"] = "banner";
243
+ })(CampaignDataType || (CampaignDataType = {}));
239
244
  export const MobileOS = ['iOS', 'Android'];
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.WalletUnlockType = exports.UnstakingStatus = exports.TransferTxErrorType = exports.TransactionDirection = exports.ThemeNames = exports.StakingType = exports.StakingTxErrorType = exports.StakingStatus = exports.RuntimeEnvironment = exports.RMRK_VER = exports.ProviderErrorType = exports.NotificationType = exports.NETWORK_STATUS = exports.NETWORK_ERROR = exports.MobileOS = exports.MantaPayEnableMessage = exports.ExtrinsicType = exports.ExtrinsicStatus = exports.ExternalRequestPromiseStatus = exports.EvmProviderErrorType = exports.CrowdloanParaState = exports.ContractType = exports.ChainType = exports.ChainEditStandard = exports.BasicTxWarningCode = exports.BasicTxErrorType = exports.BalanceErrorType = exports.AccountExternalErrorCode = exports.APIItemState = void 0;
6
+ exports.WalletUnlockType = exports.UnstakingStatus = exports.TransferTxErrorType = exports.TransactionDirection = exports.ThemeNames = exports.StakingType = exports.StakingTxErrorType = exports.StakingStatus = exports.RuntimeEnvironment = exports.RMRK_VER = exports.ProviderErrorType = exports.NotificationType = exports.NETWORK_STATUS = exports.NETWORK_ERROR = exports.MobileOS = exports.MantaPayEnableMessage = exports.ExtrinsicType = exports.ExtrinsicStatus = exports.ExternalRequestPromiseStatus = exports.EvmProviderErrorType = exports.CrowdloanParaState = exports.ContractType = exports.ChainType = exports.ChainEditStandard = exports.CampaignDataType = exports.BasicTxWarningCode = exports.BasicTxErrorType = exports.BalanceErrorType = exports.AccountExternalErrorCode = exports.APIItemState = void 0;
7
7
  // Copyright 2019-2022 @polkadot/extension-koni authors & contributors
8
8
  // SPDX-License-Identifier: Apache-2.0
9
9
  let RuntimeEnvironment;
@@ -256,5 +256,11 @@ exports.MantaPayEnableMessage = MantaPayEnableMessage;
256
256
  MantaPayEnableMessage["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
257
257
  MantaPayEnableMessage["SUCCESS"] = "SUCCESS";
258
258
  })(MantaPayEnableMessage || (exports.MantaPayEnableMessage = MantaPayEnableMessage = {}));
259
+ let CampaignDataType;
260
+ exports.CampaignDataType = CampaignDataType;
261
+ (function (CampaignDataType) {
262
+ CampaignDataType["NOTIFICATION"] = "notification";
263
+ CampaignDataType["BANNER"] = "banner";
264
+ })(CampaignDataType || (exports.CampaignDataType = CampaignDataType = {}));
259
265
  const MobileOS = ['iOS', 'Android'];
260
266
  exports.MobileOS = MobileOS;
@@ -25,9 +25,10 @@ var _exportNames = {
25
25
  ALL_GENESIS_HASH: true,
26
26
  IGNORE_GET_SUBSTRATE_FEATURES_LIST: true,
27
27
  IGNORE_QR_SIGNER: true,
28
- XCM_MIN_AMOUNT_RATIO: true
28
+ XCM_MIN_AMOUNT_RATIO: true,
29
+ MARKETING_CAMPAIGN_URL: true
29
30
  };
30
- exports.XCM_MIN_AMOUNT_RATIO = exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.MANTA_PAY_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.CRON_SYNC_MANTA_PAY = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
31
+ exports.XCM_MIN_AMOUNT_RATIO = exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.MARKETING_CAMPAIGN_URL = exports.MANTA_PAY_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.CRON_SYNC_MANTA_PAY = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
31
32
  var _staking = require("./staking");
32
33
  Object.keys(_staking).forEach(function (key) {
33
34
  if (key === "default" || key === "__esModule") return;
@@ -98,4 +99,6 @@ exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = IGNORE_GET_SUBSTRATE_FEATURES_LIST;
98
99
  const IGNORE_QR_SIGNER = [];
99
100
  exports.IGNORE_QR_SIGNER = IGNORE_QR_SIGNER;
100
101
  const XCM_MIN_AMOUNT_RATIO = 1.2;
101
- exports.XCM_MIN_AMOUNT_RATIO = XCM_MIN_AMOUNT_RATIO;
102
+ exports.XCM_MIN_AMOUNT_RATIO = XCM_MIN_AMOUNT_RATIO;
103
+ const MARKETING_CAMPAIGN_URL = process.env.MARKETING_CAMPAIGN_URL || '';
104
+ exports.MARKETING_CAMPAIGN_URL = MARKETING_CAMPAIGN_URL;
@@ -4,21 +4,40 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.getCrowdloanFundsStatus = getCrowdloanFundsStatus;
8
7
  exports.subscribeAcalaContributeInterval = void 0;
9
8
  exports.subscribeCrowdloan = subscribeCrowdloan;
10
9
  var _chainList = require("@subwallet/chain-list");
10
+ var _types = require("@subwallet/chain-list/types");
11
11
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
12
12
  var _constants = require("@subwallet/extension-base/constants");
13
13
  var _typeRegistry = _interopRequireDefault(require("@subwallet/extension-base/koni/api/dotsama/typeRegistry"));
14
- var _utils = require("@subwallet/extension-base/services/chain-service/utils");
15
- var _utils2 = require("@subwallet/extension-base/utils");
14
+ var _utils = require("@subwallet/extension-base/utils");
16
15
  var _axios = _interopRequireDefault(require("axios"));
17
16
  var _util = require("@polkadot/util");
18
17
  // Copyright 2019-2022 @subwallet/extension-base
19
18
  // SPDX-License-Identifier: Apache-2.0
20
19
 
21
- function getRPCCrowdloan(parentAPI, paraId, hexAddresses, paraState, callback) {
20
+ const STATUS_MAP = {
21
+ [_types._FundStatus.IN_AUCTION]: _KoniTypes.CrowdloanParaState.ONGOING,
22
+ [_types._FundStatus.WITHDRAW]: _KoniTypes.CrowdloanParaState.FAILED,
23
+ [_types._FundStatus.FAILED]: _KoniTypes.CrowdloanParaState.FAILED,
24
+ [_types._FundStatus.WON]: _KoniTypes.CrowdloanParaState.COMPLETED
25
+ };
26
+ const getOnlineFundList = (async () => {
27
+ const request = await _axios.default.get('https://static-data.subwallet.app/crowdloan-funds/list.json');
28
+ return request.data;
29
+ })();
30
+ function getRPCCrowdloan(parentAPI, fundInfo, hexAddresses, callback) {
31
+ const {
32
+ auctionIndex,
33
+ endTime,
34
+ firstPeriod,
35
+ fundId,
36
+ lastPeriod,
37
+ paraId,
38
+ startTime,
39
+ status
40
+ } = fundInfo;
22
41
  const unsubPromise = parentAPI.api.derive.crowdloan.ownContributions(paraId, hexAddresses, result => {
23
42
  let contribute = new _util.BN(0);
24
43
  Object.values(result).forEach(item => {
@@ -26,8 +45,16 @@ function getRPCCrowdloan(parentAPI, paraId, hexAddresses, paraState, callback) {
26
45
  });
27
46
  const rs = {
28
47
  state: _KoniTypes.APIItemState.READY,
29
- paraState,
30
- contribute: contribute.toString()
48
+ paraState: STATUS_MAP[fundInfo.status],
49
+ contribute: contribute.toString(),
50
+ fundId,
51
+ paraId,
52
+ status,
53
+ startTime,
54
+ endTime,
55
+ auctionIndex,
56
+ firstPeriod,
57
+ lastPeriod
31
58
  };
32
59
  callback(rs);
33
60
  });
@@ -37,7 +64,18 @@ function getRPCCrowdloan(parentAPI, paraId, hexAddresses, paraState, callback) {
37
64
  }).catch(console.error);
38
65
  };
39
66
  }
40
- const subscribeAcalaContributeInterval = (polkadotAddresses, paraState, callback) => {
67
+ const subscribeAcalaContributeInterval = (polkadotAddresses, fundInfo, callback) => {
68
+ const {
69
+ auctionIndex,
70
+ endTime,
71
+ firstPeriod,
72
+ fundId,
73
+ lastPeriod,
74
+ paraId,
75
+ startTime,
76
+ status
77
+ } = fundInfo;
78
+ const paraState = STATUS_MAP[fundInfo.status];
41
79
  const acalaContributionApi = 'https://api.polkawallet.io/acala-distribution-v2/crowdloan?account=';
42
80
  const getContributeInfo = () => {
43
81
  Promise.all(polkadotAddresses.map(polkadotAddress => {
@@ -46,14 +84,21 @@ const subscribeAcalaContributeInterval = (polkadotAddresses, paraState, callback
46
84
  let contribute = new _util.BN(0);
47
85
  resList.forEach(res => {
48
86
  var _res$data$data, _res$data$data$acala, _res$data$data$acala$;
49
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
87
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
50
88
  contribute = contribute.add(new _util.BN(((_res$data$data = res.data.data) === null || _res$data$data === void 0 ? void 0 : (_res$data$data$acala = _res$data$data.acala) === null || _res$data$data$acala === void 0 ? void 0 : (_res$data$data$acala$ = _res$data$data$acala[0]) === null || _res$data$data$acala$ === void 0 ? void 0 : _res$data$data$acala$.totalDOTLocked) || '0'));
51
89
  });
52
90
  const rs = {
53
91
  state: _KoniTypes.APIItemState.READY,
54
92
  paraState,
55
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
56
- contribute: contribute.toString()
93
+ contribute: contribute.toString(),
94
+ fundId,
95
+ paraId,
96
+ status,
97
+ startTime,
98
+ endTime,
99
+ auctionIndex,
100
+ firstPeriod,
101
+ lastPeriod
57
102
  };
58
103
  callback(rs);
59
104
  }).catch(console.error);
@@ -64,70 +109,71 @@ const subscribeAcalaContributeInterval = (polkadotAddresses, paraState, callback
64
109
  clearInterval(interval);
65
110
  };
66
111
  };
67
- exports.subscribeAcalaContributeInterval = subscribeAcalaContributeInterval;
68
- async function getCrowdloanFundsStatus(api) {
69
- const leases = await api.query.slots.leases.keys();
70
- const leasesParaIds = leases.map(_ref => {
71
- let {
72
- args: [paraId]
73
- } = _ref;
74
- return paraId.toString();
75
- });
76
- const rs = await api.query.crowdloan.funds.entries();
77
- const newRaise = await api.query.crowdloan.newRaise();
78
- const newRaiseParaIds = newRaise.toJSON().map(p => p.toString());
79
- return rs.reduce((stateMap, _ref2) => {
80
- let [{
81
- args: [paraId]
82
- }, fundData] = _ref2;
83
- const paraStr = paraId.toString();
84
112
 
85
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
86
- // const item = fundData.unwrap() as PolkadotRuntimeCommonCrowdloanFundInfo;
113
+ // export async function getCrowdloanFundsStatus (api: ApiPromise) {
114
+ // const leases = await api.query.slots.leases.keys<ParaId[]>();
115
+ // const leasesParaIds = leases.map(({ args: [paraId] }) => paraId.toString());
87
116
 
88
- if (leasesParaIds.indexOf(paraStr) > -1) {
89
- stateMap[paraStr] = _KoniTypes.CrowdloanParaState.COMPLETED;
90
- }
91
- if (newRaiseParaIds.indexOf(paraStr) > -1) {
92
- stateMap[paraStr] = _KoniTypes.CrowdloanParaState.ONGOING;
93
- }
94
- return stateMap;
95
- }, {});
96
- }
117
+ // const rs = await api.query.crowdloan.funds.entries<Option<any>, ParaId[]>();
118
+ // const newRaise = await api.query.crowdloan.newRaise<Vec<u32>>();
119
+
120
+ // const newRaiseParaIds = (newRaise.toJSON() as number[]).map((p) => p.toString());
121
+
122
+ // return rs.reduce((stateMap, [{ args: [paraId] }, fundData]) => {
123
+ // const paraStr = paraId.toString();
124
+ // // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
125
+ // // const item = fundData.unwrap() as PolkadotRuntimeCommonCrowdloanFundInfo;
126
+ // if (leasesParaIds.indexOf(paraStr) > -1) {
127
+ // stateMap[paraStr] = CrowdloanParaState.COMPLETED;
128
+ // }
129
+ // if (newRaiseParaIds.indexOf(paraStr) > -1) {
130
+ // stateMap[paraStr] = CrowdloanParaState.ONGOING;
131
+ // }
132
+ // return stateMap;
133
+ // }, {} as Record<string, CrowdloanParaState>);
134
+ // }
97
135
 
98
136
  // Get All crowdloan
137
+ exports.subscribeAcalaContributeInterval = subscribeAcalaContributeInterval;
99
138
  async function subscribeCrowdloan(addresses, substrateApiMap, callback, chainInfoMap) {
100
139
  const unsubMap = {};
140
+ const latestMap = {};
141
+ const rawFundList = await getOnlineFundList;
142
+ rawFundList.forEach(fundInfo => {
143
+ const chainSlug = fundInfo.chain;
144
+ if (!latestMap[chainSlug] || fundInfo.auctionIndex > latestMap[chainSlug].auctionIndex) {
145
+ latestMap[chainSlug] = fundInfo;
146
+ }
147
+ });
101
148
  if (Object.keys(substrateApiMap).includes(_chainList.COMMON_CHAIN_SLUGS.KUSAMA) && Object.keys(substrateApiMap).includes(_chainList.COMMON_CHAIN_SLUGS.POLKADOT)) {
149
+ const now = Date.now();
102
150
  const polkadotAPI = await substrateApiMap[_chainList.COMMON_CHAIN_SLUGS.POLKADOT].isReady;
103
- const polkadotFundsStatusMap = await getCrowdloanFundsStatus(polkadotAPI.api);
104
151
  const kusamaAPI = await substrateApiMap[_chainList.COMMON_CHAIN_SLUGS.KUSAMA].isReady;
105
- const kusamaFundsStatusMap = await getCrowdloanFundsStatus(kusamaAPI.api);
106
-
107
- // TODO: find all crowdloan valid networks: parachains, in-crowdloan, crowdloan but failed
108
-
109
- const substrateAddresses = (0, _utils2.categoryAddresses)(addresses)[0];
152
+ const substrateAddresses = (0, _utils.categoryAddresses)(addresses)[0];
110
153
  const hexAddresses = substrateAddresses.map(address => {
111
154
  return _typeRegistry.default.createType('AccountId', address).toHex();
112
155
  });
113
- Object.entries(chainInfoMap).forEach(_ref3 => {
114
- let [networkKey, chainInfo] = _ref3;
115
- if ((0, _utils._isSubstrateParaChain)(chainInfo)) {
116
- const parentChain = (0, _utils._getSubstrateRelayParent)(chainInfo);
156
+ if (addresses.length === 0) {
157
+ return;
158
+ }
159
+ Object.values(latestMap).forEach(fundInfo => {
160
+ var _chainInfoMap$chainSl;
161
+ const chainSlug = fundInfo.chain;
162
+ const endTime = new Date(fundInfo.endTime).getTime();
163
+ const parentChain = fundInfo.relayChain;
164
+ const substrateInfo = (_chainInfoMap$chainSl = chainInfoMap[chainSlug]) === null || _chainInfoMap$chainSl === void 0 ? void 0 : _chainInfoMap$chainSl.substrateInfo;
165
+ if (chainSlug && parentChain && STATUS_MAP[fundInfo.status] && fundInfo.paraId && endTime > now && substrateInfo) {
117
166
  const crowdloanCb = rs => {
118
- callback(networkKey, rs);
167
+ callback(chainSlug, rs);
119
168
  };
120
- const paraId = (0, _utils._getSubstrateParaId)(chainInfo);
121
- if (paraId <= -1 || addresses.length === 0 || parentChain.length === 0) {
122
- return;
123
- }
124
- if (networkKey === _chainList.COMMON_CHAIN_SLUGS.ACALA) {
125
- const acalaAddresses = substrateAddresses.map(address => (0, _utils2.reformatAddress)(address, (0, _utils._getChainSubstrateAddressPrefix)(chainInfo), (0, _utils._isChainEvmCompatible)(chainInfo)));
126
- unsubMap.acala = subscribeAcalaContributeInterval(acalaAddresses, _KoniTypes.CrowdloanParaState.COMPLETED, crowdloanCb);
127
- } else if (parentChain === _chainList.COMMON_CHAIN_SLUGS.POLKADOT && polkadotFundsStatusMap[paraId]) {
128
- unsubMap[networkKey] = getRPCCrowdloan(polkadotAPI, paraId, hexAddresses, polkadotFundsStatusMap[paraId], crowdloanCb);
129
- } else if (parentChain === _chainList.COMMON_CHAIN_SLUGS.KUSAMA && kusamaFundsStatusMap[paraId]) {
130
- unsubMap[networkKey] = getRPCCrowdloan(kusamaAPI, paraId, hexAddresses, kusamaFundsStatusMap[paraId], crowdloanCb);
169
+ fundInfo.paraId = substrateInfo.crowdloanParaId || substrateInfo.paraId || fundInfo.paraId;
170
+ if (chainSlug === _chainList.COMMON_CHAIN_SLUGS.ACALA) {
171
+ const acalaAddresses = substrateAddresses.map(address => (0, _utils.reformatAddress)(address, 10, false));
172
+ unsubMap.acala = subscribeAcalaContributeInterval(acalaAddresses, fundInfo, crowdloanCb);
173
+ } else if (parentChain === _chainList.COMMON_CHAIN_SLUGS.POLKADOT) {
174
+ unsubMap[chainSlug] = getRPCCrowdloan(polkadotAPI, fundInfo, hexAddresses, crowdloanCb);
175
+ } else if (parentChain === _chainList.COMMON_CHAIN_SLUGS.KUSAMA) {
176
+ unsubMap[chainSlug] = getRPCCrowdloan(kusamaAPI, fundInfo, hexAddresses, crowdloanCb);
131
177
  }
132
178
  }
133
179
  });
@@ -3612,6 +3612,47 @@ class KoniExtension {
3612
3612
  return true;
3613
3613
  }
3614
3614
 
3615
+ /* Campaign */
3616
+
3617
+ async subscribeProcessingBanner(id, port) {
3618
+ const cb = (0, _subscriptions.createSubscription)(id, port);
3619
+ const filterBanner = data => {
3620
+ const result = [];
3621
+ for (const item of data) {
3622
+ if (item.type === _KoniTypes.CampaignDataType.BANNER) {
3623
+ result.push(item);
3624
+ }
3625
+ }
3626
+ return result;
3627
+ };
3628
+ const callback = data => {
3629
+ cb(filterBanner(data));
3630
+ };
3631
+ const subscription = this.#koniState.campaignService.subscribeProcessingCampaign().subscribe({
3632
+ next: callback
3633
+ });
3634
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
3635
+ port.onDisconnect.addListener(() => {
3636
+ this.cancelSubscription(id);
3637
+ });
3638
+ return filterBanner(await this.#koniState.campaignService.getProcessingCampaign());
3639
+ }
3640
+ async completeCampaignBanner(_ref91) {
3641
+ let {
3642
+ slug
3643
+ } = _ref91;
3644
+ const campaign = await this.#koniState.dbService.getCampaign(slug);
3645
+ if (campaign) {
3646
+ await this.#koniState.dbService.upsertCampaign({
3647
+ ...campaign,
3648
+ isDone: true
3649
+ });
3650
+ }
3651
+ return true;
3652
+ }
3653
+
3654
+ /* Campaign */
3655
+
3615
3656
  // --------------------------------------------------------------
3616
3657
  // eslint-disable-next-line @typescript-eslint/require-await
3617
3658
  async handle(id, type, request, port) {
@@ -4048,6 +4089,13 @@ class KoniExtension {
4048
4089
  // Metadata
4049
4090
  case 'pri(metadata.find)':
4050
4091
  return this.findRawMetadata(request);
4092
+
4093
+ /* Campaign */
4094
+ case 'pri(campaign.banner.subscribe)':
4095
+ return this.subscribeProcessingBanner(id, port);
4096
+ case 'pri(campaign.banner.complete)':
4097
+ return this.completeCampaignBanner(request);
4098
+ /* Campaign */
4051
4099
  // Default
4052
4100
  default:
4053
4101
  throw new Error(`Unable to handle message of type ${type}`);
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _chainList = require("@subwallet/chain-list");
9
8
  var _EvmProviderError = require("@subwallet/extension-base/background/errors/EvmProviderError");
10
9
  var _helpers = require("@subwallet/extension-base/background/handlers/helpers");
11
10
  var _subscriptions = require("@subwallet/extension-base/background/handlers/subscriptions");
@@ -13,6 +12,7 @@ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
13
12
  var _constants = require("@subwallet/extension-base/constants");
14
13
  var _balanceService = require("@subwallet/extension-base/services/balance-service");
15
14
  var _types = require("@subwallet/extension-base/services/base/types");
15
+ var _campaignService = _interopRequireDefault(require("@subwallet/extension-base/services/campaign-service"));
16
16
  var _chainService = require("@subwallet/extension-base/services/chain-service");
17
17
  var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
18
18
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
@@ -57,15 +57,6 @@ const getSuri = (seed, type) => {
57
57
  };
58
58
  const generateDefaultCrowdloanMap = () => {
59
59
  const crowdloanMap = {};
60
- Object.entries(_chainList.ChainInfoMap).forEach(_ref => {
61
- let [networkKey, chainInfo] = _ref;
62
- if ((0, _utils._isSubstrateParaChain)(chainInfo)) {
63
- crowdloanMap[networkKey] = {
64
- state: _KoniTypes.APIItemState.PENDING,
65
- contribute: '0'
66
- };
67
- }
68
- });
69
60
  return crowdloanMap;
70
61
  };
71
62
  class KoniState {
@@ -109,7 +100,8 @@ class KoniState {
109
100
  this.historyService = new _historyService.HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService);
110
101
  this.transactionService = new _transactionService.default(this.chainService, this.eventService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
111
102
  this.walletConnectService = new _walletConnectService.default(this, this.requestService);
112
- this.migrationService = new _migrationService.default(this);
103
+ this.migrationService = new _migrationService.default(this, this.eventService);
104
+ this.campaignService = new _campaignService.default(this);
113
105
  this.subscription = new _subscription.KoniSubscription(this, this.dbService);
114
106
  this.cron = new _cron.KoniCron(this, this.subscription, this.dbService);
115
107
  this.logger = (0, _util.logger)('State');
@@ -165,12 +157,12 @@ class KoniState {
165
157
  });
166
158
  return Promise.resolve(this.providers[key].meta);
167
159
  }
168
- rpcSubscribe(_ref2, cb, port) {
160
+ rpcSubscribe(_ref, cb, port) {
169
161
  let {
170
162
  method,
171
163
  params,
172
164
  type
173
- } = _ref2;
165
+ } = _ref;
174
166
  const provider = this.injectedProviders.get(port);
175
167
  (0, _util.assert)(provider, 'Cannot call pub(rpc.subscribe) before provider is set');
176
168
  return provider.subscribe(type, method, params, cb);
@@ -548,10 +540,10 @@ class KoniState {
548
540
  address: changeAddress
549
541
  }, {
550
542
  address: changeAddress
551
- }).then(_ref3 => {
543
+ }).then(_ref2 => {
552
544
  let {
553
545
  isApproved
554
- } = _ref3;
546
+ } = _ref2;
555
547
  if (isApproved) {
556
548
  const useAddress = changeAddress || address;
557
549
  if (chainInfo && !(0, _utils._isChainEnabled)(chainState)) {
@@ -576,10 +568,10 @@ class KoniState {
576
568
  });
577
569
  }
578
570
  async addNetworkConfirm(id, url, networkData) {
579
- return this.requestService.addConfirmation(id, url, 'addNetworkRequest', networkData).then(async _ref4 => {
571
+ return this.requestService.addConfirmation(id, url, 'addNetworkRequest', networkData).then(async _ref3 => {
580
572
  let {
581
573
  isApproved
582
- } = _ref4;
574
+ } = _ref3;
583
575
  if (isApproved) {
584
576
  if (networkData.mode === 'insert') {
585
577
  await this.upsertChainInfo(networkData);
@@ -593,10 +585,10 @@ class KoniState {
593
585
  });
594
586
  }
595
587
  async addTokenConfirm(id, url, tokenInfo) {
596
- return this.requestService.addConfirmation(id, url, 'addTokenRequest', tokenInfo).then(async _ref5 => {
588
+ return this.requestService.addConfirmation(id, url, 'addTokenRequest', tokenInfo).then(async _ref4 => {
597
589
  let {
598
590
  isApproved
599
- } = _ref5;
591
+ } = _ref4;
600
592
  if (isApproved) {
601
593
  await this.upsertCustomToken({
602
594
  originChain: tokenInfo.originChain,
@@ -676,8 +668,8 @@ class KoniState {
676
668
  }
677
669
  removeInactiveChainBalances(balanceMap) {
678
670
  const activeBalanceMap = {};
679
- Object.entries(balanceMap).forEach(_ref6 => {
680
- let [tokenSlug, balanceItem] = _ref6;
671
+ Object.entries(balanceMap).forEach(_ref5 => {
672
+ let [tokenSlug, balanceItem] = _ref5;
681
673
  const tokenInfo = this.chainService.getAssetBySlug(tokenSlug);
682
674
  if (tokenInfo) {
683
675
  const chainInfo = this.chainService.getChainInfoByKey(tokenInfo.originChain);
@@ -1026,8 +1018,8 @@ class KoniState {
1026
1018
  if (!genesisHash) {
1027
1019
  return [undefined, undefined];
1028
1020
  }
1029
- const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref7 => {
1030
- let [networkKey, chainInfo] = _ref7;
1021
+ const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref6 => {
1022
+ let [networkKey, chainInfo] = _ref6;
1031
1023
  return (0, _utils._getSubstrateGenesisHash)(chainInfo) === genesisHash;
1032
1024
  });
1033
1025
  if (rs) {
@@ -1044,9 +1036,9 @@ class KoniState {
1044
1036
  if (!chainId) {
1045
1037
  return [undefined, undefined];
1046
1038
  }
1047
- const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref8 => {
1039
+ const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref7 => {
1048
1040
  var _chainInfo$evmInfo;
1049
- let [networkKey, chainInfo] = _ref8;
1041
+ let [networkKey, chainInfo] = _ref7;
1050
1042
  return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId) === chainId;
1051
1043
  });
1052
1044
  if (rs) {
@@ -1062,11 +1054,11 @@ class KoniState {
1062
1054
  }
1063
1055
  return Object.values(_constants2._PREDEFINED_SINGLE_MODES).find(item => item.networkKeys.includes(networkKey));
1064
1056
  }
1065
- accountExportPrivateKey(_ref9) {
1057
+ accountExportPrivateKey(_ref8) {
1066
1058
  let {
1067
1059
  address,
1068
1060
  password
1069
- } = _ref9;
1061
+ } = _ref8;
1070
1062
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1071
1063
  const exportedJson = _uiKeyring.keyring.backupAccount(_uiKeyring.keyring.getPair(address), password);
1072
1064
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
@@ -1076,11 +1068,11 @@ class KoniState {
1076
1068
  publicKey: (0, _util.u8aToHex)(decoded.publicKey)
1077
1069
  };
1078
1070
  }
1079
- checkPublicAndSecretKey(_ref10) {
1071
+ checkPublicAndSecretKey(_ref9) {
1080
1072
  let {
1081
1073
  publicKey,
1082
1074
  secretKey
1083
- } = _ref10;
1075
+ } = _ref9;
1084
1076
  try {
1085
1077
  const _secret = (0, _util.hexStripPrefix)(secretKey);
1086
1078
  if (_secret.length === 64) {
@@ -1198,11 +1190,11 @@ class KoniState {
1198
1190
  return this.requestService.addConfirmation(id, url, 'evmSignatureRequest', signPayload, {
1199
1191
  requiredPassword: false,
1200
1192
  address
1201
- }).then(_ref11 => {
1193
+ }).then(_ref10 => {
1202
1194
  let {
1203
1195
  isApproved,
1204
1196
  payload
1205
- } = _ref11;
1197
+ } = _ref10;
1206
1198
  if (isApproved) {
1207
1199
  if (payload) {
1208
1200
  return payload;
@@ -1486,7 +1478,7 @@ class KoniState {
1486
1478
  const chainMap = this.chainService.getChainInfoMap();
1487
1479
  const balanceDataList = await Promise.all(promiseList);
1488
1480
  balanceDataList.forEach(balanceData => {
1489
- balanceData && balanceData.forEach(_ref12 => {
1481
+ balanceData && balanceData.forEach(_ref11 => {
1490
1482
  var _currentAssetSettings;
1491
1483
  let {
1492
1484
  balance,
@@ -1495,7 +1487,7 @@ class KoniState {
1495
1487
  locked,
1496
1488
  network,
1497
1489
  symbol
1498
- } = _ref12;
1490
+ } = _ref11;
1499
1491
  const chain = _subscanChainMap.SUBSCAN_CHAIN_MAP_REVERSE[network];
1500
1492
  const chainInfo = chain ? chainMap[chain] : null;
1501
1493
  const balanceIsEmpty = (!balance || balance === '0') && (!locked || locked === '0') && (!bonded || bonded === '0');
@@ -171,11 +171,15 @@ class KoniSubscription {
171
171
  this.state.setCrowdloanItem(networkKey, rs);
172
172
  }, this.state.getChainInfoMap());
173
173
  if (onlyRunOnFirstTime) {
174
- subscriptionPromise.then(unsub => unsub()).catch(this.logger.warn);
174
+ subscriptionPromise.then(unsub => {
175
+ unsub && unsub();
176
+ }).catch(this.logger.warn);
175
177
  return;
176
178
  }
177
179
  return () => {
178
- subscriptionPromise.then(unsub => unsub()).catch(this.logger.warn);
180
+ subscriptionPromise.then(unsub => {
181
+ unsub && unsub();
182
+ }).catch(this.logger.warn);
179
183
  };
180
184
  }
181
185
  subscribeNft(address, substrateApiMap, evmApiMap, smartContractNfts, chainInfoMap) {