1- import { Currency , CurrencyAmount , JSBI , Pair , Percent , Price , TokenAmount } from '@uniswap/sdk'
1+ import { Currency , CurrencyAmount , ETHER , JSBI , Pair , Percent , Price , TokenAmount } from '@uniswap/sdk'
22import { useCallback , useMemo } from 'react'
33import { useDispatch , useSelector } from 'react-redux'
44import { PairState , usePair } from '../../data/Reserves'
@@ -65,17 +65,24 @@ export function useDerivedMintInfo(
6565 }
6666
6767 // amounts
68- const independentAmount = tryParseAmount ( typedValue , currencies [ independentField ] )
69- const dependentAmount = useMemo ( ( ) => {
70- if ( noLiquidity && otherTypedValue && currencies [ dependentField ] ) {
71- return tryParseAmount ( otherTypedValue , currencies [ dependentField ] )
68+ const independentAmount : CurrencyAmount | undefined = tryParseAmount ( typedValue , currencies [ independentField ] )
69+ const dependentAmount : CurrencyAmount | undefined = useMemo ( ( ) => {
70+ if ( noLiquidity ) {
71+ if ( otherTypedValue && currencies [ dependentField ] ) {
72+ return tryParseAmount ( otherTypedValue , currencies [ dependentField ] )
73+ }
74+ return
7275 } else if ( independentAmount ) {
76+ // we wrap the currencies just to get the price in terms of the other token
7377 const wrappedIndependentAmount = wrappedCurrencyAmount ( independentAmount , chainId )
7478 const [ tokenA , tokenB ] = [ wrappedCurrency ( currencyA , chainId ) , wrappedCurrency ( currencyB , chainId ) ]
7579 if ( tokenA && tokenB && wrappedIndependentAmount && pair ) {
76- return dependentField === Field . CURRENCY_B
77- ? pair . priceOf ( tokenA ) . quote ( wrappedIndependentAmount )
78- : pair . priceOf ( tokenB ) . quote ( wrappedIndependentAmount )
80+ const dependentCurrency = dependentField === Field . CURRENCY_B ? currencyB : currencyA
81+ const dependentTokenAmount =
82+ dependentField === Field . CURRENCY_B
83+ ? pair . priceOf ( tokenA ) . quote ( wrappedIndependentAmount )
84+ : pair . priceOf ( tokenB ) . quote ( wrappedIndependentAmount )
85+ return dependentCurrency === ETHER ? CurrencyAmount . ether ( dependentTokenAmount . raw ) : dependentTokenAmount
7986 }
8087 return
8188 } else {
@@ -89,12 +96,11 @@ export function useDerivedMintInfo(
8996
9097 const price = useMemo ( ( ) => {
9198 const { [ Field . CURRENCY_A ] : currencyAAmount , [ Field . CURRENCY_B ] : currencyBAmount } = parsedAmounts
92- if ( noLiquidity && currencyAAmount && currencyBAmount ) {
99+ if ( currencyAAmount && currencyBAmount ) {
93100 return new Price ( currencyAAmount . currency , currencyBAmount . currency , currencyAAmount . raw , currencyBAmount . raw )
94- } else {
95- return
96101 }
97- } , [ noLiquidity , parsedAmounts ] )
102+ return
103+ } , [ parsedAmounts ] )
98104
99105 // liquidity minted
100106 const totalSupply = useTotalSupply ( pair ?. liquidityToken )
0 commit comments