@txgw/payout-components 0.2.3 → 0.3.0
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.
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { bX as _, bY as q, ab as y, bZ as J } from "./vendor-DyrjuDU0.js";
|
|
2
|
+
import { t as Y, d as K, r as O, T as W } from "./amis-CGgHoXTI.js";
|
|
3
|
+
const z = "bankDetails";
|
|
4
|
+
async function j(t, n, o) {
|
|
5
|
+
const r = {
|
|
6
|
+
authorization_code: t,
|
|
7
|
+
code_verifier: o
|
|
8
|
+
};
|
|
9
|
+
return await (await fetch(`${n}/v1/payout/auth/token`, {
|
|
10
|
+
method: "POST",
|
|
11
|
+
body: JSON.stringify(r),
|
|
12
|
+
headers: {
|
|
13
|
+
"Content-Type": "application/json"
|
|
14
|
+
}
|
|
15
|
+
})).json();
|
|
16
|
+
}
|
|
17
|
+
async function B(t, n) {
|
|
18
|
+
const o = {
|
|
19
|
+
refresh_token: t
|
|
20
|
+
};
|
|
21
|
+
return await (await fetch(`${n}/v1/payout/auth/token/refresh`, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
body: JSON.stringify(o),
|
|
24
|
+
headers: {
|
|
25
|
+
"Content-Type": "application/json"
|
|
26
|
+
}
|
|
27
|
+
})).json();
|
|
28
|
+
}
|
|
29
|
+
function Q(t) {
|
|
30
|
+
const n = Date.parse(t);
|
|
31
|
+
if (!isNaN(n)) {
|
|
32
|
+
const o = Date.now(), r = Math.floor((n - o) / 1e3);
|
|
33
|
+
return r > 0 ? r : 0;
|
|
34
|
+
}
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
let h = null;
|
|
38
|
+
const H = 300;
|
|
39
|
+
function S(t, n) {
|
|
40
|
+
h && (clearTimeout(h), h = null);
|
|
41
|
+
const o = Q(t);
|
|
42
|
+
if (o <= 0)
|
|
43
|
+
return;
|
|
44
|
+
const r = Math.max(
|
|
45
|
+
0,
|
|
46
|
+
(o - H) * 1e3
|
|
47
|
+
);
|
|
48
|
+
h = setTimeout(async () => {
|
|
49
|
+
try {
|
|
50
|
+
const c = localStorage.getItem("refresh_token");
|
|
51
|
+
if (!c)
|
|
52
|
+
return;
|
|
53
|
+
const i = await B(
|
|
54
|
+
c,
|
|
55
|
+
n
|
|
56
|
+
);
|
|
57
|
+
i.access_token && i.refresh_token && (localStorage.setItem("access_token", i.access_token), localStorage.setItem(
|
|
58
|
+
"refresh_token",
|
|
59
|
+
i.refresh_token
|
|
60
|
+
), S(i.expires_in, n));
|
|
61
|
+
} catch (c) {
|
|
62
|
+
console.error("[payout-sdk] Auto refresh token failed:", c), h && (clearTimeout(h), h = null);
|
|
63
|
+
}
|
|
64
|
+
}, r);
|
|
65
|
+
}
|
|
66
|
+
function U() {
|
|
67
|
+
h && (clearTimeout(h), h = null);
|
|
68
|
+
}
|
|
69
|
+
function A() {
|
|
70
|
+
localStorage.removeItem("access_token"), localStorage.removeItem("refresh_token");
|
|
71
|
+
}
|
|
72
|
+
function R(t, n) {
|
|
73
|
+
localStorage.setItem("access_token", t), localStorage.setItem("refresh_token", n);
|
|
74
|
+
}
|
|
75
|
+
async function b(t, n, o, r = 1) {
|
|
76
|
+
if (r < 0)
|
|
77
|
+
throw new Error("[payout-sdk] fetchWithAuth retries exceeded");
|
|
78
|
+
const { headers: c, authCode: i, domain: p, codeVerifier: f } = o;
|
|
79
|
+
if (!localStorage.getItem("access_token")) {
|
|
80
|
+
const e = await j(
|
|
81
|
+
i,
|
|
82
|
+
p,
|
|
83
|
+
f
|
|
84
|
+
);
|
|
85
|
+
if (!e.access_token || !e.refresh_token)
|
|
86
|
+
throw A(), new Error(
|
|
87
|
+
"[payout-sdk] getAccessToken failed, check authCode validity"
|
|
88
|
+
);
|
|
89
|
+
R(
|
|
90
|
+
e.access_token,
|
|
91
|
+
e.refresh_token
|
|
92
|
+
), S(e.expires_in, p);
|
|
93
|
+
}
|
|
94
|
+
const k = await fetch(t, {
|
|
95
|
+
...o,
|
|
96
|
+
body: JSON.stringify({
|
|
97
|
+
...n,
|
|
98
|
+
access_token: localStorage.getItem("access_token")
|
|
99
|
+
}),
|
|
100
|
+
headers: {
|
|
101
|
+
...c,
|
|
102
|
+
"Content-Type": "application/json"
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
if (k.status === 400) {
|
|
106
|
+
const e = await k.json();
|
|
107
|
+
if (e.name != "INTERNAL_ERROR" && e.name != "INVALID_TOKEN")
|
|
108
|
+
throw Y.error(`${e.name}: ${e.message}`), new Error(`[payout-sdk] ${e.name}: ${e.message}`);
|
|
109
|
+
const C = localStorage.getItem("refresh_token");
|
|
110
|
+
if (C) {
|
|
111
|
+
const g = await B(
|
|
112
|
+
C,
|
|
113
|
+
p
|
|
114
|
+
);
|
|
115
|
+
if (!g.access_token || !g.refresh_token)
|
|
116
|
+
A(), U();
|
|
117
|
+
else
|
|
118
|
+
return R(
|
|
119
|
+
g.access_token,
|
|
120
|
+
g.refresh_token
|
|
121
|
+
), S(g.expires_in, p), b(t, n, o, --r);
|
|
122
|
+
}
|
|
123
|
+
const d = await j(
|
|
124
|
+
i,
|
|
125
|
+
p,
|
|
126
|
+
f
|
|
127
|
+
);
|
|
128
|
+
if (!d.access_token || !d.refresh_token)
|
|
129
|
+
throw new Error(
|
|
130
|
+
"[payout-sdk] getAccessToken failed, check authCode validity"
|
|
131
|
+
);
|
|
132
|
+
return R(
|
|
133
|
+
d.access_token,
|
|
134
|
+
d.refresh_token
|
|
135
|
+
), S(d.expires_in, p), b(t, n, o, --r);
|
|
136
|
+
}
|
|
137
|
+
return k;
|
|
138
|
+
}
|
|
139
|
+
function N(t) {
|
|
140
|
+
return t && t.startsWith("zh") ? "zh_CN" : "en_US";
|
|
141
|
+
}
|
|
142
|
+
async function X(t, n, o) {
|
|
143
|
+
return (await (await b(
|
|
144
|
+
"/v1/payout/beneficiary/token/countryinfos",
|
|
145
|
+
{},
|
|
146
|
+
{
|
|
147
|
+
method: "POST",
|
|
148
|
+
authCode: t,
|
|
149
|
+
domain: n,
|
|
150
|
+
codeVerifier: o
|
|
151
|
+
}
|
|
152
|
+
)).json()).country_infos || [];
|
|
153
|
+
}
|
|
154
|
+
async function Z(t, n, o, r) {
|
|
155
|
+
return await (await b(
|
|
156
|
+
"/v1/payout/beneficiary/token/paymentmethodinfos",
|
|
157
|
+
{
|
|
158
|
+
region_code: t
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
method: "POST",
|
|
162
|
+
authCode: n,
|
|
163
|
+
domain: o,
|
|
164
|
+
codeVerifier: r
|
|
165
|
+
}
|
|
166
|
+
)).json();
|
|
167
|
+
}
|
|
168
|
+
function G({ inputPayoutType: t, inputCurrency: n }, o, r, c) {
|
|
169
|
+
const i = [];
|
|
170
|
+
for (const p of Object.values(o.countries)) {
|
|
171
|
+
const f = p.payoutTypes?.[t]?.currencies;
|
|
172
|
+
if (f)
|
|
173
|
+
for (const [l, k] of Object.entries(f))
|
|
174
|
+
l === n && i.push(k);
|
|
175
|
+
}
|
|
176
|
+
if (i.length !== 0)
|
|
177
|
+
return {
|
|
178
|
+
type: "list-select",
|
|
179
|
+
name: "inputPaymentMethod",
|
|
180
|
+
label: r("paymentMethodInputLabel", "Transfer method"),
|
|
181
|
+
options: i.map((p) => ({
|
|
182
|
+
value: p.payment_method,
|
|
183
|
+
body: /* @__PURE__ */ _.jsxs("div", { children: [
|
|
184
|
+
/* @__PURE__ */ _.jsx("span", { className: "flex font-bold", children: p.display_name }),
|
|
185
|
+
/* @__PURE__ */ _.jsx("span", { className: "flex mt-1", children: p.description })
|
|
186
|
+
] })
|
|
187
|
+
})),
|
|
188
|
+
value: c?.payment_method
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
async function V({
|
|
192
|
+
inputRegionCode: t,
|
|
193
|
+
inputCurrency: n,
|
|
194
|
+
inputPaymentMethod: o
|
|
195
|
+
}, r, c, i) {
|
|
196
|
+
if (!t || !n || !o || !r || !c || !i)
|
|
197
|
+
return;
|
|
198
|
+
const l = await (await b(
|
|
199
|
+
"/v1/payout/beneficiary/form/schema/token/query",
|
|
200
|
+
{
|
|
201
|
+
payment_method: o,
|
|
202
|
+
region: t,
|
|
203
|
+
currency: n,
|
|
204
|
+
local_clearing_system: "",
|
|
205
|
+
version: "v1",
|
|
206
|
+
entity_type: "ENTITY_TYPE_PERSONAL"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
method: "POST",
|
|
210
|
+
authCode: r,
|
|
211
|
+
domain: c,
|
|
212
|
+
codeVerifier: i
|
|
213
|
+
}
|
|
214
|
+
)).json();
|
|
215
|
+
return JSON.parse(
|
|
216
|
+
l.beneficiary_schema.amis_page.replace(/Area Code/g, "AREA_CODE")
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
function ee({
|
|
220
|
+
authCode: t,
|
|
221
|
+
domain: n,
|
|
222
|
+
codeVerifier: o,
|
|
223
|
+
emitter: r,
|
|
224
|
+
defaultValues: c,
|
|
225
|
+
customizations: i,
|
|
226
|
+
locale: p
|
|
227
|
+
}) {
|
|
228
|
+
const { t: f } = q("beneficiaryForm"), [l, k] = y.useState([]), [e, C] = y.useState({
|
|
229
|
+
inputPayoutType: c?.payout_type || "B2P",
|
|
230
|
+
inputPaymentMethod: c?.payment_method,
|
|
231
|
+
inputRegionCode: c?.region_code,
|
|
232
|
+
inputCurrency: c?.currency
|
|
233
|
+
}), [d, g] = y.useState(), [I, F] = y.useState(), w = y.useMemo(() => !i?.layout?.find(
|
|
234
|
+
(a) => a.name === z
|
|
235
|
+
)?.hidden, [i?.layout]), P = y.useCallback(
|
|
236
|
+
(s) => {
|
|
237
|
+
if (!s) return;
|
|
238
|
+
const a = s.body.findIndex(
|
|
239
|
+
(m) => m.type === "form"
|
|
240
|
+
), u = s.body[a];
|
|
241
|
+
s.body[a].onFinished = (m) => {
|
|
242
|
+
const $ = K(u.api.data, m, void 0, !0);
|
|
243
|
+
r.emit("submit", $.value);
|
|
244
|
+
}, F(s);
|
|
245
|
+
},
|
|
246
|
+
[r]
|
|
247
|
+
), x = y.useMemo(() => {
|
|
248
|
+
const s = /* @__PURE__ */ new Set();
|
|
249
|
+
return l.filter(
|
|
250
|
+
(u) => u.country_number && !s.has(u.country_number) && s.add(u.country_number)
|
|
251
|
+
).map((u) => ({
|
|
252
|
+
label: u.country_name_standard || u.country_name,
|
|
253
|
+
value: u.country_code
|
|
254
|
+
})).sort((u, m) => u.label.localeCompare(m.label));
|
|
255
|
+
}, [l]), [v, L] = y.useState();
|
|
256
|
+
y.useEffect(() => {
|
|
257
|
+
if (!e?.inputRegionCode || !e?.inputPayoutType) return;
|
|
258
|
+
const s = e.inputRegionCode;
|
|
259
|
+
Z(s, t, n, o).then(
|
|
260
|
+
(a) => {
|
|
261
|
+
g(a);
|
|
262
|
+
const u = Object.keys(
|
|
263
|
+
a.countries?.[s].payoutTypes?.[e.inputPayoutType]?.currencies
|
|
264
|
+
);
|
|
265
|
+
u && u.length > 0 && L(
|
|
266
|
+
u.map((m) => ({
|
|
267
|
+
label: m,
|
|
268
|
+
value: m
|
|
269
|
+
}))
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
);
|
|
273
|
+
}, [
|
|
274
|
+
t,
|
|
275
|
+
o,
|
|
276
|
+
n,
|
|
277
|
+
e?.inputPayoutType,
|
|
278
|
+
e?.inputRegionCode
|
|
279
|
+
]);
|
|
280
|
+
const E = y.useMemo(() => Array.from(
|
|
281
|
+
new Set(l.map((a) => a.currency_code))
|
|
282
|
+
).map((a) => ({
|
|
283
|
+
label: a,
|
|
284
|
+
value: a
|
|
285
|
+
})).filter((a) => !!a.label && a.label !== "-").sort((a, u) => a.label.localeCompare(u.label)), [l]), T = y.useMemo(() => !e?.inputCurrency || !e?.inputPayoutType || !d ? void 0 : G(
|
|
286
|
+
{
|
|
287
|
+
inputPayoutType: e.inputPayoutType,
|
|
288
|
+
inputCurrency: e.inputCurrency
|
|
289
|
+
},
|
|
290
|
+
d,
|
|
291
|
+
f,
|
|
292
|
+
c
|
|
293
|
+
), [c, e, d, f]), M = y.useMemo(() => {
|
|
294
|
+
if (!(l.length === 0 || !T || !e?.inputPaymentMethod || !e?.inputRegionCode || !e?.inputCurrency))
|
|
295
|
+
return I;
|
|
296
|
+
}, [l, e, I, T]);
|
|
297
|
+
y.useEffect(() => {
|
|
298
|
+
V(
|
|
299
|
+
{
|
|
300
|
+
inputPaymentMethod: e.inputPaymentMethod,
|
|
301
|
+
inputRegionCode: e.inputRegionCode,
|
|
302
|
+
inputCurrency: e.inputCurrency
|
|
303
|
+
},
|
|
304
|
+
t,
|
|
305
|
+
n,
|
|
306
|
+
o
|
|
307
|
+
).then(P);
|
|
308
|
+
}, [
|
|
309
|
+
l,
|
|
310
|
+
T,
|
|
311
|
+
t,
|
|
312
|
+
n,
|
|
313
|
+
o,
|
|
314
|
+
P,
|
|
315
|
+
e.inputCurrency,
|
|
316
|
+
e.inputPaymentMethod,
|
|
317
|
+
e.inputRegionCode
|
|
318
|
+
]);
|
|
319
|
+
const D = y.useMemo(
|
|
320
|
+
() => ({
|
|
321
|
+
type: "page",
|
|
322
|
+
visible: w,
|
|
323
|
+
body: {
|
|
324
|
+
type: "spinner",
|
|
325
|
+
show: l.length === 0,
|
|
326
|
+
overlay: !0,
|
|
327
|
+
body: [
|
|
328
|
+
{
|
|
329
|
+
type: "form",
|
|
330
|
+
title: f("title", "Bank Details"),
|
|
331
|
+
submitText: "",
|
|
332
|
+
onChange: (s) => {
|
|
333
|
+
const a = s.inputRegionCode, u = s.inputRegionCode ? s.inputCurrency : "", m = s.inputRegionCode ? s.inputPaymentMethod : "";
|
|
334
|
+
C({
|
|
335
|
+
inputPayoutType: s.inputPayoutType,
|
|
336
|
+
inputPaymentMethod: m,
|
|
337
|
+
inputRegionCode: a,
|
|
338
|
+
inputCurrency: u
|
|
339
|
+
});
|
|
340
|
+
},
|
|
341
|
+
body: [
|
|
342
|
+
{
|
|
343
|
+
label: f("regionInputLabel", "Bank Location"),
|
|
344
|
+
type: "input-text",
|
|
345
|
+
creatable: !1,
|
|
346
|
+
name: "inputRegionCode",
|
|
347
|
+
options: x,
|
|
348
|
+
value: e?.inputRegionCode
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
label: f("payoutTypeInputLabel", "Bank account type"),
|
|
352
|
+
type: "radios",
|
|
353
|
+
name: "inputPayoutType",
|
|
354
|
+
selectFirst: !0,
|
|
355
|
+
options: [
|
|
356
|
+
{
|
|
357
|
+
label: "Individual",
|
|
358
|
+
value: "B2P"
|
|
359
|
+
}
|
|
360
|
+
],
|
|
361
|
+
value: e?.inputPayoutType
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
label: f("currencyInputLabel", "Account currency"),
|
|
365
|
+
type: "input-text",
|
|
366
|
+
creatable: !1,
|
|
367
|
+
name: "inputCurrency",
|
|
368
|
+
options: e.inputRegionCode ? v || E : [],
|
|
369
|
+
value: e?.inputCurrency
|
|
370
|
+
},
|
|
371
|
+
T
|
|
372
|
+
]
|
|
373
|
+
}
|
|
374
|
+
]
|
|
375
|
+
}
|
|
376
|
+
}),
|
|
377
|
+
[
|
|
378
|
+
l.length,
|
|
379
|
+
e,
|
|
380
|
+
E,
|
|
381
|
+
v,
|
|
382
|
+
x,
|
|
383
|
+
w,
|
|
384
|
+
f,
|
|
385
|
+
T
|
|
386
|
+
]
|
|
387
|
+
);
|
|
388
|
+
return y.useEffect(() => {
|
|
389
|
+
async function s() {
|
|
390
|
+
const a = await X(
|
|
391
|
+
t,
|
|
392
|
+
n,
|
|
393
|
+
o
|
|
394
|
+
);
|
|
395
|
+
k(a);
|
|
396
|
+
}
|
|
397
|
+
s();
|
|
398
|
+
}, [t, o, n]), /* @__PURE__ */ _.jsxs(_.Fragment, { children: [
|
|
399
|
+
/* @__PURE__ */ _.jsx(W, {}),
|
|
400
|
+
O(D, {
|
|
401
|
+
locale: N(p)
|
|
402
|
+
}),
|
|
403
|
+
M && O(M, {
|
|
404
|
+
locale: N(p)
|
|
405
|
+
})
|
|
406
|
+
] });
|
|
407
|
+
}
|
|
408
|
+
function oe(t) {
|
|
409
|
+
const { mi18n: n } = t;
|
|
410
|
+
return /* @__PURE__ */ _.jsx(J, { mi18n: n, fallback: "Loading...", children: /* @__PURE__ */ _.jsx(ee, { ...t }) });
|
|
411
|
+
}
|
|
412
|
+
export {
|
|
413
|
+
oe as default
|
|
414
|
+
};
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@txgw/payout-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -33,11 +33,15 @@
|
|
|
33
33
|
"rollup-plugin-visualizer": "^6.0.5",
|
|
34
34
|
"vite": "^7.2.2",
|
|
35
35
|
"vite-plugin-dts": "^4.5.4",
|
|
36
|
+
"vite-plugin-inspect": "^11.3.3",
|
|
36
37
|
"vite-plugin-strip-comments": "0.0.6"
|
|
37
38
|
},
|
|
38
39
|
"scripts": {
|
|
39
40
|
"dev": "tsc -b && cross-env NODE_ENV=development vite build --watch --mode development",
|
|
41
|
+
"dev:inspect": "tsc -b && cross-env NODE_ENV=development INSPECT=true vite build --watch --mode development",
|
|
40
42
|
"build": "tsc -b && cross-env NODE_ENV=production vite build --mode production",
|
|
41
|
-
"
|
|
43
|
+
"build:inspect": "tsc -b && cross-env NODE_ENV=production INSPECT=true vite build --mode production",
|
|
44
|
+
"lint": "eslint .",
|
|
45
|
+
"inspect": "pnpx serve .vite-inspect"
|
|
42
46
|
}
|
|
43
47
|
}
|
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
import { bX as h, bY as N, ab as p, bZ as L } from "./vendor-DyrjuDU0.js";
|
|
2
|
-
import { t as F, d as $, r as M, T as q } from "./amis-CGgHoXTI.js";
|
|
3
|
-
const D = "bankDetails";
|
|
4
|
-
async function b(t, n, o, c = 1) {
|
|
5
|
-
if (c < 0)
|
|
6
|
-
throw new Error("[payout-sdk] fetchWithAuth retries exceeded");
|
|
7
|
-
const { headers: i, authCode: l, domain: m, codeVerifier: y } = o, u = localStorage.getItem("access_token");
|
|
8
|
-
if (u)
|
|
9
|
-
n.access_token = u;
|
|
10
|
-
else {
|
|
11
|
-
const e = await O(
|
|
12
|
-
l,
|
|
13
|
-
m,
|
|
14
|
-
y
|
|
15
|
-
);
|
|
16
|
-
if (!e.access_token || !e.refresh_token)
|
|
17
|
-
throw localStorage.removeItem("access_token"), localStorage.removeItem("refresh_token"), new Error(
|
|
18
|
-
"[payout-sdk] getAccessToken failed, check authCode validity"
|
|
19
|
-
);
|
|
20
|
-
n.access_token = e.access_token, localStorage.setItem("access_token", e.access_token), localStorage.setItem("refresh_token", e.refresh_token);
|
|
21
|
-
}
|
|
22
|
-
const g = await fetch(t, {
|
|
23
|
-
...o,
|
|
24
|
-
body: JSON.stringify(n),
|
|
25
|
-
headers: {
|
|
26
|
-
...i,
|
|
27
|
-
"Content-Type": "application/json"
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
if (g.status === 400) {
|
|
31
|
-
const e = await g.json();
|
|
32
|
-
if (e.name != "INTERNAL_ERROR")
|
|
33
|
-
throw F.error(`${e.name}: ${e.message}`), new Error(`[payout-sdk] ${e.name}: ${e.message}`);
|
|
34
|
-
const C = localStorage.getItem("refresh_token");
|
|
35
|
-
if (C) {
|
|
36
|
-
const _ = await J(
|
|
37
|
-
C,
|
|
38
|
-
m
|
|
39
|
-
);
|
|
40
|
-
if (!_.access_token || !_.refresh_token)
|
|
41
|
-
localStorage.removeItem("access_token"), localStorage.removeItem("refresh_token");
|
|
42
|
-
else
|
|
43
|
-
return localStorage.setItem(
|
|
44
|
-
"refresh_token",
|
|
45
|
-
_.refresh_token
|
|
46
|
-
), localStorage.setItem("access_token", _.access_token), b(t, n, o, --c);
|
|
47
|
-
}
|
|
48
|
-
const d = await O(
|
|
49
|
-
l,
|
|
50
|
-
m,
|
|
51
|
-
y
|
|
52
|
-
);
|
|
53
|
-
if (!d.access_token || !d.refresh_token)
|
|
54
|
-
throw new Error(
|
|
55
|
-
"[payout-sdk] getAccessToken failed, check authCode validity"
|
|
56
|
-
);
|
|
57
|
-
return localStorage.setItem("refresh_token", d.refresh_token), localStorage.setItem("access_token", d.access_token), b(t, n, o, --c);
|
|
58
|
-
}
|
|
59
|
-
return g;
|
|
60
|
-
}
|
|
61
|
-
async function O(t, n, o) {
|
|
62
|
-
const c = {
|
|
63
|
-
authorization_code: t,
|
|
64
|
-
code_verifier: o
|
|
65
|
-
};
|
|
66
|
-
return await (await fetch(`${n}/v1/payout/auth/token`, {
|
|
67
|
-
method: "POST",
|
|
68
|
-
body: JSON.stringify(c),
|
|
69
|
-
headers: {
|
|
70
|
-
"Content-Type": "application/json"
|
|
71
|
-
}
|
|
72
|
-
})).json();
|
|
73
|
-
}
|
|
74
|
-
async function J(t, n) {
|
|
75
|
-
const o = {
|
|
76
|
-
refresh_token: t
|
|
77
|
-
};
|
|
78
|
-
return await (await fetch(`${n}/v1/payout/auth/token/refresh`, {
|
|
79
|
-
method: "POST",
|
|
80
|
-
body: JSON.stringify(o),
|
|
81
|
-
headers: {
|
|
82
|
-
"Content-Type": "application/json"
|
|
83
|
-
}
|
|
84
|
-
})).json();
|
|
85
|
-
}
|
|
86
|
-
function j(t) {
|
|
87
|
-
return t && t.startsWith("zh") ? "zh_CN" : "en_US";
|
|
88
|
-
}
|
|
89
|
-
async function Y(t, n, o) {
|
|
90
|
-
return (await (await b(
|
|
91
|
-
"/v1/payout/beneficiary/token/countryinfos",
|
|
92
|
-
{},
|
|
93
|
-
{
|
|
94
|
-
method: "POST",
|
|
95
|
-
authCode: t,
|
|
96
|
-
domain: n,
|
|
97
|
-
codeVerifier: o
|
|
98
|
-
}
|
|
99
|
-
)).json()).country_infos || [];
|
|
100
|
-
}
|
|
101
|
-
async function W(t, n, o, c) {
|
|
102
|
-
return await (await b(
|
|
103
|
-
"/v1/payout/beneficiary/token/paymentmethodinfos",
|
|
104
|
-
{
|
|
105
|
-
region_code: t
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
method: "POST",
|
|
109
|
-
authCode: n,
|
|
110
|
-
domain: o,
|
|
111
|
-
codeVerifier: c
|
|
112
|
-
}
|
|
113
|
-
)).json();
|
|
114
|
-
}
|
|
115
|
-
function z({ inputPayoutType: t, inputCurrency: n }, o, c, i) {
|
|
116
|
-
const l = [];
|
|
117
|
-
for (const m of Object.values(o.countries)) {
|
|
118
|
-
const y = m.payoutTypes?.[t]?.currencies;
|
|
119
|
-
if (y)
|
|
120
|
-
for (const [u, g] of Object.entries(y))
|
|
121
|
-
u === n && l.push(g);
|
|
122
|
-
}
|
|
123
|
-
if (l.length !== 0)
|
|
124
|
-
return {
|
|
125
|
-
type: "list-select",
|
|
126
|
-
name: "inputPaymentMethod",
|
|
127
|
-
label: c("paymentMethodInputLabel", "Transfer method"),
|
|
128
|
-
options: l.map((m) => ({
|
|
129
|
-
value: m.payment_method,
|
|
130
|
-
body: /* @__PURE__ */ h.jsxs("div", { children: [
|
|
131
|
-
/* @__PURE__ */ h.jsx("span", { className: "flex font-bold", children: m.display_name }),
|
|
132
|
-
/* @__PURE__ */ h.jsx("span", { className: "flex mt-1", children: m.description })
|
|
133
|
-
] })
|
|
134
|
-
})),
|
|
135
|
-
value: i?.payment_method
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
async function K({
|
|
139
|
-
inputRegionCode: t,
|
|
140
|
-
inputCurrency: n,
|
|
141
|
-
inputPaymentMethod: o
|
|
142
|
-
}, c, i, l) {
|
|
143
|
-
if (!t || !n || !o || !c || !i || !l)
|
|
144
|
-
return;
|
|
145
|
-
const u = await (await b(
|
|
146
|
-
"/v1/payout/beneficiary/form/schema/token/query",
|
|
147
|
-
{
|
|
148
|
-
payment_method: o,
|
|
149
|
-
region: t,
|
|
150
|
-
currency: n,
|
|
151
|
-
local_clearing_system: "",
|
|
152
|
-
version: "v1",
|
|
153
|
-
entity_type: "ENTITY_TYPE_PERSONAL"
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
method: "POST",
|
|
157
|
-
authCode: c,
|
|
158
|
-
domain: i,
|
|
159
|
-
codeVerifier: l
|
|
160
|
-
}
|
|
161
|
-
)).json();
|
|
162
|
-
return JSON.parse(
|
|
163
|
-
u.beneficiary_schema.amis_page.replace(/Area Code/g, "AREA_CODE")
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
function Q({
|
|
167
|
-
authCode: t,
|
|
168
|
-
domain: n,
|
|
169
|
-
codeVerifier: o,
|
|
170
|
-
emitter: c,
|
|
171
|
-
defaultValues: i,
|
|
172
|
-
customizations: l,
|
|
173
|
-
locale: m
|
|
174
|
-
}) {
|
|
175
|
-
const { t: y } = N("beneficiaryForm"), [u, g] = p.useState([]), [e, C] = p.useState({
|
|
176
|
-
inputPayoutType: i?.payout_type || "B2P",
|
|
177
|
-
inputPaymentMethod: i?.payment_method,
|
|
178
|
-
inputRegionCode: i?.region_code,
|
|
179
|
-
inputCurrency: i?.currency
|
|
180
|
-
}), [d, _] = p.useState(), [T, x] = p.useState(), S = p.useMemo(() => !l?.layout?.find(
|
|
181
|
-
(a) => a.name === D
|
|
182
|
-
)?.hidden, [l?.layout]), I = p.useCallback(
|
|
183
|
-
(s) => {
|
|
184
|
-
if (!s) return;
|
|
185
|
-
const a = s.body.findIndex(
|
|
186
|
-
(f) => f.type === "form"
|
|
187
|
-
), r = s.body[a];
|
|
188
|
-
s.body[a].onFinished = (f) => {
|
|
189
|
-
const B = $(r.api.data, f, void 0, !0);
|
|
190
|
-
c.emit("submit", B.value);
|
|
191
|
-
}, x(s);
|
|
192
|
-
},
|
|
193
|
-
[c]
|
|
194
|
-
), P = p.useMemo(() => {
|
|
195
|
-
const s = /* @__PURE__ */ new Set();
|
|
196
|
-
return u.filter(
|
|
197
|
-
(r) => r.country_number && !s.has(r.country_number) && s.add(r.country_number)
|
|
198
|
-
).map((r) => ({
|
|
199
|
-
label: r.country_name_standard || r.country_name,
|
|
200
|
-
value: r.country_code
|
|
201
|
-
})).sort((r, f) => r.label.localeCompare(f.label));
|
|
202
|
-
}, [u]), [R, E] = p.useState();
|
|
203
|
-
p.useEffect(() => {
|
|
204
|
-
if (!e?.inputRegionCode || !e?.inputPayoutType) return;
|
|
205
|
-
const s = e.inputRegionCode;
|
|
206
|
-
W(s, t, n, o).then(
|
|
207
|
-
(a) => {
|
|
208
|
-
_(a);
|
|
209
|
-
const r = Object.keys(
|
|
210
|
-
a.countries?.[s].payoutTypes?.[e.inputPayoutType]?.currencies
|
|
211
|
-
);
|
|
212
|
-
r && r.length > 0 && E(
|
|
213
|
-
r.map((f) => ({
|
|
214
|
-
label: f,
|
|
215
|
-
value: f
|
|
216
|
-
}))
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
);
|
|
220
|
-
}, [
|
|
221
|
-
t,
|
|
222
|
-
o,
|
|
223
|
-
n,
|
|
224
|
-
e?.inputPayoutType,
|
|
225
|
-
e?.inputRegionCode
|
|
226
|
-
]);
|
|
227
|
-
const v = p.useMemo(() => Array.from(
|
|
228
|
-
new Set(u.map((a) => a.currency_code))
|
|
229
|
-
).map((a) => ({
|
|
230
|
-
label: a,
|
|
231
|
-
value: a
|
|
232
|
-
})).filter((a) => !!a.label && a.label !== "-").sort((a, r) => a.label.localeCompare(r.label)), [u]), k = p.useMemo(() => !e?.inputCurrency || !e?.inputPayoutType || !d ? void 0 : z(
|
|
233
|
-
{
|
|
234
|
-
inputPayoutType: e.inputPayoutType,
|
|
235
|
-
inputCurrency: e.inputCurrency
|
|
236
|
-
},
|
|
237
|
-
d,
|
|
238
|
-
y,
|
|
239
|
-
i
|
|
240
|
-
), [i, e, d, y]), w = p.useMemo(() => {
|
|
241
|
-
if (!(u.length === 0 || !k || !e?.inputPaymentMethod || !e?.inputRegionCode || !e?.inputCurrency))
|
|
242
|
-
return T;
|
|
243
|
-
}, [u, e, T, k]);
|
|
244
|
-
p.useEffect(() => {
|
|
245
|
-
K(
|
|
246
|
-
{
|
|
247
|
-
inputPaymentMethod: e.inputPaymentMethod,
|
|
248
|
-
inputRegionCode: e.inputRegionCode,
|
|
249
|
-
inputCurrency: e.inputCurrency
|
|
250
|
-
},
|
|
251
|
-
t,
|
|
252
|
-
n,
|
|
253
|
-
o
|
|
254
|
-
).then(I);
|
|
255
|
-
}, [
|
|
256
|
-
u,
|
|
257
|
-
k,
|
|
258
|
-
t,
|
|
259
|
-
n,
|
|
260
|
-
o,
|
|
261
|
-
I,
|
|
262
|
-
e.inputCurrency,
|
|
263
|
-
e.inputPaymentMethod,
|
|
264
|
-
e.inputRegionCode
|
|
265
|
-
]);
|
|
266
|
-
const A = p.useMemo(
|
|
267
|
-
() => ({
|
|
268
|
-
type: "page",
|
|
269
|
-
visible: S,
|
|
270
|
-
body: {
|
|
271
|
-
type: "spinner",
|
|
272
|
-
show: u.length === 0,
|
|
273
|
-
overlay: !0,
|
|
274
|
-
body: [
|
|
275
|
-
{
|
|
276
|
-
type: "form",
|
|
277
|
-
title: y("title", "Bank Details"),
|
|
278
|
-
submitText: "",
|
|
279
|
-
onChange: (s) => {
|
|
280
|
-
const a = s.inputRegionCode, r = s.inputRegionCode ? s.inputCurrency : "", f = s.inputRegionCode ? s.inputPaymentMethod : "";
|
|
281
|
-
C({
|
|
282
|
-
inputPayoutType: s.inputPayoutType,
|
|
283
|
-
inputPaymentMethod: f,
|
|
284
|
-
inputRegionCode: a,
|
|
285
|
-
inputCurrency: r
|
|
286
|
-
});
|
|
287
|
-
},
|
|
288
|
-
body: [
|
|
289
|
-
{
|
|
290
|
-
label: y("regionInputLabel", "Bank Location"),
|
|
291
|
-
type: "input-text",
|
|
292
|
-
creatable: !1,
|
|
293
|
-
name: "inputRegionCode",
|
|
294
|
-
options: P,
|
|
295
|
-
value: e?.inputRegionCode
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
label: y("payoutTypeInputLabel", "Bank account type"),
|
|
299
|
-
type: "radios",
|
|
300
|
-
name: "inputPayoutType",
|
|
301
|
-
selectFirst: !0,
|
|
302
|
-
options: [
|
|
303
|
-
{
|
|
304
|
-
label: "Individual",
|
|
305
|
-
value: "B2P"
|
|
306
|
-
}
|
|
307
|
-
],
|
|
308
|
-
value: e?.inputPayoutType
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
label: y("currencyInputLabel", "Account currency"),
|
|
312
|
-
type: "input-text",
|
|
313
|
-
creatable: !1,
|
|
314
|
-
name: "inputCurrency",
|
|
315
|
-
options: e.inputRegionCode ? R || v : [],
|
|
316
|
-
value: e?.inputCurrency
|
|
317
|
-
},
|
|
318
|
-
k
|
|
319
|
-
]
|
|
320
|
-
}
|
|
321
|
-
]
|
|
322
|
-
}
|
|
323
|
-
}),
|
|
324
|
-
[
|
|
325
|
-
u.length,
|
|
326
|
-
e,
|
|
327
|
-
v,
|
|
328
|
-
R,
|
|
329
|
-
P,
|
|
330
|
-
S,
|
|
331
|
-
y,
|
|
332
|
-
k
|
|
333
|
-
]
|
|
334
|
-
);
|
|
335
|
-
return p.useEffect(() => {
|
|
336
|
-
async function s() {
|
|
337
|
-
const a = await Y(
|
|
338
|
-
t,
|
|
339
|
-
n,
|
|
340
|
-
o
|
|
341
|
-
);
|
|
342
|
-
g(a);
|
|
343
|
-
}
|
|
344
|
-
s();
|
|
345
|
-
}, [t, o, n]), /* @__PURE__ */ h.jsxs(h.Fragment, { children: [
|
|
346
|
-
/* @__PURE__ */ h.jsx(q, {}),
|
|
347
|
-
M(A, {
|
|
348
|
-
locale: j(m)
|
|
349
|
-
}),
|
|
350
|
-
w && M(w, {
|
|
351
|
-
locale: j(m)
|
|
352
|
-
})
|
|
353
|
-
] });
|
|
354
|
-
}
|
|
355
|
-
function Z(t) {
|
|
356
|
-
const { mi18n: n } = t;
|
|
357
|
-
return /* @__PURE__ */ h.jsx(L, { mi18n: n, fallback: "Loading...", children: /* @__PURE__ */ h.jsx(Q, { ...t }) });
|
|
358
|
-
}
|
|
359
|
-
export {
|
|
360
|
-
Z as default
|
|
361
|
-
};
|