Commit 803eb46e authored by Charles Bachmeier's avatar Charles Bachmeier Committed by GitHub

fix: Clear input and output when wrapping and unwrapping (#6913)

* add wrap handler

* onWrap passed back tx hash

* async await
parent a3f0c54f
...@@ -141,18 +141,23 @@ Please file a bug detailing how this happened - https://github.com/Uniswap/inter ...@@ -141,18 +141,23 @@ Please file a bug detailing how this happened - https://github.com/Uniswap/inter
execute: execute:
sufficientBalance && inputAmount sufficientBalance && inputAmount
? async () => { ? async () => {
const txReceipt = await wethContract.withdraw(`0x${inputAmount.quotient.toString(16)}`) try {
addTransaction(txReceipt, { const txReceipt = await wethContract.withdraw(`0x${inputAmount.quotient.toString(16)}`)
type: TransactionType.WRAP, addTransaction(txReceipt, {
unwrapped: true, type: TransactionType.WRAP,
currencyAmountRaw: inputAmount?.quotient.toString(), unwrapped: true,
chainId, currencyAmountRaw: inputAmount?.quotient.toString(),
}) chainId,
sendAnalyticsEvent(InterfaceEventName.WRAP_TOKEN_TXN_SUBMITTED, { })
...eventProperties, sendAnalyticsEvent(InterfaceEventName.WRAP_TOKEN_TXN_SUBMITTED, {
type: WrapType.UNWRAP, ...eventProperties,
}) type: WrapType.UNWRAP,
return txReceipt.hash })
return txReceipt.hash
} catch (error) {
console.error('Could not withdraw', error)
throw error
}
} }
: undefined, : undefined,
inputError: sufficientBalance inputError: sufficientBalance
......
...@@ -435,6 +435,33 @@ export function Swap({ ...@@ -435,6 +435,33 @@ export function Swap({
}) })
}, [swapCallback, stablecoinPriceImpact]) }, [swapCallback, stablecoinPriceImpact])
const handleOnWrap = useCallback(async () => {
if (!onWrap) return
try {
const txHash = await onWrap()
setSwapState((currentState) => ({
...currentState,
swapError: undefined,
txHash,
}))
onUserInput(Field.INPUT, '')
} catch (error) {
if (!didUserReject(error)) {
sendAnalyticsEvent(SwapEventName.SWAP_ERROR, {
wrapType,
input: currencies[Field.INPUT],
output: currencies[Field.OUTPUT],
})
}
console.error('Could not wrap/unwrap', error)
setSwapState((currentState) => ({
...currentState,
swapError: error,
txHash: undefined,
}))
}
}, [currencies, onUserInput, onWrap, wrapType])
// errors // errors
const [swapQuoteReceivedDate, setSwapQuoteReceivedDate] = useState<Date | undefined>() const [swapQuoteReceivedDate, setSwapQuoteReceivedDate] = useState<Date | undefined>()
...@@ -684,7 +711,7 @@ export function Swap({ ...@@ -684,7 +711,7 @@ export function Swap({
) : showWrap ? ( ) : showWrap ? (
<ButtonPrimary <ButtonPrimary
disabled={Boolean(wrapInputError)} disabled={Boolean(wrapInputError)}
onClick={() => onWrap?.().catch((e) => console.error('Could not wrap/unwrap', e))} onClick={handleOnWrap}
fontWeight={600} fontWeight={600}
data-testid="wrap-button" data-testid="wrap-button"
> >
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment