Skip to content

Commit 6590482

Browse files
chore: removing FE swap quote refresh
1 parent 1a9c4d0 commit 6590482

File tree

2 files changed

+64
-174
lines changed

2 files changed

+64
-174
lines changed

ui/pages/Swap.tsx

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ import { ReadOnlyAccountSigner } from "@tallyho/tally-background/services/signin
2929
import {
3030
NETWORKS_SUPPORTING_SWAPS,
3131
OPTIMISM,
32-
SECOND,
3332
} from "@tallyho/tally-background/constants"
34-
3533
import {
3634
selectLatestQuoteRequest,
3735
selectSwapBuyAssets,
@@ -52,12 +50,10 @@ import {
5250
getSellAssetAmounts,
5351
getOwnedSellAssetAmounts,
5452
} from "../utils/swap"
55-
import { useOnMount, usePrevious, useInterval } from "../hooks/react-hooks"
53+
import { useOnMount, usePrevious } from "../hooks/react-hooks"
5654
import SharedLoadingDoggo from "../components/Shared/SharedLoadingDoggo"
5755
import SharedBackButton from "../components/Shared/SharedBackButton"
5856

59-
const REFRESH_QUOTE_INTERVAL = 10 * SECOND
60-
6157
export default function Swap(): ReactElement {
6258
const { t } = useTranslation()
6359
const dispatch = useBackgroundDispatch()
@@ -103,7 +99,6 @@ export default function Swap(): ReactElement {
10399
assets: { sellAsset: savedSellAsset, buyAsset: savedBuyAsset },
104100
amount: savedSwapAmount,
105101
} = (!locationAsset && savedQuoteRequest) || {
106-
// ^ If coming from an asset item swap button, let the UI start fresh
107102
assets: { sellAsset: locationAsset },
108103
}
109104

@@ -214,8 +209,6 @@ export default function Swap(): ReactElement {
214209
setSellAsset(newSellAsset)
215210
setSellAmount("")
216211

217-
// Updating the source asset quotes the new source asset against the existing
218-
// target amount.
219212
if (newSellAsset && buyAsset && buyAmount) {
220213
requestQuoteUpdate({
221214
type: "getSellAmount",
@@ -234,8 +227,6 @@ export default function Swap(): ReactElement {
234227
setBuyAsset(newBuyAsset)
235228
setBuyAmount("")
236229

237-
// Updating the target asset quotes the new target asset against the existing
238-
// source amount.
239230
if (sellAsset && newBuyAsset && sellAmount) {
240231
requestQuoteUpdate({
241232
type: "getBuyAmount",
@@ -280,8 +271,6 @@ export default function Swap(): ReactElement {
280271
isSameAsset(quote.sellAsset, sellAsset) &&
281272
isSameAsset(quote.buyAsset, buyAsset)
282273

283-
// Update if quote changes
284-
285274
const prevQuoteTimestamp = usePrevious(quote?.timestamp)
286275

287276
if (
@@ -300,40 +289,7 @@ export default function Swap(): ReactElement {
300289
}
301290
}
302291

303-
const [amountInputHasFocus, setAmountInputHasFocus] = useState(false)
304-
305-
useInterval(() => {
306-
if (!isEnabled(FeatureFlags.SUPPORT_SWAP_QUOTE_REFRESH)) return
307-
308-
const isRecentQuote =
309-
quote &&
310-
// Time passed since last quote
311-
Date.now() - quote.timestamp <= 3 * SECOND
312-
313-
const skipRefresh =
314-
loadingQuote || (isRecentQuote && quoteAppliesToCurrentAssets)
315-
316-
if (
317-
!skipRefresh &&
318-
!amountInputHasFocus &&
319-
sellAsset &&
320-
buyAsset &&
321-
(sellAmount || buyAmount)
322-
) {
323-
const type = sellAmount ? "getBuyAmount" : "getSellAmount"
324-
const amount = sellAmount || buyAmount
325-
326-
requestQuoteUpdate({
327-
type,
328-
amount,
329-
sellAsset,
330-
buyAsset,
331-
})
332-
}
333-
}, REFRESH_QUOTE_INTERVAL)
334-
335292
useOnMount(() => {
336-
// Request a quote on mount
337293
if (sellAsset && buyAsset && sellAmount) {
338294
requestQuoteUpdate({
339295
type: "getBuyAmount",
@@ -357,8 +313,6 @@ export default function Swap(): ReactElement {
357313
sellAsset,
358314
buyAsset,
359315
gasPrice:
360-
// Let's use the gas price from 0x API for Optimism
361-
// to avoid problems with gas price on Optimism Bedrock.
362316
currentNetwork.chainID === OPTIMISM.chainID
363317
? gasPrice
364318
: quote.swapTransactionSettings.networkSettings.values.maxFeePerGas.toString() ??
@@ -393,7 +347,6 @@ export default function Swap(): ReactElement {
393347
<ReadOnlyNotice isLite />
394348
{isEnabled(FeatureFlags.SHOW_TOKEN_FEATURES) &&
395349
isEnabled(FeatureFlags.SHOW_SWAP_REWARDS) && (
396-
// TODO: Add onClick function after design is ready
397350
<SharedIcon
398351
399352
width={20}
@@ -429,13 +382,10 @@ export default function Swap(): ReactElement {
429382
selectedAsset={sellAsset}
430383
isDisabled={loadingSellAmount}
431384
onAssetSelect={updateSellAsset}
432-
onFocus={() => setAmountInputHasFocus(true)}
433-
onBlur={() => setAmountInputHasFocus(false)}
434385
onErrorMessageChange={(error) => setHasError(!!error)}
435386
mainCurrencySign={mainCurrencySign}
436387
onAmountChange={(newAmount, error) => {
437388
setSellAmount(newAmount)
438-
439389
if (!error) {
440390
requestQuoteUpdate({
441391
type: "getBuyAmount",
@@ -466,12 +416,9 @@ export default function Swap(): ReactElement {
466416
priceImpact={quote?.priceDetails?.priceImpact}
467417
isPriceDetailsLoading={isLoadingPriceDetails}
468418
showPriceDetails
469-
// FIXME: Merge master asset list with account balances.
470419
assetsAndAmounts={buyAssets.map((asset) => ({ asset }))}
471420
selectedAsset={buyAsset}
472421
isDisabled={loadingBuyAmount}
473-
onFocus={() => setAmountInputHasFocus(true)}
474-
onBlur={() => setAmountInputHasFocus(false)}
475422
showMaxButton={false}
476423
mainCurrencySign={mainCurrencySign}
477424
onAssetSelect={updateBuyAsset}
@@ -568,12 +515,10 @@ export default function Swap(): ReactElement {
568515
font-weight: 500;
569516
line-height: 32px;
570517
}
571-
572518
.loading_wrapper {
573519
min-height: 73.5px;
574520
margin: 7px 0 10px;
575521
}
576-
577522
.footer {
578523
display: flex;
579524
justify-content: center;

0 commit comments

Comments
 (0)