@subwallet/extension-base 1.3.2-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 (124) 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/api/nft/assethub_nft/index.js +30 -7
  11. package/cjs/koni/background/handlers/Extension.js +110 -23
  12. package/cjs/koni/background/handlers/State.js +5 -2
  13. package/cjs/packageInfo.js +1 -1
  14. package/cjs/services/balance-service/helpers/process.js +2 -1
  15. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +11 -12
  16. package/cjs/services/balance-service/transfer/xcm/availBridge.js +198 -0
  17. package/cjs/services/balance-service/transfer/xcm/index.js +50 -5
  18. package/cjs/services/chain-service/handler/EvmApi.js +12 -21
  19. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +29 -0
  20. package/cjs/services/chain-service/index.js +44 -13
  21. package/cjs/services/chain-service/utils/index.js +20 -0
  22. package/cjs/services/earning-service/handlers/base.js +14 -4
  23. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +10 -2
  24. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +2 -0
  25. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +2 -0
  26. package/cjs/services/earning-service/handlers/native-staking/tao.js +25 -38
  27. package/cjs/services/earning-service/handlers/nomination-pool/index.js +9 -4
  28. package/cjs/services/earning-service/service.js +5 -0
  29. package/cjs/services/earning-service/utils/index.js +0 -11
  30. package/cjs/services/inapp-notification-service/consts.js +31 -0
  31. package/cjs/services/inapp-notification-service/index.js +260 -0
  32. package/cjs/services/inapp-notification-service/interfaces.js +32 -0
  33. package/cjs/services/inapp-notification-service/utils.js +197 -0
  34. package/cjs/services/keyring-service/context/account-context.js +9 -0
  35. package/cjs/services/keyring-service/context/state.js +4 -0
  36. package/cjs/services/setting-service/SettingService.js +9 -1
  37. package/cjs/services/setting-service/constants.js +16 -1
  38. package/cjs/services/storage-service/DatabaseService.js +42 -3
  39. package/cjs/services/storage-service/databases/index.js +3 -0
  40. package/cjs/services/storage-service/db-stores/InappNotification.js +81 -0
  41. package/cjs/services/transaction-service/index.js +13 -0
  42. package/cjs/services/transaction-service/utils.js +3 -0
  43. package/cjs/types/avail-bridge/index.js +1 -0
  44. package/cjs/types/notification/index.js +1 -0
  45. package/cjs/utils/account/transform.js +9 -5
  46. package/cjs/utils/staticData/index.js +7 -2
  47. package/constants/blocked-actions-list.js +1 -2
  48. package/constants/index.d.ts +2 -0
  49. package/constants/index.js +3 -1
  50. package/constants/remind-notification-time.d.ts +2 -0
  51. package/constants/remind-notification-time.js +7 -0
  52. package/core/logic-validation/transfer.js +12 -6
  53. package/core/substrate/xcm-parser.d.ts +1 -0
  54. package/core/substrate/xcm-parser.js +12 -1
  55. package/koni/api/contract-handler/utils/avail_bridge_abi.json +1659 -0
  56. package/koni/api/contract-handler/utils/avail_test_bridge_abi.json +1692 -0
  57. package/koni/api/contract-handler/utils/index.d.ts +4 -0
  58. package/koni/api/contract-handler/utils/index.js +15 -0
  59. package/koni/api/nft/assethub_nft/index.d.ts +2 -0
  60. package/koni/api/nft/assethub_nft/index.js +30 -7
  61. package/koni/background/handlers/Extension.d.ts +7 -0
  62. package/koni/background/handlers/Extension.js +112 -25
  63. package/koni/background/handlers/State.d.ts +2 -0
  64. package/koni/background/handlers/State.js +5 -2
  65. package/package.json +54 -6
  66. package/packageInfo.js +1 -1
  67. package/services/balance-service/helpers/process.js +2 -1
  68. package/services/balance-service/helpers/subscribe/substrate/index.js +5 -6
  69. package/services/balance-service/transfer/xcm/availBridge.d.ts +45 -0
  70. package/services/balance-service/transfer/xcm/availBridge.js +186 -0
  71. package/services/balance-service/transfer/xcm/index.d.ts +8 -8
  72. package/services/balance-service/transfer/xcm/index.js +46 -5
  73. package/services/chain-service/handler/EvmApi.js +12 -21
  74. package/services/chain-service/handler/SubstrateChainHandler.d.ts +2 -0
  75. package/services/chain-service/handler/SubstrateChainHandler.js +29 -0
  76. package/services/chain-service/index.d.ts +2 -0
  77. package/services/chain-service/index.js +45 -14
  78. package/services/chain-service/types.d.ts +2 -1
  79. package/services/chain-service/utils/index.d.ts +3 -0
  80. package/services/chain-service/utils/index.js +14 -0
  81. package/services/earning-service/handlers/base.d.ts +2 -0
  82. package/services/earning-service/handlers/base.js +11 -1
  83. package/services/earning-service/handlers/native-staking/amplitude.js +10 -2
  84. package/services/earning-service/handlers/native-staking/para-chain.js +2 -0
  85. package/services/earning-service/handlers/native-staking/relay-chain.js +2 -0
  86. package/services/earning-service/handlers/native-staking/tao.d.ts +15 -11
  87. package/services/earning-service/handlers/native-staking/tao.js +21 -38
  88. package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -1
  89. package/services/earning-service/handlers/nomination-pool/index.js +9 -4
  90. package/services/earning-service/service.d.ts +2 -0
  91. package/services/earning-service/service.js +5 -0
  92. package/services/earning-service/utils/index.d.ts +0 -2
  93. package/services/earning-service/utils/index.js +0 -10
  94. package/services/inapp-notification-service/consts.d.ts +18 -0
  95. package/services/inapp-notification-service/consts.js +22 -0
  96. package/services/inapp-notification-service/index.d.ts +37 -0
  97. package/services/inapp-notification-service/index.js +252 -0
  98. package/services/inapp-notification-service/interfaces.d.ts +77 -0
  99. package/services/inapp-notification-service/interfaces.js +24 -0
  100. package/services/inapp-notification-service/utils.d.ts +55 -0
  101. package/services/inapp-notification-service/utils.js +173 -0
  102. package/services/keyring-service/context/account-context.d.ts +3 -0
  103. package/services/keyring-service/context/account-context.js +9 -0
  104. package/services/keyring-service/context/state.d.ts +1 -0
  105. package/services/keyring-service/context/state.js +4 -0
  106. package/services/setting-service/SettingService.js +9 -1
  107. package/services/setting-service/constants.d.ts +2 -0
  108. package/services/setting-service/constants.js +15 -0
  109. package/services/storage-service/DatabaseService.d.ts +15 -0
  110. package/services/storage-service/DatabaseService.js +42 -3
  111. package/services/storage-service/databases/index.d.ts +2 -0
  112. package/services/storage-service/databases/index.js +3 -0
  113. package/services/storage-service/db-stores/InappNotification.d.ts +14 -0
  114. package/services/storage-service/db-stores/InappNotification.js +73 -0
  115. package/services/transaction-service/index.js +13 -0
  116. package/services/transaction-service/utils.js +3 -0
  117. package/types/avail-bridge/index.d.ts +6 -0
  118. package/types/avail-bridge/index.js +1 -0
  119. package/types/notification/index.d.ts +9 -0
  120. package/types/notification/index.js +1 -0
  121. package/utils/account/transform.js +9 -5
  122. package/utils/staticData/index.d.ts +5 -1
  123. package/utils/staticData/index.js +5 -2
  124. package/utils/staticData/remindNotificationTime.json +1 -0
