@txgw/payout-components 0.2.0 → 0.2.1

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/index.js CHANGED
@@ -32,7 +32,7 @@ class c {
32
32
  }
33
33
  }
34
34
  const u = {
35
- beneficiaryForm: () => import("./component-beneficiary-form-ZOQLPYQM.js")
35
+ beneficiaryForm: () => import("./component-beneficiary-form-DIpi8Ma-.js")
36
36
  };
37
37
  class h {
38
38
  options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@txgw/payout-components",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -1,344 +0,0 @@
1
- import { bX as g, bY as x, ab as u, bZ as E, b_ as M, b$ as O, c0 as A, c1 as L, c2 as B, c3 as F } from "./vendor-fKhExfo_.js";
2
- import { t as N, d as q, r as w, T as $ } from "./amis-CjYQbrSm.js";
3
- const D = "bankDetails";
4
- async function b(n, e, o, p = 1) {
5
- if (p < 0)
6
- throw new Error("[payout-sdk] fetchWithAuth retries exceeded");
7
- const { headers: a, authCode: h, domain: y, codeVerifier: c } = o, _ = localStorage.getItem("access_token");
8
- if (_)
9
- e.access_token = _;
10
- else {
11
- const s = await R(
12
- h,
13
- y,
14
- c
15
- );
16
- if (!s.access_token || !s.refresh_token)
17
- throw localStorage.removeItem("access_token"), localStorage.removeItem("refresh_token"), new Error(
18
- "[payout-sdk] getAccessToken failed, check authCode validity"
19
- );
20
- e.access_token = s.access_token, localStorage.setItem("access_token", s.access_token), localStorage.setItem("refresh_token", s.refresh_token);
21
- }
22
- const t = await fetch(n, {
23
- ...o,
24
- body: JSON.stringify(e),
25
- headers: {
26
- ...a,
27
- "Content-Type": "application/json"
28
- }
29
- });
30
- if (t.status === 400) {
31
- const s = await t.json();
32
- if (s.name != "INTERNAL_ERROR")
33
- throw N.error(`${s.name}: ${s.message}`), new Error(`[payout-sdk] ${s.name}: ${s.message}`);
34
- const l = localStorage.getItem("refresh_token");
35
- if (l) {
36
- const d = await z(
37
- l,
38
- y
39
- );
40
- if (!d.access_token || !d.refresh_token)
41
- localStorage.removeItem("access_token"), localStorage.removeItem("refresh_token");
42
- else
43
- return localStorage.setItem(
44
- "refresh_token",
45
- d.refresh_token
46
- ), localStorage.setItem("access_token", d.access_token), b(n, e, o, --p);
47
- }
48
- const f = await R(
49
- h,
50
- y,
51
- c
52
- );
53
- if (!f.access_token || !f.refresh_token)
54
- throw new Error(
55
- "[payout-sdk] getAccessToken failed, check authCode validity"
56
- );
57
- return localStorage.setItem("refresh_token", f.refresh_token), localStorage.setItem("access_token", f.access_token), b(n, e, o, --p);
58
- }
59
- return t;
60
- }
61
- async function R(n, e, o) {
62
- const p = {
63
- authorization_code: n,
64
- code_verifier: o
65
- };
66
- return await (await fetch(`${e}/v1/payout/auth/token`, {
67
- method: "POST",
68
- body: JSON.stringify(p),
69
- headers: {
70
- "Content-Type": "application/json"
71
- }
72
- })).json();
73
- }
74
- async function z(n, e) {
75
- const o = {
76
- refresh_token: n
77
- };
78
- return await (await fetch(`${e}/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
- async function J(n, e, o) {
87
- return (await (await b(
88
- "/v1/payout/beneficiary/token/countryinfos",
89
- {},
90
- {
91
- method: "POST",
92
- authCode: n,
93
- domain: e,
94
- codeVerifier: o
95
- }
96
- )).json()).country_infos || [];
97
- }
98
- async function Y({ inputRegionCode: n, inputPayoutType: e, inputCurrency: o }, p, a, h, y, c) {
99
- const t = await (await b(
100
- "/v1/payout/beneficiary/token/paymentmethodinfos",
101
- {
102
- region_code: n
103
- },
104
- {
105
- method: "POST",
106
- authCode: p,
107
- domain: a,
108
- codeVerifier: h
109
- }
110
- )).json(), s = [];
111
- for (const l of Object.values(t.countries)) {
112
- const f = l.payoutTypes?.[e]?.currencies;
113
- if (f)
114
- for (const [d, S] of Object.entries(f))
115
- d === o && s.push(S);
116
- }
117
- if (s.length !== 0)
118
- return {
119
- type: "list-select",
120
- name: "inputPaymentMethod",
121
- label: y("paymentMethodInputLabel", "Transfer method"),
122
- options: s.map((l) => ({
123
- value: l.payment_method,
124
- body: /* @__PURE__ */ g.jsxs("div", { children: [
125
- /* @__PURE__ */ g.jsx("span", { className: "flex font-bold", children: l.display_name }),
126
- /* @__PURE__ */ g.jsx("span", { className: "flex mt-1", children: l.description })
127
- ] })
128
- })),
129
- value: c?.payment_method
130
- };
131
- }
132
- async function K({
133
- inputRegionCode: n,
134
- inputCurrency: e,
135
- inputPaymentMethod: o
136
- }, p, a, h) {
137
- const _ = await (await b(
138
- "/v1/payout/beneficiary/form/schema/token/query",
139
- {
140
- payment_method: o,
141
- region: n,
142
- currency: e,
143
- local_clearing_system: "",
144
- version: "v1",
145
- entity_type: "ENTITY_TYPE_PERSONAL"
146
- },
147
- {
148
- method: "POST",
149
- authCode: p,
150
- domain: a,
151
- codeVerifier: h
152
- }
153
- )).json();
154
- return JSON.parse(
155
- _.beneficiary_schema.amis_page.replace(/Area Code/g, "AREA_CODE")
156
- );
157
- }
158
- function W({
159
- authCode: n,
160
- domain: e,
161
- codeVerifier: o,
162
- emitter: p,
163
- defaultValues: a,
164
- customizations: h
165
- }) {
166
- const { t: y } = x("beneficiaryForm"), [c, _] = u.useState([]), [t, s] = u.useState(), [l, f] = u.useState(), [d, S] = u.useState(), C = u.useMemo(() => !h?.layout?.find(
167
- (r) => r.name === D
168
- )?.hidden, [h?.layout]), T = u.useCallback(
169
- (i) => {
170
- const r = i.body.findIndex(
171
- (k) => k.type === "form"
172
- ), m = i.body[r];
173
- i.body[r].onFinished = (k) => {
174
- const j = q(m.api.data, k, void 0, !0);
175
- p.emit("submit", j.value);
176
- }, S(i);
177
- },
178
- [p]
179
- ), v = u.useMemo(() => {
180
- const i = /* @__PURE__ */ new Set();
181
- return c.filter(
182
- (m) => m.country_number && !i.has(m.country_number) && i.add(m.country_number)
183
- ).map((m) => ({
184
- label: m.country_name_standard || m.country_name,
185
- value: m.country_code
186
- })).sort((m, k) => m.label.localeCompare(k.label));
187
- }, [c]), I = u.useMemo(() => Array.from(
188
- new Set(c.map((r) => r.currency_code))
189
- ).map((r) => ({
190
- label: r,
191
- value: r
192
- })).filter((r) => !!r.label && r.label !== "-").sort((r, m) => r.label.localeCompare(m.label)), [c]);
193
- u.useEffect(() => {
194
- c.length !== 0 && t?.inputRegionCode && t?.inputCurrency && t?.inputPayoutType && Y(
195
- {
196
- inputRegionCode: t.inputRegionCode,
197
- inputCurrency: t.inputCurrency,
198
- inputPayoutType: t.inputPayoutType
199
- },
200
- n,
201
- e,
202
- o,
203
- y,
204
- a
205
- ).then(f);
206
- }, [
207
- c,
208
- n,
209
- e,
210
- t?.inputRegionCode,
211
- t?.inputCurrency,
212
- t?.inputPayoutType,
213
- a,
214
- o,
215
- y
216
- ]), u.useEffect(() => {
217
- c.length !== 0 && l && t?.inputPaymentMethod && t?.inputRegionCode && t?.inputCurrency && K(
218
- {
219
- inputPaymentMethod: t.inputPaymentMethod,
220
- inputRegionCode: t.inputRegionCode,
221
- inputCurrency: t.inputCurrency
222
- },
223
- n,
224
- e,
225
- o
226
- ).then((i) => i && T(i));
227
- }, [
228
- c,
229
- l,
230
- n,
231
- e,
232
- o,
233
- t?.inputPaymentMethod,
234
- t?.inputRegionCode,
235
- t?.inputCurrency,
236
- T
237
- ]), u.useEffect(() => {
238
- t?.inputCurrency || f(void 0);
239
- }, [t?.inputCurrency]), u.useEffect(() => {
240
- a && s({
241
- inputPayoutType: a.payout_type || "B2P",
242
- inputPaymentMethod: a.payment_method,
243
- inputRegionCode: a.region_code,
244
- inputCurrency: a.currency
245
- });
246
- }, [a]);
247
- const P = u.useMemo(
248
- () => ({
249
- type: "page",
250
- visible: C,
251
- body: {
252
- type: "spinner",
253
- show: c.length === 0,
254
- overlay: !0,
255
- body: [
256
- {
257
- type: "form",
258
- title: y("title", "Bank Details"),
259
- submitText: "",
260
- onChange: (i) => {
261
- s(i);
262
- },
263
- body: [
264
- {
265
- label: y("regionInputLabel", "Bank Location"),
266
- type: "input-text",
267
- creatable: !1,
268
- name: "inputRegionCode",
269
- options: v,
270
- value: a?.region_code
271
- },
272
- {
273
- label: y("payoutTypeInputLabel", "Bank account type"),
274
- type: "radios",
275
- name: "inputPayoutType",
276
- selectFirst: !0,
277
- options: [
278
- {
279
- label: "Individual",
280
- value: "B2P"
281
- }
282
- ],
283
- value: a?.payout_type
284
- },
285
- {
286
- label: y("currencyInputLabel", "Account currency"),
287
- type: "input-text",
288
- creatable: !1,
289
- name: "inputCurrency",
290
- options: I,
291
- value: a?.currency
292
- },
293
- l
294
- ]
295
- }
296
- ]
297
- }
298
- }),
299
- [
300
- C,
301
- c.length,
302
- y,
303
- v,
304
- a?.region_code,
305
- a?.payout_type,
306
- a?.currency,
307
- I,
308
- l
309
- ]
310
- );
311
- return u.useEffect(() => {
312
- async function i() {
313
- const r = await J(
314
- n,
315
- e,
316
- o
317
- );
318
- _(r);
319
- }
320
- i();
321
- }, [n, o, e]), /* @__PURE__ */ g.jsxs(g.Fragment, { children: [
322
- /* @__PURE__ */ g.jsx($, {}),
323
- w(P),
324
- d && w(d)
325
- ] });
326
- }
327
- function X(n) {
328
- const { locale: e = "en" } = n, o = u.useMemo(
329
- () => E().use(M()).use(O()).use(A()).use(L()).init({
330
- language: B() || e,
331
- defaultLanguage: e,
332
- fallbackLanguage: "en",
333
- availableLanguages: ["en", "zh-Hant", "ar", "ja", "th", "tr", "zh"],
334
- apiUrl: "https://admin.midasbuy.com/i18n/api",
335
- apiKey: "tgpak_gm2tqxzygnpvsokipayuqz2yhb4hszcvkzsq",
336
- projectId: 181
337
- }),
338
- [e]
339
- );
340
- return /* @__PURE__ */ g.jsx(F, { mi18n: o, fallback: "Loading...", children: /* @__PURE__ */ g.jsx(W, { ...n }) });
341
- }
342
- export {
343
- X as default
344
- };