11import { useCallback , useContext , useEffect , useRef , useState } from "react" ;
2+ import { useTranslation } from "react-i18next" ;
23import { useParams } from "react-router-dom" ;
34import { AppContext , useNetwork } from "../../../../context/AppContext" ;
45import { useDataService } from "../../../../hooks/useDataService" ;
@@ -11,14 +12,42 @@ const REFRESH_INTERVAL = 15000; // 15 seconds
1112
1213// Common transaction gas estimates
1314const TX_GAS_ESTIMATES = [
14- { name : "ETH Transfer" , gas : 21000 , description : "Native token transfer" } ,
15- { name : "ERC20 Transfer" , gas : 65000 , description : "Token transfer" } ,
16- { name : "ERC20 Approve" , gas : 46000 , description : "Token approval" } ,
17- { name : "NFT Transfer" , gas : 85000 , description : "ERC721 transfer" } ,
18- { name : "Swap" , gas : 150000 , description : "DEX swap" } ,
19- { name : "NFT Mint" , gas : 120000 , description : "Mint an NFT" } ,
20- { name : "Contract Deploy (Simple)" , gas : 300000 , description : "Deploy basic contract" } ,
21- ] ;
15+ {
16+ nameKey : "gasTracker.ethTransfer" ,
17+ descriptionKey : "gasTracker.ethTransferDesc" ,
18+ gas : 21000 ,
19+ } ,
20+ {
21+ nameKey : "gasTracker.erc20Transfer" ,
22+ descriptionKey : "gasTracker.erc20TransferDesc" ,
23+ gas : 65000 ,
24+ } ,
25+ {
26+ nameKey : "gasTracker.erc20Approve" ,
27+ descriptionKey : "gasTracker.erc20ApproveDesc" ,
28+ gas : 46000 ,
29+ } ,
30+ {
31+ nameKey : "gasTracker.nftTransfer" ,
32+ descriptionKey : "gasTracker.nftTransferDesc" ,
33+ gas : 85000 ,
34+ } ,
35+ {
36+ nameKey : "gasTracker.swap" ,
37+ descriptionKey : "gasTracker.swapDesc" ,
38+ gas : 150000 ,
39+ } ,
40+ {
41+ nameKey : "gasTracker.nftMint" ,
42+ descriptionKey : "gasTracker.nftMintDesc" ,
43+ gas : 120000 ,
44+ } ,
45+ {
46+ nameKey : "gasTracker.contractDeploy" ,
47+ descriptionKey : "gasTracker.contractDeployDesc" ,
48+ gas : 300000 ,
49+ } ,
50+ ] as const ;
2251
2352interface GasTrackerData {
2453 gasPrices : GasPrices | null ;
@@ -65,6 +94,7 @@ function calculateTxCost(
6594}
6695
6796export default function GasTracker ( ) {
97+ const { t } = useTranslation ( "network" ) ;
6898 const { networkId } = useParams < { networkId ?: string } > ( ) ;
6999 const numericNetworkId = Number ( networkId ) || 1 ;
70100 const networkConfig = useNetwork ( numericNetworkId ) ;
@@ -129,19 +159,17 @@ export default function GasTracker() {
129159 < div className = "container-wide" >
130160 < div className = "block-display-card" >
131161 < div className = "gas-tracker-header" >
132- < h1 className = "page-title-small" > Gas Tracker </ h1 >
162+ < h1 className = "page-title-small" > { t ( "gasTracker.title" ) } </ h1 >
133163 </ div >
134164
135- { loading && ! gasPrices && < Loader text = "Loading gas prices..." /> }
165+ { loading && ! gasPrices && < Loader text = { t ( "gasTracker.loadingGasPrices" ) } /> }
136166
137- { error && < p className = "error-text-center" > Error: { error } </ p > }
167+ { error && < p className = "error-text-center" > { t ( "gasTracker.errorLoadingGas" , { error } ) } </ p > }
138168
139169 { gasPrices && (
140170 < >
141171 < section className = "gas-tracker-section" >
142- < p className = "gas-tracker-section-subtitle" >
143- Based on the last 20 blocks. Prices include base fee + priority fee.
144- </ p >
172+ < p className = "gas-tracker-section-subtitle" > { t ( "gasTracker.basedOnLastBlocks" ) } </ p >
145173
146174 { ( ( ) => {
147175 const lowPrice = formatGasPrice ( gasPrices . low ) ;
@@ -153,32 +181,38 @@ export default function GasTracker() {
153181 < >
154182 < div className = "gas-price-cards" >
155183 < div className = "gas-price-card gas-price-low" >
156- < div className = "gas-price-tier-label" > Low </ div >
184+ < div className = "gas-price-tier-label" > { t ( "gasTracker.low" ) } </ div >
157185 < div className = "gas-price-tier-value" >
158186 { lowPrice . value } { lowPrice . unit }
159187 </ div >
160- < div className = "gas-price-tier-time" > ~5+ min</ div >
188+ < div className = "gas-price-tier-time" >
189+ { t ( "gasTracker.estimatedTimeLow" ) }
190+ </ div >
161191 </ div >
162192
163193 < div className = "gas-price-card gas-price-avg" >
164- < div className = "gas-price-tier-label" > Average </ div >
194+ < div className = "gas-price-tier-label" > { t ( "gasTracker.average" ) } </ div >
165195 < div className = "gas-price-tier-value" >
166196 { avgPrice . value } { avgPrice . unit }
167197 </ div >
168- < div className = "gas-price-tier-time" > ~1-3 min</ div >
198+ < div className = "gas-price-tier-time" >
199+ { t ( "gasTracker.estimatedTimeAvg" ) }
200+ </ div >
169201 </ div >
170202
171203 < div className = "gas-price-card gas-price-high" >
172- < div className = "gas-price-tier-label" > High </ div >
204+ < div className = "gas-price-tier-label" > { t ( "gasTracker.high" ) } </ div >
173205 < div className = "gas-price-tier-value" >
174206 { highPrice . value } { highPrice . unit }
175207 </ div >
176- < div className = "gas-price-tier-time" > ~30 sec</ div >
208+ < div className = "gas-price-tier-time" >
209+ { t ( "gasTracker.estimatedTimeHigh" ) }
210+ </ div >
177211 </ div >
178212 </ div >
179213
180214 < div className = "gas-base-fee" >
181- < span className = "gas-base-fee-label" > Base Fee: </ span >
215+ < span className = "gas-base-fee-label" > { t ( "gasTracker.baseFee" ) } </ span >
182216 < span className = "gas-base-fee-value" >
183217 { baseFee . value } { baseFee . unit }
184218 </ span >
@@ -189,19 +223,21 @@ export default function GasTracker() {
189223 </ section >
190224
191225 < section className = "gas-tracker-section" >
192- < h2 className = "gas-tracker-section-title" > Transaction Cost Estimates</ h2 >
226+ < h2 className = "gas-tracker-section-title" >
227+ { t ( "gasTracker.transactionCostEstimates" ) }
228+ </ h2 >
193229 < p className = "gas-tracker-section-subtitle" >
194- Estimated costs at current gas prices
230+ { t ( "gasTracker.estimatedCostsAtCurrent" ) }
195231 { price && ` (${ currency } @ $${ price . toFixed ( 2 ) } )` }
196232 </ p >
197233
198234 < div className = "tx-cost-table" >
199235 < div className = "tx-cost-header" >
200- < div className = "tx-cost-col-name" > Transaction Type </ div >
201- < div className = "tx-cost-col-gas" > Gas </ div >
202- < div className = "tx-cost-col-low" > Low </ div >
203- < div className = "tx-cost-col-avg" > Avg </ div >
204- < div className = "tx-cost-col-high" > High </ div >
236+ < div className = "tx-cost-col-name" > { t ( "gasTracker.transactionType" ) } </ div >
237+ < div className = "tx-cost-col-gas" > { t ( "gasTracker.gas" ) } </ div >
238+ < div className = "tx-cost-col-low" > { t ( "gasTracker.low" ) } </ div >
239+ < div className = "tx-cost-col-avg" > { t ( "gasTracker.average" ) } </ div >
240+ < div className = "tx-cost-col-high" > { t ( "gasTracker.high" ) } </ div >
205241 </ div >
206242
207243 { TX_GAS_ESTIMATES . map ( ( tx ) => {
@@ -210,10 +246,10 @@ export default function GasTracker() {
210246 const highCost = calculateTxCost ( gasPrices . high , tx . gas , price ) ;
211247
212248 return (
213- < div key = { tx . name } className = "tx-cost-row" >
249+ < div key = { tx . nameKey } className = "tx-cost-row" >
214250 < div className = "tx-cost-col-name" >
215- < span className = "tx-cost-name" > { tx . name } </ span >
216- < span className = "tx-cost-desc" > { tx . description } </ span >
251+ < span className = "tx-cost-name" > { t ( tx . nameKey ) } </ span >
252+ < span className = "tx-cost-desc" > { t ( tx . descriptionKey ) } </ span >
217253 </ div >
218254 < div className = "tx-cost-col-gas" > { tx . gas . toLocaleString ( ) } </ div >
219255 < div className = "tx-cost-col-low" >
@@ -244,7 +280,9 @@ export default function GasTracker() {
244280
245281 { data . lastUpdated && (
246282 < div className = "gas-tracker-updated" >
247- Last updated: { new Date ( data . lastUpdated ) . toLocaleTimeString ( ) }
283+ { t ( "gasTracker.lastUpdated" , {
284+ time : new Date ( data . lastUpdated ) . toLocaleTimeString ( ) ,
285+ } ) }
248286 </ div >
249287 ) }
250288 </ div >
0 commit comments