This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
7e5187a
commit 9b1abf5
Showing
25 changed files
with
1,181 additions
and
451 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,166 @@ | ||
import styled from '@emotion/styled' | ||
import { AutoComplete, Form, Input } from 'antd' | ||
import { useContext, useMemo } from 'react' | ||
|
||
import _Link from './Link' | ||
import useSubnetGetBlock from '../hooks/useSubnetGetBlock' | ||
import { SelectedNetworksContext } from '../contexts/selectedNetworks' | ||
import useSubnetGetTransactionAndReceipt from '../hooks/useSubnetGetTransactionAndReceipt' | ||
import useSubnetGetCertificateById from '../hooks/useSubnetGetCertificateById' | ||
import useSubnetGetCertificates from '../hooks/useSubnetGetCertificates' | ||
import useSubnetGetAccountBalance from '../hooks/useSubnetGetAccountBalance' | ||
import { SearchOutlined } from '@ant-design/icons' | ||
|
||
const Link = styled(_Link)` | ||
color: ${({ theme }) => theme.colorText}; | ||
&:hover { | ||
color: ${({ theme }) => theme.colorText} !important; | ||
} | ||
` | ||
|
||
const MainQuery = () => { | ||
const [form] = Form.useForm() | ||
const query: string = Form.useWatch('query', form) | ||
const sanitizedQuery = useMemo(() => query?.trim(), [query]) | ||
const { selectedSubnet } = useContext(SelectedNetworksContext) | ||
const { block } = useSubnetGetBlock(selectedSubnet, sanitizedQuery) | ||
const { transaction } = useSubnetGetTransactionAndReceipt( | ||
selectedSubnet, | ||
sanitizedQuery | ||
) | ||
const { certificate } = useSubnetGetCertificateById({ | ||
certificateId: sanitizedQuery, | ||
sourceSubnetId: selectedSubnet?.id, | ||
}) | ||
const { certificates: certificatesByPosition } = useSubnetGetCertificates({ | ||
limit: 1, | ||
sourceStreamPosition: { | ||
position: isNaN(+sanitizedQuery) ? Infinity : parseInt(sanitizedQuery), | ||
sourceSubnetId: { value: selectedSubnet?.id || '' }, | ||
}, | ||
}) | ||
const { balance } = useSubnetGetAccountBalance(selectedSubnet, sanitizedQuery) | ||
|
||
const options = useMemo(() => { | ||
const options = [] | ||
|
||
if (block) { | ||
options.push({ | ||
label: ( | ||
<span> | ||
Blocks | ||
<_Link | ||
style={{ float: 'right' }} | ||
to={`/subnet/${selectedSubnet?.id}/blocks`} | ||
> | ||
more | ||
</_Link> | ||
</span> | ||
), | ||
options: [ | ||
{ | ||
label: ( | ||
<Link to={`/subnet/${selectedSubnet?.id}/block/${block.hash}`}> | ||
{block.hash} | ||
</Link> | ||
), | ||
value: block.hash, | ||
}, | ||
], | ||
}) | ||
} | ||
|
||
if (transaction) { | ||
options.push({ | ||
label: <span>Transactions</span>, | ||
options: [ | ||
{ | ||
label: ( | ||
<Link | ||
to={`/subnet/${selectedSubnet?.id}/transaction/${transaction.hash}`} | ||
> | ||
{transaction.hash} | ||
</Link> | ||
), | ||
value: transaction.hash, | ||
}, | ||
], | ||
}) | ||
} | ||
|
||
if ( | ||
certificate || | ||
(certificatesByPosition && certificatesByPosition?.length) | ||
) { | ||
options.push({ | ||
label: ( | ||
<span> | ||
Certificates | ||
<_Link | ||
style={{ float: 'right' }} | ||
to={`/subnet/${selectedSubnet?.id}/certificates`} | ||
> | ||
more | ||
</_Link> | ||
</span> | ||
), | ||
options: [ | ||
{ | ||
label: ( | ||
<Link | ||
to={`/subnet/${selectedSubnet?.id}/certificate/${ | ||
certificate ? certificate.id : certificatesByPosition![0].id | ||
}`} | ||
> | ||
{certificate ? certificate.id : certificatesByPosition![0].id} | ||
</Link> | ||
), | ||
value: certificate ? certificate.id : certificatesByPosition![0].id, | ||
}, | ||
], | ||
}) | ||
} | ||
|
||
if (balance) { | ||
options.push({ | ||
label: <span>Accounts</span>, | ||
options: [ | ||
{ | ||
label: ( | ||
<Link | ||
to={`/subnet/${selectedSubnet?.id}/account/${sanitizedQuery}`} | ||
> | ||
{sanitizedQuery} | ||
</Link> | ||
), | ||
value: sanitizedQuery, | ||
}, | ||
], | ||
}) | ||
} | ||
|
||
return options | ||
}, [block, transaction, certificate, certificatesByPosition, balance]) | ||
|
||
return ( | ||
<Form form={form}> | ||
<Form.Item name="query"> | ||
<AutoComplete | ||
options={options} | ||
popupMatchSelectWidth={700} | ||
style={{ maxWidth: 700 }} | ||
> | ||
<Input | ||
addonBefore={<SearchOutlined />} | ||
allowClear | ||
placeholder="Query by tx, block, certificate, or account" | ||
size="large" | ||
/> | ||
</AutoComplete> | ||
</Form.Item> | ||
</Form> | ||
) | ||
} | ||
|
||
export default MainQuery |
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,100 @@ | ||
import { | ||
Card, | ||
Col, | ||
Descriptions, | ||
Divider, | ||
Row, | ||
Space, | ||
Spin, | ||
Statistic, | ||
Tag, | ||
} from 'antd' | ||
import { utils } from 'ethers' | ||
import { useContext, useEffect } from 'react' | ||
|
||
import { ErrorsContext } from '../contexts/errors' | ||
import { SelectedNetworksContext } from '../contexts/selectedNetworks' | ||
import useSubnetGetAccountBalance from '../hooks/useSubnetGetAccountBalance' | ||
import useSubnetGetAccountTxCount from '../hooks/useSubnetGetAccountTxCount' | ||
import useSubnetGetAccountCode from '../hooks/useSubnetGetAccountCode' | ||
|
||
interface Props { | ||
address: string | ||
} | ||
|
||
const SubnetAccountInfo = ({ address }: Props) => { | ||
const { setErrors } = useContext(ErrorsContext) | ||
const { selectedSubnet } = useContext(SelectedNetworksContext) | ||
const { | ||
balance, | ||
errors: getBalanceErrors, | ||
loading: getBalanceLoading, | ||
} = useSubnetGetAccountBalance(selectedSubnet, address) | ||
const { | ||
txCount, | ||
errors: getTxCountErrors, | ||
loading: getTxCountLoading, | ||
} = useSubnetGetAccountTxCount(selectedSubnet, address) | ||
const { | ||
code, | ||
errors: getCodeErrors, | ||
loading: getCodeLoading, | ||
} = useSubnetGetAccountCode(selectedSubnet, address) | ||
|
||
useEffect( | ||
function bubbleErrors() { | ||
setErrors((e) => [ | ||
...e, | ||
...getBalanceErrors, | ||
...getTxCountErrors, | ||
...getCodeErrors, | ||
]) | ||
}, | ||
[getBalanceErrors, getTxCountErrors, getCodeErrors] | ||
) | ||
|
||
return ( | ||
<Space direction="vertical"> | ||
<Divider orientation="left" style={{ margin: '2rem 0' }}> | ||
Account Info | ||
</Divider> | ||
<Descriptions> | ||
<Descriptions.Item label="Type"> | ||
{getCodeLoading ? ( | ||
<Spin /> | ||
) : code === '0x' ? ( | ||
<Tag color="cyan">EOA</Tag> | ||
) : ( | ||
<Tag color="gold">Contract</Tag> | ||
)} | ||
</Descriptions.Item> | ||
</Descriptions> | ||
<Descriptions> | ||
<Descriptions.Item label="Address">{address}</Descriptions.Item> | ||
</Descriptions> | ||
<Row gutter={16}> | ||
<Col span={12}> | ||
<Card> | ||
<Statistic | ||
title="Balance" | ||
loading={getBalanceLoading} | ||
suffix={selectedSubnet?.currencySymbol} | ||
value={balance !== undefined ? utils.formatUnits(balance) : ''} | ||
/> | ||
</Card> | ||
</Col> | ||
<Col span={4}> | ||
<Card> | ||
<Statistic | ||
title="Transaction count" | ||
loading={getTxCountLoading} | ||
value={txCount} | ||
/> | ||
</Card> | ||
</Col> | ||
</Row> | ||
</Space> | ||
) | ||
} | ||
|
||
export default SubnetAccountInfo |
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.