@arcblock/ux 1.16.19 → 1.16.20

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.
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.getNFTData = getNFTData;
6
7
  exports.default = void 0;
7
8
 
8
9
  var _react = _interopRequireWildcard(require("react"));
@@ -50,6 +51,17 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
50
51
 
51
52
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
52
53
 
54
+ /**
55
+ * 从 assetState 中获取 nft data, 兼容新旧两种类型的数据结构, 建议将该方法的返回值传入 NFTDisplay 组件的 data prop
56
+ * - 旧: assetState.data.value (.credentialSubject.display)
57
+ * - 新: assetState.display
58
+ */
59
+ function getNFTData(assetState) {
60
+ var _assetState$data;
61
+
62
+ return (assetState === null || assetState === void 0 ? void 0 : assetState.display) || (assetState === null || assetState === void 0 ? void 0 : (_assetState$data = assetState.data) === null || _assetState$data === void 0 ? void 0 : _assetState$data.value);
63
+ }
64
+
53
65
  function fromBase64(v) {
54
66
  if (typeof v !== 'string') {
55
67
  throw new Error('fromBase64 requires input to be a string');
@@ -111,8 +123,9 @@ function NFTDisplay(_ref) {
111
123
 
112
124
  const {
113
125
  vcId
114
- } = parsed.current;
115
- const display = (0, _get.default)(parsed.current, 'credentialSubject.display');
126
+ } = parsed.current; // 需要兼容新旧两种类型的数据结构, nft data 有 credentialSubject 属性, 说明是旧 nft data, 否则是新 nft data
127
+
128
+ const display = parsed.current.credentialSubject ? (0, _get.default)(parsed.current, 'credentialSubject.display') : parsed.current;
116
129
  const {
117
130
  content,
118
131
  type
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "1.16.19",
3
+ "version": "1.16.20",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -53,10 +53,10 @@
53
53
  "react": ">=16.12.0",
54
54
  "react-ga": "^2.7.0"
55
55
  },
56
- "gitHead": "88965cae9c1b0273e085c8779672cedef3abd633",
56
+ "gitHead": "d24d15a8cb22c578484e9017b85c0cb2debd1f43",
57
57
  "dependencies": {
58
- "@arcblock/icons": "^1.16.19",
59
- "@arcblock/react-hooks": "^1.16.19",
58
+ "@arcblock/icons": "^1.16.20",
59
+ "@arcblock/react-hooks": "^1.16.20",
60
60
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
61
61
  "@material-ui/core": "^4.12.3",
62
62
  "@material-ui/icons": "4.11.2",
@@ -12,6 +12,15 @@ import InlineSvgEmbedder from './svg-embedder/inline-svg';
12
12
  import DefaultLoading from './loading';
13
13
  import DefaultBrokenImage from './broken';
14
14
 
15
+ /**
16
+ * 从 assetState 中获取 nft data, 兼容新旧两种类型的数据结构, 建议将该方法的返回值传入 NFTDisplay 组件的 data prop
17
+ * - 旧: assetState.data.value (.credentialSubject.display)
18
+ * - 新: assetState.display
19
+ */
20
+ export function getNFTData(assetState) {
21
+ return assetState?.display || assetState?.data?.value;
22
+ }
23
+
15
24
  function fromBase64(v) {
16
25
  if (typeof v !== 'string') {
17
26
  throw new Error('fromBase64 requires input to be a string');
@@ -66,7 +75,10 @@ function NFTDisplay({
66
75
  // console.log('[debug] parse data')
67
76
  }
68
77
  const { vcId } = parsed.current;
69
- const display = get(parsed.current, 'credentialSubject.display');
78
+ // 需要兼容新旧两种类型的数据结构, nft data 有 credentialSubject 属性, 说明是旧 nft data, 否则是新 nft data
79
+ const display = parsed.current.credentialSubject
80
+ ? get(parsed.current, 'credentialSubject.display')
81
+ : parsed.current;
70
82
  const { content, type } = display;
71
83
  const isUrlType = type === 'url';
72
84