-
-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reference): act-1446 - added ff condition for reference pages (#…
…1403) * feat(reference): act-1446 - added ff condition for reference pages * feat(reference): act-1446 - fixes for build * feat(reference): act-1446 - minor fix * feat(reference): act-1446 - minor style fix
- Loading branch information
1 parent
a630c5e
commit cd2122d
Showing
4 changed files
with
109 additions
and
20 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
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,80 @@ | ||
import React, { useState, useEffect, useMemo } from "react"; | ||
import BrowserOnly from '@docusaurus/BrowserOnly'; | ||
import { usePluginData } from "@docusaurus/useGlobalData"; | ||
import ldClient from "launchdarkly"; | ||
import { useLocation } from "@docusaurus/router"; | ||
import Layout from "@theme-original/Layout"; | ||
import ParserOpenRPC from "@site/src/components/ParserOpenRPC"; | ||
import { ResponseItem, NETWORK_NAMES } from "@site/src/plugins/plugin-json-rpc"; | ||
import styles from "./styles.module.css"; | ||
|
||
const REF_FF = "mm-new-reference-enabled"; | ||
const REF_PATH = "/wallet/reference/"; | ||
const EXEPT_METHODS = [ | ||
"wallet_requestPermissions", | ||
"wallet_revokePermissions", | ||
"eth_signTypedData_v4" | ||
]; | ||
|
||
export default function LayoutWrapper({ children }) { | ||
const location = useLocation(); | ||
const { netData } = usePluginData("plugin-json-rpc") as { netData?: ResponseItem[] }; | ||
const [ldReady, setLdReady] = useState(false); | ||
const [newReferenceEnabled, setNewReferenceEnabled] = useState(false); | ||
|
||
const metamaskNetwork = netData?.find(net => net.name === NETWORK_NAMES.metamask); | ||
const metamaskMethods = metamaskNetwork?.data?.methods?.map((item) => item.name) || []; | ||
|
||
const referencePageName = useMemo(() => { | ||
const currentPath = location.pathname; | ||
if (currentPath.includes(REF_PATH) && metamaskMethods.length > 0) { | ||
const methodPath = currentPath.replace(REF_PATH, "").replace("/", ""); | ||
const page = metamaskMethods.find(name => name.toLowerCase() === methodPath && !EXEPT_METHODS.includes(name)); | ||
return page; | ||
} | ||
return false; | ||
}, [location.pathname, metamaskMethods]); | ||
|
||
useEffect(() => { | ||
ldClient.waitUntilReady().then(() => { | ||
setNewReferenceEnabled(ldClient.variation(REF_FF, false)); | ||
setLdReady(true); | ||
}); | ||
const handleChange = (current) => { | ||
setNewReferenceEnabled(current); | ||
}; | ||
ldClient.on(`change:${REF_FF}`, handleChange); | ||
return () => { | ||
ldClient.off(`change:${REF_FF}`, handleChange); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<BrowserOnly> | ||
{ | ||
() => { | ||
return ( | ||
<> | ||
{newReferenceEnabled && ldReady && referencePageName ? ( | ||
<Layout> | ||
<div className={styles.pageWrapper}> | ||
{children?.props?.children[0]?.type === "aside" && ( | ||
<>{children.props.children[0]}</> | ||
)} | ||
<div className={styles.mainContainer}> | ||
<div className={styles.contentWrapper}> | ||
<ParserOpenRPC network={NETWORK_NAMES.metamask} method={referencePageName} /> | ||
</div> | ||
</div> | ||
</div> | ||
</Layout> | ||
) : ( | ||
<Layout>{children}</Layout> | ||
)} | ||
</> | ||
) | ||
} | ||
} | ||
</BrowserOnly> | ||
); | ||
} |
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,21 @@ | ||
.pageWrapper { | ||
display: flex; | ||
width: 100%; | ||
flex: 1 0 0%; | ||
} | ||
|
||
.mainContainer { | ||
width: 100%; | ||
padding: 20px 30px; | ||
} | ||
|
||
.contentWrapper { | ||
max-width: 1440px; | ||
margin: 0 auto; | ||
} | ||
|
||
@media (width <= 996px) { | ||
.pageWrapper { | ||
display: block; | ||
} | ||
} |