Skip to content

Commit

Permalink
Rollback yoctosToUsdWithFallback
Browse files Browse the repository at this point in the history
  • Loading branch information
carina-akaia committed Jun 21, 2024
1 parent 73de04c commit 8b7e272
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/app/_components/DonationStats.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";

import { getConfig } from "@/common/contracts/potlock/donate";
import { yoctosToUsdWithFallback } from "@/modules/core";
import { yoctosToUsdWithFallback } from "@/common/lib/yoctosToUsdWithFallback";

const DonationStats = () => {
const [donateConfig, setDonateConfig] = useState({
Expand Down
19 changes: 19 additions & 0 deletions src/common/lib/yoctosToUsdWithFallback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Big from "big.js";

import formatWithCommas from "@/common/lib/formatWithCommas";
import { fetchNearPrice } from "@/common/services";

export const yoctosToUsdWithFallback = async (
amountYoctos: string,
abbreviate?: boolean,
): Promise<string> => {
const nearToUsd = await fetchNearPrice();

if (nearToUsd === undefined) return "Error loading price";

return nearToUsd
? "~$" +
formatWithCommas(Big(amountYoctos).mul(nearToUsd).div(1e24).toFixed(2))
: formatWithCommas(Big(amountYoctos).div(1e24).toFixed(2)) +
(abbreviate ? "N" : " NEAR");
};
19 changes: 0 additions & 19 deletions src/modules/core/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
import Big from "big.js";

import { NearBalanceResponse } from "@/common/api/pagoda";
import { bigNumToFloat } from "@/common/lib";
import formatWithCommas from "@/common/lib/formatWithCommas";
import { fetchNearPrice } from "@/common/services";

export const yoctosToUsdWithFallback = async (
amountYoctos: string,
abbreviate?: boolean,
): Promise<string> => {
const nearToUsd = await fetchNearPrice();

if (nearToUsd === undefined) return "Error loading price";

return nearToUsd
? "~$" +
formatWithCommas(Big(amountYoctos).mul(nearToUsd).div(1e24).toFixed(2))
: formatWithCommas(Big(amountYoctos).div(1e24).toFixed(2)) +
(abbreviate ? "N" : " NEAR");
};

export const balanceToFloat = (
amount: NearBalanceResponse["balance"]["amount"],
Expand Down
7 changes: 3 additions & 4 deletions src/modules/profile/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import {
NEARSocialUserProfile,
getSocialProfile,
} from "@/common/contracts/social";
import { yoctosToUsdWithFallback } from "@/modules/core";

import { fetchSocialImages } from "../core/services/socialImages";
import { yoctosToUsdWithFallback } from "@/common/lib/yoctosToUsdWithFallback";
import { fetchSocialImages } from "@/modules/core/services/socialImages";
import {
getTagsFromSocialProfileData,
getTeamMembersFromProfile,
getTotalAmountNear,
} from "../project/utils";
} from "@/modules/project/utils";

export type Profile = {
socialData: NEARSocialUserProfile;
Expand Down

0 comments on commit 8b7e272

Please sign in to comment.