diff --git a/src/lib/wallet/adapters/index.ts b/src/lib/wallet/adapters/index.ts index bf5d351..41d938d 100644 --- a/src/lib/wallet/adapters/index.ts +++ b/src/lib/wallet/adapters/index.ts @@ -23,12 +23,15 @@ export async function adapterToIWallet(adapter: WalletAdapter): Promise(null); + +export class ReadOnly implements ISigner { + private constructor(private acc: AccountData) { } + + public static async connect(chain: string): Promise { + const address = get(readonlySignerAddress); + if (!address) throw new Error("Readonly Signer Address is null"); + //TODO: Missing wallet input from user + const account: AccountData = { + address, + pubkey: { type: '', value: '' } + } + + return new ReadOnly(account); + } + public disconnect() { /* noop */ } + + public static metadata: WalletMetadata = { + adapter: WalletAdapter.Readonly, + name: 'Read Only', + logo: Eye, + canSign: false, + } + + public getMetadata(): WalletMetadata { return ReadOnly.metadata; } + + public static async isInstalled(): Promise { return true; } + + public account(): AccountData { return this.acc; } + + public async sign(_client: TendermintClient, _msgs: EncodeObject[], _fee: StdFee, _memo?: string | undefined): Promise { + throw new Error("Readonly signer cannot sign"); + } +} diff --git a/src/lib/wallet/adapters/types.ts b/src/lib/wallet/adapters/types.ts index eeb65e3..ce502b2 100644 --- a/src/lib/wallet/adapters/types.ts +++ b/src/lib/wallet/adapters/types.ts @@ -8,6 +8,7 @@ import type { XDefi } from "./xdefi"; import type { StdFee } from "@cosmjs/stargate"; import type { TendermintClient } from "@cosmjs/tendermint-rpc"; import type { Pubkey } from "@cosmjs/amino"; +import type { ReadOnly } from "./readonly"; export interface AccountData { address: string; @@ -43,7 +44,7 @@ type ISignerStatic = { isInstalled(): Promise; metadata: WalletMetadata; }; -export type Connectable = ISignerStatic | ISignerStatic | ISignerStatic | ISignerStatic | ISignerStatic | ISignerStatic; +export type Connectable = ISignerStatic | ISignerStatic | ISignerStatic | ISignerStatic | ISignerStatic | ISignerStatic | ISignerStatic; export interface ISigner { disconnect: () => void; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 3441def..e0119f6 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -8,6 +8,7 @@ import { TxStep, broadcastTx, simulate } from "$lib/helpers/transaction"; import { writable } from "svelte/store"; import type { EncodeObject } from "@cosmjs/proto-signing"; + import { readonlySignerAddress } from "$lib/wallet/adapters/readonly"; const status = writable(TxStep.None); @@ -64,8 +65,9 @@

WalletWidget

A component to allow the user to connect their wallet.

-
+
+

Example Transaction