Skip to content

Commit

Permalink
feat(site): added fixed point formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
PoisonPhang authored and cor committed Oct 18, 2023
1 parent fee22b4 commit 60bbb4b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion site/src/lib/stores/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const ethereumAddress: Writable<string | null> = writable(null);
export const cosmwasmClient: Writable<SigningCosmWasmClient | null> = writable(null);
export const unionUnoBalance: Writable<Coin | null> = writable(null);
export const ethereumEthBalance: Writable<bigint | null> = writable(null);
export const ethereumUnoBalance: Writable<any | null> = writable(null);
export const ethereumUnoBalance: Writable<bigint | null> = writable(null);
export const metamaskInstalled: Writable<boolean> = writable(false);
export const connectedToSepolia: Writable<boolean> = writable(false);
export const snapInstalled: Writable<boolean> = writable(false);
Expand Down
8 changes: 8 additions & 0 deletions site/src/lib/transferDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ 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
@@ -1,7 +1,7 @@
<script lang="ts">
import { sendUnoToUnion } from '$lib/transferFromSepolia';
import { unionAccount, unionUnoBalance, ethereumEthBalance, ethereumAddress, ethereumUnoBalance } from '$lib/stores/wallets';
import { getUnoFromFaucet, sendUnoToUnionAddress, sendUnoToEthereum } from '$lib/transferDemo';
import { getUnoFromFaucet, sendUnoToUnionAddress, sendUnoToEthereum, toFixedPoint } from '$lib/transferDemo';
import TerminalContainer from '$lib/TerminalContainer.svelte';
</script>

Expand All @@ -15,19 +15,19 @@ import TerminalContainer from '$lib/TerminalContainer.svelte';
{#if $unionUnoBalance === null}
<div>Fetching Union Balance...</div>
{:else}
<div>Union UNO Balance: <span class="text-accent">{$unionUnoBalance.amount}</span> {$unionUnoBalance.denom}</div>
<div>Union UNO Balance: <span class="text-accent">{toFixedPoint(BigInt($unionUnoBalance.amount), 6)}</span> UNO</div>
{/if}

{#if $ethereumEthBalance === null}
<div>Fetching Ethereum Balance...</div>
{:else}
<div>Ethereum ETH Balance: <span class="text-accent">{$ethereumEthBalance}</span> wei</div>
<div>Ethereum ETH Balance: <span class="text-accent">{toFixedPoint($ethereumEthBalance, 18)}</span> ETH</div>
{/if}

{#if $ethereumUnoBalance === null}
<div>Fetching Ethereum UNOBalance...</div>
{:else}
<div>Ethereum UNO Balance: <span class="text-accent">{$ethereumUnoBalance}</span> muno</div>
<div>Ethereum UNO Balance: <span class="text-accent">{toFixedPoint($ethereumUnoBalance, 6)}</span> UNO</div>
{/if}

<!--
Expand Down

0 comments on commit 60bbb4b

Please sign in to comment.