@subwallet/extension-base 1.3.3-0 → 1.3.5-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 (134) hide show
  1. package/background/KoniTypes.d.ts +14 -1
  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/config.js +1 -1
  11. package/cjs/koni/api/nft/index.js +9 -0
  12. package/cjs/koni/api/nft/rari/index.js +87 -0
  13. package/cjs/koni/api/yield/helper/utils.js +1 -1
  14. package/cjs/koni/background/handlers/Extension.js +110 -23
  15. package/cjs/koni/background/handlers/State.js +5 -2
  16. package/cjs/packageInfo.js +1 -1
  17. package/cjs/services/balance-service/helpers/process.js +2 -1
  18. package/cjs/services/balance-service/helpers/subscribe/index.js +5 -0
  19. package/cjs/services/balance-service/index.js +1 -1
  20. package/cjs/services/balance-service/transfer/xcm/availBridge.js +198 -0
  21. package/cjs/services/balance-service/transfer/xcm/index.js +50 -5
  22. package/cjs/services/chain-service/constants.js +2 -1
  23. package/cjs/services/chain-service/handler/EvmApi.js +12 -21
  24. package/cjs/services/chain-service/handler/EvmChainHandler.js +0 -2
  25. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +73 -40
  26. package/cjs/services/chain-service/index.js +44 -13
  27. package/cjs/services/chain-service/utils/index.js +20 -0
  28. package/cjs/services/earning-service/handlers/base.js +12 -3
  29. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +11 -3
  30. package/cjs/services/earning-service/handlers/native-staking/astar.js +1 -1
  31. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +3 -1
  32. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +3 -1
  33. package/cjs/services/earning-service/handlers/native-staking/tao.js +11 -3
  34. package/cjs/services/earning-service/handlers/nomination-pool/index.js +14 -12
  35. package/cjs/services/earning-service/service.js +5 -0
  36. package/cjs/services/inapp-notification-service/consts.js +31 -0
  37. package/cjs/services/inapp-notification-service/index.js +260 -0
  38. package/cjs/services/inapp-notification-service/interfaces.js +32 -0
  39. package/cjs/services/inapp-notification-service/utils.js +197 -0
  40. package/cjs/services/keyring-service/context/account-context.js +9 -0
  41. package/cjs/services/keyring-service/context/state.js +4 -0
  42. package/cjs/services/setting-service/SettingService.js +9 -1
  43. package/cjs/services/setting-service/constants.js +16 -1
  44. package/cjs/services/storage-service/DatabaseService.js +42 -3
  45. package/cjs/services/storage-service/databases/index.js +3 -0
  46. package/cjs/services/storage-service/db-stores/InappNotification.js +81 -0
  47. package/cjs/services/transaction-service/index.js +18 -4
  48. package/cjs/types/avail-bridge/index.js +1 -0
  49. package/cjs/types/notification/index.js +1 -0
  50. package/cjs/utils/account/transform.js +9 -5
  51. package/cjs/utils/staticData/index.js +7 -2
  52. package/constants/blocked-actions-list.js +1 -2
  53. package/constants/index.d.ts +2 -0
  54. package/constants/index.js +3 -1
  55. package/constants/remind-notification-time.d.ts +2 -0
  56. package/constants/remind-notification-time.js +7 -0
  57. package/core/logic-validation/transfer.js +12 -6
  58. package/core/substrate/xcm-parser.d.ts +1 -0
  59. package/core/substrate/xcm-parser.js +12 -1
  60. package/koni/api/contract-handler/utils/avail_bridge_abi.json +1659 -0
  61. package/koni/api/contract-handler/utils/avail_test_bridge_abi.json +1692 -0
  62. package/koni/api/contract-handler/utils/index.d.ts +7 -2
  63. package/koni/api/contract-handler/utils/index.js +15 -0
  64. package/koni/api/nft/config.js +1 -1
  65. package/koni/api/nft/index.js +9 -0
  66. package/koni/api/nft/rari/index.d.ts +7 -0
  67. package/koni/api/nft/rari/index.js +80 -0
  68. package/koni/api/yield/helper/utils.js +1 -1
  69. package/koni/background/handlers/Extension.d.ts +7 -0
  70. package/koni/background/handlers/Extension.js +112 -25
  71. package/koni/background/handlers/State.d.ts +2 -0
  72. package/koni/background/handlers/State.js +5 -2
  73. package/package.json +59 -6
  74. package/packageInfo.js +1 -1
  75. package/services/balance-service/helpers/process.js +2 -1
  76. package/services/balance-service/helpers/subscribe/index.js +5 -0
  77. package/services/balance-service/index.js +2 -2
  78. package/services/balance-service/transfer/xcm/availBridge.d.ts +45 -0
  79. package/services/balance-service/transfer/xcm/availBridge.js +186 -0
  80. package/services/balance-service/transfer/xcm/index.d.ts +8 -8
  81. package/services/balance-service/transfer/xcm/index.js +46 -5
  82. package/services/chain-service/constants.d.ts +1 -0
  83. package/services/chain-service/constants.js +2 -1
  84. package/services/chain-service/handler/EvmApi.js +12 -21
  85. package/services/chain-service/handler/EvmChainHandler.js +0 -2
  86. package/services/chain-service/handler/SubstrateChainHandler.d.ts +3 -2
  87. package/services/chain-service/handler/SubstrateChainHandler.js +73 -40
  88. package/services/chain-service/index.d.ts +2 -0
  89. package/services/chain-service/index.js +45 -14
  90. package/services/chain-service/types.d.ts +2 -1
  91. package/services/chain-service/utils/index.d.ts +3 -0
  92. package/services/chain-service/utils/index.js +14 -0
  93. package/services/earning-service/handlers/base.d.ts +2 -0
  94. package/services/earning-service/handlers/base.js +9 -0
  95. package/services/earning-service/handlers/native-staking/amplitude.js +11 -3
  96. package/services/earning-service/handlers/native-staking/astar.js +1 -1
  97. package/services/earning-service/handlers/native-staking/para-chain.js +3 -1
  98. package/services/earning-service/handlers/native-staking/relay-chain.js +3 -1
  99. package/services/earning-service/handlers/native-staking/tao.d.ts +4 -0
  100. package/services/earning-service/handlers/native-staking/tao.js +6 -2
  101. package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -1
  102. package/services/earning-service/handlers/nomination-pool/index.js +14 -12
  103. package/services/earning-service/service.d.ts +2 -0
  104. package/services/earning-service/service.js +5 -0
  105. package/services/inapp-notification-service/consts.d.ts +18 -0
  106. package/services/inapp-notification-service/consts.js +22 -0
  107. package/services/inapp-notification-service/index.d.ts +37 -0
  108. package/services/inapp-notification-service/index.js +252 -0
  109. package/services/inapp-notification-service/interfaces.d.ts +77 -0
  110. package/services/inapp-notification-service/interfaces.js +24 -0
  111. package/services/inapp-notification-service/utils.d.ts +55 -0
  112. package/services/inapp-notification-service/utils.js +173 -0
  113. package/services/keyring-service/context/account-context.d.ts +3 -0
  114. package/services/keyring-service/context/account-context.js +9 -0
  115. package/services/keyring-service/context/state.d.ts +1 -0
  116. package/services/keyring-service/context/state.js +4 -0
  117. package/services/setting-service/SettingService.js +9 -1
  118. package/services/setting-service/constants.d.ts +2 -0
  119. package/services/setting-service/constants.js +15 -0
  120. package/services/storage-service/DatabaseService.d.ts +15 -0
  121. package/services/storage-service/DatabaseService.js +42 -3
  122. package/services/storage-service/databases/index.d.ts +2 -0
  123. package/services/storage-service/databases/index.js +3 -0
  124. package/services/storage-service/db-stores/InappNotification.d.ts +14 -0
  125. package/services/storage-service/db-stores/InappNotification.js +73 -0
  126. package/services/transaction-service/index.js +18 -4
  127. package/types/avail-bridge/index.d.ts +6 -0
  128. package/types/avail-bridge/index.js +1 -0
  129. package/types/notification/index.d.ts +9 -0
  130. package/types/notification/index.js +1 -0
  131. package/utils/account/transform.js +9 -5
  132. package/utils/staticData/index.d.ts +5 -1
  133. package/utils/staticData/index.js +5 -2
  134. package/utils/staticData/remindNotificationTime.json +1 -0
