Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
refac: add first version of refactoring on swap
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jun 11, 2022
1 parent 37af4c8 commit efa9ecf
Show file tree
Hide file tree
Showing 21 changed files with 612 additions and 732 deletions.
4 changes: 2 additions & 2 deletions packages/app/src/systems/Core/components/CoinInput.tsx
Expand Up @@ -167,7 +167,7 @@ function getRightValue(value: string, displayType: string) {
return value === "0.0" ? "0" : value;
}

type CoinInputProps = Omit<UseCoinParams, "onChange"> &
export type CoinInputProps = Omit<UseCoinParams, "onChange"> &
NumberInputProps & {
value: string;
displayType: DisplayType;
Expand Down Expand Up @@ -223,7 +223,7 @@ export const CoinInput = forwardRef<HTMLInputElement, CoinInputProps>(
setValue(e.target.value);
}}
decimalScale={DECIMAL_UNITS}
placeholder="0"
placeholder={props.placeholder || "0"}
className="coinInput--input"
thousandSeparator={false}
onInput={onInput}
Expand Down
8 changes: 8 additions & 0 deletions packages/app/src/systems/Core/utils/math.ts
Expand Up @@ -67,6 +67,14 @@ export function parseToFormattedNumber(
return ethers.commify(toFixed(formatUnits(val, precision), FIXED_UNITS));
}

export const parseValueBigInt = (value: string) => {
if (value !== '') {
const nextValue = value === '.' ? '0.' : value;
return toBigInt(parseUnits(nextValue));
}
return ZERO;
};

export function multiplyFn(value?: BigNumberish | null, by?: BigNumberish | null) {
return new Decimal(value?.toString() || 0).mul(by?.toString() || 0).toNumber();
}
Expand Down
10 changes: 8 additions & 2 deletions packages/app/src/systems/Pool/hooks/useUserPositions.ts
Expand Up @@ -10,6 +10,13 @@ import {
multiplyFn,
toFixed,
} from '~/systems/Core';
import type { PoolInfo } from '~/types/contracts/ExchangeContractAbi';

export async function getPoolRatio(info?: PoolInfo | null) {
const tokenReserve = toBigInt(info?.token_reserve || ZERO);
const ethReserve = toBigInt(info?.eth_reserve || ZERO);
return divideFnValidOnly(ethReserve, tokenReserve);
}

export function useUserPositions() {
const { data: info } = usePoolInfo();
Expand All @@ -24,6 +31,7 @@ export function useUserPositions() {
const totalLiquidity = toBigInt(info?.lp_token_supply || ZERO);
const tokenReserve = toBigInt(info?.token_reserve || ZERO);
const ethReserve = toBigInt(info?.eth_reserve || ZERO);
const poolRatio = getPoolRatio(info);

const formattedTokenReserve = parseToFormattedNumber(tokenReserve);
const formattedEthReserve = parseToFormattedNumber(ethReserve);
Expand All @@ -38,8 +46,6 @@ export function useUserPositions() {
const formattedPoolShare = toFixed(poolShare * 100);
const hasPositions = poolTokensNum > ZERO;

const poolRatio = divideFnValidOnly(ethReserve, tokenReserve);

return {
pooledDAI,
pooledETH,
Expand Down
103 changes: 0 additions & 103 deletions packages/app/src/systems/Swap/components/PricePerToken.tsx

This file was deleted.

162 changes: 0 additions & 162 deletions packages/app/src/systems/Swap/components/SwapComponent.tsx

This file was deleted.

0 comments on commit efa9ecf

Please sign in to comment.