feat: add BrokerAnalyticsDto type, API function, and hook
This commit is contained in:
parent
abf3676ba1
commit
3f0fb42d99
@ -0,0 +1,10 @@
|
||||
import type { ApiResponseMeta, BrokerAnalytics } from '@/shared/api'
|
||||
import { request } from '@/shared/api/kyClient'
|
||||
|
||||
export function getBrokerAnalytics(
|
||||
accountId: string,
|
||||
): Promise<{ data: BrokerAnalytics; meta: ApiResponseMeta }> {
|
||||
return request<BrokerAnalytics>(
|
||||
`/api/v1/broker/accounts/${encodeURIComponent(accountId)}/analytics`,
|
||||
)
|
||||
}
|
||||
2
apps/frontend/src/entities/broker-analytics/index.ts
Normal file
2
apps/frontend/src/entities/broker-analytics/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export { getBrokerAnalytics } from './api/brokerAnalyticsApi'
|
||||
export { useBrokerAnalytics } from './model/useBrokerAnalytics'
|
||||
@ -0,0 +1,14 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import type { BrokerAnalytics } from '@/shared/api'
|
||||
import { getBrokerAnalytics } from '../api/brokerAnalyticsApi'
|
||||
|
||||
export function useBrokerAnalytics(accountId: string | undefined) {
|
||||
return useQuery<BrokerAnalytics>({
|
||||
queryKey: ['broker', 'analytics', accountId],
|
||||
enabled: Boolean(accountId),
|
||||
queryFn: async () => (await getBrokerAnalytics(accountId!)).data,
|
||||
staleTime: 300_000,
|
||||
retry: 2,
|
||||
refetchOnWindowFocus: false,
|
||||
})
|
||||
}
|
||||
@ -60,3 +60,6 @@ export type BrokerOperationCategory =
|
||||
export type BrokerEventItem = components['schemas']['BrokerEventItemDto']
|
||||
export type BrokerEventsData = components['schemas']['BrokerEventsDataDto']
|
||||
export type BrokerEventsSummary = components['schemas']['BrokerEventsSummaryDto']
|
||||
|
||||
// Broker analytics
|
||||
export type BrokerAnalytics = components['schemas']['BrokerAnalyticsDto']
|
||||
|
||||
@ -1193,6 +1193,16 @@ export interface components {
|
||||
actualCouponsTotal: number
|
||||
actualPrincipalRepaymentTotal: number
|
||||
}
|
||||
BrokerAnalyticsDto: {
|
||||
totalDeposits: number
|
||||
totalWithdrawn: number
|
||||
netInvested: number
|
||||
totalDividends: number
|
||||
totalCoupons: number
|
||||
totalReceived: number
|
||||
totalReturnPercent: number | null
|
||||
currency: string
|
||||
}
|
||||
BrokerEventsDataDto: {
|
||||
items: components['schemas']['BrokerEventItemDto'][]
|
||||
summary: components['schemas']['BrokerEventsSummaryDto']
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user