@@ -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
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.DEFAULT_UNLOCK_TYPE = exports.DEFAULT_THEME = exports.DEFAULT_SHOW_ZERO_BALANCE = exports.DEFAULT_SHOW_BALANCE = exports.DEFAULT_SETTING = exports.DEFAULT_NOTIFICATION_TYPE = exports.DEFAULT_LANGUAGE = exports.DEFAULT_CURRENCY = exports.DEFAULT_CHAIN_PATROL_ENABLE = exports.DEFAULT_CAMERA_ENABLE = exports.DEFAULT_AUTO_LOCK_TIME = exports.DEFAULT_ALL_LOGO = void 0;
6
+ exports.DEFAULT_UNLOCK_TYPE = exports.DEFAULT_THEME = exports.DEFAULT_SHOW_ZERO_BALANCE = exports.DEFAULT_SHOW_BALANCE = exports.DEFAULT_SETTING = exports.DEFAULT_NOTIFICATION_TYPE = exports.DEFAULT_NOTIFICATION_SETUP = exports.DEFAULT_LANGUAGE = exports.DEFAULT_CURRENCY = exports.DEFAULT_CHAIN_PATROL_ENABLE = exports.DEFAULT_CAMERA_ENABLE = exports.DEFAULT_AUTO_LOCK_TIME = exports.DEFAULT_ALL_LOGO = void 0;
7
7
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
8
8
  var _utils = require("@subwallet/extension-base/utils");
