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
33c93b5d
Unverified
Commit
33c93b5d
authored
Sep 18, 2023
by
Zach Pomerantz
Committed by
GitHub
Sep 18, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: spurious Swap re-renders (#7333)
parent
5ba046f1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
12 deletions
+17
-12
index.tsx
src/components/Tokens/TokenDetails/index.tsx
+2
-4
index.tsx
src/pages/Swap/index.tsx
+15
-8
No files found.
src/components/Tokens/TokenDetails/index.tsx
View file @
33c93b5d
...
...
@@ -248,10 +248,8 @@ export default function TokenDetails({
<
div
style=
{
{
pointerEvents
:
isBlockedToken
?
'
none
'
:
'
auto
'
}
}
>
<
Swap
chainId=
{
pageChainId
}
prefilledState=
{
{
[
Field
.
INPUT
]:
{
currencyId
:
inputTokenAddress
},
[
Field
.
OUTPUT
]:
{
currencyId
:
address
===
NATIVE_CHAIN_ID
?
'
ETH
'
:
address
},
}
}
initialInputCurrencyId=
{
inputTokenAddress
}
initialOutputCurrencyId=
{
address
===
NATIVE_CHAIN_ID
?
'
ETH
'
:
address
}
onCurrencyChange=
{
handleCurrencyChange
}
disableTokenInputs=
{
pageChainId
!==
connectedChainId
}
/>
...
...
src/pages/Swap/index.tsx
View file @
33c93b5d
...
...
@@ -150,10 +150,8 @@ export default function SwapPage({ className }: { className?: string }) {
<
Swap
className=
{
className
}
chainId=
{
supportedChainId
??
ChainId
.
MAINNET
}
prefilledState=
{
{
[
Field
.
INPUT
]:
{
currencyId
:
loadedUrlParams
?.[
Field
.
INPUT
]?.
currencyId
},
[
Field
.
OUTPUT
]:
{
currencyId
:
loadedUrlParams
?.[
Field
.
OUTPUT
]?.
currencyId
},
}
}
initialInputCurrencyId=
{
loadedUrlParams
?.[
Field
.
INPUT
]?.
currencyId
}
initialOutputCurrencyId=
{
loadedUrlParams
?.[
Field
.
OUTPUT
]?.
currencyId
}
disableTokenInputs=
{
supportedChainId
===
undefined
}
/>
<
NetworkAlert
/>
...
...
@@ -172,13 +170,15 @@ export default function SwapPage({ className }: { className?: string }) {
*/
export
function
Swap
({
className
,
prefilledState
=
{},
initialInputCurrencyId
,
initialOutputCurrencyId
,
chainId
,
onCurrencyChange
,
disableTokenInputs
=
false
,
}:
{
className
?:
string
prefilledState
?:
Partial
<
SwapState
>
initialInputCurrencyId
?:
string
|
null
initialOutputCurrencyId
?:
string
|
null
chainId
?:
ChainId
onCurrencyChange
?:
(
selected
:
Pick
<
SwapState
,
Field
.
INPUT
|
Field
.
OUTPUT
>
)
=>
void
disableTokenInputs
?:
boolean
...
...
@@ -187,8 +187,8 @@ export function Swap({
const
trace
=
useTrace
()
// token warning stuff
const
prefilledInputCurrency
=
useCurrency
(
prefilledState
?.[
Field
.
INPUT
]?.
c
urrencyId
)
const
prefilledOutputCurrency
=
useCurrency
(
prefilledState
?.[
Field
.
OUTPUT
]?.
c
urrencyId
)
const
prefilledInputCurrency
=
useCurrency
(
initialInputC
urrencyId
)
const
prefilledOutputCurrency
=
useCurrency
(
initialOutputC
urrencyId
)
const
[
loadedInputCurrency
,
setLoadedInputCurrency
]
=
useState
(
prefilledInputCurrency
)
const
[
loadedOutputCurrency
,
setLoadedOutputCurrency
]
=
useState
(
prefilledOutputCurrency
)
...
...
@@ -236,6 +236,13 @@ export function Swap({
const
toggleWalletDrawer
=
useToggleAccountDrawer
()
// swap state
const
prefilledState
=
useMemo
(
()
=>
({
[
Field
.
INPUT
]:
{
currencyId
:
initialInputCurrencyId
},
[
Field
.
OUTPUT
]:
{
currencyId
:
initialOutputCurrencyId
},
}),
[
initialInputCurrencyId
,
initialOutputCurrencyId
]
)
const
[
state
,
dispatch
]
=
useReducer
(
swapReducer
,
{
...
initialSwapState
,
...
prefilledState
})
const
{
typedValue
,
recipient
,
independentField
}
=
state
...
...
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