@arcblock/ux 2.10.45 → 2.10.47

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.
@@ -17,6 +17,7 @@ interface IDIDPropTypes extends IDidAddressWrapper {
17
17
  endChars?: number;
18
18
  locale?: 'en' | 'zh';
19
19
  chainId?: string;
20
+ roleType?: number;
20
21
  }
21
22
  export interface HTMLDIDElement extends HTMLDidAddressElement {
22
23
  openQRCode: () => void;
package/lib/DID/index.js CHANGED
@@ -15,7 +15,7 @@ import { translate } from '../Locale/util';
15
15
  import { getDIDColor, isEthereumDid } from '../Util';
16
16
  const translations = {
17
17
  en: {
18
- scanQrcode: 'Scan with DID Wallet to view this {role}',
18
+ scanQrcode: 'Scan with DID Wallet to view the {role}',
19
19
  download: 'Download',
20
20
  downloadTips: "Don't have DID Wallet ?"
21
21
  },
@@ -47,6 +47,9 @@ const isSquareMotif = roleType => {
47
47
  return !roles[roleType];
48
48
  };
49
49
  const getRoleName = roleType => {
50
+ if (roleType === types.RoleType.ROLE_ANY) {
51
+ return 'DID';
52
+ }
50
53
  const [roleName] = Object.entries(types.RoleType).find(item => item[1] === roleType) || [];
51
54
  if (roleName) {
52
55
  // UpperCase first word, example:
@@ -54,7 +57,7 @@ const getRoleName = roleType => {
54
57
  // ROLE_APPLICATION -> Application
55
58
  return roleName.toLowerCase().replace(/role_(\S)/g, (_, $1) => $1.toUpperCase());
56
59
  }
57
- return 'Address';
60
+ return 'DID';
58
61
  };
59
62
  const getAvatarSize = (didMotifInfo, isEthDid, size) => {
60
63
  if (isEthDid) {
@@ -223,7 +226,7 @@ const DID = /*#__PURE__*/forwardRef((props, ref) => {
223
226
  fontSize: 18
224
227
  },
225
228
  children: t('scanQrcode', {
226
- role: getRoleName(didMotifInfo?.roleType)
229
+ role: getRoleName(props.roleType || didMotifInfo?.roleType)
227
230
  })
228
231
  }), /*#__PURE__*/_jsx(QRCode
229
232
  // eslint-disable-next-line max-len
@@ -1,13 +1,13 @@
1
1
  # withTracker
2
2
 
3
- Add arcblock analytics, google analytics and sentry error reporting to your application.
3
+ Add google analytics reporting to your application.
4
4
 
5
5
  ## Usage
6
6
 
7
7
  ### Installation
8
8
 
9
9
  ```bash
10
- yarn add react-ga @arcblock/analytics-js @sentry/browser @arcblock/ux
10
+ yarn add @arcblock/ux
11
11
  ```
12
12
 
13
13
  ### Configuration & Usage
@@ -16,19 +16,22 @@ In your application entry file
16
16
 
17
17
  ```javascript
18
18
  import React from 'react';
19
- import ReactDOM from 'react-dom';
20
19
  import withTracker from '@arcblock/ux/lib/withTracker';
20
+ import { BrowserRouter as Router } from 'react-router-dom';
21
21
 
22
- function App() {
23
- return <p>My awesome application</p>;
24
- }
22
+ const App = () => <p>My awesome application</p>;
23
+ const TrackedApp = withTracker(App);
25
24
 
26
- const Wrapped = withTracker(App, {
27
- appName: 'my-awesome-app',
28
- appVersion: '0.1.0',
29
- gaAccount: '',
30
- sentryDSN: '',
31
- });
25
+ export default function WrappedApp() {
26
+ // While the blocklet is deploy to a sub path, this will be work properly.
27
+ const basename = window?.blocklet?.prefix || '/';
32
28
 
33
- ReactDOM.render(<Wrapped />, document.getElementById('root'));
29
+ return (
30
+ <Router basename={basename}>
31
+ <TrackedApp />
32
+ </Router>
33
+ );
34
+ }
34
35
  ```
36
+
37
+ Then you can use `window.trackPage(path, title)` and `window.trackEvent(category, action, label, value)` to track page views and events.
@@ -1,2 +1,2 @@
1
- declare function _default(WrappedComponent: any, options?: {}): (props: any) => import("react/jsx-runtime").JSX.Element;
1
+ declare function _default(WrappedComponent: any): (props: any) => import("react/jsx-runtime").JSX.Element;
2
2
  export default _default;
@@ -1,38 +1,37 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- /* eslint-disable import/no-unresolved */
3
- import ReactGA from 'react-ga';
4
- import * as Sentry from '@sentry/browser';
5
- import { useMount, useDeepCompareEffect } from 'ahooks';
6
2
  import { useLocation } from 'react-router-dom';
7
- import ErrorBoundary from './error_boundary';
8
- export default (WrappedComponent, options = {}) => {
9
- const {
10
- appVersion,
11
- gaAccount,
12
- sentryDSN
13
- } = options;
14
- if (gaAccount) {
15
- ReactGA.initialize(gaAccount);
16
- }
17
- if (sentryDSN) {
18
- Sentry.init({
19
- dsn: sentryDSN,
20
- release: appVersion || 'unknown',
21
- environment: process.env.NODE_ENV || 'development'
22
- });
23
- }
24
- const trackPage = page => {
3
+ import { useMount, useDeepCompareEffect } from 'ahooks';
4
+ import ReactGA from 'react-ga4';
5
+ export default WrappedComponent => {
6
+ const trackingId = window.blocklet?.GA_MEASUREMENT_ID || '';
7
+ const trackPage = (page, title = document.title) => {
25
8
  if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
26
9
  return;
27
10
  }
28
- if (gaAccount) {
29
- ReactGA.set({
11
+ if (trackingId) {
12
+ ReactGA.send({
13
+ hitType: 'pageview',
30
14
  page,
31
- ...options
15
+ title
32
16
  });
33
- ReactGA.pageview(page);
34
17
  }
35
18
  };
19
+ const trackEvent = (category, action, label, value) => {
20
+ if (trackingId) {
21
+ ReactGA.event({
22
+ category,
23
+ action,
24
+ label,
25
+ value,
26
+ transport: 'beacon'
27
+ });
28
+ }
29
+ };
30
+ if (trackingId) {
31
+ ReactGA.initialize(trackingId);
32
+ }
33
+ window.trackPage = trackPage;
34
+ window.trackEvent = trackEvent;
36
35
  return function TrackedComponent(props) {
37
36
  const location = useLocation();
38
37
  useMount(() => {
@@ -41,13 +40,6 @@ export default (WrappedComponent, options = {}) => {
41
40
  useDeepCompareEffect(() => {
42
41
  trackPage(location.pathname);
43
42
  }, [location.pathname]);
44
- if (process.env.NODE_ENV === 'production') {
45
- return /*#__PURE__*/_jsx(ErrorBoundary, {
46
- children: /*#__PURE__*/_jsx(WrappedComponent, {
47
- ...props
48
- })
49
- });
50
- }
51
43
  return /*#__PURE__*/_jsx(WrappedComponent, {
52
44
  ...props
53
45
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.10.45",
3
+ "version": "2.10.47",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -64,12 +64,12 @@
64
64
  "react": ">=18.2.0",
65
65
  "react-router-dom": ">=6.22.3"
66
66
  },
67
- "gitHead": "f4387cd434dcdf0bab88973b014575613dcb3611",
67
+ "gitHead": "21ff7984142d0a17cdb695c3bcec18c096d9bbf6",
68
68
  "dependencies": {
69
69
  "@arcblock/did-motif": "^1.1.13",
70
- "@arcblock/icons": "^2.10.45",
71
- "@arcblock/nft-display": "^2.10.45",
72
- "@arcblock/react-hooks": "^2.10.45",
70
+ "@arcblock/icons": "^2.10.47",
71
+ "@arcblock/nft-display": "^2.10.47",
72
+ "@arcblock/react-hooks": "^2.10.47",
73
73
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
74
74
  "@fontsource/inter": "^5.0.16",
75
75
  "@fontsource/ubuntu-mono": "^5.0.18",
@@ -101,6 +101,7 @@
101
101
  "qrcode.react": "^3.1.0",
102
102
  "react-cookie-consent": "^6.4.1",
103
103
  "react-error-boundary": "^3.1.4",
104
+ "react-ga4": "^2.1.0",
104
105
  "react-helmet": "^6.1.0",
105
106
  "react-intersection-observer": "^8.34.0",
106
107
  "react-lottie-player": "^1.4.3",
package/src/DID/index.tsx CHANGED
@@ -18,7 +18,7 @@ import { getDIDColor, isEthereumDid } from '../Util';
18
18
 
19
19
  const translations = {
20
20
  en: {
21
- scanQrcode: 'Scan with DID Wallet to view this {role}',
21
+ scanQrcode: 'Scan with DID Wallet to view the {role}',
22
22
  download: 'Download',
23
23
  downloadTips: "Don't have DID Wallet ?",
24
24
  },
@@ -45,6 +45,7 @@ interface IDIDPropTypes extends IDidAddressWrapper {
45
45
  endChars?: number;
46
46
  locale?: 'en' | 'zh';
47
47
  chainId?: string;
48
+ roleType?: number;
48
49
  }
49
50
 
50
51
  const DEFAULT_CHAIN_ID = 'xenon-2020-01-15';
@@ -72,8 +73,11 @@ const isSquareMotif = (roleType: number) => {
72
73
  };
73
74
 
74
75
  const getRoleName = (roleType: number) => {
75
- const [roleName] = Object.entries(types.RoleType).find((item) => item[1] === roleType) || [];
76
+ if (roleType === types.RoleType.ROLE_ANY) {
77
+ return 'DID';
78
+ }
76
79
 
80
+ const [roleName] = Object.entries(types.RoleType).find((item) => item[1] === roleType) || [];
77
81
  if (roleName) {
78
82
  // UpperCase first word, example:
79
83
  // ROLE_ACCOUNT -> Account
@@ -81,7 +85,7 @@ const getRoleName = (roleType: number) => {
81
85
  return roleName.toLowerCase().replace(/role_(\S)/g, (_, $1) => $1.toUpperCase());
82
86
  }
83
87
 
84
- return 'Address';
88
+ return 'DID';
85
89
  };
86
90
 
87
91
  const getAvatarSize = (didMotifInfo: any, isEthDid: boolean, size: number) => {
@@ -268,7 +272,7 @@ const DID = forwardRef<HTMLDIDElement, IDIDPropTypes>((props, ref) => {
268
272
  {/* @ts-ignore */}
269
273
  <DialogContent align="center" sx={{ p: 3 }}>
270
274
  <Typography sx={{ mb: 2, fontWeight: 500, fontSize: 18 }}>
271
- {t('scanQrcode', { role: getRoleName(didMotifInfo?.roleType) })}
275
+ {t('scanQrcode', { role: getRoleName(props.roleType || didMotifInfo?.roleType) })}
272
276
  </Typography>
273
277
  <QRCode
274
278
  // eslint-disable-next-line max-len
@@ -1,13 +1,13 @@
1
1
  # withTracker
2
2
 
3
- Add arcblock analytics, google analytics and sentry error reporting to your application.
3
+ Add google analytics reporting to your application.
4
4
 
5
5
  ## Usage
6
6
 
7
7
  ### Installation
8
8
 
9
9
  ```bash
10
- yarn add react-ga @arcblock/analytics-js @sentry/browser @arcblock/ux
10
+ yarn add @arcblock/ux
11
11
  ```
12
12
 
13
13
  ### Configuration & Usage
@@ -16,19 +16,22 @@ In your application entry file
16
16
 
17
17
  ```javascript
18
18
  import React from 'react';
19
- import ReactDOM from 'react-dom';
20
19
  import withTracker from '@arcblock/ux/lib/withTracker';
20
+ import { BrowserRouter as Router } from 'react-router-dom';
21
21
 
22
- function App() {
23
- return <p>My awesome application</p>;
24
- }
22
+ const App = () => <p>My awesome application</p>;
23
+ const TrackedApp = withTracker(App);
25
24
 
26
- const Wrapped = withTracker(App, {
27
- appName: 'my-awesome-app',
28
- appVersion: '0.1.0',
29
- gaAccount: '',
30
- sentryDSN: '',
31
- });
25
+ export default function WrappedApp() {
26
+ // While the blocklet is deploy to a sub path, this will be work properly.
27
+ const basename = window?.blocklet?.prefix || '/';
32
28
 
33
- ReactDOM.render(<Wrapped />, document.getElementById('root'));
29
+ return (
30
+ <Router basename={basename}>
31
+ <TrackedApp />
32
+ </Router>
33
+ );
34
+ }
34
35
  ```
36
+
37
+ Then you can use `window.trackPage(path, title)` and `window.trackEvent(category, action, label, value)` to track page views and events.
@@ -1,37 +1,32 @@
1
- /* eslint-disable import/no-unresolved */
2
- import ReactGA from 'react-ga';
3
- import * as Sentry from '@sentry/browser';
4
-
5
- import { useMount, useDeepCompareEffect } from 'ahooks';
6
1
  import { useLocation } from 'react-router-dom';
2
+ import { useMount, useDeepCompareEffect } from 'ahooks';
3
+ import ReactGA from 'react-ga4';
7
4
 
8
- import ErrorBoundary from './error_boundary';
9
-
10
- export default (WrappedComponent, options = {}) => {
11
- const { appVersion, gaAccount, sentryDSN } = options;
12
-
13
- if (gaAccount) {
14
- ReactGA.initialize(gaAccount);
15
- }
16
- if (sentryDSN) {
17
- Sentry.init({
18
- dsn: sentryDSN,
19
- release: appVersion || 'unknown',
20
- environment: process.env.NODE_ENV || 'development',
21
- });
22
- }
23
-
24
- const trackPage = (page) => {
5
+ export default (WrappedComponent) => {
6
+ const trackingId = window.blocklet?.GA_MEASUREMENT_ID || '';
7
+ const trackPage = (page, title = document.title) => {
25
8
  if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
26
9
  return;
27
10
  }
28
11
 
29
- if (gaAccount) {
30
- ReactGA.set({ page, ...options });
31
- ReactGA.pageview(page);
12
+ if (trackingId) {
13
+ ReactGA.send({ hitType: 'pageview', page, title });
32
14
  }
33
15
  };
34
16
 
17
+ const trackEvent = (category, action, label, value) => {
18
+ if (trackingId) {
19
+ ReactGA.event({ category, action, label, value, transport: 'beacon' });
20
+ }
21
+ };
22
+
23
+ if (trackingId) {
24
+ ReactGA.initialize(trackingId);
25
+ }
26
+
27
+ window.trackPage = trackPage;
28
+ window.trackEvent = trackEvent;
29
+
35
30
  return function TrackedComponent(props) {
36
31
  const location = useLocation();
37
32
 
@@ -43,14 +38,6 @@ export default (WrappedComponent, options = {}) => {
43
38
  trackPage(location.pathname);
44
39
  }, [location.pathname]);
45
40
 
46
- if (process.env.NODE_ENV === 'production') {
47
- return (
48
- <ErrorBoundary>
49
- <WrappedComponent {...props} />
50
- </ErrorBoundary>
51
- );
52
- }
53
-
54
41
  return <WrappedComponent {...props} />;
55
42
  };
56
43
  };