-
Notifications
You must be signed in to change notification settings - Fork 9
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
6e0876c
commit 974c2a0
Showing
8 changed files
with
135 additions
and
59 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
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
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,64 @@ | ||
import { pagoda } from "@/common/api/pagoda"; | ||
import { | ||
NEAR_DEFAULT_TOKEN_DECIMALS, | ||
NEAR_TOKEN_DENOM, | ||
} from "@/common/constants"; | ||
import { bigNumToFloat } from "@/common/lib"; | ||
import { ByTokenId } from "@/common/types"; | ||
import { Skeleton } from "@/common/ui/components"; | ||
|
||
import { TokenIcon } from "./TokenIcon"; | ||
import { useNearUsdDisplayValue } from "../hooks/price"; | ||
|
||
export type TotalTokenValueProps = ByTokenId & | ||
({ amountFloat: number } | { amountBig: number }); | ||
|
||
export const TotalTokenValue = ({ | ||
tokenId, | ||
...props | ||
}: TotalTokenValueProps) => { | ||
const { isLoading: isTokenMetadataLoading, data: tokenMetadata } = | ||
pagoda.useTokenMetadata({ | ||
tokenId, | ||
}); | ||
|
||
const amount = | ||
"amountFloat" in props | ||
? props.amountFloat | ||
: bigNumToFloat( | ||
props.amountBig.toString(), | ||
tokenMetadata?.decimals ?? NEAR_DEFAULT_TOKEN_DECIMALS, | ||
); | ||
|
||
const totalNearAmountUsdDisplayValue = useNearUsdDisplayValue(amount); | ||
|
||
const totalAmountUsdDisplayValue = | ||
tokenId === NEAR_TOKEN_DENOM ? totalNearAmountUsdDisplayValue : null; | ||
|
||
return ( | ||
<div un-flex="~" un-items="center" un-gap="2"> | ||
<TokenIcon {...{ tokenId }} /> | ||
|
||
{isTokenMetadataLoading ? ( | ||
<Skeleton className="" /> | ||
) : ( | ||
<span | ||
className="prose line-height-none" | ||
un-mt="0.7" | ||
un-text="xl" | ||
un-font="600" | ||
>{`${amount} ${tokenMetadata?.symbol ?? "⋯"}`}</span> | ||
)} | ||
|
||
{totalAmountUsdDisplayValue && ( | ||
<span | ||
className="prose line-height-none" | ||
un-mt="0.7" | ||
un-text="gray-500 xl" | ||
> | ||
{totalAmountUsdDisplayValue} | ||
</span> | ||
)} | ||
</div> | ||
); | ||
}; |
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
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