-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We would like to be able to change the theme mode for the dApp. The mode should be detected for ledger live apps. Let's use an external chakra UI lib to create custom styles for components.
- Loading branch information
1 parent
d378a57
commit 2d2187d
Showing
9 changed files
with
1,300 additions
and
18 deletions.
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
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,24 +1,50 @@ | ||
import React from "react" | ||
import { ChakraProvider, Button, Box } from "@chakra-ui/react" | ||
import { useEmbedFeatureFlag } from "./hooks" | ||
import { LedgerWalletAPIProvider } from "./providers" | ||
import { getThemeConfig } from "./theme/utils/utils" | ||
import theme from "./theme/index" | ||
|
||
function DApp() { | ||
function DAppContent() { | ||
const { isEmbed } = useEmbedFeatureFlag() | ||
if (isEmbed === "true") return <h1>Ledger live - Acre dApp</h1> | ||
return <h1>Acre dApp</h1> | ||
let header = "Acre dApp" | ||
if (isEmbed === "true") header = "Ledger live - Acre dApp" | ||
|
||
return ( | ||
<Box p={4}> | ||
<h1>{header}</h1> | ||
<Button>Test button</Button> | ||
</Box> | ||
) | ||
} | ||
|
||
function DAppWrapper() { | ||
function DApp() { | ||
const { isEmbed } = useEmbedFeatureFlag() | ||
|
||
if (isEmbed === "true") { | ||
return ( | ||
<LedgerWalletAPIProvider> | ||
<DApp /> | ||
<DAppContent /> | ||
</LedgerWalletAPIProvider> | ||
) | ||
} | ||
return <DApp /> | ||
return <DAppContent /> | ||
} | ||
|
||
function DAppProviders() { | ||
const params = new URLSearchParams(window.location.search) | ||
const themeMode = params.get("theme") | ||
|
||
return ( | ||
<ChakraProvider | ||
theme={{ | ||
...theme, | ||
config: getThemeConfig(themeMode), | ||
}} | ||
> | ||
<DApp /> | ||
</ChakraProvider> | ||
) | ||
} | ||
|
||
export default DAppWrapper | ||
export default DAppProviders |
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,9 +1,9 @@ | ||
import React from "react" | ||
import ReactDOM from "react-dom/client" | ||
import DAppWrapper from "./DApp" | ||
import DAppProviders from "./DApp" | ||
|
||
ReactDOM.createRoot(document.getElementById("root")!).render( | ||
<React.StrictMode> | ||
<DAppWrapper /> | ||
<DAppProviders /> | ||
</React.StrictMode>, | ||
) |
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,13 @@ | ||
import { mode } from "@chakra-ui/theme-tools" | ||
import type { StyleFunctionProps } from "@chakra-ui/styled-system" | ||
|
||
const Button = { | ||
variants: { | ||
solid: (props: StyleFunctionProps) => ({ | ||
backgroundColor: mode("black", "purple")(props), | ||
color: "white", | ||
}), | ||
}, | ||
} | ||
|
||
export default Button |
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,14 @@ | ||
import { extendTheme } from "@chakra-ui/react" | ||
import Button from "./Button" | ||
import { colors } from "./utils/index" | ||
|
||
export const defaultTheme = { | ||
colors, | ||
components: { | ||
Button, | ||
}, | ||
} | ||
|
||
const theme = extendTheme(defaultTheme) | ||
|
||
export default theme |
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,8 @@ | ||
// TODO: Currently, the correct colors have not yet been defined. | ||
// Let's update them later. | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const colors = { | ||
white: "#FFF", | ||
black: "#000", | ||
purple: "#7D00FF", | ||
} |
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,2 @@ | ||
export * from "./utils" | ||
export * from "./colors" |
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,9 @@ | ||
// For the ledger live app, we should detect the theme set for the user. | ||
// Otherwise, let's set the mode to light by default. | ||
// eslint-disable-next-line import/prefer-default-export | ||
export function getThemeConfig(theme: string | null) { | ||
return { | ||
initialColorMode: theme ?? "light", | ||
useSystemColorMode: false, | ||
} | ||
} |
Oops, something went wrong.