-
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: dosplay exchange rate in the hader
Adds exchange rated displayed under page harder showing current rate in EUR.
- Loading branch information
1 parent
e97456c
commit dc60fd2
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,10 +1,41 @@ | ||
import { ResponseDto, Status } from '@tatumio/tatum'; | ||
import { getExchangeRate } from './api/getWallet'; | ||
import ethereumlogo from './logo.svg'; | ||
import { Rate } from '@tatumio/tatum/dist/src/service/rate/rates.dto'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
export function Header() { | ||
const [rateData, setRateData] = useState<ResponseDto<Rate>>(); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
let cancel = false; | ||
getExchangeRate().then((rateData) => { | ||
if (!cancel) { | ||
setRateData(rateData); | ||
} | ||
}); | ||
return () => { | ||
cancel = true; | ||
}; | ||
}; | ||
|
||
fetchData(); | ||
|
||
const intervalId = setInterval(() => { | ||
fetchData(); | ||
}, 240000); | ||
|
||
return () => clearInterval(intervalId); | ||
}, []); | ||
|
||
return ( | ||
<header className="flex flex-col items-center text-slate-50 bg-slate-700 h-30 p-5"> | ||
<img src={ethereumlogo} alt="Ethereum logo" className="w-16 h-16" /> | ||
<h1 className="text-xl font-bold">Ethereum Wallet</h1> | ||
{rateData && | ||
rateData.status === Status.SUCCESS && | ||
'\u20AC ' + parseFloat(rateData.data.value).toFixed(2)} | ||
</header> | ||
); | ||
} |
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