@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
@@ -7,7 +7,7 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
7
7
  import { isJsonPayload, SEED_DEFAULT_LENGTH, SEED_LENGTHS } from '@subwallet/extension-base/background/handlers/Extension';
8
8
  import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
9
9
  import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions';
10
- import { AccountExternalErrorCode, BasicTxErrorType, BasicTxWarningCode, ChainType, ExternalRequestPromiseStatus, ExtrinsicType, MantaPayEnableMessage, StakingType, TransferTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
10
+ import { AccountExternalErrorCode, BasicTxErrorType, BasicTxWarningCode, CampaignDataType, ChainType, ExternalRequestPromiseStatus, ExtrinsicType, MantaPayEnableMessage, StakingType, TransferTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
11
11
  import { TransactionWarning } from '@subwallet/extension-base/background/warnings/TransactionWarning';
12
12
  import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, XCM_MIN_AMOUNT_RATIO } from '@subwallet/extension-base/constants';
13
13
  import { ALLOWED_PATH } from '@subwallet/extension-base/defaults';
@@ -3512,6 +3512,46 @@ export default class KoniExtension {
3512
3512
  return true;
3513
3513
  }
3514
3514
 
3515
+ /* Campaign */
3516
+
3517
+ async subscribeProcessingBanner(id, port) {
3518
+ const cb = createSubscription(id, port);
3519
+ const filterBanner = data => {
3520
+ const result = [];
3521
+ for (const item of data) {
3522
+ if (item.type === CampaignDataType.BANNER) {
3523
+ result.push(item);
3524
+ }
3525
+ }
3526
+ return result;
3527
+ };
3528
+ const callback = data => {
3529
+ cb(filterBanner(data));
3530
+ };
3531
+ const subscription = this.#koniState.campaignService.subscribeProcessingCampaign().subscribe({
3532
+ next: callback
3533
+ });
3534
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
3535
+ port.onDisconnect.addListener(() => {
3536
+ this.cancelSubscription(id);
3537
+ });
3538
+ return filterBanner(await this.#koniState.campaignService.getProcessingCampaign());
3539
+ }
3540
+ async completeCampaignBanner({
3541
+ slug
3542
+ }) {
3543
+ const campaign = await this.#koniState.dbService.getCampaign(slug);
3544
+ if (campaign) {
3545
+ await this.#koniState.dbService.upsertCampaign({
3546
+ ...campaign,
3547
+ isDone: true
3548
+ });
3549
+ }
3550
+ return true;
3551
+ }
3552
+
3553
+ /* Campaign */
3554
+
3515
3555
  // --------------------------------------------------------------
3516
3556
  // eslint-disable-next-line @typescript-eslint/require-await
