@subwallet/extension-base 1.3.6-1 → 1.3.8-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 (132) hide show
  1. package/background/KoniTypes.d.ts +20 -5
  2. package/background/KoniTypes.js +1 -1
  3. package/cjs/background/KoniTypes.js +1 -1
  4. package/cjs/constants/blocked-actions.js +108 -0
  5. package/cjs/constants/index.js +4 -4
  6. package/cjs/core/substrate/xcm-parser.js +20 -5
  7. package/cjs/koni/api/contract-handler/utils/index.js +15 -1
  8. package/cjs/koni/api/nft/config.js +6 -4
  9. package/cjs/koni/api/nft/index.js +9 -0
  10. package/cjs/koni/api/nft/story_odyssey_nft/index.js +126 -0
  11. package/cjs/koni/background/handlers/Extension.js +64 -4
  12. package/cjs/koni/background/handlers/State.js +23 -2
  13. package/cjs/packageInfo.js +1 -1
  14. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +2 -1
  15. package/cjs/services/balance-service/transfer/xcm/index.js +31 -1
  16. package/cjs/services/balance-service/transfer/xcm/polygonBridge.js +108 -0
  17. package/cjs/services/chain-online-service/constants.js +32 -0
  18. package/cjs/services/chain-online-service/index.js +190 -0
  19. package/cjs/services/chain-service/constants.js +2 -1
  20. package/cjs/services/chain-service/index.js +87 -127
  21. package/cjs/services/chain-service/utils/index.js +0 -2
  22. package/cjs/services/chain-service/utils/patch.js +7 -3
  23. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +20 -17
  24. package/cjs/services/environment-service/stores/Environment.js +19 -0
  25. package/cjs/services/fee-service/utils/index.js +14 -0
  26. package/cjs/services/inapp-notification-service/consts.js +6 -4
  27. package/cjs/services/inapp-notification-service/index.js +110 -6
  28. package/cjs/services/inapp-notification-service/interfaces.js +9 -1
  29. package/cjs/services/inapp-notification-service/utils/avail.js +88 -0
  30. package/cjs/services/inapp-notification-service/{utils.js → utils/common.js} +1 -84
  31. package/cjs/services/inapp-notification-service/utils/index.js +38 -0
  32. package/cjs/services/inapp-notification-service/utils/polygon.js +66 -0
  33. package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +37 -0
  34. package/cjs/services/migration-service/scripts/index.js +3 -1
  35. package/cjs/services/setting-service/SettingService.js +21 -0
  36. package/cjs/services/setting-service/constants.js +2 -1
  37. package/cjs/services/storage-service/DatabaseService.js +3 -0
  38. package/cjs/services/transaction-service/index.js +13 -7
  39. package/cjs/services/transaction-service/utils.js +3 -0
  40. package/cjs/stores/ChainlistStore.js +18 -0
  41. package/cjs/stores/EnvironmentStore.js +18 -0
  42. package/cjs/stores/index.js +8 -1
  43. package/cjs/types/index.js +11 -0
  44. package/cjs/utils/account/transform.js +1 -1
  45. package/cjs/utils/environment.js +15 -1
  46. package/cjs/utils/staticData/index.js +7 -2
  47. package/constants/blocked-actions.d.ts +29 -0
  48. package/constants/blocked-actions.js +96 -0
  49. package/constants/index.d.ts +1 -1
  50. package/constants/index.js +1 -1
  51. package/core/substrate/xcm-parser.d.ts +2 -1
  52. package/core/substrate/xcm-parser.js +19 -5
  53. package/koni/api/contract-handler/utils/index.d.ts +2 -0
  54. package/koni/api/contract-handler/utils/index.js +12 -0
  55. package/koni/api/contract-handler/utils/polygon_bridge_abi.json +1004 -0
  56. package/koni/api/nft/config.d.ts +1 -1
  57. package/koni/api/nft/config.js +5 -2
  58. package/koni/api/nft/index.js +9 -0
  59. package/koni/api/nft/story_odyssey_nft/index.d.ts +40 -0
  60. package/koni/api/nft/story_odyssey_nft/index.js +119 -0
  61. package/koni/background/handlers/Extension.d.ts +5 -0
  62. package/koni/background/handlers/Extension.js +65 -5
  63. package/koni/background/handlers/State.d.ts +5 -0
  64. package/koni/background/handlers/State.js +23 -2
  65. package/package.json +76 -18
  66. package/packageInfo.js +1 -1
  67. package/services/balance-service/helpers/subscribe/substrate/index.js +2 -1
  68. package/services/balance-service/transfer/xcm/index.d.ts +1 -0
  69. package/services/balance-service/transfer/xcm/index.js +29 -1
  70. package/services/balance-service/transfer/xcm/polygonBridge.d.ts +22 -0
  71. package/services/balance-service/transfer/xcm/polygonBridge.js +95 -0
  72. package/services/chain-online-service/constants.d.ts +4 -0
  73. package/services/chain-online-service/constants.js +23 -0
  74. package/services/chain-online-service/index.d.ts +22 -0
  75. package/services/chain-online-service/index.js +182 -0
  76. package/services/chain-service/constants.d.ts +1 -0
  77. package/services/chain-service/constants.js +2 -1
  78. package/services/chain-service/index.d.ts +6 -7
  79. package/services/chain-service/index.js +78 -116
  80. package/services/chain-service/utils/index.js +0 -2
  81. package/services/chain-service/utils/patch.d.ts +16 -1
  82. package/services/chain-service/utils/patch.js +7 -3
  83. package/services/earning-service/handlers/native-staking/para-chain.js +20 -17
  84. package/services/environment-service/stores/Environment.d.ts +10 -0
  85. package/services/environment-service/stores/Environment.js +12 -0
  86. package/services/fee-service/utils/index.js +14 -0
  87. package/services/inapp-notification-service/consts.d.ts +3 -1
  88. package/services/inapp-notification-service/consts.js +6 -4
  89. package/services/inapp-notification-service/index.d.ts +10 -2
  90. package/services/inapp-notification-service/index.js +111 -7
  91. package/services/inapp-notification-service/interfaces.d.ts +27 -3
  92. package/services/inapp-notification-service/interfaces.js +7 -0
  93. package/services/inapp-notification-service/utils/avail.d.ts +40 -0
  94. package/services/inapp-notification-service/utils/avail.js +73 -0
  95. package/services/inapp-notification-service/utils/common.d.ts +11 -0
  96. package/services/inapp-notification-service/{utils.js → utils/common.js} +1 -72
  97. package/services/inapp-notification-service/utils/index.d.ts +3 -0
  98. package/services/inapp-notification-service/utils/index.js +6 -0
  99. package/services/inapp-notification-service/utils/polygon.d.ts +71 -0
  100. package/services/inapp-notification-service/utils/polygon.js +54 -0
  101. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.d.ts +4 -0
  102. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +29 -0
  103. package/services/migration-service/scripts/index.js +3 -1
  104. package/services/setting-service/SettingService.d.ts +9 -0
  105. package/services/setting-service/SettingService.js +21 -0
  106. package/services/setting-service/constants.js +2 -1
  107. package/services/storage-service/DatabaseService.d.ts +1 -0
  108. package/services/storage-service/DatabaseService.js +3 -0
  109. package/services/transaction-service/index.js +14 -8
  110. package/services/transaction-service/utils.js +3 -0
  111. package/stores/ChainlistStore.d.ts +7 -0
  112. package/stores/ChainlistStore.js +10 -0
  113. package/stores/EnvironmentStore.d.ts +5 -0
  114. package/stores/EnvironmentStore.js +10 -0
  115. package/stores/index.d.ts +1 -0
  116. package/stores/index.js +2 -1
  117. package/types/{avail-bridge → bridge}/index.d.ts +1 -1
  118. package/types/index.d.ts +1 -0
  119. package/types/index.js +1 -0
  120. package/types/notification/index.d.ts +5 -0
  121. package/utils/account/transform.js +1 -1
  122. package/utils/environment.d.ts +6 -0
  123. package/utils/environment.js +8 -0
  124. package/utils/staticData/blockedActions.json +1 -0
  125. package/utils/staticData/index.d.ts +7 -3
  126. package/utils/staticData/index.js +5 -1
  127. package/cjs/constants/blocked-actions-list.js +0 -14
  128. package/constants/blocked-actions-list.d.ts +0 -7
  129. package/constants/blocked-actions-list.js +0 -7
  130. package/services/inapp-notification-service/utils.d.ts +0 -55
  131. /package/cjs/types/{avail-bridge → bridge}/index.js +0 -0
  132. /package/types/{avail-bridge → bridge}/index.js +0 -0
