Skip to content

Commit

Permalink
fix: update mobile Homepage statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Tien Nam Dao committed Oct 14, 2022
1 parent b914fbd commit af450df
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 50 deletions.
4 changes: 3 additions & 1 deletion components/Card/Background/BackgroundCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface Props {
classes?: string
backgroundCardBlur?: boolean
backgroundColor?: boolean
radius?: boolean
border?: boolean
}

Expand All @@ -15,12 +16,13 @@ const BackgroundCard = ({
classes,
backgroundCardBlur = true,
backgroundColor = true,
radius = true,
border = true
}: Props) => {
return (
<div
className={clsx(
'radius-lg',
radius && 'radius-lg',
{
[styles.background]: backgroundColor,
'border border-base': border,
Expand Down
13 changes: 8 additions & 5 deletions views/homepage/ChainStatistics.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useMobileLayout } from '@astraprotocol/astra-ui'
import StaticsCard from 'components/Card/Layout/StaticsCard'
import Row from 'components/Grid/Row'
import { Icon } from 'utils/enum'
import { formatCurrencyValue, formatGasValue } from 'utils/helper'

Expand All @@ -10,27 +12,28 @@ interface Props {
}

const ChainStatistics = ({ classes, commonStatsData, estimateCountedData, gasTracker }: Props) => {
const { isMobile } = useMobileLayout('small')
return (
<div className="row md-wrap">
<Row classes="md-wrap" style={{ alignItem: 'space-between' }}>
<StaticsCard
classes="col col-4"
classes={isMobile ? 'margin-bottom-lg' : 'margin-right-xl'}
content={formatCurrencyValue(commonStatsData?.token_stats?.market_cap)}
icon={Icon.Chart}
title="Market Cap"
/>
<StaticsCard
classes="col col-4"
classes={isMobile ? 'margin-bottom-lg' : 'margin-right-xl'}
content={formatGasValue(gasTracker?.average)}
icon={Icon.Gas}
title="Gas Tracker"
/>
<StaticsCard
classes="col col-4"
classes={isMobile ? 'margin-bottom-lg' : ''}
content={commonStatsData?.transaction_stats?.number_of_transactions}
icon={Icon.Analytics}
title="Daily Transactions"
/>
</div>
</Row>
)
}

Expand Down
5 changes: 4 additions & 1 deletion views/homepage/Chart.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMobileLayout } from '@astraprotocol/astra-ui'
import API_LIST from 'api/api_list'
import {
CategoryScale,
Expand Down Expand Up @@ -73,6 +74,8 @@ function getTxHistoryData(transactionHistory) {
}

const OverviewChart = ({}) => {
const { isMobile } = useMobileLayout('small')

const _fetchCondition = key => {
switch (key) {
case 'market_history_price':
Expand Down Expand Up @@ -235,7 +238,7 @@ const OverviewChart = ({}) => {
)
}

return <Line className={styles.chart} height={100} options={options} data={data} />
return <Line className={styles.chart} height={isMobile ? 190 : 150} options={options} data={data} />
}

export default OverviewChart
21 changes: 13 additions & 8 deletions views/homepage/MarketStatistics.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useMobileLayout } from '@astraprotocol/astra-ui'
import API_LIST from 'api/api_list'
import clsx from 'clsx'
import StaticsCard from 'components/Card/Layout/StaticsCard'
import numeral from 'numeral'
import useSWR from 'swr'
import { Icon } from 'utils/enum'

Expand All @@ -15,6 +17,7 @@ function getLastestBlock(latestBlock: LatestBlock) {
}

const MarketStatistics = ({ classes, commonStatsData, estimateCountedData }: Props) => {
const { isMobile } = useMobileLayout('small')
const _fetchCondition = key => {
switch (key) {
case 'latest_block':
Expand All @@ -27,35 +30,37 @@ const MarketStatistics = ({ classes, commonStatsData, estimateCountedData }: Pro
const latestBlock = getLastestBlock(latestBlockRaw)

return (
<div className="md-wrap">
<div className={clsx('row margin-bottom-2xl')}>
<div>
<div className={clsx('row md-wrap', !isMobile && 'margin-bottom-2xl')}>
<StaticsCard
classes="margin-right-xl"
classes={isMobile ? 'margin-bottom-lg' : 'margin-right-xl'}
contentClasses="money-2sm"
content={`${commonStatsData?.average_block_time} seconds`}
icon={Icon.Recovery}
title="Average Block Time"
/>

<StaticsCard
content={estimateCountedData?.total_transactions}
classes={isMobile ? 'margin-bottom-lg' : ''}
content={numeral(estimateCountedData?.total_transactions).format('0,0')}
contentClasses="money-2sm"
icon={Icon.Analytics}
title="Total Transactions"
/>
</div>

<div className={clsx('row')}>
<div className={clsx('row md-wrap')}>
<StaticsCard
classes="margin-right-xl"
classes={isMobile ? 'margin-bottom-lg' : 'margin-right-xl'}
contentClasses="money-2sm"
content={latestBlock || estimateCountedData?.total_blocks}
content={numeral(latestBlock || estimateCountedData?.total_blocks).format('0,0')}
icon={Icon.Database}
title="Total Blocks"
/>

<StaticsCard
content={estimateCountedData?.wallet_addresses}
classes={isMobile ? 'margin-bottom-lg' : ''}
content={numeral(estimateCountedData?.wallet_addresses).format('0,0')}
contentClasses="money-2sm"
icon={Icon.Wallet}
title="Wallet Addresses"
Expand Down
53 changes: 25 additions & 28 deletions views/homepage/Overview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useMobileLayout } from '@astraprotocol/astra-ui'
import API_LIST from 'api/api_list'
import clsx from 'clsx'
import BackgroundCard from 'components/Card/Background/BackgroundCard'
import Row from 'components/Grid/Row'
import Logo from 'components/Logo'
import Image from 'next/image'
import useSWR from 'swr'
Expand All @@ -23,9 +25,7 @@ function getGasAvgData(gasAvgData): GasTracker {
}

const Overview = () => {
// const { isMobile } = useMobileLayout(940)
// console.log(isMobile)
const isMobile = true
const { isMobile } = useMobileLayout('small')

const _fetchCondition = key => {
switch (key) {
Expand Down Expand Up @@ -57,31 +57,28 @@ const Overview = () => {
<div className={styles.moon2}>
<Image alt="moon2" src={'/images/background/moon2.png'} layout="fill" />
</div>
<BackgroundCard>
<div className="row md-wrap">
<div className={clsx('col col-5', styles.leftBlock)}>
<div className={clsx('row', 'block-ver-center')}>
<div className={clsx('col col-6')}>
<Logo text="Astra" type="transparent" />
</div>
<div className={clsx('col col-6')}>
<Price />
</div>
</div>
<div className={styles.separateBlock} />
<MarketStatistics estimateCountedData={estimateCountedData} commonStatsData={commonStatsData} />
</div>
<div className={clsx('col', styles.centerBlock)} />
<div className={clsx('col col-7', styles.rightBlock)}>
<OverviewChart />
<ChainStatistics
gasTracker={gasAvgData}
estimateCountedData={estimateCountedData}
commonStatsData={commonStatsData}
/>
</div>
</div>
</BackgroundCard>
<div className="row md-wrap">
<BackgroundCard
radius={false}
classes={clsx(isMobile && 'margin-bottom-md', styles.leftBlock, isMobile && styles.leftMobileBlock)}
>
<Row style={{ justifyContent: 'space-between' }}>
<Logo text="Astra" type="transparent" />
<Price />
</Row>
<div className={styles.separateBlock} />
<MarketStatistics estimateCountedData={estimateCountedData} commonStatsData={commonStatsData} />
</BackgroundCard>
{!isMobile && <div className={clsx('col', styles.centerBlock)} />}
<BackgroundCard classes={styles.rightBlock} radius={false}>
<OverviewChart />
<ChainStatistics
gasTracker={gasAvgData}
estimateCountedData={estimateCountedData}
commonStatsData={commonStatsData}
/>
</BackgroundCard>
</div>
</div>
)
}
Expand Down
11 changes: 4 additions & 7 deletions views/homepage/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@
background-color: var(--border-color);
}
}
.leftMobileBlock {
border-top-left-radius: var(----radius-lg) solid var(--border-color);
}

.centerBlock {
position: absolute;
top: var(--offset-lg);
left: 40.5%;
height: 90%;
// margin: var(--offset-lg) var(--offset-sm);
width: 1px;
background-color: var(--border-color);
// color: var(--border-color);
}

.rightBlock {
position: relative;
margin: var(--offset-lg) var(--offset-lg);
padding: var(--offset-2xl) var(--offset-lg);
.chart {
margin: var(--offset-lg) 0;
}
Expand Down

0 comments on commit af450df

Please sign in to comment.