feat: 更新银行卡管理功能,添加银行卡和删除银行卡的逻辑,优化API请求方式

This commit is contained in:
2025-12-17 01:31:17 +07:00
parent 88b05581b5
commit 3cdb71effc
14 changed files with 564 additions and 29 deletions

View File

@@ -9,26 +9,38 @@ const client = treaty<App>(window.location.origin, {
});
export async function safeClient<T, E>(
requestPromise: Promise<{ data: T; error: E }>,
options: { silent?: boolean } = {},
requestPromise: () => Promise<{ data: T; error: E }>,
options: { silent?: boolean; immediate?: boolean } = {},
) {
const { data, error } = await requestPromise;
const { immediate = true } = options;
const data = ref<T | null>(null);
const error = ref<E | null>(null);
if (error) {
if (!options.silent) {
const toast = await toastController.create({
message: typeof error === "string" ? error : "Request failed. Please try again.",
duration: 3000,
position: "bottom",
color: "danger",
});
await toast.present();
const executeRequest = async () => {
const res = await requestPromise();
if (res.error) {
if (!options.silent) {
const toast = await toastController.create({
message: typeof error === "string" ? error : "Request failed. Please try again.",
duration: 3000,
position: "bottom",
color: "danger",
});
await toast.present();
}
throw res.error;
}
data.value = res.data;
error.value = res.error;
};
throw error;
if (immediate) {
await executeRequest();
}
return { data, error };
return { data, error, refresh: executeRequest };
}
export { client };

View File

@@ -25,3 +25,9 @@ export type RwaIssuanceProductsData = Treaty.Data<typeof client.api.rwa.issuance
export type RwaIssuanceProductBody = NonNullable<Parameters<typeof client.api.rwa.issuance.products.bundle.post>[0]>;
export type RwaIssuanceCategoriesData = Treaty.Data<typeof client.api.rwa.issuance.categories.get>;
export type BankAccountsData = Treaty.Data<typeof client.api.bank_account.get>;
export type BankAccountBody = Parameters<typeof client.api.bank_account.post>[0];
export type BankAccountData = Treaty.Data<typeof client.api.bank_account.post>;