@subwallet/extension-base 1.3.3-0 → 1.3.4-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 (114) hide show
  1. package/background/KoniTypes.d.ts +13 -0
  2. package/background/KoniTypes.js +1 -0
  3. package/cjs/background/KoniTypes.js +1 -0
  4. package/cjs/constants/blocked-actions-list.js +1 -2
  5. package/cjs/constants/index.js +16 -1
  6. package/cjs/constants/remind-notification-time.js +14 -0
  7. package/cjs/core/logic-validation/transfer.js +12 -6
  8. package/cjs/core/substrate/xcm-parser.js +13 -1
  9. package/cjs/koni/api/contract-handler/utils/index.js +20 -1
  10. package/cjs/koni/background/handlers/Extension.js +110 -23
  11. package/cjs/koni/background/handlers/State.js +5 -2
  12. package/cjs/packageInfo.js +1 -1
  13. package/cjs/services/balance-service/helpers/process.js +2 -1
  14. package/cjs/services/balance-service/transfer/xcm/availBridge.js +198 -0
  15. package/cjs/services/balance-service/transfer/xcm/index.js +50 -5
  16. package/cjs/services/chain-service/handler/EvmApi.js +12 -21
  17. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +29 -0
  18. package/cjs/services/chain-service/index.js +44 -13
  19. package/cjs/services/chain-service/utils/index.js +20 -0
  20. package/cjs/services/earning-service/handlers/base.js +12 -3
  21. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +10 -2
  22. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +2 -0
  23. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +2 -0
  24. package/cjs/services/earning-service/handlers/native-staking/tao.js +10 -2
  25. package/cjs/services/earning-service/handlers/nomination-pool/index.js +9 -4
  26. package/cjs/services/earning-service/service.js +5 -0
  27. package/cjs/services/inapp-notification-service/consts.js +31 -0
  28. package/cjs/services/inapp-notification-service/index.js +260 -0
  29. package/cjs/services/inapp-notification-service/interfaces.js +32 -0
  30. package/cjs/services/inapp-notification-service/utils.js +197 -0
  31. package/cjs/services/keyring-service/context/account-context.js +9 -0
  32. package/cjs/services/keyring-service/context/state.js +4 -0
  33. package/cjs/services/setting-service/SettingService.js +9 -1
  34. package/cjs/services/setting-service/constants.js +16 -1
  35. package/cjs/services/storage-service/DatabaseService.js +42 -3
  36. package/cjs/services/storage-service/databases/index.js +3 -0
  37. package/cjs/services/storage-service/db-stores/InappNotification.js +81 -0
  38. package/cjs/services/transaction-service/index.js +13 -0
  39. package/cjs/types/avail-bridge/index.js +1 -0
  40. package/cjs/types/notification/index.js +1 -0
  41. package/cjs/utils/account/transform.js +9 -5
  42. package/cjs/utils/staticData/index.js +7 -2
  43. package/constants/blocked-actions-list.js +1 -2
  44. package/constants/index.d.ts +2 -0
  45. package/constants/index.js +3 -1
  46. package/constants/remind-notification-time.d.ts +2 -0
  47. package/constants/remind-notification-time.js +7 -0
  48. package/core/logic-validation/transfer.js +12 -6
  49. package/core/substrate/xcm-parser.d.ts +1 -0
  50. package/core/substrate/xcm-parser.js +12 -1
  51. package/koni/api/contract-handler/utils/avail_bridge_abi.json +1659 -0
  52. package/koni/api/contract-handler/utils/avail_test_bridge_abi.json +1692 -0
  53. package/koni/api/contract-handler/utils/index.d.ts +4 -0
  54. package/koni/api/contract-handler/utils/index.js +15 -0
  55. package/koni/background/handlers/Extension.d.ts +7 -0
  56. package/koni/background/handlers/Extension.js +112 -25
  57. package/koni/background/handlers/State.d.ts +2 -0
  58. package/koni/background/handlers/State.js +5 -2
  59. package/package.json +54 -6
  60. package/packageInfo.js +1 -1
  61. package/services/balance-service/helpers/process.js +2 -1
  62. package/services/balance-service/transfer/xcm/availBridge.d.ts +45 -0
  63. package/services/balance-service/transfer/xcm/availBridge.js +186 -0
  64. package/services/balance-service/transfer/xcm/index.d.ts +8 -8
  65. package/services/balance-service/transfer/xcm/index.js +46 -5
  66. package/services/chain-service/handler/EvmApi.js +12 -21
  67. package/services/chain-service/handler/SubstrateChainHandler.d.ts +2 -0
  68. package/services/chain-service/handler/SubstrateChainHandler.js +29 -0
  69. package/services/chain-service/index.d.ts +2 -0
  70. package/services/chain-service/index.js +45 -14
  71. package/services/chain-service/types.d.ts +2 -1
  72. package/services/chain-service/utils/index.d.ts +3 -0
  73. package/services/chain-service/utils/index.js +14 -0
  74. package/services/earning-service/handlers/base.d.ts +2 -0
  75. package/services/earning-service/handlers/base.js +9 -0
  76. package/services/earning-service/handlers/native-staking/amplitude.js +10 -2
  77. package/services/earning-service/handlers/native-staking/para-chain.js +2 -0
  78. package/services/earning-service/handlers/native-staking/relay-chain.js +2 -0
  79. package/services/earning-service/handlers/native-staking/tao.d.ts +4 -0
  80. package/services/earning-service/handlers/native-staking/tao.js +5 -1
  81. package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -1
  82. package/services/earning-service/handlers/nomination-pool/index.js +9 -4
  83. package/services/earning-service/service.d.ts +2 -0
  84. package/services/earning-service/service.js +5 -0
  85. package/services/inapp-notification-service/consts.d.ts +18 -0
  86. package/services/inapp-notification-service/consts.js +22 -0
  87. package/services/inapp-notification-service/index.d.ts +37 -0
  88. package/services/inapp-notification-service/index.js +252 -0
  89. package/services/inapp-notification-service/interfaces.d.ts +77 -0
  90. package/services/inapp-notification-service/interfaces.js +24 -0
  91. package/services/inapp-notification-service/utils.d.ts +55 -0
  92. package/services/inapp-notification-service/utils.js +173 -0
  93. package/services/keyring-service/context/account-context.d.ts +3 -0
  94. package/services/keyring-service/context/account-context.js +9 -0
  95. package/services/keyring-service/context/state.d.ts +1 -0
  96. package/services/keyring-service/context/state.js +4 -0
  97. package/services/setting-service/SettingService.js +9 -1
  98. package/services/setting-service/constants.d.ts +2 -0
  99. package/services/setting-service/constants.js +15 -0
  100. package/services/storage-service/DatabaseService.d.ts +15 -0
  101. package/services/storage-service/DatabaseService.js +42 -3
  102. package/services/storage-service/databases/index.d.ts +2 -0
  103. package/services/storage-service/databases/index.js +3 -0
  104. package/services/storage-service/db-stores/InappNotification.d.ts +14 -0
  105. package/services/storage-service/db-stores/InappNotification.js +73 -0
  106. package/services/transaction-service/index.js +13 -0
  107. package/types/avail-bridge/index.d.ts +6 -0
  108. package/types/avail-bridge/index.js +1 -0
  109. package/types/notification/index.d.ts +9 -0
  110. package/types/notification/index.js +1 -0
  111. package/utils/account/transform.js +9 -5
  112. package/utils/staticData/index.d.ts +5 -1
  113. package/utils/staticData/index.js +5 -2
  114. package/utils/staticData/remindNotificationTime.json +1 -0
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.default = exports.bittensorApiKey = exports.BITTENSOR_API_KEY_2 = exports.BITTENSOR_API_KEY_1 = void 0;
7
+ exports.default = exports.bittensorApiKey = exports.BITTENSOR_API_KEY_6 = exports.BITTENSOR_API_KEY_5 = exports.BITTENSOR_API_KEY_4 = exports.BITTENSOR_API_KEY_3 = exports.BITTENSOR_API_KEY_2 = exports.BITTENSOR_API_KEY_1 = void 0;
8
8
  exports.fetchDelegates = fetchDelegates;
