feat: 更新提现功能,优化错误处理逻辑,添加成功提示信息,改进界面交互
This commit is contained in:
@@ -26,9 +26,19 @@ export async function safeClient<T, E>(
|
|||||||
const res = await requestPromise();
|
const res = await requestPromise();
|
||||||
|
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
|
let errMsg = "";
|
||||||
|
if (!res.error) {
|
||||||
|
errMsg = "Request failed. Please try again.";
|
||||||
|
}
|
||||||
|
else if (typeof res.error === "string") {
|
||||||
|
errMsg = res.error;
|
||||||
|
}
|
||||||
|
else if (res.error && "value" in (res.error as unknown as object)) {
|
||||||
|
errMsg = String((res.error as unknown as { value: string }).value);
|
||||||
|
}
|
||||||
if (!options.silent) {
|
if (!options.silent) {
|
||||||
const toast = await toastController.create({
|
const toast = await toastController.create({
|
||||||
message: typeof error === "string" ? error : "Request failed. Please try again.",
|
message: errMsg,
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
color: "danger",
|
color: "danger",
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
"cryptoAddress": "Crypto Address",
|
"cryptoAddress": "Crypto Address",
|
||||||
"enterCryptoAddress": "Enter the crypto address",
|
"enterCryptoAddress": "Enter the crypto address",
|
||||||
"validCryptoAddressError": "Please enter a valid crypto address.",
|
"validCryptoAddressError": "Please enter a valid crypto address.",
|
||||||
|
"successMessage": "Withdrawal request submitted successfully!",
|
||||||
"submit": "Submit"
|
"submit": "Submit"
|
||||||
},
|
},
|
||||||
"bankCard": {
|
"bankCard": {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
"cryptoAddress": "加密货币地址",
|
"cryptoAddress": "加密货币地址",
|
||||||
"enterCryptoAddress": "请输入加密货币地址",
|
"enterCryptoAddress": "请输入加密货币地址",
|
||||||
"validCryptoAddressError": "请输入有效的加密货币地址。",
|
"validCryptoAddressError": "请输入有效的加密货币地址。",
|
||||||
|
"successMessage": "提现申请提交成功!",
|
||||||
"submit": "提交"
|
"submit": "提交"
|
||||||
},
|
},
|
||||||
"bankCard": {
|
"bankCard": {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ function handleWithdraw() {
|
|||||||
router.push("/withdraw/index");
|
router.push("/withdraw/index");
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdated(() => {
|
onMounted(() => {
|
||||||
walletStore.updateBalances();
|
walletStore.updateBalances();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang='ts' setup>
|
<script lang='ts' setup>
|
||||||
import type { WithdrawBody } from "@/api/types";
|
import type { WithdrawBody } from "@/api/types";
|
||||||
|
import { toastController } from "@ionic/vue";
|
||||||
import { client, safeClient } from "@/api";
|
import { client, safeClient } from "@/api";
|
||||||
import { AssetCodeEnum, ChainEnum, WithdrawMethodEnum } from "@/api/enum";
|
import { AssetCodeEnum, ChainEnum, WithdrawMethodEnum } from "@/api/enum";
|
||||||
|
|
||||||
@@ -15,11 +16,12 @@ const [form, resetForm] = useResetRef<WithdrawBody>({
|
|||||||
chain: "BEP20",
|
chain: "BEP20",
|
||||||
});
|
});
|
||||||
const walletStore = useWalletStore();
|
const walletStore = useWalletStore();
|
||||||
const { balances } = storeToRefs(walletStore);
|
const { balances, bankAccounts } = storeToRefs(walletStore);
|
||||||
const maxAmount = computed(() => {
|
const maxAmount = computed(() => {
|
||||||
const balance = balances.value?.find(item => item.assetCode === form.value.assetCode);
|
const balance = balances.value?.find(item => item.assetCode === form.value.assetCode);
|
||||||
return balance ? balance.available : "0";
|
return balance ? balance.available : "0";
|
||||||
});
|
});
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
function markTouched() {
|
function markTouched() {
|
||||||
amountInputInst.value?.$el.classList.add("ion-touched");
|
amountInputInst.value?.$el.classList.add("ion-touched");
|
||||||
@@ -42,7 +44,17 @@ function handleCurrentChange() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
const { data } = await safeClient(() => client.api.withdraw.post(form.value));
|
await safeClient(() => client.api.withdraw.post(form.value));
|
||||||
|
const toast = await toastController.create({
|
||||||
|
message: t("withdraw.successMessage"),
|
||||||
|
duration: 2000,
|
||||||
|
position: "bottom",
|
||||||
|
color: "success",
|
||||||
|
});
|
||||||
|
|
||||||
|
await toast.present();
|
||||||
|
resetForm();
|
||||||
|
router.back();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -93,15 +105,19 @@ async function onSubmit() {
|
|||||||
@ion-blur="markTouched"
|
@ion-blur="markTouched"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ui-input-label
|
<ion-select
|
||||||
v-if="form.withdrawMethod === WithdrawMethodEnum.BANK"
|
v-if="form.withdrawMethod === WithdrawMethodEnum.BANK"
|
||||||
v-model="form.bankAccountId"
|
v-model="form.bankAccountId"
|
||||||
|
interface="action-sheet"
|
||||||
|
toggle-icon=""
|
||||||
|
label-placement="floating"
|
||||||
:label="t('withdraw.bankAccountId')"
|
:label="t('withdraw.bankAccountId')"
|
||||||
:placeholder="t('withdraw.enterBankAccountId')"
|
:placeholder="t('withdraw.enterBankAccountId')"
|
||||||
type="text"
|
>
|
||||||
inputmode="text"
|
<ion-select-option v-for="item in bankAccounts" :key="item.id" :value="item.id">
|
||||||
:error-text="t('withdraw.validBankAccountError')"
|
{{ item.bankName }} - **** **** **** {{ item.accountName.slice(-4) }}
|
||||||
/>
|
</ion-select-option>
|
||||||
|
</ion-select>
|
||||||
<template v-else-if="form.withdrawMethod === WithdrawMethodEnum.CRYPTO">
|
<template v-else-if="form.withdrawMethod === WithdrawMethodEnum.CRYPTO">
|
||||||
<ion-radio-group v-model="form.chain">
|
<ion-radio-group v-model="form.chain">
|
||||||
<ion-label class="text-sm">
|
<ion-label class="text-sm">
|
||||||
|
|||||||
Reference in New Issue
Block a user