@arcblock/ux 2.1.44 → 2.1.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.
@@ -82,14 +82,21 @@ const create = () => {
82
82
  rest = _objectWithoutProperties(_ref, _excluded);
83
83
 
84
84
  const [currentLocale, setCurrentLocale] = (0, _react.useState)(getLocale(locale));
85
- (0, _react.useEffect)(() => {
86
- setLocale(currentLocale);
87
- }, [currentLocale]);
88
85
 
89
86
  const changeLocale = newLocale => {
90
87
  setCurrentLocale(newLocale);
88
+ setLocale(newLocale);
91
89
  };
92
90
 
91
+ (0, _react.useEffect)(() => {
92
+ const tmpLocale = getLocale(locale);
93
+
94
+ if (tmpLocale !== currentLocale) {
95
+ changeLocale(locale);
96
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
97
+
98
+ }, [locale]);
99
+
93
100
  const translate = (key, data) => {
94
101
  if (!translations[currentLocale] || !translations[currentLocale][key]) {
95
102
  console.warn("Warning: no ".concat(key, " translation of ").concat(currentLocale));
@@ -114,9 +114,10 @@ function NFTDisplay(_ref) {
114
114
  children: children
115
115
  }));
116
116
 
117
- try {
118
- const parsed = (0, _react.useRef)(data); // 如果是 raw data 先解析
117
+ const parsed = (0, _react.useRef)(data);
119
118
 
119
+ try {
120
+ // 如果是 raw data 先解析
120
121
  if (typeof parsed.current === 'string') {
121
122
  parsed.current = JSON.parse(data); // console.log('[debug] parse data')
122
123
  }
@@ -208,7 +209,7 @@ function NFTDisplay(_ref) {
208
209
  const svg = _buffer.Buffer.from(buffer).toString('utf8');
209
210
 
210
211
  if (checkSvg && !(0, _isSvg.default)(svg)) {
211
- throw new Error("Invalid SVG: ".concat(svg));
212
+ throw new Error('Invalid SVG of type svg_gzipped');
212
213
  }
213
214
 
214
215
  const Embedder = getSvgEmbedder(preferredSvgEmbedder);
@@ -220,7 +221,7 @@ function NFTDisplay(_ref) {
220
221
  case 'svg':
221
222
  {
222
223
  if (checkSvg && !(0, _isSvg.default)(content)) {
223
- throw new Error("Invalid SVG: ".concat(content));
224
+ throw new Error('Invalid SVG of type svg');
224
225
  }
225
226
 
226
227
  const Embedder = getSvgEmbedder(preferredSvgEmbedder);
@@ -246,7 +247,12 @@ function NFTDisplay(_ref) {
246
247
  children: [(state.loading || !minimumLoadingReady) && (renderLoading ? renderLoading() : /*#__PURE__*/(0, _jsxRuntime.jsx)(_loading.default, {})), renderNFT()]
247
248
  }));
248
249
  } catch (e) {
249
- console.error(e);
250
+ var _parsed$current;
251
+
252
+ console.error(e === null || e === void 0 ? void 0 : e.message, {
253
+ nftId: address,
254
+ vcId: parsed === null || parsed === void 0 ? void 0 : (_parsed$current = parsed.current) === null || _parsed$current === void 0 ? void 0 : _parsed$current.vcId
255
+ });
250
256
  return wrapRoot(renderError ? renderError() : /*#__PURE__*/(0, _jsxRuntime.jsx)(_broken.default, {}));
251
257
  }
252
258
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.1.44",
3
+ "version": "2.1.47",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -52,10 +52,10 @@
52
52
  "react": ">=18.1.0",
53
53
  "react-ga": "^2.7.0"
54
54
  },
55
- "gitHead": "20e72c7ddc7f6f67d2b14782044bfc8e9609ca36",
55
+ "gitHead": "ec39f2bad16b784ed65cbf3f74bf7f32d137f4c3",
56
56
  "dependencies": {
57
- "@arcblock/icons": "^2.1.44",
58
- "@arcblock/react-hooks": "^2.1.44",
57
+ "@arcblock/icons": "^2.1.47",
58
+ "@arcblock/react-hooks": "^2.1.47",
59
59
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
60
60
  "@emotion/react": "^11.9.0",
61
61
  "@emotion/styled": "^11.8.1",
@@ -38,14 +38,19 @@ const create = () => {
38
38
  function LocaleProvider({ children, locale, translations, ...rest }) {
39
39
  const [currentLocale, setCurrentLocale] = useState(getLocale(locale));
40
40
 
41
- useEffect(() => {
42
- setLocale(currentLocale);
43
- }, [currentLocale]);
44
-
45
41
  const changeLocale = (newLocale) => {
46
42
  setCurrentLocale(newLocale);
43
+ setLocale(newLocale);
47
44
  };
48
45
 
46
+ useEffect(() => {
47
+ const tmpLocale = getLocale(locale);
48
+ if (tmpLocale !== currentLocale) {
49
+ changeLocale(locale);
50
+ }
51
+ // eslint-disable-next-line react-hooks/exhaustive-deps
52
+ }, [locale]);
53
+
49
54
  const translate = (key, data) => {
50
55
  if (!translations[currentLocale] || !translations[currentLocale][key]) {
51
56
  console.warn(`Warning: no ${key} translation of ${currentLocale}`);
@@ -69,13 +69,15 @@ function NFTDisplay({
69
69
  </Root>
70
70
  );
71
71
 
72
+ const parsed = useRef(data);
73
+
72
74
  try {
73
- const parsed = useRef(data);
74
75
  // 如果是 raw data 先解析
75
76
  if (typeof parsed.current === 'string') {
76
77
  parsed.current = JSON.parse(data);
77
78
  // console.log('[debug] parse data')
78
79
  }
80
+
79
81
  const { vcId } = parsed.current;
80
82
  // 需要兼容新旧两种类型的数据结构, nft data 有 credentialSubject 属性, 说明是旧 nft data, 否则是新 nft data
81
83
  const display = parsed.current.credentialSubject
@@ -147,14 +149,14 @@ function NFTDisplay({
147
149
  const buffer = pako.ungzip(fromBase64(content), {});
148
150
  const svg = Buffer.from(buffer).toString('utf8');
149
151
  if (checkSvg && !isSvg(svg)) {
150
- throw new Error(`Invalid SVG: ${svg}`);
152
+ throw new Error('Invalid SVG of type svg_gzipped');
151
153
  }
152
154
  const Embedder = getSvgEmbedder(preferredSvgEmbedder);
153
155
  return <Embedder svg={svg} />;
154
156
  }
155
157
  case 'svg': {
156
158
  if (checkSvg && !isSvg(content)) {
157
- throw new Error(`Invalid SVG: ${content}`);
159
+ throw new Error('Invalid SVG of type svg');
158
160
  }
159
161
  const Embedder = getSvgEmbedder(preferredSvgEmbedder);
160
162
  return <Embedder svg={content} />;
@@ -176,7 +178,10 @@ function NFTDisplay({
176
178
  </>
177
179
  );
178
180
  } catch (e) {
179
- console.error(e);
181
+ console.error(e?.message, {
182
+ nftId: address,
183
+ vcId: parsed?.current?.vcId,
184
+ });
180
185
  return wrapRoot(renderError ? renderError() : <DefaultBrokenImage />);
181
186
  }
182
187
  }