@blocklet/payment-react 1.13.236 → 1.13.237
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/es/checkout/donate.d.ts +1 -1
- package/es/checkout/donate.js +1 -2
- package/es/contexts/payment.d.ts +1 -1
- package/es/contexts/payment.js +2 -2
- package/es/payment/form/index.js +28 -5
- package/lib/checkout/donate.d.ts +1 -1
- package/lib/checkout/donate.js +1 -1
- package/lib/contexts/payment.d.ts +1 -1
- package/lib/contexts/payment.js +1 -1
- package/lib/payment/form/index.js +28 -5
- package/package.json +5 -5
- package/src/checkout/donate.tsx +1 -2
- package/src/contexts/payment.tsx +3 -3
- package/src/payment/form/index.tsx +31 -6
package/es/checkout/donate.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type DonateProps = Pick<CheckoutProps, 'onPaid' | 'onError'> & {
|
|
|
11
11
|
settings: DonationSettings;
|
|
12
12
|
livemode?: boolean;
|
|
13
13
|
};
|
|
14
|
-
declare function CheckoutDonate({ settings, livemode, onPaid, onError }: DonateProps): import("react").JSX.Element;
|
|
14
|
+
declare function CheckoutDonate({ settings, livemode, onPaid, onError }: DonateProps): import("react").JSX.Element | null;
|
|
15
15
|
declare namespace CheckoutDonate {
|
|
16
16
|
var defaultProps: {
|
|
17
17
|
livemode: boolean;
|
package/es/checkout/donate.js
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
AvatarGroup,
|
|
8
8
|
Box,
|
|
9
9
|
Button,
|
|
10
|
-
CircularProgress,
|
|
11
10
|
Hidden,
|
|
12
11
|
Stack,
|
|
13
12
|
Table,
|
|
@@ -147,7 +146,7 @@ export default function CheckoutDonate({ settings, livemode, onPaid, onError })
|
|
|
147
146
|
return /* @__PURE__ */ jsx(Alert, { severity: "error", children: formatError(donation.error) });
|
|
148
147
|
}
|
|
149
148
|
if (donation.loading || !donation.data) {
|
|
150
|
-
return
|
|
149
|
+
return null;
|
|
151
150
|
}
|
|
152
151
|
return /* @__PURE__ */ jsxs(
|
|
153
152
|
Box,
|
package/es/contexts/payment.d.ts
CHANGED
package/es/contexts/payment.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Alert
|
|
2
|
+
import { Alert } from "@mui/material";
|
|
3
3
|
import { useLocalStorageState, useRequest } from "ahooks";
|
|
4
4
|
import { createContext, useContext } from "react";
|
|
5
5
|
import api from "../api.js";
|
|
@@ -22,7 +22,7 @@ function PaymentProvider({ children, session, connect }) {
|
|
|
22
22
|
return /* @__PURE__ */ jsx(Alert, { severity: "error", children: error.message });
|
|
23
23
|
}
|
|
24
24
|
if (loading) {
|
|
25
|
-
return
|
|
25
|
+
return null;
|
|
26
26
|
}
|
|
27
27
|
return /* @__PURE__ */ jsx(
|
|
28
28
|
Provider,
|
package/es/payment/form/index.js
CHANGED
|
@@ -39,6 +39,10 @@ const waitForCheckoutComplete = async (sessionId) => {
|
|
|
39
39
|
);
|
|
40
40
|
return result;
|
|
41
41
|
};
|
|
42
|
+
const hasDidWallet = (user) => {
|
|
43
|
+
const connected = user?.connectedAccounts || user?.extraConfigs?.connectedAccounts || [];
|
|
44
|
+
return connected.some((x) => x.provider === "wallet");
|
|
45
|
+
};
|
|
42
46
|
PaymentForm.defaultProps = {};
|
|
43
47
|
export default function PaymentForm({
|
|
44
48
|
checkoutSession,
|
|
@@ -213,19 +217,38 @@ export default function PaymentForm({
|
|
|
213
217
|
setState({ submitting: false });
|
|
214
218
|
}
|
|
215
219
|
};
|
|
216
|
-
const onFormError = () => {
|
|
220
|
+
const onFormError = (err) => {
|
|
221
|
+
if (err) {
|
|
222
|
+
console.error(err);
|
|
223
|
+
}
|
|
217
224
|
setState({ submitting: false });
|
|
218
225
|
};
|
|
219
226
|
const onAction = () => {
|
|
220
227
|
if (session?.user) {
|
|
221
|
-
|
|
228
|
+
if (hasDidWallet(session.user)) {
|
|
229
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
230
|
+
} else {
|
|
231
|
+
session.bindWallet(() => {
|
|
232
|
+
setTimeout(() => {
|
|
233
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
234
|
+
}, 2e3);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
222
237
|
} else {
|
|
223
238
|
session?.login(() => {
|
|
224
239
|
setState({ submitting: true });
|
|
225
240
|
onUserLoggedIn().then(() => {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
241
|
+
if (hasDidWallet(session.user)) {
|
|
242
|
+
setTimeout(() => {
|
|
243
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
244
|
+
}, 80);
|
|
245
|
+
} else {
|
|
246
|
+
session.bindWallet(() => {
|
|
247
|
+
setTimeout(() => {
|
|
248
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
249
|
+
}, 2e3);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
229
252
|
}).catch((err) => {
|
|
230
253
|
console.error(err);
|
|
231
254
|
setState({ submitting: false });
|
package/lib/checkout/donate.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type DonateProps = Pick<CheckoutProps, 'onPaid' | 'onError'> & {
|
|
|
11
11
|
settings: DonationSettings;
|
|
12
12
|
livemode?: boolean;
|
|
13
13
|
};
|
|
14
|
-
declare function CheckoutDonate({ settings, livemode, onPaid, onError }: DonateProps): import("react").JSX.Element;
|
|
14
|
+
declare function CheckoutDonate({ settings, livemode, onPaid, onError }: DonateProps): import("react").JSX.Element | null;
|
|
15
15
|
declare namespace CheckoutDonate {
|
|
16
16
|
var defaultProps: {
|
|
17
17
|
livemode: boolean;
|
package/lib/checkout/donate.js
CHANGED
|
@@ -225,7 +225,7 @@ function CheckoutDonate({
|
|
|
225
225
|
});
|
|
226
226
|
}
|
|
227
227
|
if (donation.loading || !donation.data) {
|
|
228
|
-
return
|
|
228
|
+
return null;
|
|
229
229
|
}
|
|
230
230
|
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
231
231
|
sx: {
|
package/lib/contexts/payment.js
CHANGED
|
@@ -48,6 +48,10 @@ const waitForCheckoutComplete = async sessionId => {
|
|
|
48
48
|
});
|
|
49
49
|
return result;
|
|
50
50
|
};
|
|
51
|
+
const hasDidWallet = user => {
|
|
52
|
+
const connected = user?.connectedAccounts || user?.extraConfigs?.connectedAccounts || [];
|
|
53
|
+
return connected.some(x => x.provider === "wallet");
|
|
54
|
+
};
|
|
51
55
|
PaymentForm.defaultProps = {};
|
|
52
56
|
function PaymentForm({
|
|
53
57
|
checkoutSession,
|
|
@@ -264,23 +268,42 @@ function PaymentForm({
|
|
|
264
268
|
});
|
|
265
269
|
}
|
|
266
270
|
};
|
|
267
|
-
const onFormError =
|
|
271
|
+
const onFormError = err => {
|
|
272
|
+
if (err) {
|
|
273
|
+
console.error(err);
|
|
274
|
+
}
|
|
268
275
|
setState({
|
|
269
276
|
submitting: false
|
|
270
277
|
});
|
|
271
278
|
};
|
|
272
279
|
const onAction = () => {
|
|
273
280
|
if (session?.user) {
|
|
274
|
-
|
|
281
|
+
if (hasDidWallet(session.user)) {
|
|
282
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
283
|
+
} else {
|
|
284
|
+
session.bindWallet(() => {
|
|
285
|
+
setTimeout(() => {
|
|
286
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
287
|
+
}, 2e3);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
275
290
|
} else {
|
|
276
291
|
session?.login(() => {
|
|
277
292
|
setState({
|
|
278
293
|
submitting: true
|
|
279
294
|
});
|
|
280
295
|
onUserLoggedIn().then(() => {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
296
|
+
if (hasDidWallet(session.user)) {
|
|
297
|
+
setTimeout(() => {
|
|
298
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
299
|
+
}, 80);
|
|
300
|
+
} else {
|
|
301
|
+
session.bindWallet(() => {
|
|
302
|
+
setTimeout(() => {
|
|
303
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
304
|
+
}, 2e3);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
284
307
|
}).catch(err => {
|
|
285
308
|
console.error(err);
|
|
286
309
|
setState({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.237",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@arcblock/did-connect": "^2.9.
|
|
56
|
-
"@arcblock/ux": "^2.9.
|
|
55
|
+
"@arcblock/did-connect": "^2.9.75",
|
|
56
|
+
"@arcblock/ux": "^2.9.75",
|
|
57
57
|
"@mui/icons-material": "^5.15.15",
|
|
58
58
|
"@mui/lab": "^5.0.0-alpha.170",
|
|
59
59
|
"@mui/material": "^5.15.15",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"@babel/core": "^7.24.4",
|
|
91
91
|
"@babel/preset-env": "^7.24.4",
|
|
92
92
|
"@babel/preset-react": "^7.24.1",
|
|
93
|
-
"@blocklet/payment-types": "1.13.
|
|
93
|
+
"@blocklet/payment-types": "1.13.237",
|
|
94
94
|
"@storybook/addon-essentials": "^7.6.17",
|
|
95
95
|
"@storybook/addon-interactions": "^7.6.17",
|
|
96
96
|
"@storybook/addon-links": "^7.6.17",
|
|
@@ -119,5 +119,5 @@
|
|
|
119
119
|
"vite-plugin-babel": "^1.2.0",
|
|
120
120
|
"vite-plugin-node-polyfills": "^0.21.0"
|
|
121
121
|
},
|
|
122
|
-
"gitHead": "
|
|
122
|
+
"gitHead": "895430a130d53b62707f4f78c5295b06ce55d4db"
|
|
123
123
|
}
|
package/src/checkout/donate.tsx
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
AvatarGroup,
|
|
15
15
|
Box,
|
|
16
16
|
Button,
|
|
17
|
-
CircularProgress,
|
|
18
17
|
Hidden,
|
|
19
18
|
Stack,
|
|
20
19
|
Table,
|
|
@@ -206,7 +205,7 @@ export default function CheckoutDonate({ settings, livemode, onPaid, onError }:
|
|
|
206
205
|
}
|
|
207
206
|
|
|
208
207
|
if (donation.loading || !donation.data) {
|
|
209
|
-
return
|
|
208
|
+
return null;
|
|
210
209
|
}
|
|
211
210
|
|
|
212
211
|
return (
|
package/src/contexts/payment.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TPaymentCurrency, TPaymentMethodExpanded } from '@blocklet/payment-types';
|
|
2
|
-
import { Alert
|
|
2
|
+
import { Alert } from '@mui/material';
|
|
3
3
|
import { useLocalStorageState, useRequest } from 'ahooks';
|
|
4
4
|
import type { Axios } from 'axios';
|
|
5
5
|
import { createContext, useContext } from 'react';
|
|
@@ -41,7 +41,7 @@ const getCurrency = (currencyId: string, methods: TPaymentMethodExpanded[]) => {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
// eslint-disable-next-line react/prop-types
|
|
44
|
-
function PaymentProvider({ children, session, connect }: { children: any; session: any; connect: any })
|
|
44
|
+
function PaymentProvider({ children, session, connect }: { children: any; session: any; connect: any }) {
|
|
45
45
|
const { data, error, run, loading } = useRequest(getSettings);
|
|
46
46
|
const [livemode, setLivemode] = useLocalStorageState('livemode', { defaultValue: true });
|
|
47
47
|
|
|
@@ -50,7 +50,7 @@ function PaymentProvider({ children, session, connect }: { children: any; sessio
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
if (loading) {
|
|
53
|
-
return
|
|
53
|
+
return null;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
return (
|
|
@@ -57,6 +57,11 @@ const waitForCheckoutComplete = async (sessionId: string) => {
|
|
|
57
57
|
return result;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
+
const hasDidWallet = (user: any) => {
|
|
61
|
+
const connected = user?.connectedAccounts || user?.extraConfigs?.connectedAccounts || [];
|
|
62
|
+
return connected.some((x: any) => x.provider === 'wallet');
|
|
63
|
+
};
|
|
64
|
+
|
|
60
65
|
type PageData = CheckoutContext & CheckoutCallbacks;
|
|
61
66
|
|
|
62
67
|
PaymentForm.defaultProps = {};
|
|
@@ -219,7 +224,6 @@ export default function PaymentForm({
|
|
|
219
224
|
if (result.data.balance?.sufficient || result.data.delegation?.sufficient) {
|
|
220
225
|
await handleConnected();
|
|
221
226
|
} else {
|
|
222
|
-
// @FIXME: 需要考虑如何正确地适配前端组件的使用 @wangshijun
|
|
223
227
|
connect.open({
|
|
224
228
|
containerEl: undefined as unknown as Element,
|
|
225
229
|
action: checkoutSession.mode,
|
|
@@ -267,21 +271,42 @@ export default function PaymentForm({
|
|
|
267
271
|
}
|
|
268
272
|
};
|
|
269
273
|
|
|
270
|
-
const onFormError = () => {
|
|
274
|
+
const onFormError = (err: unknown) => {
|
|
275
|
+
if (err) {
|
|
276
|
+
console.error(err);
|
|
277
|
+
}
|
|
271
278
|
setState({ submitting: false });
|
|
272
279
|
};
|
|
273
280
|
|
|
274
281
|
const onAction = () => {
|
|
275
282
|
if (session?.user) {
|
|
276
|
-
|
|
283
|
+
if (hasDidWallet(session.user)) {
|
|
284
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
285
|
+
} else {
|
|
286
|
+
session.bindWallet(() => {
|
|
287
|
+
// timeout required because https://github.com/ArcBlock/ux/issues/1241
|
|
288
|
+
setTimeout(() => {
|
|
289
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
290
|
+
}, 2000);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
277
293
|
} else {
|
|
278
294
|
session?.login(() => {
|
|
279
295
|
setState({ submitting: true });
|
|
280
296
|
onUserLoggedIn()
|
|
281
297
|
.then(() => {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
298
|
+
if (hasDidWallet(session.user)) {
|
|
299
|
+
setTimeout(() => {
|
|
300
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
301
|
+
}, 80);
|
|
302
|
+
} else {
|
|
303
|
+
session.bindWallet(() => {
|
|
304
|
+
// timeout required because https://github.com/ArcBlock/ux/issues/1241
|
|
305
|
+
setTimeout(() => {
|
|
306
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
307
|
+
}, 2000);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
285
310
|
})
|
|
286
311
|
.catch((err) => {
|
|
287
312
|
console.error(err);
|