Skip to content

Commit

Permalink
fix(charts): type of charts tooltip data is wrong
Browse files Browse the repository at this point in the history
1. the assertion function of type of charts is wrong
2. the type of charts toolltip data must be converted from number to string
  • Loading branch information
Daryl-L committed Nov 3, 2023
1 parent 91a5a75 commit 5b0b038
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/pages/StatisticsChart/activities/BalanceDistribution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ const useOption = (
},
yAxisIndex: 0,
barWidth: isMobile || isThumbnail ? 20 : 50,
data: statisticBalanceDistributions.map(data => new BigNumber(data.addresses).toNumber()),
data: statisticBalanceDistributions.map(data => new BigNumber(data.addresses).toString()),
},
{
name: t('statistic.addresses_below_specific_balance'),
type: 'line',
yAxisIndex: 1,
symbol: isThumbnail ? 'none' : 'circle',
symbolSize: 3,
data: statisticBalanceDistributions.map(data => new BigNumber(data.sumAddresses).toNumber()),
data: statisticBalanceDistributions.map(data => new BigNumber(data.sumAddresses).toString()),
},
],
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/StatisticsChart/mining/DifficultyHashRate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ const useOption = (
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
symbolSize: 3,
data: statisticDifficultyHashRates.map(data => new BigNumber(data.difficulty).toNumber()),
data: statisticDifficultyHashRates.map(data => new BigNumber(data.difficulty).toString()),
},
{
name: t('block.hash_rate_hps'),
type: 'line',
yAxisIndex: 1,
symbol: isThumbnail ? 'none' : 'circle',
symbolSize: 3,
data: statisticDifficultyHashRates.map(data => new BigNumber(data.hashRate).toNumber()),
data: statisticDifficultyHashRates.map(data => new BigNumber(data.hashRate).toString()),
},
{
name: t('block.uncle_rate'),
Expand Down
6 changes: 3 additions & 3 deletions src/pages/StatisticsChart/monetary/TotalSupply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ const toCSV = (statisticTotalSupplies: ChartItem.TotalSupply[]) =>
statisticTotalSupplies
? statisticTotalSupplies.map(data => [
data.createdAtUnixtimestamp,
shannonToCkbDecimal(data.circulatingSupply, 8),
shannonToCkbDecimal(data.lockedCapacity, 8),
shannonToCkbDecimal(data.burnt, 8),
shannonToCkbDecimal(data.circulatingSupply, 8).toString(),
shannonToCkbDecimal(data.lockedCapacity, 8).toString(),
shannonToCkbDecimal(data.burnt, 8).toString(),
])
: []

Expand Down
2 changes: 1 addition & 1 deletion src/pages/StatisticsChart/nervosDao/NewDaoDeposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const useOption = (
source: statisticNewDaoDeposits.map(data => [
parseDateNoTime(data.createdAtUnixtimestamp),
new BigNumber(shannonToCkb(data.dailyDaoDeposit)).toFixed(0),
new BigNumber(data.dailyDaoDepositorsCount).toNumber(),
new BigNumber(data.dailyDaoDepositorsCount).toNumber().toString(),
]),
dimensions: ['timestamp', 'deposit', 'depositor'],
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/StatisticsChart/nervosDao/TotalDaoDeposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const useOption = (
source: statisticTotalDaoDeposits.map(data => [
parseDateNoTime(data.createdAtUnixtimestamp),
new BigNumber(shannonToCkb(data.totalDaoDeposit)).toFixed(0),
new BigNumber(data.totalDepositorsCount).toNumber(),
new BigNumber(data.totalDepositorsCount).toString(),
]),
dimensions: ['timestamp', 'deposit', 'depositor'],
},
Expand Down
6 changes: 3 additions & 3 deletions src/utils/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,21 @@ export const assertSerialsDataIsString: (value: EChartOption.Tooltip.Format) =>
value: EChartOption.Tooltip.Format,
) => {
if (typeof value.data !== 'string') {
throw new Error(`Value is expected to be an array, but got a ${typeof value.data}`)
throw new Error(`Value is expected to be an string, but got a ${typeof value.data}`)
}
}

export const assertSerialsDataIsStringArrayOf3: (
value: EChartOption.Tooltip.Format,
) => asserts value is { data: [string, string, string] } = (value: EChartOption.Tooltip.Format) => {
if (!Array.isArray(value.data) || value.data.length !== 3 || value.data.every(item => typeof item !== 'string')) {
if (!Array.isArray(value.data) || value.data.length !== 3 || !value.data.every(item => typeof item === 'string')) {
throw new Error('invalid SeriesItem length of 3')
}
}
export const assertSerialsDataIsStringArrayOf4: (
value: EChartOption.Tooltip.Format,
) => asserts value is { data: [string, string, string, string] } = (value: EChartOption.Tooltip.Format) => {
if (!Array.isArray(value.data) || value.data.length !== 4 || value.data.every(item => typeof item !== 'string')) {
if (!Array.isArray(value.data) || value.data.length !== 4 || !value.data.every(item => typeof item === 'string')) {
throw new Error('invalid SeriesItem length of 4')
}
}

0 comments on commit 5b0b038

Please sign in to comment.