Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/components/TotalWalletValue.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react'
import { formatNumberAbbreviated } from '@/utils/formatting'
import useKaspa from '@/hooks/contexts/useKaspa'
import LoadingPlaceholder from '@/components/animations/LoadingPlaceholder'

interface TotalValueProps {
totalValue: number
Expand All @@ -8,10 +10,18 @@ interface TotalValueProps {
const TotalWalletValue: React.FC<TotalValueProps> = ({ totalValue }) => {
const formattedCurrencyValue = formatNumberAbbreviated(totalValue, true)

const { kaspa } = useKaspa()

return (
<h1 className="text-primarytext font-rubik text-center flex-grow text-4xl py-4">
{formattedCurrencyValue}
</h1>
<>
<h1 className="text-primarytext text-center w-2/3 font-rubik flex-grow text-4xl py-4 flex justify-center">
{kaspa.balanceValid ? (
<> {formattedCurrencyValue} </>
) : (
<LoadingPlaceholder className="flex-grow font-rubik py-4 h-10 max-h-10 w-2/3" />
)}
</h1>
</>
)
}

Expand Down
7 changes: 7 additions & 0 deletions src/components/animations/LoadingPlaceholder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'

const LoadingPlaceholder: React.FC<{ className: string }> = ({ className }) => (
<div className={`bg-muted animate-pulse ${className}`} />
)

export default LoadingPlaceholder
1 change: 1 addition & 0 deletions src/contexts/kaspa/KaspaContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const defaultState: IKaspa = {
connected: false,
addresses: [],
balance: 0,
balanceValid: false,
utxos: [],
provider: '',
}
Expand Down
3 changes: 3 additions & 0 deletions src/contexts/kaspa/KaspaProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export function KaspaProvider({ children }: { children: ReactNode }) {
case 'account:balance':
dispatch({ type: 'balance', payload: message.data })
dispatch({ type: 'utxos', payload: await request('account:utxos', []) })
dispatch({ type: 'balanceValid', payload: true })
break
case 'account:addresses':
dispatch({
Expand All @@ -140,6 +141,8 @@ export function KaspaProvider({ children }: { children: ReactNode }) {
dispatch({ type: 'connected', payload: connected })
const balance = await request('account:balance', [])
dispatch({ type: 'balance', payload: balance })
const balanceValid = await request('account:balanceValid', [])
dispatch({ type: 'balanceValid', payload: balanceValid })
const utxos = await request('account:utxos', [])
dispatch({ type: 'utxos', payload: utxos })
const addresses = await request('account:addresses', [])
Expand Down
1 change: 1 addition & 0 deletions src/contexts/kaspa/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface IKaspa {
connected: boolean
addresses: string[]
balance: number
balanceValid: boolean
utxos: UTXO[]
provider: string
}
Expand Down
9 changes: 8 additions & 1 deletion src/pages/Wallet/CryptoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import ErrorMessage from '@/components/messages/ErrorMessage'
import { useLocation, useNavigate } from 'react-router-dom'
import { usePrices } from '@/hooks/ghost/usePrice'
import useVisibleTokens from '@/hooks/wallet/useVisibleTokens'
import useKaspa from '@/hooks/contexts/useKaspa'
import LoadingPlaceholder from '@/components/animations/LoadingPlaceholder'

interface CryptoListProps {
onTotalValueChange: (value: number) => void
Expand All @@ -21,6 +23,7 @@ const CryptoList: React.FC<CryptoListProps> = ({ onTotalValueChange }) => {
const kasPrice = prices.data?.kaspa?.price ?? 0

const visibleTokens = useVisibleTokens(tokens)
const { kaspa } = useKaspa()

useTotalValueCalculation(visibleTokens, kasPrice, onTotalValueChange)

Expand All @@ -44,7 +47,11 @@ const CryptoList: React.FC<CryptoListProps> = ({ onTotalValueChange }) => {
onClick={() => handleTokenClick(token)}
className="w-full text-left transition-colors hover:cursor-pointer rounded-lg"
>
<CryptoListItem token={token} />
{kaspa.balanceValid ? (
<CryptoListItem token={token} />
) : (
<LoadingPlaceholder className="flex-grow w-full h-20 p-3 rounded-lg" />
)}
</li>
))}
</ul>
Expand Down
5 changes: 1 addition & 4 deletions src/pages/Wallet/Mint/CreateMint/LoadingCreateMint.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import React from 'react'

const LoadingPlaceholder: React.FC<{ className: string }> = ({ className }) => (
<div className={`bg-muted animate-pulse ${className}`} />
)
import LoadingPlaceholder from '@/components/animations/LoadingPlaceholder'

export default function LoadingCreateMint() {
return (
Expand Down
4 changes: 4 additions & 0 deletions src/wallet/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export default class Account extends EventEmitter {
return Number(this.context.balance?.mature ?? 0) / 1e8
}

get balanceValid() {
return this.context.balance != undefined
}

get UTXOs() {
const mapUTXO = (utxo: UtxoEntryReference, mature: boolean) => ({
amount: Number(utxo.amount) / 1e8,
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/messaging/RequestMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface RequestMappings {
'node:submit': [string[]]
'account:addresses': []
'account:balance': []
'account:balanceValid': []
'account:utxos': []
'account:estimateKaspaTransactionFee': [[string, string][], number, string]
'account:create': [[string, string][], number, string, CustomInput[]?]
Expand Down Expand Up @@ -45,6 +46,7 @@ export interface EventMappings {
'node:connection': boolean
'node:network': string
'account:balance': number
'account:balanceValid': boolean
'account:addresses': string[]
'provider:connection': string
}
Expand Down
1 change: 1 addition & 0 deletions src/wallet/messaging/ResponseMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ResponseMappings {
'node:submit': string[]
'account:addresses': string[]
'account:balance': number
'account:balanceValid': boolean
'account:utxos': UTXO[]
'account:estimateKaspaTransactionFee': string
'account:create': [string[], string]
Expand Down
1 change: 1 addition & 0 deletions src/wallet/messaging/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class Router {
'node:submit': (transactions) => node.submit(transactions),
'account:addresses': () => account.addresses.receiveAddresses,
'account:balance': () => account.balance,
'account:balanceValid': () => account.balanceValid,
'account:utxos': () => account.UTXOs,
'account:estimateKaspaTransactionFee': (outputs, feeRate, fee) =>
account.transactions.estimateKaspaTransactionFee(outputs, feeRate, fee),
Expand Down
Loading