1
- import React , { useState , useEffect } from 'react'
1
+ import React , { useState } from 'react'
2
2
import { Box , Typography , Divider , InputAdornment } from '@material-ui/core'
3
3
import { ToggleButtonGroup , ToggleButton } from '@material-ui/lab'
4
4
import { makeStyles , createStyles } from '@material-ui/core/styles'
@@ -10,6 +10,7 @@ import { AltPrimaryButton } from '@components/Button'
10
10
import { useETHPrice } from '@hooks/useETHPrice'
11
11
import { useTokenBalance } from '@hooks/contracts/useTokenBalance'
12
12
import useAppCallback from '@hooks/useAppCallback'
13
+ import useAppEffect from '@hooks/useAppEffect'
13
14
import { addressesAtom } from '@state/positions/atoms'
14
15
import { useGetWSqueethPositionValue } from '@state/squeethPool/hooks'
15
16
import { useGetDepositAmounts , useGetTicksFromPriceRange , useOpenPositionDeposit } from '@state/lp/hooks'
@@ -143,9 +144,13 @@ const LpSettings: React.FC<{ onComplete: () => void; squeethToMint: string }> =
143
144
const textClasses = useTextStyles ( )
144
145
145
146
const squeethPrice = getWSqueethPositionValue ( 1 )
147
+ const collatRatioVal = new bn ( collatRatio ) . div ( 100 ) . toNumber ( )
148
+ const slippageAmountVal = new bn ( slippageAmount ) . div ( 100 ) . toNumber ( )
146
149
147
- useEffect ( ( ) => {
150
+ useAppEffect ( ( ) => {
148
151
if ( usingDefaultPriceRange ) {
152
+ setLowerTick ( TickMath . MIN_TICK )
153
+ setUpperTick ( TickMath . MAX_TICK )
149
154
return
150
155
}
151
156
@@ -164,32 +169,24 @@ const LpSettings: React.FC<{ onComplete: () => void; squeethToMint: string }> =
164
169
165
170
setLowerTick ( ticks . lowerTick )
166
171
setUpperTick ( ticks . upperTick )
167
- } , [ usingDefaultPriceRange , minPrice , maxPrice , ethPrice ] )
172
+ } , [ usingDefaultPriceRange , minPrice , maxPrice , ethPrice , getTicksFromPriceRange ] )
168
173
169
- useEffect ( ( ) => {
170
- getDepositAmounts ( new bn ( squeethToMint ) , lowerTick , upperTick , 0 , collatRatio , 0 ) . then ( ( deposits ) => {
174
+ useAppEffect ( ( ) => {
175
+ getDepositAmounts ( new bn ( squeethToMint ) , lowerTick , upperTick , 0 , collatRatioVal , 0 ) . then ( ( deposits ) => {
171
176
if ( deposits ) {
172
177
setDepositAmounts ( deposits )
173
178
}
174
179
} )
175
- } , [ squeethToMint , lowerTick , upperTick , collatRatio ] )
180
+ } , [ squeethToMint , lowerTick , upperTick , collatRatioVal , getDepositAmounts ] )
176
181
177
182
const openPosition = useAppCallback ( async ( ) => {
178
183
try {
179
- await openLpPosition (
180
- new bn ( squeethToMint ) ,
181
- lowerTick ,
182
- upperTick ,
183
- 0 ,
184
- collatRatio ,
185
- slippageAmount . toNumber ( ) ,
186
- 0 ,
187
- ( ) => {
188
- console . log ( 'successfull' )
189
- onComplete ( )
190
- } ,
191
- )
184
+ await openLpPosition ( new bn ( squeethToMint ) , lowerTick , upperTick , 0 , collatRatioVal , slippageAmountVal , 0 , ( ) => {
185
+ console . log ( 'successfully deposited' )
186
+ onComplete ( )
187
+ } )
192
188
} catch ( e ) {
189
+ console . log ( 'transaction failed' )
193
190
console . log ( e )
194
191
}
195
192
} , [ squeethToMint , lowerTick , upperTick , collatRatio , slippageAmount , openLpPosition ] )
0 commit comments