feat: 更新银行卡管理功能,添加银行卡和删除银行卡的逻辑,优化API请求方式
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user