-
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.
- Loading branch information
Showing
16 changed files
with
264 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// 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)); | ||
} 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> | ||
<Input.TextArea | ||
rows={30} | ||
value={val} | ||
onChange={(e) => { | ||
setVal(e.target.value); | ||
}} | ||
placeholder="JSON RPC playground is a simple tool to help you test queries, click to enter you requests." | ||
></Input.TextArea> | ||
|
||
<Button | ||
loading={loading} | ||
shape="round" | ||
size="large" | ||
type="primary" | ||
style={{ position: 'absolute', right: 16, bottom: 32 }} | ||
onClick={() => { | ||
fetchRpc(); | ||
}} | ||
> | ||
Send Request | ||
</Button> | ||
</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,37 @@ | ||
.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; | ||
|
||
: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
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.