@subwallet/extension-base 1.1.68-2 → 1.2.2-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 (168) hide show
  1. package/background/KoniTypes.d.ts +3 -1
  2. package/background/handlers/State.d.ts +1 -78
  3. package/background/handlers/State.js +1 -428
  4. package/background/types.d.ts +1 -0
  5. package/cjs/background/handlers/State.js +1 -456
  6. package/cjs/constants/storage.js +3 -1
  7. package/cjs/koni/api/dotsama/crowdloan.js +1 -2
  8. package/cjs/koni/api/nft/acala_nft/index.js +1 -3
  9. package/cjs/koni/api/nft/assethub_nft/index.js +1 -3
  10. package/cjs/koni/api/nft/assethub_unique/index.js +1 -3
  11. package/cjs/koni/api/nft/bit.country/index.js +4 -6
  12. package/cjs/koni/api/nft/config.js +1 -8
  13. package/cjs/koni/api/nft/evm_nft/index.js +1 -3
  14. package/cjs/koni/api/nft/karura_nft/index.js +1 -3
  15. package/cjs/koni/api/nft/ordinal_nft/index.js +4 -3
  16. package/cjs/koni/api/nft/rmrk_nft/index.js +4 -6
  17. package/cjs/koni/api/nft/unique_network_nft/index.js +1 -3
  18. package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +1 -3
  19. package/cjs/koni/api/nft/vara_nft/index.js +1 -3
  20. package/cjs/koni/api/nft/wasm_nft/index.js +10 -17
  21. package/cjs/koni/api/staking/bonding/astar.js +2 -4
  22. package/cjs/koni/api/staking/subsquidStaking.js +9 -12
  23. package/cjs/koni/api/subquery/subquery.js +1 -3
  24. package/cjs/koni/background/handlers/Extension.js +39 -15
  25. package/cjs/koni/background/handlers/Mobile.js +7 -4
  26. package/cjs/koni/background/handlers/State.js +68 -12
  27. package/cjs/koni/background/handlers/Tabs.js +7 -3
  28. package/cjs/koni/background/handlers/index.js +71 -71
  29. package/cjs/koni/background/subscription.js +7 -6
  30. package/cjs/packageInfo.js +1 -1
  31. package/cjs/services/campaign-service/helpers.js +3 -1
  32. package/cjs/services/chain-service/index.js +36 -27
  33. package/cjs/services/chain-service/utils/patch.js +1 -3
  34. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +1 -2
  35. package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +2 -3
  36. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +2 -3
  37. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +1 -2
  38. package/cjs/services/earning-service/handlers/native-staking/astar.js +3 -4
  39. package/cjs/services/event-service/index.js +0 -1
  40. package/cjs/services/history-service/subsquid-multi-chain-history.js +1 -3
  41. package/cjs/services/keyring-service/index.js +22 -0
  42. package/cjs/services/migration-service/scripts/MigrateRemoveGenesisHash.js +28 -0
  43. package/cjs/services/migration-service/scripts/index.js +3 -1
  44. package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +16 -21
  45. package/cjs/services/notification-service/NotificationService.js +3 -1
  46. package/cjs/services/price-service/coingecko.js +6 -7
  47. package/cjs/services/price-service/index.js +7 -3
  48. package/cjs/services/request-service/handler/PopupHandler.js +14 -15
  49. package/cjs/services/setting-service/SettingService.js +4 -1
  50. package/cjs/services/setting-service/constants.js +1 -1
  51. package/cjs/services/setting-service/i18n/i18n.js +2 -4
  52. package/cjs/services/storage-service/DatabaseService.js +1 -1
  53. package/cjs/services/storage-service/databases/index.js +14 -1
  54. package/cjs/services/storage-service/db-stores/KeyValue.js +13 -0
  55. package/cjs/services/subscan-service/index.js +11 -3
  56. package/cjs/services/transaction-service/index.js +3 -3
  57. package/cjs/services/wallet-connect-service/constants.js +2 -2
  58. package/cjs/services/wallet-connect-service/helpers.js +1 -4
  59. package/cjs/services/wallet-connect-service/index.js +50 -33
  60. package/cjs/storage/index.js +120 -23
  61. package/cjs/types/common/index.js +16 -0
  62. package/cjs/types/common/storage.js +1 -0
  63. package/cjs/types/index.js +11 -0
  64. package/cjs/utils/environment.js +1 -1
  65. package/cjs/utils/eth/parseTransaction/index.js +8 -10
  66. package/cjs/utils/fetch.js +55 -0
  67. package/cjs/utils/fetchStaticCache.js +2 -4
  68. package/cjs/utils/fetchStaticData.js +7 -4
  69. package/cjs/utils/index.js +24 -0
  70. package/cjs/utils/reportError.js +1 -3
  71. package/constants/storage.d.ts +1 -0
  72. package/constants/storage.js +1 -0
  73. package/koni/api/dotsama/crowdloan.js +2 -3
  74. package/koni/api/nft/acala_nft/index.js +0 -1
  75. package/koni/api/nft/assethub_nft/index.js +0 -1
  76. package/koni/api/nft/assethub_unique/index.js +0 -1
  77. package/koni/api/nft/bit.country/index.js +0 -1
  78. package/koni/api/nft/config.js +1 -7
  79. package/koni/api/nft/evm_nft/index.js +0 -1
  80. package/koni/api/nft/karura_nft/index.js +0 -1
  81. package/koni/api/nft/ordinal_nft/index.d.ts +2 -0
  82. package/koni/api/nft/ordinal_nft/index.js +4 -3
  83. package/koni/api/nft/rmrk_nft/index.js +0 -1
  84. package/koni/api/nft/unique_network_nft/index.js +0 -1
  85. package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  86. package/koni/api/nft/vara_nft/index.js +0 -1
  87. package/koni/api/nft/wasm_nft/index.js +4 -10
  88. package/koni/api/staking/bonding/astar.js +0 -1
  89. package/koni/api/staking/subsquidStaking.js +10 -12
  90. package/koni/api/subquery/subquery.js +0 -1
  91. package/koni/background/handlers/Extension.d.ts +4 -0
  92. package/koni/background/handlers/Extension.js +29 -8
  93. package/koni/background/handlers/Mobile.js +9 -6
  94. package/koni/background/handlers/State.d.ts +6 -1
  95. package/koni/background/handlers/State.js +68 -12
  96. package/koni/background/handlers/Tabs.js +7 -3
  97. package/koni/background/handlers/index.d.ts +13 -7
  98. package/koni/background/handlers/index.js +67 -62
  99. package/koni/background/subscription.js +2 -1
  100. package/package.json +35 -28
  101. package/packageInfo.js +1 -1
  102. package/services/campaign-service/helpers.js +3 -1
  103. package/services/chain-service/index.js +36 -28
  104. package/services/chain-service/utils/patch.js +0 -1
  105. package/services/earning-service/handlers/liquid-staking/acala.js +0 -1
  106. package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +0 -1
  107. package/services/earning-service/handlers/liquid-staking/bifrost.js +0 -1
  108. package/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -1
  109. package/services/earning-service/handlers/native-staking/astar.js +0 -1
  110. package/services/event-service/index.js +0 -1
  111. package/services/history-service/subsquid-multi-chain-history.js +0 -1
  112. package/services/keyring-service/index.d.ts +1 -0
  113. package/services/keyring-service/index.js +19 -0
  114. package/services/migration-service/scripts/MigrateRemoveGenesisHash.d.ts +4 -0
  115. package/services/migration-service/scripts/MigrateRemoveGenesisHash.js +20 -0
  116. package/services/migration-service/scripts/index.js +3 -1
  117. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +17 -21
  118. package/services/notification-service/NotificationService.js +3 -1
  119. package/services/price-service/coingecko.js +6 -6
  120. package/services/price-service/index.js +7 -3
  121. package/services/request-service/handler/PopupHandler.d.ts +1 -1
  122. package/services/request-service/handler/PopupHandler.js +14 -15
  123. package/services/setting-service/SettingService.d.ts +1 -0
  124. package/services/setting-service/SettingService.js +4 -1
  125. package/services/setting-service/constants.js +2 -2
  126. package/services/setting-service/i18n/i18n.js +2 -4
  127. package/services/storage-service/DatabaseService.js +1 -1
  128. package/services/storage-service/databases/index.d.ts +8 -0
  129. package/services/storage-service/databases/index.js +13 -1
  130. package/services/storage-service/db-stores/KeyValue.d.ts +4 -0
  131. package/services/storage-service/db-stores/KeyValue.js +5 -0
  132. package/services/subscan-service/index.d.ts +2 -0
  133. package/services/subscan-service/index.js +10 -1
  134. package/services/transaction-service/index.js +4 -4
  135. package/services/wallet-connect-service/constants.js +3 -3
  136. package/services/wallet-connect-service/helpers.js +1 -4
  137. package/services/wallet-connect-service/index.d.ts +2 -0
  138. package/services/wallet-connect-service/index.js +42 -31
  139. package/storage/index.d.ts +19 -9
  140. package/storage/index.js +115 -23
  141. package/types/common/index.d.ts +1 -0
  142. package/types/common/index.js +4 -0
  143. package/types/common/storage.d.ts +4 -0
  144. package/types/common/storage.js +1 -0
  145. package/types/index.d.ts +1 -0
  146. package/types/index.js +1 -0
  147. package/utils/environment.js +1 -1
  148. package/utils/eth/parseTransaction/index.js +8 -10
  149. package/utils/fetch.d.ts +8 -0
  150. package/utils/fetch.js +44 -0
  151. package/utils/fetchStaticCache.js +2 -3
  152. package/utils/fetchStaticData.d.ts +1 -1
  153. package/utils/fetchStaticData.js +7 -4
  154. package/utils/index.d.ts +2 -0
  155. package/utils/index.js +2 -0
  156. package/utils/reportError.js +0 -1
  157. package/background/handlers/Extension.d.ts +0 -55
  158. package/background/handlers/Extension.js +0 -601
  159. package/background/handlers/Tabs.d.ts +0 -24
  160. package/background/handlers/Tabs.js +0 -194
  161. package/background/handlers/index.d.ts +0 -3
  162. package/background/handlers/index.js +0 -45
  163. package/cjs/background/handlers/Extension.js +0 -642
  164. package/cjs/background/handlers/Tabs.js +0 -222
  165. package/cjs/background/handlers/index.js +0 -54
  166. package/cjs/koni/background/events.js +0 -14
  167. package/koni/background/events.d.ts +0 -1
  168. package/koni/background/events.js +0 -7
