From a9e408df94c08da6f37b19d139bbde4e97888648 Mon Sep 17 00:00:00 2001 From: Connor Davis <17688291+PoisonPhang@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:28:38 -0500 Subject: [PATCH] feat(site): format more balanced --- site/src/lib/format.ts | 6 ++++++ site/src/lib/transferDemo.ts | 7 ------- .../routes/blog/start-of-the-endgame/FaucetButton.svelte | 3 ++- .../blog/start-of-the-endgame/TransferUnoToEthereum.svelte | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 site/src/lib/format.ts diff --git a/site/src/lib/format.ts b/site/src/lib/format.ts new file mode 100644 index 0000000000..29e24a36b6 --- /dev/null +++ b/site/src/lib/format.ts @@ -0,0 +1,6 @@ +export const toFixedPoint = (value: bigint, decimals: number) => { + let right = BigInt(value) % BigInt(10 ** decimals); + let left = BigInt(value) - right; + + return left.toString().concat('.', right.toString().padStart(decimals, '0')); +}; diff --git a/site/src/lib/transferDemo.ts b/site/src/lib/transferDemo.ts index 25858f5568..6f3b8b8954 100644 --- a/site/src/lib/transferDemo.ts +++ b/site/src/lib/transferDemo.ts @@ -123,13 +123,6 @@ export const startBalanceWorkers = () => { balanceWorker(updateUnionUnoBalance, 2000); }; -export const toFixedPoint = (value: bigint, decimals: number) => { - let right = BigInt(value) % BigInt(10 ** decimals); - let left = BigInt(value) - right; - - return left.toString().concat('.', right.toString().padStart(decimals, '0')); -}; - export const updateUnionUnoBalance = async () => { const sgClient = get(stargateClient); const uAccount = get(unionAccount); diff --git a/site/src/routes/blog/start-of-the-endgame/FaucetButton.svelte b/site/src/routes/blog/start-of-the-endgame/FaucetButton.svelte index 2d68362b70..b0316f0778 100644 --- a/site/src/routes/blog/start-of-the-endgame/FaucetButton.svelte +++ b/site/src/routes/blog/start-of-the-endgame/FaucetButton.svelte @@ -8,6 +8,7 @@ import { connectedToUnion } from "$lib/stores/wallets"; import { unionUnoBalance } from "$lib/stores/wallets"; import AddressesAndBalances from "./AddressesAndBalances.svelte"; + import { toFixedPoint } from "$lib/format"; let loading: Writable = writable(false); let fetchedFromFaucet: Writable = writable(false); @@ -41,7 +42,7 @@ {:else if $fetchedFromFaucet}
-
✅ Received UNO from faucet, new balance is {$unionUnoBalance.amount}
+
✅ Received UNO from faucet, new balance is {toFixedPoint(BigInt($unionUnoBalance.amount), 6)}
{:else} Get UNO from faucet diff --git a/site/src/routes/blog/start-of-the-endgame/TransferUnoToEthereum.svelte b/site/src/routes/blog/start-of-the-endgame/TransferUnoToEthereum.svelte index 1198a3e6c9..f47e6dbc18 100644 --- a/site/src/routes/blog/start-of-the-endgame/TransferUnoToEthereum.svelte +++ b/site/src/routes/blog/start-of-the-endgame/TransferUnoToEthereum.svelte @@ -8,6 +8,7 @@ import type { ExecuteResult } from "@cosmjs/cosmwasm-stargate"; import { ethereumEthBalance, ethereumUnoBalance } from "$lib/stores/wallets"; import { get } from "svelte/store"; + import { toFixedPoint } from "$lib/format"; const clickHandler = async () => { sendingUnoToEthereum.set('sending'); @@ -52,7 +53,7 @@ Send UNO to Ethereum {:else if $sendingUnoToEthereum === 'done'}
-
✅ Received UNO on Sepolia, new balance is {$ethereumUnoBalance}muno
+
✅ Received UNO on Sepolia, new balance is {toFixedPoint($ethereumUnoBalance, 6)}UNO
{/if}