Skip to content

Commit

Permalink
usd value crypto (#3314)
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-justin authored Sep 20, 2024
1 parent 4eb6ccd commit 7f4baf3
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/components/TokenField/TokenField.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { roundToCents, unpack } from "helpers";
import { humanize, roundToCents, unpack } from "helpers";
import { forwardRef, useEffect, useState } from "react";
import { number } from "yup";
import TokenSelector from "./TokenSelector";
import type { Props, Token } from "./types";

type El = HTMLInputElement;

const multipliable = (amount: string) =>
number().min(0).isValidSync(amount) ? +amount : 0;

const TokenField: React.ForwardRefRenderFunction<El, Props> = (props, ref) => {
const style = unpack(props.classes);
const [tokenState, setTokenState] = useState<Token.State>("ok");
Expand All @@ -20,12 +24,22 @@ const TokenField: React.ForwardRefRenderFunction<El, Props> = (props, ref) => {

return (
<div className={`grid ${style.container}`}>
<label
htmlFor="amount"
className={`font-semibold mr-auto mb-2 after:content-['_*'] after:text-red ${style.label}`}
>
{props.label}
</label>
<div className="flex items-center gap-2">
<label
htmlFor="amount"
className={`font-semibold mr-auto mb-2 after:content-['_*'] after:text-red ${style.label}`}
>
{props.label}
</label>
<span className="text-navy-l1 text-sm mr-1">
{tokenState === "ok"
? `$ ${humanize(
props.token.rate * multipliable(props.token.amount),
2
)}`
: "$ --"}
</span>
</div>

<div
className={`${style.inputContainer} relative grid grid-cols-[1fr_auto] items-center gap-2 field-container`}
Expand Down

0 comments on commit 7f4baf3

Please sign in to comment.