feat: 更新 API 地址,添加分类组件,优化市场页面布局和功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { App } from "@riwa/api-types";
|
||||
import type { Awaitable } from "@vueuse/core";
|
||||
import { treaty } from "@elysiajs/eden";
|
||||
import { toastController } from "@ionic/vue";
|
||||
|
||||
@@ -13,10 +14,17 @@ export interface SafeClientOptions {
|
||||
immediate?: boolean;
|
||||
}
|
||||
|
||||
export async function safeClient<T, E>(
|
||||
export interface SafeClientReturn<T, E> {
|
||||
data: Ref<T | null>;
|
||||
error: Ref<E | null>;
|
||||
refresh: () => Promise<void>;
|
||||
onFetchResponse: (callback: (data: T, error: E) => void) => void;
|
||||
}
|
||||
|
||||
export function safeClient<T, E>(
|
||||
requestPromise: () => Promise<{ data: T; error: E }>,
|
||||
options: SafeClientOptions = {},
|
||||
) {
|
||||
): SafeClientReturn<T, E> & Promise<SafeClientReturn<T, E>> {
|
||||
const { immediate = true } = options;
|
||||
const data = ref<T | null>(null);
|
||||
const error = ref<E | null>(null);
|
||||
@@ -61,11 +69,20 @@ export async function safeClient<T, E>(
|
||||
responseCallback = callback;
|
||||
}
|
||||
|
||||
if (immediate) {
|
||||
await execute();
|
||||
}
|
||||
const result: SafeClientReturn<T, E> = {
|
||||
data: data as Ref<T | null>,
|
||||
error: error as Ref<E | null>,
|
||||
refresh: execute,
|
||||
onFetchResponse,
|
||||
};
|
||||
|
||||
return { data, error, refresh: execute, onFetchResponse };
|
||||
// 创建一个 Promise 并在其上添加属性
|
||||
const promise = immediate ? execute().then(() => result) : Promise.resolve(result);
|
||||
|
||||
// 将 result 的属性添加到 promise 上
|
||||
Object.assign(promise, result);
|
||||
|
||||
return promise as SafeClientReturn<T, E> & Promise<SafeClientReturn<T, E>>;
|
||||
}
|
||||
|
||||
export { client };
|
||||
|
||||
@@ -7,6 +7,10 @@ export type DepositFiatBody = Parameters<typeof client.api.deposit.fiat.post>[0]
|
||||
assetCode: AssetCodeEnum;
|
||||
};
|
||||
|
||||
export type TreatyQuery<T> = T extends (...args: any[]) => any
|
||||
? NonNullable<NonNullable<Parameters<T>[0]>["query"]>
|
||||
: never;
|
||||
|
||||
export type DepositFiatData = Treaty.Data<typeof client.api.deposit.fiat.post>;
|
||||
|
||||
export type BalancesData = Treaty.Data<typeof client.api.asset.balances.get>;
|
||||
@@ -18,18 +22,22 @@ export type WithdrawBody = Omit<Parameters<typeof client.api.withdraw.post>[0],
|
||||
|
||||
export type UserProfileData = Treaty.Data<typeof client.api.user.profile.get>["userProfile"];
|
||||
|
||||
export type UpdateUserProfileBody = NonNullable<Parameters<typeof client.api.user.profile.put>[0]>;
|
||||
export type UpdateUserProfileBody = TreatyQuery<typeof client.api.user.profile.put>;
|
||||
|
||||
export type RwaIssuanceProductsData = Treaty.Data<typeof client.api.rwa.issuance.products.bundle.post>;
|
||||
|
||||
export type RwaIssuanceProductBody = NonNullable<Parameters<typeof client.api.rwa.issuance.products.bundle.post>[0]>;
|
||||
export type RwaIssuanceProductBody = TreatyQuery<typeof client.api.rwa.issuance.products.bundle.post>;
|
||||
|
||||
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 BankAccountBody = TreatyQuery<typeof client.api.bank_account.post>;
|
||||
|
||||
export type BankAccountData = Treaty.Data<typeof client.api.bank_account.post>;
|
||||
|
||||
export type SupportBanksData = Treaty.Data<typeof client.api.bank_account.banks.get>;
|
||||
|
||||
export type AvailableSubscriptionData = Treaty.Data<typeof client.api.rwa.subscription.available_editions.get>;
|
||||
|
||||
export type AvailableSubscriptionBody = TreatyQuery<typeof client.api.rwa.subscription.available_editions.get>;
|
||||
|
||||
Reference in New Issue
Block a user