add mint
This commit is contained in:
parent
0cb006816e
commit
0b6b17f4f9
@ -11,23 +11,26 @@ import { useNavigate } from "react-router-dom";
|
|||||||
const ConnectCashu = () => {
|
const ConnectCashu = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const [config, setConfig] = useState<string>();
|
const [mintUrl, setMintUrl] = useState<string>();
|
||||||
const [error, setError] = useState<string>();
|
const [error, setError] = useState<string>();
|
||||||
|
|
||||||
async function tryConnect(config: string) {
|
async function tryConnect(config: string) {
|
||||||
try {
|
try {
|
||||||
// const connection = new CashuWallet(config);
|
if (!mintUrl) {
|
||||||
// await connection.login();
|
throw new Error("Mint URL is required");
|
||||||
// const info = await connection.getInfo();
|
}
|
||||||
// const newWallet = {
|
const connection = new CashuWallet(config);
|
||||||
// id: uuid(),
|
await connection.login();
|
||||||
// kind: WalletKind.LNDHub,
|
const info = await connection.getInfo();
|
||||||
// active: true,
|
const newWallet = {
|
||||||
// info,
|
id: uuid(),
|
||||||
// data: config,
|
kind: WalletKind.Cashu,
|
||||||
// } as WalletConfig;
|
active: true,
|
||||||
// Wallets.add(newWallet);
|
info,
|
||||||
// navigate("/wallet");
|
data: mintUrl,
|
||||||
|
} as WalletConfig;
|
||||||
|
Wallets.add(newWallet);
|
||||||
|
navigate("/wallet");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
setError((e as Error).message);
|
setError((e as Error).message);
|
||||||
@ -44,19 +47,19 @@ const ConnectCashu = () => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h4>
|
<h4>
|
||||||
<FormattedMessage defaultMessage="Enter LNDHub config" />
|
<FormattedMessage defaultMessage="Enter mint URL" />
|
||||||
</h4>
|
</h4>
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
<div className="f-grow mr10">
|
<div className="f-grow mr10">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="lndhub://username:password@lndhub.io"
|
placeholder="Mint URL"
|
||||||
className="w-max"
|
className="w-max"
|
||||||
value={config}
|
value={mintUrl}
|
||||||
onChange={e => setConfig(e.target.value)}
|
onChange={e => setMintUrl(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<AsyncButton onClick={() => tryConnect(unwrap(config))} disabled={!config}>
|
<AsyncButton onClick={() => tryConnect(unwrap(mintUrl))} disabled={!mintUrl}>
|
||||||
<FormattedMessage defaultMessage="Connect" />
|
<FormattedMessage defaultMessage="Connect" />
|
||||||
</AsyncButton>
|
</AsyncButton>
|
||||||
</div>
|
</div>
|
||||||
|
@ -14,12 +14,10 @@ import { CashuMint, CashuWallet as TheCashuWallet, getEncodedToken, Proof } from
|
|||||||
|
|
||||||
export class CashuWallet implements LNWallet {
|
export class CashuWallet implements LNWallet {
|
||||||
#mint: string;
|
#mint: string;
|
||||||
#walletPath: string;
|
|
||||||
#wallet?: TheCashuWallet;
|
#wallet?: TheCashuWallet;
|
||||||
|
|
||||||
constructor(mint: string, path: string) {
|
constructor(mint: string) {
|
||||||
this.#mint = mint;
|
this.#mint = mint;
|
||||||
this.#walletPath = path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isReady(): boolean {
|
isReady(): boolean {
|
||||||
@ -30,14 +28,15 @@ export class CashuWallet implements LNWallet {
|
|||||||
if (!this.#wallet) {
|
if (!this.#wallet) {
|
||||||
throw new WalletError(WalletErrorCode.GeneralError, "Wallet not initialized");
|
throw new WalletError(WalletErrorCode.GeneralError, "Wallet not initialized");
|
||||||
}
|
}
|
||||||
|
const keysets = await this.#wallet.mint.getKeySets();
|
||||||
return {
|
return {
|
||||||
nodePubKey: "asd",
|
nodePubKey: "asdd",
|
||||||
alias: "asd",
|
alias: "Cashu mint: " + this.#mint,
|
||||||
} as WalletInfo;
|
} as WalletInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
async login(_?: string | undefined): Promise<boolean> {
|
async login(_?: string | undefined): Promise<boolean> {
|
||||||
const m = new CashuMint(this.#mint, this.#walletPath);
|
const m = new CashuMint(this.#mint);
|
||||||
const keys = await m.getKeys();
|
const keys = await m.getKeys();
|
||||||
this.#wallet = new TheCashuWallet(keys, m);
|
this.#wallet = new TheCashuWallet(keys, m);
|
||||||
return true;
|
return true;
|
||||||
@ -58,7 +57,7 @@ export class CashuWallet implements LNWallet {
|
|||||||
throw new Error("Method not implemented.");
|
throw new Error("Method not implemented.");
|
||||||
}
|
}
|
||||||
getInvoices(): Promise<WalletInvoice[]> {
|
getInvoices(): Promise<WalletInvoice[]> {
|
||||||
throw new Error("Method not implemented.");
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import { decodeInvoice, unwrap } from "Util";
|
|||||||
import { LNCWallet } from "./LNCWallet";
|
import { LNCWallet } from "./LNCWallet";
|
||||||
import LNDHubWallet from "./LNDHub";
|
import LNDHubWallet from "./LNDHub";
|
||||||
import { NostrConnectWallet } from "./NostrWalletConnect";
|
import { NostrConnectWallet } from "./NostrWalletConnect";
|
||||||
|
import { CashuWallet } from "./Cashu";
|
||||||
import { setupWebLNWalletConfig, WebLNWallet } from "./WebLN";
|
import { setupWebLNWalletConfig, WebLNWallet } from "./WebLN";
|
||||||
|
|
||||||
export enum WalletKind {
|
export enum WalletKind {
|
||||||
@ -11,6 +12,7 @@ export enum WalletKind {
|
|||||||
LNC = 2,
|
LNC = 2,
|
||||||
WebLN = 3,
|
WebLN = 3,
|
||||||
NWC = 4,
|
NWC = 4,
|
||||||
|
Cashu = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum WalletErrorCode {
|
export enum WalletErrorCode {
|
||||||
@ -251,6 +253,9 @@ export class WalletStore {
|
|||||||
case WalletKind.NWC: {
|
case WalletKind.NWC: {
|
||||||
return new NostrConnectWallet(unwrap(cfg.data));
|
return new NostrConnectWallet(unwrap(cfg.data));
|
||||||
}
|
}
|
||||||
|
case WalletKind.Cashu: {
|
||||||
|
return new CashuWallet(unwrap(cfg.data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user