@txgw/payout-components 0.4.1 → 0.4.3
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/dist/{component-beneficiary-form-Dw13hlCn.js → component-beneficiary-form-CNfScDy-.js}
RENAMED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { bX as h, bY as
|
|
2
|
-
import { t as
|
|
3
|
-
const
|
|
4
|
-
async function
|
|
5
|
-
const
|
|
1
|
+
import { bX as h, bY as J, ab as y, bZ as W, b_ as Y } from "./vendor-k2fZ6Zi8.js";
|
|
2
|
+
import { t as K, r as O, T as z } from "./amis-BhaLeuNO.js";
|
|
3
|
+
const Q = "bankDetails";
|
|
4
|
+
async function A(t, n, o) {
|
|
5
|
+
const a = {
|
|
6
6
|
authorization_code: t,
|
|
7
7
|
code_verifier: o
|
|
8
8
|
};
|
|
9
9
|
return await (await fetch(`${n}/v1/payout/auth/token`, {
|
|
10
10
|
method: "POST",
|
|
11
|
-
body: JSON.stringify(
|
|
11
|
+
body: JSON.stringify(a),
|
|
12
12
|
headers: {
|
|
13
13
|
"Content-Type": "application/json"
|
|
14
14
|
}
|
|
15
15
|
})).json();
|
|
16
16
|
}
|
|
17
|
-
async function
|
|
17
|
+
async function B(t, n) {
|
|
18
18
|
const o = {
|
|
19
19
|
refresh_token: t
|
|
20
20
|
};
|
|
@@ -26,44 +26,44 @@ async function N(t, n) {
|
|
|
26
26
|
}
|
|
27
27
|
})).json();
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function U(t) {
|
|
30
30
|
const n = Date.parse(t);
|
|
31
31
|
if (!isNaN(n)) {
|
|
32
|
-
const o = Date.now(),
|
|
33
|
-
return
|
|
32
|
+
const o = Date.now(), a = Math.floor((n - o) / 1e3);
|
|
33
|
+
return a > 0 ? a : 0;
|
|
34
34
|
}
|
|
35
35
|
return 0;
|
|
36
36
|
}
|
|
37
37
|
let m = null;
|
|
38
|
-
const
|
|
38
|
+
const H = 300;
|
|
39
39
|
function S(t, n) {
|
|
40
40
|
m && (clearTimeout(m), m = null);
|
|
41
|
-
const o =
|
|
41
|
+
const o = U(t);
|
|
42
42
|
if (o <= 0)
|
|
43
43
|
return;
|
|
44
|
-
const
|
|
44
|
+
const a = Math.max(
|
|
45
45
|
0,
|
|
46
|
-
(o -
|
|
46
|
+
(o - H) * 1e3
|
|
47
47
|
);
|
|
48
48
|
m = setTimeout(async () => {
|
|
49
49
|
try {
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
50
|
+
const r = localStorage.getItem("refresh_token");
|
|
51
|
+
if (!r)
|
|
52
52
|
return;
|
|
53
|
-
const u = await
|
|
54
|
-
|
|
53
|
+
const u = await B(
|
|
54
|
+
r,
|
|
55
55
|
n
|
|
56
56
|
);
|
|
57
57
|
u.access_token && u.refresh_token && (localStorage.setItem("access_token", u.access_token), localStorage.setItem(
|
|
58
58
|
"refresh_token",
|
|
59
59
|
u.refresh_token
|
|
60
60
|
), S(u.expires_in, n));
|
|
61
|
-
} catch (
|
|
62
|
-
console.error("[payout-sdk] Auto refresh token failed:",
|
|
61
|
+
} catch (r) {
|
|
62
|
+
console.error("[payout-sdk] Auto refresh token failed:", r), m && (clearTimeout(m), m = null);
|
|
63
63
|
}
|
|
64
|
-
},
|
|
64
|
+
}, a);
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function X() {
|
|
67
67
|
m && (clearTimeout(m), m = null);
|
|
68
68
|
}
|
|
69
69
|
function j() {
|
|
@@ -72,12 +72,12 @@ function j() {
|
|
|
72
72
|
function R(t, n) {
|
|
73
73
|
localStorage.setItem("access_token", t), localStorage.setItem("refresh_token", n);
|
|
74
74
|
}
|
|
75
|
-
async function b(t, n, o,
|
|
76
|
-
if (
|
|
75
|
+
async function b(t, n, o, a = 1) {
|
|
76
|
+
if (a < 0)
|
|
77
77
|
throw new Error("[payout-sdk] fetchWithAuth retries exceeded");
|
|
78
|
-
const { headers:
|
|
78
|
+
const { headers: r, authCode: u, domain: p, codeVerifier: f } = o;
|
|
79
79
|
if (!localStorage.getItem("access_token")) {
|
|
80
|
-
const e = await
|
|
80
|
+
const e = await A(
|
|
81
81
|
u,
|
|
82
82
|
p,
|
|
83
83
|
f
|
|
@@ -98,29 +98,29 @@ async function b(t, n, o, r = 1) {
|
|
|
98
98
|
access_token: localStorage.getItem("access_token")
|
|
99
99
|
}),
|
|
100
100
|
headers: {
|
|
101
|
-
...
|
|
101
|
+
...r,
|
|
102
102
|
"Content-Type": "application/json"
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
105
|
if (_.status === 400) {
|
|
106
106
|
const e = await _.json();
|
|
107
107
|
if (e.name != "INTERNAL_ERROR" && e.name != "INVALID_TOKEN")
|
|
108
|
-
throw
|
|
108
|
+
throw K.error(`${e.name}: ${e.message}`), new Error(`[payout-sdk] ${e.name}: ${e.message}`);
|
|
109
109
|
const C = localStorage.getItem("refresh_token");
|
|
110
110
|
if (C) {
|
|
111
|
-
const k = await
|
|
111
|
+
const k = await B(
|
|
112
112
|
C,
|
|
113
113
|
p
|
|
114
114
|
);
|
|
115
115
|
if (!k.access_token || !k.refresh_token)
|
|
116
|
-
j(),
|
|
116
|
+
j(), X();
|
|
117
117
|
else
|
|
118
118
|
return R(
|
|
119
119
|
k.access_token,
|
|
120
120
|
k.refresh_token
|
|
121
|
-
), S(k.expires_in, p), b(t, n, o, --
|
|
121
|
+
), S(k.expires_in, p), b(t, n, o, --a);
|
|
122
122
|
}
|
|
123
|
-
const d = await
|
|
123
|
+
const d = await A(
|
|
124
124
|
u,
|
|
125
125
|
p,
|
|
126
126
|
f
|
|
@@ -132,14 +132,14 @@ async function b(t, n, o, r = 1) {
|
|
|
132
132
|
return R(
|
|
133
133
|
d.access_token,
|
|
134
134
|
d.refresh_token
|
|
135
|
-
), S(d.expires_in, p), b(t, n, o, --
|
|
135
|
+
), S(d.expires_in, p), b(t, n, o, --a);
|
|
136
136
|
}
|
|
137
137
|
return _;
|
|
138
138
|
}
|
|
139
|
-
function
|
|
139
|
+
function N(t) {
|
|
140
140
|
return t && t.startsWith("zh") ? "zh_CN" : "en_US";
|
|
141
141
|
}
|
|
142
|
-
async function
|
|
142
|
+
async function Z(t, n, o) {
|
|
143
143
|
return (await (await b(
|
|
144
144
|
"/v1/payout/beneficiary/token/countryinfos",
|
|
145
145
|
{},
|
|
@@ -151,7 +151,7 @@ async function U(t, n, o) {
|
|
|
151
151
|
}
|
|
152
152
|
)).json()).country_infos || [];
|
|
153
153
|
}
|
|
154
|
-
async function
|
|
154
|
+
async function G(t, n, o, a) {
|
|
155
155
|
return await (await b(
|
|
156
156
|
"/v1/payout/beneficiary/token/paymentmethodinfos",
|
|
157
157
|
{
|
|
@@ -161,11 +161,11 @@ async function H(t, n, o, r) {
|
|
|
161
161
|
method: "POST",
|
|
162
162
|
authCode: n,
|
|
163
163
|
domain: o,
|
|
164
|
-
codeVerifier:
|
|
164
|
+
codeVerifier: a
|
|
165
165
|
}
|
|
166
166
|
)).json();
|
|
167
167
|
}
|
|
168
|
-
function
|
|
168
|
+
function V({ inputPayoutType: t, inputCurrency: n }, o, a, r) {
|
|
169
169
|
const u = [];
|
|
170
170
|
for (const p of Object.values(o.countries)) {
|
|
171
171
|
const f = p.payoutTypes?.[t]?.currencies;
|
|
@@ -177,7 +177,7 @@ function X({ inputPayoutType: t, inputCurrency: n }, o, r, i) {
|
|
|
177
177
|
return {
|
|
178
178
|
type: "list-select",
|
|
179
179
|
name: "inputPaymentMethod",
|
|
180
|
-
label:
|
|
180
|
+
label: a("paymentMethodInputLabel", "Transfer method"),
|
|
181
181
|
options: u.map((p) => ({
|
|
182
182
|
value: p.payment_method,
|
|
183
183
|
body: /* @__PURE__ */ h.jsxs("div", { children: [
|
|
@@ -185,15 +185,15 @@ function X({ inputPayoutType: t, inputCurrency: n }, o, r, i) {
|
|
|
185
185
|
/* @__PURE__ */ h.jsx("span", { className: "flex mt-1", children: p.description })
|
|
186
186
|
] })
|
|
187
187
|
})),
|
|
188
|
-
value:
|
|
188
|
+
value: r?.payment_method
|
|
189
189
|
};
|
|
190
190
|
}
|
|
191
|
-
async function
|
|
191
|
+
async function ee({
|
|
192
192
|
inputRegionCode: t,
|
|
193
193
|
inputCurrency: n,
|
|
194
194
|
inputPaymentMethod: o
|
|
195
|
-
},
|
|
196
|
-
if (!t || !n || !o || !
|
|
195
|
+
}, a, r, u) {
|
|
196
|
+
if (!t || !n || !o || !a || !r || !u)
|
|
197
197
|
return;
|
|
198
198
|
const l = await (await b(
|
|
199
199
|
"/v1/payout/beneficiary/form/schema/token/query",
|
|
@@ -207,8 +207,8 @@ async function Z({
|
|
|
207
207
|
},
|
|
208
208
|
{
|
|
209
209
|
method: "POST",
|
|
210
|
-
authCode:
|
|
211
|
-
domain:
|
|
210
|
+
authCode: a,
|
|
211
|
+
domain: r,
|
|
212
212
|
codeVerifier: u
|
|
213
213
|
}
|
|
214
214
|
)).json();
|
|
@@ -216,47 +216,47 @@ async function Z({
|
|
|
216
216
|
l.beneficiary_schema.amis_page.replace(/Area Code/g, "AREA_CODE")
|
|
217
217
|
);
|
|
218
218
|
}
|
|
219
|
-
function
|
|
219
|
+
function te(t) {
|
|
220
220
|
return "B2P";
|
|
221
221
|
}
|
|
222
|
-
function
|
|
222
|
+
function ne({
|
|
223
223
|
authCode: t,
|
|
224
224
|
domain: n,
|
|
225
225
|
codeVerifier: o,
|
|
226
|
-
emitter:
|
|
227
|
-
defaultValues:
|
|
226
|
+
emitter: a,
|
|
227
|
+
defaultValues: r,
|
|
228
228
|
customizations: u,
|
|
229
229
|
locale: p
|
|
230
230
|
}) {
|
|
231
|
-
const { t: f } =
|
|
232
|
-
inputPayoutType:
|
|
233
|
-
|
|
231
|
+
const { t: f } = J("beneficiaryForm"), [l, _] = y.useState([]), [e, C] = y.useState({
|
|
232
|
+
inputPayoutType: te(
|
|
233
|
+
r?.beneficiary?.entity_details?.type
|
|
234
234
|
),
|
|
235
|
-
inputPaymentMethod:
|
|
236
|
-
inputRegionCode:
|
|
237
|
-
inputCurrency:
|
|
238
|
-
}), [d, k] = y.useState(), [I,
|
|
239
|
-
(
|
|
235
|
+
inputPaymentMethod: r?.payment_method,
|
|
236
|
+
inputRegionCode: r?.beneficiary?.address?.country,
|
|
237
|
+
inputCurrency: r?.receive_currency
|
|
238
|
+
}), [d, k] = y.useState(), [I, L] = y.useState(), w = y.useMemo(() => !u?.layout?.find(
|
|
239
|
+
(c) => c.name === Q
|
|
240
240
|
)?.hidden, [u?.layout]), P = y.useMemo(() => {
|
|
241
241
|
const s = /* @__PURE__ */ new Set();
|
|
242
242
|
return l.filter(
|
|
243
|
-
(
|
|
244
|
-
).map((
|
|
245
|
-
label:
|
|
246
|
-
value:
|
|
247
|
-
})).sort((
|
|
248
|
-
}, [l]), [v,
|
|
243
|
+
(i) => i.country_number && !s.has(i.country_number) && s.add(i.country_number)
|
|
244
|
+
).map((i) => ({
|
|
245
|
+
label: i.country_name_standard || i.country_name,
|
|
246
|
+
value: i.country_code
|
|
247
|
+
})).sort((i, g) => i.label.localeCompare(g.label));
|
|
248
|
+
}, [l]), [v, D] = y.useState();
|
|
249
249
|
y.useEffect(() => {
|
|
250
250
|
if (!e?.inputRegionCode || !e?.inputPayoutType) return;
|
|
251
251
|
const s = e.inputRegionCode;
|
|
252
|
-
|
|
253
|
-
(
|
|
254
|
-
k(
|
|
255
|
-
const
|
|
256
|
-
|
|
252
|
+
G(s, t, n, o).then(
|
|
253
|
+
(c) => {
|
|
254
|
+
k(c);
|
|
255
|
+
const i = Object.keys(
|
|
256
|
+
c.countries?.[s].payoutTypes?.[e.inputPayoutType]?.currencies
|
|
257
257
|
);
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
i && i.length > 0 && D(
|
|
259
|
+
i.map((g) => ({
|
|
260
260
|
label: g,
|
|
261
261
|
value: g
|
|
262
262
|
}))
|
|
@@ -271,24 +271,24 @@ function V({
|
|
|
271
271
|
e?.inputRegionCode
|
|
272
272
|
]);
|
|
273
273
|
const x = y.useMemo(() => Array.from(
|
|
274
|
-
new Set(l.map((
|
|
275
|
-
).map((
|
|
276
|
-
label:
|
|
277
|
-
value:
|
|
278
|
-
})).filter((
|
|
274
|
+
new Set(l.map((c) => c.currency_code))
|
|
275
|
+
).map((c) => ({
|
|
276
|
+
label: c,
|
|
277
|
+
value: c
|
|
278
|
+
})).filter((c) => !!c.label && c.label !== "-").sort((c, i) => c.label.localeCompare(i.label)), [l]), T = y.useMemo(() => !e?.inputCurrency || !e?.inputPayoutType || !d ? void 0 : V(
|
|
279
279
|
{
|
|
280
280
|
inputPayoutType: e.inputPayoutType,
|
|
281
281
|
inputCurrency: e.inputCurrency
|
|
282
282
|
},
|
|
283
283
|
d,
|
|
284
284
|
f,
|
|
285
|
-
|
|
286
|
-
), [
|
|
285
|
+
r
|
|
286
|
+
), [r, e, d, f]), E = y.useMemo(() => {
|
|
287
287
|
if (!(l.length === 0 || !T || !e?.inputPaymentMethod || !e?.inputRegionCode || !e?.inputCurrency))
|
|
288
288
|
return I;
|
|
289
289
|
}, [l, e, I, T]);
|
|
290
290
|
y.useEffect(() => {
|
|
291
|
-
|
|
291
|
+
ee(
|
|
292
292
|
{
|
|
293
293
|
inputPaymentMethod: e.inputPaymentMethod,
|
|
294
294
|
inputRegionCode: e.inputRegionCode,
|
|
@@ -299,11 +299,17 @@ function V({
|
|
|
299
299
|
o
|
|
300
300
|
).then((s) => {
|
|
301
301
|
if (!s) return;
|
|
302
|
-
const
|
|
303
|
-
(
|
|
302
|
+
const c = s.body.findIndex(
|
|
303
|
+
(i) => i.type === "form"
|
|
304
304
|
);
|
|
305
|
-
s.body[
|
|
306
|
-
return
|
|
305
|
+
s.body[c].api.url = "/api/form", s.body[c].api.requestAdaptor = function(i, g) {
|
|
306
|
+
return i?.body?.value && a.emit(
|
|
307
|
+
"submit",
|
|
308
|
+
W(i.body.value, r, (M, q) => {
|
|
309
|
+
if (Array.isArray(M))
|
|
310
|
+
return M.concat(q);
|
|
311
|
+
})
|
|
312
|
+
), {
|
|
307
313
|
mockResponse: {
|
|
308
314
|
status: 200,
|
|
309
315
|
data: {
|
|
@@ -314,7 +320,7 @@ function V({
|
|
|
314
320
|
}
|
|
315
321
|
}
|
|
316
322
|
};
|
|
317
|
-
},
|
|
323
|
+
}, L(s);
|
|
318
324
|
});
|
|
319
325
|
}, [
|
|
320
326
|
l,
|
|
@@ -325,9 +331,10 @@ function V({
|
|
|
325
331
|
e.inputCurrency,
|
|
326
332
|
e.inputPaymentMethod,
|
|
327
333
|
e.inputRegionCode,
|
|
334
|
+
a,
|
|
328
335
|
r
|
|
329
336
|
]);
|
|
330
|
-
const
|
|
337
|
+
const F = y.useMemo(
|
|
331
338
|
() => ({
|
|
332
339
|
type: "page",
|
|
333
340
|
visible: w,
|
|
@@ -341,12 +348,12 @@ function V({
|
|
|
341
348
|
title: f("title", "Bank Details"),
|
|
342
349
|
submitText: "",
|
|
343
350
|
onChange: (s) => {
|
|
344
|
-
const
|
|
351
|
+
const c = s.inputRegionCode, i = s.inputRegionCode ? s.inputCurrency : "", g = s.inputRegionCode ? s.inputPaymentMethod : "";
|
|
345
352
|
C({
|
|
346
353
|
inputPayoutType: s.inputPayoutType,
|
|
347
354
|
inputPaymentMethod: g,
|
|
348
|
-
inputRegionCode:
|
|
349
|
-
inputCurrency:
|
|
355
|
+
inputRegionCode: c,
|
|
356
|
+
inputCurrency: i
|
|
350
357
|
});
|
|
351
358
|
},
|
|
352
359
|
body: [
|
|
@@ -398,16 +405,16 @@ function V({
|
|
|
398
405
|
);
|
|
399
406
|
y.useEffect(() => {
|
|
400
407
|
async function s() {
|
|
401
|
-
const
|
|
408
|
+
const c = await Z(
|
|
402
409
|
t,
|
|
403
410
|
n,
|
|
404
411
|
o
|
|
405
412
|
);
|
|
406
|
-
_(
|
|
413
|
+
_(c);
|
|
407
414
|
}
|
|
408
415
|
s();
|
|
409
416
|
}, [t, o, n]);
|
|
410
|
-
const
|
|
417
|
+
const $ = y.useMemo(
|
|
411
418
|
() => ({
|
|
412
419
|
fetcher: () => new Promise(() => ({
|
|
413
420
|
status: 200,
|
|
@@ -422,23 +429,23 @@ function V({
|
|
|
422
429
|
[]
|
|
423
430
|
);
|
|
424
431
|
return /* @__PURE__ */ h.jsxs(h.Fragment, { children: [
|
|
425
|
-
/* @__PURE__ */ h.jsx(
|
|
426
|
-
|
|
427
|
-
locale:
|
|
432
|
+
/* @__PURE__ */ h.jsx(z, {}),
|
|
433
|
+
O(F, {
|
|
434
|
+
locale: N(p)
|
|
428
435
|
}),
|
|
429
|
-
E &&
|
|
436
|
+
E && O(
|
|
430
437
|
E,
|
|
431
438
|
{
|
|
432
|
-
locale:
|
|
439
|
+
locale: N(p)
|
|
433
440
|
},
|
|
434
|
-
|
|
441
|
+
$
|
|
435
442
|
)
|
|
436
443
|
] });
|
|
437
444
|
}
|
|
438
|
-
function
|
|
445
|
+
function se(t) {
|
|
439
446
|
const { mi18n: n } = t;
|
|
440
|
-
return /* @__PURE__ */ h.jsx(
|
|
447
|
+
return /* @__PURE__ */ h.jsx(Y, { mi18n: n, fallback: "Loading...", children: /* @__PURE__ */ h.jsx(ne, { ...t }) });
|
|
441
448
|
}
|
|
442
449
|
export {
|
|
443
|
-
|
|
450
|
+
se as default
|
|
444
451
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b$ as m, c0 as u, c1 as c, c2 as h, c3 as l, c4 as f, c5 as p } from "./vendor-k2fZ6Zi8.js";
|
|
2
2
|
class d {
|
|
3
3
|
loader;
|
|
4
4
|
options;
|
|
@@ -11,7 +11,7 @@ class d {
|
|
|
11
11
|
}
|
|
12
12
|
async mount(t) {
|
|
13
13
|
if (this.mounted) return;
|
|
14
|
-
const n = await this.loader(), e = n.default ?? n, a = await import("./vendor-
|
|
14
|
+
const n = await this.loader(), e = n.default ?? n, a = await import("./vendor-k2fZ6Zi8.js").then((i) => i.R), r = (await import("./vendor-k2fZ6Zi8.js").then((i) => i.c)).createRoot(t);
|
|
15
15
|
r.render(
|
|
16
16
|
a.createElement(e, {
|
|
17
17
|
...this.options,
|
|
@@ -34,7 +34,7 @@ class d {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
const g = {
|
|
37
|
-
beneficiaryForm: () => import("./component-beneficiary-form-
|
|
37
|
+
beneficiaryForm: () => import("./component-beneficiary-form-CNfScDy-.js")
|
|
38
38
|
}, w = {
|
|
39
39
|
staticData: {
|
|
40
40
|
en: () => import("./en-Cb5xUNU4.js")
|