From 743cb06637de5da988a05227e6269418a11c256d Mon Sep 17 00:00:00 2001 From: sheykei Date: Mon, 16 Dec 2024 13:08:52 +0100 Subject: [PATCH] add: price util & filter out local chain --- src/context/Dapp.context.tsx | 2 +- src/utils/formatter.service.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/context/Dapp.context.tsx b/src/context/Dapp.context.tsx index 612dd28c..6098a8fa 100644 --- a/src/context/Dapp.context.tsx +++ b/src/context/Dapp.context.tsx @@ -38,7 +38,7 @@ export function DAppProvider({ }: PropsWithChildren) { return ( - + id !== 1337)} config={config}> {children} diff --git a/src/utils/formatter.service.ts b/src/utils/formatter.service.ts index e0c536b9..bce1a86c 100644 --- a/src/utils/formatter.service.ts +++ b/src/utils/formatter.service.ts @@ -13,7 +13,11 @@ export class FormatterService { } } - toNumber(value: bigint | string, decimals = 18): number { + public static toPrice(value: bigint | string, token: { price?: number | null; decimals: number }): number { + return FormatterService.toNumber(value, token.decimals) * (token.price ?? 0); + } + + public static toNumber(value: bigint | string, decimals = 18): number { const bi = BigInt(value); const fractionalPart = Number.parseFloat((bi % BigInt(10 ** decimals)).toString()) / 10 ** decimals;