-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a130712
commit 081da3a
Showing
4 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useSpvWalletClient } from '@/contexts'; | ||
import { userBalanceQueryOptions } from '@/utils/userBalanceQueryOptions'; | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { Badge } from '../ui'; | ||
import { WalletIcon } from 'lucide-react'; | ||
|
||
export const UserBalance = () => { | ||
const { spvWalletClient } = useSpvWalletClient(); | ||
|
||
const { data: balance } = useSuspenseQuery( | ||
userBalanceQueryOptions({ | ||
spvWalletClient: spvWalletClient!, | ||
}), | ||
); | ||
|
||
return ( | ||
<> | ||
{balance ? ( | ||
<Badge variant="outline" className="p-2 pl-3 pr-3 flex justify-center items-center gap-2"> | ||
<WalletIcon size="16px" /> | ||
{balance.toLocaleString()} SATS | ||
</Badge> | ||
) : null} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './UserBalance.tsx'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { SpvWalletClientExtended } from '@/contexts'; | ||
import { queryOptions } from '@tanstack/react-query'; | ||
|
||
export interface UserBalanceQueryOptions { | ||
spvWalletClient: SpvWalletClientExtended; | ||
} | ||
|
||
export const userBalanceQueryOptions = (opts: UserBalanceQueryOptions) => { | ||
return queryOptions({ | ||
queryKey: ['balance', opts], | ||
queryFn: async () => { | ||
const user = await opts.spvWalletClient.GetUserInfo(); | ||
return user.currentBalance; | ||
}, | ||
}); | ||
}; |