mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 19:55:54 +00:00
WS Tool fixes: cURL modal, Clio Only
This commit is contained in:
@@ -11,6 +11,13 @@ ul.nav.navbar-nav {
|
|||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.clio-only-notice {
|
||||||
|
background-color: var(--admonition-info-bg-color);
|
||||||
|
margin-left: var(--spacing-sm);
|
||||||
|
padding: var(--spacing-xs);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
}
|
||||||
|
|
||||||
:root, :root.dark {
|
:root, :root.dark {
|
||||||
--navbar-height: 80px;
|
--navbar-height: 80px;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import * as React from 'react';
|
import * as React from 'react'
|
||||||
import { useThemeHooks } from '@redocly/theme/core/hooks';
|
import { useThemeHooks } from '@redocly/theme/core/hooks'
|
||||||
|
|
||||||
const alertStyle = {
|
const alertStyle = {
|
||||||
position: "relative",
|
position: "relative",
|
||||||
@@ -30,7 +30,7 @@ interface AlertTemplateProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function AlertTemplate ({ message, options, style, close }: AlertTemplateProps): React.JSX.Element {
|
export default function AlertTemplate ({ message, options, style, close }: AlertTemplateProps): React.JSX.Element {
|
||||||
const { useTranslate } = useThemeHooks();
|
const { useTranslate } = useThemeHooks()
|
||||||
const { translate } = useTranslate()
|
const { translate } = useTranslate()
|
||||||
return(
|
return(
|
||||||
<div className={clsx("bootstrap-growl alert alert-dismissible", typeToClass(options.type))} style={{ ...alertStyle, ...style }}>
|
<div className={clsx("bootstrap-growl alert alert-dismissible", typeToClass(options.type))} style={{ ...alertStyle, ...style }}>
|
||||||
|
|||||||
26
resources/dev-tools/components/websocket-api/ClioOnly.tsx
Normal file
26
resources/dev-tools/components/websocket-api/ClioOnly.tsx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { useThemeHooks } from '@redocly/theme/core/hooks';
|
||||||
|
|
||||||
|
export function ClioOnlyIcon () {
|
||||||
|
const { useTranslate } = useThemeHooks()
|
||||||
|
const { translate } = useTranslate()
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className="status clio_only"
|
||||||
|
title={translate("This method is only available from the Clio server.")}
|
||||||
|
>
|
||||||
|
<i className="fa fa-exclamation-circle"></i>
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ClioOnlyNotice() {
|
||||||
|
const { useTranslate } = useThemeHooks()
|
||||||
|
const { translate } = useTranslate()
|
||||||
|
return (
|
||||||
|
<span className="clio-only-notice"
|
||||||
|
>
|
||||||
|
<ClioOnlyIcon />
|
||||||
|
{translate(" Clio only")}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
import React, { useRef, useState } from 'react';
|
||||||
import { useThemeHooks } from '@redocly/theme/core/hooks';
|
import { useThemeHooks } from '@redocly/theme/core/hooks';
|
||||||
import { Connection } from './types';
|
import { Connection } from './types';
|
||||||
import { useRef, useState } from 'react';
|
|
||||||
import { Modal, ModalClipboardBtn, ModalCloseBtn } from '../Modal';
|
import { Modal, ModalClipboardBtn, ModalCloseBtn } from '../Modal';
|
||||||
|
|
||||||
interface CurlButtonProps {
|
interface CurlButtonProps {
|
||||||
@@ -12,36 +12,18 @@ interface CurlProps extends CurlButtonProps{
|
|||||||
closeCurlModal: () => void;
|
closeCurlModal: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getCurl = function (currentBody, selectedConnection: Connection) {
|
|
||||||
let body;
|
|
||||||
try {
|
|
||||||
// change WS to JSON-RPC syntax
|
|
||||||
const params = JSON.parse(currentBody);
|
|
||||||
delete params.id;
|
|
||||||
const method = params.command;
|
|
||||||
delete params.command;
|
|
||||||
const body_json = { method: method, params: [params] };
|
|
||||||
body = JSON.stringify(body_json, null, null);
|
|
||||||
} catch (e) {
|
|
||||||
alert("Can't provide curl format of invalid JSON syntax");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const server = selectedConnection.jsonrpc_url;
|
|
||||||
|
|
||||||
return `curl -H 'Content-Type: application/json' -d '${body}' ${server}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const CurlModal: React.FC<CurlProps> = ({
|
export const CurlModal: React.FC<CurlProps> = ({
|
||||||
currentBody,
|
closeCurlModal,
|
||||||
selectedConnection,
|
currentBody,
|
||||||
|
selectedConnection,
|
||||||
}) => {
|
}) => {
|
||||||
const curlRef = useRef(null);
|
|
||||||
const { useTranslate } = useThemeHooks();
|
const { useTranslate } = useThemeHooks();
|
||||||
const { translate } = useTranslate();
|
const { translate } = useTranslate();
|
||||||
|
const curlRef = useRef(null);
|
||||||
|
|
||||||
const footer = <>
|
const footer = <>
|
||||||
<ModalClipboardBtn textareaRef={curlRef} />
|
<ModalClipboardBtn textareaRef={curlRef} />
|
||||||
<ModalCloseBtn onClick={() => {}} />
|
<ModalCloseBtn onClick={closeCurlModal} />
|
||||||
</>
|
</>
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -63,16 +45,16 @@ export const CurlModal: React.FC<CurlProps> = ({
|
|||||||
className="form-control"
|
className="form-control"
|
||||||
rows={8}
|
rows={8}
|
||||||
ref={curlRef}
|
ref={curlRef}
|
||||||
>
|
value={getCurl(selectedConnection, currentBody)}
|
||||||
{getCurl(currentBody, selectedConnection)}
|
onChange={() => {}}
|
||||||
</textarea>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CurlButton = ({selectedConnection, currentBody}: CurlButtonProps) => {
|
export function CurlButton ({selectedConnection, currentBody}: CurlButtonProps) {
|
||||||
const [showCurlModal, setShowCurlModal] = useState(false);
|
const [showCurlModal, setShowCurlModal] = useState(false);
|
||||||
const { useTranslate } = useThemeHooks();
|
const { useTranslate } = useThemeHooks();
|
||||||
const { translate } = useTranslate();
|
const { translate } = useTranslate();
|
||||||
@@ -87,10 +69,32 @@ export const CurlButton = ({selectedConnection, currentBody}: CurlButtonProps) =
|
|||||||
>
|
>
|
||||||
<i className="fa fa-terminal"></i>
|
<i className="fa fa-terminal"></i>
|
||||||
</button>
|
</button>
|
||||||
{showCurlModal && <CurlModal
|
{showCurlModal && (
|
||||||
closeCurlModal={() => setShowCurlModal(false)}
|
<CurlModal
|
||||||
currentBody={currentBody}
|
closeCurlModal={() => setShowCurlModal(false)}
|
||||||
selectedConnection={selectedConnection}
|
currentBody={currentBody}
|
||||||
/>}
|
selectedConnection={selectedConnection}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCurl(selectedConnection: Connection, currentBody) {
|
||||||
|
let body : string;
|
||||||
|
try {
|
||||||
|
// change WS to JSON-RPC syntax
|
||||||
|
const params = JSON.parse(currentBody);
|
||||||
|
delete params.id;
|
||||||
|
const method = params.command;
|
||||||
|
delete params.command;
|
||||||
|
const body_json = { method: method, params: [params] };
|
||||||
|
body = JSON.stringify(body_json, null, null);
|
||||||
|
} catch (e) {
|
||||||
|
alert("Can't provide curl format of invalid JSON syntax");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const server = selectedConnection.jsonrpc_url;
|
||||||
|
|
||||||
|
return `curl -H 'Content-Type: application/json' -d '${body}' ${server}`;
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"methods": [
|
"methods": [
|
||||||
{
|
{
|
||||||
"name": "account_channels",
|
"name": "account_channels",
|
||||||
"description": "Returns information about an account's <a href='/docs/concepts/payment-types/payment-channels/'>payment channels</a>.",
|
"description": "Returns information about an account's payment channels.",
|
||||||
"link": "/docs/references/http-websocket-apis/public-api-methods/account-methods/account_channels",
|
"link": "/docs/references/http-websocket-apis/public-api-methods/account-methods/account_channels",
|
||||||
"body": {
|
"body": {
|
||||||
"command": "account_channels",
|
"command": "account_channels",
|
||||||
@@ -414,7 +414,7 @@
|
|||||||
"methods": [
|
"methods": [
|
||||||
{
|
{
|
||||||
"name": "mpt_holders",
|
"name": "mpt_holders",
|
||||||
"description": "Return all holders of an MPT and their balance (Clio only).",
|
"description": "Return all holders of an MPT and their balance.",
|
||||||
"link": "/docs/references/http-websocket-apis/public-api-methods/clio-methods/mpt_holders",
|
"link": "/docs/references/http-websocket-apis/public-api-methods/clio-methods/mpt_holders",
|
||||||
"clio_only": true,
|
"clio_only": true,
|
||||||
"body": {
|
"body": {
|
||||||
@@ -431,7 +431,7 @@
|
|||||||
"methods": [
|
"methods": [
|
||||||
{
|
{
|
||||||
"name": "nft_history",
|
"name": "nft_history",
|
||||||
"description": "Get past transaction metadata for an NFT (Clio only).",
|
"description": "Get past transaction metadata for an NFT.",
|
||||||
"link": "/docs/references/http-websocket-apis/public-api-methods/clio-methods/nft_history",
|
"link": "/docs/references/http-websocket-apis/public-api-methods/clio-methods/nft_history",
|
||||||
"clio_only": true,
|
"clio_only": true,
|
||||||
"body": {
|
"body": {
|
||||||
@@ -442,7 +442,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "nft_info",
|
"name": "nft_info",
|
||||||
"description": "Get info about an NFT (Clio only).",
|
"description": "Get info about an NFT.",
|
||||||
"clio_only": true,
|
"clio_only": true,
|
||||||
"link": "/docs/references/http-websocket-apis/public-api-methods/clio-methods/nft_info",
|
"link": "/docs/references/http-websocket-apis/public-api-methods/clio-methods/nft_info",
|
||||||
"body": {
|
"body": {
|
||||||
@@ -453,7 +453,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "nfts_by_issuer",
|
"name": "nfts_by_issuer",
|
||||||
"description": "Get a list of NFTs issued by a specific account, optionally filtered by taxon (Clio only).",
|
"description": "Get a list of NFTs issued by a specific account, optionally filtered by taxon.",
|
||||||
"clio_only": true,
|
"clio_only": true,
|
||||||
"link": "/docs/references/http-websocket-apis/public-api-methods/clio-methods/nfts_by_issuer",
|
"link": "/docs/references/http-websocket-apis/public-api-methods/clio-methods/nfts_by_issuer",
|
||||||
"body": {
|
"body": {
|
||||||
|
|||||||
@@ -45,14 +45,14 @@
|
|||||||
{
|
{
|
||||||
"id": "connection-testnet-clio",
|
"id": "connection-testnet-clio",
|
||||||
"ws_url": "wss://clio.altnet.rippletest.net:51233/",
|
"ws_url": "wss://clio.altnet.rippletest.net:51233/",
|
||||||
"jsonrpc-url": "https://clio.altnet.rippletest.net:51234/",
|
"jsonrpc_url": "https://clio.altnet.rippletest.net:51234/",
|
||||||
"shortname": "Testnet-clio",
|
"shortname": "Testnet-clio",
|
||||||
"longname": "clio.altnet.rippletest.net (Testnet Public Cluster with Clio)"
|
"longname": "clio.altnet.rippletest.net (Testnet Public Cluster with Clio)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "connection-devnet-clio",
|
"id": "connection-devnet-clio",
|
||||||
"ws_url": "wss://clio.devnet.rippletest.net:51233/",
|
"ws_url": "wss://clio.devnet.rippletest.net:51233/",
|
||||||
"jsonrpc-url": "https://clio.devnet.rippletest.net:51234/",
|
"jsonrpc_url": "https://clio.devnet.rippletest.net:51234/",
|
||||||
"shortname": "Devnet-clio",
|
"shortname": "Devnet-clio",
|
||||||
"longname": "clio.devnet.rippletest.net (Devnet Public Cluster with Clio)"
|
"longname": "clio.devnet.rippletest.net (Devnet Public Cluster with Clio)"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ interface PermaLinkButtonProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface PermaLinkProps extends PermaLinkButtonProps {
|
interface PermaLinkProps extends PermaLinkButtonProps {
|
||||||
closePermalinkModal: any;
|
closePermalinkModal: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PermalinkModal: React.FC<PermaLinkProps> = ({
|
const PermalinkModal: React.FC<PermaLinkProps> = ({
|
||||||
@@ -43,6 +43,7 @@ const PermalinkModal: React.FC<PermaLinkProps> = ({
|
|||||||
<textarea
|
<textarea
|
||||||
id="permalink-box-1"
|
id="permalink-box-1"
|
||||||
className="form-control"
|
className="form-control"
|
||||||
|
rows={8}
|
||||||
ref={permalinkRef}
|
ref={permalinkRef}
|
||||||
value={getPermalink(selectedConnection, currentBody)}
|
value={getPermalink(selectedConnection, currentBody)}
|
||||||
onChange={() => {}}
|
onChange={() => {}}
|
||||||
@@ -53,15 +54,8 @@ const PermalinkModal: React.FC<PermaLinkProps> = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PermalinkButton = ({currentBody, selectedConnection}: PermaLinkButtonProps) => {
|
export function PermalinkButton ({currentBody, selectedConnection}: PermaLinkButtonProps) {
|
||||||
const [isPermalinkModalVisible, setIsPermalinkModalVisible] = useState(false);
|
const [showPermalinkModal, setShowPermalinkModal] = useState(false);
|
||||||
|
|
||||||
const openPermalinkModal = () => {
|
|
||||||
setIsPermalinkModalVisible(true);
|
|
||||||
};
|
|
||||||
const closePermalinkModal = () => {
|
|
||||||
setIsPermalinkModalVisible(false);
|
|
||||||
};
|
|
||||||
const { useTranslate } = useThemeHooks();
|
const { useTranslate } = useThemeHooks();
|
||||||
const { translate } = useTranslate();
|
const { translate } = useTranslate();
|
||||||
|
|
||||||
@@ -71,13 +65,13 @@ export const PermalinkButton = ({currentBody, selectedConnection}: PermaLinkButt
|
|||||||
data-toggle="modal"
|
data-toggle="modal"
|
||||||
data-target="#wstool-1-permalink"
|
data-target="#wstool-1-permalink"
|
||||||
title={translate("Permalink")}
|
title={translate("Permalink")}
|
||||||
onClick={openPermalinkModal}
|
onClick={() => setShowPermalinkModal(true)}
|
||||||
>
|
>
|
||||||
<i className="fa fa-link"></i>
|
<i className="fa fa-link"></i>
|
||||||
</button>
|
</button>
|
||||||
{isPermalinkModalVisible && (
|
{showPermalinkModal && (
|
||||||
<PermalinkModal
|
<PermalinkModal
|
||||||
closePermalinkModal={closePermalinkModal}
|
closePermalinkModal={() => setShowPermalinkModal(false)}
|
||||||
currentBody={currentBody}
|
currentBody={currentBody}
|
||||||
selectedConnection={selectedConnection}
|
selectedConnection={selectedConnection}
|
||||||
/>
|
/>
|
||||||
@@ -85,12 +79,12 @@ export const PermalinkButton = ({currentBody, selectedConnection}: PermaLinkButt
|
|||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPermalink = (selectedConnection, currentBody) => {
|
function getPermalink (selectedConnection: Connection, currentBody) {
|
||||||
const startHref = window.location.origin + window.location.pathname;
|
const startHref = window.location.origin + window.location.pathname;
|
||||||
const encodedBody = encodeURIComponent(get_compressed_body(currentBody));
|
const encodedBody = encodeURIComponent(get_compressed_body(currentBody));
|
||||||
const encodedServer = encodeURIComponent(selectedConnection.ws_url);
|
const encodedServer = encodeURIComponent(selectedConnection.ws_url);
|
||||||
return `${startHref}?server=${encodedServer}&req=${encodedBody}`;
|
return `${startHref}?server=${encodedServer}&req=${encodedBody}`;
|
||||||
};
|
}
|
||||||
|
|
||||||
function get_compressed_body(currentBody) {
|
function get_compressed_body(currentBody) {
|
||||||
return currentBody.replace("\n", "").trim();
|
return currentBody.replace("\n", "").trim();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { useThemeHooks } from '@redocly/theme/core/hooks';
|
|||||||
import { Link } from "@redocly/theme/components/Link/Link";
|
import { Link } from "@redocly/theme/components/Link/Link";
|
||||||
import { slugify } from "./slugify";
|
import { slugify } from "./slugify";
|
||||||
import { CommandGroup, CommandMethod } from './types';
|
import { CommandGroup, CommandMethod } from './types';
|
||||||
|
import { ClioOnlyIcon } from './ClioOnly';
|
||||||
|
|
||||||
interface RightSideBarProps {
|
interface RightSideBarProps {
|
||||||
commandList: CommandGroup[];
|
commandList: CommandGroup[];
|
||||||
@@ -53,12 +54,7 @@ export const RightSideBar: React.FC<RightSideBarProps> = ({
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{method.clio_only && (
|
{method.clio_only && (
|
||||||
<span
|
<ClioOnlyIcon />
|
||||||
className="status clio_only"
|
|
||||||
title="This method is only available from the Clio server."
|
|
||||||
>
|
|
||||||
<i className="fa fa-exclamation-circle"></i>
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { CommandGroup, CommandMethod } from './components/websocket-api/types';
|
|||||||
import commandList from "./components/websocket-api/data/command-list.json";
|
import commandList from "./components/websocket-api/data/command-list.json";
|
||||||
import connections from "./components/websocket-api/data/connections.json";
|
import connections from "./components/websocket-api/data/connections.json";
|
||||||
import XRPLoader from '../../@theme/components/XRPLoader';
|
import XRPLoader from '../../@theme/components/XRPLoader';
|
||||||
|
import { ClioOnlyNotice } from './components/websocket-api/ClioOnly';
|
||||||
|
|
||||||
export const frontmatter = {
|
export const frontmatter = {
|
||||||
seo: {
|
seo: {
|
||||||
@@ -208,10 +209,12 @@ export function WebsocketApiTool() {
|
|||||||
{currentMethod.description && (
|
{currentMethod.description && (
|
||||||
<p
|
<p
|
||||||
className="blurb"
|
className="blurb"
|
||||||
dangerouslySetInnerHTML={{
|
>
|
||||||
__html: currentMethod.description,
|
{currentMethod.description}
|
||||||
}}
|
{currentMethod.clio_only ?
|
||||||
/>
|
<ClioOnlyNotice /> : ""
|
||||||
|
}
|
||||||
|
</p>
|
||||||
)}
|
)}
|
||||||
{currentMethod.link && (
|
{currentMethod.link && (
|
||||||
<Link
|
<Link
|
||||||
|
|||||||
Reference in New Issue
Block a user