Skip to content

Commit

Permalink
feat: verify contract (#21)
Browse files Browse the repository at this point in the history
and fix some bugs
  • Loading branch information
Tien Dao authored Nov 16, 2022
1 parent 45c501d commit ff1d1a2
Show file tree
Hide file tree
Showing 68 changed files with 3,359 additions and 563 deletions.
8 changes: 6 additions & 2 deletions api/api_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const API_LIST = {

ALL_BLOCKS: '/api/v1/blocks',
BLOCKS: '/api/v1/blocks/',
TRANSACTION_OF_BLOCK: '/api/v1/blocks/:id/transactions?pagination=offset&page=1&limit=20&order=height.desc',
TRANSACTION_OF_BLOCK: '/api/v1/blocks/:id/transactions',
LATEST_BLOCK: 'evm_/api/v1?module=block&action=eth_block_number',

ALL_TOKENS: 'evm_/api/v1?module=token&action=getListTokens', // &page=1&offset=20
Expand Down Expand Up @@ -41,7 +41,11 @@ const API_LIST = {

TOKEN_DETAIL: '/api/v1?module=token&action=gettoken&contractaddress=', // SSR
TOKEN_TRANSACTIONS: 'evm_/api/v1?module=token&action=getlisttokentransfers',
TOKEN_HOLDERS: 'evm_/api/v1?module=token&action=getTokenHolders' // contractaddress=0x60baCCdfdCa114f97F32121f6b2879fB555Df4d0&page=1&offset=20
TOKEN_HOLDERS: 'evm_/api/v1?module=token&action=getTokenHolders', // contractaddress=0x60baCCdfdCa114f97F32121f6b2879fB555Df4d0&page=1&offset=20

CONTRACT_CODE: 'evm_/api/v1?module=contract&action=getsourcecode',
VERIFY_CONTRACT: 'https://blockscout.astranaut.dev/verify_smart_contract/contract_verifications',
CHECK_VERIFY_STATUS: 'evm_/api/v1?module=contract&action=checkverifystatus'
}

export default API_LIST
27 changes: 27 additions & 0 deletions components/Button/CloseButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import clsx from 'clsx'

/***
* @param textCopy text copy into clipboard
* @param textTitle text show on screen
* @param onCopy trigger event copy
* @param iconCopy only copy when user click on icon
*/
interface Props {
classes?: string
onClose: Function
}

const CloseButton = ({ classes, onClose }: Props) => {
const onClick = (e: any) => {
e.preventDefault()
onClose()
}

return (
<a onClick={onClick} className={clsx('link block-hor-center', classes)}>
<span className={clsx('pointer icon-close text text-base contrast-color-100')} />
</a>
)
}

export default CloseButton
45 changes: 24 additions & 21 deletions components/Button/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ interface Props {
textColor?: string
textClasses?: string
size?: 'small' | 'medium' | 'large'
classes?: string
}

const CopyButton = ({ textCopy, textTitle, onCopy, textColor, textClasses, size = 'medium' }: Props) => {
const CopyButton = ({ classes, textCopy, textTitle, onCopy, textColor, textClasses, size = 'medium' }: Props) => {
const [copied, setCopied] = useState(false)

useEffect(() => {
Expand All @@ -28,26 +29,28 @@ const CopyButton = ({ textCopy, textTitle, onCopy, textColor, textClasses, size

const fontSize = size === 'large' ? 24 : size === 'medium' ? 20 : 16
return (
<CopyToClipboard
text={textCopy}
onCopy={() => {
setCopied(true)
if (onCopy) {
onCopy()
}
}}
>
<div className={clsx('block-hor-center', textColor || 'contrast-color-100')}>
{textTitle && <span className={clsx(styles.text, textClasses)}>{textTitle}</span>}
<span
style={{ fontSize }}
className={clsx('padding-left-xs pointer word-break-all', {
'icon-copy contrast-color-100': !copied,
'icon-checked alert-color-success': copied
})}
/>
</div>
</CopyToClipboard>
<div className={classes}>
<CopyToClipboard
text={textCopy}
onCopy={() => {
setCopied(true)
if (onCopy) {
onCopy()
}
}}
>
<div className={clsx('block-hor-center', textColor || 'contrast-color-100')}>
{textTitle && <span className={clsx(styles.text, textClasses)}>{textTitle}</span>}
<span
style={{ fontSize }}
className={clsx('padding-left-xs pointer word-break-all', {
'icon-copy contrast-color-100': !copied,
'icon-checked alert-color-success': copied
})}
/>
</div>
</CopyToClipboard>
</div>
)
}

Expand Down
4 changes: 3 additions & 1 deletion components/Card/CardInfo/Components/Decode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default function Decode({ methodId, call, items }: DecodeProps) {
{
title: 'Call',
key: 'call',
render: value => <span className={clsx('money money-sm', styles.primaryColor)}>{value}</span>
render: value => (
<span className={clsx('money money-sm', styles.primaryColor)}>{value || '...'}</span>
)
}
]}
rows={[{ method: methodId, call }]}
Expand Down
12 changes: 6 additions & 6 deletions components/Card/CardInfo/Components/RawInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ export default function RawInput({ text }: RawInputProps) {
<div style={{ maxWidth: '885px', maxHeight: '200px', overflowY: 'scroll' }}>
<Tabs
tabs={[
{ title: 'Hex', id: '1', padding: ' ' },
{ title: 'UTF-8', id: '2', padding: ' ' }
{ title: 'Hex', id: 'hex', padding: ' ' },
{ title: 'UTF-8', id: 'utf8', padding: ' ' }
]}
contents={{
'1': <Copy text={text} />,
'2': <Copy text={utf8Text} />
hex: <Copy text={text} />,
utf8: <Copy text={utf8Text} />
}}
classes=" "
classes="padding-top-xs"
headerBorder={false}
headerPadding="padding-left-sm"
></Tabs>
/>
</div>
)
}
25 changes: 25 additions & 0 deletions components/CodeView/AutoView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import CopyButton from 'components/Button/CopyButton'
import Prism from 'prismjs'
import 'prismjs/components/prism-gettext'
import { useEffect } from 'react'

interface Props {
code: string
filename: string
}

const AutoLanguageView = ({ code, filename }: Props) => {
useEffect(() => {
Prism.highlightAll()
}, [])
return (
<div className="margin-bottom-xl">
<CopyButton textCopy={code} textTitle={filename} classes="margin-bottom-sm" />
<pre style={{ maxHeight: 500 }}>
<code className="language-gettext">{code}</code>
</pre>
</div>
)
}

export default AutoLanguageView
25 changes: 25 additions & 0 deletions components/CodeView/JsonView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import CopyButton from 'components/Button/CopyButton'
import Prism from 'prismjs'
import 'prismjs/components/prism-json'
import { useEffect } from 'react'

interface Props {
code: string
filename: string
}

const JsonView = ({ code, filename }: Props) => {
useEffect(() => {
Prism.highlightAll()
}, [])
return (
<div className="margin-bottom-xl">
<CopyButton textCopy={code} textTitle={filename} classes="margin-bottom-sm" />
<pre style={{ maxHeight: 500 }}>
<code className="language-json">{code}</code>
</pre>
</div>
)
}

export default JsonView
25 changes: 25 additions & 0 deletions components/CodeView/SolidityView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import CopyButton from 'components/Button/CopyButton'
import Prism from 'prismjs'
import 'prismjs/components/prism-solidity'
import { useEffect } from 'react'

interface Props {
code: string
filename: string
}

const SolidityView = ({ code, filename }: Props) => {
useEffect(() => {
Prism.highlightAll()
}, [])
return (
<div className="margin-bottom-xl">
<CopyButton textCopy={code} textTitle={filename} classes="margin-bottom-sm" />
<pre style={{ maxHeight: 500 }}>
<code className="language-solidity">{code}</code>
</pre>
</div>
)
}

export default SolidityView
104 changes: 104 additions & 0 deletions components/FormItem/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import clsx from 'clsx'
import { useEffect, useRef, useState } from 'react'
import styles from './style.module.scss'

/**
* @param label
* @param inputInfo: Caption text, description, error notification
* * icon: font icon
* * type: default normal
*
*/
export interface TextAreaProps
extends React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement> {
label?: React.ReactNode
inputInfo?: {
icon?: string
text: React.ReactNode
type?: 'error' | 'normal'
}
statusType?: 'error' | 'normal'
classes?: {
wapper?: string
label?: string
inputFont?: string
inputWrapperPadding?: string
}
}
export default function TextArea({
label,
statusType,
classes,
inputInfo,
disabled,
readOnly,
onChange,
...rest
}: TextAreaProps) {
const [_focus, _setFocus] = useState(false)
const inputWrapperRef = useRef<HTMLTextAreaElement>(null)

useEffect(() => {
if (inputWrapperRef) {
inputWrapperRef.current?.addEventListener('focusin', _focusin, true)
inputWrapperRef.current?.addEventListener('focusout', _focusout, true)
}
return () => {
if (inputWrapperRef) {
inputWrapperRef.current?.removeEventListener('focusin', _focusin)
inputWrapperRef.current?.removeEventListener('focusout', _focusout)
}
}
}, [inputWrapperRef])

const _focusin = () => {
_setFocus(true)
}
const _focusout = () => {
_setFocus(false)
}

return (
<div className={clsx(classes?.wapper, 'flex flex-column margin-bottom-md')}>
{label ? (
<span className={classes?.label || 'text text-base contrast-color-70 padding-bottom-xs work-break-all'}>
{label}
</span>
) : null}
<textarea
{...rest}
onChange={onChange}
disabled={disabled}
readOnly={readOnly}
ref={inputWrapperRef}
className={clsx(
styles.textAreaWrapper,
'width-100 flex',
'contrast-bg-color-10',
'contrast-color-100',
classes?.inputWrapperPadding || 'padding-left-sm padding-right-sm padding-top-xs padding-bottom-xs',
'radius-lg',
'border border-base',
'width-100',
'text text-base',
{
[styles.inputError]: statusType === 'error',
[styles.inputDisabled]: disabled,
[styles.focus]: !disabled && _focus
}
)}
/>
{inputInfo ? (
<div
className={clsx('text text-base margin-top-xs word-break-all', {
'contrast-color-70': inputInfo.type !== 'error',
'alert-color-error': inputInfo.type === 'error'
})}
>
{inputInfo.icon ? <span className={clsx(inputInfo.icon, 'margin-right-xs')}></span> : null}
<span>{inputInfo.text}</span>
</div>
) : null}
</div>
)
}
Loading

0 comments on commit ff1d1a2

Please sign in to comment.