|
@@ -8,10 +8,11 @@ import { neReg } from "@/utils";
|
|
|
import { Form, Input, Toast } from "antd-mobile";
|
|
|
import { FormInstance } from "antd-mobile/es/components/form";
|
|
|
import { useTranslations } from "next-intl";
|
|
|
-import { FC, Fragment, useRef, useState } from "react";
|
|
|
+import { FC, Fragment, useLayoutEffect, useRef, useState } from "react";
|
|
|
|
|
|
import actions from "@/app/[locale]/(TabBar)/deposit/actions";
|
|
|
import "@/styles/deposit.scss";
|
|
|
+import { server } from "@/utils/client";
|
|
|
interface Props {
|
|
|
deposits: DepositsTypes[];
|
|
|
}
|
|
@@ -59,11 +60,26 @@ const RewardsText: FC<RewardsProps> = (props) => {
|
|
|
</div>
|
|
|
);
|
|
|
};
|
|
|
+
|
|
|
+const getDepositApi = async () => {
|
|
|
+ return server
|
|
|
+ .request<DepositsTypes[]>({
|
|
|
+ url: "/v1/api/user/user_deposit_config",
|
|
|
+ method: "post",
|
|
|
+ data: { activity_type: 0 },
|
|
|
+ })
|
|
|
+ .then((res) => {
|
|
|
+ if (res.code === 200) return res.data;
|
|
|
+ return [];
|
|
|
+ });
|
|
|
+};
|
|
|
const DepositData: FC<Props> = (props) => {
|
|
|
const { deposits } = props;
|
|
|
const t = useTranslations();
|
|
|
const userInfo = useUserInfoStore((state) => state.userInfo);
|
|
|
- const [activeType, setActiveType] = useState<DepositsTypes>(deposits[0]);
|
|
|
+ const [depositState, setDepositState] = useState<DepositsTypes[]>([]);
|
|
|
+
|
|
|
+ const [activeType, setActiveType] = useState<Partial<DepositsTypes>>({});
|
|
|
|
|
|
const formInstanceRef = useRef<FormInstance>(null);
|
|
|
let [amount, setAmount] = useState<number | undefined>(undefined);
|
|
@@ -86,6 +102,9 @@ const DepositData: FC<Props> = (props) => {
|
|
|
if (res.data.pay_url) {
|
|
|
window.open(res.data.pay_url);
|
|
|
}
|
|
|
+ const data = await getDepositApi();
|
|
|
+ setDepositState(data);
|
|
|
+ setActiveType(data[0]);
|
|
|
await actions();
|
|
|
})
|
|
|
.catch((error) => {
|
|
@@ -103,28 +122,35 @@ const DepositData: FC<Props> = (props) => {
|
|
|
};
|
|
|
const amountValidator = (rules: any, value: any) => {
|
|
|
if (!value) return Promise.reject(new Error(t("form.amount")));
|
|
|
- if (+value < activeType.min_amount)
|
|
|
+ if (+value < activeType.min_amount!)
|
|
|
return Promise.reject(
|
|
|
new Error(t("form.amountMinReg", { amount: activeType.min_amount }))
|
|
|
);
|
|
|
- if (+value > activeType.max_amount)
|
|
|
+ if (+value > activeType.max_amount!)
|
|
|
return Promise.reject(
|
|
|
new Error(t("form.amountMaxReg", { amount: activeType.max_amount }))
|
|
|
);
|
|
|
return Promise.resolve();
|
|
|
};
|
|
|
+
|
|
|
+ useLayoutEffect(() => {
|
|
|
+ getDepositApi().then((data) => {
|
|
|
+ setDepositState(data);
|
|
|
+ setActiveType(data[0]);
|
|
|
+ });
|
|
|
+ }, []);
|
|
|
return (
|
|
|
<div className="deposit-box">
|
|
|
<div className="img-box"></div>
|
|
|
|
|
|
<div className={"flex flex-wrap"}>
|
|
|
- {deposits.map((item, index) => {
|
|
|
+ {depositState.map((item, index) => {
|
|
|
return (
|
|
|
<Fragment key={item.id}>
|
|
|
<p
|
|
|
className="btn-box truncate"
|
|
|
style={{
|
|
|
- borderColor: activeType.id === item.id ? "#ff9323" : "#333",
|
|
|
+ borderColor: activeType?.id === item.id ? "#ff9323" : "#333",
|
|
|
}}
|
|
|
onClick={() => titleChangeHandler(item, index)}
|
|
|
>
|
|
@@ -178,16 +204,16 @@ const DepositData: FC<Props> = (props) => {
|
|
|
rules={[{ required: true, type: "number", validator: amountValidator }]}
|
|
|
>
|
|
|
<Input
|
|
|
- placeholder={`${t("DepositPage.Montante")}(BRL): Mín. ${activeType.min_amount}`}
|
|
|
+ placeholder={`${t("DepositPage.Montante")}(BRL): Mín. ${activeType?.min_amount}`}
|
|
|
type={"number"}
|
|
|
- maxLength={activeType.max_amount}
|
|
|
+ maxLength={activeType?.max_amount}
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
|
|
|
<div className={"flex flex-col"}>
|
|
|
<div className={"flex-1"}>
|
|
|
<ul className="ul-box">
|
|
|
- {activeType.products.map((item, index) => (
|
|
|
+ {activeType?.products?.map((item, index) => (
|
|
|
<li
|
|
|
className={amount == item.amount ? "active" : ""}
|
|
|
key={index}
|
|
@@ -200,8 +226,15 @@ const DepositData: FC<Props> = (props) => {
|
|
|
<span> {item.amount}</span>
|
|
|
</div>
|
|
|
|
|
|
- {!activeType.has_pay && item.rewards && (
|
|
|
- <RewardsText rewards={item.rewards} />
|
|
|
+ {item.rewards && (
|
|
|
+ <RewardsText
|
|
|
+ rewards={
|
|
|
+ item.rewards &&
|
|
|
+ item.rewards.sort(
|
|
|
+ (p, n) => p.coin_type - n.coin_type
|
|
|
+ )
|
|
|
+ }
|
|
|
+ />
|
|
|
)}
|
|
|
</li>
|
|
|
))}
|