Skip to content

Commit

Permalink
add getPriceInUsd
Browse files Browse the repository at this point in the history
  • Loading branch information
dkackman committed Jan 18, 2025
1 parent 030de4c commit 80698c9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/contexts/PriceContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {

export interface PriceContextType {
getBalanceInUsd: (assetId: string, balance: string) => string;
getPriceInUsd: (assetId: string) => number;
}

export const PriceContext = createContext<PriceContextType | undefined>(
Expand Down Expand Up @@ -63,6 +64,16 @@ export function PriceProvider({ children }: { children: ReactNode }) {
}
}, [walletState.sync.unit.ticker]);

const getPriceInUsd = useCallback(
(assetId: string) => {
if (assetId === 'xch') {
return xchUsdPrice;
}
return (catPrices[assetId] || 0) * xchUsdPrice;
},
[xchUsdPrice, catPrices],
);

const getBalanceInUsd = useCallback(
(assetId: string, balance: string) => {
if (assetId === 'xch') {
Expand All @@ -78,7 +89,7 @@ export function PriceProvider({ children }: { children: ReactNode }) {
);

return (
<PriceContext.Provider value={{ getBalanceInUsd }}>
<PriceContext.Provider value={{ getBalanceInUsd, getPriceInUsd }}>
{children}
</PriceContext.Provider>
);
Expand Down

0 comments on commit 80698c9

Please sign in to comment.