3517
3557
  async handle(id, type, request, port) {
@@ -3948,6 +3988,13 @@ export default class KoniExtension {
3948
3988
  // Metadata
3949
3989
  case 'pri(metadata.find)':
3950
3990
  return this.findRawMetadata(request);
3991
+
3992
+ /* Campaign */
3993
+ case 'pri(campaign.banner.subscribe)':
3994
+ return this.subscribeProcessingBanner(id, port);
3995
+ case 'pri(campaign.banner.complete)':
3996
+ return this.completeCampaignBanner(request);
3997
+ /* Campaign */
3951
3998
  // Default
3952
3999
  default:
3953
4000
  throw new Error(`Unable to handle message of type ${type}`);
@@ -3,6 +3,7 @@ import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from
3
3
  import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, BalanceItem, BalanceJson, ChainStakingMetadata, ConfirmationsQueue, CrowdloanItem, CrowdloanJson, CurrentAccountInfo, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCheckPublicAndSecretKey, RequestConfirmationComplete, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCheckPublicAndSecretKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
4
4
  import { AccountJson, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning } from '@subwallet/extension-base/background/types';
5
5
  import { BalanceService } from '@subwallet/extension-base/services/balance-service';
6
+ import CampaignService from '@subwallet/extension-base/services/campaign-service';
6
7
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
7
8
  import { _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest } from '@subwallet/extension-base/services/chain-service/types';
8
9
  import { EventService } from '@subwallet/extension-base/services/event-service';
@@ -62,6 +63,7 @@ export default class KoniState {
62
63
  readonly migrationService: MigrationService;
63
64
  readonly subscanService: SubscanService;
64
65
  readonly walletConnectService: WalletConnectService;
66
+ readonly campaignService: CampaignService;
65
67
  private generalStatus;
66
68
  private waitSleeping;
67
69
  private waitStarting;
@@ -1,7 +1,6 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { ChainInfoMap } from '@subwallet/chain-list';
5
4
  import { EvmProviderError } from '@subwallet/extension-base/background/errors/EvmProviderError';
6
5
  import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
7
6
  import { isSubscriptionRunning, unsubscribe } from '@subwallet/extension-base/background/handlers/subscriptions';
@@ -9,9 +8,10 @@ import { APIItemState, BasicTxErrorType, ChainType, EvmProviderErrorType, Extern
9
8
  import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, MANTA_PAY_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
10
9
  import { BalanceService } from '@subwallet/extension-base/services/balance-service';
11
10
  import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
11
+ import CampaignService from '@subwallet/extension-base/services/campaign-service';
12
12
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
13
13
  import { _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _PREDEFINED_SINGLE_MODES } from '@subwallet/extension-base/services/chain-service/constants';
14
- import { _getEvmChainId, _getSubstrateGenesisHash, _getTokenOnChainAssetId, _isAssetFungibleToken, _isChainEnabled, _isChainTestNet, _isSubstrateParaChain, _parseMetadataForSmartContractAsset } from '@subwallet/extension-base/services/chain-service/utils';
14
+ import { _getEvmChainId, _getSubstrateGenesisHash, _getTokenOnChainAssetId, _isAssetFungibleToken, _isChainEnabled, _isChainTestNet, _parseMetadataForSmartContractAsset } from '@subwallet/extension-base/services/chain-service/utils';
15
15
  import { EventService } from '@subwallet/extension-base/services/event-service';
16
16
  import { HistoryService } from '@subwallet/extension-base/services/history-service';
17
17
  import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
@@ -51,14 +51,6 @@ const getSuri = (seed, type) => {
51
51
  };
52
52
  const generateDefaultCrowdloanMap = () => {
53
53
  const crowdloanMap = {};
54
- Object.entries(ChainInfoMap).forEach(([networkKey, chainInfo]) => {
55
- if (_isSubstrateParaChain(chainInfo)) {
56
- crowdloanMap[networkKey] = {
57
- state: APIItemState.PENDING,
58
- contribute: '0'
59
- };
60
- }
61
- });
62
54
  return crowdloanMap;
63
55
  };
64
56
  export default class KoniState {
@@ -101,7 +93,8 @@ export default class KoniState {
101
93
  this.historyService = new HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService);
102
94
  this.transactionService = new TransactionService(this.chainService, this.eventService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
103
95
  this.walletConnectService = new WalletConnectService(this, this.requestService);
104
- this.migrationService = new MigrationService(this);
96
+ this.migrationService = new MigrationService(this, this.eventService);
97
+ this.campaignService = new CampaignService(this);
105
98
  this.subscription = new KoniSubscription(this, this.dbService);
106
99
  this.cron = new KoniCron(this, this.subscription, this.dbService);
107
100
  this.logger = createLogger('State');
@@ -165,11 +165,15 @@ export class KoniSubscription {
165
165
  this.state.setCrowdloanItem(networkKey, rs);
166
166
  }, this.state.getChainInfoMap());
167
167
  if (onlyRunOnFirstTime) {
168
- subscriptionPromise.then(unsub => unsub()).catch(this.logger.warn);
168
+ subscriptionPromise.then(unsub => {
169
+ unsub && unsub();
170
+ }).catch(this.logger.warn);
169
171
  return;
170
172
  }
171
173
  return () => {
172
- subscriptionPromise.then(unsub => unsub()).catch(this.logger.warn);
174
+ subscriptionPromise.then(unsub => {
175
+ unsub && unsub();
176
+ }).catch(this.logger.warn);
173
177
  };
174
178
  }
175
179
  subscribeNft(address, substrateApiMap, evmApiMap, smartContractNfts, chainInfoMap) {
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.1.17-0",
20
+ "version": "1.1.18-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -520,6 +520,21 @@
520
520
  "require": "./cjs/services/base/types.js",
521
521
  "default": "./services/base/types.js"
522
522
  },
523
+ "./services/campaign-service": {
524
+ "types": "./services/campaign-service/index.d.ts",
525
+ "require": "./cjs/services/campaign-service/index.js",
526
+ "default": "./services/campaign-service/index.js"
527
+ },
528
+ "./services/campaign-service/helpers": {
529
+ "types": "./services/campaign-service/helpers.d.ts",
530
+ "require": "./cjs/services/campaign-service/helpers.js",
531
+ "default": "./services/campaign-service/helpers.js"
532
+ },
533
+ "./services/campaign-service/types": {
534
+ "types": "./services/campaign-service/types.d.ts",
535
+ "require": "./cjs/services/campaign-service/types.js",
536
+ "default": "./services/campaign-service/types.js"
537
+ },
523
538
  "./services/chain-service": {
524
539
  "types": "./services/chain-service/index.d.ts",
525
540
  "require": "./cjs/services/chain-service/index.js",
@@ -903,6 +918,11 @@
903
918
  "require": "./cjs/services/storage-service/db-stores/BaseStoreWithChain.js",
904
919
  "default": "./services/storage-service/db-stores/BaseStoreWithChain.js"
905
920
  },
921
+ "./services/storage-service/db-stores/Campaign": {
922
+ "types": "./services/storage-service/db-stores/Campaign.d.ts",
923
+ "require": "./cjs/services/storage-service/db-stores/Campaign.js",
924
+ "default": "./services/storage-service/db-stores/Campaign.js"
925
+ },
906
926
  "./services/storage-service/db-stores/Chain": {
907
927
  "types": "./services/storage-service/db-stores/Chain.d.ts",
908
928
  "require": "./cjs/services/storage-service/db-stores/Chain.js",
@@ -1257,11 +1277,11 @@
1257
1277
  "@reduxjs/toolkit": "^1.9.1",
1258
1278
  "@sora-substrate/type-definitions": "^1.17.7",
1259
1279
  "@substrate/connect": "^0.7.26",
1260
- "@subwallet/chain-list": "0.2.16-beta.12",
1261
- "@subwallet/extension-base": "^1.1.17-0",
1262
- "@subwallet/extension-chains": "^1.1.17-0",
1263
- "@subwallet/extension-dapp": "^1.1.17-0",
1264
- "@subwallet/extension-inject": "^1.1.17-0",
1280
+ "@subwallet/chain-list": "0.2.18-beta.2",
1281
+ "@subwallet/extension-base": "^1.1.18-0",
1282
+ "@subwallet/extension-chains": "^1.1.18-0",
1283
+ "@subwallet/extension-dapp": "^1.1.18-0",
1284
+ "@subwallet/extension-inject": "^1.1.18-0",
1265
1285
  "@subwallet/keyring": "^0.1.1",
1266
1286
  "@subwallet/ui-keyring": "^0.1.1",
1267
1287
  "@walletconnect/sign-client": "^2.8.4",
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.1.17-0'
10
+ version: '1.1.18-0'
11
11
  };
@@ -0,0 +1,3 @@
1
+ import { CampaignNotification } from '@subwallet/extension-base/background/KoniTypes';
2
+ import NotificationService from '@subwallet/extension-base/services/notification-service/NotificationService';
3
+ export declare const runCampaign: (notificationService: NotificationService, campaign: CampaignNotification) => void;
@@ -0,0 +1,54 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { NotificationType } from '@subwallet/extension-base/background/KoniTypes';
5
+ import { t } from 'i18next';
6
+ export const runCampaign = (notificationService, campaign) => {
7
+ const {
8
+ action,
9
+ message,
10
+ metadata,
11
+ title
12
+ } = campaign.data;
13
+ const {
14
+ buttons
15
+ } = campaign;
16
+ const onClick = (action, metadata) => {
17
+ return () => {
18
+ switch (action) {
19
+ case 'open_url':
20
+ {
21
+ if (metadata) {
22
+ const url = metadata.url;
23
+ if (url) {
24
+ window.open(url);
25
+ }
26
+ }
27
+ break;
28
+ }
29
+ default:
30
+ break;
31
+ }
32
+ };
33
+ };
34
+ const onButtonClick = btnIndex => {
35
+ const {
36
+ metadata,
37
+ type
38
+ } = buttons[btnIndex];
39
+ onClick(type, metadata)();
40
+ };
41
+ notificationService.notify({
42
+ type: NotificationType.SUCCESS,
43
+ title: t(title),
44
+ message: t(message),
45
+ action: {
46
+ buttonClick: onButtonClick,
47
+ click: onClick(action, metadata)
48
+ },
49
+ notifyViaBrowser: true,
50
+ buttons: buttons.map(button => ({
51
+ title: button.name
52
+ }))
53
+ });
54
+ };
@@ -0,0 +1,11 @@
1
+ import { CampaignData } from '@subwallet/extension-base/background/KoniTypes';
2
+ import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
3
+ export default class CampaignService {
4
+ #private;
5
+ constructor(state: KoniState);
6
+ private fetchCampaign;
7
+ private runCampaign;
8
+ getProcessingCampaign(): Promise<CampaignData[]>;
9
+ subscribeProcessingCampaign(): import("dexie").Observable<CampaignData[]>;
10
+ private completeCampaignNotification;
11
+ }
@@ -0,0 +1,134 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { CampaignDataType } from '@subwallet/extension-base/background/KoniTypes';
5
+ import { MARKETING_CAMPAIGN_URL } from '@subwallet/extension-base/constants';
6
+ import { TARGET_ENV } from '@subwallet/extension-base/utils';
7
+ import axios from 'axios';
8
+ import { runCampaign } from "./helpers.js";
9
+ export default class CampaignService {
10
+ #state;
11
+ constructor(state) {
12
+ this.#state = state;
13
+ this.fetchCampaign().catch(e => {
14
+ console.error('Error on fetch campaigns', e);
15
+ });
16
+ this.runCampaign().catch(e => {
17
+ console.error('Error on run campaigns', e);
18
+ });
19
+ }
20
+ async fetchCampaign() {
21
+ const response = await axios.request({
22
+ method: 'GET',
23
+ url: MARKETING_CAMPAIGN_URL
24
+ });
25
+ const respData = response.data;
26
+ const campaigns = [];
27
+ for (const data of respData) {
28
+ // eslint-disable-next-line camelcase
29
+ const {
30
+ condition,
31
+ end_time,
32
+ id: campaignId,
33
+ start_time
34
+ } = data;
35
+ const endTime = new Date(end_time).getTime();
36
+ const startTime = new Date(start_time).getTime();
37
+ for (const banner of data.banners) {
38
+ const {
39
+ buttons,
40
+ id,
41
+ ...baseData
42
+ } = banner;
43
+ const slug = `${campaignId}-banner-${id}`;
44
+ if (banner.environments.includes(TARGET_ENV)) {
45
+ campaigns.push({
46
+ slug,
47
+ endTime,
48
+ startTime,
49
+ isDone: false,
50
+ campaignId,
51
+ type: CampaignDataType.BANNER,
52
+ buttons,
53
+ data: baseData,
54
+ condition
55
+ });
56
+ }
57
+ }
58
+ for (const notification of data.notifications) {
59
+ const {
60
+ buttons,
61
+ id,
62
+ ...baseData
63
+ } = notification;
64
+ const slug = `${campaignId}-notification-${id}`;
65
+ campaigns.push({
66
+ slug,
67
+ endTime,
68
+ startTime,
69
+ isDone: false,
70
+ campaignId,
71
+ type: CampaignDataType.NOTIFICATION,
72
+ buttons,
73
+ data: baseData,
74
+ condition
75
+ });
76
+ }
77
+ }
78
+ for (const campaign of campaigns) {
79
+ const exists = await this.#state.dbService.getCampaign(campaign.slug);
80
+ if (!exists) {
81
+ await this.#state.dbService.upsertCampaign(campaign);
82
+ }
83
+ }
84
+ this.#state.eventService.emit('campaign.ready', true);
85
+ }
86
+ async runCampaign() {
87
+ await this.#state.eventService.waitCampaignReady;
88
+ const campaigns = (await this.getProcessingCampaign()).filter(data => data.type === CampaignDataType.NOTIFICATION);
89
+ campaigns.forEach(campaign => {
90
+ const {
91
+ isDone,
92
+ slug,
93
+ type
94
+ } = campaign;
95
+ if (isDone) {
96
+ return;
97
+ }
98
+ const onComplete = () => {
99
+ this.completeCampaignNotification(slug).catch(e => {
100
+ console.error('Error when complete campaign', slug, e);
101
+ });
102
+ };
103
+ try {
104
+ switch (type) {
105
+ case CampaignDataType.NOTIFICATION:
106
+ {
107
+ runCampaign(this.#state.notificationService, campaign);
108
+ onComplete();
109
+ break;
110
+ }
111
+ default:
112
+ throw new Error('Missing handle campaign');
113
+ }
114
+ } catch (e) {
115
+ console.error('Error on running campaigns', slug, e);
116
+ }
117
+ });
118
+ }
119
+ getProcessingCampaign() {
120
+ return this.#state.dbService.getProcessingCampaign();
121
+ }
122
+ subscribeProcessingCampaign() {
123
+ return this.#state.dbService.subscribeProcessingCampaign();
124
+ }
125
+ async completeCampaignNotification(slug) {
126
+ const campaign = await this.#state.dbService.getCampaign(slug);
127
+ if (campaign) {
128
+ await this.#state.dbService.upsertCampaign({
129
+ ...campaign,
130
+ isDone: true
131
+ });
132
+ }
133
+ }
134
+ }
@@ -0,0 +1,34 @@
1
+ import { CampaignAction, CampaignButton } from '@subwallet/extension-base/background/KoniTypes';
2
+ declare type Metadata = Record<string, any> | null;
3
+ interface _BannerData {
4
+ id: number;
5
+ alt: string;
6
+ action: CampaignAction;
7
+ metadata: Metadata;
8
+ environments: string[];
9
+ position: string[];
10
+ buttons: CampaignButton[];
11
+ media: string;
12
+ }
13
+ interface _NotificationData {
14
+ id: number;
15
+ title: string;
16
+ message: string;
17
+ repeat: number;
18
+ repeatAfter: number;
19
+ action: CampaignAction;
20
+ metadata: Metadata;
21
+ buttons: CampaignButton[];
22
+ }
23
+ interface _CampaignData {
24
+ id: number;
25
+ name: string;
26
+ description: null;
27
+ start_time: string;
28
+ end_time: string;
29
+ condition: Metadata;
30
+ banners: _BannerData[];
31
+ notifications: _NotificationData[];
32
+ }
33
+ export declare type ListCampaignResponse = _CampaignData[];
34
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -11,6 +11,8 @@ export declare class EventService extends EventEmitter<EventRegistry> {
11
11
  readonly waitAccountReady: Promise<boolean>;
12
12
  readonly waitChainReady: Promise<boolean>;
13
13
  readonly waitAssetReady: Promise<boolean>;
14
+ readonly waitMigrateReady: Promise<boolean>;
15
+ readonly waitCampaignReady: Promise<boolean>;
14
16
  constructor(options?: {
15
17
  lazyTime: number;
16
18
  });
@@ -19,6 +19,8 @@ export class EventService extends EventEmitter {
19
19
  this.waitAccountReady = this.generateWaitPromise('account.ready');
20
20
  this.waitChainReady = this.generateWaitPromise('chain.ready');
21
21
  this.waitAssetReady = this.generateWaitPromise('asset.ready');
22
+ this.waitMigrateReady = this.generateWaitPromise('migration.done');
23
+ this.waitCampaignReady = this.generateWaitPromise('campaign.ready');
22
24
  }
23
25
  generateWaitPromise(eventType) {
24
26
  return new Promise(resolve => {
@@ -23,6 +23,8 @@ export interface EventRegistry {
23
23
  'mantaPay.initSync': [string | undefined];
24
24
  'mantaPay.submitTransaction': [SWTransaction | undefined];
25
25
  'mantaPay.enable': [string];
26
+ 'migration.done': [boolean];
27
+ 'campaign.ready': [boolean];
26
28
  }
27
29
  export declare type EventType = keyof EventRegistry;
28
30
  export declare const COMMON_RELOAD_EVENTS: EventType[];
@@ -1,7 +1,9 @@
1
1
  import State from '@subwallet/extension-base/koni/background/handlers/State';
2
+ import { EventService } from '@subwallet/extension-base/services/event-service';
2
3
  export default class MigrationService {
4
+ #private;
3
5
  readonly state: State;
4
6
  private logger;
5
- constructor(state: State);
7
+ constructor(state: State, eventService: EventService);
6
8
  run(): Promise<void>;
7
9
  }
@@ -4,8 +4,10 @@
4
4
  import { logger as createLogger } from '@polkadot/util';
5
5
  import MigrationScripts, { EVERYTIME } from "./scripts/index.js";
6
6
  export default class MigrationService {
7
- constructor(state) {
7
+ #eventService;
8
+ constructor(state, eventService) {
8
9
  this.state = state;
10
+ this.#eventService = eventService;
9
11
  this.logger = createLogger('Migration');
10
12
  }
11
13
  async run() {
@@ -32,5 +34,6 @@ export default class MigrationService {
32
34
  this.logger.error('Migration error: ', MigrationScripts[keys[i]].name, error);
33
35
  }
34
36
  }
37
+ this.#eventService.emit('migration.done', true);
35
38
  }
36
39
  }
@@ -1,8 +1,8 @@
1
- import { Notification, NotificationParams } from '@subwallet/extension-base/background/KoniTypes';
1
+ import { Notification, NotificationButton, NotificationParams } from '@subwallet/extension-base/background/KoniTypes';
2
2
  import { BehaviorSubject } from 'rxjs';
3
3
  export default class NotificationService {
4
4
  private notificationSubject;
5
5
  getNotificationSubject(): BehaviorSubject<Notification[]>;
6
6
  notify(notification: NotificationParams): void;
7
- static createBrowserNotification(title: string, message: string, link?: string): void;
7
+ static createBrowserNotification(title: string, message: string, action?: NotificationParams['action'], buttons?: NotificationButton[]): void;
8
8
  }
@@ -19,26 +19,40 @@ export default class NotificationService {
19
19
  });
20
20
  this.notificationSubject.next(notifications);
21
21
  if (notification.notifyViaBrowser) {
22
- var _notification$action;
23
- NotificationService.createBrowserNotification(notification.title, notification.message, notification === null || notification === void 0 ? void 0 : (_notification$action = notification.action) === null || _notification$action === void 0 ? void 0 : _notification$action.url);
22
+ NotificationService.createBrowserNotification(notification.title, notification.message, notification.action, notification.buttons);
24
23
  }
25
24
  }
26
25
 
27
26
  // Create a new chrome notification with link
28
- static createBrowserNotification(title, message, link) {
27
+ static createBrowserNotification(title, message, action, buttons) {
29
28
  var _chrome, _chrome$notifications;
29
+ const link = action === null || action === void 0 ? void 0 : action.url;
30
+ const onClick = action === null || action === void 0 ? void 0 : action.click;
31
+ const onButtonClick = action === null || action === void 0 ? void 0 : action.buttonClick;
30
32
  (_chrome = chrome) === null || _chrome === void 0 ? void 0 : (_chrome$notifications = _chrome.notifications) === null || _chrome$notifications === void 0 ? void 0 : _chrome$notifications.create({
31
33
  type: 'basic',
32
34
  title,
33
35
  message,
34
36
  iconUrl: './images/icon-128.png',
35
37
  priority: 2,
36
- isClickable: !!link
38
+ isClickable: !!link || !!onClick,
39
+ buttons
37
40
  }, notificationId => {
38
- if (link) {
41
+ if (link || onClick) {
39
42
  chrome.notifications.onClicked.addListener(nId => {
40
43
  if (nId === notificationId) {
41
- window.open(link);
44
+ if (onClick) {
45
+ onClick();
46
+ } else {
47
+ window.open(link);
48
+ }
49
+ }
50
+ });
51
+ }
52
+ if (onButtonClick) {
53
+ chrome.notifications.onButtonClicked.addListener((nId, btnIndex) => {
54
+ if (nId === notificationId) {
55
+ onButtonClick(btnIndex);
42
56
  }
43
57
  });
44
58
  }
@@ -1,8 +1,9 @@
1
1
  import { _ChainAsset } from '@subwallet/chain-list/types';
2
2
  import { BalanceItem, 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 { IBalance, 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 CampaignStore from '@subwallet/extension-base/services/storage-service/db-stores/Campaign';
6
7
  import ChainStakingMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/ChainStakingMetadata';
7
8
  import MantaPayStore from '@subwallet/extension-base/services/storage-service/db-stores/MantaPay';
8
9
  import NominatorMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/NominatorMetadata';
@@ -26,6 +27,7 @@ export default class DatabaseService {
26
27
  chainStakingMetadata: ChainStakingMetadataStore;
27
28
  nominatorMetadata: NominatorMetadataStore;
28
29
  mantaPay: MantaPayStore;
30
+ campaign: CampaignStore;
29
31
  };
30
32
  private logger;
31
33
  private nftSubscription;
@@ -77,4 +79,8 @@ export default class DatabaseService {
77
79
  subscribeMantaPayConfig(chain: string, callback: (data: MantaPayConfig[]) => void): void;
78
80
  getMantaPayConfig(chain: string): Promise<any[]>;
79
81
  getMantaPayFirstConfig(chain: string): Promise<any>;
82
+ subscribeProcessingCampaign(): import("dexie").Observable<import("@subwallet/extension-base/background/KoniTypes").CampaignData[]>;
83
+ getProcessingCampaign(): Promise<import("@subwallet/extension-base/background/KoniTypes").CampaignData[]>;
84
+ getCampaign(slug: string): Promise<import("@subwallet/extension-base/background/KoniTypes").CampaignData | undefined>;
85
+ upsertCampaign(campaign: ICampaign): import("dexie").PromiseExtended<unknown>;
80
86
  }
@@ -4,6 +4,7 @@
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 CampaignStore from '@subwallet/extension-base/services/storage-service/db-stores/Campaign';
7
8
  import ChainStakingMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/ChainStakingMetadata';
8
9
  import MantaPayStore from '@subwallet/extension-base/services/storage-service/db-stores/MantaPay';
9
10
  import NominatorMetadataStore from '@subwallet/extension-base/services/storage-service/db-stores/NominatorMetadata';
@@ -34,7 +35,8 @@ export default class DatabaseService {
34
35
  // staking
35
36
  chainStakingMetadata: new ChainStakingMetadataStore(this._db.chainStakingMetadata),
36
37
  nominatorMetadata: new NominatorMetadataStore(this._db.nominatorMetadata),
37
- mantaPay: new MantaPayStore(this._db.mantaPay)
38
+ mantaPay: new MantaPayStore(this._db.mantaPay),
39
+ campaign: new CampaignStore(this._db.campaign)
38
40
  };
39
41
  }
40
42
  async updatePriceStore(priceData) {
@@ -262,4 +264,19 @@ export default class DatabaseService {
262
264
  async getMantaPayFirstConfig(chain) {
263
265
  return this.stores.mantaPay.getFirstConfig(chain);
264
266
  }
267
+
268
+ /* Campaign */
269
+
270
+ subscribeProcessingCampaign() {
271
+ return this.stores.campaign.subscribeProcessingCampaign();
272
+ }
273
+ getProcessingCampaign() {
274
+ return this.stores.campaign.getProcessingCampaign();
275
+ }
276
+ getCampaign(slug) {
277
+ return this.stores.campaign.getCampaign(slug);
278
+ }
279
+ upsertCampaign(campaign) {
280
+ return this.stores.campaign.upsertCampaign(campaign);
281
+ }
265
282
  }