@subwallet/extension-base 1.1.68-2 → 1.2.1

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 +4 -1
  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 +4 -1
  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
@@ -1,8 +1,7 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { isSameAddress } from '@subwallet/extension-base/utils';
5
- import axios from 'axios';
4
+ import { fetchJson, isSameAddress } from '@subwallet/extension-base/utils';
6
5
  import { BehaviorSubject } from 'rxjs';
7
6
  import { MINT_HOST } from "../constants.js";
8
7
  export default class UnlockDotCampaign {
@@ -59,13 +58,13 @@ export default class UnlockDotCampaign {
59
58
  network
60
59
  }
61
60
  };
62
- const response = await axios.request({
63
- baseURL: this.#host,
64
- url: '/api/mint/check',
61
+ const respData = await fetchJson(`${this.#host}/api/mint/check`, {
65
62
  method: 'POST',
66
- data
63
+ headers: {
64
+ 'Content-Type': 'application/json'
65
+ },
66
+ body: JSON.stringify(data)
67
67
  });
68
- const respData = response.data;
69
68
  if (respData.inMintingTime && respData.hasBalance && respData.validCampaign && respData.validCategory && respData.validUser && respData.notDuplicated && respData.requestId && respData.requestId > 1) {
70
69
  return respData.requestId;
71
70
  }
@@ -76,13 +75,13 @@ export default class UnlockDotCampaign {
76
75
  requestId: id,
77
76
  recipient: address
78
77
  };
79
- const response = await axios.request({
80
- baseURL: this.#host,
81
- url: '/api/mint/submit',
78
+ return await fetchJson(`${this.#host}/api/mint/submit`, {
82
79
  method: 'POST',
83
- data
80
+ headers: {
81
+ 'Content-Type': 'application/json'
82
+ },
83
+ body: JSON.stringify(data)
84
84
  });
85
- return response.data;
86
85
  }
87
86
 
88
87
  // @ts-ignore
@@ -90,13 +89,10 @@ export default class UnlockDotCampaign {
90
89
  const params = {
91
90
  address
92
91
  };
93
- const response = await axios.request({
94
- baseURL: this.#host,
95
- url: '/api/mint/fetch',
92
+ const data = await fetchJson(`${this.#host}/api/mint/check`, {
96
93
  method: 'GET',
97
94
  params: params
98
95
  });
99
- const data = response.data;
100
96
  for (const item of data) {
101
97
  if (isSameAddress(item.address, address) && slug === item.mintCategory && item.status === 'success' && item.campaignId === this.#campaignId) {
102
98
  return item;
@@ -114,13 +110,13 @@ export default class UnlockDotCampaign {
114
110
  network
115
111
  }
116
112
  };
117
- const response = await axios.request({
118
- baseURL: this.#host,
119
- url: '/api/mint/check',
113
+ const respData = await fetchJson(`${this.#host}/api/mint/check`, {
120
114
  method: 'POST',
121
- data
115
+ headers: {
116
+ 'Content-Type': 'application/json'
117
+ },
118
+ body: JSON.stringify(data)
122
119
  });
123
- const respData = response.data;
124
120
  if (respData.inMintingTime && respData.validCampaign && respData.validCategory && respData.validUser && respData.notDuplicated) {
125
121
  return true;
126
122
  }
@@ -48,7 +48,9 @@ export default class NotificationService {
48
48
  if (onClick) {
49
49
  onClick();
50
50
  } else {
51
- window.open(link);
51
+ chrome.tabs.create({
52
+ url: link
53
+ }).catch(console.error);
52
54
  }
53
55
  }
54
56
  });
@@ -2,12 +2,12 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { staticData, StaticKey } from '@subwallet/extension-base/utils/staticData';
5
- import axios from 'axios';
6
5
  const DEFAULT_CURRENCY = 'USD';
7
6
  let useBackupApi = false;
8
7
  export const getExchangeRateMap = async () => {
9
8
  try {
10
- const responseDataExchangeRate = (await axios.get('https://api-cache.subwallet.app/exchange-rate')).data || {};
9
+ const response = await fetch('https://api-cache.subwallet.app/exchange-rate');
10
+ const responseDataExchangeRate = (await response.json()) || {};
11
11
  const exchangeRateMap = Object.keys(responseDataExchangeRate.conversion_rates).reduce((map, exchangeKey) => {
12
12
  if (!staticData[StaticKey.CURRENCY_SYMBOL][exchangeKey]) {
13
13
  return map;
@@ -25,24 +25,24 @@ export const getExchangeRateMap = async () => {
25
25
  }
26
26
  };
27
27
  export const getPriceMap = async (priceIds, currency = 'USD') => {
28
- var _rs, _rs2, _rs3;
28
+ var _rs, _rs2;
29
29
  const idStr = Array.from(priceIds).join(',');
30
30
  let rs;
31
31
  if (!useBackupApi) {
32
32
  try {
33
- rs = await axios.get(`https://api.coingecko.com/api/v3/coins/markets?vs_currency=${currency.toLowerCase()}&per_page=250&ids=${idStr}`);
33
+ rs = await fetch(`https://api.coingecko.com/api/v3/coins/markets?vs_currency=${currency.toLowerCase()}&per_page=250&ids=${idStr}`);
34
34
  } catch (err) {
35
35
  useBackupApi = true;
36
36
  }
37
37
  }
38
38
  if (useBackupApi || ((_rs = rs) === null || _rs === void 0 ? void 0 : _rs.status) !== 200) {
39
39
  useBackupApi = true;
40
- rs = await axios.get(`https://chain-data.subwallet.app/api/price/get?ids=${idStr}`);
40
+ rs = await fetch(`https://chain-data.subwallet.app/api/price/get?ids=${idStr}`);
41
41
  }
42
42
  if (((_rs2 = rs) === null || _rs2 === void 0 ? void 0 : _rs2.status) !== 200) {
43
43
  console.warn('Failed to get token price');
44
44
  }
45
- const responseDataPrice = ((_rs3 = rs) === null || _rs3 === void 0 ? void 0 : _rs3.data) || [];
45
+ const responseDataPrice = (await rs.json()) || [];
46
46
  const currencyData = staticData[StaticKey.CURRENCY_SYMBOL][currency || DEFAULT_CURRENCY];
47
47
  const priceMap = {};
48
48
  const price24hMap = {};
@@ -36,8 +36,9 @@ export class PriceService {
36
36
  this.eventService = eventService;
37
37
  this.chainService = chainService;
38
38
  const updateCurrency = currentCurrency => {
39
- const currency = SWStorage.instance.getItem(CURRENCY);
40
- this.setCurrentCurrency(currency || currentCurrency || DEFAULT_CURRENCY);
39
+ SWStorage.instance.getItem(CURRENCY).then(currency => {
40
+ this.setCurrentCurrency(currency || currentCurrency || DEFAULT_CURRENCY);
41
+ }).catch(console.error);
41
42
  };
42
43
  this.init().then(() => this.getCurrentCurrency(updateCurrency)).catch(console.error);
43
44
  }
@@ -87,6 +88,9 @@ export class PriceService {
87
88
  } = this.rawPriceSubject.value;
88
89
  const exchangeRateData = this.rawExchangeRateMap.value;
89
90
  const currencyKey = currency || DEFAULT_CURRENCY;
91
+ if (Object.keys(this.rawPriceSubject.value).length === 0) {
92
+ return;
93
+ }
90
94
  if (Object.keys(exchangeRateData).length === 0) {
91
95
  return;
92
96
  }
@@ -126,7 +130,7 @@ export class PriceService {
126
130
 
127
131
  // Await 1s to get the latest exchange rate
128
132
  await new Promise(resolve => setTimeout(resolve, 300));
129
- SWStorage.instance.setItem(CURRENCY, newCurrencyCode);
133
+ await SWStorage.instance.setItem(CURRENCY, newCurrencyCode);
130
134
  return true;
131
135
  }
132
136
  refreshPriceData(priceIds) {
@@ -1,5 +1,5 @@
1
1
  import RequestService from '@subwallet/extension-base/services/request-service';
2
- export declare function openPopup(url: string): void;
2
+ export declare function openPopup(url: string): Promise<void>;
3
3
  export default class PopupHandler {
4
4
  #private;
5
5
  constructor(requestService: RequestService);
@@ -4,7 +4,7 @@
4
4
  import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
5
5
  import { DEFAULT_NOTIFICATION_TYPE } from '@subwallet/extension-base/services/setting-service/constants';
6
6
  import { osName } from '@subwallet/extension-base/utils';
7
- const NOTIFICATION_URL = chrome.extension.getURL('notification.html');
7
+ const NOTIFICATION_URL = chrome.runtime.getURL('notification.html');
8
8
  const extraHeight = osName === 'Linux' ? 0 : 28;
9
9
  const extraWidth = osName === 'Windows' ? 16 : 0;
10
10
  const POPUP_WINDOW_OPTS = {
@@ -19,18 +19,17 @@ const NORMAL_WINDOW_OPTS = {
19
19
  type: 'normal',
20
20
  url: NOTIFICATION_URL
21
21
  };
22
- export function openPopup(url) {
23
- chrome.windows.getCurrent(win => {
24
- const popupOptions = {
25
- ...POPUP_WINDOW_OPTS,
26
- url
27
- };
28
- if (win) {
29
- popupOptions.left = (win.left || 0) + (win.width || 0) - (popupOptions.width || 0) - 20;
30
- popupOptions.top = (win.top || 0) + 110;
31
- }
32
- chrome.windows.create(popupOptions).catch(console.error);
33
- });
22
+ export async function openPopup(url) {
23
+ const win = await chrome.windows.getCurrent();
24
+ const popupOptions = {
25
+ ...POPUP_WINDOW_OPTS,
26
+ url
27
+ };
28
+ if (win) {
29
+ popupOptions.left = (win.left || 0) + (win.width || 0) - (popupOptions.width || 0) - 20;
30
+ popupOptions.top = (win.top || 0) + 110;
31
+ }
32
+ await chrome.windows.create(popupOptions);
34
33
  }
35
34
  export default class PopupHandler {
36
35
  #requestService;
@@ -50,8 +49,8 @@ export default class PopupHandler {
50
49
  const numRequests = this.#requestService.numRequests;
51
50
  const text = numRequests > 0 ? numRequests.toString() : '';
52
51
  withErrorLog(() => {
53
- var _chrome$browserAction;
54
- return (_chrome$browserAction = chrome.browserAction) === null || _chrome$browserAction === void 0 ? void 0 : _chrome$browserAction.setBadgeText({
52
+ var _chrome$action;
53
+ return (_chrome$action = chrome.action) === null || _chrome$action === void 0 ? void 0 : _chrome$action.setBadgeText({
55
54
  text
56
55
  });
57
56
  });
@@ -4,6 +4,7 @@ export default class SettingService {
4
4
  private readonly settingsStore;
5
5
  private readonly passPhishingStore;
6
6
  constructor();
7
+ private initSetting;
7
8
  getSubject(): Subject<RequestSettingsType>;
8
9
  getSettings(update: (value: RequestSettingsType) => void): void;
9
10
  setSettings(data: RequestSettingsType, callback?: () => void): void;
@@ -11,7 +11,10 @@ export default class SettingService {
11
11
  settingsStore = new SettingsStore();
12
12
  passPhishingStore = new PassPhishingStore();
13
13
  constructor() {
14
- let old = SWStorage.instance.getItem(LANGUAGE) || 'en';
14
+ this.initSetting().catch(console.error);
15
+ }
16
+ async initSetting() {
17
+ let old = (await SWStorage.instance.getItem(LANGUAGE)) || 'en';
15
18
  const updateLanguage = ({
16
19
  language
17
20
  }) => {
@@ -2,11 +2,11 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { ThemeNames, WalletUnlockType } from '@subwallet/extension-base/background/KoniTypes';
5
- import { TARGET_ENV } from '@subwallet/extension-base/utils';
5
+ import { targetIsExtension } from '@subwallet/extension-base/utils';
6
6
  export const DEFAULT_THEME = ThemeNames.DARK;
7
7
  export const DEFAULT_NOTIFICATION_TYPE = 'popup';
8
8
  export const DEFAULT_AUTO_LOCK_TIME = 15;
9
- export const DEFAULT_UNLOCK_TYPE = TARGET_ENV === 'extension' ? WalletUnlockType.ALWAYS_REQUIRED : WalletUnlockType.WHEN_NEEDED;
9
+ export const DEFAULT_UNLOCK_TYPE = targetIsExtension ? WalletUnlockType.ALWAYS_REQUIRED : WalletUnlockType.WHEN_NEEDED;
10
10
  export const DEFAULT_CHAIN_PATROL_ENABLE = false;
11
11
  export const DEFAULT_LANGUAGE = 'en';
12
12
  export const DEFAULT_CURRENCY = 'usd';
@@ -1,8 +1,6 @@
1
1
  // Copyright 2019-2022 @polkadot/extension-ui authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { LANGUAGE } from '@subwallet/extension-base/constants';
5
- import { SWStorage } from '@subwallet/extension-base/storage';
6
4
  import i18next from 'i18next';
7
5
  import Backend from "./Backend.js";
8
6
  i18next.use(Backend).init({
@@ -13,10 +11,10 @@ i18next.use(Backend).init({
13
11
  escapeValue: false
14
12
  },
15
13
  keySeparator: false,
16
- lng: SWStorage.instance.getItem(LANGUAGE) || 'en',
14
+ lng: 'en',
17
15
  load: 'languageOnly',
18
16
  nsSeparator: false,
19
17
  returnEmptyString: false,
20
18
  returnNull: false
21
- }).catch(error => console.log('i18n: failure', error));
19
+ }).catch(console.error);
22
20
  export default i18next;
@@ -21,7 +21,7 @@ export default class DatabaseService {
21
21
  constructor(eventService) {
22
22
  this.eventService = eventService;
23
23
  this.logger = createLogger('DB-Service');
24
- this._db = new KoniDatabase();
24
+ this._db = KoniDatabase.getInstance();
25
25
  this._db.on('ready', () => {
26
26
  this.eventService.emit('database.ready', true);
27
27
  });
@@ -2,6 +2,7 @@ import { _AssetRef, _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types'
2
2
  import { CampaignData, ChainStakingMetadata, CrowdloanItem, MetadataItem, NftCollection, NftItem, NominatorMetadata, PriceJson, StakingItem, TransactionHistoryItem } from '@subwallet/extension-base/background/KoniTypes';
3
3
  import { BalanceItem, YieldPoolInfo, YieldPositionInfo } from '@subwallet/extension-base/types';
4
4
  import Dexie, { Table } from 'dexie';
5
+ export declare const DEFAULT_DATABASE = "SubWalletDB_v2";
5
6
  export interface DefaultChainDoc {
6
7
  chain: string;
7
8
  }
@@ -19,6 +20,10 @@ export interface IChain extends _ChainInfo {
19
20
  }
20
21
  export interface ICrowdloanItem extends CrowdloanItem, DefaultAddressDoc, DefaultChainDoc {
21
22
  }
23
+ export interface IKeyValue {
24
+ key: string;
25
+ value: string;
26
+ }
22
27
  export interface INft extends NftItem, DefaultAddressDoc {
23
28
  }
24
29
  export interface ITransactionHistoryItem extends TransactionHistoryItem, DefaultAddressDoc, DefaultChainDoc {
@@ -53,7 +58,10 @@ export default class KoniDatabase extends Dexie {
53
58
  yieldPosition: Table<YieldPositionInfo, object>;
54
59
  mantaPay: Table<IMantaPayLedger, object>;
55
60
  campaign: Table<ICampaign, object>;
61
+ keyValue: Table<IKeyValue, object>;
56
62
  private schemaVersion;
57
63
  constructor(name?: string, schemaVersion?: number);
58
64
  private conditionalVersion;
65
+ static instance: KoniDatabase;
66
+ static getInstance(name?: string, schemaVersion?: number): KoniDatabase;
59
67
  }
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import Dexie from 'dexie';
5
- const DEFAULT_DATABASE = 'SubWalletDB_v2';
5
+ export const DEFAULT_DATABASE = 'SubWalletDB_v2';
6
6
  export default class KoniDatabase extends Dexie {
7
7
  constructor(name = DEFAULT_DATABASE, schemaVersion = 11) {
8
8
  super(name);
@@ -37,6 +37,9 @@ export default class KoniDatabase extends Dexie {
37
37
  this.conditionalVersion(5, {
38
38
  campaign: 'slug'
39
39
  });
40
+ this.conditionalVersion(6, {
41
+ keyValue: 'key'
42
+ });
40
43
  }
41
44
  conditionalVersion(version, schema, upgrade) {
42
45
  if (this.schemaVersion != null && this.schemaVersion < version) {
@@ -47,4 +50,13 @@ export default class KoniDatabase extends Dexie {
47
50
  dexieVersion.upgrade(upgrade);
48
51
  }
49
52
  }
53
+
54
+ // Singletons
55
+
56
+ static getInstance(name, schemaVersion) {
57
+ if (!KoniDatabase.instance) {
58
+ KoniDatabase.instance = new KoniDatabase(name, schemaVersion);
59
+ }
60
+ return KoniDatabase.instance;
61
+ }
50
62
  }
@@ -0,0 +1,4 @@
1
+ import { IKeyValue } from '@subwallet/extension-base/services/storage-service/databases';
2
+ import BaseStore from '@subwallet/extension-base/services/storage-service/db-stores/BaseStore';
3
+ export default class KeyValueStore extends BaseStore<IKeyValue> {
4
+ }
@@ -0,0 +1,5 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import BaseStore from '@subwallet/extension-base/services/storage-service/db-stores/BaseStore';
5
+ export default class KeyValueStore extends BaseStore {}
@@ -39,4 +39,6 @@ export declare class SubscanService {
39
39
  getRewardHistoryList(chain: string, address: string, page?: number): Promise<RewardHistoryListResponse>;
40
40
  getAccountRemarkEvents(chain: string, address: string): Promise<SubscanEventBaseItemData[]>;
41
41
  getExtrinsicParams(chain: string, extrinsicIndexes: string[], ordinal?: number): Promise<SubscanExtrinsicParam[]>;
42
+ private static _instance;
43
+ static getInstance(): SubscanService;
42
44
  }
@@ -3,8 +3,8 @@
3
3
 
4
4
  import { SWError } from '@subwallet/extension-base/background/errors/SWError';
5
5
  import { BASE_FETCH_ORDINAL_EVENT_DATA } from '@subwallet/extension-base/koni/api/nft/ordinal_nft/constants';
6
+ import { SUBSCAN_API_CHAIN_MAP } from '@subwallet/extension-base/services/subscan-service/subscan-chain-map';
6
7
  import { wait } from '@subwallet/extension-base/utils';
7
- import fetch from 'cross-fetch';
8
8
  const QUERY_ROW = 100;
9
9
  export class SubscanService {
10
10
  callRate = 2; // limit per interval check
@@ -313,4 +313,13 @@ export class SubscanService {
313
313
  return jsonData.data;
314
314
  }, ordinal);
315
315
  }
316
+
317
+ // Singleton
318
+
319
+ static getInstance() {
320
+ if (!SubscanService._instance) {
321
+ SubscanService._instance = new SubscanService(SUBSCAN_API_CHAIN_MAP);
322
+ }
323
+ return SubscanService._instance;
324
+ }
316
325
  }
@@ -25,7 +25,7 @@ import { addHexPrefix } from 'ethereumjs-util';
25
25
  import { ethers } from 'ethers';
26
26
  import EventEmitter from 'eventemitter3';
27
27
  import { t } from 'i18next';
28
- import { BehaviorSubject } from 'rxjs';
28
+ import { BehaviorSubject, interval as rxjsInterval } from 'rxjs';
29
29
  import { isHex } from '@polkadot/util';
30
30
  import { _TRANSFER_CHAIN_GROUP } from "../chain-service/constants.js";
31
31
  export default class TransactionService {
@@ -1000,8 +1000,8 @@ export default class TransactionService {
1000
1000
  // eslint-disable-next-line prefer-const
1001
1001
  let subscribe;
1002
1002
  const onComplete = () => {
1003
- var _subscribe, _subscribe$unsubscrib, _subscribe$unsubscrib2;
1004
- (_subscribe = subscribe) === null || _subscribe === void 0 ? void 0 : (_subscribe$unsubscrib = _subscribe.unsubscribe) === null || _subscribe$unsubscrib === void 0 ? void 0 : (_subscribe$unsubscrib2 = _subscribe$unsubscrib.call(_subscribe)) === null || _subscribe$unsubscrib2 === void 0 ? void 0 : _subscribe$unsubscrib2.then(console.debug).catch(console.debug);
1003
+ var _subscribe, _subscribe$unsubscrib;
1004
+ (_subscribe = subscribe) === null || _subscribe === void 0 ? void 0 : (_subscribe$unsubscrib = _subscribe.unsubscribe) === null || _subscribe$unsubscrib === void 0 ? void 0 : _subscribe$unsubscrib.call(_subscribe);
1005
1005
  delete this.watchTransactionSubscribes[id];
1006
1006
  };
1007
1007
  const onSuccess = rs => {
@@ -1026,7 +1026,7 @@ export default class TransactionService {
1026
1026
  const onCheck = () => {
1027
1027
  web3Api.eth.getTransactionReceipt(txHash).then(onSuccess).catch(onError);
1028
1028
  };
1029
- subscribe = web3Api.eth.subscribe('newBlockHeaders', onCheck);
1029
+ subscribe = rxjsInterval(3000).subscribe(onCheck);
1030
1030
  });
1031
1031
  } else {
1032
1032
  this.removeTransaction(id);
@@ -2,13 +2,13 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { EIP155_SIGNING_METHODS, POLKADOT_SIGNING_METHODS } from '@subwallet/extension-base/services/wallet-connect-service/types';
5
- import { isMobile } from '@subwallet/extension-base/utils';
5
+ import { targetIsMobile } from '@subwallet/extension-base/utils';
6
6
  export const PROJECT_ID_EXTENSION = '6da34c0b48164d27681924dd9a46d6be';
7
7
  export const PROJECT_ID_MOBILE = '6da34c0b48164d27681924dd9a46d6be';
8
8
  export const RELAY_URL = 'wss://relay.walletconnect.com';
9
9
  export const DEFAULT_WALLET_CONNECT_OPTIONS = {
10
- logger: 'debug',
11
- projectId: !isMobile ? PROJECT_ID_EXTENSION : PROJECT_ID_MOBILE,
10
+ logger: 'error',
11
+ projectId: targetIsMobile ? PROJECT_ID_MOBILE : PROJECT_ID_EXTENSION,
12
12
  relayUrl: RELAY_URL,
13
13
  metadata: {
14
14
  name: 'SubWallet',
@@ -55,10 +55,7 @@ export const isWalletConnectRequest = id => {
55
55
  return prefix === WALLET_CONNECT_REQUEST_KEY;
56
56
  };
57
57
  export const isProposalExpired = params => {
58
- const timeNum = params.expiry;
59
- const expireTime = new Date(timeNum > 10 ** 12 ? timeNum : timeNum * 1000);
60
- const now = new Date();
61
- return now.getTime() >= expireTime.getTime();
58
+ return params.expiryTimestamp * 1000 < Date.now();
62
59
  };
63
60
  export const isSupportWalletConnectNamespace = namespace => {
64
61
  return WALLET_CONNECT_SUPPORT_NAMESPACES.includes(namespace);
@@ -7,6 +7,8 @@ export default class WalletConnectService {
7
7
  #private;
8
8
  readonly sessionSubject: BehaviorSubject<SessionTypes.Struct[]>;
9
9
  constructor(koniState: KoniState, requestService: RequestService, option?: SignClientTypes.Options);
10
+ private haveData;
11
+ initClient(force?: boolean): Promise<void>;
10
12
  get sessions(): SessionTypes.Struct[];
11
13
  getSession(topic: string): SessionTypes.Struct;
12
14
  changeOption(newOption: Omit<SignClientTypes.Options, 'projectId'>): Promise<void>;
@@ -16,14 +16,31 @@ import { EIP155_SIGNING_METHODS, POLKADOT_SIGNING_METHODS } from "./types.js";
16
16
  const storage = SWStorage.instance;
17
17
  const methodDOTRequire = [POLKADOT_SIGNING_METHODS.POLKADOT_SIGN_MESSAGE, POLKADOT_SIGNING_METHODS.POLKADOT_SIGN_TRANSACTION];
18
18
  const methodEVMRequire = [EIP155_SIGNING_METHODS.PERSONAL_SIGN, EIP155_SIGNING_METHODS.ETH_SIGN, EIP155_SIGNING_METHODS.ETH_SEND_TRANSACTION];
19
+ class WCStorage {
20
+ async getEntries() {
21
+ const datas = await storage.getEntries();
22
+ return Promise.resolve(datas.filter(([key]) => key.startsWith('wc@')).map(([key, value]) => [key, JSON.parse(value)]));
23
+ }
24
+ async getItem(key) {
25
+ const data = await storage.getItem(key);
26
+ return data ? JSON.parse(data) : undefined;
27
+ }
28
+ async getKeys() {
29
+ return (await storage.keys()).filter(key => key.startsWith('wc@'));
30
+ }
31
+ async removeItem(key) {
32
+ return await storage.removeItem(key);
33
+ }
34
+ async setItem(key, value) {
35
+ return await storage.setItem(key, JSON.stringify(value));
36
+ }
37
+ }
19
38
  var _requestService = /*#__PURE__*/_classPrivateFieldLooseKey("requestService");
20
39
  var _polkadotRequestHandler = /*#__PURE__*/_classPrivateFieldLooseKey("polkadotRequestHandler");
21
40
  var _eip155RequestHandler = /*#__PURE__*/_classPrivateFieldLooseKey("eip155RequestHandler");
22
41
  var _koniState = /*#__PURE__*/_classPrivateFieldLooseKey("koniState");
23
42
  var _client = /*#__PURE__*/_classPrivateFieldLooseKey("client");
24
43
  var _option = /*#__PURE__*/_classPrivateFieldLooseKey("option");
25
- var _haveData = /*#__PURE__*/_classPrivateFieldLooseKey("haveData");
26
- var _initClient = /*#__PURE__*/_classPrivateFieldLooseKey("initClient");
27
44
  var _updateSessions = /*#__PURE__*/_classPrivateFieldLooseKey("updateSessions");
28
45
  var _onSessionProposal = /*#__PURE__*/_classPrivateFieldLooseKey("onSessionProposal");
29
46
  var _onSessionRequest = /*#__PURE__*/_classPrivateFieldLooseKey("onSessionRequest");
@@ -50,13 +67,6 @@ export default class WalletConnectService {
50
67
  Object.defineProperty(this, _updateSessions, {
51
68
  value: _updateSessions2
52
69
  });
53
- Object.defineProperty(this, _initClient, {
54
- value: _initClient2
55
- });
56
- Object.defineProperty(this, _haveData, {
57
- get: _get_haveData,
58
- set: void 0
59
- });
60
70
  Object.defineProperty(this, _requestService, {
61
71
  writable: true,
62
72
  value: void 0
@@ -84,10 +94,28 @@ export default class WalletConnectService {
84
94
  this.sessionSubject = new BehaviorSubject([]);
85
95
  _classPrivateFieldLooseBase(this, _koniState)[_koniState] = koniState;
86
96
  _classPrivateFieldLooseBase(this, _requestService)[_requestService] = requestService;
97
+ option.storage = new WCStorage();
87
98
  _classPrivateFieldLooseBase(this, _option)[_option] = option;
88
99
  _classPrivateFieldLooseBase(this, _polkadotRequestHandler)[_polkadotRequestHandler] = new PolkadotRequestHandler(this, requestService);
89
100
  _classPrivateFieldLooseBase(this, _eip155RequestHandler)[_eip155RequestHandler] = new Eip155RequestHandler(_classPrivateFieldLooseBase(this, _koniState)[_koniState], this);
90
- _classPrivateFieldLooseBase(this, _initClient)[_initClient]().catch(console.error);
101
+ this.initClient().catch(console.error);
102
+ }
103
+ async haveData() {
104
+ const sessionStorage = await storage.getItem('wc@2:client:0.3//session');
105
+ const pairingStorage = await storage.getItem('wc@2:core:0.3//pairing');
106
+ const subscriptionStorage = await storage.getItem('wc@2:core:0.3//subscription');
107
+ const sessions = sessionStorage ? JSON.parse(sessionStorage) : [];
108
+ const pairings = pairingStorage ? JSON.parse(pairingStorage) : [];
109
+ const subscriptions = subscriptionStorage ? JSON.parse(subscriptionStorage) : [];
110
+ return !!sessions.length || !!pairings.length || !!subscriptions.length;
111
+ }
112
+ async initClient(force) {
113
+ _classPrivateFieldLooseBase(this, _removeListener)[_removeListener]();
114
+ if (force || (await this.haveData())) {
115
+ _classPrivateFieldLooseBase(this, _client)[_client] = await SignClient.init(_classPrivateFieldLooseBase(this, _option)[_option]);
116
+ }
117
+ _classPrivateFieldLooseBase(this, _updateSessions)[_updateSessions]();
118
+ _classPrivateFieldLooseBase(this, _createListener)[_createListener]();
91
119
  }
92
120
  get sessions() {
93
121
  var _classPrivateFieldLoo;
@@ -104,12 +132,12 @@ export default class WalletConnectService {
104
132
  }
105
133
  async changeOption(newOption) {
106
134
  _classPrivateFieldLooseBase(this, _option)[_option] = Object.assign({}, _classPrivateFieldLooseBase(this, _option)[_option], newOption);
107
- await _classPrivateFieldLooseBase(this, _initClient)[_initClient]();
135
+ await this.initClient();
108
136
  }
109
137
  async connect(uri) {
110
138
  var _classPrivateFieldLoo3;
111
- if (!_classPrivateFieldLooseBase(this, _haveData)[_haveData]) {
112
- await _classPrivateFieldLooseBase(this, _initClient)[_initClient](true);
139
+ if (!(await this.haveData())) {
140
+ await this.initClient(true);
113
141
  }
114
142
  _classPrivateFieldLooseBase(this, _checkClient)[_checkClient]();
115
143
  await ((_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(this, _client)[_client]) === null || _classPrivateFieldLoo3 === void 0 ? void 0 : _classPrivateFieldLoo3.pair({
@@ -182,7 +210,7 @@ export default class WalletConnectService {
182
210
  console.error(e);
183
211
  }
184
212
  }
185
- await _classPrivateFieldLooseBase(this, _initClient)[_initClient]();
213
+ await this.initClient();
186
214
  _classPrivateFieldLooseBase(this, _updateSessions)[_updateSessions]();
187
215
  }
188
216
  async disconnect(topic) {
@@ -204,23 +232,6 @@ export default class WalletConnectService {
204
232
  }, []);
205
233
  }
206
234
  }
207
- function _get_haveData() {
208
- const sessionStorage = storage.getItem('wc@2:client:0.3//session');
209
- const pairingStorage = storage.getItem('wc@2:core:0.3//pairing');
210
- const subscriptionStorage = storage.getItem('wc@2:core:0.3//subscription');
211
- const sessions = sessionStorage ? JSON.parse(sessionStorage) : [];
212
- const pairings = pairingStorage ? JSON.parse(pairingStorage) : [];
213
- const subscriptions = subscriptionStorage ? JSON.parse(subscriptionStorage) : [];
214
- return !!sessions.length || !!pairings.length || !!subscriptions.length;
215
- }
216
- async function _initClient2(force) {
217
- _classPrivateFieldLooseBase(this, _removeListener)[_removeListener]();
218
- if (force || _classPrivateFieldLooseBase(this, _haveData)[_haveData]) {
219
- _classPrivateFieldLooseBase(this, _client)[_client] = await SignClient.init(_classPrivateFieldLooseBase(this, _option)[_option]);
220
- }
221
- _classPrivateFieldLooseBase(this, _updateSessions)[_updateSessions]();
222
- _classPrivateFieldLooseBase(this, _createListener)[_createListener]();
223
- }
224
235
  function _updateSessions2() {
225
236
  this.sessionSubject.next(this.sessions);
226
237
  }
@@ -1,14 +1,24 @@
1
1
  export declare class SWStorage {
2
2
  private _storage;
3
+ private localStorage;
4
+ private kvDatabase;
5
+ private isReady;
6
+ private waitReadyHandler;
7
+ get waitReady(): Promise<SWStorage>;
3
8
  constructor();
4
- setItem(key: string, value: string): void;
5
- getItem(key: string): string | null;
6
- removeItem(key: string): void;
7
- clear(): void;
8
- key(index: number): string | null;
9
- length(index: number): string | null;
10
- keys(): string[];
11
- copy(): Record<string, string>;
12
- sync(): void;
9
+ setItem(key: string, value: string): Promise<void>;
10
+ getEntries(): Promise<[string, string][]>;
11
+ setMap(map: Record<string, string>): Promise<void>;
12
+ getItem(key: string): Promise<string | null>;
13
+ getItems(keys: string[]): Promise<Array<string | null>>;
14
+ getMap(keys: string[]): Promise<Record<string, string | null>>;
15
+ removeItem(key: string): Promise<void>;
16
+ removeItems(keys: string[]): Promise<void>;
17
+ clear(): Promise<void>;
18
+ key(index: number): Promise<string | null>;
19
+ length(index: number): Promise<string | null>;
20
+ keys(): Promise<string[]>;
21
+ copy(): Promise<Record<string, string>>;
22
+ sync(): Promise<void>;
13
23
  static get instance(): SWStorage;
14
24
  }