11import { Pool , ZapRouteDetail } from '@kyber/schema'
2- import { StatusDialog , StatusDialogType , translateFriendlyErrorMessage , translateZapMessage } from '@kyber/ui'
3- import { t } from '@lingui/macro'
2+ import { StatusDialog , StatusDialogType , translateZapMessage } from '@kyber/ui'
43import { Text } from 'rebass'
4+ import { BuildZapInData } from 'services/zapInService'
55import styled from 'styled-components'
66
7- import { ButtonPrimary } from 'components/Button'
7+ import { ButtonOutlined , ButtonPrimary } from 'components/Button'
88import Modal from 'components/Modal'
99import { HStack , Stack } from 'components/Stack'
1010import useTheme from 'hooks/useTheme'
@@ -17,7 +17,6 @@ import { CloseIcon } from 'theme/components'
1717import EstimateInfo from './EstimateInfo'
1818import PriceInfo from './PriceInfo'
1919import ZapInfo from './ZapInfo'
20- import { useReviewBuild } from './useReviewBuild'
2120import { ReviewTransactionStatusPhase , useReviewTransaction } from './useReviewTransaction'
2221
2322type ReviewWarningItem = {
@@ -37,26 +36,19 @@ const ModalContent = styled(Stack)`
3736 ` }
3837`
3938
40- const DisclaimerText = styled . div `
41- color: ${ ( { theme } ) => theme . subText } ;
42- font-size: 14px;
43- font-style: italic;
44- `
45-
4639type AddLiquidityReviewModalProps = {
47- isOpen : boolean
4840 pool : Pool
49- route : ZapRouteDetail
50- routeLoading : boolean
51- refetchRoute ?: ( ) => Promise < unknown >
52- warnings : ReviewWarningItem [ ]
41+ buildData : BuildZapInData
5342 chainId : number
54- tokenInput : ZapState [ 'tokenInput' ]
43+ error ?: string | null
44+ isRefreshing ?: boolean
5545 priceRange : ZapState [ 'priceRange' ]
46+ route : ZapRouteDetail
5647 slippage ?: number
48+ tokenInput : ZapState [ 'tokenInput' ]
49+ warnings : ReviewWarningItem [ ]
5750 onDismiss ?: ( ) => void
5851 onUseSuggestedSlippage ?: ( suggestedSlippage ?: number ) => void
59- onClearTracking ?: ( ) => void
6052 onAddTrackedTxHash ?: ( hash : string ) => void
6153 onAddTransactionWithType ?: ( transaction : any ) => void
6254}
@@ -79,45 +71,36 @@ const getStatusDialogType = (statusPhase: ReviewTransactionStatusPhase) => {
7971
8072const StatusContent = ( {
8173 statusPhase,
82- slippage,
83- suggestedSlippage,
8474 txError,
8575 transactionExplorerUrl,
8676 onDismiss,
87- onUseSuggestedSlippage,
8877 onViewPosition,
8978} : {
9079 statusPhase : ReviewTransactionStatusPhase
91- slippage ?: number
92- suggestedSlippage ?: number
9380 txError ?: string | null
9481 transactionExplorerUrl ?: string
9582 onDismiss ?: ( ) => void
96- onUseSuggestedSlippage ?: ( ) => void
9783 onViewPosition ?: ( ) => void
9884} ) => {
9985 const translatedErrorMessage = getStatusErrorMessage ( txError )
100- const errorMessage = txError ?. toLowerCase ( ) || ''
101-
102- const isSlippageError = errorMessage . includes ( 'slippage' )
86+ const canDismiss = statusPhase !== 'waiting_wallet'
10387 const canViewPosition = statusPhase === 'success' && Boolean ( onViewPosition )
10488
105- const statusAction = (
106- < >
107- < button className = "ks-outline-btn flex-1" onClick = { onDismiss } >
108- Close
109- </ button >
110- { canViewPosition ? (
111- < button className = "ks-primary-btn flex-1" onClick = { onViewPosition } >
112- View position
113- </ button >
114- ) : isSlippageError ? (
115- < button className = "ks-primary-btn flex-1" onClick = { onUseSuggestedSlippage || onDismiss } >
116- { slippage !== suggestedSlippage ? t `Use Suggested Slippage` : t `Set Custom Slippage` }
117- </ button >
118- ) : null }
119- </ >
120- )
89+ const statusAction =
90+ canDismiss || canViewPosition ? (
91+ < >
92+ { canDismiss ? (
93+ < ButtonOutlined flex = "1" height = "36px" onClick = { onDismiss } >
94+ Close
95+ </ ButtonOutlined >
96+ ) : null }
97+ { canViewPosition ? (
98+ < ButtonPrimary flex = "1" height = "36px" onClick = { onViewPosition } >
99+ View position
100+ </ ButtonPrimary >
101+ ) : null }
102+ </ >
103+ ) : undefined
121104
122105 return (
123106 < StatusDialog
@@ -126,38 +109,31 @@ const StatusContent = ({
126109 description = { statusPhase === 'waiting_wallet' ? 'Confirm this transaction in your wallet' : undefined }
127110 errorMessage = { translatedErrorMessage }
128111 transactionExplorerUrl = { transactionExplorerUrl }
129- onClose = { onDismiss || ( ( ) => { } ) }
112+ onClose = { canDismiss ? onDismiss || ( ( ) => { } ) : ( ) => { } }
130113 />
131114 )
132115}
133116
134117const AddLiquidityReviewModal = ( {
135- isOpen,
136118 pool,
137- route,
138- routeLoading,
139- refetchRoute,
140- warnings,
119+ buildData,
141120 chainId,
142- tokenInput,
121+ error,
122+ isRefreshing,
143123 priceRange,
124+ route,
144125 slippage,
126+ tokenInput,
127+ warnings,
145128 onDismiss,
146129 onUseSuggestedSlippage,
147- onClearTracking,
148130 onAddTrackedTxHash,
149131 onAddTransactionWithType,
150132} : AddLiquidityReviewModalProps ) => {
151133 const theme = useTheme ( )
152- const { buildData, buildError, buildLoading, rebuildReview } = useReviewBuild ( {
153- isOpen,
154- route,
155- refetchRoute,
156- onClearTracking,
157- } )
158134
159135 const transaction = useReviewTransaction ( {
160- isOpen,
136+ isOpen : true ,
161137 buildData,
162138 pool,
163139 tokenInput,
@@ -166,54 +142,37 @@ const AddLiquidityReviewModal = ({
166142 onDismiss,
167143 } )
168144
169- const isWaitingForWallet = transaction . statusPhase === 'waiting_wallet'
170- const isProcessing = transaction . statusPhase === 'processing'
171145 const isSuccessful = transaction . statusPhase === 'success'
172146 const showStatusDialog = transaction . statusPhase !== 'idle'
173147
174- const handleStatusClose = async ( ) => {
175- if ( isWaitingForWallet ) {
176- transaction . resetTransactionState ( )
148+ const handleStatusClose = ( ) => {
149+ if ( transaction . statusPhase === 'waiting_wallet' ) {
177150 return
178151 }
179152
180- if ( isSuccessful || isProcessing ) {
181- onDismiss ?.( )
182- return
183- }
153+ const shouldDismiss = transaction . statusPhase === 'processing' || transaction . statusPhase === 'success'
184154
185155 transaction . resetTransactionState ( )
186- await rebuildReview ( )
187- }
188156
189- const handleUseSuggestedSlippage = ( ) => {
190- onUseSuggestedSlippage ?.( route . zapDetails . suggestedSlippage )
191- transaction . resetTransactionState ( )
157+ if ( shouldDismiss ) {
158+ onDismiss ?.( )
159+ }
192160 }
193161
194- if ( ! isOpen ) return null
195-
196162 if ( showStatusDialog ) {
197163 return (
198164 < StatusContent
199165 statusPhase = { transaction . statusPhase }
200- slippage = { slippage }
201- suggestedSlippage = { route . zapDetails . suggestedSlippage }
202166 txError = { transaction . submitError }
203167 transactionExplorerUrl = { transaction . transactionExplorerUrl }
204- onDismiss = { ( ) => {
205- void handleStatusClose ( )
206- } }
207- onUseSuggestedSlippage = { ( ) => {
208- handleUseSuggestedSlippage ( )
209- } }
168+ onDismiss = { handleStatusClose }
210169 onViewPosition = { isSuccessful ? transaction . handleViewPosition : undefined }
211170 />
212171 )
213172 }
214173
215174 return (
216- < Modal isOpen = { isOpen } borderRadius = "20px" maxWidth = { 480 } mobileFullWidth onDismiss = { onDismiss } >
175+ < Modal isOpen borderRadius = "20px" maxWidth = { 480 } mobileFullWidth onDismiss = { onDismiss } >
217176 < ModalContent gap = { 16 } >
218177 < HStack align = "center" justify = "space-between" width = "100%" >
219178 < Text fontSize = { 24 } fontWeight = { 500 } >
@@ -228,11 +187,9 @@ const AddLiquidityReviewModal = ({
228187
229188 < PriceInfo pool = { pool } priceRange = { priceRange } />
230189
231- < EstimateInfo pool = { pool } route = { route } slippage = { slippage } />
190+ < EstimateInfo onUseSuggestedSlippage = { onUseSuggestedSlippage } pool = { pool } route = { route } slippage = { slippage } />
232191
233- { buildError ? (
234- < NoteCard $tone = "error" > { translateFriendlyErrorMessage ( buildError ) || buildError } </ NoteCard >
235- ) : null }
192+ { error ? < NoteCard $tone = "error" > { translateZapMessage ( error ) } </ NoteCard > : null }
236193
237194 { warnings . length ? (
238195 < Stack gap = { 12 } >
@@ -244,25 +201,21 @@ const AddLiquidityReviewModal = ({
244201 </ Stack >
245202 ) : null }
246203
247- < DisclaimerText >
204+ < Text color = { theme . subText } fontSize = { 14 } fontStyle = "italic" >
248205 The information is intended solely for your reference at the time you are viewing. It is your responsibility
249- to verify all information before making decisions
250- </ DisclaimerText >
206+ to verify all information before making decisions.
207+ </ Text >
251208
252209 < ButtonPrimary
253210 altDisabledStyle
254211 borderRadius = "20px"
255212 color = { theme . buttonBlack }
256- disabled = { transaction . confirmDisabled || routeLoading || buildLoading || Boolean ( buildError ) }
213+ disabled = { transaction . confirmDisabled || isRefreshing || Boolean ( error ) }
257214 height = "48px"
258215 onClick = { ( ) => void transaction . handleSubmit ( ) }
259216 type = "button"
260217 >
261- { transaction . confirmLoading
262- ? 'Adding Liquidity...'
263- : routeLoading || buildLoading
264- ? 'Refreshing Route...'
265- : 'Add Liquidity' }
218+ { transaction . confirmLoading ? 'Adding Liquidity...' : isRefreshing ? 'Refreshing Route...' : 'Add Liquidity' }
266219 </ ButtonPrimary >
267220 </ ModalContent >
268221 </ Modal >
0 commit comments