-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathindex.tsx
80 lines (76 loc) · 2.56 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from 'react';
import Layout from "@theme/Layout";
import ParserOpenRPC from "@site/src/components/ParserOpenRPC";
import DocSidebar from '@theme/DocSidebar';
import { useLocation } from "@docusaurus/router";
import { prepareLinkItems, MM_REF_PATH } from '@site/src/plugins/plugin-json-rpc';
import styles from "./styles.module.css";
const sidebar = require("../../../wallet-sidebar.js");
import AdmonitionWrapper from '@site/src/theme/Admonition';
function transformItems(items, dynamicItems) {
return items.map(item => {
let newItem = { ...item };
if (newItem.type === "doc") {
newItem.type = "link";
newItem.href = newItem.id;
delete newItem.id;
}
if (newItem.type === "category") {
if (newItem.label === "JSON-RPC API") {
newItem.items = dynamicItems;
newItem.collapsed = false;
}
if (newItem.link) {
newItem.href = newItem.link.id || newItem.link.slug;
delete newItem.link;
}
if (newItem.items && Array.isArray(newItem.items)) {
newItem.items = transformItems(newItem.items, dynamicItems);
}
}
if (newItem.href) {
if (newItem.href.endsWith("/index")) {
newItem.href = newItem.href.slice(0, -5);
}
if (!newItem.href.startsWith("/")) {
newItem.href = `/${newItem.href}`;
}
newItem.href = `/wallet${newItem.href}`;
}
return newItem;
});
}
const NoteMsg = () => (
<AdmonitionWrapper type="note" title="note">
<p>MetaMask doesn't support session IDs.</p>
</AdmonitionWrapper>
);
const CustomReferencePage = (props) => {
const customData = props.route.customData;
const { pathname } = useLocation();
const refItems = prepareLinkItems(props.methodsData, MM_REF_PATH).map(item => ({...item, href: item.href.replace("/wallet", "")}))
const updatedSidebar = transformItems(sidebar.walletSidebar, refItems);
return (
<Layout>
<div className={styles.pageWrapper}>
<aside>
<div className={styles.sidebarViewport}>
<div className={styles.sidebar}>
<DocSidebar sidebar={updatedSidebar} path={pathname} onCollapse={() => {}} isHidden={false} />
</div>
</div>
</aside>
<div className={styles.mainContainer}>
<div className={styles.contentWrapper}>
<ParserOpenRPC
network={customData.networkName}
method={customData.name}
extraContent={<NoteMsg />}
/>
</div>
</div>
</div>
</Layout>
);
};
export default CustomReferencePage;