-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b61ce5
commit 3e281c6
Showing
23 changed files
with
1,014 additions
and
375 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
23 changes: 3 additions & 20 deletions
23
apps/dapp/src/components/Pages/Core/DappPages/SpiceBazaar/Earn/Auctions/Chart/Chart.tsx
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
85 changes: 8 additions & 77 deletions
85
apps/dapp/src/components/Pages/Core/DappPages/SpiceBazaar/Earn/Auctions/Table/Table.tsx
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
83 changes: 83 additions & 0 deletions
83
...c/components/Pages/Core/DappPages/SpiceBazaar/Earn/Auctions/hooks/use-auctions-history.ts
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,83 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { stableGoldAuctionInstances, subgraphQuery } from 'utils/subgraph'; | ||
|
||
export type Transaction = { | ||
epoch: string; | ||
status: 'Upcoming' | 'Active' | 'Closed'; | ||
startTime: string; | ||
endTime: string; | ||
totalAuctionTokenAmount: string; | ||
priceRatio: string; | ||
}; | ||
|
||
type UseAuctionsHistoryReturn = { | ||
data: Transaction[] | null; | ||
loading: boolean; | ||
error: string | null; | ||
refetch: () => void; | ||
}; | ||
|
||
export const useAuctionsHistory = (): UseAuctionsHistoryReturn => { | ||
const [data, setData] = useState<Transaction[] | null>(null); | ||
const [loading, setLoading] = useState<boolean>(true); | ||
const [error, setError] = useState<string | null>(null); | ||
|
||
function getAuctionStatus( | ||
startTime: string, | ||
endTime: string | ||
): 'Upcoming' | 'Active' | 'Closed' { | ||
const now = new Date(); | ||
|
||
const startDate = new Date(startTime); | ||
const endDate = new Date(endTime); | ||
|
||
if (startDate > now) { | ||
return 'Upcoming'; | ||
} else if (endDate > now) { | ||
return 'Active'; | ||
} else { | ||
return 'Closed'; | ||
} | ||
} | ||
|
||
const fetchData = async () => { | ||
setLoading(true); | ||
setError(null); | ||
|
||
try { | ||
const response = await subgraphQuery( | ||
'https://subgraph.satsuma-prod.com/a912521dd162/templedao/spice-bazaar-sepolia/api', | ||
stableGoldAuctionInstances() | ||
); | ||
|
||
setData( | ||
response.stableGoldAuctionInstances.map((r) => ({ | ||
epoch: r.epoch, | ||
startTime: new Date((r.startTime as any) * 1000).toLocaleDateString(), | ||
endTime: new Date((r.endTime as any) * 1000).toLocaleDateString(), | ||
totalAuctionTokenAmount: parseFloat( | ||
r.totalAuctionTokenAmount | ||
).toFixed(2), | ||
priceRatio: parseFloat(r.priceRatio).toFixed(5), | ||
status: getAuctionStatus(r.startTime, r.endTime), | ||
})) | ||
); | ||
setLoading(false); | ||
} catch (err) { | ||
console.error('Error fetching data:', err); | ||
setError('Failed to fetch auction history.'); | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchData(); | ||
}, []); | ||
|
||
return { | ||
data, | ||
loading, | ||
error, | ||
refetch: fetchData, | ||
}; | ||
}; |
28 changes: 28 additions & 0 deletions
28
...ponents/Pages/Core/DappPages/SpiceBazaar/Earn/Auctions/hooks/use-auctions-priceHistory.ts
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,28 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { subDays } from 'date-fns'; | ||
|
||
type Metric = { timestamp: number; price: number }; | ||
|
||
const pricesLast7Days: Metric[] = [ | ||
{ timestamp: subDays(new Date(), 6).getTime(), price: 5.32 }, | ||
{ timestamp: subDays(new Date(), 5).getTime(), price: 5.3 }, | ||
{ timestamp: subDays(new Date(), 4).getTime(), price: 5.3 }, | ||
{ timestamp: subDays(new Date(), 3).getTime(), price: 5.36 }, | ||
{ timestamp: subDays(new Date(), 2).getTime(), price: 5.36 }, | ||
{ timestamp: subDays(new Date(), 1).getTime(), price: 5.34 }, | ||
{ timestamp: new Date().getTime(), price: 5.45 }, | ||
]; | ||
|
||
export const useAuctionsPriceHistory = (isPhoneOrAbove: boolean) => { | ||
const [metrics, setMetrics] = useState<Metric[]>([]); | ||
|
||
useEffect(() => { | ||
if (isPhoneOrAbove) { | ||
setMetrics(pricesLast7Days); | ||
} else { | ||
setMetrics(pricesLast7Days.filter((_, index) => index % 2 === 0)); | ||
} | ||
}, [isPhoneOrAbove]); | ||
|
||
return metrics; | ||
}; |
Oops, something went wrong.