Skip to content

Commit

Permalink
Merge pull request #14 from cryptoalgebra/fix/apr-calcualtion
Browse files Browse the repository at this point in the history
fix: pool initial price
  • Loading branch information
lilchizh authored Mar 29, 2024
2 parents 6262118 + c0ce330 commit c9a3d8a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 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
13 changes: 6 additions & 7 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,17 +36,16 @@ 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
showBalance={false}
value={typedValue}
value={startPriceTypedValue}
handleTokenSelection={handleInputSelect}
currency={currencyA}
otherCurrency={currencyB}
Expand Down

0 comments on commit c9a3d8a

Please sign in to comment.