@@ -7,7 +7,8 @@ exports.default = void 0;
7
7
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
8
8
  var _constants = require("@subwallet/extension-base/constants");
9
9
  var _constants2 = require("@subwallet/extension-base/services/earning-service/constants");
10
- var _utils = require("@subwallet/extension-base/utils");
10
+ var _utils = require("@subwallet/extension-base/services/inapp-notification-service/utils");
11
+ var _utils2 = require("@subwallet/extension-base/utils");
11
12
  var _util = require("@polkadot/util");
12
13
  // Copyright 2019-2022 @subwallet/extension-base
13
14
  // SPDX-License-Identifier: Apache-2.0
@@ -82,7 +83,8 @@ class BasePoolHandler {
82
83
  const decimals = this.nativeToken.decimals || 0;
83
84
  const defaultMaintainBalance = new _util.BN(1).mul(_util.BN_TEN.pow(new _util.BN(decimals)));
84
85
  const ed = new _util.BN(this.nativeToken.minAmount || '0');
85
- const maintainBalance = ed.gte(defaultMaintainBalance) ? new _util.BN(15).mul(ed).div(_util.BN_TEN) : defaultMaintainBalance;
86
+ const calculateMaintainBalance = new _util.BN(15).mul(ed).div(_util.BN_TEN);
87
+ const maintainBalance = ed.gte(defaultMaintainBalance) ? calculateMaintainBalance : defaultMaintainBalance;
86
88
  return maintainBalance.toString();
87
89
  }
