Skip to content

Commit da46f61

Browse files
committed
fix: Bitcoin price chart display and percentage calculation
- Fix chart lines not appearing by using correct ECharts data format - Remove unused encode block that expected object data but received arrays - Fix tooltip formatter to read value directly instead of value[1] - Fix 0% price change by comparing first vs last rate instead of consecutive rates
1 parent a9bc6fd commit da46f61

2 files changed

Lines changed: 5 additions & 12 deletions

File tree

src/components/relay-dashboard/totalEarning/TotalEarning.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export const TotalEarning: React.FC = () => {
2929
}, [bitcoinRates]);
3030

3131
const latestRate = bitcoinRates.length > 0 ? Number(bitcoinRates[bitcoinRates.length - 1]?.usd_value) : undefined;
32-
const previousRate = bitcoinRates.length > 1 ? Number(bitcoinRates[bitcoinRates.length - 2]?.usd_value) : undefined;
33-
const isIncreased = latestRate && previousRate ? latestRate > previousRate : false;
34-
const rateDifference = latestRate && previousRate ? ((latestRate - previousRate) / previousRate) * 100 : 0;
32+
const firstRate = bitcoinRates.length > 1 ? Number(bitcoinRates[0]?.usd_value) : undefined;
33+
const isIncreased = latestRate && firstRate ? latestRate > firstRate : false;
34+
const rateDifference = latestRate && firstRate ? ((latestRate - firstRate) / firstRate) * 100 : 0;
3535

3636

3737
if (isLoading) {

src/components/relay-dashboard/totalEarning/TotalEarningChart/TotalEarningChart.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const TotalEarningChart: React.FC<TotalEarningChartProps> = ({ xAxisData,
3939
{
4040
name: t('nft.earnings'),
4141
type: 'line',
42-
data: earningData.data.map((value, index) => [xAxisData[index], value]),
42+
data: earningData.data,
4343
showSymbol: false,
4444
smooth: true,
4545
lineStyle: {
@@ -68,13 +68,6 @@ export const TotalEarningChart: React.FC<TotalEarningChartProps> = ({ xAxisData,
6868
width: 4,
6969
},
7070
},
71-
encode: {
72-
x: 'date',
73-
y: 'usd_value',
74-
label: ['date', 'usd_value'],
75-
itemName: 'date',
76-
tooltip: ['usd_value'],
77-
},
7871
},
7972
];
8073

@@ -85,7 +78,7 @@ export const TotalEarningChart: React.FC<TotalEarningChartProps> = ({ xAxisData,
8578
confine: true,
8679
formatter: (data: any) => {
8780
const currentSeries = data[0];
88-
const roundedValue = Math.round(currentSeries.value[1]); // Round to nearest dollar
81+
const roundedValue = Math.round(currentSeries.value); // Round to nearest dollar
8982
return `${currentSeries.name} - ${getCurrencyPrice(
9083
formatNumberWithCommas(roundedValue),
9184
CurrencyTypeEnum.USD,

0 commit comments

Comments
 (0)