feat(wallet): 补齐钱包提现与卖家资金页面
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import { apiClient, unwrapData } from '@/shared/api/client'
|
||||
import type { ApiResponse } from '@/shared/api/types'
|
||||
import type {
|
||||
CreatePaymentAccountPayload,
|
||||
CreateWithdrawalPayload,
|
||||
PaymentAccount,
|
||||
PaymentAccountPage,
|
||||
UpdatePaymentAccountPayload,
|
||||
WalletAccount,
|
||||
WalletLedger,
|
||||
WalletLedgerPage,
|
||||
WithdrawalPage,
|
||||
WithdrawalRecord,
|
||||
} from '@/features/wallet/types'
|
||||
|
||||
export const WALLET_PAGE_SIZE = 20
|
||||
|
||||
export function fetchWalletBalance() {
|
||||
return unwrapData<WalletAccount>(apiClient.get<ApiResponse<WalletAccount>>('/wallet/balance'))
|
||||
}
|
||||
|
||||
export function fetchWalletLedger(page = 1, pageSize = WALLET_PAGE_SIZE) {
|
||||
return unwrapData<Partial<WalletLedgerPage>>(
|
||||
apiClient.get<ApiResponse<Partial<WalletLedgerPage>>>('/wallet/ledger', {
|
||||
params: { page, page_size: pageSize },
|
||||
})
|
||||
).then(data => ({
|
||||
items: (data.items ?? []) as WalletLedger[],
|
||||
total: data.total ?? 0,
|
||||
page: data.page ?? page,
|
||||
page_size: data.page_size ?? pageSize,
|
||||
}))
|
||||
}
|
||||
|
||||
export function fetchPaymentAccounts(page = 1, pageSize = WALLET_PAGE_SIZE) {
|
||||
return unwrapData<Partial<PaymentAccountPage>>(
|
||||
apiClient.get<ApiResponse<Partial<PaymentAccountPage>>>('/payment-accounts', {
|
||||
params: { page, page_size: pageSize },
|
||||
})
|
||||
).then(data => ({
|
||||
items: (data.items ?? []) as PaymentAccount[],
|
||||
total: data.total ?? 0,
|
||||
page: data.page ?? page,
|
||||
page_size: data.page_size ?? pageSize,
|
||||
}))
|
||||
}
|
||||
|
||||
export function createPaymentAccount(payload: CreatePaymentAccountPayload) {
|
||||
return unwrapData<PaymentAccount>(
|
||||
apiClient.post<ApiResponse<PaymentAccount>>('/payment-accounts', payload)
|
||||
)
|
||||
}
|
||||
|
||||
export function updatePaymentAccount(id: number, payload: UpdatePaymentAccountPayload) {
|
||||
return unwrapData<PaymentAccount>(
|
||||
apiClient.put<ApiResponse<PaymentAccount>>(`/payment-accounts/${id}`, payload)
|
||||
)
|
||||
}
|
||||
|
||||
export function deletePaymentAccount(id: number) {
|
||||
return unwrapData<{ deleted: boolean }>(
|
||||
apiClient.delete<ApiResponse<{ deleted: boolean }>>(`/payment-accounts/${id}`)
|
||||
)
|
||||
}
|
||||
|
||||
export function setDefaultPaymentAccount(id: number) {
|
||||
return unwrapData<{ updated: boolean }>(
|
||||
apiClient.post<ApiResponse<{ updated: boolean }>>(`/payment-accounts/${id}/set-default`)
|
||||
)
|
||||
}
|
||||
|
||||
export function fetchWithdrawals(page = 1, pageSize = WALLET_PAGE_SIZE) {
|
||||
return unwrapData<Partial<WithdrawalPage>>(
|
||||
apiClient.get<ApiResponse<Partial<WithdrawalPage>>>('/withdrawals', {
|
||||
params: { page, page_size: pageSize },
|
||||
})
|
||||
).then(data => ({
|
||||
items: (data.items ?? []) as WithdrawalRecord[],
|
||||
total: data.total ?? 0,
|
||||
page: data.page ?? page,
|
||||
page_size: data.page_size ?? pageSize,
|
||||
}))
|
||||
}
|
||||
|
||||
export function createWithdrawal(payload: CreateWithdrawalPayload) {
|
||||
return unwrapData<WithdrawalRecord>(
|
||||
apiClient.post<ApiResponse<WithdrawalRecord>>('/withdrawals', payload)
|
||||
)
|
||||
}
|
||||
|
||||
export function cancelWithdrawal(id: number) {
|
||||
return unwrapData<{ cancelled: boolean }>(
|
||||
apiClient.post<ApiResponse<{ cancelled: boolean }>>(`/withdrawals/${id}/cancel`)
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user