Skip to content

Commit

Permalink
fix: fallback failed usd value
Browse files Browse the repository at this point in the history
  • Loading branch information
grikomsn committed Nov 28, 2023
1 parent 36602be commit b958abf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/UsdValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import { create } from "zustand";
import { Args, useUsdDiffValue, useUsdValue } from "@/hooks/useUsdValue";

type UsdValueProps = Args & {
error?: ReactNode;
loading?: ReactNode;
context?: "src" | "dest";
};

export const UsdValue = ({
error = "Price not available",
loading = "...",
context,
...args
}: UsdValueProps) => {
const { data: usdValue = 0, isLoading } = useUsdValue(args);
const { data: usdValue = 0, isError, isLoading } = useUsdValue(args);

const prevValue = useRef(usdValue);
useEffect(() => {
Expand All @@ -32,6 +34,10 @@ export const UsdValue = ({
}
});

if (isError) {
return <>{error}</>;
}

if (isLoading && prevValue.current) {
return <>{`$${prevValue.current.toFixed(2)}`}</>;
}
Expand Down

0 comments on commit b958abf

Please sign in to comment.