@opexa/portal-components 0.0.806 → 0.0.808
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/components/DepositWithdrawal/DepositWithdrawal.lazy.js +4 -1
- package/dist/components/DepositWithdrawal/Deposit__next/AiOGCashDeposit/AiOGCashDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/AiOGCashDeposit/AiOGCashDeposit.js +217 -0
- package/dist/components/DepositWithdrawal/Deposit__next/AiOGrabPayDeposit/AiOGrabPayDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/AiOGrabPayDeposit/AiOGrabPayDeposit.js +215 -0
- package/dist/components/DepositWithdrawal/Deposit__next/AiOPalawanPayDeposit/AiOPalawanPayDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/AiOPalawanPayDeposit/AiOPalawanPayDeposit.js +215 -0
- package/dist/components/DepositWithdrawal/Deposit__next/AiOPayMayaDeposit/AiOPayMayaDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/AiOPayMayaDeposit/AiOPayMayaDeposit.js +215 -0
- package/dist/components/DepositWithdrawal/Deposit__next/AvailablePromos.d.ts +8 -0
- package/dist/components/DepositWithdrawal/Deposit__next/AvailablePromos.js +33 -0
- package/dist/components/DepositWithdrawal/Deposit__next/Deposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/Deposit.js +120 -0
- package/dist/components/DepositWithdrawal/Deposit__next/GCashDeposit/GCashDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/GCashDeposit/GCashDeposit.js +208 -0
- package/dist/components/DepositWithdrawal/Deposit__next/GCashWebpayDeposit/GCashWebpayDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/GCashWebpayDeposit/GCashWebpayDeposit.js +210 -0
- package/dist/components/DepositWithdrawal/Deposit__next/LibanganDeposit/LibanganDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/LibanganDeposit/LibanganDeposit.js +210 -0
- package/dist/components/DepositWithdrawal/Deposit__next/MayaAppDeposit/MayaAppDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/MayaAppDeposit/MayaAppDeposit.js +157 -0
- package/dist/components/DepositWithdrawal/Deposit__next/MayaDeposit/MayaDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/MayaDeposit/MayaDeposit.js +208 -0
- package/dist/components/DepositWithdrawal/Deposit__next/MayaWebpayDeposit/MayaWebpayDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/MayaWebpayDeposit/MayaWebpayDeposit.js +211 -0
- package/dist/components/DepositWithdrawal/Deposit__next/OnlineBankDeposit/OnlineBankDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/OnlineBankDeposit/OnlineBankDeposit.js +10 -0
- package/dist/components/DepositWithdrawal/Deposit__next/OnlineBankDeposit/OnlineBankDepositAlert.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/OnlineBankDeposit/OnlineBankDepositAlert.js +99 -0
- package/dist/components/DepositWithdrawal/Deposit__next/OnlineBankDeposit/OnlineBankDepositContext.d.ts +25 -0
- package/dist/components/DepositWithdrawal/Deposit__next/OnlineBankDeposit/OnlineBankDepositContext.js +2 -0
- package/dist/components/DepositWithdrawal/Deposit__next/OnlineBankDeposit/OnlineBankDepositDetails.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/OnlineBankDeposit/OnlineBankDepositDetails.js +19 -0
- package/dist/components/DepositWithdrawal/Deposit__next/OnlineBankDeposit/OnlineBankDepositForm.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/OnlineBankDeposit/OnlineBankDepositForm.js +115 -0
- package/dist/components/DepositWithdrawal/Deposit__next/OnlineBankDeposit/useOnlineBankDeposit.d.ts +13 -0
- package/dist/components/DepositWithdrawal/Deposit__next/OnlineBankDeposit/useOnlineBankDeposit.js +81 -0
- package/dist/components/DepositWithdrawal/Deposit__next/PisoPayDeposit/PisoPayDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/PisoPayDeposit/PisoPayDeposit.js +224 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/QRPHDeposit.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/QRPHDeposit.js +10 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/QRPHDepositAlert.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/QRPHDepositAlert.js +99 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/QRPHDepositContext.d.ts +25 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/QRPHDepositContext.js +2 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/QRPHDepositDetails.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/QRPHDepositDetails.js +17 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/QRPHDepositForm.d.ts +1 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/QRPHDepositForm.js +116 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/QRPHQRCode.d.ts +3 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/QRPHQRCode.js +69 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/useQRPHDeposit.d.ts +13 -0
- package/dist/components/DepositWithdrawal/Deposit__next/QRPHDeposit/useQRPHDeposit.js +85 -0
- package/dist/components/Disclaimer/DisclaimerV2.js +1 -1
- package/dist/styles/theme.css +4 -1
- package/package.json +1 -1
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
3
|
+
import Link from 'next/link';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
6
|
+
import invariant from 'tiny-invariant';
|
|
7
|
+
import { useBoolean } from 'usehooks-ts';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { useShallow } from 'zustand/shallow';
|
|
10
|
+
import { useAvailablePromosQuery } from '../../../../client/hooks/useAvailablePromosQuery.js';
|
|
11
|
+
import { useCreateLibanganDepositMutation } from '../../../../client/hooks/useCreateLibanganDepositMutation.js';
|
|
12
|
+
import { useDepositQuery } from '../../../../client/hooks/useDepositQuery.js';
|
|
13
|
+
import { useDepositsCountQuery } from '../../../../client/hooks/useDepositsCountQuery.js';
|
|
14
|
+
import { useDisclosure } from '../../../../client/hooks/useDisclosure.js';
|
|
15
|
+
import { useGlobalStore } from '../../../../client/hooks/useGlobalStore.js';
|
|
16
|
+
import { useMemberVerificationQuery } from '../../../../client/hooks/useMemberVerificationQuery.js';
|
|
17
|
+
import { usePaymentSettingsQuery } from '../../../../client/hooks/usePaymentSettingsQuery.js';
|
|
18
|
+
import { AlertCircleIcon } from '../../../../icons/AlertCircleIcon.js';
|
|
19
|
+
import { ChevronDownIcon } from '../../../../icons/ChevronDownIcon.js';
|
|
20
|
+
import { ChevronUpIcon } from '../../../../icons/ChevronUpIcon.js';
|
|
21
|
+
import { RefreshCcw01Icon } from '../../../../icons/RefreshCcw01Icon.js';
|
|
22
|
+
import { SpinnerIcon } from '../../../../icons/SpinnerIcon.js';
|
|
23
|
+
import { XIcon } from '../../../../icons/XIcon.js';
|
|
24
|
+
import { AlertDialog } from '../../../../ui/AlertDialog/index.js';
|
|
25
|
+
import { Button } from '../../../../ui/Button/index.js';
|
|
26
|
+
import { Field } from '../../../../ui/Field/index.js';
|
|
27
|
+
import { NumberInput } from '../../../../ui/NumberInput/index.js';
|
|
28
|
+
import { Portal } from '../../../../ui/Portal/index.js';
|
|
29
|
+
import { parseDecimal } from '../../../../utils/parseDecimal.js';
|
|
30
|
+
import { AmountChoices } from '../../AmountChoices.js';
|
|
31
|
+
import { useDepositWithdrawalPropsContext } from '../../DepositWithdrawalContext.js';
|
|
32
|
+
import { AvailablePromos } from '../AvailablePromos.js';
|
|
33
|
+
export function LibanganDeposit() {
|
|
34
|
+
const depositWithdrawalProps = useDepositWithdrawalPropsContext();
|
|
35
|
+
const disclosure = useDisclosure({
|
|
36
|
+
onOpenChange(open) {
|
|
37
|
+
if (!open) {
|
|
38
|
+
form.reset();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const globalStore = useGlobalStore(useShallow((ctx) => ({
|
|
43
|
+
depositWithdrawal: ctx.depositWithdrawal,
|
|
44
|
+
kycVerificationStatus: ctx.kycVerificationStatus,
|
|
45
|
+
})));
|
|
46
|
+
const verificationQuery = useMemberVerificationQuery();
|
|
47
|
+
const verificationStatus = verificationQuery.data?.status ?? 'UNVERIFIED';
|
|
48
|
+
const [status, setStatus] = useState('waiting');
|
|
49
|
+
const createDepositMutation = useCreateLibanganDepositMutation({
|
|
50
|
+
onMutate() {
|
|
51
|
+
disclosure.setOpen(true);
|
|
52
|
+
setStatus('processing');
|
|
53
|
+
},
|
|
54
|
+
onSuccess(data) {
|
|
55
|
+
invariant(data.checkoutUrl);
|
|
56
|
+
window.open(data.checkoutUrl, '_blank', 'noopener,noreferrer');
|
|
57
|
+
setStatus('success');
|
|
58
|
+
},
|
|
59
|
+
onError() {
|
|
60
|
+
setStatus('failed');
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
const warn = useBoolean();
|
|
64
|
+
const depositQuery = useDepositQuery(createDepositMutation.data?.id, {
|
|
65
|
+
enabled: !warn.value && status === 'success',
|
|
66
|
+
refetchInterval: (ctx) => ctx.state.data?.status === 'CONFIRMED' ||
|
|
67
|
+
ctx.state.data?.status === 'REJECTED' ||
|
|
68
|
+
ctx.state.data?.status === 'CANCELLED'
|
|
69
|
+
? false
|
|
70
|
+
: 1000,
|
|
71
|
+
});
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (depositQuery.data?.status === 'CONFIRMED') {
|
|
74
|
+
setStatus('confirmed');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (depositQuery.data?.status === 'REJECTED' ||
|
|
78
|
+
depositQuery.data?.status === 'CANCELLED') {
|
|
79
|
+
setStatus('failed');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}, [depositQuery.data?.status]);
|
|
83
|
+
const depositsCountQuery = useDepositsCountQuery();
|
|
84
|
+
const depositsCount = depositsCountQuery.data ?? 0;
|
|
85
|
+
const paymentSettingsQuery = usePaymentSettingsQuery();
|
|
86
|
+
const paymentSettings = paymentSettingsQuery.data;
|
|
87
|
+
const gatewaySettings = paymentSettings?.libanganDepositGatewaySettings;
|
|
88
|
+
const maximumAmount = parseDecimal(gatewaySettings?.maximumAmount, 0);
|
|
89
|
+
const minimumAmount = depositsCount <= 0
|
|
90
|
+
? parseDecimal(paymentSettingsQuery.data?.minimumFirstDepositAmount, 0)
|
|
91
|
+
: parseDecimal(gatewaySettings?.minimumAmount, 0);
|
|
92
|
+
const promosQuery = useAvailablePromosQuery();
|
|
93
|
+
const promos = promosQuery.data ?? [];
|
|
94
|
+
const definition = z
|
|
95
|
+
.object({
|
|
96
|
+
amount: z.string().superRefine((val, ctx) => {
|
|
97
|
+
const n = parseDecimal(val, 0);
|
|
98
|
+
if (n < minimumAmount) {
|
|
99
|
+
ctx.addIssue({
|
|
100
|
+
type: 'number',
|
|
101
|
+
code: z.ZodIssueCode.too_small,
|
|
102
|
+
inclusive: true,
|
|
103
|
+
minimum: minimumAmount,
|
|
104
|
+
message: `Minimum amount is ${minimumAmount.toLocaleString()}`,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (n > maximumAmount) {
|
|
108
|
+
ctx.addIssue({
|
|
109
|
+
type: 'number',
|
|
110
|
+
code: z.ZodIssueCode.too_big,
|
|
111
|
+
inclusive: true,
|
|
112
|
+
maximum: maximumAmount,
|
|
113
|
+
message: `Maximum amount is ${maximumAmount.toLocaleString()}`,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}),
|
|
117
|
+
promo: z.string().optional().nullable(),
|
|
118
|
+
})
|
|
119
|
+
.superRefine((value, ctx) => {
|
|
120
|
+
const promo = promos.find((o) => o.id === value.promo);
|
|
121
|
+
const promoMinAmount = parseDecimal(promo?.minimumDepositAmount, 0);
|
|
122
|
+
const promoMaxAmount = parseDecimal(promo?.maximumDepositAmount, 0);
|
|
123
|
+
const amount = parseDecimal(value.amount, 0);
|
|
124
|
+
if (promo && amount < promoMinAmount) {
|
|
125
|
+
ctx.addIssue({
|
|
126
|
+
path: ['amount'],
|
|
127
|
+
code: z.ZodIssueCode.custom,
|
|
128
|
+
message: `Minimum amount for this promo is ${promoMinAmount.toLocaleString()}`,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (promo && amount > promoMaxAmount) {
|
|
132
|
+
ctx.addIssue({
|
|
133
|
+
path: ['amount'],
|
|
134
|
+
code: z.ZodIssueCode.custom,
|
|
135
|
+
message: `Maximum amount for this promo is ${promoMaxAmount}`,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
const form = useForm({
|
|
140
|
+
mode: 'all',
|
|
141
|
+
resolver: zodResolver(definition),
|
|
142
|
+
defaultValues: {
|
|
143
|
+
amount: '0',
|
|
144
|
+
promo: globalStore.depositWithdrawal.promo ?? null,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (minimumAmount) {
|
|
149
|
+
form.reset({
|
|
150
|
+
amount: minimumAmount.toString(),
|
|
151
|
+
promo: form.getValues('promo') ?? null,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}, [form, minimumAmount]);
|
|
155
|
+
return (_jsxs("form", { onSubmit: form.handleSubmit(async (data) => {
|
|
156
|
+
//handle new kyc process
|
|
157
|
+
if (verificationStatus === 'PENDING' ||
|
|
158
|
+
verificationStatus === 'UNVERIFIED' ||
|
|
159
|
+
verificationStatus === 'REJECTED' ||
|
|
160
|
+
verificationStatus === 'CREATED') {
|
|
161
|
+
globalStore.kycVerificationStatus.setOpen(true);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
createDepositMutation.reset();
|
|
166
|
+
createDepositMutation.mutate({
|
|
167
|
+
amount: data.amount.toString(),
|
|
168
|
+
promo: data.promo ?? undefined,
|
|
169
|
+
redirectUrl: depositWithdrawalProps.libanganRedirectionUrl,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}), noValidate: true, children: [_jsx(Controller, { control: form.control, name: "amount", render: (o) => (_jsxs(Field.Root, { invalid: !!form.formState.errors.amount, children: [_jsxs(NumberInput.Root, { min: 0, step: 1, value: o.field.value, onValueChange: (details) => {
|
|
173
|
+
o.field.onChange(details.value);
|
|
174
|
+
}, allowMouseWheel: true, children: [_jsx(NumberInput.Label, { children: "Enter amount you want to deposit" }), _jsxs(NumberInput.Control, { children: [_jsx(NumberInput.Input, {}), _jsx(NumberInput.IncrementTrigger, { children: _jsx(ChevronUpIcon, {}) }), _jsx(NumberInput.DecrementTrigger, { children: _jsx(ChevronDownIcon, {}) })] })] }), _jsx(Field.ErrorText, { children: form.formState.errors.amount?.message })] })) }), _jsx(AmountChoices, { value: parseDecimal(form.watch('amount'), 0), onChange: (value) => {
|
|
175
|
+
form.setValue('amount', value.toString(), {
|
|
176
|
+
shouldTouch: true,
|
|
177
|
+
shouldDirty: true,
|
|
178
|
+
shouldValidate: true,
|
|
179
|
+
});
|
|
180
|
+
}, min: minimumAmount, max: maximumAmount, className: "mt-lg" }), _jsx(Controller, { control: form.control, name: "promo", render: (o) => (_jsx(AvailablePromos, { value: o.field.value, onChange: (value) => {
|
|
181
|
+
o.field.onChange(value);
|
|
182
|
+
globalStore.depositWithdrawal.setPromo(null);
|
|
183
|
+
}, className: "mt-3xl" })) }), _jsx(Button, { type: "submit", className: "mt-3xl", disabled: createDepositMutation.isPending, children: "Deposit" }), depositWithdrawalProps.hasPrivacyPolicyAndTermsOfUse && (_jsxs("p", { className: "mt-lg text-text-tertiary-600 text-xs", children: ["By depositing, you agree to our", ' ', _jsx(Link, { href: depositWithdrawalProps.termsOfUseUrl ?? '/terms-of-use', onClick: () => globalStore.depositWithdrawal.setOpen(false), className: "text-text-warning-primary-600 underline underline-offset-2", children: "Terms of Use" }), ' ', "and", ' ', _jsx(Link, { href: depositWithdrawalProps.privacyPolicyUrl ?? '/privacy-policy', onClick: () => globalStore.depositWithdrawal.setOpen(false), className: "text-text-warning-primary-600 underline underline-offset-2", children: "Privacy Policy" }), "."] })), _jsx(AlertDialog.Root, { open: disclosure.open, onOpenChange: (details) => {
|
|
184
|
+
disclosure.setOpen(details.open);
|
|
185
|
+
}, lazyMount: true, unmountOnExit: true, closeOnEscape: false, closeOnInteractOutside: false, onExitComplete: () => {
|
|
186
|
+
setStatus('waiting');
|
|
187
|
+
form.reset();
|
|
188
|
+
warn.setFalse();
|
|
189
|
+
}, children: _jsxs(Portal, { children: [_jsx(AlertDialog.Backdrop, { className: "!z-[calc(var(--z-dialog)+2)]" }), _jsx(AlertDialog.Positioner, { className: "!z-[calc(var(--z-dialog)+3)]", children: _jsxs(AlertDialog.Content, { children: [_jsx(AlertDialog.Context, { children: (api) => (_jsx("button", { type: "button", className: "absolute top-2.5 right-2.5 flex icon:size-6 size-11 items-center justify-center text-text-quinary", onClick: () => {
|
|
190
|
+
if (status === 'success' && !warn.value) {
|
|
191
|
+
warn.setTrue();
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
api.setOpen(false);
|
|
195
|
+
}
|
|
196
|
+
}, children: _jsx(XIcon, {}) })) }), _jsxs(AlertDialog.Header, { children: [status === 'processing' && (_jsx(SpinnerIcon, { className: "size-12 text-text-brand-primary-600" })), status === 'success' && !warn.value && (_jsx("div", { className: "flex size-12 items-center justify-center rounded-full bg-bg-brand-secondary text-text-featured-icon-light-brand", children: _jsx(RefreshCcw01Icon, {}) })), status === 'success' && warn.value && (_jsx("div", { className: "flex size-12 items-center justify-center rounded-full bg-bg-error-secondary text-text-featured-icon-light-error", children: _jsx(AlertCircleIcon, {}) })), status === 'confirmed' && (_jsx("div", { className: "flex size-12 items-center justify-center rounded-full bg-bg-success-secondary text-text-featured-icon-light-success", children: _jsx(AlertCircleIcon, {}) })), status === 'failed' && (_jsx("div", { className: "flex size-12 items-center justify-center rounded-full bg-bg-error-secondary text-text-featured-icon-light-error", children: _jsx(AlertCircleIcon, {}) }))] }), _jsxs(AlertDialog.Body, { children: [_jsxs(AlertDialog.Title, { children: [status === 'processing' && 'Processing Deposit', status === 'success' &&
|
|
197
|
+
!warn.value &&
|
|
198
|
+
'Didn’t see the payment window?', status === 'success' && warn.value && (_jsx(_Fragment, { children: "Are you sure you want to close this\u00A0window?" })), status === 'confirmed' && 'Deposit Successful', status === 'failed' && 'Deposit Failed'] }), _jsxs(AlertDialog.Description, { children: [status === 'processing' &&
|
|
199
|
+
"We're verifying your account and amount. Please hold a moment.", status === 'success' &&
|
|
200
|
+
!warn.value &&
|
|
201
|
+
'Sometimes the payment pop up doesn’t appear right away. Don’t worry, just click the button below to reopen it and continue your deposit.', status === 'success' &&
|
|
202
|
+
warn.value &&
|
|
203
|
+
'Closing this window might cancel your current deposit. Do you want to continue?', status === 'confirmed' &&
|
|
204
|
+
'Your deposit has been successfully processed.', status === 'failed' &&
|
|
205
|
+
'Something went wrong while processing your deposit. Please try again or contact support.'] })] }), (status === 'failed' ||
|
|
206
|
+
status === 'success' ||
|
|
207
|
+
status === 'confirmed') && (_jsxs(AlertDialog.Footer, { children: [status === 'success' && !warn.value && (_jsx(Button, { asChild: true, children: _jsx("a", { href: createDepositMutation.data?.checkoutUrl ?? '', target: "_blank", rel: "noopener noreferrer", children: "Try Again" }) })), status === 'success' && warn.value && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "outline", onClick: () => {
|
|
208
|
+
warn.setFalse();
|
|
209
|
+
}, children: "Go back" }), _jsx(AlertDialog.Context, { children: (api) => (_jsx(Button, { onClick: () => api.setOpen(false), children: "Continue" })) })] })), status !== 'success' && (_jsx(AlertDialog.Context, { children: (api) => (_jsx(Button, { onClick: () => api.setOpen(false), children: "Ok" })) }))] }))] }) })] }) })] }));
|
|
210
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function MayaAppDeposit(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
3
|
+
import Link from 'next/link';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { useShallow } from 'zustand/shallow';
|
|
8
|
+
import { useAvailablePromosQuery } from '../../../../client/hooks/useAvailablePromosQuery.js';
|
|
9
|
+
import { useCreateMayaAppDepositMutation } from '../../../../client/hooks/useCreateMayaAppDepositMutation.js';
|
|
10
|
+
import { useDepositsCountQuery } from '../../../../client/hooks/useDepositsCountQuery.js';
|
|
11
|
+
import { useGlobalStore } from '../../../../client/hooks/useGlobalStore.js';
|
|
12
|
+
import { useMemberVerificationQuery } from '../../../../client/hooks/useMemberVerificationQuery.js';
|
|
13
|
+
import { usePaymentSettingsQuery } from '../../../../client/hooks/usePaymentSettingsQuery.js';
|
|
14
|
+
import { AlertCircleIcon } from '../../../../icons/AlertCircleIcon.js';
|
|
15
|
+
import { ChevronDownIcon } from '../../../../icons/ChevronDownIcon.js';
|
|
16
|
+
import { ChevronUpIcon } from '../../../../icons/ChevronUpIcon.js';
|
|
17
|
+
import { SpinnerIcon } from '../../../../icons/SpinnerIcon.js';
|
|
18
|
+
import { XIcon } from '../../../../icons/XIcon.js';
|
|
19
|
+
import { AlertDialog } from '../../../../ui/AlertDialog/index.js';
|
|
20
|
+
import { Button } from '../../../../ui/Button/index.js';
|
|
21
|
+
import { Field } from '../../../../ui/Field/index.js';
|
|
22
|
+
import { NumberInput } from '../../../../ui/NumberInput/index.js';
|
|
23
|
+
import { Portal } from '../../../../ui/Portal/index.js';
|
|
24
|
+
import { parseDecimal } from '../../../../utils/parseDecimal.js';
|
|
25
|
+
import { AmountChoices } from '../../AmountChoices.js';
|
|
26
|
+
import { useDepositWithdrawalPropsContext } from '../../DepositWithdrawalContext.js';
|
|
27
|
+
import { AvailablePromos } from '../AvailablePromos.js';
|
|
28
|
+
export function MayaAppDeposit() {
|
|
29
|
+
const depositWithdrawalProps = useDepositWithdrawalPropsContext();
|
|
30
|
+
const globalStore = useGlobalStore(useShallow((ctx) => ({
|
|
31
|
+
depositWithdrawal: ctx.depositWithdrawal,
|
|
32
|
+
kycVerificationStatus: ctx.kycVerificationStatus,
|
|
33
|
+
})));
|
|
34
|
+
const verificationQuery = useMemberVerificationQuery();
|
|
35
|
+
const verificationStatus = verificationQuery.data?.status ?? 'UNVERIFIED';
|
|
36
|
+
const [status, setStatus] = useState('waiting');
|
|
37
|
+
const createDepositMutation = useCreateMayaAppDepositMutation({
|
|
38
|
+
onMutate() {
|
|
39
|
+
setStatus('processing');
|
|
40
|
+
},
|
|
41
|
+
onSuccess() {
|
|
42
|
+
setStatus('success');
|
|
43
|
+
form.reset();
|
|
44
|
+
},
|
|
45
|
+
onError() {
|
|
46
|
+
setStatus('failed');
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
const depositsCountQuery = useDepositsCountQuery();
|
|
50
|
+
const depositsCount = depositsCountQuery.data ?? 0;
|
|
51
|
+
const paymentSettingsQuery = usePaymentSettingsQuery();
|
|
52
|
+
const paymentSettings = paymentSettingsQuery.data;
|
|
53
|
+
const gatewaySettings = paymentSettings?.mayaAppDepositGatewaySettings;
|
|
54
|
+
const maximumAmount = parseDecimal(gatewaySettings?.maximumAmount, 0);
|
|
55
|
+
const minimumAmount = depositsCount <= 0
|
|
56
|
+
? parseDecimal(paymentSettingsQuery.data?.minimumFirstDepositAmount, 0)
|
|
57
|
+
: parseDecimal(gatewaySettings?.minimumAmount, 0);
|
|
58
|
+
const promosQuery = useAvailablePromosQuery();
|
|
59
|
+
const promos = promosQuery.data ?? [];
|
|
60
|
+
const definition = z
|
|
61
|
+
.object({
|
|
62
|
+
amount: z.string().superRefine((val, ctx) => {
|
|
63
|
+
const n = parseDecimal(val, 0);
|
|
64
|
+
if (n < minimumAmount) {
|
|
65
|
+
ctx.addIssue({
|
|
66
|
+
type: 'number',
|
|
67
|
+
code: z.ZodIssueCode.too_small,
|
|
68
|
+
inclusive: true,
|
|
69
|
+
minimum: minimumAmount,
|
|
70
|
+
message: `Minimum amount is ${minimumAmount.toLocaleString()}`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (n > maximumAmount) {
|
|
74
|
+
ctx.addIssue({
|
|
75
|
+
type: 'number',
|
|
76
|
+
code: z.ZodIssueCode.too_big,
|
|
77
|
+
inclusive: true,
|
|
78
|
+
maximum: maximumAmount,
|
|
79
|
+
message: `Maximum amount is ${maximumAmount.toLocaleString()}`,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}),
|
|
83
|
+
promo: z.string().optional().nullable(),
|
|
84
|
+
})
|
|
85
|
+
.superRefine((value, ctx) => {
|
|
86
|
+
const promo = promos.find((o) => o.id === value.promo);
|
|
87
|
+
const promoMinAmount = parseDecimal(promo?.minimumDepositAmount, 0);
|
|
88
|
+
const promoMaxAmount = parseDecimal(promo?.maximumDepositAmount, 0);
|
|
89
|
+
const amount = parseDecimal(value.amount, 0);
|
|
90
|
+
if (promo && amount < promoMinAmount) {
|
|
91
|
+
ctx.addIssue({
|
|
92
|
+
path: ['amount'],
|
|
93
|
+
code: z.ZodIssueCode.custom,
|
|
94
|
+
message: `Minimum amount for this promo is ${promoMinAmount.toLocaleString()}`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (promo && amount > promoMaxAmount) {
|
|
98
|
+
ctx.addIssue({
|
|
99
|
+
path: ['amount'],
|
|
100
|
+
code: z.ZodIssueCode.custom,
|
|
101
|
+
message: `Maximum amount for this promo is ${promoMaxAmount}`,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const form = useForm({
|
|
106
|
+
mode: 'all',
|
|
107
|
+
resolver: zodResolver(definition),
|
|
108
|
+
defaultValues: {
|
|
109
|
+
amount: '0',
|
|
110
|
+
promo: globalStore.depositWithdrawal.promo ?? null,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (minimumAmount) {
|
|
115
|
+
form.reset({
|
|
116
|
+
amount: minimumAmount.toString(),
|
|
117
|
+
promo: form.getValues('promo') ?? null,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}, [form, minimumAmount]);
|
|
121
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
122
|
+
//handle new kyc process
|
|
123
|
+
if (verificationStatus === 'PENDING' ||
|
|
124
|
+
verificationStatus === 'UNVERIFIED' ||
|
|
125
|
+
verificationStatus === 'REJECTED' ||
|
|
126
|
+
verificationStatus === 'CREATED') {
|
|
127
|
+
globalStore.kycVerificationStatus.setOpen(true);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
createDepositMutation.mutate({
|
|
132
|
+
amount: data.amount.toString(),
|
|
133
|
+
promo: data.promo ?? undefined,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return (_jsxs("form", { onSubmit: handleSubmit, noValidate: true, children: [_jsx(Controller, { control: form.control, name: "amount", render: (o) => (_jsxs(Field.Root, { invalid: !!form.formState.errors.amount, children: [_jsxs(NumberInput.Root, { min: 0, step: 1, value: o.field.value, onValueChange: (details) => {
|
|
138
|
+
o.field.onChange(details.value);
|
|
139
|
+
}, allowMouseWheel: true, children: [_jsx(NumberInput.Label, { children: "Enter amount you want to deposit" }), _jsxs(NumberInput.Control, { children: [_jsx(NumberInput.Input, {}), _jsx(NumberInput.IncrementTrigger, { children: _jsx(ChevronUpIcon, {}) }), _jsx(NumberInput.DecrementTrigger, { children: _jsx(ChevronDownIcon, {}) })] })] }), _jsx(Field.ErrorText, { children: form.formState.errors.amount?.message })] })) }), _jsx(AmountChoices, { value: parseDecimal(form.watch('amount'), 0), onChange: (value) => {
|
|
140
|
+
form.setValue('amount', value.toString(), {
|
|
141
|
+
shouldTouch: true,
|
|
142
|
+
shouldDirty: true,
|
|
143
|
+
shouldValidate: true,
|
|
144
|
+
});
|
|
145
|
+
}, min: minimumAmount, max: maximumAmount, className: "mt-lg" }), _jsx(Controller, { control: form.control, name: "promo", render: (o) => (_jsx(AvailablePromos, { value: o.field.value, onChange: (value) => {
|
|
146
|
+
o.field.onChange(value);
|
|
147
|
+
globalStore.depositWithdrawal.setPromo(null);
|
|
148
|
+
}, className: "mt-3xl" })) }), _jsx(Button, { type: "submit", className: "mt-3xl", disabled: createDepositMutation.isPending, children: "Deposit" }), depositWithdrawalProps.hasPrivacyPolicyAndTermsOfUse && (_jsxs("p", { className: "mt-lg text-text-tertiary-600 text-xs", children: ["By depositing, you agree to our", ' ', _jsx(Link, { href: depositWithdrawalProps.termsOfUseUrl ?? '/terms-of-use', onClick: () => globalStore.depositWithdrawal.setOpen(false), className: "text-text-warning-primary-600 underline underline-offset-2", children: "Terms of Use" }), ' ', "and", ' ', _jsx(Link, { href: depositWithdrawalProps.privacyPolicyUrl ?? '/privacy-policy', onClick: () => globalStore.depositWithdrawal.setOpen(false), className: "text-text-warning-primary-600 underline underline-offset-2", children: "Privacy Policy" }), "."] })), _jsx(AlertDialog.Root, { open: status !== 'waiting', onOpenChange: (details) => {
|
|
149
|
+
if (!details.open) {
|
|
150
|
+
setStatus('waiting');
|
|
151
|
+
}
|
|
152
|
+
}, lazyMount: true, unmountOnExit: true, closeOnEscape: false, closeOnInteractOutside: false, children: _jsxs(Portal, { children: [_jsx(AlertDialog.Backdrop, { className: "!z-[calc(var(--z-dialog)+2)]" }), _jsx(AlertDialog.Positioner, { className: "!z-[calc(var(--z-dialog)+3)]", children: _jsxs(AlertDialog.Content, { children: [_jsx(AlertDialog.CloseTrigger, { disabled: status === 'processing', children: _jsx(XIcon, {}) }), _jsxs(AlertDialog.Header, { children: [status === 'processing' && (_jsx(SpinnerIcon, { className: "size-12 text-text-brand-primary-600" })), status === 'success' && (_jsx("div", { className: "flex size-12 items-center justify-center rounded-full bg-bg-success-secondary text-text-featured-icon-light-success", children: _jsx(AlertCircleIcon, {}) })), status === 'failed' && (_jsx("div", { className: "flex size-12 items-center justify-center rounded-full bg-bg-error-secondary text-text-featured-icon-light-error", children: _jsx(AlertCircleIcon, {}) }))] }), _jsxs(AlertDialog.Body, { children: [_jsxs(AlertDialog.Title, { children: [status === 'processing' && 'Processing Deposit', status === 'success' && 'Deposit Successful', status === 'failed' && 'Deposit Failed'] }), _jsxs(AlertDialog.Description, { children: [status === 'processing' &&
|
|
153
|
+
"We're verifying your account and amount. Please hold a moment.", status === 'success' && (_jsxs(_Fragment, { children: ["Your deposit has been successfully processed. ", _jsx("br", {}), " If you are not redirected automatically, click", ' ', !!createDepositMutation.data?.checkoutUrl && (_jsx("a", { href: createDepositMutation.data?.checkoutUrl, target: "_blank", rel: "noopener noreferrer", className: "text-text-brand underline underline-offset-2", children: "here" })), "."] })), status === 'failed' &&
|
|
154
|
+
'Something went wrong while processing your deposit. Please try again or contact support.'] })] }), (status === 'failed' || status === 'success') && (_jsx(AlertDialog.Footer, { children: _jsx(AlertDialog.Context, { children: (api) => (_jsx(Button, { onClick: () => {
|
|
155
|
+
api.setOpen(false);
|
|
156
|
+
}, children: status === 'failed' ? 'Try Again' : 'Ok' })) }) }))] }) })] }) })] }));
|
|
157
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function MayaDeposit(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
3
|
+
import Link from 'next/link';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
6
|
+
import invariant from 'tiny-invariant';
|
|
7
|
+
import { useBoolean } from 'usehooks-ts';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { useShallow } from 'zustand/shallow';
|
|
10
|
+
import { useAvailablePromosQuery } from '../../../../client/hooks/useAvailablePromosQuery.js';
|
|
11
|
+
import { useCreateMayaDepositMutation } from '../../../../client/hooks/useCreateMayaDepositMutation.js';
|
|
12
|
+
import { useDepositQuery } from '../../../../client/hooks/useDepositQuery.js';
|
|
13
|
+
import { useDepositsCountQuery } from '../../../../client/hooks/useDepositsCountQuery.js';
|
|
14
|
+
import { useDisclosure } from '../../../../client/hooks/useDisclosure.js';
|
|
15
|
+
import { useGlobalStore } from '../../../../client/hooks/useGlobalStore.js';
|
|
16
|
+
import { useMemberVerificationQuery } from '../../../../client/hooks/useMemberVerificationQuery.js';
|
|
17
|
+
import { usePaymentSettingsQuery } from '../../../../client/hooks/usePaymentSettingsQuery.js';
|
|
18
|
+
import { AlertCircleIcon } from '../../../../icons/AlertCircleIcon.js';
|
|
19
|
+
import { ChevronDownIcon } from '../../../../icons/ChevronDownIcon.js';
|
|
20
|
+
import { ChevronUpIcon } from '../../../../icons/ChevronUpIcon.js';
|
|
21
|
+
import { RefreshCcw01Icon } from '../../../../icons/RefreshCcw01Icon.js';
|
|
22
|
+
import { SpinnerIcon } from '../../../../icons/SpinnerIcon.js';
|
|
23
|
+
import { XIcon } from '../../../../icons/XIcon.js';
|
|
24
|
+
import { AlertDialog } from '../../../../ui/AlertDialog/index.js';
|
|
25
|
+
import { Button } from '../../../../ui/Button/index.js';
|
|
26
|
+
import { Field } from '../../../../ui/Field/index.js';
|
|
27
|
+
import { NumberInput } from '../../../../ui/NumberInput/index.js';
|
|
28
|
+
import { Portal } from '../../../../ui/Portal/index.js';
|
|
29
|
+
import { parseDecimal } from '../../../../utils/parseDecimal.js';
|
|
30
|
+
import { AmountChoices } from '../../AmountChoices.js';
|
|
31
|
+
import { useDepositWithdrawalPropsContext } from '../../DepositWithdrawalContext.js';
|
|
32
|
+
import { AvailablePromos } from '../AvailablePromos.js';
|
|
33
|
+
export function MayaDeposit() {
|
|
34
|
+
const depositWithdrawalProps = useDepositWithdrawalPropsContext();
|
|
35
|
+
const disclosure = useDisclosure({
|
|
36
|
+
onOpenChange(open) {
|
|
37
|
+
if (!open) {
|
|
38
|
+
form.reset();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const globalStore = useGlobalStore(useShallow((ctx) => ({
|
|
43
|
+
depositWithdrawal: ctx.depositWithdrawal,
|
|
44
|
+
kycVerificationStatus: ctx.kycVerificationStatus,
|
|
45
|
+
})));
|
|
46
|
+
const verificationQuery = useMemberVerificationQuery();
|
|
47
|
+
const verificationStatus = verificationQuery.data?.status ?? 'UNVERIFIED';
|
|
48
|
+
const [status, setStatus] = useState('waiting');
|
|
49
|
+
const createDepositMutation = useCreateMayaDepositMutation({
|
|
50
|
+
onMutate() {
|
|
51
|
+
disclosure.setOpen(true);
|
|
52
|
+
setStatus('processing');
|
|
53
|
+
},
|
|
54
|
+
onSuccess(data) {
|
|
55
|
+
invariant(data.checkoutUrl);
|
|
56
|
+
window.open(data.checkoutUrl, '_blank', 'noopener,noreferrer');
|
|
57
|
+
setStatus('success');
|
|
58
|
+
},
|
|
59
|
+
onError() {
|
|
60
|
+
setStatus('failed');
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
const warn = useBoolean();
|
|
64
|
+
const depositQuery = useDepositQuery(createDepositMutation.data?.id, {
|
|
65
|
+
enabled: !warn.value && status === 'success',
|
|
66
|
+
refetchInterval: (ctx) => ctx.state.data?.status === 'CONFIRMED' ||
|
|
67
|
+
ctx.state.data?.status === 'REJECTED' ||
|
|
68
|
+
ctx.state.data?.status === 'CANCELLED'
|
|
69
|
+
? false
|
|
70
|
+
: 1000,
|
|
71
|
+
});
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (depositQuery.data?.status === 'CONFIRMED') {
|
|
74
|
+
setStatus('confirmed');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (depositQuery.data?.status === 'REJECTED' ||
|
|
78
|
+
depositQuery.data?.status === 'CANCELLED') {
|
|
79
|
+
setStatus('failed');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}, [depositQuery.data?.status]);
|
|
83
|
+
const depositsCountQuery = useDepositsCountQuery();
|
|
84
|
+
const depositsCount = depositsCountQuery.data ?? 0;
|
|
85
|
+
const paymentSettingsQuery = usePaymentSettingsQuery();
|
|
86
|
+
const paymentSettings = paymentSettingsQuery.data;
|
|
87
|
+
const gatewaySettings = paymentSettings?.mayaDepositGatewaySettings;
|
|
88
|
+
const maximumAmount = parseDecimal(gatewaySettings?.maximumAmount, 0);
|
|
89
|
+
const minimumAmount = depositsCount <= 0
|
|
90
|
+
? parseDecimal(paymentSettingsQuery.data?.minimumFirstDepositAmount, 0)
|
|
91
|
+
: parseDecimal(gatewaySettings?.minimumAmount, 0);
|
|
92
|
+
const promosQuery = useAvailablePromosQuery();
|
|
93
|
+
const promos = promosQuery.data ?? [];
|
|
94
|
+
const definition = z
|
|
95
|
+
.object({
|
|
96
|
+
amount: z.string().superRefine((val, ctx) => {
|
|
97
|
+
const n = parseDecimal(val, 0);
|
|
98
|
+
if (n < minimumAmount) {
|
|
99
|
+
ctx.addIssue({
|
|
100
|
+
type: 'number',
|
|
101
|
+
code: z.ZodIssueCode.too_small,
|
|
102
|
+
inclusive: true,
|
|
103
|
+
minimum: minimumAmount,
|
|
104
|
+
message: `Minimum amount is ${minimumAmount.toLocaleString()}`,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (n > maximumAmount) {
|
|
108
|
+
ctx.addIssue({
|
|
109
|
+
type: 'number',
|
|
110
|
+
code: z.ZodIssueCode.too_big,
|
|
111
|
+
inclusive: true,
|
|
112
|
+
maximum: maximumAmount,
|
|
113
|
+
message: `Maximum amount is ${maximumAmount.toLocaleString()}`,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}),
|
|
117
|
+
promo: z.string().optional().nullable(),
|
|
118
|
+
})
|
|
119
|
+
.superRefine((value, ctx) => {
|
|
120
|
+
const promo = promos.find((o) => o.id === value.promo);
|
|
121
|
+
const promoMinAmount = parseDecimal(promo?.minimumDepositAmount, 0);
|
|
122
|
+
const promoMaxAmount = parseDecimal(promo?.maximumDepositAmount, 0);
|
|
123
|
+
const amount = parseDecimal(value.amount, 0);
|
|
124
|
+
if (promo && amount < promoMinAmount) {
|
|
125
|
+
ctx.addIssue({
|
|
126
|
+
path: ['amount'],
|
|
127
|
+
code: z.ZodIssueCode.custom,
|
|
128
|
+
message: `Minimum amount for this promo is ${promoMinAmount.toLocaleString()}`,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (promo && amount > promoMaxAmount) {
|
|
132
|
+
ctx.addIssue({
|
|
133
|
+
path: ['amount'],
|
|
134
|
+
code: z.ZodIssueCode.custom,
|
|
135
|
+
message: `Maximum amount for this promo is ${promoMaxAmount}`,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
const form = useForm({
|
|
140
|
+
mode: 'all',
|
|
141
|
+
resolver: zodResolver(definition),
|
|
142
|
+
defaultValues: {
|
|
143
|
+
amount: '0',
|
|
144
|
+
promo: globalStore.depositWithdrawal.promo ?? null,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (minimumAmount) {
|
|
149
|
+
form.reset({
|
|
150
|
+
amount: minimumAmount.toString(),
|
|
151
|
+
promo: form.getValues('promo') ?? null,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}, [form, minimumAmount]);
|
|
155
|
+
return (_jsxs("form", { onSubmit: form.handleSubmit(async (data) => {
|
|
156
|
+
if (verificationStatus === 'PENDING' ||
|
|
157
|
+
verificationStatus === 'UNVERIFIED' ||
|
|
158
|
+
verificationStatus === 'REJECTED' ||
|
|
159
|
+
verificationStatus === 'CREATED') {
|
|
160
|
+
globalStore.kycVerificationStatus.setOpen(true);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
createDepositMutation.reset();
|
|
165
|
+
createDepositMutation.mutate({
|
|
166
|
+
amount: data.amount.toString(),
|
|
167
|
+
promo: data.promo ?? undefined,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}), noValidate: true, children: [_jsx(Controller, { control: form.control, name: "amount", render: (o) => (_jsxs(Field.Root, { invalid: !!form.formState.errors.amount, children: [_jsxs(NumberInput.Root, { min: 0, step: 1, value: o.field.value, onValueChange: (details) => {
|
|
171
|
+
o.field.onChange(details.value);
|
|
172
|
+
}, allowMouseWheel: true, children: [_jsx(NumberInput.Label, { children: "Enter amount you want to deposit" }), _jsxs(NumberInput.Control, { children: [_jsx(NumberInput.Input, {}), _jsx(NumberInput.IncrementTrigger, { children: _jsx(ChevronUpIcon, {}) }), _jsx(NumberInput.DecrementTrigger, { children: _jsx(ChevronDownIcon, {}) })] })] }), _jsx(Field.ErrorText, { children: form.formState.errors.amount?.message })] })) }), _jsx(AmountChoices, { value: parseDecimal(form.watch('amount'), 0), onChange: (value) => {
|
|
173
|
+
form.setValue('amount', value.toString(), {
|
|
174
|
+
shouldTouch: true,
|
|
175
|
+
shouldDirty: true,
|
|
176
|
+
shouldValidate: true,
|
|
177
|
+
});
|
|
178
|
+
}, min: minimumAmount, max: maximumAmount, className: "mt-lg" }), _jsx(Controller, { control: form.control, name: "promo", render: (o) => (_jsx(AvailablePromos, { value: o.field.value, onChange: (value) => {
|
|
179
|
+
o.field.onChange(value);
|
|
180
|
+
globalStore.depositWithdrawal.setPromo(null);
|
|
181
|
+
}, className: "mt-3xl" })) }), _jsx(Button, { type: "submit", className: "mt-3xl", disabled: createDepositMutation.isPending, children: "Deposit" }), depositWithdrawalProps.hasPrivacyPolicyAndTermsOfUse && (_jsxs("p", { className: "mt-lg text-text-tertiary-600 text-xs", children: ["By depositing, you agree to our", ' ', _jsx(Link, { href: depositWithdrawalProps.termsOfUseUrl ?? '/terms-of-use', onClick: () => globalStore.depositWithdrawal.setOpen(false), className: "text-text-warning-primary-600 underline underline-offset-2", children: "Terms of Use" }), ' ', "and", ' ', _jsx(Link, { href: depositWithdrawalProps.privacyPolicyUrl ?? '/privacy-policy', onClick: () => globalStore.depositWithdrawal.setOpen(false), className: "text-text-warning-primary-600 underline underline-offset-2", children: "Privacy Policy" }), "."] })), _jsx(AlertDialog.Root, { open: disclosure.open, onOpenChange: (details) => {
|
|
182
|
+
disclosure.setOpen(details.open);
|
|
183
|
+
}, lazyMount: true, unmountOnExit: true, closeOnEscape: false, closeOnInteractOutside: false, onExitComplete: () => {
|
|
184
|
+
setStatus('waiting');
|
|
185
|
+
form.reset();
|
|
186
|
+
warn.setFalse();
|
|
187
|
+
}, children: _jsxs(Portal, { children: [_jsx(AlertDialog.Backdrop, { className: "!z-[calc(var(--z-dialog)+2)]" }), _jsx(AlertDialog.Positioner, { className: "!z-[calc(var(--z-dialog)+3)]", children: _jsxs(AlertDialog.Content, { children: [_jsx(AlertDialog.Context, { children: (api) => (_jsx("button", { type: "button", className: "absolute top-2.5 right-2.5 flex icon:size-6 size-11 items-center justify-center text-text-quinary", onClick: () => {
|
|
188
|
+
if (status === 'success' && !warn.value) {
|
|
189
|
+
warn.setTrue();
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
api.setOpen(false);
|
|
193
|
+
}
|
|
194
|
+
}, children: _jsx(XIcon, {}) })) }), _jsxs(AlertDialog.Header, { children: [status === 'processing' && (_jsx(SpinnerIcon, { className: "size-12 text-text-brand-primary-600" })), status === 'success' && !warn.value && (_jsx("div", { className: "flex size-12 items-center justify-center rounded-full bg-bg-brand-secondary text-text-featured-icon-light-brand", children: _jsx(RefreshCcw01Icon, {}) })), status === 'success' && warn.value && (_jsx("div", { className: "flex size-12 items-center justify-center rounded-full bg-bg-error-secondary text-text-featured-icon-light-error", children: _jsx(AlertCircleIcon, {}) })), status === 'confirmed' && (_jsx("div", { className: "flex size-12 items-center justify-center rounded-full bg-bg-success-secondary text-text-featured-icon-light-success", children: _jsx(AlertCircleIcon, {}) })), status === 'failed' && (_jsx("div", { className: "flex size-12 items-center justify-center rounded-full bg-bg-error-secondary text-text-featured-icon-light-error", children: _jsx(AlertCircleIcon, {}) }))] }), _jsxs(AlertDialog.Body, { children: [_jsxs(AlertDialog.Title, { children: [status === 'processing' && 'Processing Deposit', status === 'success' &&
|
|
195
|
+
!warn.value &&
|
|
196
|
+
'Didn’t see the payment window?', status === 'success' && warn.value && (_jsx(_Fragment, { children: "Are you sure you want to close this\u00A0window?" })), status === 'confirmed' && 'Deposit Successful', status === 'failed' && 'Deposit Failed'] }), _jsxs(AlertDialog.Description, { children: [status === 'processing' &&
|
|
197
|
+
"We're verifying your account and amount. Please hold a moment.", status === 'success' &&
|
|
198
|
+
!warn.value &&
|
|
199
|
+
'Sometimes the payment pop up doesn’t appear right away. Don’t worry, just click the button below to reopen it and continue your deposit.', status === 'success' &&
|
|
200
|
+
warn.value &&
|
|
201
|
+
'Closing this window might cancel your current deposit. Do you want to continue?', status === 'confirmed' &&
|
|
202
|
+
'Your deposit has been successfully processed.', status === 'failed' &&
|
|
203
|
+
'Something went wrong while processing your deposit. Please try again or contact support.'] })] }), (status === 'failed' ||
|
|
204
|
+
status === 'success' ||
|
|
205
|
+
status === 'confirmed') && (_jsxs(AlertDialog.Footer, { children: [status === 'success' && !warn.value && (_jsx(Button, { asChild: true, children: _jsx("a", { href: createDepositMutation.data?.checkoutUrl ?? '', target: "_blank", rel: "noopener noreferrer", children: "Try Again" }) })), status === 'success' && warn.value && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "outline", onClick: () => {
|
|
206
|
+
warn.setFalse();
|
|
207
|
+
}, children: "Go back" }), _jsx(AlertDialog.Context, { children: (api) => (_jsx(Button, { onClick: () => api.setOpen(false), children: "Continue" })) })] })), status !== 'success' && (_jsx(AlertDialog.Context, { children: (api) => (_jsx(Button, { onClick: () => api.setOpen(false), children: "Ok" })) }))] }))] }) })] }) })] }));
|
|
208
|
+
}
|
package/dist/components/DepositWithdrawal/Deposit__next/MayaWebpayDeposit/MayaWebpayDeposit.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function MayaWebpayDeposit(): import("react/jsx-runtime").JSX.Element;
|