mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 15:54:03 +00:00
feat(miniapp): add finance dashboard view
This commit is contained in:
@@ -14,6 +14,29 @@ export interface MiniAppSession {
|
||||
reason?: string
|
||||
}
|
||||
|
||||
export interface MiniAppDashboard {
|
||||
period: string
|
||||
currency: 'USD' | 'GEL'
|
||||
totalDueMajor: string
|
||||
members: {
|
||||
memberId: string
|
||||
displayName: string
|
||||
rentShareMajor: string
|
||||
utilityShareMajor: string
|
||||
purchaseOffsetMajor: string
|
||||
netDueMajor: string
|
||||
explanations: readonly string[]
|
||||
}[]
|
||||
ledger: {
|
||||
id: string
|
||||
kind: 'purchase' | 'utility'
|
||||
title: string
|
||||
amountMajor: string
|
||||
actorDisplayName: string | null
|
||||
occurredAt: string | null
|
||||
}[]
|
||||
}
|
||||
|
||||
function apiBaseUrl(): string {
|
||||
const runtimeConfigured = runtimeBotApiUrl()
|
||||
if (runtimeConfigured) {
|
||||
@@ -64,3 +87,28 @@ export async function fetchMiniAppSession(initData: string): Promise<MiniAppSess
|
||||
...(payload.reason ? { reason: payload.reason } : {})
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchMiniAppDashboard(initData: string): Promise<MiniAppDashboard> {
|
||||
const response = await fetch(`${apiBaseUrl()}/api/miniapp/dashboard`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
initData
|
||||
})
|
||||
})
|
||||
|
||||
const payload = (await response.json()) as {
|
||||
ok: boolean
|
||||
authorized?: boolean
|
||||
dashboard?: MiniAppDashboard
|
||||
error?: string
|
||||
}
|
||||
|
||||
if (!response.ok || !payload.authorized || !payload.dashboard) {
|
||||
throw new Error(payload.error ?? 'Failed to load dashboard')
|
||||
}
|
||||
|
||||
return payload.dashboard
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user