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
58b25d29
Unverified
Commit
58b25d29
authored
May 19, 2023
by
Mike Grabowski
Committed by
GitHub
May 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: expand settings by default when custom values are set (#6603)
feat: expand by default
parent
a2db3e27
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
126 deletions
+68
-126
index.test.tsx.snap
src/components/Expand/__snapshots__/index.test.tsx.snap
+0
-105
index.test.tsx
src/components/Expand/index.test.tsx
+18
-10
index.tsx
src/components/Expand/index.tsx
+10
-7
index.test.tsx
src/components/Settings/MaxSlippageSettings/index.test.tsx
+15
-2
index.tsx
src/components/Settings/MaxSlippageSettings/index.tsx
+5
-0
index.test.tsx
...nents/Settings/TransactionDeadlineSettings/index.test.tsx
+15
-2
index.tsx
...components/Settings/TransactionDeadlineSettings/index.tsx
+5
-0
No files found.
src/components/Expand/__snapshots__/index.test.tsx.snap
deleted
100644 → 0
View file @
a2db3e27
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Expand renders correctly 1`] = `
<DocumentFragment>
.c1 {
box-sizing: border-box;
margin: 0;
min-width: 0;
}
.c2 {
width: 100%;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
padding: 0;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: start;
-webkit-justify-content: flex-start;
-ms-flex-pack: start;
justify-content: flex-start;
}
.c3 {
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
}
.c0 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: start;
-webkit-justify-content: flex-start;
-ms-flex-pack: start;
justify-content: flex-start;
gap: 12px;
}
.c4 {
cursor: pointer;
-webkit-box-pack: end;
-webkit-justify-content: flex-end;
-ms-flex-pack: end;
justify-content: flex-end;
width: unset;
}
.c5 {
color: #7780A0;
-webkit-transform: rotate(0deg);
-ms-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: -webkit-transform 250ms;
-webkit-transition: transform 250ms;
transition: transform 250ms;
}
<div
class="c0"
>
<div
class="c1 c2 c3"
>
<span>
Header
</span>
<div
aria-expanded="false"
class="c1 c2 c4"
>
<span>
Button
</span>
<svg
class="c5"
fill="none"
height="24"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<polyline
points="6 9 12 15 18 9"
/>
</svg>
</div>
</div>
</div>
</DocumentFragment>
`;
src/components/Expand/index.test.tsx
View file @
58b25d29
import
{
fireEvent
,
render
,
screen
}
from
'
test-utils/render
'
import
noop
from
'
utils/noop
'
import
Expand
from
'
./index
'
describe
(
'
Expand
'
,
()
=>
{
it
(
'
renders correctly
'
,
()
=>
{
const
{
asFragment
}
=
render
(
<
Expand
header=
{
<
span
>
Header
</
span
>
}
button=
{
<
span
>
Button
</
span
>
}
>
it
(
'
does not render children when closed
'
,
()
=>
{
render
(
<
Expand
header=
{
<
span
>
Header
</
span
>
}
isOpen=
{
false
}
onToggle=
{
noop
}
button=
{
<
span
>
Button
</
span
>
}
>
Body
</
Expand
>
)
expect
(
asFragment
()).
toMatchSnapsho
t
()
expect
(
screen
.
queryByText
(
'
Body
'
)).
not
.
toBeInTheDocumen
t
()
})
it
(
'
toggles children on button press
'
,
()
=>
{
it
(
'
renders children when open
'
,
()
=>
{
render
(
<
Expand
header=
{
<
span
>
Header
</
span
>
}
button=
{
<
span
>
Button
</
span
>
}
>
<
Expand
header=
{
<
span
>
Header
</
span
>
}
isOpen=
{
true
}
onToggle=
{
noop
}
button=
{
<
span
>
Button
</
span
>
}
>
Body
</
Expand
>
)
expect
(
screen
.
queryByText
(
'
Body
'
)).
toBeInTheDocument
()
})
const
button
=
screen
.
getByText
(
'
Button
'
)
it
(
'
calls `onToggle` when button is pressed
'
,
()
=>
{
const
onToggle
=
jest
.
fn
()
render
(
<
Expand
header=
{
<
span
>
Header
</
span
>
}
isOpen=
{
false
}
onToggle=
{
onToggle
}
button=
{
<
span
>
Button
</
span
>
}
>
Body
</
Expand
>
)
fireEvent
.
click
(
button
)
expect
(
screen
.
queryByText
(
'
Body
'
)).
not
.
toBeNull
()
const
button
=
screen
.
getByText
(
'
Button
'
)
fireEvent
.
click
(
button
)
expect
(
screen
.
queryByText
(
'
Body
'
)).
toBeNull
()
expect
(
onToggle
).
toHaveBeenCalled
()
})
})
src/components/Expand/index.tsx
View file @
58b25d29
import
Column
from
'
components/Column
'
import
React
,
{
PropsWithChildren
,
ReactElement
,
useState
}
from
'
react
'
import
React
,
{
PropsWithChildren
,
ReactElement
}
from
'
react
'
import
{
ChevronDown
}
from
'
react-feather
'
import
styled
from
'
styled-components/macro
'
...
...
@@ -11,9 +11,9 @@ const ButtonContainer = styled(Row)`
width: unset;
`
const
ExpandIcon
=
styled
(
ChevronDown
)
<
{
$is
Expanded
:
boolean
}
>
`
const
ExpandIcon
=
styled
(
ChevronDown
)
<
{
$is
Open
:
boolean
}
>
`
color:
${({
theme
})
=>
theme
.
textSecondary
}
;
transform:
${({
$is
Expanded
})
=>
(
$isExpanded
?
'
rotate(180deg)
'
:
'
rotate(0deg)
'
)}
;
transform:
${({
$is
Open
})
=>
(
$isOpen
?
'
rotate(180deg)
'
:
'
rotate(0deg)
'
)}
;
transition: transform
${({
theme
})
=>
theme
.
transition
.
duration
.
medium
}
;
`
...
...
@@ -22,22 +22,25 @@ export default function Expand({
button
,
children
,
testId
,
isOpen
,
onToggle
,
}:
PropsWithChildren
<
{
header
:
ReactElement
button
:
ReactElement
testId
?:
string
isOpen
:
boolean
onToggle
:
()
=>
void
}
>
)
{
const
[
isExpanded
,
setExpanded
]
=
useState
(
false
)
return
(
<
Column
gap=
"md"
>
<
RowBetween
>
{
header
}
<
ButtonContainer
data
-
testid=
{
testId
}
onClick=
{
()
=>
setExpanded
(
!
isExpanded
)
}
aria
-
expanded=
{
isExpanded
}
>
<
ButtonContainer
data
-
testid=
{
testId
}
onClick=
{
onToggle
}
aria
-
expanded=
{
isOpen
}
>
{
button
}
<
ExpandIcon
$is
Expanded=
{
isExpanded
}
/>
<
ExpandIcon
$is
Open=
{
isOpen
}
/>
</
ButtonContainer
>
</
RowBetween
>
{
is
Expanded
&&
children
}
{
is
Open
&&
children
}
</
Column
>
)
}
src/components/Settings/MaxSlippageSettings/index.test.tsx
View file @
58b25d29
...
...
@@ -8,8 +8,12 @@ import MaxSlippageSettings from '.'
const
AUTO_SLIPPAGE
=
new
Percent
(
5
,
10
_000
)
const
render
AndExpand
SlippageSettings
=
()
=>
{
const
renderSlippageSettings
=
()
=>
{
render
(<
MaxSlippageSettings
autoSlippage=
{
AUTO_SLIPPAGE
}
/>)
}
const
renderAndExpandSlippageSettings
=
()
=>
{
renderSlippageSettings
()
// By default, the button to expand Slippage component and show `input` will have `Auto` label
fireEvent
.
click
(
screen
.
getByText
(
'
Auto
'
))
...
...
@@ -20,7 +24,7 @@ const switchToCustomSlippage = () => {
fireEvent
.
click
(
screen
.
getByText
(
'
Custom
'
))
}
const
getSlippageInput
=
()
=>
screen
.
get
ByTestId
(
'
slippage-input
'
)
as
HTMLInputElement
const
getSlippageInput
=
()
=>
screen
.
query
ByTestId
(
'
slippage-input
'
)
as
HTMLInputElement
describe
(
'
MaxSlippageSettings
'
,
()
=>
{
describe
(
'
input
'
,
()
=>
{
...
...
@@ -28,6 +32,15 @@ describe('MaxSlippageSettings', () => {
beforeEach
(()
=>
{
store
.
dispatch
(
updateUserSlippageTolerance
({
userSlippageTolerance
:
SlippageTolerance
.
Auto
}))
})
it
(
'
is not expanded by default
'
,
()
=>
{
renderSlippageSettings
()
expect
(
getSlippageInput
()).
not
.
toBeInTheDocument
()
})
it
(
'
is expanded by default when custom slippage is set
'
,
()
=>
{
store
.
dispatch
(
updateUserSlippageTolerance
({
userSlippageTolerance
:
10
}))
renderSlippageSettings
()
expect
(
getSlippageInput
()).
toBeInTheDocument
()
})
it
(
'
does not render auto slippage as a value, but a placeholder
'
,
()
=>
{
renderAndExpandSlippageSettings
()
switchToCustomSlippage
()
...
...
src/components/Settings/MaxSlippageSettings/index.tsx
View file @
58b25d29
...
...
@@ -53,6 +53,9 @@ export default function MaxSlippageSettings({ autoSlippage }: { autoSlippage: Pe
const
[
slippageInput
,
setSlippageInput
]
=
useState
(
defaultSlippageInputValue
)
const
[
slippageError
,
setSlippageError
]
=
useState
<
SlippageError
|
false
>
(
false
)
// If user has previously entered a custom slippage, we want to show the settings expanded by default.
const
[
isOpen
,
setIsOpen
]
=
useState
(
defaultSlippageInputValue
.
length
>
0
)
const
parseSlippageInput
=
(
value
:
string
)
=>
{
// Do not allow non-numerical characters in the input field or more than two decimals
if
(
value
.
length
>
0
&&
!
NUMBER_WITH_MAX_TWO_DECIMAL_PLACES
.
test
(
value
))
{
...
...
@@ -93,6 +96,8 @@ export default function MaxSlippageSettings({ autoSlippage }: { autoSlippage: Pe
return
(
<
Expand
testId=
"max-slippage-settings"
isOpen=
{
isOpen
}
onToggle=
{
()
=>
setIsOpen
(
!
isOpen
)
}
header=
{
<
Row
width=
"auto"
>
<
ThemedText
.
BodySecondary
>
...
...
src/components/Settings/TransactionDeadlineSettings/index.test.tsx
View file @
58b25d29
...
...
@@ -5,14 +5,18 @@ import { fireEvent, render, screen } from 'test-utils/render'
import
TransactionDeadlineSettings
from
'
.
'
const
render
AndExpand
TransactionDeadlineSettings
=
()
=>
{
const
renderTransactionDeadlineSettings
=
()
=>
{
render
(<
TransactionDeadlineSettings
/>)
}
const
renderAndExpandTransactionDeadlineSettings
=
()
=>
{
renderTransactionDeadlineSettings
()
// By default, the button to expand Slippage component and show `input` will have `<deadline>m` label
fireEvent
.
click
(
screen
.
getByText
(
`
${
DEFAULT_DEADLINE_FROM_NOW
/
60
}
m`
))
}
const
getDeadlineInput
=
()
=>
screen
.
get
ByTestId
(
'
deadline-input
'
)
as
HTMLInputElement
const
getDeadlineInput
=
()
=>
screen
.
query
ByTestId
(
'
deadline-input
'
)
as
HTMLInputElement
describe
(
'
TransactionDeadlineSettings
'
,
()
=>
{
describe
(
'
input
'
,
()
=>
{
...
...
@@ -20,6 +24,15 @@ describe('TransactionDeadlineSettings', () => {
beforeEach
(()
=>
{
store
.
dispatch
(
updateUserDeadline
({
userDeadline
:
DEFAULT_DEADLINE_FROM_NOW
}))
})
it
(
'
is not expanded by default
'
,
()
=>
{
renderTransactionDeadlineSettings
()
expect
(
getDeadlineInput
()).
not
.
toBeInTheDocument
()
})
it
(
'
is expanded by default when custom deadline is set
'
,
()
=>
{
store
.
dispatch
(
updateUserDeadline
({
userDeadline
:
DEFAULT_DEADLINE_FROM_NOW
*
2
}))
renderTransactionDeadlineSettings
()
expect
(
getDeadlineInput
()).
toBeInTheDocument
()
})
it
(
'
does not render default deadline as a value, but a placeholder
'
,
()
=>
{
renderAndExpandTransactionDeadlineSettings
()
expect
(
getDeadlineInput
().
value
).
toBe
(
''
)
...
...
src/components/Settings/TransactionDeadlineSettings/index.tsx
View file @
58b25d29
...
...
@@ -26,6 +26,9 @@ export default function TransactionDeadlineSettings() {
const
[
deadlineInput
,
setDeadlineInput
]
=
useState
(
defaultInputValue
)
const
[
deadlineError
,
setDeadlineError
]
=
useState
<
DeadlineError
|
false
>
(
false
)
// If user has previously entered a custom deadline, we want to show the settings expanded by default.
const
[
isOpen
,
setIsOpen
]
=
useState
(
defaultInputValue
.
length
>
0
)
function
parseCustomDeadline
(
value
:
string
)
{
// Do not allow non-numerical characters in the input field
if
(
value
.
length
>
0
&&
!
NUMBERS_ONLY
.
test
(
value
))
{
...
...
@@ -56,6 +59,8 @@ export default function TransactionDeadlineSettings() {
return
(
<
Expand
isOpen=
{
isOpen
}
onToggle=
{
()
=>
setIsOpen
(
!
isOpen
)
}
testId=
"transaction-deadline-settings"
header=
{
<
Row
width=
"auto"
>
...
...
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