package/storage/index.js CHANGED
@@ -1,52 +1,144 @@
1
1
  // Copyright 2019-2022 @polkadot/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import KoniDatabase from '@subwallet/extension-base/services/storage-service/databases';
5
+ import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
6
+ import { xglobal } from '@polkadot/x-global';
7
+ const hasLocalStorage = typeof localStorage !== 'undefined';
8
+
9
+ // Create localStorage adaptor
4
10
  export class SWStorage {
5
11
  _storage = {};
12
+ localStorage = hasLocalStorage ? localStorage : undefined;
13
+ kvDatabase = KoniDatabase.getInstance().keyValue;
14
+ isReady = false;
15
+ waitReadyHandler = createPromiseHandler();
16
+ get waitReady() {
17
+ return this.waitReadyHandler.promise;
18
+ }
6
19
  constructor() {
7
- this.sync();
20
+ this.sync().then(() => {
21
+ this.isReady = true;
22
+ this.waitReadyHandler.resolve(this);
23
+ }).catch(console.error);
8
24
  }
9
- setItem(key, value) {
25
+ async setItem(key, value) {
26
+ !this.isReady && (await this.waitReady);
10
27
  this._storage[key] = value;
11
- localStorage.setItem(key, value);
28
+ if (this.localStorage) {
29
+ var _this$localStorage;
30
+ (_this$localStorage = this.localStorage) === null || _this$localStorage === void 0 ? void 0 : _this$localStorage.setItem(key, value);
31
+ } else {
32
+ this.kvDatabase.put({
33
+ key,
34
+ value
35
+ }).catch(console.error);
36
+ }
37
+ }
38
+ async getEntries() {
39
+ !this.isReady && (await this.waitReady);
40
+ return Object.entries(this._storage);
41
+ }
42
+ async setMap(map) {
43
+ !this.isReady && (await this.waitReady);
44
+ this._storage = {
45
+ ...this._storage,
46
+ ...map
47
+ };
48
+ if (this.localStorage) {
49
+ Object.entries(map).forEach(([key, value]) => {
50
+ var _this$localStorage2;
51
+ (_this$localStorage2 = this.localStorage) === null || _this$localStorage2 === void 0 ? void 0 : _this$localStorage2.setItem(key, value);
52
+ });
53
+ } else {
54
+ const putList = Object.entries(map).map(([key, value]) => ({
55
+ key,
56
+ value
57
+ }));
58
+ this.kvDatabase.bulkPut(putList).catch(console.error);
59
+ }
60
+ }
61
+ async getItem(key) {
62
+ !this.isReady && (await this.waitReady);
63
+ return this._storage[key] || null;
12
64
  }
13
- getItem(key) {
14
- return this._storage[key] || localStorage.getItem(key) || null;
65
+ async getItems(keys) {
66
+ !this.isReady && (await this.waitReady);
67
+ return keys.map(key => this._storage[key] || null);
15
68
  }
16
- removeItem(key) {
69
+ async getMap(keys) {
70
+ !this.isReady && (await this.waitReady);
71
+ return keys.reduce((result, key) => {
72
+ result[key] = this._storage[key] || null;
73
+ return result;
74
+ }, {});
75
+ }
76
+ async removeItem(key) {
77
+ !this.isReady && (await this.waitReady);
17
78
  this._storage[key] && delete this._storage[key];
18
- localStorage.removeItem(key);
79
+ if (this.localStorage) {
80
+ this.localStorage.removeItem(key);
81
+ } else {
82
+ this.kvDatabase.where({
83
+ key
84
+ }).delete().catch(console.error);
85
+ }
86
+ }
87
+ async removeItems(keys) {
88
+ !this.isReady && (await this.waitReady);
89
+ keys.forEach(key => {
90
+ this._storage[key] && delete this._storage[key];
91
+ });
92
+ if (this.localStorage) {
93
+ keys.forEach(key => {
94
+ this.localStorage && this.localStorage.removeItem(key);
95
+ });
96
+ } else {
97
+ this.kvDatabase.where('key').anyOf(keys).delete().catch(console.error);
98
+ }
19
99
  }
20
- clear() {
100
+ async clear() {
101
+ !this.isReady && (await this.waitReady);
21
102
  this._storage = {};
22
- localStorage.clear();
103
+ if (this.localStorage) {
104
+ this.localStorage.clear();
105
+ } else {
106
+ this.kvDatabase.clear().catch(console.error);
107
+ }
23
108
  }
24
- key(index) {
109
+ async key(index) {
110
+ !this.isReady && (await this.waitReady);
25
111
  return Object.keys(this._storage)[index] || null;
26
112
  }
27
- length(index) {
113
+ async length(index) {
114
+ !this.isReady && (await this.waitReady);
28
115
  return Object.keys(this._storage)[index] || null;
29
116
  }
30
117
 
31
118
  // Additional methods
32
- keys() {
119
+ async keys() {
120
+ !this.isReady && (await this.waitReady);
33
121
  return Object.keys(this._storage) || [];
34
122
  }
35
- copy() {
123
+ async copy() {
124
+ !this.isReady && (await this.waitReady);
36
125
  return JSON.parse(JSON.stringify(this._storage));
37
126
  }
38
- sync() {
39
- this._storage = JSON.parse(JSON.stringify(localStorage));
127
+ async sync() {
128
+ if (this.localStorage) {
129
+ this._storage = JSON.parse(JSON.stringify(this.localStorage));
130
+ } else {
131
+ const items = await this.kvDatabase.toArray();
132
+ this._storage = {};
133
+ items.forEach(item => {
134
+ this._storage[item.key] = item.value;
135
+ });
136
+ }
40
137
  }
41
138
  static get instance() {
42
- // @ts-ignore
43
- if (!window.SWStorage) {
44
- console.log('SWStorage init');
45
- // @ts-ignore
46
- window.SWStorage = new SWStorage();
139
+ if (!xglobal.SWStorage) {
140
+ xglobal.SWStorage = new SWStorage();
47
141
  }
48
-
49
- // @ts-ignore
50
- return window.SWStorage;
142
+ return xglobal.SWStorage;
51
143
  }
52
144
  }
@@ -0,0 +1 @@
1
+ export * from './storage';
@@ -0,0 +1,4 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from "./storage.js";
@@ -0,0 +1,4 @@
1
+ export interface StorageDataInterface {
2
+ key: string;
3
+ value: unknown;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
package/types/index.d.ts CHANGED
@@ -15,3 +15,4 @@ export * from './fee';
15
15
  export * from './ordinal';
16
16
  export * from './transaction';
17
17
  export * from './yield';
18
+ export * from './common';
package/types/index.js CHANGED
@@ -8,4 +8,5 @@ export * from "./fee/index.js";
8
8
  export * from "./ordinal.js";
9
9
  export * from "./transaction.js";
10
10
  export * from "./yield/index.js";
11
+ export * from "./common/index.js";
11
12
  export {};
@@ -75,5 +75,5 @@ export const targetIsExtension = TARGET_ENV === 'extension';
75
75
  export const targetIsWeb = TARGET_ENV === 'webapp';
76
76
  export const targetIsMobile = TARGET_ENV === 'mobile';
77
77
  export const MODULE_SUPPORT = {
78
- MANTA_ZK: targetIsExtension
78
+ MANTA_ZK: false
79
79
  };
@@ -3,9 +3,9 @@
3
3
 
4
4
  import { _ERC20_ABI, _ERC721_ABI } from '@subwallet/extension-base/services/chain-service/helper';
5
5
  import { _getEvmAbiExplorer, _getEvmChainId, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
6
+ import { fetchJson } from '@subwallet/extension-base/utils';
6
7
  import { createTransactionFromRLP } from '@subwallet/extension-base/utils/eth';
7
8
  import { InputDataDecoder } from '@subwallet/extension-base/utils/eth/parseTransaction/base';
8
- import axios from 'axios';
9
9
  import BigN from 'bignumber.js';
10
10
  import { t } from 'i18next';
11
11
 
@@ -130,17 +130,15 @@ export const parseContractInput = async (input, contractAddress, network) => {
130
130
  if (contractAddress && network) {
131
131
  if (_getEvmAbiExplorer(network)) {
132
132
  try {
133
- const res = await axios.get(_getEvmAbiExplorer(network), {
133
+ const data = await fetchJson(_getEvmAbiExplorer(network), {
134
134
  params: {
135
135
  address: contractAddress
136
136
  },
137
137
  timeout: 3000
138
138
  });
139
-
140
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
141
- if (res.status === 200 && res.data.status === '1') {
142
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
143
- const abi = res.data.result;
139
+ if (data.status === '1') {
140
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
141
+ const abi = data.result;
144
142
  const temp = parseInputWithAbi(input, abi);
145
143
  if (temp) {
146
144
  return {
@@ -205,7 +203,7 @@ export const parseEvmRlp = async (data, networkMap, evmApiMap) => {
205
203
  if (await isContractAddress(tx.to, evmApiMap[network.slug])) {
206
204
  if (_getEvmAbiExplorer(network) !== '') {
207
205
  try {
208
- const res = await axios.get(_getEvmAbiExplorer(network), {
206
+ const data = await fetchJson(_getEvmAbiExplorer(network), {
209
207
  params: {
210
208
  address: tx.to
211
209
  },
@@ -213,9 +211,9 @@ export const parseEvmRlp = async (data, networkMap, evmApiMap) => {
213
211
  });
214
212
 
215
213
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
216
- if (res.status === 200 && res.data.status === '1') {
214
+ if (data.status === '1') {
217
215
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
218
- const abi = res.data.result;
216
+ const abi = data.result;
219
217
  const temp = parseInputWithAbi(tx.data, abi);
220
218
  if (temp) {
221
219
  result.data = temp;
@@ -0,0 +1,8 @@
1
+ export declare type fetchJsonOptions = RequestInit & {
2
+ params?: Record<string, string>;
3
+ data?: Record<string, unknown>;
4
+ timeout?: number;
5
+ };
6
+ export declare function fetchData(url: string, options?: fetchJsonOptions): Promise<Response>;
7
+ export declare function fetchJson<T = any>(url: string, options?: fetchJsonOptions): Promise<T>;
8
+ export declare function fetchText<T = any>(url: string, options?: fetchJsonOptions): Promise<T>;
package/utils/fetch.js ADDED
@@ -0,0 +1,44 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export async function fetchData(url, options = {}) {
5
+ const {
6
+ data,
7
+ params,
8
+ timeout,
9
+ ...fetchOptions
10
+ } = options;
11
+ let timeoutId;
12
+ if (timeout) {
13
+ const controller = new AbortController();
14
+ timeoutId = setTimeout(() => controller.abort(), timeout);
15
+ fetchOptions.signal = new AbortController().signal;
16
+ }
17
+ if (params) {
18
+ const urlParams = new URLSearchParams(params);
19
+ url = `${url}?${urlParams.toString()}`;
20
+ }
21
+ if (data) {
22
+ fetchOptions.headers = {
23
+ 'Content-Type': 'application/json',
24
+ Accept: 'application/json',
25
+ ...fetchOptions.headers
26
+ };
27
+ fetchOptions.body = JSON.stringify(data);
28
+ }
29
+ const response = await fetch(url, fetchOptions);
30
+ if (!response.ok) {
31
+ throw new Error(`HTTP error! Status: ${response.status}`);
32
+ } else {
33
+ clearTimeout(timeoutId);
34
+ }
35
+ return response;
36
+ }
37
+ export async function fetchJson(url, options = {}) {
38
+ const response = await fetchData(url, options);
39
+ return await response.json();
40
+ }
41
+ export async function fetchText(url, options = {}) {
42
+ const response = await fetchData(url, options);
43
+ return await response.text();
44
+ }
@@ -1,16 +1,15 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import axios from 'axios';
4
+ import { fetchJson } from '@subwallet/extension-base/utils/fetch';
5
5
  const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
6
6
  const branchName = process.env.BRANCH_NAME || 'koni-dev';
7
7
  const fetchTarget = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://static-cache.subwallet.app' : 'https://dev.sw-static-cache.pages.dev';
8
8
  export async function fetchStaticCache(slug, defaultData, timeout = 9000) {
9
9
  try {
10
- const rs = await axios.get(`${fetchTarget}/${slug}`, {
10
+ return await fetchJson(`${fetchTarget}/${slug}`, {
11
11
  timeout
12
12
  });
13
- return rs.data;
14
13
  } catch (e) {
15
14
  return defaultData;
16
15
  }
@@ -1 +1 @@
1
- export declare function fetchStaticData<T>(slug: string, targetFile?: string): Promise<T>;
1
+ export declare function fetchStaticData<T>(slug: string, targetFile?: string, isJson?: boolean): Promise<T>;
@@ -1,16 +1,19 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { fetchJson, fetchText } from '@subwallet/extension-base/utils/fetch';
4
5
  import { staticData } from '@subwallet/extension-base/utils/staticData';
5
- import axios from 'axios';
6
6
  const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
7
7
  const branchName = process.env.BRANCH_NAME || 'koni-dev';
8
8
  const fetchTarget = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list.json' : 'preview.json';
9
- export async function fetchStaticData(slug, targetFile) {
9
+ export async function fetchStaticData(slug, targetFile, isJson = true) {
10
10
  const fetchFile = targetFile || fetchTarget;
11
11
  try {
12
- const rs = await axios.get(`https://static-data.subwallet.app/${slug}/${fetchFile}`);
13
- return rs.data;
12
+ if (isJson) {
13
+ return await fetchJson(`https://static-data.subwallet.app/${slug}/${fetchFile}`);
14
+ } else {
15
+ return await fetchText(`https://static-data.subwallet.app/${slug}/${fetchFile}`);
16
+ }
14
17
  } catch (e) {
15
18
  return staticData[slug];
16
19
  }
package/utils/index.d.ts CHANGED
@@ -2,6 +2,8 @@ import { CrowdloanParaState, NetworkJson } from '@subwallet/extension-base/backg
2
2
  import { AccountAuthType, AccountJson } from '@subwallet/extension-base/background/types';
3
3
  import { BN } from '@polkadot/util';
4
4
  export { canDerive } from './canDerive';
5
+ export * from './mv3';
6
+ export * from './fetch';
5
7
  export declare const notDef: (x: any) => boolean;
6
8
  export declare const isDef: (x: any) => boolean;
7
9
  export declare const nonEmptyArr: (x: any) => boolean;
package/utils/index.js CHANGED
@@ -8,6 +8,8 @@ import { t } from 'i18next';
8
8
  import { assert, BN, hexToU8a, isHex } from '@polkadot/util';
9
9
  import { decodeAddress, encodeAddress, ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
10
10
  export { canDerive } from "./canDerive.js";
11
+ export * from "./mv3.js";
12
+ export * from "./fetch.js";
11
13
  export const notDef = x => x === null || typeof x === 'undefined';
12
14
  export const isDef = x => !notDef(x);
13
15
  export const nonEmptyArr = x => Array.isArray(x) && x.length > 0;
@@ -2,7 +2,6 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { TARGET_ENV } from '@subwallet/extension-base/utils/environment';
5
- import fetch from 'cross-fetch';
6
5
  const EXTENSION_REPORT_ERROR_URL = 'https://extension-feedback.subwallet.app/gelf';
7
6
  const WEBAPP_REPORT_ERROR_URL = 'https://web-feedback.subwallet.app/gelf';
8
7
  export const reportError = async (e, pathName) => {
@@ -1,55 +0,0 @@
1
- /// <reference types="chrome" />
2
- import type { KeyringPair } from '@subwallet/keyring/types';
3
- import type { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
4
- import type { KeypairType } from '@polkadot/util-crypto/types';
5
- import type { MessageTypes, RequestTypes, ResponseType } from '../types';
6
- import State from './State';
7
- declare type CachedUnlocks = Record<string, number>;
8
- export declare const SEED_DEFAULT_LENGTH = 12;
9
- export declare const SEED_LENGTHS: number[];
10
- export declare const ETH_DERIVE_DEFAULT = "/m/44'/60'/0'/0/0";
11
- export declare function getSuri(seed: string, type?: KeypairType): string;
12
- export declare function isJsonPayload(value: SignerPayloadJSON | SignerPayloadRaw): value is SignerPayloadJSON;
13
- export default class Extension {
14
- #private;
15
- protected readonly cachedUnlocks: CachedUnlocks;
16
- constructor(state: State);
17
- private accountsCreateExternal;
18
- private accountsCreateHardware;
19
- private accountsCreateSuri;
20
- private accountsChangePassword;
21
- private accountsEdit;
22
- private accountsExport;
23
- private accountsForget;
24
- protected refreshAccountPasswordCache(pair: KeyringPair): number;
25
- private accountsShow;
26
- private accountsTie;
27
- private accountsValidate;
28
- private accountsSubscribe;
29
- private authorizeApprove;
30
- private getAuthList;
31
- private authorizeReject;
32
- private authorizeSubscribe;
33
- private metadataApprove;
34
- private metadataGet;
35
- private metadataList;
36
- private metadataReject;
37
- private metadataSubscribe;
38
- private jsonRestore;
39
- private batchRestore;
40
- private jsonGetAccountInfo;
41
- private seedCreate;
42
- private seedValidate;
43
- private signingApprovePassword;
44
- private signingApproveSignature;
45
- private signingCancel;
46
- private signingIsLocked;
47
- private signingSubscribe;
48
- private windowOpen;
49
- private derive;
50
- private derivationValidate;
51
- private derivationCreate;
52
- private toggleAuthorization;
53
- handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
54
- }
55
- export {};