diff --git a/src/app/components/AllowanceMenu/index.test.tsx b/src/app/components/AllowanceMenu/index.test.tsx index 03eb195479..7474a50595 100644 --- a/src/app/components/AllowanceMenu/index.test.tsx +++ b/src/app/components/AllowanceMenu/index.test.tsx @@ -7,7 +7,7 @@ import * as SettingsContext from "~/app/context/SettingsContext"; import type { Props } from "./index"; import AllowanceMenu from "./index"; -const mockGetFiatValue = jest.fn(() => Promise.resolve("$1,22")); +const mockGetFiatValue = jest.fn(() => "$1,22"); jest.spyOn(SettingsContext, "useSettings").mockReturnValue({ settings: mockSettings, diff --git a/src/app/components/AllowanceMenu/index.tsx b/src/app/components/AllowanceMenu/index.tsx index 69671c14c1..791cce8548 100644 --- a/src/app/components/AllowanceMenu/index.tsx +++ b/src/app/components/AllowanceMenu/index.tsx @@ -38,12 +38,8 @@ function AllowanceMenu({ allowance, onEdit, onDelete }: Props) { useEffect(() => { if (budget !== "" && showFiat) { - const getFiat = async () => { - const res = await getFiatValue(budget); - setFiatAmount(res); - }; - - getFiat(); + const res = getFiatValue(budget); + setFiatAmount(res); } }, [budget, showFiat, getFiatValue]); diff --git a/src/app/context/AccountContext.tsx b/src/app/context/AccountContext.tsx index 312f1c229d..9904d74d19 100644 --- a/src/app/context/AccountContext.tsx +++ b/src/app/context/AccountContext.tsx @@ -74,8 +74,8 @@ export function AccountProvider({ children }: { children: React.ReactNode }) { const setAccountId = (id: string) => setAccount({ id }); const updateFiatValue = useCallback( - async (balance: string | number) => { - const fiat = await getFiatValue(balance); + (balance: string | number) => { + const fiat = getFiatValue(balance); setFiatBalance(fiat); }, [getFiatValue] diff --git a/src/app/context/SettingsContext.tsx b/src/app/context/SettingsContext.tsx index 8abda2026c..756219e2e0 100644 --- a/src/app/context/SettingsContext.tsx +++ b/src/app/context/SettingsContext.tsx @@ -12,7 +12,7 @@ interface SettingsContextType { settings: SettingsStorage; updateSetting: (setting: Setting) => void; isLoading: boolean; - getFiatValue: (amount: number | string) => Promise; + getFiatValue: (amount: number | string) => string; } type Setting = Partial; @@ -62,8 +62,8 @@ export const SettingsProvider = ({ }); }, [settings.currency]); - const getFiatValue = async (amount: number | string) => - await getFiatValueFunc({ + const getFiatValue = (amount: number | string) => + getFiatValueFunc({ amount, rate: currencyRate, currency: settings.currency, diff --git a/src/app/screens/ConfirmKeysend/index.test.tsx b/src/app/screens/ConfirmKeysend/index.test.tsx index 626b8878f6..94c1c742bb 100644 --- a/src/app/screens/ConfirmKeysend/index.test.tsx +++ b/src/app/screens/ConfirmKeysend/index.test.tsx @@ -13,10 +13,10 @@ jest.spyOn(SettingsContext, "useSettings").mockReturnValue({ updateSetting: jest.fn(), getFiatValue: jest .fn() - .mockImplementationOnce(() => Promise.resolve("$0.00")) - .mockImplementationOnce(() => Promise.resolve("$0.00")) - .mockImplementationOnce(() => Promise.resolve("$0.01")) - .mockImplementationOnce(() => Promise.resolve("$0.05")), + .mockImplementationOnce(() => "$0.00") + .mockImplementationOnce(() => "$0.00") + .mockImplementationOnce(() => "$0.01") + .mockImplementationOnce(() => "$0.05"), }); const mockOrigin: OriginData = { diff --git a/src/app/screens/ConfirmKeysend/index.tsx b/src/app/screens/ConfirmKeysend/index.tsx index d70d6b785b..fbd7cd1559 100644 --- a/src/app/screens/ConfirmKeysend/index.tsx +++ b/src/app/screens/ConfirmKeysend/index.tsx @@ -47,20 +47,16 @@ function ConfirmKeysend() { const [successMessage, setSuccessMessage] = useState(""); useEffect(() => { - (async () => { - if (showFiat && amount) { - const res = await getFiatValue(amount); - setFiatAmount(res); - } - })(); + if (showFiat && amount) { + const res = getFiatValue(amount); + setFiatAmount(res); + } }, [amount, showFiat, getFiatValue]); useEffect(() => { if (showFiat) { - (async () => { - const res = await getFiatValue(budget); - setFiatBudgetAmount(res); - })(); + const res = getFiatValue(budget); + setFiatBudgetAmount(res); } }, [budget, showFiat, getFiatValue]); diff --git a/src/app/screens/ConfirmPayment/index.test.tsx b/src/app/screens/ConfirmPayment/index.test.tsx index ae80177317..f7e22bfe9e 100644 --- a/src/app/screens/ConfirmPayment/index.test.tsx +++ b/src/app/screens/ConfirmPayment/index.test.tsx @@ -55,7 +55,7 @@ describe("ConfirmPayment", () => { settings: { ...mockSettings }, isLoading: false, updateSetting: jest.fn(), - getFiatValue: jest.fn(() => Promise.resolve("$0.01")), + getFiatValue: jest.fn(() => "$0.01"), }); await act(async () => { @@ -86,7 +86,7 @@ describe("ConfirmPayment", () => { settings: { ...mockSettings, showFiat: false }, isLoading: false, updateSetting: jest.fn(), - getFiatValue: jest.fn(() => Promise.resolve("$0.01")), + getFiatValue: jest.fn(() => "$0.01"), }); const user = userEvent.setup(); @@ -121,7 +121,7 @@ describe("ConfirmPayment", () => { settings: { ...mockSettings }, isLoading: false, updateSetting: jest.fn(), - getFiatValue: jest.fn(() => Promise.resolve("$0.01")), + getFiatValue: jest.fn(() => "$0.01"), }); await act(async () => { diff --git a/src/app/screens/ConfirmPayment/index.tsx b/src/app/screens/ConfirmPayment/index.tsx index 361a801c6f..d2ef18285a 100644 --- a/src/app/screens/ConfirmPayment/index.tsx +++ b/src/app/screens/ConfirmPayment/index.tsx @@ -47,21 +47,17 @@ function ConfirmPayment() { const [fiatBudgetAmount, setFiatBudgetAmount] = useState(""); useEffect(() => { - (async () => { - if (showFiat && invoice.satoshis) { - const res = await getFiatValue(invoice.satoshis); - setFiatAmount(res); - } - })(); + if (showFiat && invoice.satoshis) { + const res = getFiatValue(invoice.satoshis); + setFiatAmount(res); + } }, [invoice.satoshis, showFiat, getFiatValue]); useEffect(() => { - (async () => { - if (showFiat && budget) { - const res = await getFiatValue(budget); - setFiatBudgetAmount(res); - } - })(); + if (showFiat && budget) { + const res = getFiatValue(budget); + setFiatBudgetAmount(res); + } }, [budget, showFiat, getFiatValue]); const [rememberMe, setRememberMe] = useState(false); diff --git a/src/app/screens/Home/index.tsx b/src/app/screens/Home/index.tsx index 83ec09b311..ccb2ce60d0 100644 --- a/src/app/screens/Home/index.tsx +++ b/src/app/screens/Home/index.tsx @@ -127,9 +127,9 @@ function Home() { ), })); - for await (const payment of payments) { + for (const payment of payments) { const totalAmountFiat = settings.showFiat - ? await getFiatValue(payment.totalAmount) + ? getFiatValue(payment.totalAmount) : ""; payment.totalAmountFiat = totalAmountFiat; } @@ -172,7 +172,7 @@ function Home() { for (const invoice of invoices) { const totalAmountFiat = settings.showFiat - ? await getFiatValue(invoice.totalAmount) + ? getFiatValue(invoice.totalAmount) : ""; invoice.totalAmountFiat = totalAmountFiat; } diff --git a/src/app/screens/LNURLPay/index.test.tsx b/src/app/screens/LNURLPay/index.test.tsx index b5d6b22517..c6d95481c3 100644 --- a/src/app/screens/LNURLPay/index.test.tsx +++ b/src/app/screens/LNURLPay/index.test.tsx @@ -6,7 +6,7 @@ import type { LNURLDetails, OriginData } from "~/types"; import LNURLPay from "./index"; -const mockGetFiatValue = jest.fn(() => Promise.resolve("$1,22")); +const mockGetFiatValue = jest.fn(() => "$1,22"); jest.spyOn(SettingsContext, "useSettings").mockReturnValue({ settings: mockSettings, diff --git a/src/app/screens/LNURLPay/index.tsx b/src/app/screens/LNURLPay/index.tsx index d721f753f5..56d41efceb 100644 --- a/src/app/screens/LNURLPay/index.tsx +++ b/src/app/screens/LNURLPay/index.tsx @@ -65,12 +65,8 @@ function LNURLPay() { useEffect(() => { if (valueSat !== "" && showFiat) { - const getFiat = async () => { - const res = await getFiatValue(valueSat); - setFiatValue(res); - }; - - getFiat(); + const res = getFiatValue(valueSat); + setFiatValue(res); } }, [valueSat, showFiat, getFiatValue]); diff --git a/src/app/screens/LNURLWithdraw/index.test.tsx b/src/app/screens/LNURLWithdraw/index.test.tsx index bcc0aff849..8eb5d85623 100644 --- a/src/app/screens/LNURLWithdraw/index.test.tsx +++ b/src/app/screens/LNURLWithdraw/index.test.tsx @@ -114,14 +114,14 @@ describe("LNURLWithdraw", () => { }); test("show error-reason on error-status", async () => { - (useNavigationState as jest.Mock).mockReturnValueOnce({ + (useNavigationState as jest.Mock).mockReturnValue({ origin: mockOrigin, args: { lnurlDetails: mockDetailsLnBits, }, }); - (makeInvoice as jest.Mock).mockReturnValueOnce({ + (makeInvoice as jest.Mock).mockReturnValue({ invoice: { paymentRequest: "lnbc100n1p3s975dpp508vpywcj857rxc78mrwpurhulzxe7slkdqdxsjzyrs3wv9jvsaksdqdwehh2cmgv4e8xcqzpgxqyz5vqsp5vpdqeutqqrwn4eq62a6agmnp3t7rru0asfgy23kcsr6k0tftfxfs9qyyssqf8zxtm0hm5veepjk4kz2ejegkg9449k4e9g5jz25mne096x6k4ajav0afdyx4uw883nv5jdy95w4ltfrfs4hes83j7zh50ygl8w3xxcqf0nhz8", diff --git a/src/app/screens/LNURLWithdraw/index.tsx b/src/app/screens/LNURLWithdraw/index.tsx index f5398755b3..e23d3919e1 100644 --- a/src/app/screens/LNURLWithdraw/index.tsx +++ b/src/app/screens/LNURLWithdraw/index.tsx @@ -44,10 +44,8 @@ function LNURLWithdraw() { useEffect(() => { if (valueSat !== "" && showFiat) { - (async () => { - const res = await getFiatValue(valueSat); - setFiatValue(res); - })(); + const res = getFiatValue(valueSat); + setFiatValue(res); } }, [valueSat, showFiat, getFiatValue]); diff --git a/src/app/screens/Publisher.tsx b/src/app/screens/Publisher.tsx index 882e08a25f..d8abb093de 100644 --- a/src/app/screens/Publisher.tsx +++ b/src/app/screens/Publisher.tsx @@ -83,9 +83,9 @@ function Publisher() { ), }; }); - for await (const payment of payments) { + for (const payment of payments) { const totalAmountFiat = settings.showFiat - ? await getFiatValue(payment.totalAmount) + ? getFiatValue(payment.totalAmount) : ""; payment.totalAmountFiat = totalAmountFiat; } diff --git a/src/app/screens/Receive/index.tsx b/src/app/screens/Receive/index.tsx index daaae5e94f..9a18d70788 100644 --- a/src/app/screens/Receive/index.tsx +++ b/src/app/screens/Receive/index.tsx @@ -63,10 +63,8 @@ function Receive() { useEffect(() => { if (formData.amount !== "" && showFiat) { - (async () => { - const res = await getFiatValue(formData.amount); - setFiatAmount(res); - })(); + const res = getFiatValue(formData.amount); + setFiatAmount(res); } }, [formData, showFiat, getFiatValue]); diff --git a/src/common/utils/__tests__/currencyConvert.test.ts b/src/common/utils/__tests__/currencyConvert.test.ts index 4681fb2230..3ee85c04fd 100644 --- a/src/common/utils/__tests__/currencyConvert.test.ts +++ b/src/common/utils/__tests__/currencyConvert.test.ts @@ -3,8 +3,8 @@ import { CURRENCIES } from "~/common/constants"; import { getFiatValue, getSatValue } from "../currencyConvert"; describe("Currency coversion utils", () => { - test("getFiatValue", async () => { - const result = await getFiatValue({ + test("getFiatValue", () => { + const result = getFiatValue({ amount: 123456789, rate: 0.00029991836, currency: CURRENCIES["USD"], diff --git a/src/common/utils/currencyConvert.ts b/src/common/utils/currencyConvert.ts index 0ee75c1909..df92759802 100644 --- a/src/common/utils/currencyConvert.ts +++ b/src/common/utils/currencyConvert.ts @@ -3,22 +3,7 @@ */ import type { CURRENCIES } from "../constants"; -const satsToFiat = async (amount: number | string, rate: number) => { - return Number(amount) * rate; -}; - -const satoshisToFiat = async ({ - amountInSats, - rate, -}: { - amountInSats: number | string; - rate: number; -}) => { - const fiat = await satsToFiat(amountInSats, rate); - return fiat; -}; - -export const getFiatValue = async ({ +export const getFiatValue = ({ amount, rate, currency, @@ -27,10 +12,7 @@ export const getFiatValue = async ({ rate: number; currency: CURRENCIES; }) => { - const fiatValue = await satoshisToFiat({ - amountInSats: amount, - rate, - }); + const fiatValue = Number(amount) * rate; return fiatValue.toLocaleString("en", { style: "currency", diff --git a/src/extension/background-script/events/notifications.ts b/src/extension/background-script/events/notifications.ts index 248c3f7104..eeab3be524 100644 --- a/src/extension/background-script/events/notifications.ts +++ b/src/extension/background-script/events/notifications.ts @@ -30,7 +30,7 @@ const paymentSuccessNotification = async ( if (showFiat) { const rate = await getCurrencyRateWithCache(currency); - paymentAmountFiatLocale = await getFiatValue({ + paymentAmountFiatLocale = getFiatValue({ amount: paymentAmount, rate, currency,