Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -4,7 +4,7 @@ import type { FormInstance } from "@/utils";
|
||||
import { loadingController, toastController } from "@ionic/vue";
|
||||
import { swapVerticalOutline } from "ionicons/icons";
|
||||
import { ErrorMessage, Field, Form } from "vee-validate";
|
||||
import * as yup from "yup";
|
||||
import { z } from "zod";
|
||||
import { client, safeClient } from "@/api";
|
||||
import { AssetCodeEnum } from "@/api/enum";
|
||||
import { getCryptoIcon } from "@/config/crypto";
|
||||
@@ -43,15 +43,15 @@ const availableBalance = computed(() => {
|
||||
});
|
||||
|
||||
// 验证规则
|
||||
const schema = computed(() => yup.object({
|
||||
assetCode: yup.string().required(t("transfer.assetCodeRequired")),
|
||||
amount: yup
|
||||
.string()
|
||||
.required(t("transfer.amountRequired"))
|
||||
.test("min", t("transfer.amountMinError"), value => Number(value) > 0)
|
||||
.test("max", t("transfer.amountMaxError", { amount: availableBalance.value }), value => Number(value) <= Number(availableBalance.value)),
|
||||
fromAccount: yup.string().required(t("transfer.fromAccountRequired")),
|
||||
toAccount: yup.string().required(t("transfer.toAccountRequired")),
|
||||
const schema = computed(() => z.object({
|
||||
assetCode: z.string({ message: t("transfer.assetCodeRequired") }).min(1, t("transfer.assetCodeRequired")),
|
||||
amount: z
|
||||
.string({ message: t("transfer.amountRequired") })
|
||||
.min(1, t("transfer.amountRequired"))
|
||||
.refine(value => Number(value) > 0, t("transfer.amountMinError"))
|
||||
.refine(value => Number(value) <= Number(availableBalance.value), t("transfer.amountMaxError", { amount: availableBalance.value })),
|
||||
fromAccount: z.string({ message: t("transfer.fromAccountRequired") }).min(1, t("transfer.fromAccountRequired")),
|
||||
toAccount: z.string({ message: t("transfer.toAccountRequired") }).min(1, t("transfer.toAccountRequired")),
|
||||
}));
|
||||
|
||||
// 交换账户
|
||||
|
||||
Reference in New Issue
Block a user