-
Notifications
You must be signed in to change notification settings - Fork 0
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
336915c
commit 5993e5f
Showing
37 changed files
with
4,220 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import { MonikerIcons } from "@/constants/tokens"; | ||
import { Avatar, Typography } from "@mochi-ui/core"; | ||
import clsx from "clsx"; | ||
import { SVGProps } from "react"; | ||
|
||
interface AmountProps { | ||
value: string; | ||
valueUsd?: string; | ||
tokenIcon?: string; | ||
platformIcon?: string | ((props: SVGProps<SVGSVGElement>) => JSX.Element); | ||
unit?: string; | ||
approxMoniker?: string; | ||
className?: string; | ||
size?: "sm" | "base" | "md" | "lg"; | ||
// 14 16 24 32 | ||
isMultipleTokens?: boolean; | ||
isMoniker?: boolean; | ||
alignment?: "left" | "center"; | ||
inline?: boolean; | ||
} | ||
|
||
const titleSize: any = { | ||
sm: "h9", | ||
base: "h7", | ||
md: "h5", | ||
lg: "h4", | ||
}; | ||
|
||
const subtitleSize: any = { | ||
sm: "p6", | ||
base: "p6", | ||
md: "p6", | ||
lg: "p5", | ||
}; | ||
|
||
const iconSize: any = { | ||
sm: 16, | ||
base: 16, | ||
md: 24, | ||
lg: 32, | ||
}; | ||
|
||
export default function Amount({ | ||
value, | ||
valueUsd, | ||
tokenIcon = "", | ||
platformIcon, | ||
unit, | ||
approxMoniker, | ||
className = "", | ||
size = "md", | ||
isMultipleTokens = false, | ||
alignment = "center", | ||
isMoniker, | ||
inline = false, | ||
}: AmountProps) { | ||
const isLongNumber = value.length >= 12; | ||
|
||
return ( | ||
<div | ||
style={{ | ||
gridTemplateColumns: `${iconSize[size]}px minmax(0, 1fr)`, | ||
gridTemplateRows: !isLongNumber | ||
? "minmax(0, 1fr) min-content" | ||
: `${iconSize[size]}px minmax(0, 1fr) min-content`, | ||
}} | ||
className={clsx("shrink-0 gap-x-2 font-medium text-left", className, { | ||
grid: !inline, | ||
"inline-grid": inline, | ||
"gap-y-1.5 grid-cols-1": isLongNumber, | ||
})} | ||
> | ||
<div className="h-8 flex items-center"> | ||
{isMoniker ? ( | ||
<div className="my-auto flex justify-center items-center w-7 h-7 rounded-full border border-[#E5E4E3]"> | ||
<span className="text-sm">{MonikerIcons.get(tokenIcon)}</span> | ||
</div> | ||
) : ( | ||
<Avatar | ||
size={size === "lg" || size === "md" ? "xs" : "xxs"} | ||
className={clsx("shrink-0 aspect-square [&>img]:rounded-none", { | ||
/* 'my-1': size === 'md' && alignment === 'center' && !isLongNumber, */ | ||
"row-start-1 row-span-2 my-auto": | ||
alignment === "left" && !isLongNumber, | ||
"mx-auto": isLongNumber, | ||
})} | ||
src={tokenIcon} | ||
smallSrc={platformIcon} | ||
/> | ||
)} | ||
</div> | ||
<div | ||
className={clsx("flex gap-x-1 items-center", { | ||
"flex-col items-center": isLongNumber, | ||
})} | ||
> | ||
<Typography | ||
level={titleSize[size]} | ||
className="!leading-[1] font-mono" | ||
fontWeight="md" | ||
> | ||
{value} | ||
</Typography> | ||
<Typography | ||
level={titleSize[size]} | ||
className="!leading-[1] font-mono" | ||
fontWeight="md" | ||
> | ||
{unit} | ||
</Typography> | ||
</div> | ||
{(valueUsd || isMultipleTokens) && ( | ||
<div | ||
className={clsx({ | ||
"col-start-1 col-span-2 text-center": | ||
alignment === "center" && !isLongNumber, | ||
"col-start-2 col-span-1": alignment === "left" && !isLongNumber, | ||
"text-center": isLongNumber, | ||
})} | ||
> | ||
{isMultipleTokens && ( | ||
<Typography | ||
level={subtitleSize[size]} | ||
color="textSecondary" | ||
fontWeight="md" | ||
className="font-mono" | ||
> | ||
and other tokens | ||
</Typography> | ||
)} | ||
<Typography | ||
level={subtitleSize[size]} | ||
fontWeight="md" | ||
color="textTertiary" | ||
className="font-mono" | ||
> | ||
{approxMoniker} {valueUsd?.startsWith("<") ? "" : <>≈</>}{" "} | ||
{valueUsd} | ||
</Typography> | ||
</div> | ||
)} | ||
</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
Oops, something went wrong.