Skip to content

Commit

Permalink
feat(site): send uno to ethereum state management
Browse files Browse the repository at this point in the history
  • Loading branch information
cor committed Oct 18, 2023
1 parent 6301325 commit e77eabc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
9 changes: 4 additions & 5 deletions site/src/lib/transferDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,11 @@ export const startBalanceWorkers = () => {
};

export const toFixedPoint = (value: bigint, decimals: number) => {
let right = BigInt(value) % BigInt(10**decimals);
let right = BigInt(value) % BigInt(10 ** decimals);
let left = BigInt(value) - right;

return left.toString()
.concat(".", right.toString().padStart(decimals, "0"))
}
return left.toString().concat('.', right.toString().padStart(decimals, '0'));
};

export const updateUnionUnoBalance = async () => {
const sgClient = get(stargateClient);
Expand Down Expand Up @@ -179,7 +178,7 @@ export const sendUnoToEthereum = async () => {
return;
}

await cwClient.execute(
return cwClient.execute(
uAccount.address,
UCS01_RELAY_CONTRACT,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,52 @@
import DemoButton from "$lib/DemoButton.svelte";
import { sendUnoToEthereum } from "$lib/transferDemo";
import TerminalContainer from "$lib/TerminalContainer.svelte";
import { sendingUnoToEthereum } from './demoStore';
import PulseSpinner from "$lib/PulseSpinner.svelte";
import type { ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { ethereumEthBalance, ethereumUnoBalance } from "$lib/stores/wallets";
import { get } from "svelte/store";
const clickHandler = async () => {
sendingUnoToEthereum.set('sending');
let result: ExecuteResult | undefined = undefined;
try {
result = await sendUnoToEthereum();
} catch {
sendingUnoToEthereum.set('start');
}
if (result === undefined) {
return;
}
const currentEthereumUnoBalance = get(ethereumUnoBalance);
ethereumUnoBalance.subscribe((balance) => {
if (balance > currentEthereumUnoBalance) {
sendingUnoToEthereum.set('done');
}
});
};
</script>

<TerminalContainer>
<DemoButton on:click={sendUnoToEthereum}>Send UNO to Ethereum</DemoButton>
{#if $ethereumUnoBalance === null}
<div>Complete the previous steps to continue</div>
{:else}
{#if $sendingUnoToEthereum === 'sending'}
<div class="flex gap-4 h-[48px] items-center">
<div>Sending UNO to Ethereum</div>
<PulseSpinner/>
</div>
{:else if $sendingUnoToEthereum === 'start'}
<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>

{/if}
{/if}
</TerminalContainer>
4 changes: 4 additions & 0 deletions site/src/routes/blog/start-of-the-endgame/demoStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { writable } from 'svelte/store';
import type { Writable } from 'svelte/store';

export const sendingUnoToEthereum: Writable<'start' | 'sending' | 'done'> = writable('start');

0 comments on commit e77eabc

Please sign in to comment.