-
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.
wallet sidebar: add relative time from fill tooltip
- Loading branch information
Showing
8 changed files
with
125 additions
and
127 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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React from "react" | ||
|
||
import { OrderMetadata, useOrderHistory } from "@renegade-fi/react" | ||
|
||
import { useLastVisit } from "@/app/components/track-last-visit" | ||
import { | ||
useViewedFills, | ||
generateFillIdentifier, | ||
} from "@/app/components/wallet-sidebar/hooks/use-viewed-fills" | ||
|
||
export function useRecentUnviewedFills() { | ||
const { lastVisit } = useLastVisit() | ||
const lastVisitBigInt = React.useMemo( | ||
() => (lastVisit ? BigInt(lastVisit) : null), | ||
[lastVisit], | ||
) | ||
|
||
const { data: orders } = useOrderHistory({ | ||
query: { | ||
select: (data) => { | ||
if (!lastVisitBigInt) return [] | ||
|
||
const filteredOrders: OrderMetadata[] = [] | ||
|
||
for (const order of data.values()) { | ||
const latestFill = order.fills[order.fills.length - 1] | ||
if (!latestFill || latestFill.price.timestamp <= lastVisitBigInt) { | ||
continue | ||
} | ||
|
||
const recentFills = order.fills.filter( | ||
(fill) => fill.price.timestamp > lastVisitBigInt, | ||
) | ||
|
||
if (recentFills.length > 0) { | ||
filteredOrders.push({ | ||
...order, | ||
fills: recentFills, | ||
}) | ||
} | ||
} | ||
|
||
return filteredOrders.sort((a, b) => { | ||
const latestFillA = a.fills[a.fills.length - 1].price.timestamp | ||
const latestFillB = b.fills[b.fills.length - 1].price.timestamp | ||
return Number(latestFillB - latestFillA) | ||
}) | ||
}, | ||
}, | ||
}) | ||
|
||
const { isFillViewed } = useViewedFills() | ||
|
||
const filteredOrders = React.useMemo(() => { | ||
if (!orders) return [] | ||
|
||
return orders | ||
.map((order) => ({ | ||
...order, | ||
fills: order.fills.filter( | ||
(fill) => | ||
!isFillViewed( | ||
generateFillIdentifier(order.id, fill.price.timestamp), | ||
), | ||
), | ||
})) | ||
.filter((order) => order.fills.length > 0) | ||
}, [orders, isFillViewed]) | ||
|
||
const totalUnviewedFills = React.useMemo( | ||
() => filteredOrders.reduce((acc, order) => acc + order.fills.length, 0), | ||
[filteredOrders], | ||
) | ||
|
||
return { | ||
filteredOrders, | ||
totalUnviewedFills, | ||
} | ||
} |
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