@arcblock/did-playground 2.1.18 → 2.1.19
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 +1 -1
- package/lib/Action/index.js +95 -76
- package/package.json +5 -5
- package/src/Action/actions.js +9 -9
- package/src/Action/index.js +6 -18
- package/src/Action/session.js +1 -2
package/lib/Action/actions.js
CHANGED
|
@@ -30,7 +30,7 @@ const getValidPayAmount = (payAmount, price) => {
|
|
|
30
30
|
|
|
31
31
|
const getMessage = function getMessage() {
|
|
32
32
|
let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
33
|
-
let session = arguments.length > 1 ? arguments[1] :
|
|
33
|
+
let session = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
34
34
|
|
|
35
35
|
try {
|
|
36
36
|
return _mustache.default.render(message, {
|
package/lib/Action/index.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = require("react");
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
@@ -33,13 +33,17 @@ var _session = require("./session");
|
|
|
33
33
|
|
|
34
34
|
var _actions = require("./actions");
|
|
35
35
|
|
|
36
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
37
|
+
|
|
36
38
|
const _excluded = ["autoClose", "action", "buttonText", "buttonColor", "buttonVariant", "buttonSize", "buttonRounded", "children", "disableClose", "title", "scanMessage", "successMessage", "successUrl", "successTarget", "frameProps", "confirmMessage", "extraParams", "timeout", "theme", "webWalletUrl"];
|
|
37
39
|
|
|
38
40
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
41
|
|
|
40
|
-
function
|
|
42
|
+
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
|
+
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; }
|
|
41
45
|
|
|
42
|
-
function
|
|
46
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
43
47
|
|
|
44
48
|
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; }
|
|
45
49
|
|
|
@@ -49,9 +53,10 @@ function Close(_ref) {
|
|
|
49
53
|
let {
|
|
50
54
|
onClose
|
|
51
55
|
} = _ref;
|
|
52
|
-
return /*#__PURE__*/
|
|
53
|
-
onClick: onClose
|
|
54
|
-
|
|
56
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(CloseContainer, {
|
|
57
|
+
onClick: onClose,
|
|
58
|
+
children: "\xD7"
|
|
59
|
+
});
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
Close.propTypes = {
|
|
@@ -111,21 +116,23 @@ function PlaygroundAction(props) {
|
|
|
111
116
|
|
|
112
117
|
if (action === 'login') {
|
|
113
118
|
if (session.user) {
|
|
114
|
-
return /*#__PURE__*/
|
|
119
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, _objectSpread(_objectSpread({}, rest), {}, {
|
|
115
120
|
rounded: buttonRounded,
|
|
116
121
|
color: buttonColor,
|
|
117
122
|
variant: buttonVariant,
|
|
118
|
-
size: buttonSize
|
|
119
|
-
|
|
123
|
+
size: buttonSize,
|
|
124
|
+
children: (0, _actions.getMessage)(successMessage || "Hello ".concat(session.user.name), session)
|
|
125
|
+
}));
|
|
120
126
|
}
|
|
121
127
|
|
|
122
|
-
return /*#__PURE__*/
|
|
128
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, _objectSpread(_objectSpread({}, rest), {}, {
|
|
123
129
|
rounded: buttonRounded,
|
|
124
130
|
color: buttonColor,
|
|
125
131
|
variant: buttonVariant,
|
|
126
132
|
size: buttonSize,
|
|
127
|
-
onClick: () => session.login()
|
|
128
|
-
|
|
133
|
+
onClick: () => session.login(),
|
|
134
|
+
children: (0, _actions.getMessage)(buttonText || title, session)
|
|
135
|
+
}));
|
|
129
136
|
}
|
|
130
137
|
|
|
131
138
|
const config = _actions.actions[action];
|
|
@@ -179,72 +186,84 @@ function PlaygroundAction(props) {
|
|
|
179
186
|
}
|
|
180
187
|
};
|
|
181
188
|
|
|
182
|
-
const renderRedirectUrlAfterSuccess = () => /*#__PURE__*/
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
189
|
+
const renderRedirectUrlAfterSuccess = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
190
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Close, {
|
|
191
|
+
onClose: onClose
|
|
192
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
193
|
+
children: ["Redirecting to", ' ', /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
|
|
194
|
+
href: successUrl,
|
|
195
|
+
target: successTarget,
|
|
196
|
+
children: successUrl
|
|
197
|
+
})]
|
|
198
|
+
})]
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const renderFrameAfterSuccess = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
202
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Close, {
|
|
203
|
+
onClose: onClose
|
|
204
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("iframe", _objectSpread({
|
|
205
|
+
style: {
|
|
206
|
+
width: '100%',
|
|
207
|
+
height: '100%'
|
|
208
|
+
},
|
|
209
|
+
allow: "fullscreen",
|
|
210
|
+
id: "successFrame",
|
|
211
|
+
title: "successFrame",
|
|
212
|
+
src: successUrl
|
|
213
|
+
}, frameProps))]
|
|
214
|
+
});
|
|
201
215
|
|
|
202
216
|
const showDidConnect = !successUrl || successUrl && !success;
|
|
203
|
-
return /*#__PURE__*/
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
217
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
218
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Button.default, _objectSpread(_objectSpread({}, rest), {}, {
|
|
219
|
+
rounded: buttonRounded,
|
|
220
|
+
color: buttonColor,
|
|
221
|
+
variant: buttonVariant,
|
|
222
|
+
size: buttonSize,
|
|
223
|
+
onClick: onStart,
|
|
224
|
+
children: [(0, _actions.getMessage)(buttonText || title, session), " ", loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {
|
|
225
|
+
size: 12,
|
|
226
|
+
sx: {
|
|
227
|
+
color: '#fff'
|
|
228
|
+
}
|
|
229
|
+
})]
|
|
230
|
+
})), open && !showDidConnect && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dialog.default, {
|
|
231
|
+
open: true,
|
|
232
|
+
disableEscapeKeyDown: true,
|
|
233
|
+
fullScreen: width < theme.breakpoints.values.sm && !browser.wallet,
|
|
234
|
+
fullWidth: showFrame,
|
|
235
|
+
maxWidth: showFrame ? 'lg' : '',
|
|
236
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_DialogContent.default, {
|
|
237
|
+
style: {
|
|
238
|
+
padding: success && !showFrame && successUrl ? 55 : 0,
|
|
239
|
+
display: 'flex',
|
|
240
|
+
justifyContent: 'center',
|
|
241
|
+
alignItems: 'center',
|
|
242
|
+
height: showFrame ? theme.breakpoints.values.md : ''
|
|
243
|
+
},
|
|
244
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Close, {
|
|
245
|
+
onClose: onClose
|
|
246
|
+
}), successUrl && success && !showFrame && renderRedirectUrlAfterSuccess(), showFrame && renderFrameAfterSuccess()]
|
|
247
|
+
})
|
|
248
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Connect.default, {
|
|
249
|
+
popup: true,
|
|
250
|
+
open: open && showDidConnect,
|
|
251
|
+
action: (0, _actions.getActionName)(config, rest),
|
|
252
|
+
checkFn: api.get,
|
|
253
|
+
onClose: onClose,
|
|
254
|
+
onSuccess: onSuccess,
|
|
255
|
+
checkTimeout: timeout // 3 layers of extraParams: user props, dynamically generated, from other props
|
|
256
|
+
,
|
|
257
|
+
extraParams: Object.assign((0, _actions.getActionParams)(config, rest, session), dynamicParams, extraParams),
|
|
258
|
+
webWalletUrl: webWalletUrl,
|
|
259
|
+
messages: {
|
|
260
|
+
title: (0, _actions.getMessage)(title, session),
|
|
261
|
+
scan: (0, _actions.getMessage)(scanMessage, session),
|
|
262
|
+
confirm: (0, _actions.getMessage)(confirmMessage, session),
|
|
263
|
+
success: children || (0, _actions.getMessage)(successMessage, session)
|
|
264
|
+
}
|
|
265
|
+
})]
|
|
266
|
+
});
|
|
248
267
|
}
|
|
249
268
|
|
|
250
269
|
PlaygroundAction.propTypes = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/did-playground",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.19",
|
|
4
4
|
"description": "React components that works with wallet-playground",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"url": "https://github.com/ArcBlock/wallet-playground/issues"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@arcblock/did-connect": "^2.1.
|
|
38
|
-
"@arcblock/react-hooks": "^2.1.
|
|
39
|
-
"@arcblock/ux": "^2.1.
|
|
37
|
+
"@arcblock/did-connect": "^2.1.19",
|
|
38
|
+
"@arcblock/react-hooks": "^2.1.19",
|
|
39
|
+
"@arcblock/ux": "^2.1.19",
|
|
40
40
|
"@mui/material": "^5.6.4",
|
|
41
41
|
"axios": "^0.21.2",
|
|
42
42
|
"core-js": "^3.6.4",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "7dd94cbff3bef095f0701de5779ecd9cc8d82b8f"
|
|
61
61
|
}
|
package/src/Action/actions.js
CHANGED
|
@@ -15,7 +15,7 @@ const getValidPayAmount = (payAmount, price) => {
|
|
|
15
15
|
return 1;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export const getMessage = (message = '', session) => {
|
|
18
|
+
export const getMessage = (message = '', session = {}) => {
|
|
19
19
|
try {
|
|
20
20
|
return mustache.render(
|
|
21
21
|
message,
|
|
@@ -38,40 +38,40 @@ export const actions = {
|
|
|
38
38
|
// Currency
|
|
39
39
|
receive_local_token: {
|
|
40
40
|
action: 'receive_token',
|
|
41
|
-
extraParams: props => ({ chain: 'local', amount: props.amount || 1 }),
|
|
41
|
+
extraParams: (props) => ({ chain: 'local', amount: props.amount || 1 }),
|
|
42
42
|
},
|
|
43
43
|
receive_foreign_token: {
|
|
44
44
|
action: 'receive_token',
|
|
45
|
-
extraParams: props => ({ chain: 'foreign', amount: props.amount || 1 }),
|
|
45
|
+
extraParams: (props) => ({ chain: 'foreign', amount: props.amount || 1 }),
|
|
46
46
|
},
|
|
47
47
|
send_local_token: {
|
|
48
48
|
action: 'send_token',
|
|
49
|
-
extraParams: props => ({ chain: 'local', amount: props.amount || 1 }),
|
|
49
|
+
extraParams: (props) => ({ chain: 'local', amount: props.amount || 1 }),
|
|
50
50
|
},
|
|
51
51
|
send_foreign_token: {
|
|
52
52
|
action: 'send_token',
|
|
53
|
-
extraParams: props => ({ chain: 'foreign', amount: props.amount || 1 }),
|
|
53
|
+
extraParams: (props) => ({ chain: 'foreign', amount: props.amount || 1 }),
|
|
54
54
|
},
|
|
55
55
|
exchange_to_foreign_token: {
|
|
56
56
|
action: 'swap_token',
|
|
57
57
|
onStart: createSwapOrder,
|
|
58
|
-
extraParams: props => ({ action: 'buy', rate: props.exchangeRate, amount: props.amount || 1 }),
|
|
58
|
+
extraParams: (props) => ({ action: 'buy', rate: props.exchangeRate, amount: props.amount || 1 }),
|
|
59
59
|
},
|
|
60
60
|
exchange_to_local_token: {
|
|
61
61
|
action: 'swap_token',
|
|
62
62
|
onStart: createSwapOrder,
|
|
63
|
-
extraParams: props => ({ action: 'sell', rate: props.exchangeRate, amount: props.amount || 1 }),
|
|
63
|
+
extraParams: (props) => ({ action: 'sell', rate: props.exchangeRate, amount: props.amount || 1 }),
|
|
64
64
|
},
|
|
65
65
|
|
|
66
66
|
exchange_to_foreign_token_v2: {
|
|
67
67
|
action: 'swap_token_v2',
|
|
68
68
|
onStart: createSwapOrder,
|
|
69
|
-
extraParams: props => ({ action: 'buy', rate: props.exchangeRate, amount: props.amount || 1 }),
|
|
69
|
+
extraParams: (props) => ({ action: 'buy', rate: props.exchangeRate, amount: props.amount || 1 }),
|
|
70
70
|
},
|
|
71
71
|
exchange_to_local_token_v2: {
|
|
72
72
|
action: 'swap_token_v2',
|
|
73
73
|
onStart: createSwapOrder,
|
|
74
|
-
extraParams: props => ({ action: 'sell', rate: props.exchangeRate, amount: props.amount || 1 }),
|
|
74
|
+
extraParams: (props) => ({ action: 'sell', rate: props.exchangeRate, amount: props.amount || 1 }),
|
|
75
75
|
},
|
|
76
76
|
|
|
77
77
|
// Cross chain assets and tokens
|
package/src/Action/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useContext, useState, useEffect } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import useWindowSize from 'react-use/lib/useWindowSize';
|
|
4
4
|
import useBrowser from '@arcblock/react-hooks/lib/useBrowser';
|
|
@@ -22,7 +22,7 @@ function Close({ onClose }) {
|
|
|
22
22
|
|
|
23
23
|
Close.propTypes = { onClose: PropTypes.func.isRequired };
|
|
24
24
|
const CloseContainer = styled.div`
|
|
25
|
-
display: ${props => (props.disableClose ? 'none' : 'block')};
|
|
25
|
+
display: ${(props) => (props.disableClose ? 'none' : 'block')};
|
|
26
26
|
position: absolute;
|
|
27
27
|
top: 1rem;
|
|
28
28
|
right: 1rem;
|
|
@@ -81,12 +81,7 @@ function PlaygroundAction(props) {
|
|
|
81
81
|
if (action === 'login') {
|
|
82
82
|
if (session.user) {
|
|
83
83
|
return (
|
|
84
|
-
<Button
|
|
85
|
-
{...rest}
|
|
86
|
-
rounded={buttonRounded}
|
|
87
|
-
color={buttonColor}
|
|
88
|
-
variant={buttonVariant}
|
|
89
|
-
size={buttonSize}>
|
|
84
|
+
<Button {...rest} rounded={buttonRounded} color={buttonColor} variant={buttonVariant} size={buttonSize}>
|
|
90
85
|
{getMessage(successMessage || `Hello ${session.user.name}`, session)}
|
|
91
86
|
</Button>
|
|
92
87
|
);
|
|
@@ -118,9 +113,7 @@ function PlaygroundAction(props) {
|
|
|
118
113
|
setDynamicParams(params);
|
|
119
114
|
setLoading(false);
|
|
120
115
|
} catch (err) {
|
|
121
|
-
console.error(
|
|
122
|
-
`Cannot generate dynamicParams for playground action ${getActionName(config, rest)}`
|
|
123
|
-
);
|
|
116
|
+
console.error(`Cannot generate dynamicParams for playground action ${getActionName(config, rest)}`);
|
|
124
117
|
}
|
|
125
118
|
setOpen(true);
|
|
126
119
|
} else {
|
|
@@ -193,8 +186,7 @@ function PlaygroundAction(props) {
|
|
|
193
186
|
variant={buttonVariant}
|
|
194
187
|
size={buttonSize}
|
|
195
188
|
onClick={onStart}>
|
|
196
|
-
{getMessage(buttonText || title, session)}{'
|
|
197
|
-
{loading && <CircularProgress size={12} sx={{ color: '#fff' }} />}
|
|
189
|
+
{getMessage(buttonText || title, session)} {loading && <CircularProgress size={12} sx={{ color: '#fff' }} />}
|
|
198
190
|
</Button>
|
|
199
191
|
{open && !showDidConnect && (
|
|
200
192
|
<Dialog
|
|
@@ -226,11 +218,7 @@ function PlaygroundAction(props) {
|
|
|
226
218
|
onSuccess={onSuccess}
|
|
227
219
|
checkTimeout={timeout}
|
|
228
220
|
// 3 layers of extraParams: user props, dynamically generated, from other props
|
|
229
|
-
extraParams={Object.assign(
|
|
230
|
-
getActionParams(config, rest, session),
|
|
231
|
-
dynamicParams,
|
|
232
|
-
extraParams
|
|
233
|
-
)}
|
|
221
|
+
extraParams={Object.assign(getActionParams(config, rest, session), dynamicParams, extraParams)}
|
|
234
222
|
webWalletUrl={webWalletUrl}
|
|
235
223
|
messages={{
|
|
236
224
|
title: getMessage(title, session),
|
package/src/Action/session.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createAuthServiceSessionContext } from '@arcblock/did-connect/lib/Session';
|
|
2
2
|
|
|
3
|
-
const { SessionProvider, SessionContext, SessionConsumer, withSession } =
|
|
4
|
-
createAuthServiceSessionContext();
|
|
3
|
+
const { SessionProvider, SessionContext, SessionConsumer, withSession } = createAuthServiceSessionContext();
|
|
5
4
|
export { SessionProvider, SessionContext, SessionConsumer, withSession };
|