mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 06:10:44 +08:00
Add WalletConnect support
Co-authored-by: Njoku Emmanuel <kalunjoku123@gmail.com> Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
co-authored by
Njoku Emmanuel
parent
767355b782
commit
400a2df0a4
+34
-7
@@ -1,23 +1,42 @@
|
||||
<script lang="ts">
|
||||
import { Connection } from "@app/session";
|
||||
import { state } from '@app/session';
|
||||
import { get } from "svelte/store";
|
||||
import { Connection, state } from "@app/session";
|
||||
import type { Err } from '@app/error';
|
||||
import Error from '@app/Error.svelte';
|
||||
import type { Config } from '@app/config';
|
||||
import ConnectWallet from "@app/components/Modal/ConnectWallet.svelte";
|
||||
|
||||
export let config: Config;
|
||||
export let caption = "Connect";
|
||||
export let className = "";
|
||||
export let style = "";
|
||||
export let config: Config;
|
||||
|
||||
let walletUnavailable = !window.ethereum;
|
||||
let error: Err | null = null;
|
||||
|
||||
const onModalClose = () => {
|
||||
const wcs = get(config.walletConnect.state);
|
||||
|
||||
if (wcs.state === "open") {
|
||||
config.walletConnect.state.set({ state: "close" });
|
||||
wcs.onClose();
|
||||
}
|
||||
};
|
||||
const onConnect = async () => {
|
||||
try {
|
||||
await state.connectWalletConnect(config);
|
||||
} catch (e) {
|
||||
walletConnectState.set({ state: "close" });
|
||||
error = e;
|
||||
}
|
||||
};
|
||||
|
||||
$: connecting = $state.connection === Connection.Connecting;
|
||||
$: walletConnectState = config.walletConnect.state;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
|
||||
<button
|
||||
on:click={() => state.connect(config)}
|
||||
on:click|stopPropagation={onConnect}
|
||||
{style}
|
||||
class="connect {className}"
|
||||
disabled={connecting || walletUnavailable}
|
||||
@@ -29,3 +48,11 @@
|
||||
{caption}
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
{#if $walletConnectState.state === "open"}
|
||||
<ConnectWallet {config} uri={$walletConnectState.uri} on:close={onModalClose} />
|
||||
{:else if error}
|
||||
<Error floating title="Wallet connection failed" {error}
|
||||
on:close={() => error = null} />
|
||||
{/if}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user