Skip to content

Commit dd4b2dc

Browse files
authored
fix: only change input currency to weth after eth wrap completes for uniswapx eth input trades (Uniswap#7604)
* only change input currency to weth after wrap completes * add e2e test * update test
1 parent 5ded55e commit dd4b2dc

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

cypress/e2e/swap/uniswapx.test.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ describe('UniswapX Eth Input', () => {
190190
cy.contains('Swapped')
191191
})
192192

193-
it('switches swap input to WETH after wrap', () => {
193+
it('keeps ETH as the input currency before wrap completes', () => {
194194
// Setup a swap
195195
cy.get('#swap-currency-input .token-amount-input').type('1')
196196
cy.wait('@quote')
@@ -202,16 +202,25 @@ describe('UniswapX Eth Input', () => {
202202

203203
// Close review modal before wrap is confirmed on chain
204204
cy.get(getTestSelector('confirmation-close-icon')).click()
205+
// Confirm ETH is still the input token before wrap succeeds
206+
cy.contains('ETH')
207+
})
208+
209+
it('switches swap input to WETH after wrap', () => {
210+
// Setup a swap
211+
cy.get('#swap-currency-input .token-amount-input').type('1')
212+
cy.wait('@quote')
213+
214+
// Prompt ETH wrap and confirm
215+
cy.get('#swap-button').click()
216+
cy.contains('Confirm swap').click()
217+
cy.wait('@eth_sendRawTransaction')
205218
cy.hardhat().then((hardhat) => hardhat.mine())
206219

207220
// Confirm wrap is successful and WETH is now input token
208221
cy.contains('Wrapped')
209222
cy.contains('WETH')
210223

211-
// Reopen review modal and continue swap
212-
cy.get('#swap-button').click()
213-
cy.contains('Confirm swap').click()
214-
215224
// Approve WETH spend
216225
cy.wait('@eth_sendRawTransaction')
217226
cy.hardhat().then((hardhat) => hardhat.mine())
@@ -226,6 +235,11 @@ describe('UniswapX Eth Input', () => {
226235

227236
// Verify swap success
228237
cy.contains('Swapped')
238+
239+
// Close modal
240+
cy.get(getTestSelector('confirmation-close-icon')).click()
241+
// The input currency should now be WETH
242+
cy.contains('WETH')
229243
})
230244
})
231245

src/components/swap/ConfirmSwapModal.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ function useConfirmModalState({
133133
onWrap?.()
134134
.then((wrapTxHash) => {
135135
setWrapTxHash(wrapTxHash)
136-
// After the wrap has succeeded, reset the input currency to be WETH
137-
// because the trade will be on WETH -> token
138-
onCurrencySelection(Field.INPUT, trade.inputAmount.currency)
139136
sendAnalyticsEvent(InterfaceEventName.WRAP_TOKEN_TXN_SUBMITTED, {
140137
chain_id: chainId,
141138
token_symbol: maximumAmountIn?.currency.symbol,
@@ -183,7 +180,6 @@ function useConfirmModalState({
183180
onWrap,
184181
trace,
185182
trade,
186-
onCurrencySelection,
187183
]
188184
)
189185

@@ -200,10 +196,20 @@ function useConfirmModalState({
200196
useEffect(() => {
201197
// If the wrapping step finished, trigger the next step (allowance or swap).
202198
if (wrapConfirmed && !prevWrapConfirmed) {
199+
// After the wrap has succeeded, reset the input currency to be WETH
200+
// because the trade will be on WETH -> token
201+
onCurrencySelection(Field.INPUT, trade.inputAmount.currency)
203202
// moves on to either approve WETH or to swap submission
204203
performStep(pendingModalSteps[1])
205204
}
206-
}, [pendingModalSteps, performStep, prevWrapConfirmed, wrapConfirmed])
205+
}, [
206+
pendingModalSteps,
207+
performStep,
208+
prevWrapConfirmed,
209+
wrapConfirmed,
210+
onCurrencySelection,
211+
trade.inputAmount.currency,
212+
])
207213

208214
useEffect(() => {
209215
if (

0 commit comments

Comments
 (0)