wip: migrate to desktop2
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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>;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import { type VListHandle } from "virtua";
|
||||
import { LumeStorage } from "./storage";
|
||||
|
||||
const platformName = await platform();
|
||||
const osLocale = await locale();
|
||||
const osLocale = (await locale()).slice(0, 2);
|
||||
|
||||
const store = new Store("lume.dat");
|
||||
const storage = new LumeStorage(store, platformName, osLocale);
|
||||
|
||||
3
packages/types/index.d.ts
vendored
3
packages/types/index.d.ts
vendored
@@ -55,8 +55,7 @@ export interface Metadata {
|
||||
}
|
||||
|
||||
export interface CurrentAccount {
|
||||
pubkey: string;
|
||||
npub?: string;
|
||||
npub: string;
|
||||
contacts?: string[];
|
||||
interests?: Interests;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user