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
2aa4ec6a
Unverified
Commit
2aa4ec6a
authored
Nov 10, 2022
by
Zach Pomerantz
Committed by
GitHub
Nov 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: clear or retain amounts on token select (#5161)
* fix: clear or retain amounts on token select * lint: add curlies
parent
a70ef432
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
19 deletions
+23
-19
inputs.tsx
src/components/Widget/inputs.tsx
+23
-19
No files found.
src/components/Widget/inputs.tsx
View file @
2aa4ec6a
...
...
@@ -48,7 +48,7 @@ export function useSyncWidgetInputs({
if
(
origin
===
'
max
'
)
{
sendAnalyticsEvent
(
EventName
.
SWAP_MAX_TOKEN_AMOUNT_SELECTED
,
{
...
trace
})
}
setType
(
toTradeType
(
field
)
)
setType
(
field
===
Field
.
INPUT
?
TradeType
.
EXACT_INPUT
:
TradeType
.
EXACT_OUTPUT
)
setAmount
(
amount
)
},
[
trace
]
...
...
@@ -71,20 +71,34 @@ export function useSyncWidgetInputs({
},
[])
const
onTokenSelect
=
useCallback
(
(
t
oken
:
Currency
)
=>
{
(
selectingT
oken
:
Currency
)
=>
{
if
(
selectingField
===
undefined
)
return
setType
(
toTradeType
(
selectingField
))
const
otherField
=
invertField
(
selectingField
)
let
otherToken
=
tokens
[
otherField
]
otherToken
=
otherToken
?.
equals
(
token
)
?
tokens
[
selectingField
]
:
otherToken
const
update
=
{
[
selectingField
]:
token
,
[
otherField
]:
otherToken
,
const
isFlip
=
tokens
[
otherField
]?.
equals
(
selectingToken
)
const
update
:
SwapTokens
=
{
[
selectingField
]:
selectingToken
,
[
otherField
]:
isFlip
?
tokens
[
selectingField
]
:
tokens
[
otherField
],
default
:
tokens
.
default
,
}
setType
((
type
)
=>
{
// If flipping the tokens, also flip the type/amount.
if
(
isFlip
)
{
return
invertTradeType
(
type
)
}
// Setting a new token should clear its amount, if it is set.
const
activeField
=
type
===
TradeType
.
EXACT_INPUT
?
Field
.
INPUT
:
Field
.
OUTPUT
if
(
selectingField
===
activeField
)
{
setAmount
(()
=>
EMPTY_AMOUNT
)
}
return
type
})
if
(
!
includesDefaultToken
(
update
))
{
onTokenChange
?.(
update
[
Field
.
OUTPUT
]
||
update
[
Field
.
INPUT
]
||
t
oken
)
onTokenChange
?.(
update
[
Field
.
OUTPUT
]
||
selectingT
oken
)
}
setTokens
(
update
)
},
...
...
@@ -127,16 +141,6 @@ function invertField(field: Field) {
}
}
// TODO(zzmp): Move to @uniswap/widgets.
function
toTradeType
(
modifiedField
:
Field
)
{
switch
(
modifiedField
)
{
case
Field
.
INPUT
:
return
TradeType
.
EXACT_INPUT
case
Field
.
OUTPUT
:
return
TradeType
.
EXACT_OUTPUT
}
}
// TODO(zzmp): Include in @uniswap/sdk-core (on TradeType, if possible).
function
invertTradeType
(
tradeType
:
TradeType
)
{
switch
(
tradeType
)
{
...
...
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