Skip to content

Commit

Permalink
fix: do not display approx and warnings anymore for buy orders
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanNeiverth committed Oct 28, 2024
1 parent 832b1b4 commit e55e2d5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/create-vesting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@bleu/ui": "0.1.131",
"@bleu/utils": "workspace:*",
"@cowprotocol/cow-sdk": "^5.5.1",
"@cowprotocol/hook-dapp-lib": "1.1.0-RC0",
"@cowprotocol/hook-dapp-lib": "1.2.0",
"@hookform/resolvers": "3.9.0",
"@radix-ui/react-icons": "1.3.0",
"@uniswap/sdk-core": "5.4.0",
Expand Down
8 changes: 7 additions & 1 deletion apps/create-vesting/src/components/AmountInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TokenAmountInput } from "@bleu/cow-hooks-ui";
import { TokenAmountInput, useIFrameContext } from "@bleu/cow-hooks-ui";
import type { Token } from "@uniswap/sdk-core";

export const AmountInput = ({
Expand All @@ -20,6 +20,8 @@ export const AmountInput = ({
userBalanceFloat: number | undefined;
shouldEnableMaxSelector: boolean;
}) => {
const { context } = useIFrameContext();

return (
<TokenAmountInput
name="amount"
Expand All @@ -37,6 +39,10 @@ export const AmountInput = ({
userBalance={formattedUserBalance}
userBalanceFullDecimals={String(userBalanceFloat)}
shouldEnableMaxSelector={shouldEnableMaxSelector}
shouldDisplayApprox={
//@ts-ignore
context?.orderParams.kind === "sell"
}
validation={{
setValueAs: (v) => (v === "" ? undefined : Number(v)),
required: !(vestAllFromAccount || vestAllFromSwap),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { Checkbox } from "@bleu/cow-hooks-ui";
import { Checkbox, useIFrameContext } from "@bleu/cow-hooks-ui";
import { useFormContext } from "react-hook-form";

export const VestAllFromAccountCheckbox = () => {
const { setValue } = useFormContext();
const { context } = useIFrameContext();

return (
<Checkbox
name="vestAllFromAccount"
label="Use all your tokens after swap"
isSelectedMessage="The token buy amount may vary due to price changes."
isSelectedMessage={
//@ts-ignore
context?.orderParams?.kind === "sell"
? "The token buy amount may vary due to price changes."
: undefined
}
onSelectSideEffect={() => {
setValue("amount", undefined);
setValue("vestUserInput", false);
Expand Down
10 changes: 8 additions & 2 deletions apps/create-vesting/src/components/VestAllFromSwapCheckbox.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { Checkbox } from "@bleu/cow-hooks-ui";
import { Checkbox, useIFrameContext } from "@bleu/cow-hooks-ui";
import { useFormContext } from "react-hook-form";

export const VestAllFromSwapCheckbox = () => {
const { setValue } = useFormContext();
const { context } = useIFrameContext();

return (
<Checkbox
name="vestAllFromSwap"
label="Use all tokens from swap"
isSelectedMessage="The token buy amount may vary due to price changes."
isSelectedMessage={
//@ts-ignore
context?.orderParams?.kind === "sell"
? "The token buy amount may vary due to price changes."
: undefined
}
onSelectSideEffect={() => {
setValue("amount", undefined);
setValue("vestUserInput", false);
Expand Down
5 changes: 4 additions & 1 deletion packages/cow-hooks-ui/src/ui/TokenAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ITokenAmountInput
userBalance?: string | undefined;
userBalanceFullDecimals?: string | undefined;
shouldEnableMaxSelector?: boolean;
shouldDisplayApprox?: boolean;
}

export function TokenAmountInput({
Expand All @@ -42,6 +43,7 @@ export function TokenAmountInput({
userBalance,
userBalanceFullDecimals,
shouldEnableMaxSelector,
shouldDisplayApprox,
...props
}: ITokenAmountInput) {
const { register, control, setValue } = useFormContext();
Expand Down Expand Up @@ -77,7 +79,8 @@ export function TokenAmountInput({
title={disabledValueFullDecimals}
className="outline-none text-right p-0 m-0 border-none text-xl text-color-text-paper bg-inherit placeholder:opacity-70 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none cursor-default"
>
{disabledValue}
{shouldDisplayApprox && "≈ "}
{disabledValue}
</span>
) : (
<Input
Expand Down
11 changes: 9 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e55e2d5

Please sign in to comment.