Skip to content

Commit

Permalink
fix: update address/contract address
Browse files Browse the repository at this point in the history
  • Loading branch information
Tien Nam Dao committed Oct 21, 2022
1 parent 98c7623 commit af1cdbf
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 35 deletions.
1 change: 1 addition & 0 deletions api/api_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const API_LIST = {
ESTIMATE_COUNTED_INFO: 'evm_/api/v1/estimate-counted-info',
GAS_AVG: 'evm_/api/v1/gas-price-oracle',

ADDRESS_DETAIL: '/api/v1?module=account&action=getaddress&address=',
ADDRESS_TOKEN: 'evm_/api/v1?module=account&action=tokenlist', // address = ?
ADDRESS_COUNTER: 'evm_/api/v1?module=account&action=getaddresscounters', // address=?
ADDRESS_BALANCE: 'evm_/api/v1?module=account&action=balance', // address=?
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const nextConfig = {
reactStrictMode: false,
env: {
NEXT_PUBLIC_COSMOS_API: 'http://128.199.238.171:8080',
NEXT_PUBLIC_COSMOS_API: 'https://chainindexing.astranaut.dev',
NEXT_PUBLIC_EVM_API: 'https://blockscout.astranaut.dev',
NEXT_PUBLIC_BLOCK_INTERVAL: '5000',
NEXT_PUBLIC_TRANSACTION_INTERVAL: '5000',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"license": "MIT",
"dependencies": {
"@astradefi/address-converter": "^0.4.1",
"@astraprotocol/astra-ui": "^1.0.12",
"@astraprotocol/astra-ui": "^1.0.13",
"@cosmjs/crypto": "^0.29.0",
"@cosmjs/encoding": "^0.29.0",
"@reduxjs/toolkit": "^1.8.5",
Expand Down
54 changes: 27 additions & 27 deletions pages/address/[address].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Breadcumbs, useMobileLayout } from '@astraprotocol/astra-ui'
import { evmApi } from 'api'
import API_LIST from 'api/api_list'
import Container from 'components/Container'
import Head from 'next/head'
import React from 'react'
Expand All @@ -10,19 +12,22 @@ import Layout from '../../components/Layout'

type Props = {
address: string
addressData: Address
}

const AddressDetailPage: React.FC<Props> = props => {
const { isMobile } = useMobileLayout()
const { address } = props
const { address, addressData } = props

const isContract = addressData.type === 'contractaddress'
const title = isContract
? `Contract ${address} | ${process.env.NEXT_PUBLIC_TITLE}`
: `Address ${address} | ${process.env.NEXT_PUBLIC_TITLE}`
return (
<Layout>
<Head>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<title>
Address {address} | {process.env.NEXT_PUBLIC_TITLE}
</title>
<title>{title}</title>
</Head>
<Container>
<Breadcumbs
Expand All @@ -31,7 +36,7 @@ const AddressDetailPage: React.FC<Props> = props => {
{ label: isMobile ? ellipseBetweenText(address) : address }
]}
/>
<AddressOverview address={address} />
<AddressOverview address={address} addressData={addressData} />
<AddressDetailTabs address={address} />
</Container>
</Layout>
Expand All @@ -41,30 +46,25 @@ const AddressDetailPage: React.FC<Props> = props => {
export async function getServerSideProps({ params }) {
const { address } = params
if (web3.utils.isAddress(address))
return {
props: {
address
try {
const addressRes = await evmApi.get<BlockDetailResponse>(`${API_LIST.ADDRESS_DETAIL}${address}`)
const addressData = addressRes.data.result
return {
props: {
address,
addressData
}
}
} catch (e) {
// console.log(e.message)
return {
redirect: {
destination: '/404',
permanent: false
}
}
}
// try {
// const blockRes = await cosmosApi.get<BlockDetailResponse>(`${API_LIST.BLOCKS}${blockHeight}`)
// const transactionRes = await cosmosApi.get<TransactionResponse>(
// `${API_LIST.TRANSACTION_OF_BLOCK.replace(':id', blockHeight)}`
// )
// const transactions = transactionRes.data.result
// if (blockRes.status === 200) {
// return { props: { blockDetail: blockRes.data.result, blockHeight, transactions } }
// } else {
// return { props: { data: {} } }
// }
// } catch (e) {
// return {
// redirect: {
// destination: '/404',
// permanent: false
// }
// }
// }

return {
redirect: {
destination: '/404',
Expand Down
10 changes: 10 additions & 0 deletions types/address.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
interface Address {
balance: string
creationTransaction: string
creator: string
lastBalanceUpdate: number
tokenName: string
tokenSymbol: string
type: 'address' | 'contractaddress' // string
}

interface AbiResponse {
message: string
result: string
Expand Down
27 changes: 25 additions & 2 deletions views/accounts/AddressOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ import styles from './style.module.scss'

interface Props {
address: string
addressData: Address
}

const AddressOverview = ({ address }: Props) => {
const AddressOverview = ({ address, addressData }: Props) => {
const addressCounter = useAddressCounter(address)
const addressBalance = useAddressBalance(address)
const astraSummary = useAppSelector(getAstraSummary)

const isContract = addressData.type === 'contractaddress'
return (
<BackgroundCard classes={clsx('padding-lg margin-top-2xl', styles.overview)}>
<Row style={{ justifyContent: 'space-between' }} classes={clsx(styles.borderBottom, 'padding-bottom-lg')}>
<div>
<span className="text text-base contrast-color-50">Wallet Address:</span>
<span className="text text-base contrast-color-50">
{isContract ? 'Contract' : 'Wallet Address'}
</span>
<br />
<span className="text text-lg">{address}</span>
</div>
Expand All @@ -35,6 +39,25 @@ const AddressOverview = ({ address }: Props) => {
{/* <QrButton textTitle="qrcode" content={address} /> */}
</div>
</Row>
{isContract && (
<div
style={{ justifyContent: 'space-between' }}
className={clsx(styles.borderBottom, 'padding-bottom-lg padding-top-lg')}
>
<div>
<span className="text text-base contrast-color-50">Owner</span>
<br />
<LinkText href={LinkMaker.address(addressData.creator)}>{addressData.creator}</LinkText>
</div>
<div>
<span className="text text-base contrast-color-50">Transaction Hash</span>
<br />
<LinkText href={LinkMaker.transaction(addressData.creationTransaction)}>
{addressData.creationTransaction}
</LinkText>
</div>
</div>
)}
<Row style={{ justifyContent: 'space-between' }} classes="padding-top-lg">
<div className={styles.colBalance}>
<span className="text text-base contrast-color-50">Balance:</span>
Expand Down
19 changes: 15 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
link-module-alias "^1.2.0"
shx "^0.3.4"

"@astraprotocol/astra-ui@^1.0.12":
version "1.0.12"
resolved "https://npm.pkg.github.com/download/@astraprotocol/astra-ui/1.0.12/bfb8b32e6cfc5870dd8b9042bf3ba02ef915d922#bfb8b32e6cfc5870dd8b9042bf3ba02ef915d922"
integrity sha512-auafVe12rFCvNEfXvY8eymCB8JM0OgvfSGlOxrOg87bcl1fgwLL8lrlSfx48/py8nF3W3wfuL4k4q8aYR2yq8w==
"@astraprotocol/astra-ui@^1.0.13":
version "1.0.13"
resolved "https://npm.pkg.github.com/download/@astraprotocol/astra-ui/1.0.13/63c928535e294a78b8abc167c555e31c81c8449e#63c928535e294a78b8abc167c555e31c81c8449e"
integrity sha512-a8MH96P4nKoy/vziqJIbI4hJZJPyPEl4nSTqR1nF6vAW4KEgaxN3VgMSqrNYSQlkaK5WWsaVJSRN0ADTdg8h2Q==
dependencies:
"@types/numeral" "^2.0.2"
"@types/react-copy-to-clipboard" "^5.0.4"
clsx "^1.2.1"
numeral "^2.0.6"
react "^18.2.0"
react-copy-to-clipboard "^5.1.0"
react-dom "^18.2.0"

"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.18.6":
Expand Down Expand Up @@ -2176,6 +2180,13 @@
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==

"@types/react-copy-to-clipboard@^5.0.4":
version "5.0.4"
resolved "https://registry.yarnpkg.com/@types/react-copy-to-clipboard/-/react-copy-to-clipboard-5.0.4.tgz#558f2c38a97f53693e537815f6024f1e41e36a7e"
integrity sha512-otTJsJpofYAeaIeOwV5xBUGpo6exXG2HX7X4nseToCB2VgPEBxGBHCm/FecZ676doNR7HCSTVtmohxfG2b3/yQ==
dependencies:
"@types/react" "*"

"@types/[email protected]":
version "18.0.6"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.0.6.tgz#36652900024842b74607a17786b6662dd1e103a1"
Expand Down

0 comments on commit af1cdbf

Please sign in to comment.