Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
e2fea4a5
Unverified
Commit
e2fea4a5
authored
Oct 26, 2022
by
Zach Pomerantz
Committed by
GitHub
Oct 26, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: do not flicker when navigating tokens (#5013)
parent
1f810f84
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
4 deletions
+13
-4
index.tsx
src/components/Widget/index.tsx
+13
-4
No files found.
src/components/Widget/index.tsx
View file @
e2fea4a5
...
@@ -20,7 +20,7 @@ import {
...
@@ -20,7 +20,7 @@ import {
getTokenAddress
,
getTokenAddress
,
}
from
'
analytics/utils
'
}
from
'
analytics/utils
'
import
{
useActiveLocale
}
from
'
hooks/useActiveLocale
'
import
{
useActiveLocale
}
from
'
hooks/useActiveLocale
'
import
{
useCallback
,
useEffect
,
useState
}
from
'
react
'
import
{
useCallback
,
useEffect
,
use
Ref
,
use
State
}
from
'
react
'
import
{
useIsDarkMode
}
from
'
state/user/hooks
'
import
{
useIsDarkMode
}
from
'
state/user/hooks
'
import
{
DARK_THEME
,
LIGHT_THEME
}
from
'
theme/widget
'
import
{
DARK_THEME
,
LIGHT_THEME
}
from
'
theme/widget
'
import
{
computeRealizedPriceImpact
}
from
'
utils/prices
'
import
{
computeRealizedPriceImpact
}
from
'
utils/prices
'
...
@@ -51,14 +51,23 @@ export default function Widget({ defaultToken, onTokensChange, onReviewSwapClick
...
@@ -51,14 +51,23 @@ export default function Widget({ defaultToken, onTokensChange, onReviewSwapClick
const
{
inputs
,
tokenSelector
}
=
useSyncWidgetInputs
(
defaultToken
)
const
{
inputs
,
tokenSelector
}
=
useSyncWidgetInputs
(
defaultToken
)
const
{
settings
}
=
useSyncWidgetSettings
()
const
{
settings
}
=
useSyncWidgetSettings
()
const
{
transactions
}
=
useSyncWidgetTransactions
()
const
{
transactions
}
=
useSyncWidgetTransactions
()
const
lastValue
=
useRef
([
inputs
.
value
.
INPUT
,
inputs
.
value
.
OUTPUT
])
useEffect
(()
=>
{
const
[
input
,
output
]
=
[
inputs
.
value
.
INPUT
,
inputs
.
value
.
OUTPUT
]
const
[
lastInput
,
lastOutput
]
=
lastValue
.
current
// Avoid calling onTokensChange if only the handler has changed.
if
(
input
===
lastInput
&&
output
===
lastOutput
)
return
if
(
input
&&
lastInput
&&
input
.
equals
(
lastInput
)
&&
output
&&
lastOutput
&&
lastOutput
.
equals
(
lastOutput
))
return
lastValue
.
current
=
[
input
,
output
]
onTokensChange
?.(
inputs
.
value
.
INPUT
,
inputs
.
value
.
OUTPUT
)
},
[
inputs
.
value
.
INPUT
,
inputs
.
value
.
OUTPUT
,
onTokensChange
])
const
onSwitchChain
=
useCallback
(
const
onSwitchChain
=
useCallback
(
// TODO(WEB-1757): Widget should not break if this rejects - upstream the catch to ignore it.
// TODO(WEB-1757): Widget should not break if this rejects - upstream the catch to ignore it.
({
chainId
}:
AddEthereumChainParameter
)
=>
switchChain
(
connector
,
Number
(
chainId
)).
catch
(()
=>
undefined
),
({
chainId
}:
AddEthereumChainParameter
)
=>
switchChain
(
connector
,
Number
(
chainId
)).
catch
(()
=>
undefined
),
[
connector
]
[
connector
]
)
)
useEffect
(()
=>
{
onTokensChange
?.(
inputs
.
value
.
INPUT
,
inputs
.
value
.
OUTPUT
)
},
[
inputs
.
value
.
INPUT
,
inputs
.
value
.
OUTPUT
,
onTokensChange
])
const
trace
=
useTrace
({
section
:
SectionName
.
WIDGET
})
const
trace
=
useTrace
({
section
:
SectionName
.
WIDGET
})
const
[
initialQuoteDate
,
setInitialQuoteDate
]
=
useState
<
Date
>
()
const
[
initialQuoteDate
,
setInitialQuoteDate
]
=
useState
<
Date
>
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment