This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(exchange-rate): exchange rate page
- Loading branch information
1 parent
ff3e676
commit 27b61ad
Showing
19 changed files
with
461 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import { Typography, Box, Grid, Paper, Avatar, Button } from '@mui/material'; | ||
import { setSelectedCurrency, fetchExchangeRates } from '../redux/slices/currencySlice'; | ||
import { FlagIcon } from 'react-flag-kit'; | ||
import currencyToCountry from '../utils/currencyToCountry'; | ||
import useOnlineStatus from '../hooks/useOnlineStatus'; | ||
|
||
function ExchangeRates() { | ||
const dispatch = useDispatch(); | ||
const { exchangeRates, availableCurrencies, selectedCurrency, lastUpdated, status } = useSelector((state) => state.currency); | ||
const isOnline = useOnlineStatus(); | ||
|
||
const handleRefresh = () => { | ||
if (isOnline) { | ||
dispatch(fetchExchangeRates()); | ||
} else { | ||
alert('Cannot refresh exchange rates while offline.'); | ||
} | ||
}; | ||
|
||
return ( | ||
<Box sx={{ mt: 4 }}> | ||
<Box sx={{ display: 'flex', justifyContent: 'space-between', mb: 2 }}> | ||
<Typography variant="h5">Current Exchange Rates</Typography> | ||
<Button variant="contained" onClick={handleRefresh} disabled={!isOnline}> | ||
Refresh Rates | ||
</Button> | ||
</Box> | ||
<Typography variant="body2" color="textSecondary" sx={{ mb: 2 }}> | ||
Last Updated: {lastUpdated || 'N/A'} | ||
</Typography> | ||
<Paper elevation={3} sx={{ p: 2 }}> | ||
<Grid container spacing={2}> | ||
{availableCurrencies.map((currency) => { | ||
const countryCode = currencyToCountry[currency]; | ||
if (!countryCode) { | ||
console.warn(`No country code found for currency: ${currency}`); | ||
} else { | ||
console.log(`Currency: ${currency}, Country Code: ${countryCode}`); | ||
} | ||
return ( | ||
<Grid item xs={12} sm={6} md={4} key={currency}> | ||
<Box sx={{ display: 'flex', alignItems: 'center' }}> | ||
{countryCode ? ( | ||
<Avatar sx={{ mr: 2, bgcolor: 'transparent' }}> | ||
<FlagIcon code={countryCode} size={24} /> | ||
</Avatar> | ||
) : ( | ||
<Avatar sx={{ mr: 2, bgcolor: 'transparent' }}> | ||
{/* Optionally, use a default icon or omit the avatar */} | ||
<span>🏳️</span> | ||
</Avatar> | ||
)} | ||
<Typography variant="body1" sx={{ flexGrow: 1 }}> | ||
{currency}: {exchangeRates[currency]} | ||
</Typography> | ||
{selectedCurrency !== currency && ( | ||
<Button | ||
size="small" | ||
variant="outlined" | ||
onClick={() => dispatch(setSelectedCurrency(currency))} | ||
> | ||
Select | ||
</Button> | ||
)} | ||
</Box> | ||
</Grid> | ||
); | ||
})} | ||
</Grid> | ||
</Paper> | ||
</Box> | ||
); | ||
} | ||
|
||
export default ExchangeRates; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { Typography, Box } from '@mui/material'; | ||
|
||
function Metadata() { | ||
const commitHash = process.env.REACT_APP_COMMIT_HASH || 'N/A'; | ||
|
||
return ( | ||
<Box sx={{ mt: 2, mb: 2 }}> | ||
<Typography variant="body2" color="textSecondary"> | ||
Latest Commit: {commitHash.substring(0, 7)} | ||
</Typography> | ||
</Box> | ||
); | ||
} | ||
|
||
export default Metadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useState, useEffect } from 'react'; | ||
|
||
function useOnlineStatus() { | ||
const [isOnline, setIsOnline] = useState(navigator.onLine); | ||
|
||
const updateOnlineStatus = () => { | ||
setIsOnline(navigator.onLine); | ||
}; | ||
|
||
useEffect(() => { | ||
window.addEventListener('online', updateOnlineStatus); | ||
window.addEventListener('offline', updateOnlineStatus); | ||
|
||
// Cleanup | ||
return () => { | ||
window.removeEventListener('online', updateOnlineStatus); | ||
window.removeEventListener('offline', updateOnlineStatus); | ||
}; | ||
}, []); | ||
|
||
return isOnline; | ||
} | ||
|
||
export default useOnlineStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.