@@ -1,13 +1,14 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { COMMON_ASSETS, COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
4
5
  import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
6
  import { CRON_LISTEN_AVAIL_BRIDGE_CLAIM } from '@subwallet/extension-base/constants';
6
7
  import { fetchLastestRemindNotificationTime } from '@subwallet/extension-base/constants/remind-notification-time';
7
8
  import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
8
9
  import { NotificationDescriptionMap, NotificationTitleMap, ONE_DAY_MILLISECOND } from '@subwallet/extension-base/services/inapp-notification-service/consts';
9
10
  import { NotificationActionType, NotificationTab } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
10
- import { AvailBridgeSourceChain, fetchAllAvailBridgeClaimable, hrsToMillisecond } from '@subwallet/extension-base/services/inapp-notification-service/utils';
11
+ import { AvailBridgeSourceChain, fetchAllAvailBridgeClaimable, fetchPolygonBridgeTransactions, hrsToMillisecond } from '@subwallet/extension-base/services/inapp-notification-service/utils';
11
12
  import { categoryAddresses, formatNumber } from '@subwallet/extension-base/utils';
12
13
  import { isSubstrateAddress } from '@subwallet/keyring';
13
14
  export class InappNotificationService {
@@ -103,6 +104,28 @@ export class InappNotificationService {
103
104
  }
104
105
  }
105
106
  }
