@blocklet/payment-react 1.13.236 → 1.13.238
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 +30 -8
- 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 +29 -7
- 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 +34 -9
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
|
@@ -5,7 +5,7 @@ import { useTheme } from "@arcblock/ux/lib/Theme";
|
|
|
5
5
|
import Toast from "@arcblock/ux/lib/Toast";
|
|
6
6
|
import { LoadingButton } from "@mui/lab";
|
|
7
7
|
import { Fade, InputAdornment, Stack, Typography } from "@mui/material";
|
|
8
|
-
import { useCreation, useSetState, useSize } from "ahooks";
|
|
8
|
+
import { useCreation, useMemoizedFn, useSetState, useSize } from "ahooks";
|
|
9
9
|
import { PhoneNumberUtil } from "google-libphonenumber";
|
|
10
10
|
import pWaitFor from "p-wait-for";
|
|
11
11
|
import { useEffect, useState } from "react";
|
|
@@ -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,
|
|
@@ -95,6 +99,17 @@ export default function PaymentForm({
|
|
|
95
99
|
}
|
|
96
100
|
return false;
|
|
97
101
|
}, [domSize, theme]);
|
|
102
|
+
const afterUserLoggedIn = useMemoizedFn(() => {
|
|
103
|
+
if (hasDidWallet(session.user)) {
|
|
104
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
105
|
+
} else {
|
|
106
|
+
session.bindWallet(() => {
|
|
107
|
+
setTimeout(() => {
|
|
108
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
109
|
+
}, 2e3);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
98
113
|
const payee = getStatementDescriptor(checkoutSession.line_items);
|
|
99
114
|
let buttonText = "";
|
|
100
115
|
if (paymentLink?.donation_settings) {
|
|
@@ -213,20 +228,27 @@ export default function PaymentForm({
|
|
|
213
228
|
setState({ submitting: false });
|
|
214
229
|
}
|
|
215
230
|
};
|
|
216
|
-
const onFormError = () => {
|
|
231
|
+
const onFormError = (err) => {
|
|
232
|
+
if (err) {
|
|
233
|
+
console.error(err);
|
|
234
|
+
}
|
|
217
235
|
setState({ submitting: false });
|
|
218
236
|
};
|
|
219
237
|
const onAction = () => {
|
|
220
238
|
if (session?.user) {
|
|
221
|
-
|
|
239
|
+
if (hasDidWallet(session.user)) {
|
|
240
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
241
|
+
} else {
|
|
242
|
+
session.bindWallet(() => {
|
|
243
|
+
setTimeout(() => {
|
|
244
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
245
|
+
}, 2e3);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
222
248
|
} else {
|
|
223
249
|
session?.login(() => {
|
|
224
250
|
setState({ submitting: true });
|
|
225
|
-
onUserLoggedIn().then(() => {
|
|
226
|
-
setTimeout(() => {
|
|
227
|
-
handleSubmit(onFormSubmit, onFormError)();
|
|
228
|
-
}, 50);
|
|
229
|
-
}).catch((err) => {
|
|
251
|
+
onUserLoggedIn().then(afterUserLoggedIn).catch((err) => {
|
|
230
252
|
console.error(err);
|
|
231
253
|
setState({ submitting: false });
|
|
232
254
|
});
|
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,
|
|
@@ -117,6 +121,17 @@ function PaymentForm({
|
|
|
117
121
|
}
|
|
118
122
|
return false;
|
|
119
123
|
}, [domSize, theme]);
|
|
124
|
+
const afterUserLoggedIn = (0, _ahooks.useMemoizedFn)(() => {
|
|
125
|
+
if (hasDidWallet(session.user)) {
|
|
126
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
127
|
+
} else {
|
|
128
|
+
session.bindWallet(() => {
|
|
129
|
+
setTimeout(() => {
|
|
130
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
131
|
+
}, 2e3);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
});
|
|
120
135
|
const payee = (0, _util.getStatementDescriptor)(checkoutSession.line_items);
|
|
121
136
|
let buttonText = "";
|
|
122
137
|
if (paymentLink?.donation_settings) {
|
|
@@ -264,24 +279,31 @@ function PaymentForm({
|
|
|
264
279
|
});
|
|
265
280
|
}
|
|
266
281
|
};
|
|
267
|
-
const onFormError =
|
|
282
|
+
const onFormError = err => {
|
|
283
|
+
if (err) {
|
|
284
|
+
console.error(err);
|
|
285
|
+
}
|
|
268
286
|
setState({
|
|
269
287
|
submitting: false
|
|
270
288
|
});
|
|
271
289
|
};
|
|
272
290
|
const onAction = () => {
|
|
273
291
|
if (session?.user) {
|
|
274
|
-
|
|
292
|
+
if (hasDidWallet(session.user)) {
|
|
293
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
294
|
+
} else {
|
|
295
|
+
session.bindWallet(() => {
|
|
296
|
+
setTimeout(() => {
|
|
297
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
298
|
+
}, 2e3);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
275
301
|
} else {
|
|
276
302
|
session?.login(() => {
|
|
277
303
|
setState({
|
|
278
304
|
submitting: true
|
|
279
305
|
});
|
|
280
|
-
onUserLoggedIn().then((
|
|
281
|
-
setTimeout(() => {
|
|
282
|
-
handleSubmit(onFormSubmit, onFormError)();
|
|
283
|
-
}, 50);
|
|
284
|
-
}).catch(err => {
|
|
306
|
+
onUserLoggedIn().then(afterUserLoggedIn).catch(err => {
|
|
285
307
|
console.error(err);
|
|
286
308
|
setState({
|
|
287
309
|
submitting: false
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.238",
|
|
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.238",
|
|
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": "3476a64bdb10cf042551f55f087c5e1b30717894"
|
|
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 (
|
|
@@ -6,7 +6,7 @@ import Toast from '@arcblock/ux/lib/Toast';
|
|
|
6
6
|
import type { TCustomer, TPaymentIntent, TPaymentMethodExpanded } from '@blocklet/payment-types';
|
|
7
7
|
import { LoadingButton } from '@mui/lab';
|
|
8
8
|
import { Fade, InputAdornment, Stack, Typography } from '@mui/material';
|
|
9
|
-
import { useCreation, useSetState, useSize } from 'ahooks';
|
|
9
|
+
import { useCreation, useMemoizedFn, useSetState, useSize } from 'ahooks';
|
|
10
10
|
import { PhoneNumberUtil } from 'google-libphonenumber';
|
|
11
11
|
import pWaitFor from 'p-wait-for';
|
|
12
12
|
import { useEffect, useState } from 'react';
|
|
@@ -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 = {};
|
|
@@ -141,6 +146,19 @@ export default function PaymentForm({
|
|
|
141
146
|
return false;
|
|
142
147
|
}, [domSize, theme]);
|
|
143
148
|
|
|
149
|
+
const afterUserLoggedIn = useMemoizedFn(() => {
|
|
150
|
+
if (hasDidWallet(session.user)) {
|
|
151
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
152
|
+
} else {
|
|
153
|
+
session.bindWallet(() => {
|
|
154
|
+
// timeout required because https://github.com/ArcBlock/ux/issues/1241
|
|
155
|
+
setTimeout(() => {
|
|
156
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
157
|
+
}, 2000);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
144
162
|
const payee = getStatementDescriptor(checkoutSession.line_items);
|
|
145
163
|
let buttonText = '';
|
|
146
164
|
if (paymentLink?.donation_settings) {
|
|
@@ -219,7 +237,6 @@ export default function PaymentForm({
|
|
|
219
237
|
if (result.data.balance?.sufficient || result.data.delegation?.sufficient) {
|
|
220
238
|
await handleConnected();
|
|
221
239
|
} else {
|
|
222
|
-
// @FIXME: 需要考虑如何正确地适配前端组件的使用 @wangshijun
|
|
223
240
|
connect.open({
|
|
224
241
|
containerEl: undefined as unknown as Element,
|
|
225
242
|
action: checkoutSession.mode,
|
|
@@ -267,22 +284,30 @@ export default function PaymentForm({
|
|
|
267
284
|
}
|
|
268
285
|
};
|
|
269
286
|
|
|
270
|
-
const onFormError = () => {
|
|
287
|
+
const onFormError = (err: unknown) => {
|
|
288
|
+
if (err) {
|
|
289
|
+
console.error(err);
|
|
290
|
+
}
|
|
271
291
|
setState({ submitting: false });
|
|
272
292
|
};
|
|
273
293
|
|
|
274
294
|
const onAction = () => {
|
|
275
295
|
if (session?.user) {
|
|
276
|
-
|
|
296
|
+
if (hasDidWallet(session.user)) {
|
|
297
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
298
|
+
} else {
|
|
299
|
+
session.bindWallet(() => {
|
|
300
|
+
// timeout required because https://github.com/ArcBlock/ux/issues/1241
|
|
301
|
+
setTimeout(() => {
|
|
302
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
303
|
+
}, 2000);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
277
306
|
} else {
|
|
278
307
|
session?.login(() => {
|
|
279
308
|
setState({ submitting: true });
|
|
280
309
|
onUserLoggedIn()
|
|
281
|
-
.then(
|
|
282
|
-
setTimeout(() => {
|
|
283
|
-
handleSubmit(onFormSubmit, onFormError)();
|
|
284
|
-
}, 50);
|
|
285
|
-
})
|
|
310
|
+
.then(afterUserLoggedIn)
|
|
286
311
|
.catch((err) => {
|
|
287
312
|
console.error(err);
|
|
288
313
|
setState({ submitting: false });
|