Skip to content

Commit

Permalink
run lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yvesfracari committed Nov 22, 2024
1 parent ba07c53 commit df2fb7d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 31 deletions.
16 changes: 7 additions & 9 deletions apps/deposit-pool/src/components/PoolForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { useCallback, useEffect, useMemo } from "react";
import { useFormContext, useWatch } from "react-hook-form";
import { type Address, formatUnits } from "viem";
import { usePoolBalance } from "#/hooks/usePoolBalance";
import { useSwapAmount } from "#/hooks/useSwapAmount";
import { useTokenBalanceAfterSwap } from "#/hooks/useTokenBalanceAfterSwap";
import type { FormType } from "#/types";
import { formDefaultValues } from "#/utils/formDefaultValues";
import { calculateProportionalTokenAmounts, getTokenPrice } from "#/utils/math";
Expand All @@ -23,10 +21,10 @@ export function PoolForm({ pool }: { pool: IPool | undefined }) {
const { context } = useIFrameContext();
const { control, setValue, reset } = useFormContext<FormType>();

const { buyAmount } = useSwapAmount();
const buyAmountAfterSwap = useTokenBalanceAfterSwap(
context?.orderParams?.buyTokenAddress as Address
);
// const { buyAmount } = useSwapAmount();
// const _buyAmountAfterSwap = useTokenBalanceAfterSwap(
// context?.orderParams?.buyTokenAddress as Address,
// );

const { data: poolBalances, isLoading: isBalanceLoading } = usePoolBalance({
poolId: pool?.id,
Expand All @@ -46,7 +44,7 @@ export function PoolForm({ pool }: { pool: IPool | undefined }) {

const tokenPrices = useMemo(
() => poolBalances?.map((poolBalance) => getTokenPrice(poolBalance)),
[poolBalances]
[poolBalances],
);

const totalUsd = useMemo(() => {
Expand Down Expand Up @@ -82,14 +80,14 @@ export function PoolForm({ pool }: { pool: IPool | undefined }) {
const tokenAmountKey = `amounts.${tokenAmountAddress}` as const;
const calculatedAmount = formatUnits(
tokenAmount.rawAmount,
tokenAmount.decimals
tokenAmount.decimals,
);
setValue(tokenAmountKey, calculatedAmount);
}

setValue("referenceTokenAddress", address);
},
[poolBalances, tokenPrices, pool, setValue]
[poolBalances, tokenPrices, pool, setValue],
);

// useEffect(() => {
Expand Down
16 changes: 8 additions & 8 deletions apps/deposit-pool/src/components/TokenAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
import { useCallback, useMemo } from "react";
import { useFormContext, useWatch } from "react-hook-form";
import type { Address } from "viem";
import { useSwapAmount } from "#/hooks/useSwapAmount";
import { useTokenBalanceAfterSwap } from "#/hooks/useTokenBalanceAfterSwap";
import type { FormType } from "#/types";
import { constraintStringToBeNumeric } from "#/utils/constraintStringToBeNumeric";
import { useSwapAmount } from "#/hooks/useSwapAmount";

export function TokenAmountInput({
poolBalance,
Expand All @@ -36,7 +36,7 @@ export function TokenAmountInput({
// });

const tokenBalanceAfterSwap = useTokenBalanceAfterSwap(
poolBalance.token.address
poolBalance.token.address,
);

const isTokenBuy = useMemo(() => {
Expand All @@ -59,11 +59,11 @@ export function TokenAmountInput({
if (updateTokenAmounts) {
updateTokenAmounts(
constraintStringToBeNumeric(amount),
poolBalance.token.address as Address
poolBalance.token.address as Address,
);
}
},
[updateTokenAmounts, poolBalance.token.address]
[updateTokenAmounts, poolBalance.token.address],
);

// const disabled = amountType !== "userInput";
Expand Down Expand Up @@ -101,7 +101,7 @@ export function TokenAmountInput({
onChange(e.target.value);
setValue(
`amounts.${poolBalance.token.address.toLowerCase()}`,
constraintStringToBeNumeric(e.target.value)
constraintStringToBeNumeric(e.target.value),
);
},
})}
Expand All @@ -127,7 +127,7 @@ export function TokenAmountInput({
4,
"decimal",
"standard",
0.0001
0.0001,
).replace(/\.?0+$/, "") || "0"}
</span>
{!maxButtonDisabled && (
Expand All @@ -138,7 +138,7 @@ export function TokenAmountInput({
onClick={() => {
setValue(
`amounts.${poolBalance.token.address.toLowerCase()}`,
tokenBalanceAfterSwap
tokenBalanceAfterSwap,
);
onChange(tokenBalanceAfterSwap);
}}
Expand All @@ -154,7 +154,7 @@ export function TokenAmountInput({
onClick={() => {
setValue(
`amounts.${poolBalance.token.address.toLowerCase()}`,
buyAmount
buyAmount,
);
onChange(buyAmount);
}}
Expand Down
4 changes: 2 additions & 2 deletions apps/deposit-pool/src/utils/decodeCalldata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { FormType } from "#/types";

export const decodeCalldata = async (
string: `0x${string}`,
publicClient: PublicClient
publicClient: PublicClient,
): Promise<FormType> => {
const encodedFormData = string.slice(-290);

Expand Down Expand Up @@ -61,7 +61,7 @@ export const decodeCalldata = async (
const referenceTokenAddress = `0x${encodedFormData.slice(248, 288)}`;

// const optionSelected = decodeSelectedOption(encodedFormData[289]);
const optionSelected = "userInput";
const _optionSelected = "userInput";

const result = {
poolId,
Expand Down
7 changes: 3 additions & 4 deletions apps/deposit-pool/src/utils/encodeFormData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ export function encodeFormData(data: FormType): string {
// const optionSelected = processSelectedOption(data); // size = 2

// total size = 288
const result =
const result = `${
encodedPoolId +
encodedToken1 +
encodedToken2 +
encodedAmount1 +
encodedAmount2 +
encodedReferenceTokenAddress +
// optionSelected;
"00";
encodedReferenceTokenAddress
}00`;

return result;
}
12 changes: 6 additions & 6 deletions apps/deposit-pool/src/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ export function calculateProportionalTokenAmounts({
const referenceToken =
poolBalances.find(
(balance) =>
balance.token.address.toLowerCase() === tokenAddress.toLowerCase()
balance.token.address.toLowerCase() === tokenAddress.toLowerCase(),
) || poolBalances[0];

return calculateProportionalAmounts(
{
address: pool.address,
totalShares: formatUnits(
BigInt(pool.dynamicData.totalShares.toString()),
pool.decimals
pool.decimals,
) as `${number}`,
tokens: poolBalances.map((balance) => ({
address: balance.token.address.toLowerCase() as Address,
balance: formatUnits(
BigInt(balance.balance.toString()),
balance.token.decimals
balance.token.decimals,
) as `${number}`,
decimals: balance.token.decimals,
})),
Expand All @@ -46,7 +46,7 @@ export function calculateProportionalTokenAmounts({
address: referenceToken.token.address.toLowerCase() as Address,
decimals: referenceToken.token.decimals,
rawAmount: parseUnits(tokenAmount, referenceToken.token.decimals),
}
},
);
}

Expand Down Expand Up @@ -75,7 +75,7 @@ export function updateTokenBalanceAfterSwap({
) {
return formatUnits(
balance - parseUnits(sellAmount, tokenDecimals),
tokenDecimals
tokenDecimals,
) as `${number}`;
}

Expand All @@ -85,7 +85,7 @@ export function updateTokenBalanceAfterSwap({
) {
return formatUnits(
balance + parseUnits(buyAmount, tokenDecimals),
tokenDecimals
tokenDecimals,
) as `${number}`;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cow-hooks-ui/src/ui/TokenAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function TokenAmountInput({
<Input
className={cn(
"outline-none font-semibold text-xl text-color-text-paper bg-inherit placeholder:opacity-70 text-xl text-color-text-paper bg-inherit placeholder:opacity-70 text-right p-0 m-0 h-min border-none rounded-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none truncate",
className
className,
)}
{...register(name, validation)}
{...props}
Expand Down
2 changes: 1 addition & 1 deletion packages/cow-hooks-ui/src/ui/TooltipBase.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { cn, Tooltip, TooltipTrigger } from "@bleu.builders/ui";
import { Tooltip, TooltipTrigger, cn } from "@bleu.builders/ui";
import {
ExclamationTriangleIcon,
InfoCircledIcon,
Expand Down

0 comments on commit df2fb7d

Please sign in to comment.