From 8b7e2727078942aa6bc918810420d0881f40c5e8 Mon Sep 17 00:00:00 2001 From: "Carina.Akaia.io" Date: Fri, 21 Jun 2024 07:19:33 +0400 Subject: [PATCH] Rollback yoctosToUsdWithFallback --- src/app/_components/DonationStats.tsx | 2 +- src/common/lib/yoctosToUsdWithFallback.ts | 19 +++++++++++++++++++ src/modules/core/utils/index.ts | 19 ------------------- src/modules/profile/models.ts | 7 +++---- 4 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 src/common/lib/yoctosToUsdWithFallback.ts diff --git a/src/app/_components/DonationStats.tsx b/src/app/_components/DonationStats.tsx index b7b5a6b5..a80a8e20 100644 --- a/src/app/_components/DonationStats.tsx +++ b/src/app/_components/DonationStats.tsx @@ -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({ diff --git a/src/common/lib/yoctosToUsdWithFallback.ts b/src/common/lib/yoctosToUsdWithFallback.ts new file mode 100644 index 00000000..761b730c --- /dev/null +++ b/src/common/lib/yoctosToUsdWithFallback.ts @@ -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 => { + 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"); +}; diff --git a/src/modules/core/utils/index.ts b/src/modules/core/utils/index.ts index c989ec1c..8eaad8f9 100644 --- a/src/modules/core/utils/index.ts +++ b/src/modules/core/utils/index.ts @@ -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 => { - 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"], diff --git a/src/modules/profile/models.ts b/src/modules/profile/models.ts index fb0c026c..5db9e2e1 100644 --- a/src/modules/profile/models.ts +++ b/src/modules/profile/models.ts @@ -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;