Skip to content

Commit bd53155

Browse files
committed
Continue
1 parent dfcea1c commit bd53155

File tree

4 files changed

+290
-296
lines changed

4 files changed

+290
-296
lines changed

apps/kyberswap-interface/src/pages/Earns/PoolDetail/AddLiquidity/components/ReviewModal/EstimateInfo.tsx

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { PartnerFeeAction, Pool, ProtocolFeeAction, RefundAction, ZapAction, ZapRouteDetail } from '@kyber/schema'
22
import { getZapImpact } from '@kyber/utils'
3+
import { Trans } from '@lingui/macro'
34
import { useMemo } from 'react'
45
import { Text } from 'rebass'
56
import styled from 'styled-components'
@@ -31,9 +32,25 @@ const MetricCard = styled(Stack)`
3132
padding: 8px 12px;
3233
`
3334

35+
const Suggestion = styled.button`
36+
margin-left: auto;
37+
width: fit-content;
38+
border: none;
39+
background: transparent;
40+
color: ${({ theme }) => theme.primary};
41+
font-size: 14px;
42+
padding: 0;
43+
cursor: pointer;
44+
45+
:hover {
46+
filter: brightness(1.12);
47+
}
48+
`
49+
3450
type EstimateInfoProps = {
3551
pool: Pool
3652
route: ZapRouteDetail
53+
onUseSuggestedSlippage?: (suggestedSlippage?: number) => void
3754
slippage?: number
3855
}
3956

@@ -93,9 +110,12 @@ const buildEstimate = ({
93110
}
94111
}
95112

96-
const EstimateInfo = ({ pool, route, slippage }: EstimateInfoProps) => {
113+
const EstimateInfo = ({ pool, route, onUseSuggestedSlippage, slippage }: EstimateInfoProps) => {
97114
const theme = useTheme()
98115
const estimate = useMemo(() => buildEstimate({ pool, route, slippage }), [pool, route, slippage])
116+
const suggestedSlippage = route.zapDetails.suggestedSlippage
117+
const showSuggestedSlippageAction =
118+
suggestedSlippage !== undefined && suggestedSlippage > 0 && suggestedSlippage !== slippage
99119

100120
return (
101121
<Card gap={8}>
@@ -128,12 +148,20 @@ const EstimateInfo = ({ pool, route, slippage }: EstimateInfoProps) => {
128148
<Divider />
129149

130150
<Stack gap={8}>
131-
<HStack align="center" justify="space-between">
132-
<Text color={theme.subText}>Max Slippage</Text>
133-
<Text color={theme.text} fontWeight={500}>
134-
{formatBpsLabel(estimate.slippage)}
135-
</Text>
136-
</HStack>
151+
<Stack gap={4}>
152+
<HStack align="center" justify="space-between">
153+
<Text color={theme.subText}>Max Slippage</Text>
154+
<Text color={theme.text} fontWeight={500}>
155+
{formatBpsLabel(estimate.slippage)}
156+
</Text>
157+
</HStack>
158+
159+
{showSuggestedSlippageAction && (
160+
<Suggestion onClick={() => onUseSuggestedSlippage?.(suggestedSlippage)} type="button">
161+
<Trans>Suggestion</Trans>: {formatBpsLabel(suggestedSlippage)}
162+
</Suggestion>
163+
)}
164+
</Stack>
137165

138166
<HStack align="stretch" gap={8} wrap="wrap">
139167
<MetricCard>

apps/kyberswap-interface/src/pages/Earns/PoolDetail/AddLiquidity/components/ReviewModal/index.tsx

Lines changed: 48 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { 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'
43
import { Text } from 'rebass'
4+
import { BuildZapInData } from 'services/zapInService'
55
import styled from 'styled-components'
66

7-
import { ButtonPrimary } from 'components/Button'
7+
import { ButtonOutlined, ButtonPrimary } from 'components/Button'
88
import Modal from 'components/Modal'
99
import { HStack, Stack } from 'components/Stack'
1010
import useTheme from 'hooks/useTheme'
@@ -17,7 +17,6 @@ import { CloseIcon } from 'theme/components'
1717
import EstimateInfo from './EstimateInfo'
1818
import PriceInfo from './PriceInfo'
1919
import ZapInfo from './ZapInfo'
20-
import { useReviewBuild } from './useReviewBuild'
2120
import { ReviewTransactionStatusPhase, useReviewTransaction } from './useReviewTransaction'
2221

2322
type 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-
4639
type 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

8072
const 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

134117
const 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

Comments
 (0)