Skip to content

Commit

Permalink
Merge pull request #16 from cryptoalgebra/master
Browse files Browse the repository at this point in the history
Merge "master" to "dev"
  • Loading branch information
lilchizh authored Apr 2, 2024
2 parents 7f4a0ee + caecc4a commit 8dd041a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
16 changes: 8 additions & 8 deletions src/components/create-pool/CreatePoolForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { usePrepareAlgebraPositionManagerMulticall } from '@/generated';
import { useTransitionAwait } from '@/hooks/common/useTransactionAwait';
import { Address, useContractWrite } from 'wagmi';
import { useDerivedMintInfo } from '@/state/mintStore';
import { useDerivedMintInfo, useMintState } from '@/state/mintStore';
import Loader from '@/components/common/Loader';
import { PoolState, usePool } from '@/hooks/pools/usePool';
import Summary from '../Summary';
Expand All @@ -21,7 +21,9 @@ import { STABLECOINS } from '@/constants/tokens';
const CreatePoolForm = () => {
const { currencies } = useDerivedSwapInfo();

const { typedValue, actions: { selectCurrency, typeInput } } = useSwapState();
const { actions: { selectCurrency } } = useSwapState();

const { startPriceTypedValue, actions: { typeStartPriceInput } } = useMintState()

const currencyA = currencies[SwapField.INPUT];
const currencyB = currencies[SwapField.OUTPUT];
Expand Down Expand Up @@ -83,14 +85,12 @@ const CreatePoolForm = () => {
useEffect(() => {
selectCurrency(SwapField.INPUT, undefined)
selectCurrency(SwapField.OUTPUT, undefined)
typeInput(SwapField.INPUT, '')
typeInput(SwapField.OUTPUT, '')
typeStartPriceInput('')

return () => {
selectCurrency(SwapField.INPUT, ADDRESS_ZERO)
selectCurrency(SwapField.OUTPUT, STABLECOINS.USDT.address as Account)
typeInput(SwapField.INPUT, '')
typeInput(SwapField.OUTPUT, '')
typeStartPriceInput('')
}
}, [])

Expand All @@ -114,7 +114,7 @@ const CreatePoolForm = () => {
disabled={
isLoading ||
isPoolExists ||
!typedValue ||
!startPriceTypedValue ||
!areCurrenciesSelected ||
isSameToken
}
Expand All @@ -128,7 +128,7 @@ const CreatePoolForm = () => {
'Select currencies'
) : isPoolExists ? (
'Pool already exists'
) : !typedValue ? (
) : !startPriceTypedValue ? (
'Enter initial price'
) : (
'Create Pool'
Expand Down
24 changes: 12 additions & 12 deletions src/components/create-pool/SelectPair/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TokenCard from '@/components/swap/TokenCard';
import { IDerivedMintInfo, useMintActionHandlers } from '@/state/mintStore';
import { useSwapActionHandlers, useSwapState } from '@/state/swapStore';
import { IDerivedMintInfo, useMintActionHandlers, useMintState } from '@/state/mintStore';
import { useSwapActionHandlers } from '@/state/swapStore';
import { SwapField } from '@/types/swap-field';
import { Currency } from '@cryptoalgebra/integral-sdk';
import { ChevronsUpDownIcon } from 'lucide-react';
Expand All @@ -13,12 +13,12 @@ interface ISelectPair {
}

const SelectPair = ({ mintInfo, currencyA, currencyB }: ISelectPair) => {
const { onCurrencySelection, onUserInput, onSwitchTokens } =
const { onCurrencySelection, onSwitchTokens } =
useSwapActionHandlers();

const { onStartPriceInput } = useMintActionHandlers(mintInfo.noLiquidity);

const { typedValue } = useSwapState();
const { startPriceTypedValue } = useMintState();

const handleInputSelect = useCallback(
(inputCurrency: Currency) => {
Expand All @@ -36,21 +36,20 @@ const SelectPair = ({ mintInfo, currencyA, currencyB }: ISelectPair) => {

const handleTypeInput = useCallback(
(value: string) => {
onUserInput(SwapField.INPUT, value);
onStartPriceInput(value);
},
[onUserInput, onStartPriceInput]
[onStartPriceInput]
);

return (
<div className="relative flex flex-col gap-2 items-center">
<TokenCard
disabled
showBalance={false}
value={typedValue}
handleTokenSelection={handleInputSelect}
value={'1'}
currency={currencyA}
otherCurrency={currencyB}
handleValueChange={handleTypeInput}
handleTokenSelection={handleInputSelect}
/>

<button
Expand All @@ -61,13 +60,14 @@ const SelectPair = ({ mintInfo, currencyA, currencyB }: ISelectPair) => {
</button>

<TokenCard
disabled
showBalance={false}
value={'1'}
value={startPriceTypedValue}
handleTokenSelection={handleOutputSelect}
currency={currencyB}
otherCurrency={currencyA}
handleTokenSelection={handleOutputSelect}
handleValueChange={handleTypeInput}
/>

</div>
);
};
Expand Down
12 changes: 6 additions & 6 deletions src/components/create-pool/Summary/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CurrencyLogo from '@/components/common/CurrencyLogo';
import { Skeleton } from '@/components/ui/skeleton';
import { useSingleTokenQuery } from '@/graphql/generated/graphql';
import { useSwapState } from '@/state/swapStore';
import { useMintState } from '@/state/mintStore';
import { Currency } from '@cryptoalgebra/integral-sdk';
import { useEffect, useState } from 'react';
import { Address } from 'viem';
Expand All @@ -13,7 +13,7 @@ interface ISummary {

const Summary = ({ currencyA, currencyB }: ISummary) => {
const [suggestedPrice, setSuggestedPrice] = useState(0);
const { typedValue } = useSwapState();
const { startPriceTypedValue } = useMintState();

const token0 = currencyA?.wrapped.address.toLowerCase() as Address;
const token1 = currencyB?.wrapped.address.toLowerCase() as Address;
Expand Down Expand Up @@ -67,15 +67,15 @@ const Summary = ({ currencyA, currencyB }: ISummary) => {
)}

<div>
{`1 ${currencyB?.symbol} = ${typedValue || 0} ${
currencyA?.symbol
{`1 ${currencyA?.symbol} = ${startPriceTypedValue || 0} ${
currencyB?.symbol
}`}
</div>
</div>
{suggestedPrice > 0 && (
<div className="text-left ml-2 flex justify-between">
<p className="opacity-50">Suggested price:</p>
<p className="opacity-50">{` 1 ${currencyB?.symbol} = ${suggestedPrice} ${currencyA?.symbol}`}</p>
<p className="opacity-50">Suggested price:</p>
<p className="opacity-50">{` 1 ${currencyA?.symbol} = ${suggestedPrice} ${currencyB?.symbol}`}</p>
</div>
)}
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/hooks/positions/usePositionAPR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export function usePositionAPR(

const nativePrice = bundles?.bundles[0] && Number(bundles.bundles[0].maticPriceUSD)

const poolDayFees = poolFeeData && Boolean(poolFeeData.poolDayDatas.length) && poolFeeData.poolDayDatas.reduce((acc, v) => acc + Number(v.feesUSD), 0)
// Today fees
const poolDayFees = poolFeeData && Boolean(poolFeeData.poolDayDatas.length) && Number(poolFeeData.poolDayDatas[0].feesUSD)

// Avg fees
// const poolDayFees = poolFeeData && Boolean(poolFeeData.poolDayDatas.length) && poolFeeData.poolDayDatas.reduce((acc, v) => acc + Number(v.feesUSD), 0) / poolFeeData.poolDayDatas.length

const yearFee = poolDayFees && poolDayFees * 365

Expand Down
6 changes: 5 additions & 1 deletion src/utils/positions/getPositionAPR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export async function getPositionAPR(

const liquidity = await algebraPool.read.liquidity()

const poolDayFees = poolFeeData && Boolean(poolFeeData.length) && poolFeeData.reduce((acc, v) => acc + Number(v.feesUSD), 0)
// Today fees
const poolDayFees = poolFeeData && Boolean(poolFeeData.length) && Number(poolFeeData[0].feesUSD)

// Avg fees
// const poolDayFees = poolFeeData && Boolean(poolFeeData.length) && poolFeeData.reduce((acc, v) => acc + Number(v.feesUSD), 0) / poolFeeData.length

const yearFee = poolDayFees && poolDayFees * 365

Expand Down

0 comments on commit 8dd041a

Please sign in to comment.