Skip to content

Commit

Permalink
feat(site): track sepolia UNO
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiserKarel authored and cor committed Oct 24, 2023
1 parent 5f71249 commit a30eb2a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
25 changes: 25 additions & 0 deletions site/src/lib/ethersSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {
connectedToSepolia,
snapInstalled,
connectedToUnion,
sepUNOAdded,
} from "./stores/wallets";
import { get } from "svelte/store";
import { MUNO_ERC20_ADDRESS } from "$lib/constants";

const SEPOLIA_CHAIN_ID = "0xaa36a7";

Expand Down Expand Up @@ -119,3 +121,26 @@ export const updateConnectedToUnion = async () => {
connectedToUnion.set(false);
}
};

export const addUnoErc = async () => {
try {
const wasAdded = await window.ethereum.request({
method: "wallet_watchAsset",
params: {
type: "ERC20",
options: {
address: MUNO_ERC20_ADDRESS, // The address of the token.
symbol: "UNO", // A ticker symbol or shorthand, up to 5 characters.
decimals: 6, // The number of decimals in the token.
image: "https://union.build/logo.svg", // A string URL of the token logo.
},
},
});

if (wasAdded) {
sepUNOAdded.set(true);
}
} catch {
sepUNOAdded.set(false);
}
};
1 change: 1 addition & 0 deletions site/src/lib/stores/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ export const metamaskInstalled: Writable<boolean> = writable(false);
export const connectedToSepolia: Writable<boolean> = writable(false);
export const snapInstalled: Writable<boolean> = writable(false);
export const connectedToUnion: Writable<boolean> = writable(false);
export const sepUNOAdded: Writable<boolean> = writable(false);
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { browser } from '$app/environment';
import { initClients, startBalanceWorkers } from '$lib/transferDemo';
import { onMount } from 'svelte';
import { metamaskInstalled, connectedToSepolia, connectedToUnion, snapInstalled } from '$lib/stores/wallets';
import { ethersSetup, connectToSepolia, updateConnectedToSepolia, connectLeapSnap, updateSnapInstalled, updateConnectedToUnion, connectToUnion } from '$lib/ethersSetup';
import { metamaskInstalled, connectedToSepolia, connectedToUnion, snapInstalled, sepUNOAdded } from '$lib/stores/wallets';
import { ethersSetup, connectToSepolia, updateConnectedToSepolia, connectLeapSnap, updateSnapInstalled, updateConnectedToUnion, connectToUnion, addUnoErc } from '$lib/ethersSetup';
import TerminalContainer from '$lib/TerminalContainer.svelte';
import DemoButton from '$lib/DemoButton.svelte';
Expand Down Expand Up @@ -61,7 +61,14 @@
<DemoButton on:click={connectToUnion}>Connect to Union in Leap 🚀</DemoButton>
</div>
{:else}
<div>✅ Connected to Union Testnet</div>
<div>✅ Connected to Union Testnet</div>
{#if !$sepUNOAdded}
<div class="mt-4">
<DemoButton on:click={addUnoErc}>Add UNO (ERC-20) 💸</DemoButton>
</div>
{:else}
<div>✅ Tracking UNO (Sepolia) </div>
{/if}
{/if}
{/if}
{/if}
Expand Down

0 comments on commit a30eb2a

Please sign in to comment.