Skip to content

Commit 472f6d1

Browse files
feat(ref): act-1567 - added wss tab to code example section (#1728)
1 parent cf68789 commit 472f6d1

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

src/components/ParserOpenRPC/RequestBox/index.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React, { useContext, useMemo } from "react";
1+
import React, { useContext, useMemo, useState } from "react";
22
import clsx from "clsx";
33
import CodeBlock from "@theme/CodeBlock";
44
import { MethodParam } from "@site/src/components/ParserOpenRPC/interfaces";
55
import styles from "./styles.module.css";
66
import global from "../global.module.css";
77
import { Tooltip } from "@site/src/components/Tooltip";
88
import { MetamaskProviderContext } from "@site/src/theme/Root";
9+
import Select from "react-dropdown-select";
910

1011
interface RequestBoxProps {
1112
isMetamaskInstalled: boolean;
@@ -22,6 +23,17 @@ interface RequestBoxProps {
2223
isLoading: boolean;
2324
}
2425

26+
const langOptions = [
27+
{
28+
value: "curl",
29+
label: "CURL"
30+
},
31+
{
32+
value: "wss",
33+
label: "WSS"
34+
}
35+
]
36+
2537
export default function RequestBox({
2638
isMetamaskInstalled,
2739
method,
@@ -37,15 +49,19 @@ export default function RequestBox({
3749
isLoading,
3850
}: RequestBoxProps) {
3951
const { userAPIKey } = useContext(MetamaskProviderContext);
52+
const [currentLang, setCurrentLang] = useState(langOptions[0]);
4053
const exampleRequest = useMemo(() => {
4154
const preparedParams = JSON.stringify(paramsData, null, 2);
4255
const preparedShellParams = JSON.stringify(paramsData);
4356
const API_KEY = userAPIKey ? userAPIKey : "<YOUR-API-KEY>";
4457
if (isMetamaskNetwork) {
4558
return `await window.ethereum.request({\n "method": "${method}",\n "params": ${preparedParams.replace(/"([^"]+)":/g, '$1:')},\n});`;
4659
}
60+
if (currentLang.value === "wss") {
61+
return `wscat -c ${requestURL.replace("https", "wss")}${API_KEY} -x '{"jsonrpc":"2.0","method":"${method}","params": ${preparedShellParams},"id":1}'`
62+
}
4763
return `curl ${requestURL}${API_KEY} \\\n -X POST \\\n -H "Content-Type: application/json" \\\n -d '{\n "jsonrpc": "2.0",\n "method": "${method}",\n "params": ${preparedShellParams},\n "id": 1\n }'`;
48-
}, [userAPIKey, method, paramsData]);
64+
}, [userAPIKey, method, paramsData, currentLang]);
4965

5066
const exampleResponse = useMemo(() => {
5167
if (defExampleResponse && response === undefined) {
@@ -80,8 +96,20 @@ export default function RequestBox({
8096
return (
8197
<>
8298
<div className={styles.cardWrapper}>
83-
<div className={styles.cardHeader}>
99+
<div className={clsx(styles.cardHeader, !isMetamaskNetwork && styles.addIndent)}>
84100
<strong className={styles.cardHeading}>Request</strong>
101+
{!isMetamaskNetwork && (
102+
<Select
103+
className={"select-lang"}
104+
options={langOptions}
105+
values={[currentLang]}
106+
multi={false}
107+
searchable={false}
108+
onChange={(value) => {
109+
setCurrentLang(value[0]);
110+
}}
111+
/>
112+
)}
85113
</div>
86114
<div className={styles.codeWrapper}>
87115
<CodeBlock

src/components/ParserOpenRPC/RequestBox/styles.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
justify-content: space-between;
1515
}
1616

17+
.addIndent {
18+
padding: 10px 95px 10px 16px;
19+
}
20+
1721
.cardHeading {
1822
color: #fff;
1923
}

src/css/custom.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,30 @@ button:hover {
369369
font-size: 14px;
370370
}
371371
}
372+
373+
.react-dropdown-select.select-lang {
374+
min-width: 100px;
375+
background: #292a36;
376+
border: 1px solid #848C96;
377+
padding-left: 10px;
378+
border-radius: 6px;
379+
color: #fff;
380+
}
381+
382+
.react-dropdown-select.select-lang .react-dropdown-select-item {
383+
background: #292a36;
384+
color: #fff;
385+
border: 0;
386+
}
387+
388+
.react-dropdown-select.select-lang .react-dropdown-select-item:hover {
389+
background: #141618;
390+
}
391+
392+
.react-dropdown-select.select-lang .react-dropdown-select-item:not(:first-child) {
393+
border-top: 1px solid #848c96;
394+
}
395+
396+
.react-dropdown-select.select-lang .react-dropdown-select-dropdown-handle{
397+
color: #fff;
398+
}

0 commit comments

Comments
 (0)