@arcblock/ux 2.5.23 → 2.5.24

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.
package/lib/Util/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.detectWalletExtension = detectWalletExtension;
6
7
  exports.formatToDate = formatToDate;
7
8
  exports.formatToDatetime = formatToDatetime;
8
9
  exports.getColor = exports.getBackground = exports.formatUptime = void 0;
@@ -289,9 +290,19 @@ function formatToDatetime(date) {
289
290
  });
290
291
  }
291
292
 
292
- function openWebWallet(_ref3) {
293
+ function detectWalletExtension() {
293
294
  var _window;
294
295
 
296
+ const extension = ((_window = window) === null || _window === void 0 ? void 0 : _window.ABT_DEV) || window.ABT;
297
+
298
+ if (extension && typeof extension.open === 'function') {
299
+ return extension;
300
+ }
301
+
302
+ return null;
303
+ }
304
+
305
+ function openWebWallet(_ref3) {
295
306
  let {
296
307
  webWalletUrl,
297
308
  action = 'login',
@@ -300,10 +311,10 @@ function openWebWallet(_ref3) {
300
311
  windowFeatures
301
312
  } = _ref3;
302
313
  // web wallet extension
303
- const webWalletExtension = ((_window = window) === null || _window === void 0 ? void 0 : _window.ABT_DEV) || window.ABT;
314
+ const extension = detectWalletExtension();
304
315
 
305
- if (webWalletExtension && typeof webWalletExtension.open === 'function') {
306
- webWalletExtension.open({
316
+ if (extension) {
317
+ extension.open({
307
318
  action,
308
319
  locale,
309
320
  url: encodeURIComponent(url)
@@ -15,6 +15,8 @@ var _useLocalStorage = _interopRequireDefault(require("react-use/lib/useLocalSto
15
15
 
16
16
  var _useBrowser = _interopRequireDefault(require("@arcblock/react-hooks/lib/useBrowser"));
17
17
 
18
+ var _Util = require("@arcblock/ux/lib/Util");
19
+
18
20
  var _wallet = require("../Util/wallet");
19
21
 
20
22
  var _jsxRuntime = require("react/jsx-runtime");
@@ -130,7 +132,7 @@ const withWebWalletSWKeeper = Component => {
130
132
 
131
133
  webWalletUrl = webWalletUrl || (0, _wallet.getWebWalletUrl)();
132
134
  const [disabled] = (0, _useLocalStorage.default)(STORAGE_KEY_DISABLED, 1);
133
- const webWalletExtension = window.ABT_DEV || window.ABT;
135
+ const extension = (0, _Util.detectWalletExtension)();
134
136
  const isSameProtocol = (0, _wallet.checkSameProtocol)(webWalletUrl);
135
137
  const isWalletWebview = browser.wallet; // 以下几种情况不会嵌入 wallet iframe :
136
138
  // - 通过设置 localStorage#wallet_sw_keeper_disabled = 1 明确禁止 (开发调试过程中可以使用, 避免控制台打印一堆日志影响调试)
@@ -139,7 +141,7 @@ const withWebWalletSWKeeper = Component => {
139
141
  // - wallet webview
140
142
 
141
143
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
142
- children: [!disabled && !webWalletExtension && isSameProtocol && !isWalletWebview && /*#__PURE__*/(0, _jsxRuntime.jsx)(WebWalletSWKeeper, {
144
+ children: [!disabled && !extension && isSameProtocol && !isWalletWebview && /*#__PURE__*/(0, _jsxRuntime.jsx)(WebWalletSWKeeper, {
143
145
  webWalletUrl: webWalletUrl,
144
146
  maxIdleTime: maxIdleTime
145
147
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, _objectSpread({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.5.23",
3
+ "version": "2.5.24",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -47,11 +47,11 @@
47
47
  "react": ">=18.1.0",
48
48
  "react-ga": "^2.7.0"
49
49
  },
50
- "gitHead": "4b21e8ef44e777eacef7be93e8792e37cef2998a",
50
+ "gitHead": "9745fcd6e990cdf75732781a3e05e3c4b987ce48",
51
51
  "dependencies": {
52
52
  "@arcblock/did-motif": "^1.1.10",
53
- "@arcblock/icons": "^2.5.23",
54
- "@arcblock/react-hooks": "^2.5.23",
53
+ "@arcblock/icons": "^2.5.24",
54
+ "@arcblock/react-hooks": "^2.5.24",
55
55
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
56
56
  "@emotion/react": "^11.10.4",
57
57
  "@emotion/styled": "^11.10.4",
package/src/Util/index.js CHANGED
@@ -227,11 +227,20 @@ export function formatToDatetime(date, { locale, tz } = {}) {
227
227
  return createDateFormater('lll')(date, { locale, tz });
228
228
  }
229
229
 
230
+ export function detectWalletExtension() {
231
+ const extension = window?.ABT_DEV || window.ABT;
232
+ if (extension && typeof extension.open === 'function') {
233
+ return extension;
234
+ }
235
+
236
+ return null;
237
+ }
238
+
230
239
  export function openWebWallet({ webWalletUrl, action = 'login', locale = 'en', url, windowFeatures }) {
231
240
  // web wallet extension
232
- const webWalletExtension = window?.ABT_DEV || window.ABT;
233
- if (webWalletExtension && typeof webWalletExtension.open === 'function') {
234
- webWalletExtension.open({
241
+ const extension = detectWalletExtension();
242
+ if (extension) {
243
+ extension.open({
235
244
  action,
236
245
  locale,
237
246
  url: encodeURIComponent(url),
@@ -3,6 +3,8 @@ import PropTypes from 'prop-types';
3
3
  import useIdle from 'react-use/lib/useIdle';
4
4
  import useLocalStorage from 'react-use/lib/useLocalStorage';
5
5
  import useBrowser from '@arcblock/react-hooks/lib/useBrowser';
6
+ import { detectWalletExtension } from '@arcblock/ux/lib/Util';
7
+
6
8
  import { getWebWalletUrl, checkSameProtocol } from '../Util/wallet';
7
9
 
8
10
  // 默认最大空闲时间: 30min
@@ -91,7 +93,7 @@ export const withWebWalletSWKeeper = (Component) => {
91
93
  // eslint-disable-next-line no-param-reassign
92
94
  webWalletUrl = webWalletUrl || getWebWalletUrl();
93
95
  const [disabled] = useLocalStorage(STORAGE_KEY_DISABLED, 1);
94
- const webWalletExtension = window.ABT_DEV || window.ABT;
96
+ const extension = detectWalletExtension();
95
97
  const isSameProtocol = checkSameProtocol(webWalletUrl);
96
98
  const isWalletWebview = browser.wallet;
97
99
  // 以下几种情况不会嵌入 wallet iframe :
@@ -101,7 +103,7 @@ export const withWebWalletSWKeeper = (Component) => {
101
103
  // - wallet webview
102
104
  return (
103
105
  <>
104
- {!disabled && !webWalletExtension && isSameProtocol && !isWalletWebview && (
106
+ {!disabled && !extension && isSameProtocol && !isWalletWebview && (
105
107
  <WebWalletSWKeeper webWalletUrl={webWalletUrl} maxIdleTime={maxIdleTime} />
106
108
  )}
107
109
  <Component webWalletUrl={webWalletUrl} {...rest} />