-
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.
- Loading branch information
Showing
4 changed files
with
74 additions
and
32 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 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,52 @@ | ||
import { Exchange, Token } from "@renegade-fi/react" | ||
|
||
/** Mapping of token price statuses with text, statusColor, and priceColor. */ | ||
export const PRICE_STATUSES = { | ||
live: { | ||
text: "LIVE", | ||
statusColor: "text-green-price", | ||
priceColor: "price-green", | ||
}, | ||
stale: { | ||
text: "STALE", | ||
statusColor: "text-red-price", | ||
priceColor: "price-red", | ||
}, | ||
noData: { | ||
text: "NO DATA", | ||
statusColor: "text-muted", | ||
priceColor: "text-muted", | ||
}, | ||
unsupported: { | ||
text: "N/A", | ||
statusColor: "text-muted", | ||
priceColor: "text-muted", | ||
}, | ||
} as const | ||
|
||
/** Returns the price status based on price, staleness, mint, and exchange. */ | ||
export function getPriceStatus({ | ||
price, | ||
isStale, | ||
mint, | ||
exchange = "binance", | ||
}: { | ||
price: number | undefined | ||
isStale: boolean | ||
mint: `0x${string}` | ||
exchange?: Exchange | ||
}) { | ||
const token = Token.findByAddress(mint) | ||
const tokenSupported = token.supportedExchanges.has(exchange) | ||
|
||
if (!tokenSupported) { | ||
return PRICE_STATUSES.unsupported | ||
} | ||
if (isStale) { | ||
if (!price) { | ||
return PRICE_STATUSES.noData | ||
} | ||
return PRICE_STATUSES.stale | ||
} | ||
return PRICE_STATUSES.live | ||
} |