107
+ if ([NotificationActionType.CLAIM_POLYGON_BRIDGE].includes(candidateNotification.actionType)) {
108
+ const {
109
+ address,
110
+ metadata,
111
+ time
112
+ } = candidateNotification;
113
+ const candidateMetadata = metadata;
114
+ const remindTime = hrsToMillisecond(remindTimeConfigInHrs[candidateNotification.actionType]);
115
+ for (const notification of comparedNotifications) {
116
+ if (notification.address !== address) {
117
+ continue;
118
+ }
119
+ if (time - notification.time >= remindTime) {
120
+ continue;
121
+ }
122
+ const comparedMetadata = notification.metadata;
123
+ const sameNotification = candidateMetadata._id === comparedMetadata._id && candidateMetadata.transactionHash === comparedMetadata.transactionHash && candidateMetadata.counter === comparedMetadata.counter;
124
+ if (sameNotification) {
125
+ return false;
126
+ }
127
+ }
128
+ }
106
129
  return true;
107
130
  }
108
131
  async validateAndWriteNotificationsToDB(notifications, address) {
@@ -124,17 +147,23 @@ export class InappNotificationService {
124
147
  }
125
148
  await this.dbService.upsertNotifications(passNotifications);
126
149
  }
127
- cronCreateAvailBridgeClaimNotification() {
150
+ cronCreateBridgeClaimNotification() {
128
151
  clearTimeout(this.refeshAvailBridgeClaimTimeOut);
129
152
  this.createAvailBridgeClaimNotification();
130
- this.refeshAvailBridgeClaimTimeOut = setTimeout(this.cronCreateAvailBridgeClaimNotification.bind(this), CRON_LISTEN_AVAIL_BRIDGE_CLAIM);
153
+ this.createPolygonClaimableTransactions().catch(err => {
154
+ console.error('Error:', err);
155
+ });
156
+ this.refeshAvailBridgeClaimTimeOut = setTimeout(this.cronCreateBridgeClaimNotification.bind(this), CRON_LISTEN_AVAIL_BRIDGE_CLAIM);
131
157
  }
132
- createAvailBridgeClaimNotification() {
158
+ getCategorizedAddresses() {
133
159
  const addresses = this.keyringService.context.getAllAddresses();
160
+ return categoryAddresses(addresses);
161
+ }
162
+ createAvailBridgeClaimNotification() {
134
163
  const {
135
164
  evm: evmAddresses,
136
165
  substrate: substrateAddresses
137
- } = categoryAddresses(addresses);
166
+ } = this.getCategorizedAddresses();
138
167
  const chainAssets = this.chainService.getAssetRegistry();
139
168
  let ASSET_TYPE;
140
169
  (function (ASSET_TYPE) {
@@ -208,7 +237,7 @@ export class InappNotificationService {
208
237
  title: NotificationTitleMap[actionType].replace('{{tokenSymbol}}', symbol),
209
238
  description: NotificationDescriptionMap[actionType](formatNumber(amount, decimals), symbol),
210
239
  time: timestamp,
211
- extrinsicType: ExtrinsicType.CLAIM_AVAIL_BRIDGE,
240
+ extrinsicType: ExtrinsicType.CLAIM_BRIDGE,
212
241
  isRead: false,
213
242
  actionType,
214
243
  metadata
@@ -216,6 +245,81 @@ export class InappNotificationService {
216
245
  });
217
246
  await this.validateAndWriteNotificationsToDB(notifications, address);
218
247
  }
248
+
249
+ // Polygon Claimable Handle
250
+ async createPolygonClaimableTransactions() {
251
+ const {
252
+ evm: evmAddresses
253
+ } = this.getCategorizedAddresses();
254
+ const etherChains = [COMMON_ASSETS.ETH, COMMON_ASSETS.ETH_SEPOLIA];
255
+ const polygonAssets = Object.values(this.chainService.getAssetRegistry()).filter(asset => etherChains.includes(asset.slug));
256
+ for (const polygonAsset of polygonAssets) {
257
+ const isTestnet = (polygonAsset === null || polygonAsset === void 0 ? void 0 : polygonAsset.originChain) === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA;
258
+ if (evmAddresses.length === 0) {
259
+ return;
260
+ }
261
+ for (const address of evmAddresses) {
262
+ const response = await fetchPolygonBridgeTransactions(address, isTestnet);
263
+ if (response && response.success) {
264
+ await this.processPolygonClaimNotification(address, response.result, polygonAsset);
265
+ }
266
+ }
267
+ }
268
+ }
269
+ async processPolygonClaimNotification(address, transactions, token) {
270
+ var _token$decimals2;
271
+ const actionType = NotificationActionType.CLAIM_POLYGON_BRIDGE;
272
+ const timestamp = Date.now();
273
+ const symbol = token.symbol;
274
+ const decimals = (_token$decimals2 = token.decimals) !== null && _token$decimals2 !== void 0 ? _token$decimals2 : 0;
275
+ const notifications = transactions.map(transaction => {
276
+ const {
277
+ _id,
278
+ amounts,
279
+ counter,
280
+ destinationNetwork,
281
+ originTokenAddress,
282
+ originTokenNetwork,
283
+ receiver,
284
+ sourceNetwork,
285
+ status,
286
+ transactionHash,
287
+ transactionInitiator,
288
+ userAddress
289
+ } = transaction;
290
+ const metadata = {
291
+ chainSlug: token.originChain,
292
+ tokenSlug: token.slug,
293
+ _id,
294
+ amounts,
295
+ counter,
296
+ destinationNetwork,
297
+ originTokenAddress,
298
+ originTokenNetwork,
299
+ receiver,
300
+ sourceNetwork,
301
+ status,
302
+ transactionHash,
303
+ transactionInitiator,
304
+ userAddress
305
+ };
306
+ return {
307
+ id: `${actionType}___${_id}___${timestamp}`,
308
+ address: address,
309
+ title: NotificationTitleMap[actionType].replace('{{tokenSymbol}}', symbol),
310
+ description: NotificationDescriptionMap[actionType](formatNumber(amounts[0], decimals), symbol),
311
+ time: timestamp,
312
+ extrinsicType: ExtrinsicType.CLAIM_BRIDGE,
313
+ isRead: false,
314
+ actionType,
315
+ metadata
316
+ };
317
+ });
318
+ await this.validateAndWriteNotificationsToDB(notifications, address);
319
+ }
320
+
321
+ // Polygon Claimable Handle
322
+
219
323
  async start() {
220
324
  if (this.status === ServiceStatus.STARTED) {
221
325
  return;
@@ -228,7 +332,7 @@ export class InappNotificationService {
228
332
  }
229
333
  async startCron() {
230
334
  this.cleanUpOldNotifications().catch(console.error);
231
- this.cronCreateAvailBridgeClaimNotification();
335
+ this.cronCreateBridgeClaimNotification();
232
336
  return Promise.resolve();
233
337
  }
234
338
  async stop() {
@@ -1,5 +1,5 @@
1
1
  import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
- import { AvailBridgeSourceChain, AvailBridgeTransactionStatus } from '@subwallet/extension-base/services/inapp-notification-service/utils';
2
+ import { AvailBridgeSourceChain } from '@subwallet/extension-base/services/inapp-notification-service/utils';
3
3
  import { YieldPoolType } from '@subwallet/extension-base/types';
4
4
  export interface _BaseNotificationInfo {
5
5
  id: string;
@@ -15,6 +15,11 @@ export interface _BaseNotificationInfo {
15
15
  export interface _NotificationInfo extends _BaseNotificationInfo {
16
16
  proxyId: string;
17
17
  }
18
+ export declare enum BridgeTransactionStatus {
19
+ READY_TO_CLAIM = "READY_TO_CLAIM",
20
+ CLAIMED = "CLAIMED",
21
+ BRIDGED = "BRIDGED"
22
+ }
18
23
  export interface ActionTypeToMetadataMap {
19
24
  [NotificationActionType.SEND]: SendReceiveNotificationMetadata;
20
25
  [NotificationActionType.RECEIVE]: SendReceiveNotificationMetadata;
@@ -22,6 +27,7 @@ export interface ActionTypeToMetadataMap {
22
27
  [NotificationActionType.CLAIM]: WithdrawClaimNotificationMetadata;
23
28
  [NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_AVAIL]: ClaimAvailBridgeNotificationMetadata;
24
29
  [NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM]: ClaimAvailBridgeNotificationMetadata;
30
+ [NotificationActionType.CLAIM_POLYGON_BRIDGE]: ClaimPolygonBridgeNotificationMetadata;
25
31
  }
26
32
  export interface SendReceiveNotificationMetadata {
27
33
  chain: string;
@@ -46,7 +52,23 @@ export interface ClaimAvailBridgeNotificationMetadata {
46
52
  amount: string;
47
53
  sourceBlockHash: string;
48
54
  sourceTransactionIndex: string;
49
- status: AvailBridgeTransactionStatus;
55
+ status: BridgeTransactionStatus;
56
+ }
57
+ export interface ClaimPolygonBridgeNotificationMetadata {
58
+ chainSlug: string;
59
+ tokenSlug: string;
60
+ _id: string;
61
+ amounts: string[];
62
+ counter: number;
63
+ destinationNetwork: number;
64
+ originTokenAddress: string;
65
+ originTokenNetwork: number;
66
+ receiver: string;
67
+ sourceNetwork: number;
68
+ status: BridgeTransactionStatus;
69
+ transactionHash: string;
70
+ transactionInitiator: string;
71
+ userAddress: string;
50
72
  }
51
73
  export declare enum NotificationTimePeriod {
52
74
  TODAY = "TODAY",
@@ -59,7 +81,8 @@ export declare enum NotificationActionType {
59
81
  WITHDRAW = "WITHDRAW",
60
82
  CLAIM = "CLAIM",
61
83
  CLAIM_AVAIL_BRIDGE_ON_AVAIL = "CLAIM_AVAIL_BRIDGE_ON_AVAIL",
62
- CLAIM_AVAIL_BRIDGE_ON_ETHEREUM = "CLAIM_AVAIL_BRIDGE_ON_ETHEREUM"
84
+ CLAIM_AVAIL_BRIDGE_ON_ETHEREUM = "CLAIM_AVAIL_BRIDGE_ON_ETHEREUM",
85
+ CLAIM_POLYGON_BRIDGE = "CLAIM_POLYGON_BRIDGE"
63
86
  }
64
87
  export declare enum NotificationTab {
65
88
  ALL = "ALL",
@@ -70,6 +93,7 @@ export interface ShowNotificationPayload {
70
93
  earningClaim: boolean;
71
94
  earningWithdraw: boolean;
72
95
  availBridgeClaim: boolean;
96
+ polygonBridgeClaim: boolean;
73
97
  }
74
98
  export interface NotificationSetup {
75
99
  isEnabled: boolean;
@@ -1,6 +1,12 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ export let BridgeTransactionStatus;
5
+ (function (BridgeTransactionStatus) {
6
+ BridgeTransactionStatus["READY_TO_CLAIM"] = "READY_TO_CLAIM";
7
+ BridgeTransactionStatus["CLAIMED"] = "CLAIMED";
8
+ BridgeTransactionStatus["BRIDGED"] = "BRIDGED";
9
+ })(BridgeTransactionStatus || (BridgeTransactionStatus = {}));
4
10
  export let NotificationTimePeriod;
5
11
  (function (NotificationTimePeriod) {
6
12
  NotificationTimePeriod["TODAY"] = "TODAY";
@@ -15,6 +21,7 @@ export let NotificationActionType;
15
21
  NotificationActionType["CLAIM"] = "CLAIM";
16
22
  NotificationActionType["CLAIM_AVAIL_BRIDGE_ON_AVAIL"] = "CLAIM_AVAIL_BRIDGE_ON_AVAIL";
17
23
  NotificationActionType["CLAIM_AVAIL_BRIDGE_ON_ETHEREUM"] = "CLAIM_AVAIL_BRIDGE_ON_ETHEREUM";
24
+ NotificationActionType["CLAIM_POLYGON_BRIDGE"] = "CLAIM_POLYGON_BRIDGE";
18
25
  })(NotificationActionType || (NotificationActionType = {}));
19
26
  export let NotificationTab;
20
27
  (function (NotificationTab) {
@@ -0,0 +1,40 @@
1
+ import { BridgeTransactionStatus } from '../interfaces';
2
+ export declare function getAvailBridgeClaimDescription(amount: string, symbol: string): string;
3
+ export declare const AVAIL_BRIDGE_INDEXER: {
4
+ AVAIL_MAINNET: string;
5
+ AVAIL_TESTNET: string;
6
+ };
7
+ export declare const AVAIL_BRIDGE_API: {
8
+ AVAIL_MAINNET: string;
9
+ AVAIL_TESTNET: string;
10
+ };
11
+ interface AvailBridgeTransactionsResponse {
12
+ data: {
13
+ paginationData: {
14
+ hasNextPage: boolean;
15
+ page: number;
16
+ pageSize: number;
17
+ totalCount: number;
18
+ };
19
+ result: AvailBridgeTransaction[];
20
+ };
21
+ }
22
+ export interface AvailBridgeTransaction {
23
+ messageId: string;
24
+ sourceChain: AvailBridgeSourceChain;
25
+ sourceTransactionHash: string;
26
+ depositorAddress: string;
27
+ receiverAddress: string;
28
+ amount: string;
29
+ sourceBlockHash: string;
30
+ sourceTransactionIndex: string;
31
+ status: BridgeTransactionStatus;
32
+ }
33
+ export declare enum AvailBridgeSourceChain {
34
+ AVAIL = "AVAIL",
35
+ ETHEREUM = "ETHEREUM"
36
+ }
37
+ export declare function fetchAllAvailBridgeClaimable(address: string, sourceChain: AvailBridgeSourceChain, isTestnet: boolean): Promise<AvailBridgeTransaction[]>;
38
+ export declare function fetchAvailBridgeTransactions(userAddress: string, sourceChain: AvailBridgeSourceChain, status: BridgeTransactionStatus, pageSize: number | undefined, page: number | undefined, isTestnet: boolean): Promise<AvailBridgeTransactionsResponse | undefined>;
39
+ export declare function filterClaimableOfAddress(address: string, transactions: AvailBridgeTransaction[]): AvailBridgeTransaction[];
40
+ export {};
@@ -0,0 +1,73 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { BridgeTransactionStatus } from "../interfaces.js";
5
+
6
+ /* Description */
7
+ export function getAvailBridgeClaimDescription(amount, symbol) {
8
+ return `${amount} ${symbol} ready to claim from ${symbol} cross-chain transfer. Click to claim now!`;
9
+ }
10
+ /* Description */
11
+
12
+ // todo: can refactor utils and const of avail bridge to a new file. Also check in /transfer/xcm/availBridge.ts file
13
+
14
+ export const AVAIL_BRIDGE_INDEXER = {
15
+ AVAIL_MAINNET: 'https://bridge-indexer.avail.so',
16
+ AVAIL_TESTNET: 'https://turing-bridge-indexer.fra.avail.so'
17
+ };
18
+ export const AVAIL_BRIDGE_API = {
19
+ AVAIL_MAINNET: 'https://bridge-api.avail.so',
20
+ AVAIL_TESTNET: 'https://turing-bridge-api.fra.avail.so'
21
+ };
22
+ export let AvailBridgeSourceChain;
23
+ (function (AvailBridgeSourceChain) {
24
+ AvailBridgeSourceChain["AVAIL"] = "AVAIL";
25
+ AvailBridgeSourceChain["ETHEREUM"] = "ETHEREUM";
26
+ })(AvailBridgeSourceChain || (AvailBridgeSourceChain = {}));
27
+ export async function fetchAllAvailBridgeClaimable(address, sourceChain, isTestnet) {
28
+ const transactions = [];
29
+ let isContinue = true;
30
+ let page = 0;
31
+ const pageSize = 100;
32
+ while (isContinue) {
33
+ const response = await fetchAvailBridgeTransactions(address, sourceChain, BridgeTransactionStatus.READY_TO_CLAIM, pageSize, page, isTestnet);
34
+ if (!response) {
35
+ break;
36
+ }
37
+ transactions.push(...filterClaimableOfAddress(address, response.data.result));
38
+ isContinue = response.data.paginationData.hasNextPage;
39
+ page = page + 1;
40
+ }
41
+ return transactions;
42
+ }
43
+ export async function fetchAvailBridgeTransactions(userAddress, sourceChain, status, pageSize = 100, page = 0, isTestnet) {
44
+ const params = new URLSearchParams({
45
+ userAddress,
46
+ sourceChain,
47
+ status,
48
+ pageSize: pageSize.toString(),
49
+ page: page.toString()
50
+ });
51
+ try {
52
+ const api = isTestnet ? AVAIL_BRIDGE_INDEXER.AVAIL_TESTNET : AVAIL_BRIDGE_INDEXER.AVAIL_MAINNET;
53
+ const rawResponse = await fetch(`${api}/transactions?${params.toString()}`, {
54
+ method: 'GET',
55
+ headers: {
56
+ 'Content-Type': 'application/json',
57
+ 'Access-Control-Allow-Origin': '*'
58
+ },
59
+ credentials: 'omit'
60
+ });
61
+ if (!rawResponse.ok) {
62
+ console.error('Error fetching claimable bridge transactions');
63
+ return undefined;
64
+ }
65
+ return await rawResponse.json();
66
+ } catch (e) {
67
+ console.error(e);
68
+ return undefined;
69
+ }
70
+ }
71
+ export function filterClaimableOfAddress(address, transactions) {
72
+ return transactions.filter(transaction => transaction.receiverAddress.toLowerCase() === address.toLowerCase());
73
+ }
@@ -0,0 +1,11 @@
1
+ import { _ChainAsset } from '@subwallet/chain-list/types';
2
+ import { _BaseNotificationInfo, NotificationTab } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
3
+ import { EarningRewardItem, UnstakingInfo, YieldPoolType } from '@subwallet/extension-base/types';
4
+ export declare function getWithdrawDescription(amount: string, symbol: string, stakingType: YieldPoolType): string;
5
+ export declare function getClaimDescription(amount: string, symbol: string): string;
6
+ export declare function getSendDescription(amount: string, symbol: string): string;
7
+ export declare function getReceiveDescription(amount: string, symbol: string): string;
8
+ export declare function getIsTabRead(notificationTab: NotificationTab): boolean | undefined;
9
+ export declare function createWithdrawNotifications(unstakingInfos: UnstakingInfo[], tokenInfo: _ChainAsset, address: string, stakingSlug: string, stakingType: YieldPoolType): _BaseNotificationInfo[];
10
+ export declare function createClaimNotification(claimItemInfo: EarningRewardItem, tokenInfo: _ChainAsset): _BaseNotificationInfo;
11
+ export declare function hrsToMillisecond(hours: number): number;
@@ -24,9 +24,7 @@ export function getSendDescription(amount, symbol) {
24
24
  export function getReceiveDescription(amount, symbol) {
25
25
  return `You have just received ${amount} ${symbol}`;
26
26
  }
27
- export function getAvailBridgeClaimDescription(amount, symbol) {
28
- return `${amount} ${symbol} ready to claim from ${symbol} cross-chain transfer. Click to claim now!`;
29
- }
27
+
30
28
  /* Description */
31
29
 
32
30
  export function getIsTabRead(notificationTab) {
@@ -99,75 +97,6 @@ export function createClaimNotification(claimItemInfo, tokenInfo) {
99
97
  }
100
98
  };
101
99
  }
102
-
103
- // todo: can refactor utils and const of avail bridge to a new file. Also check in /transfer/xcm/availBridge.ts file
104
-
105
- export const AVAIL_BRIDGE_INDEXER = {
106
- AVAIL_MAINNET: 'https://bridge-indexer.avail.so',
107
- AVAIL_TESTNET: 'https://turing-bridge-indexer.fra.avail.so'
108
- };
109
- export const AVAIL_BRIDGE_API = {
110
- AVAIL_MAINNET: 'https://bridge-api.avail.so',
111
- AVAIL_TESTNET: 'https://turing-bridge-api.fra.avail.so'
112
- };
113
- export let AvailBridgeTransactionStatus;
114
- (function (AvailBridgeTransactionStatus) {
115
- AvailBridgeTransactionStatus["READY_TO_CLAIM"] = "READY_TO_CLAIM";
116
- AvailBridgeTransactionStatus["CLAIMED"] = "CLAIMED";
117
- AvailBridgeTransactionStatus["BRIDGED"] = "BRIDGED";
118
- })(AvailBridgeTransactionStatus || (AvailBridgeTransactionStatus = {}));
119
- export let AvailBridgeSourceChain;
120
- (function (AvailBridgeSourceChain) {
121
- AvailBridgeSourceChain["AVAIL"] = "AVAIL";
122
- AvailBridgeSourceChain["ETHEREUM"] = "ETHEREUM";
123
- })(AvailBridgeSourceChain || (AvailBridgeSourceChain = {}));
124
- export async function fetchAllAvailBridgeClaimable(address, sourceChain, isTestnet) {
125
- const transactions = [];
126
- let isContinue = true;
127
- let page = 0;
128
- const pageSize = 100;
129
- while (isContinue) {
130
- const response = await fetchAvailBridgeTransactions(address, sourceChain, AvailBridgeTransactionStatus.READY_TO_CLAIM, pageSize, page, isTestnet);
131
- if (!response) {
132
- break;
133
- }
134
- transactions.push(...filterClaimableOfAddress(address, response.data.result));
135
- isContinue = response.data.paginationData.hasNextPage;
136
- page = page + 1;
137
- }
138
- return transactions;
139
- }
140
- export async function fetchAvailBridgeTransactions(userAddress, sourceChain, status, pageSize = 100, page = 0, isTestnet) {
141
- const params = new URLSearchParams({
142
- userAddress,
143
- sourceChain,
144
- status,
145
- pageSize: pageSize.toString(),
146
- page: page.toString()
147
- });
148
- try {
149
- const api = isTestnet ? AVAIL_BRIDGE_INDEXER.AVAIL_TESTNET : AVAIL_BRIDGE_INDEXER.AVAIL_MAINNET;
150
- const rawResponse = await fetch(`${api}/transactions?${params.toString()}`, {
151
- method: 'GET',
152
- headers: {
153
- 'Content-Type': 'application/json',
154
- 'Access-Control-Allow-Origin': '*'
155
- },
156
- credentials: 'omit'
157
- });
158
- if (!rawResponse.ok) {
159
- console.error('Error fetching claimable bridge transactions');
160
- return undefined;
161
- }
162
- return await rawResponse.json();
163
- } catch (e) {
164
- console.error(e);
165
- return undefined;
166
- }
167
- }
168
- export function filterClaimableOfAddress(address, transactions) {
169
- return transactions.filter(transaction => transaction.receiverAddress.toLowerCase() === address.toLowerCase());
170
- }
171
100
  export function hrsToMillisecond(hours) {
172
101
  return hours * 60 * 60 * 1000;
173
102
  }
@@ -0,0 +1,3 @@
1
+ export * from './avail';
2
+ export * from './common';
3
+ export * from './polygon';
@@ -0,0 +1,6 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from "./avail.js";
5
+ export * from "./common.js";
6
+ export * from "./polygon.js";
@@ -0,0 +1,71 @@
1
+ import { BridgeTransactionStatus } from '../interfaces';
2
+ export declare const POLYGON_BRIDGE_INDEXER: {
3
+ MAINNET: string;
4
+ TESTNET: string;
5
+ };
6
+ export interface PolygonTransaction {
7
+ _id: string;
8
+ transactionIndex?: number;
9
+ sourceNetwork: number;
10
+ destinationNetwork: number;
11
+ blockNumber: number;
12
+ amounts: string[];
13
+ bridgeType: string;
14
+ dataType: string;
15
+ isDecoded?: boolean;
16
+ status: BridgeTransactionStatus;
17
+ timestamp: string;
18
+ tokenIds: any[];
19
+ transactionHash: string;
20
+ userAddress: string;
21
+ wrappedTokenAddress?: string;
22
+ wrappedTokenNetwork?: number;
23
+ counter: number;
24
+ bridgeContractAddress?: string;
25
+ eventInitiatorAddress?: string;
26
+ globalExitRootManager?: string;
27
+ leaf?: string;
28
+ mainnetExitRoot?: string;
29
+ metadata?: string;
30
+ originTokenAddress: string;
31
+ originTokenNetwork: number;
32
+ receiver: string;
33
+ refuel: boolean;
34
+ rollUpExitRoot?: string;
35
+ nonce?: any;
36
+ rootTunnelAddress?: string;
37
+ claimContractAddress?: string;
38
+ claimTransactionBlockNumber?: number;
39
+ claimTransactionHash?: string;
40
+ claimTransactionTimestamp?: string;
41
+ transactionInitiator: string;
42
+ }
43
+ interface PaginationData {
44
+ hasNextPage: boolean;
45
+ page: number;
46
+ pageSize: number;
47
+ totalCount: number;
48
+ }
49
+ interface LastCheckpoint {
50
+ _id: string;
51
+ proposer: string;
52
+ checkpointNumber: number;
53
+ reward: number;
54
+ start: number;
55
+ end: number;
56
+ root: string;
57
+ transactionHash: string;
58
+ timestamp: number;
59
+ __v: number;
60
+ }
61
+ interface PolygonTransactionResponse {
62
+ success: boolean;
63
+ result: PolygonTransaction[];
64
+ paginationData: PaginationData;
65
+ posWithdrawInterval: number;
66
+ lastCheckpoint: LastCheckpoint;
67
+ }
68
+ export declare function getPolygonBridgeClaimDescription(amount: string, symbol: string): string;
69
+ export declare function fetchPolygonBridgeTransactions(userAddress: string, isTestnet: boolean, pageSize?: number, page?: number): Promise<PolygonTransactionResponse | undefined>;
70
+ export declare function fetchAndFilterPolygonTransactionById(transactionId: string, userAddress: string, isTestnet: boolean): Promise<PolygonTransaction | undefined>;
71
+ export {};
@@ -0,0 +1,54 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { BridgeTransactionStatus } from "../interfaces.js";
5
+ export const POLYGON_BRIDGE_INDEXER = {
6
+ MAINNET: 'https://api-gateway.polygon.technology/api/v3/transactions/mainnet',
7
+ TESTNET: 'https://api-gateway.polygon.technology/api/v3/transactions/testnet'
8
+ };
9
+ /* Description */
10
+ export function getPolygonBridgeClaimDescription(amount, symbol) {
11
+ return `${amount} ${symbol} ready to claim from ${symbol} cross-chain transfer. Click to claim now!`;
12
+ }
13
+ /* Description */
14
+
15
+ export async function fetchPolygonBridgeTransactions(userAddress, isTestnet, pageSize = 500, page = 0) {
16
+ const params = new URLSearchParams({
17
+ userAddress,
18
+ pageSize: pageSize.toString(),
19
+ page: page.toString()
20
+ });
21
+ const networkIds = [0, 1];
22
+ networkIds.forEach(networkId => {
23
+ params.append('destinationNetworkIds', networkId.toString());
24
+ params.append('sourceNetworkIds', networkId.toString());
25
+ params.append('status', BridgeTransactionStatus.READY_TO_CLAIM);
26
+ });
27
+ try {
28
+ const domain = isTestnet ? POLYGON_BRIDGE_INDEXER.TESTNET : POLYGON_BRIDGE_INDEXER.MAINNET;
29
+ const rawResponse = await fetch(`${domain}?${params.toString()}`, {
30
+ method: 'GET',
31
+ headers: {
32
+ 'Content-Type': 'application/json',
33
+ 'Access-Control-Allow-Origin': '*',
34
+ 'x-api-key': 'polygonag_4RFN-g_wt2o12GmK9WWOWrGf-4Hamhtd'
35
+ },
36
+ credentials: 'omit'
37
+ });
38
+ if (!rawResponse.ok) {
39
+ console.error('Error fetching claimable bridge transactions');
40
+ return undefined;
41
+ }
42
+ return await rawResponse.json();
43
+ } catch (e) {
44
+ console.error(e);
45
+ return undefined;
46
+ }
47
+ }
48
+ export async function fetchAndFilterPolygonTransactionById(transactionId, userAddress, isTestnet) {
49
+ const response = await fetchPolygonBridgeTransactions(userAddress, isTestnet);
50
+ if (!response || !response.success) {
51
+ return undefined;
52
+ }
53
+ return response.result.find(tx => tx._id === transactionId);
54
+ }
@@ -0,0 +1,4 @@
1
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
+ export default class MigrateTransactionHistoryBridge extends BaseMigrationJob {
3
+ run(): Promise<void>;
4
+ }
@@ -0,0 +1,29 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
6
+ import Dexie from 'dexie';
7
+ export default class MigrateTransactionHistoryBridge extends BaseMigrationJob {
8
+ async run() {
9
+ const state = this.state;
10
+ const newTransactionItems = [];
11
+ try {
12
+ const db = new Dexie('SubWalletDB_v2');
13
+ const dexieDB = await db.open();
14
+ const transactionTable = dexieDB.table('transactions');
15
+ const oldTransactionData = await transactionTable.toArray();
16
+ const claimAvailBridgeTransactions = oldTransactionData.filter(item => item.type === 'claim.claim_avail_bridge');
17
+ claimAvailBridgeTransactions.forEach(item => {
18
+ const newItem = {
19
+ ...item,
20
+ type: ExtrinsicType.CLAIM_BRIDGE
21
+ };
22
+ newTransactionItems.push(newItem);
23
+ });
24
+ await state.dbService.upsertHistory(newTransactionItems);
25
+ } catch (e) {
26
+ this.logger.error(e);
27
+ }
28
+ }
29
+ }
@@ -27,6 +27,7 @@ import MigrateNetworkSettings from "./MigrateNetworkSettings.js";
27
27
  import MigrateSettings from "./MigrateSettings.js";
28
28
  import MigrateTokenDecimals from "./MigrateTokenDecimals.js";
29
29
  import MigrateTransactionHistory from "./MigrateTransactionHistory.js";
30
+ import MigrateTransactionHistoryBridge from "./MigrateTransactionHistoryBridge.js";
30
31
  import MigrateTransactionHistoryBySymbol from "./MigrateTransactionHistoryBySymbol.js";
31
32
  import MigrateWalletReference from "./MigrateWalletReference.js";
32
33
  export const EVERYTIME = '__everytime__';
@@ -59,7 +60,8 @@ export default {
59
60
  '1.2.69-01': MigrateRemoveGenesisHash,
60
61
  '1.2.13-01': ReloadMetadata,
61
62
  '1.2.14-01': ClearMetadataDatabase,
62
- '1.2.32-01': MigratePairData
63
+ '1.2.32-01': MigratePairData,
64
+ '1.3.6-01': MigrateTransactionHistoryBridge
63
65
  // [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
64
66
  // [`${EVERYTIME}-1`]: AutoEnableChainsTokens
65
67
  };