Skip to content

Commit

Permalink
update file locations
Browse files Browse the repository at this point in the history
  • Loading branch information
jnastaskin committed Aug 14, 2024
1 parent a33452a commit a4a4a8b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 34 deletions.
6 changes: 3 additions & 3 deletions packages/app/src/lib/components/foil/addEditLiquidity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ import {
} from 'wagmi';

import erc20ABI from '../../erc20abi.json';
import { getNewLiquidity } from '../util/positionUtil';
import { renderContractErrorToast, renderToastSuccess } from '../util/util';
import { getNewLiquidity } from '../../util/positionUtil';
import { renderContractErrorToast, renderToastSuccess } from '../../util/util';
import { TOKEN_DECIMALS } from '~/lib/constants/constants';
import { useLoading } from '~/lib/context/LoadingContext';
import { MarketContext } from '~/lib/context/MarketProvider';
import type { FoilPosition } from '~/lib/interfaces/interfaces';
Expand All @@ -45,7 +46,6 @@ import useFoilDeployment from './useFoilDeployment';

const tickSpacingDefault = 200; // 1% - Hardcoded for now, should be retrieved with pool.tickSpacing()

const TOKEN_DECIMALS = 18; // should be retrieved from the contract?
const priceToTick = (price: number, tickSpacing: number): number => {
const tick = Math.log(price) / Math.log(1.0001);
return Math.round(tick / tickSpacing) * tickSpacing;
Expand Down
31 changes: 0 additions & 31 deletions packages/app/src/lib/components/util/util.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/app/src/lib/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TOKEN_DECIMALS = 18; // should be retrieved from the contract?
File renamed without changes.
52 changes: 52 additions & 0 deletions packages/app/src/lib/util/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { ToastId, UseToastOptions } from '@chakra-ui/react';
import type { ReadContractErrorType, WriteContractErrorType } from 'viem';

export const renderContractErrorToast = (
error: ReadContractErrorType | WriteContractErrorType | null,
toast: (options?: UseToastOptions) => ToastId,
desc: string
) => {
if (error) {
console.error(desc, error.message);
toast({
title: desc,
description: error.message,
status: 'error',
duration: 5000,
isClosable: true,
});
}
};

export const renderToastSuccess = (
toast: (options?: UseToastOptions) => ToastId,
desc: string
) => {
toast({
title: desc,
status: 'success',
duration: 5000,
isClosable: true,
});
};

export function decimalToFraction(
decimal: number,
decimalPlaces?: number
): [number, number] {
if (Number.isInteger(decimal)) {
return [decimal, 1];
}

const precision = decimalPlaces || 1000000; // Adjust this for more/less precision
let numerator = Math.round(decimal * precision);
let denominator = precision;

const gcd = (a: number, b: number): number => (b ? gcd(b, a % b) : a);
const divisor = gcd(numerator, denominator);

numerator /= divisor;
denominator /= divisor;

return [numerator, denominator];
}

0 comments on commit a4a4a8b

Please sign in to comment.