-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #636 from subquery/feat/rpc-playground
feat: rpc playground
- Loading branch information
Showing
22 changed files
with
308 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2020-2022 SubQuery Pte Ltd authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React, { FC, useMemo, useState } from 'react'; | ||
import { Typography } from '@subql/components'; | ||
import { getAuthReqHeader } from '@utils'; | ||
import { Button, Input } from 'antd'; | ||
import { fetchJson } from 'ethers/lib/utils'; | ||
|
||
import styles from './index.module.less'; | ||
|
||
interface IProps { | ||
url?: string; | ||
trailToken: string; | ||
} | ||
|
||
const RpcPlayground: FC<IProps> = ({ url, trailToken }) => { | ||
const [val, setVal] = useState(''); | ||
const [loading, setLoading] = useState(false); | ||
const enteredRows = useMemo(() => { | ||
return val.split('\n').length; | ||
}, [val]); | ||
|
||
const [responseData, setResponseData] = useState(''); | ||
|
||
const fetchRpc = async () => { | ||
if (!url) return; | ||
try { | ||
setLoading(true); | ||
const res = await fetchJson( | ||
{ | ||
url, | ||
headers: { | ||
...getAuthReqHeader(trailToken), | ||
}, | ||
}, | ||
val, | ||
); | ||
|
||
setResponseData(JSON.stringify(res)); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} catch (e: any) { | ||
setResponseData(`${e.toString()}`); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={styles.rpcPlayground}> | ||
<div className={styles.rpcPlaygroundEditor}> | ||
<Typography style={{ color: '#fff', marginBottom: 8 }} weight={500}> | ||
Request | ||
</Typography> | ||
<div style={{ display: 'flex', gap: 8 }}> | ||
<div className={styles.rows}> | ||
{new Array(enteredRows).fill(0).map((_, index) => ( | ||
<span key={index}>{index + 1}</span> | ||
))} | ||
</div> | ||
<Input.TextArea | ||
rows={30} | ||
value={val} | ||
onChange={(e) => { | ||
setVal(e.target.value); | ||
}} | ||
style={{ resize: 'none' }} | ||
placeholder="JSON RPC playground is a simple tool to help you test queries, click to enter you requests." | ||
></Input.TextArea> | ||
</div> | ||
|
||
<div style={{ display: 'flex', justifyContent: 'flex-end', position: 'sticky', bottom: 32 }}> | ||
<Button | ||
loading={loading} | ||
shape="round" | ||
size="large" | ||
type="primary" | ||
onClick={() => { | ||
fetchRpc(); | ||
}} | ||
> | ||
Send Request | ||
</Button> | ||
</div> | ||
</div> | ||
|
||
<div className={styles.rpcPlaygroundResponse}> | ||
<Typography style={{ color: '#fff', marginBottom: 8 }} weight={500}> | ||
Response | ||
</Typography> | ||
<div style={{ overflowWrap: 'anywhere', wordBreak: 'break-all', color: 'var(--sq-gray500)' }}> | ||
{responseData} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
export default RpcPlayground; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
.rpcPlayground { | ||
display: flex; | ||
padding: 16px; | ||
border-radius: 0px 0px 16px 16px; | ||
background: #2A3546; | ||
|
||
&Editor { | ||
flex: 1; | ||
padding: 16px; | ||
background: #1F2A3B; | ||
border-radius: 10px; | ||
position: relative; | ||
|
||
.rows { | ||
display: flex; | ||
flex-direction: column; | ||
color: var(--sq-gray600); | ||
font-size: 14px; | ||
line-height: 1.5714285714285714; | ||
padding-top: 2px; | ||
} | ||
|
||
:global { | ||
.ant-input { | ||
background: #1F2A3B; | ||
border: 1px solid #1F2A3B; | ||
color: var(--sq-gray500); | ||
padding: 0; | ||
font-family: var(--sq-font-family); | ||
&:focus { | ||
box-shadow: none; | ||
} | ||
|
||
&::placeholder { | ||
color: var(--sq-gary500); | ||
} | ||
} | ||
} | ||
} | ||
|
||
&Response { | ||
flex: 1; | ||
padding: 16px; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.