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
e88a50d3
Unverified
Commit
e88a50d3
authored
Jan 04, 2023
by
eddie
Committed by
GitHub
Jan 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: colors in token warnings (#5787)
parent
102d99af
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
29 deletions
+81
-29
TokenSafetyLabel.tsx
src/components/TokenSafety/TokenSafetyLabel.tsx
+4
-4
TokenSafetyMessage.tsx
src/components/TokenSafety/TokenSafetyMessage.tsx
+8
-7
useTokenWarningColor.test.ts
src/hooks/useTokenWarningColor.test.ts
+41
-0
useTokenWarningColor.ts
src/hooks/useTokenWarningColor.ts
+21
-14
test-utils.tsx
src/test-utils.tsx
+4
-1
colors.ts
src/theme/colors.ts
+3
-3
No files found.
src/components/TokenSafety/TokenSafetyLabel.tsx
View file @
e88a50d3
import
{
WARNING_LEVEL
}
from
'
constants/tokenSafety
'
import
{
useTokenWarningColor
}
from
'
hooks/useTokenWarningColor
'
import
{
useTokenWarningColor
,
useTokenWarningTextColor
}
from
'
hooks/useTokenWarningColor
'
import
{
ReactNode
}
from
'
react
'
import
{
AlertTriangle
,
Slash
}
from
'
react-feather
'
import
{
Text
}
from
'
rebass
'
import
styled
from
'
styled-components/macro
'
const
Label
=
styled
.
div
<
{
color
:
string
}
>
`
const
Label
=
styled
.
div
<
{
color
:
string
;
backgroundColor
:
string
}
>
`
padding: 4px 4px;
font-size: 12px;
background-color:
${({
color
})
=>
color
+
'
1F
'
}
;
background-color:
${({
backgroundColor
})
=>
backgroundColor
}
;
border-radius: 8px;
color:
${({
color
})
=>
color
}
;
display: inline-flex;
...
...
@@ -28,7 +28,7 @@ type TokenWarningLabelProps = {
}
export
default
function
TokenSafetyLabel
({
level
,
canProceed
,
children
}:
TokenWarningLabelProps
)
{
return
(
<
Label
color=
{
useTokenWarningColor
(
level
)
}
>
<
Label
color=
{
useTokenWarning
TextColor
(
level
)
}
backgroundColor=
{
useTokenWarning
Color
(
level
)
}
>
<
Title
marginRight=
"5px"
>
{
children
}
</
Title
>
{
canProceed
?
<
AlertTriangle
strokeWidth=
{
2.5
}
size=
"14px"
/>
:
<
Slash
strokeWidth=
{
2.5
}
size=
"14px"
/>
}
</
Label
>
...
...
src/components/TokenSafety/TokenSafetyMessage.tsx
View file @
e88a50d3
import
{
Trans
}
from
'
@lingui/macro
'
import
{
getWarningCopy
,
TOKEN_SAFETY_ARTICLE
,
Warning
}
from
'
constants/tokenSafety
'
import
{
useTokenWarningColor
}
from
'
hooks/useTokenWarningColor
'
import
{
useTokenWarningColor
,
useTokenWarningTextColor
}
from
'
hooks/useTokenWarningColor
'
import
{
AlertTriangle
,
Slash
}
from
'
react-feather
'
import
{
Text
}
from
'
rebass
'
import
styled
from
'
styled-components/macro
'
import
{
ExternalLink
}
from
'
theme
'
const
Label
=
styled
.
div
<
{
color
:
string
}
>
`
const
Label
=
styled
.
div
<
{
color
:
string
;
backgroundColor
:
string
}
>
`
width: 100%;
padding: 12px 20px 16px;
background-color:
${({
color
})
=>
color
+
'
1F
'
}
;
background-color:
${({
backgroundColor
})
=>
backgroundColor
}
;
border-radius: 16px;
color:
${({
color
})
=>
color
}
;
`
...
...
@@ -39,17 +39,18 @@ const StyledLink = styled(ExternalLink)`
font-weight: 700;
`
type
Token
Warning
MessageProps
=
{
type
Token
Safety
MessageProps
=
{
warning
:
Warning
tokenAddress
:
string
}
export
default
function
TokenWarningMessage
({
warning
,
tokenAddress
}:
TokenWarningMessageProps
)
{
const
color
=
useTokenWarningColor
(
warning
.
level
)
export
default
function
TokenSafetyMessage
({
warning
,
tokenAddress
}:
TokenSafetyMessageProps
)
{
const
backgroundColor
=
useTokenWarningColor
(
warning
.
level
)
const
textColor
=
useTokenWarningTextColor
(
warning
.
level
)
const
{
heading
,
description
}
=
getWarningCopy
(
warning
)
return
(
<
Label
color=
{
c
olor
}
>
<
Label
color=
{
textColor
}
backgroundColor=
{
backgroundC
olor
}
>
<
TitleRow
>
{
warning
.
canProceed
?
<
AlertTriangle
size=
"16px"
/>
:
<
Slash
size=
"16px"
/>
}
<
Title
marginLeft=
"7px"
>
{
warning
.
message
}
</
Title
>
...
...
src/hooks/useTokenWarningColor.test.ts
0 → 100644
View file @
e88a50d3
import
{
WARNING_LEVEL
}
from
'
constants/tokenSafety
'
import
{
renderHook
}
from
'
test-utils
'
import
{
lightTheme
}
from
'
theme/colors
'
import
{
useTokenWarningColor
,
useTokenWarningTextColor
}
from
'
./useTokenWarningColor
'
describe
(
'
Token Warning Colors
'
,
()
=>
{
describe
(
'
useTokenWarningColor
'
,
()
=>
{
it
(
'
medium
'
,
()
=>
{
const
{
result
}
=
renderHook
(()
=>
useTokenWarningColor
(
WARNING_LEVEL
.
MEDIUM
))
expect
(
result
.
current
).
toEqual
(
lightTheme
.
accentWarningSoft
)
})
it
(
'
strong
'
,
()
=>
{
const
{
result
}
=
renderHook
(()
=>
useTokenWarningColor
(
WARNING_LEVEL
.
UNKNOWN
))
expect
(
result
.
current
).
toEqual
(
lightTheme
.
accentFailureSoft
)
})
it
(
'
blocked
'
,
()
=>
{
const
{
result
}
=
renderHook
(()
=>
useTokenWarningColor
(
WARNING_LEVEL
.
BLOCKED
))
expect
(
result
.
current
).
toEqual
(
lightTheme
.
backgroundFloating
)
})
})
describe
(
'
useTokenWarningTextColor
'
,
()
=>
{
it
(
'
medium
'
,
()
=>
{
const
{
result
}
=
renderHook
(()
=>
useTokenWarningTextColor
(
WARNING_LEVEL
.
MEDIUM
))
expect
(
result
.
current
).
toEqual
(
lightTheme
.
accentWarning
)
})
it
(
'
strong
'
,
()
=>
{
const
{
result
}
=
renderHook
(()
=>
useTokenWarningTextColor
(
WARNING_LEVEL
.
UNKNOWN
))
expect
(
result
.
current
).
toEqual
(
lightTheme
.
accentFailure
)
})
it
(
'
blocked
'
,
()
=>
{
const
{
result
}
=
renderHook
(()
=>
useTokenWarningTextColor
(
WARNING_LEVEL
.
BLOCKED
))
expect
(
result
.
current
).
toEqual
(
lightTheme
.
textSecondary
)
})
})
})
src/hooks/useTokenWarningColor.ts
View file @
e88a50d3
import
{
WARNING_LEVEL
}
from
'
constants/tokenSafety
'
import
{
useEffect
,
useState
}
from
'
react
'
import
{
useTheme
}
from
'
styled-components/macro
'
export
const
useTokenWarningColor
=
(
level
:
WARNING_LEVEL
)
=>
{
const
[
color
,
setColor
]
=
useState
(
''
)
export
const
useTokenWarningTextColor
=
(
level
:
WARNING_LEVEL
)
=>
{
const
theme
=
useTheme
()
useEffect
(()
=>
{
switch
(
level
)
{
case
WARNING_LEVEL
.
MEDIUM
:
return
setColor
(
theme
.
accentWarning
)
return
theme
.
accentWarning
case
WARNING_LEVEL
.
UNKNOWN
:
return
setColor
(
theme
.
accentFailure
)
return
theme
.
accentFailure
case
WARNING_LEVEL
.
BLOCKED
:
return
setColor
(
theme
.
textSecondary
)
return
theme
.
textSecondary
}
},
[
level
,
theme
])
}
export
const
useTokenWarningColor
=
(
level
:
WARNING_LEVEL
)
=>
{
const
theme
=
useTheme
()
return
color
switch
(
level
)
{
case
WARNING_LEVEL
.
MEDIUM
:
return
theme
.
accentWarningSoft
case
WARNING_LEVEL
.
UNKNOWN
:
return
theme
.
accentFailureSoft
case
WARNING_LEVEL
.
BLOCKED
:
return
theme
.
backgroundFloating
}
}
src/test-utils.tsx
View file @
e88a50d3
import
{
i18n
}
from
'
@lingui/core
'
import
{
I18nProvider
}
from
'
@lingui/react
'
import
{
render
}
from
'
@testing-library/react
'
import
{
render
,
renderHook
}
from
'
@testing-library/react
'
import
Web3Provider
from
'
components/Web3Provider
'
import
{
DEFAULT_LOCALE
}
from
'
constants/locales
'
import
{
BlockNumberProvider
}
from
'
lib/hooks/useBlockNumber
'
...
...
@@ -44,6 +44,9 @@ const WithProviders = ({ children }: { children?: ReactNode }) => {
}
const
customRender
=
(
ui
:
ReactElement
)
=>
render
(
ui
,
{
wrapper
:
WithProviders
})
const
customRenderHook
=
<
Result
,
Props
>
(hook: (initialProps: Props) =
>
Result) =
>
renderHook(hook,
{
wrapper
:
WithProviders
}
)
export * from '@testing-library/react'
export
{
customRender
as
render
}
export
{
customRenderHook
as
renderHook
}
src/theme/colors.ts
View file @
e88a50d3
...
...
@@ -150,7 +150,7 @@ export const darkTheme = {
accentActiveSoft
:
opacify
(
24
,
colors
.
blue400
),
accentSuccessSoft
:
opacify
(
24
,
colors
.
green400
),
accentWarningSoft
:
opacify
(
24
,
colors
.
gold200
),
accentFailureSoft
:
opacify
(
12
,
colors
.
red
4
00
),
accentFailureSoft
:
opacify
(
12
,
colors
.
red
3
00
),
accentTextDarkPrimary
:
opacify
(
80
,
colors
.
gray900
),
accentTextDarkSecondary
:
opacify
(
60
,
colors
.
gray900
),
...
...
@@ -200,7 +200,7 @@ export const lightTheme: Theme = {
accentActionSoft
:
opacify
(
24
,
colors
.
pink400
),
accentActiveSoft
:
opacify
(
24
,
colors
.
blue400
),
accentSuccessSoft
:
opacify
(
24
,
colors
.
green
4
00
),
accentSuccessSoft
:
opacify
(
24
,
colors
.
green
3
00
),
accentWarningSoft
:
opacify
(
24
,
colors
.
gold200
),
accentFailureSoft
:
opacify
(
12
,
colors
.
red400
),
...
...
@@ -209,7 +209,7 @@ export const lightTheme: Theme = {
accentTextDarkTertiary
:
opacify
(
24
,
colors
.
gray900
),
accentTextLightPrimary
:
colors
.
gray50
,
accentTextLightSecondary
:
opacify
(
60
,
colors
.
gray50
),
accentTextLightSecondary
:
opacify
(
72
,
colors
.
gray50
),
accentTextLightTertiary
:
opacify
(
12
,
colors
.
gray50
),
deepShadow
:
...
...
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