9
9
  exports.fetchTaoDelegateState = fetchTaoDelegateState;
10
10
  var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
@@ -24,6 +24,14 @@ const BITTENSOR_API_KEY_1 = process.env.BITTENSOR_API_KEY_1 || '';
24
24
  exports.BITTENSOR_API_KEY_1 = BITTENSOR_API_KEY_1;
25
25
  const BITTENSOR_API_KEY_2 = process.env.BITTENSOR_API_KEY_2 || '';
26
26
  exports.BITTENSOR_API_KEY_2 = BITTENSOR_API_KEY_2;
27
+ const BITTENSOR_API_KEY_3 = process.env.BITTENSOR_API_KEY_3 || '';
28
+ exports.BITTENSOR_API_KEY_3 = BITTENSOR_API_KEY_3;
29
+ const BITTENSOR_API_KEY_4 = process.env.BITTENSOR_API_KEY_4 || '';
30
+ exports.BITTENSOR_API_KEY_4 = BITTENSOR_API_KEY_4;
31
+ const BITTENSOR_API_KEY_5 = process.env.BITTENSOR_API_KEY_5 || '';
32
+ exports.BITTENSOR_API_KEY_5 = BITTENSOR_API_KEY_5;
33
+ const BITTENSOR_API_KEY_6 = process.env.BITTENSOR_API_KEY_6 || '';
34
+ exports.BITTENSOR_API_KEY_6 = BITTENSOR_API_KEY_6;
27
35
  function random() {
28
36
  for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
29
37
  keys[_key] = arguments[_key];
@@ -33,7 +41,7 @@ function random() {
33
41
  return validKeys[randomIndex];
34
42
  }
35
43
  const bittensorApiKey = () => {
36
- return random(BITTENSOR_API_KEY_1, BITTENSOR_API_KEY_2);
44
+ return random(BITTENSOR_API_KEY_1, BITTENSOR_API_KEY_2, BITTENSOR_API_KEY_3, BITTENSOR_API_KEY_4, BITTENSOR_API_KEY_5, BITTENSOR_API_KEY_6);
37
45
  };
38
46
 
39
47
  /* Fetch data */
@@ -153,7 +153,7 @@ class NominationPoolHandler extends _base.default {
153
153
 
154
154
  /* Subscribe pool position */
155
155
 
156
- async parsePoolMemberMetadata(substrateApi, poolMemberInfo, currentEra, _deriveSessionProgress) {
156
+ async parsePoolMemberMetadata(substrateApi, poolMemberInfo, currentEra, _deriveSessionProgress, address) {
157
157
  const chainInfo = this.chainInfo;
158
158
  const unlimitedNominatorRewarded = substrateApi.api.consts.staking.maxExposurePageSize !== undefined;
159
159
  const _maxNominatorRewardedPerValidator = (substrateApi.api.consts.staking.maxNominatorRewardedPerValidator || 0).toString();
@@ -224,6 +224,7 @@ class NominationPoolHandler extends _base.default {
224
224
  if (!bnActiveStake.gt(_util.BN_ZERO)) {
225
225
  stakingStatus = _types.EarningStatus.NOT_EARNING;
226
226
  }
227
+ await this.createWithdrawNotifications(unstakings, this.nativeToken, address);
227
228
  return {
228
229
  status: stakingStatus,
229
230
  balanceToken: this.nativeToken.slug,
@@ -255,7 +256,7 @@ class NominationPoolHandler extends _base.default {
255
256
  const poolMemberInfo = _poolMemberInfo.toPrimitive();
256
257
  const owner = (0, _utils3.reformatAddress)(useAddresses[i], 42);
257
258
  if (poolMemberInfo) {
258
- const nominatorMetadata = await this.parsePoolMemberMetadata(substrateApi, poolMemberInfo, currentEra, _deriveSessionProgress);
259
+ const nominatorMetadata = await this.parsePoolMemberMetadata(substrateApi, poolMemberInfo, currentEra, _deriveSessionProgress, owner);
259
260
  resultCallback({
260
261
  ...defaultInfo,
261
262
  ...nominatorMetadata,
@@ -301,13 +302,17 @@ class NominationPoolHandler extends _base.default {
301
302
  var _substrateApi$api$cal, _substrateApi$api$cal2;
302
303
  const _unclaimedReward = await ((_substrateApi$api$cal = substrateApi.api.call) === null || _substrateApi$api$cal === void 0 ? void 0 : (_substrateApi$api$cal2 = _substrateApi$api$cal.nominationPoolsApi) === null || _substrateApi$api$cal2 === void 0 ? void 0 : _substrateApi$api$cal2.pendingRewards(address));
303
304
  if (_unclaimedReward) {
304
- callBack({
305
+ const earningRewardItem = {
305
306
  ...this.baseInfo,
306
307
  address: address,
307
308
  type: this.type,
308
309
  unclaimedReward: _unclaimedReward.toString(),
309
310
  state: _KoniTypes.APIItemState.READY
310
- });
311
+ };
312
+ if (_unclaimedReward.toString() !== '0') {
313
+ await this.createClaimNotification(earningRewardItem, this.nativeToken);
314
+ }
315
+ callBack(earningRewardItem);
311
316
  }
312
317
  }
313
318
  }
@@ -526,6 +526,7 @@ class EarningService {
526
526
  stakingRewardState.ready = true;
527
527
  this.earningRewardSubject.next(stakingRewardState);
528
528
  this.earningsRewardQueue = [];
529
+ this.earningRewardReady.resolve();
529
530
  });
530
531
  }
531
532
  async getPoolReward(addresses, callback) {
@@ -563,6 +564,10 @@ class EarningService {
563
564
  getEarningRewards() {
564
565
  return this.earningRewardSubject.getValue();
565
566
  }
567
+ earningRewardReady = (0, _utils2.createPromiseHandler)();
568
+ waitEarningRewardReady() {
569
+ return this.earningRewardReady.promise;
570
+ }
566
571
  runSubscribeStakingRewardInterval() {
567
572
  const addresses = this.state.keyringService.context.getDecodedAddresses();
568
573
  if (!addresses.length) {
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ONE_DAY_MILLISECOND = exports.NotificationTitleMap = exports.NotificationDescriptionMap = void 0;
7
+ var _interfaces = require("@subwallet/extension-base/services/inapp-notification-service/interfaces");
8
+ var _utils = require("@subwallet/extension-base/services/inapp-notification-service/utils");
9
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
10
+ // SPDX-License-Identifier: Apache-2.0
11
+
12
+ const NotificationTitleMap = {
13
+ [_interfaces.NotificationActionType.WITHDRAW]: '[{{accountName}}] WITHDRAW {{tokenSymbol}}',
14
+ [_interfaces.NotificationActionType.CLAIM]: '[{{accountName}}] CLAIM {{tokenSymbol}}',
15
+ [_interfaces.NotificationActionType.SEND]: '[{{accountName}}] SEND {{tokenSymbol}}',
16
+ [_interfaces.NotificationActionType.RECEIVE]: '[{{accountName}}] RECEIVE {{tokenSymbol}}',
17
+ [_interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_AVAIL]: '[{{accountName}}] CLAIM {{tokenSymbol}}',
18
+ [_interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM]: '[{{accountName}}] CLAIM {{tokenSymbol}}'
19
+ };
20
+ exports.NotificationTitleMap = NotificationTitleMap;
21
+ const NotificationDescriptionMap = {
22
+ [_interfaces.NotificationActionType.WITHDRAW]: _utils.getWithdrawDescription,
23
+ [_interfaces.NotificationActionType.CLAIM]: _utils.getClaimDescription,
24
+ [_interfaces.NotificationActionType.SEND]: _utils.getSendDescription,
25
+ [_interfaces.NotificationActionType.RECEIVE]: _utils.getReceiveDescription,
26
+ [_interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_AVAIL]: _utils.getAvailBridgeClaimDescription,
27
+ [_interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM]: _utils.getAvailBridgeClaimDescription
28
+ };
29
+ exports.NotificationDescriptionMap = NotificationDescriptionMap;
30
+ const ONE_DAY_MILLISECOND = 1000 * 24 * 60 * 60;
31
+ exports.ONE_DAY_MILLISECOND = ONE_DAY_MILLISECOND;
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.InappNotificationService = void 0;
7
+ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
8
+ var _constants = require("@subwallet/extension-base/constants");
9
+ var _remindNotificationTime = require("@subwallet/extension-base/constants/remind-notification-time");
10
+ var _types = require("@subwallet/extension-base/services/base/types");
11
+ var _consts = require("@subwallet/extension-base/services/inapp-notification-service/consts");
12
+ var _interfaces = require("@subwallet/extension-base/services/inapp-notification-service/interfaces");
13
+ var _utils = require("@subwallet/extension-base/services/inapp-notification-service/utils");
14
+ var _utils2 = require("@subwallet/extension-base/utils");
15
+ var _keyring = require("@subwallet/keyring");
16
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
17
+ // SPDX-License-Identifier: Apache-2.0
18
+
19
+ class InappNotificationService {
20
+ constructor(dbService, keyringService, eventService, chainService) {
21
+ this.dbService = dbService;
22
+ this.keyringService = keyringService;
23
+ this.eventService = eventService;
24
+ this.chainService = chainService;
25
+ this.status = _types.ServiceStatus.NOT_INITIALIZED;
26
+ }
27
+ async init() {
28
+ this.status = _types.ServiceStatus.INITIALIZING;
29
+ await this.eventService.waitAccountReady;
30
+ this.status = _types.ServiceStatus.INITIALIZED;
31
+ await this.start();
32
+ this.onAccountProxyRemove();
33
+ }
34
+ async markAllRead(proxyId) {
35
+ await this.dbService.markAllRead(proxyId);
36
+ }
37
+ async switchReadStatus(params) {
38
+ await this.dbService.switchReadStatus(params);
39
+ }
40
+ subscribeUnreadNotificationsCountMap(callback) {
41
+ return this.dbService.subscribeUnreadNotificationsCountMap().subscribe({
42
+ next: callback
43
+ });
44
+ }
45
+ async getUnreadNotificationsCountMap() {
46
+ return await this.dbService.getUnreadNotificationsCountMap();
47
+ }
48
+ async fetchNotificationsByParams(params) {
49
+ return this.dbService.getNotificationsByParams(params);
50
+ }
51
+ async getNotificationById(id) {
52
+ return this.dbService.getNotification(id);
53
+ }
54
+ cleanUpOldNotifications() {
55
+ let overdueTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _consts.ONE_DAY_MILLISECOND * 60;
56
+ return this.dbService.cleanUpOldNotifications(overdueTime);
57
+ }
58
+ passValidateNotification(candidateNotification, comparedNotifications, remindTimeConfigInHrs) {
59
+ // todo: simplify condition !!
60
+ if ([_interfaces.NotificationActionType.WITHDRAW, _interfaces.NotificationActionType.CLAIM].includes(candidateNotification.actionType)) {
61
+ const {
62
+ actionType,
63
+ address,
64
+ metadata,
65
+ time
66
+ } = candidateNotification;
67
+ const candidateMetadata = metadata;
68
+ const remindTime = (0, _utils.hrsToMillisecond)(remindTimeConfigInHrs[candidateNotification.actionType]);
69
+ for (const comparedNotification of comparedNotifications) {
70
+ const specialCase = comparedNotification.actionType === _interfaces.NotificationActionType.WITHDRAW && !comparedNotification.isRead;
71
+ if (comparedNotification.address !== address) {
72
+ continue;
73
+ }
74
+ if (comparedNotification.actionType !== actionType) {
75
+ continue;
76
+ }
77
+ const comparedMetadata = comparedNotification.metadata;
78
+ const sameNotification = candidateMetadata.stakingType === comparedMetadata.stakingType && candidateMetadata.stakingSlug === comparedMetadata.stakingSlug;
79
+ if (!sameNotification) {
80
+ continue;
81
+ }
82
+ if (time - comparedNotification.time <= remindTime) {
83
+ return false;
84
+ } else {
85
+ if (specialCase) {
86
+ return false;
87
+ }
88
+ }
89
+ }
90
+ }
91
+ if ([_interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM, _interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_AVAIL].includes(candidateNotification.actionType)) {
92
+ const {
93
+ address,
94
+ metadata,
95
+ time
96
+ } = candidateNotification;
97
+ const candidateMetadata = metadata;
98
+ const remindTime = (0, _utils.hrsToMillisecond)(remindTimeConfigInHrs[candidateNotification.actionType]);
99
+ for (const notification of comparedNotifications) {
100
+ if (notification.address !== address) {
101
+ continue;
102
+ }
103
+ if (time - notification.time >= remindTime) {
104
+ continue;
105
+ }
106
+ const comparedMetadata = notification.metadata;
107
+ const sameNotification = candidateMetadata.messageId === comparedMetadata.messageId && candidateMetadata.sourceBlockHash === comparedMetadata.sourceBlockHash && candidateMetadata.sourceTransactionHash === comparedMetadata.sourceTransactionHash;
108
+ if (sameNotification) {
109
+ return false;
110
+ }
111
+ }
112
+ }
113
+ return true;
114
+ }
115
+ async validateAndWriteNotificationsToDB(notifications, address) {
116
+ const proxyId = this.keyringService.context.belongUnifiedAccount(address) || address;
117
+ const accountName = this.keyringService.context.getCurrentAccountProxyName(proxyId);
118
+ const passNotifications = [];
119
+ const [comparedNotifications, remindTimeConfig] = await Promise.all([this.fetchNotificationsByParams({
120
+ notificationTab: _interfaces.NotificationTab.ALL,
121
+ proxyId
122
+ }), await (0, _remindNotificationTime.fetchLastestRemindNotificationTime)()]);
123
+ for (const candidateNotification of notifications) {
124
+ candidateNotification.title = candidateNotification.title.replace('{{accountName}}', accountName);
125
+ if (this.passValidateNotification(candidateNotification, comparedNotifications, remindTimeConfig)) {
126
+ passNotifications.push({
127
+ ...candidateNotification,
128
+ proxyId
129
+ });
130
+ }
131
+ }
132
+ await this.dbService.upsertNotifications(passNotifications);
133
+ }
134
+ cronCreateAvailBridgeClaimNotification() {
135
+ clearTimeout(this.refeshAvailBridgeClaimTimeOut);
136
+ this.createAvailBridgeClaimNotification();
137
+ this.refeshAvailBridgeClaimTimeOut = setTimeout(this.cronCreateAvailBridgeClaimNotification.bind(this), _constants.CRON_LISTEN_AVAIL_BRIDGE_CLAIM);
138
+ }
139
+ createAvailBridgeClaimNotification() {
140
+ const addresses = this.keyringService.context.getAllAddresses();
141
+ const {
142
+ evm: evmAddresses,
143
+ substrate: substrateAddresses
144
+ } = (0, _utils2.categoryAddresses)(addresses);
145
+ const chainAssets = this.chainService.getAssetRegistry();
146
+ let ASSET_TYPE;
147
+ (function (ASSET_TYPE) {
148
+ ASSET_TYPE["TEST_EVM"] = "test_evm";
149
+ ASSET_TYPE["TEST_SUBSTRATE"] = "test_substrate";
150
+ ASSET_TYPE["MAIN_EVM"] = "main_evm";
151
+ ASSET_TYPE["MAIN_SUBSTRATE"] = "main_substrate";
152
+ })(ASSET_TYPE || (ASSET_TYPE = {}));
153
+ const chainAssetMap = Object.values(chainAssets).reduce((acc, chainAsset) => {
154
+ let type;
155
+ if (chainAsset.symbol === 'AVAIL') {
156
+ if (chainAsset.originChain === 'sepolia_ethereum') {
157
+ type = ASSET_TYPE.TEST_EVM;
158
+ } else if (chainAsset.originChain === 'availTuringTest') {
159
+ type = ASSET_TYPE.TEST_SUBSTRATE;
160
+ } else if (chainAsset.originChain === 'ethereum') {
161
+ type = ASSET_TYPE.MAIN_EVM;
162
+ } else if (chainAsset.originChain === 'avail_mainnet') {
163
+ type = ASSET_TYPE.MAIN_SUBSTRATE;
164
+ }
165
+ }
166
+ if (type) {
167
+ acc[type] = chainAsset;
168
+ }
169
+ return acc;
170
+ }, {});
171
+ substrateAddresses.forEach(address => {
172
+ (0, _utils.fetchAllAvailBridgeClaimable)(address, _utils.AvailBridgeSourceChain.ETHEREUM, true).then(async transactions => await this.processWriteAvailBridgeClaim(address, transactions, chainAssetMap[ASSET_TYPE.TEST_SUBSTRATE])).catch(console.error);
173
+ (0, _utils.fetchAllAvailBridgeClaimable)(address, _utils.AvailBridgeSourceChain.ETHEREUM, false).then(async transactions => await this.processWriteAvailBridgeClaim(address, transactions, chainAssetMap[ASSET_TYPE.MAIN_SUBSTRATE])).catch(console.error);
174
+ });
175
+ evmAddresses.forEach(address => {
176
+ (0, _utils.fetchAllAvailBridgeClaimable)(address, _utils.AvailBridgeSourceChain.AVAIL, true).then(async transactions => await this.processWriteAvailBridgeClaim(address, transactions, chainAssetMap[ASSET_TYPE.TEST_EVM])).catch(console.error);
177
+ (0, _utils.fetchAllAvailBridgeClaimable)(address, _utils.AvailBridgeSourceChain.AVAIL, false).then(async transactions => await this.processWriteAvailBridgeClaim(address, transactions, chainAssetMap[ASSET_TYPE.MAIN_EVM])).catch(console.error);
178
+ });
179
+ }
180
+ async processWriteAvailBridgeClaim(address, transactions, token) {
181
+ var _token$decimals;
182
+ const actionType = (0, _keyring.isSubstrateAddress)(address) ? _interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_AVAIL : _interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM;
183
+ const timestamp = Date.now();
184
+ const symbol = token.symbol;
185
+ const decimals = (_token$decimals = token.decimals) !== null && _token$decimals !== void 0 ? _token$decimals : 0;
186
+ const notifications = transactions.map(transaction => {
187
+ const {
188
+ amount,
189
+ depositorAddress,
190
+ messageId,
191
+ receiverAddress,
192
+ sourceBlockHash,
193
+ sourceChain,
194
+ sourceTransactionHash,
195
+ sourceTransactionIndex,
196
+ status
197
+ } = transaction;
198
+ const metadata = {
199
+ chainSlug: token.originChain,
200
+ tokenSlug: token.slug,
201
+ messageId,
202
+ sourceChain,
203
+ sourceTransactionHash,
204
+ depositorAddress,
205
+ receiverAddress,
206
+ amount,
207
+ sourceBlockHash,
208
+ sourceTransactionIndex,
209
+ status
210
+ };
211
+ return {
212
+ id: `${actionType}___${messageId}___${timestamp}`,
213
+ address: address,
214
+ // address is receiverAddress
215
+ title: _consts.NotificationTitleMap[actionType].replace('{{tokenSymbol}}', symbol),
216
+ description: _consts.NotificationDescriptionMap[actionType]((0, _utils2.formatNumber)(amount, decimals), symbol),
217
+ time: timestamp,
218
+ extrinsicType: _KoniTypes.ExtrinsicType.CLAIM_AVAIL_BRIDGE,
219
+ isRead: false,
220
+ actionType,
221
+ metadata
222
+ };
223
+ });
224
+ await this.validateAndWriteNotificationsToDB(notifications, address);
225
+ }
226
+ async start() {
227
+ if (this.status === _types.ServiceStatus.STARTED) {
228
+ return;
229
+ }
230
+ try {
231
+ this.status = _types.ServiceStatus.STARTING;
232
+ await this.startCron();
233
+ this.status = _types.ServiceStatus.STARTED;
234
+ } catch (e) {}
235
+ }
236
+ async startCron() {
237
+ this.cleanUpOldNotifications().catch(console.error);
238
+ this.cronCreateAvailBridgeClaimNotification();
239
+ return Promise.resolve();
240
+ }
241
+ async stop() {
242
+ try {
243
+ this.status = _types.ServiceStatus.STOPPING;
244
+ await this.stopCron();
245
+ this.status = _types.ServiceStatus.STOPPED;
246
+ } catch (e) {}
247
+ }
248
+ stopCron() {
249
+ return Promise.resolve(undefined);
250
+ }
251
+ onAccountProxyRemove() {
252
+ this.eventService.on('accountProxy.remove', proxyId => {
253
+ this.removeAccountNotifications(proxyId);
254
+ });
255
+ }
256
+ removeAccountNotifications(proxyId) {
257
+ this.dbService.removeAccountNotifications(proxyId).catch(console.error);
258
+ }
259
+ }
260
+ exports.InappNotificationService = InappNotificationService;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NotificationTimePeriod = exports.NotificationTab = exports.NotificationActionType = void 0;
7
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
8
+ // SPDX-License-Identifier: Apache-2.0
9
+ let NotificationTimePeriod;
10
+ exports.NotificationTimePeriod = NotificationTimePeriod;
11
+ (function (NotificationTimePeriod) {
12
+ NotificationTimePeriod["TODAY"] = "TODAY";
13
+ NotificationTimePeriod["THIS_WEEK"] = "THIS_WEEK";
14
+ NotificationTimePeriod["THIS_MONTH"] = "THIS_MONTH";
15
+ })(NotificationTimePeriod || (exports.NotificationTimePeriod = NotificationTimePeriod = {}));
16
+ let NotificationActionType;
17
+ exports.NotificationActionType = NotificationActionType;
18
+ (function (NotificationActionType) {
19
+ NotificationActionType["SEND"] = "SEND";
20
+ NotificationActionType["RECEIVE"] = "RECEIVE";
21
+ NotificationActionType["WITHDRAW"] = "WITHDRAW";
22
+ NotificationActionType["CLAIM"] = "CLAIM";
23
+ NotificationActionType["CLAIM_AVAIL_BRIDGE_ON_AVAIL"] = "CLAIM_AVAIL_BRIDGE_ON_AVAIL";
24
+ NotificationActionType["CLAIM_AVAIL_BRIDGE_ON_ETHEREUM"] = "CLAIM_AVAIL_BRIDGE_ON_ETHEREUM";
25
+ })(NotificationActionType || (exports.NotificationActionType = NotificationActionType = {}));
26
+ let NotificationTab;
27
+ exports.NotificationTab = NotificationTab;
28
+ (function (NotificationTab) {
29
+ NotificationTab["ALL"] = "ALL";
30
+ NotificationTab["UNREAD"] = "UNREAD";
31
+ NotificationTab["READ"] = "READ";
32
+ })(NotificationTab || (exports.NotificationTab = NotificationTab = {}));
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AvailBridgeTransactionStatus = exports.AvailBridgeSourceChain = exports.AVAIL_BRIDGE_INDEXER = exports.AVAIL_BRIDGE_API = void 0;
7
+ exports.createClaimNotification = createClaimNotification;
8
+ exports.createWithdrawNotifications = createWithdrawNotifications;
9
+ exports.fetchAllAvailBridgeClaimable = fetchAllAvailBridgeClaimable;
10
+ exports.fetchAvailBridgeTransactions = fetchAvailBridgeTransactions;
11
+ exports.filterClaimableOfAddress = filterClaimableOfAddress;
12
+ exports.getAvailBridgeClaimDescription = getAvailBridgeClaimDescription;
13
+ exports.getClaimDescription = getClaimDescription;
14
+ exports.getIsTabRead = getIsTabRead;
15
+ exports.getReceiveDescription = getReceiveDescription;
16
+ exports.getSendDescription = getSendDescription;
17
+ exports.getWithdrawDescription = getWithdrawDescription;
18
+ exports.hrsToMillisecond = hrsToMillisecond;
19
+ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
20
+ var _utils = require("@subwallet/extension-base/services/chain-service/utils");
21
+ var _consts = require("@subwallet/extension-base/services/inapp-notification-service/consts");
22
+ var _interfaces = require("@subwallet/extension-base/services/inapp-notification-service/interfaces");
23
+ var _types = require("@subwallet/extension-base/types");
24
+ var _utils2 = require("@subwallet/extension-base/utils");
25
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
26
+ // SPDX-License-Identifier: Apache-2.0
27
+
28
+ /* Description */
29
+ function getWithdrawDescription(amount, symbol, stakingType) {
30
+ if (stakingType === _types.YieldPoolType.LIQUID_STAKING) {
31
+ return `${amount} ${symbol} ready to withdraw from ${symbol} liquid staking. Click to withdraw now!`;
32
+ }
33
+ return `${amount} ${symbol} ready to withdraw from ${symbol} staking. Click to withdraw now!`;
34
+ }
35
+ function getClaimDescription(amount, symbol) {
36
+ return `${amount} ${symbol} ready to claim from ${symbol} staking. Click to claim now!`;
37
+ }
38
+ function getSendDescription(amount, symbol) {
39
+ return `You have just sent ${amount} ${symbol}`;
40
+ }
41
+ function getReceiveDescription(amount, symbol) {
42
+ return `You have just received ${amount} ${symbol}`;
43
+ }
44
+ function getAvailBridgeClaimDescription(amount, symbol) {
45
+ return `${amount} ${symbol} ready to claim from ${symbol} cross-chain transfer. Click to claim now!`;
46
+ }
47
+ /* Description */
48
+
49
+ function getIsTabRead(notificationTab) {
50
+ if (notificationTab === _interfaces.NotificationTab.UNREAD) {
51
+ return false;
52
+ }
53
+ if (notificationTab === _interfaces.NotificationTab.READ) {
54
+ return true;
55
+ }
56
+ return undefined;
57
+ }
58
+ function createWithdrawNotification(amount, address, symbol, stakingSlug, stakingType) {
59
+ const actionType = _interfaces.NotificationActionType.WITHDRAW;
60
+ const extrinsicType = _KoniTypes.ExtrinsicType.STAKING_WITHDRAW;
61
+ const time = Date.now();
62
+ return {
63
+ id: `${actionType}___${stakingSlug}___${time}`,
64
+ title: _consts.NotificationTitleMap[actionType].replace('{{tokenSymbol}}', symbol),
65
+ description: _consts.NotificationDescriptionMap[actionType](amount, symbol, stakingType),
66
+ address,
67
+ time,
68
+ extrinsicType,
69
+ isRead: false,
70
+ actionType,
71
+ metadata: {
72
+ stakingType,
73
+ stakingSlug
74
+ }
75
+ };
76
+ }
77
+ function createWithdrawNotifications(unstakingInfos, tokenInfo, address, stakingSlug, stakingType) {
78
+ const allWithdrawNotifications = [];
79
+ for (const unstaking of unstakingInfos) {
80
+ if (unstaking.status !== _types.UnstakingStatus.CLAIMABLE) {
81
+ continue;
82
+ }
83
+ const rawClaimableAmount = unstaking.claimable;
84
+ const decimals = (0, _utils._getAssetDecimals)(tokenInfo);
85
+ const symbol = (0, _utils._getAssetSymbol)(tokenInfo);
86
+ const amount = (0, _utils2.formatNumber)(rawClaimableAmount, decimals);
87
+ allWithdrawNotifications.push(createWithdrawNotification(amount, address, symbol, stakingSlug, stakingType));
88
+ }
89
+ return allWithdrawNotifications;
90
+ }
91
+ function createClaimNotification(claimItemInfo, tokenInfo) {
92
+ const {
93
+ address,
94
+ slug,
95
+ type,
96
+ unclaimedReward = '0'
97
+ } = claimItemInfo;
98
+ const decimals = (0, _utils._getAssetDecimals)(tokenInfo);
99
+ const symbol = (0, _utils._getAssetSymbol)(tokenInfo);
100
+ const amount = (0, _utils2.formatNumber)(unclaimedReward, decimals);
101
+ const actionType = _interfaces.NotificationActionType.CLAIM;
102
+ const extrinsicType = _KoniTypes.ExtrinsicType.STAKING_CLAIM_REWARD;
103
+ const time = Date.now();
104
+ return {
105
+ id: `${actionType}___${slug}___${time}`,
106
+ title: _consts.NotificationTitleMap[actionType].replace('{{tokenSymbol}}', symbol),
107
+ description: _consts.NotificationDescriptionMap[actionType](amount, symbol),
108
+ address,
109
+ time,
110
+ extrinsicType,
111
+ isRead: false,
112
+ actionType,
113
+ metadata: {
114
+ stakingType: type,
115
+ stakingSlug: slug
116
+ }
117
+ };
118
+ }
119
+
120
+ // todo: can refactor utils and const of avail bridge to a new file. Also check in /transfer/xcm/availBridge.ts file
121
+
122
+ const AVAIL_BRIDGE_INDEXER = {
123
+ AVAIL_MAINNET: 'https://bridge-indexer.avail.so',
124
+ AVAIL_TESTNET: 'https://turing-bridge-indexer.fra.avail.so'
125
+ };
126
+ exports.AVAIL_BRIDGE_INDEXER = AVAIL_BRIDGE_INDEXER;
127
+ const AVAIL_BRIDGE_API = {
128
+ AVAIL_MAINNET: 'https://bridge-api.avail.so',
129
+ AVAIL_TESTNET: 'https://turing-bridge-api.fra.avail.so'
130
+ };
131
+ exports.AVAIL_BRIDGE_API = AVAIL_BRIDGE_API;
132
+ let AvailBridgeTransactionStatus;
133
+ exports.AvailBridgeTransactionStatus = AvailBridgeTransactionStatus;
134
+ (function (AvailBridgeTransactionStatus) {
135
+ AvailBridgeTransactionStatus["READY_TO_CLAIM"] = "READY_TO_CLAIM";
136
+ AvailBridgeTransactionStatus["CLAIMED"] = "CLAIMED";
137
+ AvailBridgeTransactionStatus["BRIDGED"] = "BRIDGED";
138
+ })(AvailBridgeTransactionStatus || (exports.AvailBridgeTransactionStatus = AvailBridgeTransactionStatus = {}));
139
+ let AvailBridgeSourceChain;
140
+ exports.AvailBridgeSourceChain = AvailBridgeSourceChain;
141
+ (function (AvailBridgeSourceChain) {
142
+ AvailBridgeSourceChain["AVAIL"] = "AVAIL";
143
+ AvailBridgeSourceChain["ETHEREUM"] = "ETHEREUM";
144
+ })(AvailBridgeSourceChain || (exports.AvailBridgeSourceChain = AvailBridgeSourceChain = {}));
145
+ async function fetchAllAvailBridgeClaimable(address, sourceChain, isTestnet) {
146
+ const transactions = [];
147
+ let isContinue = true;
148
+ let page = 0;
149
+ const pageSize = 100;
150
+ while (isContinue) {
151
+ const response = await fetchAvailBridgeTransactions(address, sourceChain, AvailBridgeTransactionStatus.READY_TO_CLAIM, pageSize, page, isTestnet);
152
+ if (!response) {
153
+ break;
154
+ }
155
+ transactions.push(...filterClaimableOfAddress(address, response.data.result));
156
+ isContinue = response.data.paginationData.hasNextPage;
157
+ page = page + 1;
158
+ }
159
+ return transactions;
160
+ }
161
+ async function fetchAvailBridgeTransactions(userAddress, sourceChain, status) {
162
+ let pageSize = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 100;
163
+ let page = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
164
+ let isTestnet = arguments.length > 5 ? arguments[5] : undefined;
165
+ const params = new URLSearchParams({
166
+ userAddress,
167
+ sourceChain,
168
+ status,
169
+ pageSize: pageSize.toString(),
170
+ page: page.toString()
171
+ });
172
+ try {
173
+ const api = isTestnet ? AVAIL_BRIDGE_INDEXER.AVAIL_TESTNET : AVAIL_BRIDGE_INDEXER.AVAIL_MAINNET;
174
+ const rawResponse = await fetch(`${api}/transactions?${params.toString()}`, {
175
+ method: 'GET',
176
+ headers: {
177
+ 'Content-Type': 'application/json',
178
+ 'Access-Control-Allow-Origin': '*'
179
+ },
180
+ credentials: 'omit'
181
+ });
182
+ if (!rawResponse.ok) {
183
+ console.error('Error fetching claimable bridge transactions');
184
+ return undefined;
185
+ }
186
+ return await rawResponse.json();
187
+ } catch (e) {
188
+ console.error(e);
189
+ return undefined;
190
+ }
191
+ }
192
+ function filterClaimableOfAddress(address, transactions) {
193
+ return transactions.filter(transaction => transaction.receiverAddress.toLowerCase() === address.toLowerCase());
194
+ }
195
+ function hrsToMillisecond(hours) {
196
+ return hours * 60 * 60 * 1000;
197
+ }
@@ -61,9 +61,15 @@ class AccountContext {
61
61
  isUnifiedAccount(proxyId) {
62
62
  return this.state.isUnifiedAccount(proxyId);
63
63
  }
64
+ belongUnifiedAccount(address) {
65
+ return this.state.belongUnifiedAccount(address);
66
+ }
64
67
  addressesByProxyId(proxyId) {
65
68
  return this.state.addressesByProxyId(proxyId);
66
69
  }
70
+ getCurrentAccountProxyName(proxyId) {
71
+ return this.state.getAccountProxyName(proxyId);
72
+ }
67
73
 
68
74
  /* Modify accounts */
69
75
 
@@ -104,6 +110,9 @@ class AccountContext {
104
110
  let allowGetAllAccount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
105
111
  return this.state.getDecodedAddresses(accountProxy, allowGetAllAccount);
106
112
  }
113
+ getAllAddresses() {
114
+ return this.state.getAllAddresses();
115
+ }
107
116
 
108
117
  /* Get address for another service */
109
118
 
@@ -274,6 +274,10 @@ class AccountState {
274
274
 
275
275
  /* Current account */
276
276
 
277
+ getAccountProxyName(proxyId) {
278
+ return this.accounts[proxyId].name;
279
+ }
280
+
277
281
  /* Check address exists */
278
282
  checkAddressExists(addresses) {
279
283
  for (const address of addresses) {
@@ -41,9 +41,17 @@ class SettingService {
41
41
  }
42
42
  getSettings(update) {
43
43
  this.settingsStore.get('Settings', value => {
44
+ var _value$notificationSe, _value$notificationSe2, _value$notificationSe3;
44
45
  update({
45
46
  ..._constants2.DEFAULT_SETTING,
46
- ...(value || {})
47
+ ...(value || {}),
48
+ notificationSetup: {
49
+ isEnabled: (_value$notificationSe = value === null || value === void 0 ? void 0 : (_value$notificationSe2 = value.notificationSetup) === null || _value$notificationSe2 === void 0 ? void 0 : _value$notificationSe2.isEnabled) !== null && _value$notificationSe !== void 0 ? _value$notificationSe : _constants2.DEFAULT_SETTING.notificationSetup.isEnabled,
50
+ showNotice: {
51
+ ..._constants2.DEFAULT_SETTING.notificationSetup.showNotice,
52
+ ...((value === null || value === void 0 ? void 0 : (_value$notificationSe3 = value.notificationSetup) === null || _value$notificationSe3 === void 0 ? void 0 : _value$notificationSe3.showNotice) || {})
53
+ }
54
+ }
47
55
  });
48
56
  });
49
57
  }