@subwallet/extension-base 1.3.7-0 → 1.3.9-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 (109) hide show
  1. package/background/KoniTypes.d.ts +11 -5
  2. package/background/KoniTypes.js +1 -1
  3. package/cjs/background/KoniTypes.js +1 -1
  4. package/cjs/core/logic-validation/transfer.js +35 -24
  5. package/cjs/core/substrate/system-pallet.js +1 -1
  6. package/cjs/core/substrate/xcm-parser.js +16 -2
  7. package/cjs/core/utils.js +2 -2
  8. package/cjs/koni/api/contract-handler/utils/index.js +15 -1
  9. package/cjs/koni/background/handlers/Extension.js +158 -86
  10. package/cjs/koni/background/handlers/State.js +11 -2
  11. package/cjs/packageInfo.js +1 -1
  12. package/cjs/services/balance-service/index.js +24 -2
  13. package/cjs/services/balance-service/transfer/smart-contract.js +16 -5
  14. package/cjs/services/balance-service/transfer/xcm/index.js +31 -1
  15. package/cjs/services/balance-service/transfer/xcm/polygonBridge.js +108 -0
  16. package/cjs/services/chain-online-service/constants.js +32 -0
  17. package/cjs/services/chain-online-service/index.js +190 -0
  18. package/cjs/services/chain-service/constants.js +3 -1
  19. package/cjs/services/chain-service/index.js +87 -127
  20. package/cjs/services/chain-service/utils/index.js +0 -2
  21. package/cjs/services/chain-service/utils/patch.js +7 -3
  22. package/cjs/services/fee-service/utils/index.js +14 -0
  23. package/cjs/services/inapp-notification-service/consts.js +6 -4
  24. package/cjs/services/inapp-notification-service/index.js +110 -6
  25. package/cjs/services/inapp-notification-service/interfaces.js +9 -1
  26. package/cjs/services/inapp-notification-service/utils/avail.js +88 -0
  27. package/cjs/services/inapp-notification-service/{utils.js → utils/common.js} +1 -84
  28. package/cjs/services/inapp-notification-service/utils/index.js +38 -0
  29. package/cjs/services/inapp-notification-service/utils/polygon.js +66 -0
  30. package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +37 -0
  31. package/cjs/services/migration-service/scripts/index.js +3 -1
  32. package/cjs/services/setting-service/SettingService.js +8 -0
  33. package/cjs/services/setting-service/constants.js +2 -1
  34. package/cjs/services/storage-service/DatabaseService.js +3 -0
  35. package/cjs/services/transaction-service/index.js +1 -1
  36. package/cjs/stores/ChainlistStore.js +18 -0
  37. package/cjs/types/index.js +11 -0
  38. package/cjs/types/transaction/error.js +1 -0
  39. package/cjs/utils/account/transform.js +1 -1
  40. package/core/logic-validation/transfer.d.ts +2 -1
  41. package/core/logic-validation/transfer.js +36 -25
  42. package/core/substrate/system-pallet.js +1 -1
  43. package/core/substrate/xcm-parser.d.ts +1 -0
  44. package/core/substrate/xcm-parser.js +15 -2
  45. package/core/types.d.ts +1 -0
  46. package/core/utils.js +2 -2
  47. package/koni/api/contract-handler/utils/index.d.ts +2 -0
  48. package/koni/api/contract-handler/utils/index.js +12 -0
  49. package/koni/api/contract-handler/utils/polygon_bridge_abi.json +1004 -0
  50. package/koni/background/handlers/Extension.d.ts +4 -0
  51. package/koni/background/handlers/Extension.js +93 -22
  52. package/koni/background/handlers/State.d.ts +2 -0
  53. package/koni/background/handlers/State.js +11 -2
  54. package/package.json +56 -14
  55. package/packageInfo.js +1 -1
  56. package/services/balance-service/index.d.ts +3 -0
  57. package/services/balance-service/index.js +21 -2
  58. package/services/balance-service/transfer/smart-contract.js +16 -5
  59. package/services/balance-service/transfer/xcm/index.d.ts +1 -0
  60. package/services/balance-service/transfer/xcm/index.js +29 -1
  61. package/services/balance-service/transfer/xcm/polygonBridge.d.ts +22 -0
  62. package/services/balance-service/transfer/xcm/polygonBridge.js +95 -0
  63. package/services/chain-online-service/constants.d.ts +4 -0
  64. package/services/chain-online-service/constants.js +23 -0
  65. package/services/chain-online-service/index.d.ts +22 -0
  66. package/services/chain-online-service/index.js +182 -0
  67. package/services/chain-service/constants.d.ts +1 -0
  68. package/services/chain-service/constants.js +1 -0
  69. package/services/chain-service/index.d.ts +6 -7
  70. package/services/chain-service/index.js +78 -116
  71. package/services/chain-service/utils/index.js +0 -2
  72. package/services/chain-service/utils/patch.d.ts +16 -1
  73. package/services/chain-service/utils/patch.js +7 -3
  74. package/services/fee-service/utils/index.js +14 -0
  75. package/services/inapp-notification-service/consts.d.ts +3 -1
  76. package/services/inapp-notification-service/consts.js +6 -4
  77. package/services/inapp-notification-service/index.d.ts +10 -2
  78. package/services/inapp-notification-service/index.js +111 -7
  79. package/services/inapp-notification-service/interfaces.d.ts +27 -3
  80. package/services/inapp-notification-service/interfaces.js +7 -0
  81. package/services/inapp-notification-service/utils/avail.d.ts +40 -0
  82. package/services/inapp-notification-service/utils/avail.js +73 -0
  83. package/services/inapp-notification-service/utils/common.d.ts +11 -0
  84. package/services/inapp-notification-service/{utils.js → utils/common.js} +1 -72
  85. package/services/inapp-notification-service/utils/index.d.ts +3 -0
  86. package/services/inapp-notification-service/utils/index.js +6 -0
  87. package/services/inapp-notification-service/utils/polygon.d.ts +71 -0
  88. package/services/inapp-notification-service/utils/polygon.js +54 -0
  89. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.d.ts +4 -0
  90. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +29 -0
  91. package/services/migration-service/scripts/index.js +3 -1
  92. package/services/setting-service/SettingService.d.ts +4 -0
  93. package/services/setting-service/SettingService.js +8 -0
  94. package/services/setting-service/constants.js +2 -1
  95. package/services/storage-service/DatabaseService.d.ts +1 -0
  96. package/services/storage-service/DatabaseService.js +3 -0
  97. package/services/transaction-service/index.js +1 -1
  98. package/stores/ChainlistStore.d.ts +7 -0
  99. package/stores/ChainlistStore.js +10 -0
  100. package/types/{avail-bridge → bridge}/index.d.ts +1 -1
  101. package/types/index.d.ts +1 -0
  102. package/types/index.js +1 -0
  103. package/types/notification/index.d.ts +5 -0
  104. package/types/transaction/error.d.ts +2 -1
  105. package/types/transaction/error.js +1 -0
  106. package/utils/account/transform.js +1 -1
  107. package/services/inapp-notification-service/utils.d.ts +0 -55
  108. /package/cjs/types/{avail-bridge → bridge}/index.js +0 -0
  109. /package/types/{avail-bridge → bridge}/index.js +0 -0