88
90
  get metadataInfo() {
@@ -97,6 +99,14 @@ class BasePoolHandler {
97
99
  availableMethod: this.availableMethod
98
100
  };
99
101
  }
102
+ async createWithdrawNotifications(unstakingInfos, tokenInfo, address) {
103
+ const notifications = (0, _utils.createWithdrawNotifications)(unstakingInfos, tokenInfo, address, this.baseInfo.slug, this.type);
104
+ await this.state.inappNotificationService.validateAndWriteNotificationsToDB(notifications, address);
105
+ }
106
+ async createClaimNotification(claimItemInfo, tokenInfo) {
107
+ const notification = (0, _utils.createClaimNotification)(claimItemInfo, tokenInfo);
108
+ await this.state.inappNotificationService.validateAndWriteNotificationsToDB([notification], claimItemInfo.address);
109
+ }
100
110
 
101
111
  /** Can mint when haven't enough native token (use input token for fee) */
102
112
  get isPoolSupportAlternativeFee() {
@@ -106,7 +116,7 @@ class BasePoolHandler {
106
116
  return await this.state.earningService.getYieldPool(this.slug);
107
117
  }
108
118
  async getPoolPosition(address) {
109
- const originAddress = (0, _utils.reformatAddress)(address);
119
+ const originAddress = (0, _utils2.reformatAddress)(address);
110
120
  return await this.state.earningService.getYieldPosition(originAddress, this.slug);
111
121
  }
112
122
 
@@ -139,7 +149,7 @@ class BasePoolHandler {
139
149
  const bnNativeTokenBalance = new _util.BN(nativeTokenBalance.value);
140
150
  const bnMinBalanceToJoin = new _util.BN(((_poolInfo$statistic2 = poolInfo.statistic) === null || _poolInfo$statistic2 === void 0 ? void 0 : (_poolInfo$statistic2$ = _poolInfo$statistic2.earningThreshold) === null || _poolInfo$statistic2$ === void 0 ? void 0 : _poolInfo$statistic2$.join) || '0').add(new _util.BN(poolInfo.metadata.maintainBalance));
141
151
  if (bnNativeTokenBalance.lte(bnMinBalanceToJoin)) {
142
- const minJoin = (0, _utils.formatNumber)(bnMinBalanceToJoin.toString(), this.nativeToken.decimals || 0);
152
+ const minJoin = (0, _utils2.formatNumber)(bnMinBalanceToJoin.toString(), this.nativeToken.decimals || 0);
143
153
  const originChain = this.state.getChainInfo(nativeTokenInfo.originChain);
144
154
  return {
145
155
  passed: false,
@@ -166,6 +166,7 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
166
166
  }
167
167
  const totalBalance = new _util.BN(activeStake).add(new _util.BN(unstakingBalance));
168
168
  const stakingStatus = (0, _utils.getEarningStatusByNominations)(new _util.BN(activeStake), nominationList);
169
+ await this.createWithdrawNotifications(unstakingList, this.nativeToken, address);
169
170
  return {
170
171
  status: stakingStatus,
171
172
  balanceToken: this.nativeToken.slug,
@@ -251,13 +252,20 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
251
252
  if (cancel) {
252
253
  return;
253
254
  }
254
- callBack({
255
+ const earningRewardItem = {
255
256
  ...this.baseInfo,
256
257
  address: address,
257
258
  type: this.type,
258
259
  unclaimedReward: _unclaimedReward.toString(),
259
260
  state: _KoniTypes.APIItemState.READY
260
- });
261
+ };
262
+
263
+ // TODO: Enable this when claim action is ready
264
+ // if (_unclaimedReward.toString() !== '0') {
265
+ // await this.createClaimNotification(earningRewardItem, this.nativeToken);
266
+ // }
267
+
268
+ callBack(earningRewardItem);
261
269
  }));
262
270
  }
