@arcblock/did-playground 2.5.58 → 2.5.59
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/Action/actions.js +2 -21
- package/lib/Action/index.js +32 -68
- package/lib/Action/session.js +0 -2
- package/lib/index.js +0 -3
- package/package.json +5 -5
package/lib/Action/actions.js
CHANGED
|
@@ -4,34 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getMessage = exports.getActionParams = exports.getActionName = exports.actions = void 0;
|
|
7
|
-
|
|
8
7
|
var _mustache = _interopRequireDefault(require("mustache"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
async function createSwapOrder(api) {
|
|
13
10
|
const res = await api.post('/api/did/swap', {});
|
|
14
11
|
return {
|
|
15
12
|
tid: res.data.traceId
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
const getValidPayAmount = (payAmount, price) => {
|
|
20
16
|
if (Number(payAmount) >= 0) {
|
|
21
17
|
return payAmount;
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
if (Number(price) >= 0) {
|
|
25
20
|
return price;
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
return 1;
|
|
29
23
|
};
|
|
30
|
-
|
|
31
24
|
const getMessage = function getMessage() {
|
|
32
25
|
let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
33
26
|
let session = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
34
|
-
|
|
35
27
|
try {
|
|
36
28
|
return _mustache.default.render(message, {
|
|
37
29
|
user: session.user || {},
|
|
@@ -45,9 +37,9 @@ const getMessage = function getMessage() {
|
|
|
45
37
|
});
|
|
46
38
|
return message;
|
|
47
39
|
}
|
|
48
|
-
};
|
|
49
|
-
|
|
40
|
+
};
|
|
50
41
|
|
|
42
|
+
// https://github.com/ArcBlock/gatsby-extensions/issues/56
|
|
51
43
|
exports.getMessage = getMessage;
|
|
52
44
|
const actions = {
|
|
53
45
|
// Currency
|
|
@@ -615,43 +607,32 @@ const actions = {
|
|
|
615
607
|
}
|
|
616
608
|
};
|
|
617
609
|
exports.actions = actions;
|
|
618
|
-
|
|
619
610
|
const getActionName = (config, props) => {
|
|
620
611
|
if (typeof config === 'string') {
|
|
621
612
|
return config;
|
|
622
613
|
}
|
|
623
|
-
|
|
624
614
|
if (typeof config.action === 'string') {
|
|
625
615
|
return config.action;
|
|
626
616
|
}
|
|
627
|
-
|
|
628
617
|
if (typeof config.action === 'function') {
|
|
629
618
|
return config.action(props);
|
|
630
619
|
}
|
|
631
|
-
|
|
632
620
|
throw new Error('Cannot determine playground button action');
|
|
633
621
|
};
|
|
634
|
-
|
|
635
622
|
exports.getActionName = getActionName;
|
|
636
|
-
|
|
637
623
|
const getActionParams = (config, props, session) => {
|
|
638
624
|
if (typeof config === 'string') {
|
|
639
625
|
return {};
|
|
640
626
|
}
|
|
641
|
-
|
|
642
627
|
if (!config.extraParams) {
|
|
643
628
|
return {};
|
|
644
629
|
}
|
|
645
|
-
|
|
646
630
|
if (typeof config.extraParams === 'function') {
|
|
647
631
|
return config.extraParams(props, session);
|
|
648
632
|
}
|
|
649
|
-
|
|
650
633
|
if (typeof config.extraParams === 'object') {
|
|
651
634
|
return config.extraParams;
|
|
652
635
|
}
|
|
653
|
-
|
|
654
636
|
return {};
|
|
655
637
|
};
|
|
656
|
-
|
|
657
638
|
exports.getActionParams = getActionParams;
|
package/lib/Action/index.js
CHANGED
|
@@ -4,53 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _useWindowSize = _interopRequireDefault(require("react-use/lib/useWindowSize"));
|
|
13
|
-
|
|
14
10
|
var _useBrowser = _interopRequireDefault(require("@arcblock/react-hooks/lib/useBrowser"));
|
|
15
|
-
|
|
16
11
|
var _Theme = require("@arcblock/ux/lib/Theme");
|
|
17
|
-
|
|
18
12
|
var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularProgress"));
|
|
19
|
-
|
|
20
13
|
var _Dialog = _interopRequireDefault(require("@mui/material/Dialog"));
|
|
21
|
-
|
|
22
14
|
var _DialogContent = _interopRequireDefault(require("@mui/material/DialogContent"));
|
|
23
|
-
|
|
24
15
|
var _Connect = _interopRequireDefault(require("@arcblock/did-connect/lib/Connect"));
|
|
25
|
-
|
|
26
16
|
var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
|
|
27
|
-
|
|
28
17
|
var _Util = require("@arcblock/ux/lib/Util");
|
|
29
|
-
|
|
30
18
|
var _session = require("./session");
|
|
31
|
-
|
|
32
19
|
var _actions = require("./actions");
|
|
33
|
-
|
|
34
20
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
35
|
-
|
|
36
21
|
const _excluded = ["autoClose", "action", "buttonText", "buttonColor", "buttonVariant", "buttonSize", "buttonRounded", "children", "disableClose", "title", "scanMessage", "successMessage", "successUrl", "successTarget", "frameProps", "confirmMessage", "extraParams", "timeout", "webWalletUrl"];
|
|
37
|
-
|
|
38
22
|
var _templateObject;
|
|
39
|
-
|
|
40
23
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
41
|
-
|
|
42
24
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
43
|
-
|
|
44
25
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
45
|
-
|
|
46
|
-
function
|
|
47
|
-
|
|
26
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
28
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
48
29
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
49
|
-
|
|
50
30
|
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; }
|
|
51
|
-
|
|
52
31
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
53
|
-
|
|
54
32
|
function Close(_ref) {
|
|
55
33
|
let {
|
|
56
34
|
onClose
|
|
@@ -60,38 +38,34 @@ function Close(_ref) {
|
|
|
60
38
|
children: "\xD7"
|
|
61
39
|
});
|
|
62
40
|
}
|
|
63
|
-
|
|
64
41
|
Close.propTypes = {
|
|
65
42
|
onClose: _propTypes.default.func.isRequired
|
|
66
43
|
};
|
|
67
44
|
const CloseContainer = (0, _Theme.styled)('div')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: ", ";\n position: absolute;\n top: 1rem;\n right: 1rem;\n color: #999999;\n font-size: 2rem;\n line-height: 1rem;\n cursor: pointer;\n user-select: none;\n"])), props => props.disableClose ? 'none' : 'block');
|
|
68
|
-
|
|
69
45
|
function PlaygroundAction(props) {
|
|
70
46
|
const newProps = (0, _Util.mergeProps)(props, PlaygroundAction, ['buttonRounded', 'extraParams', 'timeout']);
|
|
71
|
-
|
|
72
47
|
const {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
48
|
+
autoClose,
|
|
49
|
+
action,
|
|
50
|
+
buttonText,
|
|
51
|
+
buttonColor,
|
|
52
|
+
buttonVariant,
|
|
53
|
+
buttonSize,
|
|
54
|
+
buttonRounded,
|
|
55
|
+
children,
|
|
56
|
+
disableClose,
|
|
57
|
+
title,
|
|
58
|
+
scanMessage,
|
|
59
|
+
successMessage,
|
|
60
|
+
successUrl,
|
|
61
|
+
successTarget,
|
|
62
|
+
frameProps,
|
|
63
|
+
confirmMessage,
|
|
64
|
+
extraParams,
|
|
65
|
+
timeout,
|
|
66
|
+
webWalletUrl
|
|
67
|
+
} = newProps,
|
|
68
|
+
rest = _objectWithoutProperties(newProps, _excluded);
|
|
95
69
|
const theme = (0, _Theme.useTheme)();
|
|
96
70
|
const browser = (0, _useBrowser.default)();
|
|
97
71
|
const {
|
|
@@ -105,13 +79,15 @@ function PlaygroundAction(props) {
|
|
|
105
79
|
width
|
|
106
80
|
} = (0, _useWindowSize.default)();
|
|
107
81
|
const [success, setSuccess] = (0, _react.useState)(false);
|
|
108
|
-
const [showFrame, setShowFrame] = (0, _react.useState)(success && successUrl && successTarget === 'frame');
|
|
82
|
+
const [showFrame, setShowFrame] = (0, _react.useState)(success && successUrl && successTarget === 'frame');
|
|
109
83
|
|
|
84
|
+
// 当打开或关闭组件时,重置部分状态
|
|
110
85
|
(0, _react.useEffect)(() => () => {
|
|
111
86
|
setSuccess(false);
|
|
112
87
|
setShowFrame(false);
|
|
113
|
-
}, [open]);
|
|
88
|
+
}, [open]);
|
|
114
89
|
|
|
90
|
+
// If this is just a login button, we do not do anything actually
|
|
115
91
|
if (action === 'login') {
|
|
116
92
|
if (session.user) {
|
|
117
93
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, _objectSpread(_objectSpread({}, rest), {}, {
|
|
@@ -122,7 +98,6 @@ function PlaygroundAction(props) {
|
|
|
122
98
|
children: (0, _actions.getMessage)(successMessage || "Hello ".concat(session.user.name), session)
|
|
123
99
|
}));
|
|
124
100
|
}
|
|
125
|
-
|
|
126
101
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, _objectSpread(_objectSpread({}, rest), {}, {
|
|
127
102
|
rounded: buttonRounded,
|
|
128
103
|
color: buttonColor,
|
|
@@ -132,13 +107,10 @@ function PlaygroundAction(props) {
|
|
|
132
107
|
children: (0, _actions.getMessage)(buttonText || title, session)
|
|
133
108
|
}));
|
|
134
109
|
}
|
|
135
|
-
|
|
136
110
|
const config = _actions.actions[action];
|
|
137
|
-
|
|
138
111
|
if (!_actions.actions[action]) {
|
|
139
112
|
throw new Error("Unsupported playground action ".concat(action));
|
|
140
113
|
}
|
|
141
|
-
|
|
142
114
|
const doStart = async () => {
|
|
143
115
|
if (typeof config.onStart === 'function') {
|
|
144
116
|
try {
|
|
@@ -149,27 +121,21 @@ function PlaygroundAction(props) {
|
|
|
149
121
|
} catch (err) {
|
|
150
122
|
console.error("Cannot generate dynamicParams for playground action ".concat((0, _actions.getActionName)(config, rest)));
|
|
151
123
|
}
|
|
152
|
-
|
|
153
124
|
setOpen(true);
|
|
154
125
|
} else {
|
|
155
126
|
setOpen(true);
|
|
156
127
|
}
|
|
157
128
|
};
|
|
158
|
-
|
|
159
129
|
const onStart = async () => {
|
|
160
130
|
if (!session.user) {
|
|
161
131
|
session.login(doStart);
|
|
162
132
|
return;
|
|
163
133
|
}
|
|
164
|
-
|
|
165
134
|
await doStart();
|
|
166
135
|
};
|
|
167
|
-
|
|
168
136
|
const onClose = () => setOpen(false);
|
|
169
|
-
|
|
170
137
|
const onSuccess = () => {
|
|
171
138
|
setSuccess(true);
|
|
172
|
-
|
|
173
139
|
if (successUrl) {
|
|
174
140
|
if (successTarget === 'frame') {
|
|
175
141
|
setShowFrame(!!successUrl);
|
|
@@ -178,12 +144,12 @@ function PlaygroundAction(props) {
|
|
|
178
144
|
} else {
|
|
179
145
|
window.open(successUrl, '_self');
|
|
180
146
|
}
|
|
181
|
-
} else if (children) {
|
|
147
|
+
} else if (children) {
|
|
148
|
+
// Do nothing
|
|
182
149
|
} else if (autoClose) {
|
|
183
150
|
setTimeout(onClose, 2000);
|
|
184
151
|
}
|
|
185
152
|
};
|
|
186
|
-
|
|
187
153
|
const renderRedirectUrlAfterSuccess = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
188
154
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Close, {
|
|
189
155
|
onClose: onClose
|
|
@@ -195,7 +161,6 @@ function PlaygroundAction(props) {
|
|
|
195
161
|
})]
|
|
196
162
|
})]
|
|
197
163
|
});
|
|
198
|
-
|
|
199
164
|
const renderFrameAfterSuccess = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
200
165
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Close, {
|
|
201
166
|
onClose: onClose
|
|
@@ -210,7 +175,6 @@ function PlaygroundAction(props) {
|
|
|
210
175
|
src: successUrl
|
|
211
176
|
}, frameProps))]
|
|
212
177
|
});
|
|
213
|
-
|
|
214
178
|
const showDidConnect = !successUrl || successUrl && !success;
|
|
215
179
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
216
180
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Button.default, _objectSpread(_objectSpread({}, rest), {}, {
|
|
@@ -250,7 +214,8 @@ function PlaygroundAction(props) {
|
|
|
250
214
|
checkFn: api.get,
|
|
251
215
|
onClose: onClose,
|
|
252
216
|
onSuccess: onSuccess,
|
|
253
|
-
checkTimeout: timeout
|
|
217
|
+
checkTimeout: timeout
|
|
218
|
+
// 3 layers of extraParams: user props, dynamically generated, from other props
|
|
254
219
|
,
|
|
255
220
|
extraParams: Object.assign((0, _actions.getActionParams)(config, rest, session), dynamicParams, extraParams),
|
|
256
221
|
webWalletUrl: webWalletUrl,
|
|
@@ -263,7 +228,6 @@ function PlaygroundAction(props) {
|
|
|
263
228
|
})]
|
|
264
229
|
});
|
|
265
230
|
}
|
|
266
|
-
|
|
267
231
|
PlaygroundAction.propTypes = {
|
|
268
232
|
action: _propTypes.default.string.isRequired,
|
|
269
233
|
autoClose: _propTypes.default.bool,
|
package/lib/Action/session.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.withSession = exports.SessionProvider = exports.SessionContext = exports.SessionConsumer = void 0;
|
|
7
|
-
|
|
8
7
|
var _Session = require("@arcblock/did-connect/lib/Session");
|
|
9
|
-
|
|
10
8
|
const {
|
|
11
9
|
SessionProvider,
|
|
12
10
|
SessionContext,
|
package/lib/index.js
CHANGED
|
@@ -27,9 +27,6 @@ Object.defineProperty(exports, "SessionProvider", {
|
|
|
27
27
|
return _session.SessionProvider;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
|
|
31
30
|
var _Action = _interopRequireDefault(require("./Action"));
|
|
32
|
-
|
|
33
31
|
var _session = require("./Action/session");
|
|
34
|
-
|
|
35
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/did-playground",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.59",
|
|
4
4
|
"description": "React components that works with wallet-playground",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"url": "https://github.com/ArcBlock/wallet-playground/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@arcblock/did-connect": "^2.5.
|
|
34
|
-
"@arcblock/react-hooks": "^2.5.
|
|
35
|
-
"@arcblock/ux": "^2.5.
|
|
33
|
+
"@arcblock/did-connect": "^2.5.59",
|
|
34
|
+
"@arcblock/react-hooks": "^2.5.59",
|
|
35
|
+
"@arcblock/ux": "^2.5.59",
|
|
36
36
|
"@emotion/react": "^11.10.4",
|
|
37
37
|
"@emotion/styled": "^11.10.4",
|
|
38
38
|
"@mui/material": "^5.10.8",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "f50c420e5f06ae108d59636cfdcfde88d1e10f4c"
|
|
57
57
|
}
|