@@ -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
  };
@@ -1,9 +1,11 @@
1
1
  import { PassPhishing, RequestSettingsType } from '@subwallet/extension-base/background/KoniTypes';
2
2
  import { EnvConfig } from '@subwallet/extension-base/constants';
3
+ import { ChainlistConfig } from '@subwallet/extension-base/stores/ChainlistStore';
3
4
  import { Subject } from 'rxjs';
4
5
  export default class SettingService {
5
6
  private readonly settingsStore;
6
7
  private readonly passPhishingStore;
8
+ private readonly chainlistStore;
7
9
  private readonly environmentStore;
8
10
  constructor();
9
11
  private initSetting;
@@ -13,6 +15,8 @@ export default class SettingService {
13
15
  passPhishingSubject(): Subject<Record<string, PassPhishing>>;
14
16
  getPassPhishingList(update: (value: Record<string, PassPhishing>) => void): void;
15
17
  setPassPhishing(data: Record<string, PassPhishing>, callback?: () => void): void;
18
+ getChainlistSetting(): Promise<ChainlistConfig>;
19
+ setChainlist(data: ChainlistConfig, callback?: () => void): void;
16
20
  getEnvironmentSetting(): EnvConfig;
17
21
  getEnvironmentList(update: (value: EnvConfig) => void): void;
18
22
  setEnvironment(data: EnvConfig): void;
@@ -4,6 +4,7 @@
4
4
  import { LANGUAGE } from '@subwallet/extension-base/constants';
5
5
  import { EnvironmentStoreSubject } from '@subwallet/extension-base/services/environment-service/stores/Environment';
6
6
  import { SWStorage } from '@subwallet/extension-base/storage';
7
+ import ChainlistStore from '@subwallet/extension-base/stores/ChainlistStore';
7
8
  import PassPhishingStore from '@subwallet/extension-base/stores/PassPhishingStore';
8
9
  import SettingsStore from '@subwallet/extension-base/stores/Settings';
9
10
  import i18n from "./i18n/i18n.js";
@@ -11,6 +12,7 @@ import { DEFAULT_SETTING } from "./constants.js";
11
12
  export default class SettingService {
12
13
  settingsStore = new SettingsStore();
13
14
  passPhishingStore = new PassPhishingStore();
15
+ chainlistStore = new ChainlistStore();
14
16
  environmentStore = new EnvironmentStoreSubject();
15
17
  constructor() {
16
18
  this.initSetting().catch(console.error);
@@ -63,6 +65,12 @@ export default class SettingService {
63
65
  setPassPhishing(data, callback) {
64
66
  this.passPhishingStore.set('PassPhishing', data, callback);
65
67
  }
68
+ getChainlistSetting() {
69
+ return this.chainlistStore.asyncGet('Chainlist');
70
+ }
71
+ setChainlist(data, callback) {
72
+ this.chainlistStore.set('Chainlist', data, callback);
73
+ }
66
74
  getEnvironmentSetting() {
67
75
  return this.environmentStore.subject.value;
68
76
  }
@@ -21,7 +21,8 @@ export const DEFAULT_NOTIFICATION_SETUP = {
21
21
  // receive: true,
22
22
  earningClaim: true,
23
23
  earningWithdraw: true,
24
- availBridgeClaim: true
24
+ availBridgeClaim: true,
25
+ polygonBridgeClaim: true
25
26
  // isHideWithdraw: false, // todo: just for test, remove later
26
27
  // isHideMarketing: false,
27
28
  // isHideAnnouncement: false
@@ -82,6 +82,7 @@ export default class DatabaseService {
82
82
  removeFromChainStore(chains: string[]): Promise<number>;
83
83
  getAllChainStore(): Promise<IChain[]>;
84
84
  updateAssetStore(item: _ChainAsset): Promise<unknown>;
85
+ bulkUpdateAssetsStore(items: _ChainAsset[]): Promise<unknown>;
85
86
  getAllAssetStore(): Promise<_ChainAsset[]>;
86
87
  removeFromAssetStore(items: string[]): Promise<number>;
87
88
  updateChainStakingMetadata(item: ChainStakingMetadata, changes?: Record<string, unknown>): Promise<unknown>;
@@ -332,6 +332,9 @@ export default class DatabaseService {
332
332
  async updateAssetStore(item) {
333
333
  return this.stores.asset.upsert(item);
334
334
  }
335
+ async bulkUpdateAssetsStore(items) {
336
+ return this.stores.asset.bulkUpsert(items);
337
+ }
335
338
  async getAllAssetStore() {
336
339
  return this.stores.asset.getAll();
337
340
  }
@@ -585,7 +585,7 @@ export default class TransactionService {
585
585
  historyItem.additionalInfo = data;
586
586
  break;
587
587
  }
588
- case ExtrinsicType.CLAIM_AVAIL_BRIDGE:
588
+ case ExtrinsicType.CLAIM_BRIDGE:
589
589
  {
590
590
  const data = parseTransactionData(transaction.data); // TODO: switch by provider
591
591
  const metadata = data.notification.metadata;
@@ -0,0 +1,7 @@
1
+ import SubscribableStore from '@subwallet/extension-base/stores/SubscribableStore';
2
+ export interface ChainlistConfig {
3
+ patchVersion: string;
4
+ }
5
+ export default class ChainlistStore extends SubscribableStore<ChainlistConfig> {
6
+ constructor();
7
+ }
@@ -0,0 +1,10 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { EXTENSION_PREFIX } from '@subwallet/extension-base/defaults';
5
+ import SubscribableStore from '@subwallet/extension-base/stores/SubscribableStore';
6
+ export default class ChainlistStore extends SubscribableStore {
7
+ constructor() {
8
+ super(EXTENSION_PREFIX ? `${EXTENSION_PREFIX}chainlist` : null);
9
+ }
10
+ }
@@ -1,5 +1,5 @@
1
1
  import { _NotificationInfo } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
2
- export interface RequestClaimAvailBridge {
2
+ export interface RequestClaimBridge {
3
3
  address: string;
4
4
  chain: string;
5
5
  notification: _NotificationInfo;
package/types/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export interface Message extends MessageEvent {
10
10
  }
11
11
  export * from './account';
12
12
  export * from './balance';
13
+ export * from './bridge';
13
14
  export * from './buy';
14
15
  export * from './campaigns';
15
16
  export * from './common';
package/types/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  export * from "./account/index.js";
5
5
  export * from "./balance/index.js";
6
+ export * from "./bridge/index.js";
6
7
  export * from "./buy.js";
7
8
  export * from "./campaigns/index.js";
8
9
  export * from "./common/index.js";
@@ -7,3 +7,8 @@ export interface RequestSwitchStatusParams {
7
7
  id: string;
8
8
  isRead: boolean;
9
9
  }
10
+ export interface RequestIsClaimedPolygonBridge {
11
+ chainslug: string;
12
+ counter: number;
13
+ sourceNetwork: number;
14
+ }
@@ -34,6 +34,7 @@ export declare enum TransferTxErrorType {
34
34
  NOT_ENOUGH_FEE = "NOT_ENOUGH_FEE",
35
35
  INVALID_TOKEN = "INVALID_TOKEN",
36
36
  TRANSFER_ERROR = "TRANSFER_ERROR",
37
- RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT = "RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT"
37
+ RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT = "RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT",
38
+ RECEIVER_ACCOUNT_INACTIVE = "RECEIVER_ACCOUNT_INACTIVE"
38
39
  }
39
40
  export declare type TransactionErrorType = BasicTxErrorType | TransferTxErrorType | StakingTxErrorType | YieldValidationStatus | SwapErrorType;