263
271
  return () => {
@@ -216,6 +216,8 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
216
216
  const totalStake = bnTotalStake.toString();
217
217
  const activeStake = bnTotalActiveStake.toString();
218
218
  const unstakingBalance = bnTotalUnstaking.toString();
219
+ const tokenInfo = this.state.chainService.getAssetBySlug(this.nativeToken.slug);
220
+ await this.createWithdrawNotifications(Object.values(unstakingMap), tokenInfo, address);
219
221
  return {
220
222
  status: stakingStatus,
221
223
  totalStake,
@@ -178,6 +178,8 @@ class RelayNativeStakingPoolHandler extends _base.default {
178
178
  targetTimestampMs: targetTimestampMs
179
179
  });
180
180
  });
181
+ const tokenInfo = this.state.chainService.getAssetBySlug(this.nativeToken.slug);
182
+ await this.createWithdrawNotifications(unstakingList, tokenInfo, address);
181
183
  return {
182
184
  status: stakingStatus,
183
185
  balanceToken: this.nativeToken.slug,
@@ -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");
@@ -20,16 +20,18 @@ var _utils3 = require("../../utils");
20
20
  // Copyright 2019-2022 @subwallet/extension-base
21
21
  // SPDX-License-Identifier: Apache-2.0
22
22
 
23
- // interface ValidatorName {
24
- // count: number;
25
- // delegates: {
26
- // name: string;
27
- // }[];
28
- // }
29
23
  const BITTENSOR_API_KEY_1 = process.env.BITTENSOR_API_KEY_1 || '';
30
24
  exports.BITTENSOR_API_KEY_1 = BITTENSOR_API_KEY_1;
31
25
  const BITTENSOR_API_KEY_2 = process.env.BITTENSOR_API_KEY_2 || '';
32
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;
33
35
  function random() {
34
36
  for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
35
37
  keys[_key] = arguments[_key];
@@ -39,7 +41,7 @@ function random() {
39
41
  return validKeys[randomIndex];
40
42
  }
41
43
  const bittensorApiKey = () => {
42
- 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);
43
45
  };
44
46
 
45
47
  /* Fetch data */
@@ -47,7 +49,7 @@ exports.bittensorApiKey = bittensorApiKey;
47
49
  async function fetchDelegates() {
48
50
  const apiKey = bittensorApiKey();
49
51
  return new Promise(function (resolve) {
50
- fetch('https://api.taostats.io/api/v1/validator?order=amount%3Adesc&limit=100', {
52
+ fetch('https://api-prod-v2.taostats.io/api/validator/latest/v1', {
51
53
  method: 'GET',
52
54
  headers: {
53
55
  'Content-Type': 'application/json',
@@ -61,7 +63,7 @@ async function fetchDelegates() {
61
63
  async function fetchTaoDelegateState(address) {
62
64
  const apiKey = bittensorApiKey();
63
65
  return new Promise(function (resolve) {
64
- fetch(`https://api.taostats.io/api/v1/delegate/balance?nominator_address=${address}`, {
66
+ fetch(`https://api-prod-v2.taostats.io/api/delegation/balance/latest/v1?nominator=${address}`, {
65
67
  method: 'GET',
66
68
  headers: {
67
69
  'Content-Type': 'application/json',
@@ -95,21 +97,12 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
95
97
  }
96
98
  /* Unimplemented function */
97
99
 
98
- // async fetchDelegatesInfo (address: string): Promise<ValidatorName> {
99
- // const apiKey = this.bittensorApiKey;
100
-
101
- // return new Promise(function (resolve) {
102
- // fetch(`https://api.taostats.io/api/v1/delegate/info?address=${address}`, {
103
- // method: 'GET',
104
- // headers: {
105
- // 'Content-Type': 'application/json',
106
- // Authorization: `${apiKey}`
107
- // }
108
- // }).then((resp) => {
109
- // resolve(resp.json());
110
- // }).catch(console.error);
111
- // });
112
- // }
100
+ get maintainBalance() {
101
+ const ed = new _util.BN(this.nativeToken.minAmount || '0');
102
+ const calculateMaintainBalance = new _util.BN(15).mul(ed).div(_util.BN_TEN);
103
+ const maintainBalance = calculateMaintainBalance;
104
+ return maintainBalance.toString();
105
+ }
113
106
 
114
107
  /* Subscribe pool info */
115
108
 
@@ -242,11 +235,11 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
242
235
  const owner = (0, _utils2.reformatAddress)(useAddresses[i], 42);
243
236
  const delegatorState = [];
244
237
  let bnTotalBalance = _util.BN_ZERO;
245
- const delegateStateInfo = rawDelegateStateInfo.items;
238
+ const delegateStateInfo = rawDelegateStateInfo.data;
246
239
  for (const delegate of delegateStateInfo) {
247
240
  bnTotalBalance = bnTotalBalance.add(new _util.BN(delegate.balance));
248
241
  delegatorState.push({
249
- owner: delegate.delegate_address.ss58,
242
+ owner: delegate.delegate.ss58,
250
243
  amount: delegate.balance.toString()
251
244
  });
252
245
  }
@@ -329,11 +322,11 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
329
322
  const getNominatorMinRequiredStake = this.substrateApi.api.query.subtensorModule.nominatorMinRequiredStake();
330
323
  const nominatorMinRequiredStake = (await getNominatorMinRequiredStake).toString();
331
324
  const bnMinBond = new _util.BN(nominatorMinRequiredStake);
332
- const validatorList = topValidator.validators;
325
+ const validatorList = topValidator.data;
333
326
  const validatorAddresses = Object.keys(validatorList);
334
327
  const results = await Promise.all(validatorAddresses.map(i => {
335
- const address = validatorList[i].hot_key.ss58;
336
- const bnTotalStake = new _util.BN(validatorList[i].amount);
328
+ const address = validatorList[i].hotkey.ss58;
329
+ const bnTotalStake = new _util.BN(validatorList[i].stake);
337
330
  const bnOwnStake = new _util.BN(validatorList[i].validator_stake);
338
331
  const otherStake = bnTotalStake.sub(bnOwnStake);
339
332
  const nominatorCount = validatorList[i].nominators;
@@ -341,12 +334,7 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
341
334
  const roundedCommission = (parseFloat(commission) * 100).toFixed(0);
342
335
  const apr = (parseFloat(validatorList[i].apr) / 10 ** 9 * 100).toFixed(2);
343
336
  const apyCalculate = (0, _utils3.calculateReward)(parseFloat(apr));
344
-
345
- // let name = '';
346
- // const delegateInfo = await this.fetchDelegatesInfo(address);
347
-
348
- // name = delegateInfo.delegates[0]?.name || address;
349
-
337
+ const name = validatorList[i].name || address;
350
338
  return {
351
339
  address: address,
352
340
  totalStake: bnTotalStake.toString(),
@@ -360,10 +348,9 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
360
348
  isVerified: false,
361
349
  chain: this.chain,
362
350
  isCrowded: false,
363
- identity: address // name
351
+ identity: name
364
352
  };
365
353
  }));
366
-
367
354
  return results;
368
355
  }
369
356
  async getPoolTargets() {
@@ -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) {
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.applyDecimal = applyDecimal;
7
7
  exports.calculateReward = calculateReward;
8
- exports.getTaoTotalStake = getTaoTotalStake;
9
8
  exports.isActionFromValidator = isActionFromValidator;
10
9
  exports.isNominationPool = exports.isNativeStakingPool = exports.isLiquidPool = exports.isLendingPool = void 0;
11
10
  exports.parseIdentity = parseIdentity;
@@ -141,14 +140,4 @@ exports.isLendingPool = isLendingPool;
141
140
  function applyDecimal(bnNumber, decimals) {
142
141
  const bnDecimals = new _util.BN((10 ** decimals).toString());
143
142
  return bnNumber.div(bnDecimals);
144
- }
145
- function getTaoTotalStake(rawDelegateState) {
146
- const nodeInfos = rawDelegateState.items;
147
- const stakes = nodeInfos.map(stake => stake.balance);
148
- let totalStake = BigInt(0);
149
- for (const _stake of stakes) {
150
- const stakeAmount = BigInt(_stake);
151
- totalStake += stakeAmount;
152
- }
153
- return totalStake;
154
143
  }
@@ -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 = {}));