- {assetPrice >= 0.01 ? usdFormatter.format(assetPrice) : `$${assetPrice.toExponential(2)}`}
+ {/* {assetPrice >= 0.01 ? usdFormatter.format(assetPrice) : `$${assetPrice.toExponential(2)}`} */}
+ {assetPrice >= 1
+ ? usdFormatter.format(assetPrice)
+ : assetPrice >= 0.0000001
+ ? `$${dynamicNumeralFormatter(assetPrice, {
+ minDisplay: 0.0000001,
+ tokenPrice: assetPrice,
+ forceDecimals: true,
+ })}`
+ : `$${assetPrice.toExponential(2)}`}
{assetPriceOffset > assetPrice * 0.1 && (
diff --git a/apps/marginfi-v2-ui/src/pages/api/oracle/price.ts b/apps/marginfi-v2-ui/src/pages/api/oracle/price.ts
index 5ec7625c13..054862a350 100644
--- a/apps/marginfi-v2-ui/src/pages/api/oracle/price.ts
+++ b/apps/marginfi-v2-ui/src/pages/api/oracle/price.ts
@@ -432,7 +432,7 @@ async function fetchMultiPrice(tokens: string[]): Promise
? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
: process.env.VERCEL_BRANCH_URL
? `https://${process.env.VERCEL_BRANCH_URL}`
- : "localhost:3004";
+ : "http://localhost:3004";
const response = await fetch(`${baseUrl}/api/tokens/multi?mintList=${tokens.join(",")}`, {
signal: controller.signal,
@@ -440,8 +440,13 @@ async function fetchMultiPrice(tokens: string[]): Promise
clearTimeout(timeoutId);
const data = (await response.json()) as BirdeyePriceResponse;
+
+ if (!data || !data.success) {
+ throw new Error("Error fetching birdeye prices");
+ }
+
return data;
} catch (error) {
- throw new Error("Error fetching birdey prices");
+ throw new Error("Error fetching birdeye prices");
}
}
diff --git a/apps/marginfi-v2-ui/src/pages/api/tokens/multi.ts b/apps/marginfi-v2-ui/src/pages/api/tokens/multi.ts
index 0efb73f327..88de0bf629 100644
--- a/apps/marginfi-v2-ui/src/pages/api/tokens/multi.ts
+++ b/apps/marginfi-v2-ui/src/pages/api/tokens/multi.ts
@@ -96,7 +96,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
const data = await response.json();
- // cache for 20 minutes
+ if (!data || !data.data) {
+ console.log("data not found");
+ return res.status(404).json({
+ error: "Birdeye API error: data not found",
+ });
+ }
+
+ // cache for 20 minutes (1200 seconds)
res.setHeader("Cache-Control", "s-maxage=1200, stale-while-revalidate=300");
res.status(200).json(data);
} catch (error) {
diff --git a/packages/mrgn-common/src/utils/formatters.utils.ts b/packages/mrgn-common/src/utils/formatters.utils.ts
index f32a7ad498..c49148397a 100644
--- a/packages/mrgn-common/src/utils/formatters.utils.ts
+++ b/packages/mrgn-common/src/utils/formatters.utils.ts
@@ -31,10 +31,11 @@ const numeralFormatter = (value: number) => {
interface dynamicNumeralFormatterOptions {
minDisplay?: number;
tokenPrice?: number;
+ forceDecimals?: boolean;
}
export const dynamicNumeralFormatter = (value: number, options: dynamicNumeralFormatterOptions = {}) => {
- const { minDisplay = 0.00001, tokenPrice } = options;
+ const { minDisplay = 0.00001, tokenPrice, forceDecimals } = options;
if (value === 0) return "0";
@@ -43,11 +44,11 @@ export const dynamicNumeralFormatter = (value: number, options: dynamicNumeralFo
}
if (Math.abs(value) > 10000) {
- return numeral(value).format("0,0.[00]a");
+ return numeral(value).format(forceDecimals ? "0,0.00a" : "0,0.[00]a");
}
if (Math.abs(value) >= 0.01) {
- return numeral(value).format("0,0.[0000]a");
+ return numeral(value).format(forceDecimals ? "0,0.00a" : "0,0.[0000]a");
}
if (tokenPrice) {