Skip to content

Commit

Permalink
feat(site): format more balanced
Browse files Browse the repository at this point in the history
  • Loading branch information
PoisonPhang authored and cor committed Oct 18, 2023
1 parent acfd7a5 commit a9e408d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
6 changes: 6 additions & 0 deletions site/src/lib/format.ts
Original file line number Diff line number Diff line change
@@ -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'));
};
7 changes: 0 additions & 7 deletions site/src/lib/transferDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> = writable(false);
let fetchedFromFaucet: Writable<boolean> = writable(false);
Expand Down Expand Up @@ -41,7 +42,7 @@
</div>
{:else if $fetchedFromFaucet}
<div class="flex gap-4 h-[48px] items-center">
<div>✅ Received UNO from faucet, new balance is <span class="text-accent">{$unionUnoBalance.amount}</span></div>
<div>✅ Received UNO from faucet, new balance is <span class="text-accent">{toFixedPoint(BigInt($unionUnoBalance.amount), 6)}</span></div>
</div>
{:else}
<DemoButton on:click={clickHandler}>Get UNO from faucet</DemoButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -52,7 +53,7 @@
<DemoButton on:click={clickHandler}>Send UNO to Ethereum</DemoButton>
{:else if $sendingUnoToEthereum === 'done'}
<div class="flex gap-4 h-[48px] items-center">
<div>✅ Received UNO on Sepolia, new balance is <span class="text-accent">{$ethereumUnoBalance}</span>muno</div>
<div>✅ Received UNO on Sepolia, new balance is <span class="text-accent">{toFixedPoint($ethereumUnoBalance, 6)}</span>UNO</div>
</div>

{/if}
Expand Down

0 comments on commit a9e408d

Please sign in to comment.