import { useTranslate } from "@portal/hooks"; import { Connection } from './types'; import { useRef, useState } from 'react'; import { Modal, ModalClipboardBtn, ModalCloseBtn } from '../Modal'; interface CurlButtonProps { currentBody: any; selectedConnection: Connection; } interface CurlProps extends CurlButtonProps{ 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 = ({ currentBody, selectedConnection, }) => { const curlRef = useRef(null); const { translate } = useTranslate(); const footer = <> {}} /> return ( {}} footer={footer} >
); }; export const CurlButton = ({selectedConnection, currentBody}: CurlButtonProps) => { const [showCurlModal, setShowCurlModal] = useState(false); return <> {showCurlModal && setShowCurlModal(false)} currentBody={currentBody} selectedConnection={selectedConnection} />} }