-
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.
Fix a bug with rendering of the root component
There was a problem with calling `ReactDOMClient.createRoot()` on a container that has already been passed to `createRoot()` before. Let's move the provider logic into a separate file to make sure the entry point file will be run only once.
- Loading branch information
1 parent
d6a45bc
commit 71226eb
Showing
3 changed files
with
31 additions
and
32 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
import React from "react" | ||
import { useEmbedFeatureFlag } from "./hooks" | ||
import { LedgerWalletAPIProvider } from "./providers" | ||
import { LOCAL_STORAGE_EMBED } from "./constants" | ||
|
||
function DApp() { | ||
const { isEmbed } = useEmbedFeatureFlag() | ||
if (isEmbed === "true") return <h1>Ledger live - Acre dApp</h1> | ||
return <h1>Acre dApp</h1> | ||
} | ||
|
||
function DAppWrapper() { | ||
const { enableIsEmbedFeatureFlag } = useEmbedFeatureFlag() | ||
|
||
const params = new URLSearchParams(window.location.search) | ||
const isEmbed = params.get(LOCAL_STORAGE_EMBED) | ||
|
||
if (isEmbed) { | ||
enableIsEmbedFeatureFlag() | ||
return ( | ||
<LedgerWalletAPIProvider> | ||
<DApp /> | ||
</LedgerWalletAPIProvider> | ||
) | ||
} | ||
return <DApp /> | ||
} | ||
|
||
export default DAppWrapper |
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,29 +1,9 @@ | ||
import React from "react" | ||
import ReactDOM from "react-dom/client" | ||
import App from "./App" | ||
import { LedgerWalletAPIProvider } from "./providers" | ||
import { LOCAL_STORAGE_EMBED } from "./constants" | ||
import { useEmbedFeatureFlag } from "./hooks" | ||
|
||
function DAppProvider() { | ||
const { enableIsEmbedFeatureFlag } = useEmbedFeatureFlag() | ||
|
||
const params = new URLSearchParams(window.location.search) | ||
const isEmbed = params.get(LOCAL_STORAGE_EMBED) | ||
|
||
if (isEmbed) { | ||
enableIsEmbedFeatureFlag() | ||
return ( | ||
<LedgerWalletAPIProvider> | ||
<App /> | ||
</LedgerWalletAPIProvider> | ||
) | ||
} | ||
return <App /> | ||
} | ||
import DAppWrapper from "./DApp" | ||
|
||
ReactDOM.createRoot(document.getElementById("root")!).render( | ||
<React.StrictMode> | ||
<DAppProvider /> | ||
<DAppWrapper /> | ||
</React.StrictMode>, | ||
) |