@@ -5,8 +5,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
55import { Bar , BarChart , CartesianGrid , XAxis , YAxis } from "recharts"
66import { type ChartConfig , ChartContainer , ChartLegend , ChartLegendContent } from "@/components/ui/chart"
77import { Skeleton } from "@/components/ui/skeleton"
8- import { debitBalance , creditBalance } from "@/generated/client/sdk.gen"
9- // import { ECashBalance } from "@/generated/client/types.gen"
8+ import { debitBalance , creditBalance , onchainBalance } from "@/generated/client/sdk.gen"
109
1110function Loader ( ) {
1211 return (
@@ -155,11 +154,15 @@ function useBalances() {
155154
156155 try {
157156 // Fetch both credit and debit balances concurrently
158- const [ creditResponse , debitResponse ] = await Promise . allSettled ( [ creditBalance ( { } ) , debitBalance ( { } ) ] )
157+ const [ creditResponse , debitResponse , onchainResponse ] = await Promise . allSettled ( [
158+ creditBalance ( { } ) ,
159+ debitBalance ( { } ) ,
160+ onchainBalance ( { } ) ,
161+ ] )
159162
160163 const newBalances : Record < string , BalanceDisplay > = {
161- bitcoin : { amount : "0" , unit : "BTC" } , // TODO: Implement bitcoin balance fetching
162- eiou : { amount : "0" , unit : "eIOU" } , // TODO: Implement e-IOU balance fetching
164+ bitcoin : { amount : "0" , unit : "BTC" } ,
165+ eiou : { amount : "0" , unit : "eIOU" } ,
163166 credit : { amount : "0" , unit : "credit" } ,
164167 debit : { amount : "0" , unit : "debit" } ,
165168 }
@@ -196,6 +199,22 @@ function useBalances() {
196199 )
197200 }
198201
202+ if ( onchainResponse . status === "fulfilled" && ! isErrorResponse ( onchainResponse . value ) ) {
203+ const onchainData = onchainResponse . value . data
204+ if ( onchainData && typeof onchainData === "object" && "confirmed" in onchainData ) {
205+ console . log ( "Onchain balance:" , onchainData . confirmed )
206+ newBalances . bitcoin = {
207+ amount : String ( onchainData . confirmed ) ,
208+ unit : "BTC" ,
209+ }
210+ }
211+ } else {
212+ console . warn (
213+ "Failed to fetch onchain balance:" ,
214+ onchainResponse . status === "rejected" ? onchainResponse . reason : onchainResponse . value . error ,
215+ )
216+ }
217+
199218 setBalances ( newBalances )
200219 } catch ( error ) {
201220 const errorMessage = error instanceof Error ? error . message : "Unknown error occurred"
0 commit comments