9
9
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
@@ -31,6 +31,20 @@ const DEFAULT_ALL_LOGO = '';
31
31
  exports.DEFAULT_ALL_LOGO = DEFAULT_ALL_LOGO;
32
32
  const DEFAULT_CAMERA_ENABLE = false;
33
33
  exports.DEFAULT_CAMERA_ENABLE = DEFAULT_CAMERA_ENABLE;
34
+ const DEFAULT_NOTIFICATION_SETUP = {
35
+ isEnabled: true,
36
+ showNotice: {
37
+ // send: true,
38
+ // receive: true,
39
+ earningClaim: true,
40
+ earningWithdraw: true,
41
+ availBridgeClaim: true
42
+ // isHideWithdraw: false, // todo: just for test, remove later
43
+ // isHideMarketing: false,
44
+ // isHideAnnouncement: false
45
+ }
46
+ };
47
+ exports.DEFAULT_NOTIFICATION_SETUP = DEFAULT_NOTIFICATION_SETUP;
34
48
  const DEFAULT_SETTING = {
35
49
  language: DEFAULT_LANGUAGE,
36
50
  currency: DEFAULT_CURRENCY,
@@ -43,6 +57,7 @@ const DEFAULT_SETTING = {
43
57
  camera: DEFAULT_CAMERA_ENABLE,
44
58
  timeAutoLock: DEFAULT_AUTO_LOCK_TIME,
45
59
  enableChainPatrol: DEFAULT_CHAIN_PATROL_ENABLE,
60
+ notificationSetup: DEFAULT_NOTIFICATION_SETUP,
46
61
  walletReference: ''
47
62
  };
48
63
  exports.DEFAULT_SETTING = DEFAULT_SETTING;
@@ -10,6 +10,7 @@ var _databases = _interopRequireDefault(require("@subwallet/extension-base/servi
10
10
  var _dbStores = require("@subwallet/extension-base/services/storage-service/db-stores");
11
11
  var _Campaign = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/Campaign"));
12
12
  var _ChainStakingMetadata = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/ChainStakingMetadata"));
13
+ var _InappNotification = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/InappNotification"));
13
14
  var _MantaPay = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/MantaPay"));
14
15
  var _NominatorMetadata = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/NominatorMetadata"));
15
16
  var _YieldPoolStore = _interopRequireDefault(require("@subwallet/extension-base/services/storage-service/db-stores/YieldPoolStore"));
@@ -53,11 +54,13 @@ class DatabaseService {
53
54
  chainStakingMetadata: new _ChainStakingMetadata.default(this._db.chainStakingMetadata),
54
55
  nominatorMetadata: new _NominatorMetadata.default(this._db.nominatorMetadata),
55
56
  mantaPay: new _MantaPay.default(this._db.mantaPay),
56
- campaign: new _Campaign.default(this._db.campaign)
57
+ campaign: new _Campaign.default(this._db.campaign),
57
58
  // assetRef: new AssetRefStore(this._db.assetRef)
59
+
60
+ // inapp notification
61
+ inappNotification: new _InappNotification.default(this._db.inappNotification)
58
62
  };
59
63
  }
60
-
61
64
  async updatePriceStore(priceData) {
62
65
  await this.stores.price.table.put(priceData);
63
66
  }
@@ -370,7 +373,7 @@ class DatabaseService {
370
373
  }
371
374
  async resetWallet(resetAll) {
372
375
  return new Promise((resolve, reject) => {
373
- const stores = [this.stores.balance, this.stores.nft, this.stores.nftCollection, this.stores.crowdloan, this.stores.staking, this.stores.transaction, this.stores.nominatorMetadata];
376
+ const stores = [this.stores.balance, this.stores.nft, this.stores.nftCollection, this.stores.crowdloan, this.stores.staking, this.stores.transaction, this.stores.nominatorMetadata, this.stores.inappNotification];
374
377
  if (resetAll) {
375
378
  stores.push(this.stores.chain, this.stores.asset);
376
379
  }
@@ -457,6 +460,9 @@ class DatabaseService {
457
460
  async updateYieldPositions(data) {
458
461
  await this.stores.yieldPosition.bulkUpsert(data);
459
462
  }
463
+ async getYieldPositions() {
464
+ return this.stores.yieldPosition.getAll();
465
+ }
460
466
  async getYieldPositionByAddress(addresses) {
461
467
  return this.stores.yieldPosition.getByAddress(addresses);
462
468
  }
@@ -486,6 +492,39 @@ class DatabaseService {
486
492
  upsertCampaign(campaign) {
487
493
  return this.stores.campaign.upsertCampaign(campaign);
488
494
  }
495
+
496
+ /* Inapp Notification */
497
+
498
+ getNotification(id) {
499
+ return this.stores.inappNotification.getNotificationInfo(id);
500
+ }
501
+ updateNotification(notification) {
502
+ return this.stores.inappNotification.upsert(notification);
503
+ }
504
+ async getNotificationsByParams(params) {
505
+ return this.stores.inappNotification.getNotificationsByParams(params);
506
+ }
507
+ cleanUpOldNotifications(overdueTime) {
508
+ return this.stores.inappNotification.cleanUpOldNotifications(overdueTime);
509
+ }
510
+ subscribeUnreadNotificationsCountMap() {
511
+ return this.stores.inappNotification.subscribeUnreadNotificationsCount();
512
+ }
513
+ getUnreadNotificationsCountMap() {
514
+ return this.stores.inappNotification.getUnreadNotificationsCountMap();
515
+ }
516
+ upsertNotifications(notifications) {
517
+ return this.stores.inappNotification.bulkUpsert(notifications);
518
+ }
519
+ markAllRead(proxyId) {
520
+ return this.stores.inappNotification.markAllRead(proxyId);
521
+ }
522
+ switchReadStatus(params) {
523
+ return this.stores.inappNotification.switchReadStatus(params);
524
+ }
525
+ removeAccountNotifications(proxyId) {
526
+ return this.stores.inappNotification.removeAccountNotifications(proxyId);
527
+ }
489
528
  async exportDB() {
490
529
  const blob = await (0, _dexieExportImport.exportDB)(this._db, {
491
530
  filter: (table, value, key) => {
@@ -50,6 +50,9 @@ class KoniDatabase extends _dexie.default {
50
50
  this.conditionalVersion(6, {
51
51
  keyValue: 'key'
52
52
  });
53
+ this.conditionalVersion(7, {
54
+ inappNotification: 'id, address, proxyId, [proxyId+actionType], actionType'
55
+ });
53
56
  }
54
57
  conditionalVersion(version, schema, upgrade) {
55
58
  if (this.schemaVersion != null && this.schemaVersion < version) {