wip: migrate to desktop2

This commit is contained in:
2024-02-12 09:08:35 +07:00
parent c809ab6b4e
commit 1950cb59a2
25 changed files with 347 additions and 51 deletions

View File

@@ -1,20 +1,35 @@
import { type CurrentAccount, Event, Metadata } from "@lume/types";
import { type CurrentAccount, Event, Keys, Metadata } from "@lume/types";
import { invoke } from "@tauri-apps/api/core";
export class Ark {
public account: CurrentAccount;
constructor() {
this.account = { pubkey: "" };
this.account = { npub: "" };
}
public async verify_signer() {
public async load_account() {
try {
const cmd: string = await invoke("verify_signer");
const cmd: string = await invoke("load_account");
if (cmd) {
this.account.pubkey = cmd;
this.account.npub = cmd;
}
} catch (e) {
console.error(String(e));
}
}
public async save_account(keys: Keys) {
try {
const cmd: boolean = await invoke("save_key", { nsec: keys.nsec });
if (cmd) {
await invoke("update_signer", { nsec: keys.nsec });
this.account.npub = keys.npub;
return true;
}
return false;
} catch (e) {
console.error(String(e));

View File

@@ -1,10 +1,21 @@
import { PropsWithChildren, createContext, useContext, useMemo } from "react";
import {
PropsWithChildren,
createContext,
useContext,
useEffect,
useMemo,
} from "react";
import { Ark } from "./ark";
export const ArkContext = createContext<Ark>(undefined);
export const ArkProvider = ({ children }: PropsWithChildren<object>) => {
const ark = useMemo(() => new Ark(), []);
useEffect(() => {
if (ark) ark.load_account();
}, []);
return <ArkContext.Provider value={ark}>{children}</ArkContext.Provider>;
};