Skip to content

Commit

Permalink
feat: update some endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Tien Nam Dao committed Feb 16, 2023
1 parent 1e9c20e commit d574289
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 60 deletions.
22 changes: 11 additions & 11 deletions api/api_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ const API_LIST = {
ALL_BLOCKS: '/api/v1/blocks',
BLOCKS: '/api/v1/blocks/',
TRANSACTION_OF_BLOCK: '/api/v1/blocks/:id/transactions',
LATEST_BLOCK: 'evm_/api/v1?module=block&action=eth_block_number',
LATEST_BLOCK: '/api/v1/eth-block-number',

ALL_TOKENS: 'evm_/api/v1?module=token&action=getListTokens', // &page=1&offset=20
ALL_HOLDERS: 'api/v1/accounts/get-top-addresses-balance?blockscout=true', // &page=1&offset=20
ALL_TOKENS: '/api/v1/accounts/get-list-tokens?blockscout=true', // &page=1&offset=20
ALL_HOLDERS: '/api/v1/accounts/get-top-addresses-balance?blockscout=true', // &page=1&offset=20
ALL_TRANSACTIONS: '/api/v1/transactions',

TRANSACTIONS: '/api/v1/transactions',
EVM_INTERNAL_TRANSACTION: 'evm_/api/v1?module=account&action=txlistinternal&txhash=', // call axios
EVM_INTERNAL_TRANSACTION: '/api/v1/transactions/internal-transactions/', // call axios
COSMOS_TRANSACTION: '/api/v1?module=transaction&action=getTxCosmosInfo&txhash=', // call axios

ABI: '/api/v1?module=contract&action=getabi&address=',
HASH_ABI: '/api/v1?module=transaction&action=getabibytxhash&txhash=',
ABI: '/api/v1/accounts/getabi/',
HASH_ABI: '/api/v1/transactions/getabi/',

VALIDATORS: '/api/v1/validators',

MARKET_HISTORY_PRICE: 'evm_/api/v1/market-history-chart',
MARKET_HISTORY_PRICE: '/api/v1/market-history-chart',
TRANSACTION_HISTORY_COUNTER: '/api/v1/transactions-history-chart',
TRANSACTION_RAW_TRACE: 'evm_/api/v1?module=transaction&action=getrawtracebytxhash', // txhash
TRANSACTION_RAW_TRACE: '/api/v1/transactions/getrawtrace/', // txhash

MARKET_PRICE: 'https://api.tiki.vn/sandseel/api/v2/public/markets/astra/summary',
COMMON_STATS: '/api/v1/common-stats',
ESTIMATE_COUNTED_INFO: '/api/v1/estimate-counted-info',
GAS_AVG: 'evm_/api/v1/gas-price-oracle',
GAS_AVG: '/api/v1/gas-price-oracle',

ADDRESS_DETAIL: '/api/v1/accounts/detail',
ADDRESS_TOKEN: 'evm_/api/v1?module=account&action=tokenlist', // address = ?
ADDRESS_TOKEN: '/api/v1/accounts/tokenlist/', // address = ?
ADDRESS_COUNTER: '/api/v1/accounts', // address=?
// ADDRESS_BALANCE: 'evm_/api/v1?module=account&action=balance', // address=?
ADDRESS_COIN_BALANCE_HISTORY: 'evm_/api/v1?module=account&action=getcoinbalancehistory', // address, page, offset=?
ADDRESS_COIN_BALANCE_HISTORY_CHART: 'evm_/address', // address, page, offset=?
ADDRESS_COIN_BALANCE_HISTORY_CHART: 'api/v1/accounts', // address, page, offset=?
ADDRESS_TRANSACTION: '/api/v1/accounts',
ADDRESS_INTERNAL_TRANSACTION: 'evm_/api/v1?module=account&action=txlistinternal', // address, page, offset
ADDRESS_TOKEN_TRANSFER: 'evm_/api/v1?module=account&action=getlisttokentransfers', // address=?
Expand Down
2 changes: 1 addition & 1 deletion hooks/useAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function useAbi(address: string) {
const { data } = useSWR<AbiResponse>(_fetch())

useEffect(() => {
if (data.message === 'OK') {
if (data) {
const abiRaw = data.result
setAbi(JSON.parse(abiRaw))
}
Expand Down
22 changes: 14 additions & 8 deletions project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ interface TransactionHistoryCounter {
}

interface MarketHistoryPriceResponse {
history_data: string
supply_data: string
result: {
history_data: string
supply_data: string
}
}

interface TransactionHistoryCounterResponse {
Expand Down Expand Up @@ -72,15 +74,19 @@ interface CommonStatsResponse {
}

interface GasTracker {
average: number
fast: number
slow: number
result: {
average: number
fast: number
slow: number
}
}

interface LatestBlock {
jsonrpc: string
result: string
id: number
result: {
jsonrpc: string
result: string
id: number
}
}

interface MarketPriceResponse {
Expand Down
40 changes: 40 additions & 0 deletions sentry.edge.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// This file configures the initialization of Sentry on the browser.
// The config you add here will be used whenever a page is visited.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from '@sentry/nextjs'

const SENTRY_DSN = process.env.SENTRY_CLIENT_DSN

const isUserRejected = err => {
// provider user rejected error code
return typeof err === 'object' && 'code' in err && err.code === 4001
}

const ENV = process.env.VERCEL_ENV || process.env.NODE_ENV

Sentry.init({
dsn: SENTRY_DSN,

environment: ENV === 'production' ? 'production' : 'development',
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 0,
// ...
// Note: if you want to override the automatic release value, do not set a
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
// that it will also get attached to your source maps
beforeSend(event, hint) {
const error = hint?.originalException
if (error && isUserRejected(error)) {
return null
}
return event
},
ignoreErrors: [
'User denied transaction signature',
'Non-Error promise rejection captured',
'User rejected the transaction',
'cancelled',
'PollingBlockTracker'
]
})
16 changes: 9 additions & 7 deletions types/address.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ interface AddressDetailResponse {
}

interface AbiResponse {
message: string
result: string
status: string
}

interface HashAbiResponse {
message: string
result: {
abi: {
inputs: []
Expand All @@ -40,7 +37,6 @@ interface HashAbiResponse {
}
verified: boolean
}
status: string
}

interface AddressCounterResponse {
Expand All @@ -63,9 +59,11 @@ interface AddressTokenTransferResponse {
}

interface AddressTokenResponse {
hasNextPage: boolean
nextPagePath: string
result: AddressToken[]
result: {
hasNextPage: boolean
nextPagePath: string
result: AddressToken[]
}
}

interface AddressInternalTransactionResponse {
Expand Down Expand Up @@ -172,6 +170,10 @@ interface AddressCoinBalanceHistoryChartData {
value: number
}

interface AddressCoinBalanceHistoryChartResponse {
result: AddressCoinBalanceHistoryChartData[]
}

interface AddressCounterData {
gasUsageCount?: number
tokenTransferCount?: number
Expand Down
6 changes: 4 additions & 2 deletions types/token.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ interface UseTokenHookData {
}

interface TokenResponse {
result: Token[]
hasNextPage: boolean
result: {
result: Token[]
hasNextPage: boolean
}
}

interface TokenTransaction {
Expand Down
4 changes: 0 additions & 4 deletions types/transactions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,13 @@ interface InternalTransactionItem {
toAddressName: string
}
interface InternalTransactionReponse {
message: 'OK' | string
result: InternalTransactionItem[]
status: string
}

interface TransactionRawTraceResponse {
message: string
result: {
rawTrace: any[]
}
status: string
}

interface EvmTransactionDetailResponse {
Expand Down
6 changes: 3 additions & 3 deletions views/accounts/hook/useAddressCoinBalanceHistoryChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export default function useAddressCoinBalanceHistoryChart(address: string) {
const [hookData, setState] = useState<UseAddressCoinBalanceHistoryChartData>({ result: [] })

const _fetchCondition = () => {
return [`${API_LIST.ADDRESS_COIN_BALANCE_HISTORY_CHART}/${address}/coin-balances/by-day?type=JSON`]
return [`${API_LIST.ADDRESS_COIN_BALANCE_HISTORY_CHART}/${address}/coin-balances/by-day`]
}
const { data } = useSWR<AddressCoinBalanceHistoryChartData[]>(_fetchCondition())
const { data } = useSWR<AddressCoinBalanceHistoryChartResponse>(_fetchCondition())

useEffect(() => {
if (data) {
setState({ result: data })
setState({ result: data.result })
}
}, [data])
return hookData.result
Expand Down
9 changes: 5 additions & 4 deletions views/accounts/hook/useAddressToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ export default function useAddressToken(address: string, params: string | undefi
const _fetchCondition = () => {
if (params) {
return [
`${API_LIST.ADDRESS_TOKEN}${params}`,
`${API_LIST.ADDRESS_TOKEN}${address}${params}`,
{
address
blockscout: true
}
]
}

return [
API_LIST.ADDRESS_TOKEN,
`${API_LIST.ADDRESS_TOKEN}${address}`,
{
blockscout: true,
address,
page: 1,
offset: getEnvNumber('NEXT_PUBLIC_PAGE_OFFSET')
Expand All @@ -34,7 +35,7 @@ export default function useAddressToken(address: string, params: string | undefi

useEffect(() => {
if (data?.result) {
setState(data)
setState(data?.result)
}
}, [data])

Expand Down
2 changes: 1 addition & 1 deletion views/homepage/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const OverviewChart = ({}) => {
useSWR<TransactionHistoryCounterResponse>(_fetchCondition('transaction_history_counter'))

// const availableSupply = JSON.parse(historyPriceRaw.supply_data)
const marketHistoryData = historyPriceRaw ? humps.camelizeKeys(JSON.parse(historyPriceRaw.history_data)) : []
const marketHistoryData = historyPriceRaw ? humps.camelizeKeys(JSON.parse(historyPriceRaw.result.history_data)) : []
const historyCounterTransaction = historyCounterTransactionRaw ? historyCounterTransactionRaw.result : []

const data: any = {
Expand Down
2 changes: 1 addition & 1 deletion views/homepage/MarketStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Props {
}

function getLastestBlock(latestBlock: LatestBlock) {
return latestBlock ? parseInt(latestBlock.result) : undefined
return latestBlock ? parseInt(latestBlock.result.result) : undefined
}

const MarketStatistics = ({ classes, commonStatsData, estimateCountedData }: Props) => {
Expand Down
2 changes: 1 addition & 1 deletion views/homepage/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const Overview = () => {

const estimateCountedData = getEstimateCountedData(estimateCountedDataRaw?.result)
const commonStatsData = getCommonStatsData(commonStatsDataRaw?.result)
const gasAvgData = getGasAvgData(gasAvgRaw)
const gasAvgData = getGasAvgData(gasAvgRaw?.result)

return (
<div className={clsx(styles.overview, isMobile && 'margin-bottom-2xl')}>
Expand Down
4 changes: 2 additions & 2 deletions views/tokens/hook/useTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default function useTokens(page: number): UseTokenHookData {
const { data, isValidating } = useSWR<TokenResponse>(_fetchCondition())

useEffect(() => {
if (data?.result) {
setState({ tokens: data.result, hasNextPage: data.hasNextPage })
if (data?.result?.result) {
setState({ tokens: data.result.result, hasNextPage: data.result.hasNextPage })
}
}, [data])
return {
Expand Down
6 changes: 3 additions & 3 deletions views/transactions/DecodeInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import abiDecoder from 'abi-decoder'
import { evmApi } from 'api'
import { cosmosApi } from 'api'
import API_LIST from 'api/api_list'
import clsx from 'clsx'
import BackgroundCard from 'components/Card/Background/BackgroundCard'
Expand Down Expand Up @@ -45,9 +45,9 @@ export default function DecodeInput({ dataInput, address, evmHash }: DecodeInput
const getAbi = async (address: string): Promise<{ abi: AbiItem[]; hasVerified: boolean }> => {
// datainput from hash
if (evmHash) {
const hashAbiRes = await evmApi.get<HashAbiResponse>(`${API_LIST.HASH_ABI}${evmHash}`)
const hashAbiRes = await cosmosApi.get<HashAbiResponse>(`${API_LIST.HASH_ABI}${evmHash}`)

if (hashAbiRes.data.message === 'OK') {
if (hashAbiRes.data) {
return { abi: [hashAbiRes?.data?.result?.abi], hasVerified: hashAbiRes?.data?.result?.verified }
}
}
Expand Down
6 changes: 3 additions & 3 deletions views/transactions/Log.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import abiDecoder from 'abi-decoder'
import { evmApi } from 'api'
import { cosmosApi } from 'api'
import API_LIST from 'api/api_list'
import { EventDecode } from 'components/Card/CardInfo/Components/Decode'
import RowLoader from 'components/Loader/RowLoader'
Expand All @@ -25,9 +25,9 @@ export default function Log({ logs, display, evmHash }: LogProps) {

const getAbi = async (address: string): Promise<AbiItem[]> => {
if (evmHash) {
const hashAbiRes = await evmApi.get<HashAbiResponse>(`${API_LIST.HASH_ABI}${evmHash}`)
const hashAbiRes = await cosmosApi.get<HashAbiResponse>(`${API_LIST.HASH_ABI}${evmHash}`)

if (hashAbiRes.data.message === 'OK') {
if (hashAbiRes.data) {
return [hashAbiRes?.data?.result?.abi]
}
}
Expand Down
7 changes: 4 additions & 3 deletions views/transactions/hook/useInternalTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ export default function useInternalTransactions({ hash }: { hash: string }) {

const isLoadedData = useCallback(() => {
return !isEmpty(data) || error
}, [data])
}, [data, error])

const { isWaiting } = useDelayUntilDone(isLoadedData)

const _convertData = useCallback((): TransactionRowProps[] => {
if (!data) return []
const items: TransactionRowProps[] = []
if (data && data?.result.length > 0) {
const internalItems = data.result
if (data && data?.result && data?.result.length > 0) {
const internalItems = data?.result
for (let internalItem of internalItems) {
items.push({
blockNumber: Number(internalItem?.blockNumber),
Expand Down
7 changes: 1 addition & 6 deletions views/transactions/hook/useTxRawTrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ export default function useTxRawTrace(txhash: string, type: 'evm' | 'cosmos') {
const _fetchCondition = () => {
if (type === 'cosmos') return ''

return [
`${API_LIST.TRANSACTION_RAW_TRACE}`,
{
txhash
}
]
return [`${API_LIST.TRANSACTION_RAW_TRACE}${txhash}`]
}
const { data } = useSWR<TransactionRawTraceResponse>(_fetchCondition())

Expand Down

0 comments on commit d574289

Please sign in to comment.