-
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.
Merge pull request #54 from bleu/pedro/cow-311-copy-minor-cow-feedbacks
Pedro/cow 311 copy minor cow feedbacks
- Loading branch information
Showing
41 changed files
with
2,193 additions
and
1,963 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,26 +1,84 @@ | ||
"use client"; | ||
|
||
import { formatNumber } from "@bleu/ui"; | ||
import { | ||
Collapsible, | ||
CollapsibleContent, | ||
CollapsibleTrigger, | ||
formatNumber, | ||
} from "@bleu/ui"; | ||
import { ChevronDownIcon, ChevronUpIcon } from "@radix-ui/react-icons"; | ||
import { useState } from "react"; | ||
import { useFormContext, useWatch } from "react-hook-form"; | ||
|
||
import { useTokens } from "#/contexts/tokensContext"; | ||
import { SwapData } from "#/lib/types"; | ||
|
||
export function CurrentMarketPrice() { | ||
const { control } = useFormContext<SwapData>(); | ||
|
||
const [tokenSell, tokenBuy, marketPrice] = useWatch({ | ||
const [tokenSell, tokenBuy] = useWatch({ | ||
control, | ||
name: ["tokenSell", "tokenBuy", "marketPrice"], | ||
name: ["tokenSell", "tokenBuy"], | ||
}); | ||
const [open, setOpen] = useState(false); | ||
|
||
const { useTokenPairPrice, useTokenPrice } = useTokens(); | ||
const { data: tokenBuyPrice } = useTokenPrice(tokenBuy); | ||
const { data: tokenSellPrice } = useTokenPrice(tokenSell); | ||
const { data: marketPrice } = useTokenPairPrice(tokenSell, tokenBuy); | ||
|
||
if (!tokenSell || !tokenBuy || !marketPrice || marketPrice <= 0) return null; | ||
|
||
const formatPrice = (price: number) => | ||
formatNumber(price, 6, "currency", "standard"); | ||
const formatDecimal = (price: number) => | ||
formatNumber(price, 6, "decimal", "standard"); | ||
const inversePrice = 1 / marketPrice; | ||
|
||
return ( | ||
<span className="text-xs"> | ||
Current market price:{" "} | ||
<b> | ||
{tokenSell.symbol} = {formatNumber(marketPrice, 4)}{" "} | ||
</b> | ||
{tokenBuy.symbol} | ||
</span> | ||
<div className="text-xs font-mono p-2 rounded-lg text-white inline-block"> | ||
<Collapsible open={open} onOpenChange={setOpen}> | ||
<div className="flex items-center justify-between"> | ||
<span className="w-24 flex space-x-1 hover:opacity-100 opacity-50"> | ||
<span>1 {tokenSell.symbol} </span> | ||
<CollapsibleTrigger> | ||
{open ? ( | ||
<ChevronUpIcon className="size-3" /> | ||
) : ( | ||
<ChevronDownIcon className="size-3" /> | ||
)} | ||
</CollapsibleTrigger> | ||
</span> | ||
|
||
<div className="flex items-center justify-end flex-1 space-x-2"> | ||
<span className="text-right whitespace-nowrap"> | ||
{formatDecimal(inversePrice)} {tokenBuy.symbol} | ||
</span> | ||
{tokenSellPrice && ( | ||
<span className="opacity-50 text-right whitespace-nowrap"> | ||
~{formatPrice(tokenSellPrice)} | ||
</span> | ||
)} | ||
</div> | ||
</div> | ||
|
||
<CollapsibleContent> | ||
<div className="flex items-center justify-between mt-1"> | ||
<span className="w-24 hover:opacity-100 opacity-50"> | ||
1 {tokenBuy.symbol} | ||
</span> | ||
<div className="flex items-center justify-end flex-1 space-x-2"> | ||
<span className="text-right whitespace-nowrap"> | ||
{formatDecimal(marketPrice)} {tokenSell.symbol} | ||
</span> | ||
{tokenBuyPrice && ( | ||
<span className="opacity-50 text-right whitespace-nowrap"> | ||
~{formatPrice(tokenBuyPrice)} | ||
</span> | ||
)} | ||
</div> | ||
</div> | ||
</CollapsibleContent> | ||
</Collapsible> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.