Skip to content

Commit cd2122d

Browse files
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
1 parent a630c5e commit cd2122d

File tree

4 files changed

+109
-20
lines changed

4 files changed

+109
-20
lines changed

src/components/ParserOpenRPC/global.module.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585

8686
.colLeft {
8787
position: relative;
88-
width: 65%;
88+
width: calc(100% - 420px);
8989
border-right: 1px solid #444950;
9090
overflow: hidden;
9191
}
@@ -97,7 +97,7 @@
9797
}
9898

9999
.colRight {
100-
width: 35%;
100+
width: 420px;
101101
padding-left: 23px;
102102
}
103103

src/components/ParserOpenRPC/index.tsx

+6-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { createContext, useEffect, useMemo, useState } from 'react'
1+
import React, { createContext, useMemo, useState } from 'react'
22
import { usePluginData } from "@docusaurus/useGlobalData";
33
import { ResponseItem, NETWORK_NAMES } from "@site/src/plugins/plugin-json-rpc";
44
import DetailsBox from "@site/src/components/ParserOpenRPC/DetailsBox";
@@ -11,11 +11,7 @@ import global from "./global.module.css";
1111
import modalDrawerStyles from "./ModalDrawer/styles.module.css";
1212
import clsx from "clsx";
1313
import { useColorMode } from "@docusaurus/theme-common";
14-
import {
15-
trackPageViewForSegment,
16-
trackClickForSegment,
17-
trackInputChangeForSegment
18-
} from "@site/src/lib/segmentAnalytics";
14+
import { trackClickForSegment, trackInputChangeForSegment } from "@site/src/lib/segmentAnalytics";
1915
import { useLocation } from "@docusaurus/router";
2016
import { useSyncProviders } from "@site/src/hooks/useSyncProviders.ts"
2117

@@ -47,13 +43,13 @@ export default function ParserOpenRPC({ network, method }: ParserProps) {
4743
trackClickForSegment({
4844
eventName: "Customize Request",
4945
clickType: "Customize Request",
50-
userExperience: "new"
46+
userExperience: "B"
5147
})
5248
};
5349
const closeModal = () => setModalOpen(false);
5450

5551
const { netData } = usePluginData("plugin-json-rpc") as { netData?: ResponseItem[] };
56-
const currentNetwork = netData.find(net => net.name === network);
52+
const currentNetwork = netData?.find(net => net.name === network);
5753

5854
if (!currentNetwork && currentNetwork.error) return null;
5955

@@ -97,14 +93,6 @@ export default function ParserOpenRPC({ network, method }: ParserProps) {
9793
setSelectedWallet(i);
9894
}
9995

100-
useEffect(() => {
101-
trackPageViewForSegment({
102-
name: "Reference page",
103-
path: location.pathname,
104-
userExperience: "new"
105-
})
106-
}, []);
107-
10896
const metamaskProviders = useMemo(() => {
10997
const isMetamasks = providers.filter(pr => pr?.info?.name?.includes("MetaMask"));
11098
if (isMetamasks.length > 1) {
@@ -121,7 +109,7 @@ export default function ParserOpenRPC({ network, method }: ParserProps) {
121109
setParamsData(Object.values(data));
122110
trackInputChangeForSegment({
123111
eventName: "Request Configuration Started",
124-
userExperience: "new"
112+
userExperience: "B"
125113
})
126114
}
127115

@@ -136,7 +124,7 @@ export default function ParserOpenRPC({ network, method }: ParserProps) {
136124
trackClickForSegment({
137125
eventName: "Request Sent",
138126
clickType: "Request Sent",
139-
userExperience: "new",
127+
userExperience: "B",
140128
...(response?.code && { responseStatus: response.code })
141129
})
142130
} catch (e) {

src/theme/Layout/index.tsx

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import React, { useState, useEffect, useMemo } from "react";
2+
import BrowserOnly from '@docusaurus/BrowserOnly';
3+
import { usePluginData } from "@docusaurus/useGlobalData";
4+
import ldClient from "launchdarkly";
5+
import { useLocation } from "@docusaurus/router";
6+
import Layout from "@theme-original/Layout";
7+
import ParserOpenRPC from "@site/src/components/ParserOpenRPC";
8+
import { ResponseItem, NETWORK_NAMES } from "@site/src/plugins/plugin-json-rpc";
9+
import styles from "./styles.module.css";
10+
11+
const REF_FF = "mm-new-reference-enabled";
12+
const REF_PATH = "/wallet/reference/";
13+
const EXEPT_METHODS = [
14+
"wallet_requestPermissions",
15+
"wallet_revokePermissions",
16+
"eth_signTypedData_v4"
17+
];
18+
19+
export default function LayoutWrapper({ children }) {
20+
const location = useLocation();
21+
const { netData } = usePluginData("plugin-json-rpc") as { netData?: ResponseItem[] };
22+
const [ldReady, setLdReady] = useState(false);
23+
const [newReferenceEnabled, setNewReferenceEnabled] = useState(false);
24+
25+
const metamaskNetwork = netData?.find(net => net.name === NETWORK_NAMES.metamask);
26+
const metamaskMethods = metamaskNetwork?.data?.methods?.map((item) => item.name) || [];
27+
28+
const referencePageName = useMemo(() => {
29+
const currentPath = location.pathname;
30+
if (currentPath.includes(REF_PATH) && metamaskMethods.length > 0) {
31+
const methodPath = currentPath.replace(REF_PATH, "").replace("/", "");
32+
const page = metamaskMethods.find(name => name.toLowerCase() === methodPath && !EXEPT_METHODS.includes(name));
33+
return page;
34+
}
35+
return false;
36+
}, [location.pathname, metamaskMethods]);
37+
38+
useEffect(() => {
39+
ldClient.waitUntilReady().then(() => {
40+
setNewReferenceEnabled(ldClient.variation(REF_FF, false));
41+
setLdReady(true);
42+
});
43+
const handleChange = (current) => {
44+
setNewReferenceEnabled(current);
45+
};
46+
ldClient.on(`change:${REF_FF}`, handleChange);
47+
return () => {
48+
ldClient.off(`change:${REF_FF}`, handleChange);
49+
};
50+
}, []);
51+
52+
return (
53+
<BrowserOnly>
54+
{
55+
() => {
56+
return (
57+
<>
58+
{newReferenceEnabled && ldReady && referencePageName ? (
59+
<Layout>
60+
<div className={styles.pageWrapper}>
61+
{children?.props?.children[0]?.type === "aside" && (
62+
<>{children.props.children[0]}</>
63+
)}
64+
<div className={styles.mainContainer}>
65+
<div className={styles.contentWrapper}>
66+
<ParserOpenRPC network={NETWORK_NAMES.metamask} method={referencePageName} />
67+
</div>
68+
</div>
69+
</div>
70+
</Layout>
71+
) : (
72+
<Layout>{children}</Layout>
73+
)}
74+
</>
75+
)
76+
}
77+
}
78+
</BrowserOnly>
79+
);
80+
}

src/theme/Layout/styles.module.css

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.pageWrapper {
2+
display: flex;
3+
width: 100%;
4+
flex: 1 0 0%;
5+
}
6+
7+
.mainContainer {
8+
width: 100%;
9+
padding: 20px 30px;
10+
}
11+
12+
.contentWrapper {
13+
max-width: 1440px;
14+
margin: 0 auto;
15+
}
16+
17+
@media (width <= 996px) {
18+
.pageWrapper {
19+
display: block;
20+
}
21+
}

0 commit comments

Comments
 (0)