Skip to content

Commit 95eba28

Browse files
authored
Gas tracker: bug fixes and improvements (#2792)
* Gas tracker page: hide `Gas price history` if chart is not enabled Fixes #2781 * change default value for NEXT_PUBLIC_GAS_TRACKER_UNITS for testnets * fix env for pw tests
1 parent fcdf8d9 commit 95eba28

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

configs/app/features/gasTracker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import type { Feature } from './types';
22
import { GAS_UNITS } from 'types/client/gasTracker';
33
import type { GasUnit } from 'types/client/gasTracker';
44

5+
import chainConfig from '../chain';
56
import { getEnvValue, parseEnvJson } from '../utils';
67

78
const isDisabled = getEnvValue('NEXT_PUBLIC_GAS_TRACKER_ENABLED') === 'false';
89

910
const units = ((): Array<GasUnit> => {
1011
const envValue = getEnvValue('NEXT_PUBLIC_GAS_TRACKER_UNITS');
1112
if (!envValue) {
13+
if (chainConfig.isTestnet) {
14+
return [ 'gwei' ];
15+
}
1216
return [ 'usd', 'gwei' ];
1317
}
1418

configs/envs/.env.pw

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ NEXT_PUBLIC_RE_CAPTCHA_APP_SITE_KEY=xxx
5858
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=xxx
5959
NEXT_PUBLIC_VIEWS_ADDRESS_FORMAT=['base16','bech32']
6060
NEXT_PUBLIC_VIEWS_ADDRESS_BECH_32_PREFIX=tom
61-
NEXT_PUBLIC_HELIA_VERIFIED_FETCH_ENABLED=false
61+
NEXT_PUBLIC_HELIA_VERIFIED_FETCH_ENABLED=false
62+
NEXT_PUBLIC_GAS_TRACKER_UNITS=['usd','gwei']

docs/ENVS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ This feature is **enabled by default**. To switch it off pass `NEXT_PUBLIC_GAS_T
383383
| Variable | Type| Description | Compulsoriness | Default value | Example value | Version |
384384
| --- | --- | --- | --- | --- | --- | --- |
385385
| NEXT_PUBLIC_GAS_TRACKER_ENABLED | `boolean` | Set to true to enable "Gas tracker" in the app | Required | `true` | `false` | v1.25.0+ |
386-
| NEXT_PUBLIC_GAS_TRACKER_UNITS | Array<`usd` \| `gwei`> | Array of units for displaying gas prices on the Gas Tracker page, in the stats snippet on the Home page, and in the top bar. The first value in the array will take priority over the second one in all mentioned views. If only one value is provided, gas prices will be displayed only in that unit. | - | `[ 'usd', 'gwei' ]` | `[ 'gwei' ]` | v1.25.0+ |
386+
| NEXT_PUBLIC_GAS_TRACKER_UNITS | Array<`usd` \| `gwei`> | Array of units for displaying gas prices on the Gas Tracker page, in the stats snippet on the Home page, and in the top bar. The first value in the array will take priority over the second one in all mentioned views. If only one value is provided, gas prices will be displayed only in that unit. | - | For testnets: `[ 'gwei' ]`, for mainnets: `[ 'usd', 'gwei' ]` | `[ 'gwei' ]` | v1.25.0+ |
387387

388388
&nbsp;
389389

stubs/stats.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ export const STATS_CHARTS_SECTION: stats.LineChartSection = {
7979
],
8080
};
8181

82+
export const STATS_CHARTS_SECTION_GAS: stats.LineChartSection = {
83+
id: 'gas',
84+
title: 'Gas',
85+
charts: [ {
86+
id: 'averageGasPrice',
87+
title: 'Average gas price',
88+
description: 'Average gas price',
89+
units: 'ETH',
90+
resolutions: [ 'DAY', 'MONTH' ],
91+
} ],
92+
};
93+
8294
export const STATS_CHARTS = {
8395
sections: [ STATS_CHARTS_SECTION ],
8496
};

ui/gasTracker/GasTrackerChart.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react';
44
import { route } from 'nextjs-routes';
55

66
import useApiQuery from 'lib/api/useApiQuery';
7-
import { STATS_CHARTS } from 'stubs/stats';
7+
import { STATS_CHARTS_SECTION_GAS } from 'stubs/stats';
88
import { Link } from 'toolkit/chakra/link';
99
import ContentLoader from 'ui/shared/ContentLoader';
1010
import DataFetchAlert from 'ui/shared/DataFetchAlert';
@@ -16,14 +16,18 @@ const GasTrackerChart = () => {
1616
const [ isChartLoadingError, setChartLoadingError ] = React.useState(false);
1717
const { data, isPlaceholderData, isError } = useApiQuery('stats:lines', {
1818
queryOptions: {
19-
placeholderData: STATS_CHARTS,
19+
placeholderData: {
20+
sections: [ STATS_CHARTS_SECTION_GAS ],
21+
},
2022
},
2123
});
2224

2325
const handleLoadingError = React.useCallback(() => {
2426
setChartLoadingError(true);
2527
}, []);
2628

29+
const chart = data?.sections.map((section) => section.charts.find((chart) => chart.id === GAS_PRICE_CHART_ID)).filter(Boolean)?.[0];
30+
2731
const content = (() => {
2832
if (isPlaceholderData) {
2933
return <ContentLoader/>;
@@ -33,10 +37,8 @@ const GasTrackerChart = () => {
3337
return <DataFetchAlert/>;
3438
}
3539

36-
const chart = data?.sections.map((section) => section.charts.find((chart) => chart.id === GAS_PRICE_CHART_ID)).filter(Boolean)?.[0];
37-
3840
if (!chart) {
39-
return <DataFetchAlert/>;
41+
return null;
4042
}
4143

4244
return (
@@ -53,6 +55,10 @@ const GasTrackerChart = () => {
5355
);
5456
})();
5557

58+
if (!chart) {
59+
return null;
60+
}
61+
5662
return (
5763
<Box>
5864
<Flex justifyContent="space-between" alignItems="center" mb={ 6 }>

ui/pages/GasTracker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const GasTracker = () => {
9191
<Heading level="2" mt={ 8 } mb={ 4 }>{ `Track ${ config.chain.name } gas fees` }</Heading>
9292
{ snippets }
9393
{ config.features.stats.isEnabled && (
94-
<Box mt={ 12 }>
94+
<Box mt={ 12 } _empty={{ display: 'none' }}>
9595
<GasTrackerChart/>
9696
</Box>
9797
) }

0 commit comments

Comments
 (0)