-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move CSS reset, font loading and theme switch outside React to prevent flicker #494
Open
Danziger
wants to merge
11
commits into
development
Choose a base branch
from
feature/ui-fixes
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
09f073d
Add different logos when using the extension in development.
Danziger 2f796ce
Move CSS reset outside React.
Danziger 5a4bf78
Merge development and resolve conflicts.
Danziger 5b87679
Fix theme flicker.
Danziger 3ecfe8c
Remove comments.
Danziger 9d56e9c
- Remove unnecessary markup.
Danziger 11c1d05
Remove expanded URL param for the expanded popup view.
Danziger 9b44947
Implement the expanded mode with another HTML file and just CSS (no JS).
Danziger ef5c981
Implement reduced motion (no framer animations/transitions) mode base…
Danziger 739d547
Speed up cover removal.
Danziger 7ef6198
Add .editorcofig, .env.example and remove console.log().
Danziger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.{sh,bash}] | ||
end_of_line = lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PLASMO_PUBLIC_APP_TYPE=extension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
@font-face { | ||
font-family: "ManropeLocal"; | ||
font-style: normal; | ||
font-weight: 300; | ||
src: url(/assets/fonts/Manrope-Light.woff2) format('woff2'); | ||
} | ||
|
||
@font-face { | ||
font-family: "ManropeLocal"; | ||
font-style: normal; | ||
font-weight: 400; | ||
src: url(/assets/fonts/Manrope-Regular.woff2) format('woff2'); | ||
} | ||
|
||
@font-face { | ||
font-family: "ManropeLocal"; | ||
font-style: normal; | ||
font-weight: 500; | ||
src: url(/assets/fonts/Manrope-Medium.woff2) format('woff2'); | ||
} | ||
|
||
@font-face { | ||
font-family: "ManropeLocal"; | ||
font-style: normal; | ||
font-weight: 600; | ||
src: url(/assets/fonts/Manrope-SemiBold.woff2) format('woff2'); | ||
} | ||
|
||
@font-face { | ||
font-family: "ManropeLocal"; | ||
font-style: normal; | ||
font-weight: 600; | ||
src: url(/assets/fonts/Manrope-Bold.woff2) format('woff2'); | ||
} | ||
|
||
@font-face { | ||
font-family: "ManropeLocal"; | ||
font-style: normal; | ||
font-weight: 700; | ||
src: url(/assets/fonts/Manrope-ExtraBold.woff2) format('woff2'); | ||
} | ||
|
||
* { | ||
scrollbar-width: none; | ||
} | ||
|
||
*::-webkit-scrollbar { | ||
display: none | ||
} | ||
|
||
::selection { | ||
background-color: rgba(171, 154, 255, .6); | ||
color: #fff; | ||
} | ||
|
||
:root { | ||
--defaultBackgroundColor: white; | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
:root { | ||
--defaultBackgroundColor: black; | ||
} | ||
} | ||
|
||
body { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
body#popup { | ||
width: 377px; | ||
height: 600px; | ||
} | ||
|
||
body.fullscreen { | ||
width: 377px; | ||
height: 100vh; | ||
margin: 0 auto; | ||
} | ||
|
||
body.fullscreen::before { | ||
content: ""; | ||
position: fixed; | ||
top: 50%; | ||
left: 50%; | ||
width: 377px; | ||
height: 100vh; | ||
transform: translate(-50%, -50%); | ||
pointer-events: none; | ||
box-shadow: 0 0 128px 0 rgba(171, 154, 255, .4); | ||
} | ||
|
||
body, | ||
button, | ||
input, | ||
select, | ||
textarea { | ||
font-family: "ManropeLocal", "Manrope VF", "Manrope", sans-serif !important; | ||
} | ||
|
||
button { | ||
background: transparent; | ||
border: 0; | ||
padding: 0; | ||
} | ||
|
||
#cover { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
z-index: 99999999; | ||
background-color: var(--backgroundColor, var(--defaultBackgroundColor, white)); | ||
transition: background-color linear 230ms; | ||
} | ||
|
||
#cover[aria-hidden] { | ||
background: transparent; | ||
pointer-events: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const backgroundColor = localStorage.getItem("ARCONNECT_THEME_BACKGROUND_COLOR"); | ||
|
||
if (backgroundColor) document.documentElement.style.setProperty('--backgroundColor', backgroundColor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,11 @@ | |
"packageManager": "[email protected]", | ||
"homepage": "https://arconnect.io", | ||
"scripts": { | ||
"dev:chrome": "plasmo dev", | ||
"dev:chrome": "plasmo dev --verbose", | ||
"build:chrome": "plasmo build --no-hoist", | ||
"dev:firefox": "plasmo dev --target=firefox-mv2", | ||
"build:firefox": "plasmo build --target=firefox-mv2 --no-hoist", | ||
"nuke": "rm -rf node_modules build .plasmo", | ||
"fmt": "prettier --write .", | ||
"fmt:check": "prettier --check .", | ||
"prepare": "husky install" | ||
|
@@ -69,7 +70,7 @@ | |
"check-password-strength": "^2.0.7", | ||
"copy-to-clipboard": "^3.3.2", | ||
"dayjs": "^1.11.6", | ||
"framer-motion": "7.5.3", | ||
"framer-motion": "^11.11.7", | ||
"human-crypto-keys": "^0.1.4", | ||
"js-confetti": "^0.11.0", | ||
"mitt": "^3.0.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,81 @@ | ||
import { type DefaultTheme, ThemeProvider } from "styled-components"; | ||
import { type PropsWithChildren, useMemo } from "react"; | ||
import { ThemeProvider, type DefaultTheme } from "styled-components"; | ||
import { useEffect, type PropsWithChildren } from "react"; | ||
import { useHardwareApi } from "~wallets/hooks"; | ||
import { useTheme } from "~utils/theme"; | ||
import { Provider } from "@arconnect/components"; | ||
import { useTheme as useStyledComponentsTheme } from "styled-components"; | ||
import { MotionGlobalConfig } from "framer-motion"; | ||
|
||
export default function HardwareWalletTheme({ | ||
children | ||
}: PropsWithChildren<{}>) { | ||
// hardware api type | ||
const ARCONNECT_THEME_BACKGROUND_COLOR = "ARCONNECT_THEME_BACKGROUND_COLOR"; | ||
|
||
/** | ||
* Modify the theme if the active wallet is a hardware wallet. We transform the | ||
* default accent color to match the hardware wallet's accent. | ||
*/ | ||
function hardwareThemeModifier(theme: DefaultTheme): DefaultTheme { | ||
return { | ||
...theme, | ||
theme: "154, 184, 255", | ||
primary: "#9AB8FF", | ||
primaryBtnHover: "#6F93E1" | ||
}; | ||
} | ||
|
||
function noThemeModifier(theme: DefaultTheme): DefaultTheme { | ||
return theme; | ||
} | ||
|
||
export function ArConnectThemeProvider({ children }: PropsWithChildren<{}>) { | ||
const hardwareApi = useHardwareApi(); | ||
const theme = useTheme(); | ||
const themeModifier = hardwareApi ? hardwareThemeModifier : noThemeModifier; | ||
|
||
useEffect(() => { | ||
const reducedMotionPreference = window.matchMedia( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this here. It could eventually be added in settings too, just like the system theme can be overridden. |
||
"(prefers-reduced-motion)" | ||
); | ||
|
||
// hardware wallet accent color | ||
const hardwareApiTheme = useMemo<string | false>(() => { | ||
if (!hardwareApi) return false; | ||
if (reducedMotionPreference.matches) { | ||
// This could also be always set to `true` at the top of the file and then set to `false` after the application | ||
// loads if we still notice some flicker due to any animation/transition playing when the view first loads. | ||
|
||
MotionGlobalConfig.skipAnimations = true; | ||
} | ||
}, []); | ||
|
||
return ( | ||
<Provider theme={theme}> | ||
<ThemeProvider theme={themeModifier}> | ||
<ThemeBackgroundObserver /> | ||
|
||
{children} | ||
</ThemeProvider> | ||
</Provider> | ||
); | ||
} | ||
|
||
export function ThemeBackgroundObserver() { | ||
const styledComponentsTheme = useStyledComponentsTheme(); | ||
const backgroundColor = styledComponentsTheme.background; | ||
|
||
useEffect(() => { | ||
let formattedBackgroundColor = ""; | ||
|
||
if (backgroundColor.length === 3 || backgroundColor.length === 6) { | ||
formattedBackgroundColor = `#${backgroundColor}`; | ||
} else if (/\d{1,3}, ?\d{1,3}, ?\d{1,3}/.test(backgroundColor)) { | ||
formattedBackgroundColor = `rgb(${backgroundColor})`; | ||
} else if (/\d{1,3}, ?\d{1,3}, ?\d{1,3}, ?.+/.test(backgroundColor)) { | ||
formattedBackgroundColor = `rgba(${backgroundColor})`; | ||
} | ||
|
||
if (hardwareApi === "keystone") { | ||
return "154, 184, 255"; | ||
if (formattedBackgroundColor) { | ||
localStorage.setItem( | ||
ARCONNECT_THEME_BACKGROUND_COLOR, | ||
formattedBackgroundColor | ||
); | ||
} | ||
}, [backgroundColor]); | ||
|
||
return false; | ||
}, [hardwareApi]); | ||
|
||
// modify theme if the active wallet is a | ||
// hardware wallet | ||
// we transform the default accent color | ||
// to match the hardware wallet's accent | ||
function themeModifier(theme: DefaultTheme): DefaultTheme { | ||
if (!hardwareApiTheme) return theme; | ||
|
||
return { | ||
...theme, | ||
theme: hardwareApiTheme, | ||
primary: "#9AB8FF", | ||
primaryBtnHover: "#6F93E1" | ||
}; | ||
} | ||
|
||
return <ThemeProvider theme={themeModifier}>{children}</ThemeProvider>; | ||
return null; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Send view, the last option inside the menus was covered by the bottom navigation.