generated from scaffold-eth/scaffold-eth
-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3143 from OlympusDAO/rbsPriceDisplayUpdates
Update RBS Pricing Display
- Loading branch information
Showing
5 changed files
with
169 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
type CountdownProps = { | ||
targetDate: Date; | ||
}; | ||
|
||
const CountdownTimer: React.FC<CountdownProps> = ({ targetDate }) => { | ||
const calculateTimeLeft = () => { | ||
const now = new Date(); | ||
const difference = targetDate.getTime() - now.getTime(); | ||
let timeLeft = { hours: 0, minutes: 0 }; | ||
|
||
if (difference > 0) { | ||
timeLeft = { | ||
hours: Math.floor(difference / (1000 * 60 * 60)), | ||
minutes: Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60)), | ||
}; | ||
} | ||
|
||
return timeLeft; | ||
}; | ||
|
||
const [timeLeft, setTimeLeft] = useState(calculateTimeLeft()); | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
setTimeLeft(calculateTimeLeft()); | ||
}, 60000); | ||
|
||
return () => clearTimeout(timer); | ||
}); | ||
|
||
return ( | ||
<> | ||
{timeLeft.hours > 0 || timeLeft.minutes > 0 ? ( | ||
<> | ||
in {timeLeft.hours} hours, {timeLeft.minutes} minutes | ||
</> | ||
) : ( | ||
<> in 0 hours, 0 minutes</> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default CountdownTimer; |
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,29 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import axios from "axios"; | ||
|
||
interface DefillamaPriceResponse { | ||
coins: { | ||
[address: string]: { | ||
symbol: string; | ||
price: number; | ||
}; | ||
}; | ||
} | ||
/**Mainnet only addresses */ | ||
export const useGetDefillamaPrice = ({ addresses }: { addresses: string[] }) => { | ||
return useQuery( | ||
["useGetDefillamaPrice", addresses], | ||
async () => { | ||
try { | ||
const joinedAddresses = addresses.map(address => `ethereum:${address}`).join(","); | ||
const response = await axios.get<DefillamaPriceResponse>( | ||
`https://coins.llama.fi/prices/current/${joinedAddresses}`, | ||
); | ||
return response.data.coins; | ||
} catch (error) { | ||
return {}; | ||
} | ||
}, | ||
{ enabled: addresses.length > 0 }, | ||
); | ||
}; |
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