chore: fixes

This commit is contained in:
2024-04-11 14:42:34 +01:00
parent 27a111466a
commit 93ea3e8e80
9 changed files with 23 additions and 15 deletions

View File

@ -2,6 +2,7 @@
"name": "@snort/app", "name": "@snort/app",
"version": "0.2.0", "version": "0.2.0",
"dependencies": { "dependencies": {
"@cashu/cashu-ts": "^1.0.0-rc.3",
"@here/maps-api-for-javascript": "^1.50.0", "@here/maps-api-for-javascript": "^1.50.0",
"@noble/curves": "^1.0.0", "@noble/curves": "^1.0.0",
"@noble/hashes": "^1.3.3", "@noble/hashes": "^1.3.3",

View File

@ -1,5 +1,5 @@
import { LNWallet } from "@snort/wallet"; import { LNWallet } from "@snort/wallet";
import React, { ReactNode } from "react"; import { ReactNode } from "react";
import { FormattedMessage } from "react-intl"; import { FormattedMessage } from "react-intl";
import Copy from "@/Components/Copy/Copy"; import Copy from "@/Components/Copy/Copy";

View File

@ -5,10 +5,10 @@ import { useNavigate } from "react-router-dom";
import LndLogo from "@/assets/img/lnd-logo.png"; import LndLogo from "@/assets/img/lnd-logo.png";
import AlbyIcon from "@/Components/Icons/Alby"; import AlbyIcon from "@/Components/Icons/Alby";
import BlueWallet from "@/Components/Icons/BlueWallet"; import BlueWallet from "@/Components/Icons/BlueWallet";
import CashuIcon from "@/Components/Icons/Cashu";
import Icon from "@/Components/Icons/Icon"; import Icon from "@/Components/Icons/Icon";
import NostrIcon from "@/Components/Icons/Nostrich"; import NostrIcon from "@/Components/Icons/Nostrich";
import { getAlbyOAuth } from "@/Pages/settings/wallet/utils"; import { getAlbyOAuth } from "@/Pages/settings/wallet/utils";
import CashuIcon from "@/Components/Icons/Cashu";
const WalletRow = (props: { const WalletRow = (props: {
logo: ReactNode; logo: ReactNode;

View File

@ -2,7 +2,7 @@ import { RouteObject } from "react-router-dom";
import WalletSettings from "../WalletSettings"; import WalletSettings from "../WalletSettings";
import AlbyOAuth from "./Alby"; import AlbyOAuth from "./Alby";
import ConnectCashu from "./Cashu"; //import ConnectCashu from "./Cashu";
import ConnectLNC from "./LNC"; import ConnectLNC from "./LNC";
import ConnectLNDHub from "./LNDHub"; import ConnectLNDHub from "./LNDHub";
import ConnectNostrWallet from "./NWC"; import ConnectNostrWallet from "./NWC";
@ -24,10 +24,10 @@ export const WalletSettingsRoutes = [
path: "/settings/wallet/nwc", path: "/settings/wallet/nwc",
element: <ConnectNostrWallet />, element: <ConnectNostrWallet />,
}, },
{ /*{
path: "/settings/wallet/cashu", path: "/settings/wallet/cashu",
element: <ConnectCashu />, element: <ConnectCashu />,
}, },*/
{ {
path: "/settings/wallet/alby", path: "/settings/wallet/alby",
element: <AlbyOAuth />, element: <AlbyOAuth />,

View File

@ -51,8 +51,10 @@ export class WalletStore extends ExternalStore<WalletStoreSnapshot> {
if (w) { if (w) {
if ("then" in w) { if ("then" in w) {
w.then(async wx => { w.then(async wx => {
this.#instance.set(activeConfig.id, wx); if (wx) {
this.notifyChange(); this.#instance.set(activeConfig.id, wx);
this.notifyChange();
}
}); });
return undefined; return undefined;
} else { } else {
@ -116,8 +118,8 @@ export class WalletStore extends ExternalStore<WalletStoreSnapshot> {
} as WalletStoreSnapshot; } as WalletStoreSnapshot;
} }
#activateWallet(cfg: WalletConfig): LNWallet | Promise<LNWallet> | undefined { async #activateWallet(cfg: WalletConfig) {
const w = loadWallet(cfg.kind, cfg.data); const w = await loadWallet(cfg.kind, cfg.data);
if (w) { if (w) {
w.on("change", d => this.#onWalletChange(cfg, d)); w.on("change", d => this.#onWalletChange(cfg, d));
} }

View File

@ -1,13 +1,13 @@
import { decodeInvoice, unwrap } from "@snort/shared"; import { decodeInvoice, unwrap } from "@snort/shared";
import AlbyWallet from "./AlbyWallet"; import AlbyWallet from "./AlbyWallet";
import { CashuWallet } from "./Cashu"; //import { CashuWallet } from "./Cashu";
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 { WebLNWallet } from "./WebLN"; import { WebLNWallet } from "./WebLN";
import EventEmitter from "eventemitter3"; import EventEmitter from "eventemitter3";
export enum WalletKind { export const enum WalletKind {
LNDHub = 1, LNDHub = 1,
LNC = 2, LNC = 2,
WebLN = 3, WebLN = 3,
@ -126,12 +126,15 @@ export type LNWallet = EventEmitter<WalletEvents> & {
/** /**
* Load wallet by kind * Load wallet by kind
*
* Some wallets are loaded using `async import` to avoid large dependency costs in bundle
* @param kind The wallet kind to create * @param kind The wallet kind to create
* @param data Opaque data * @param data Opaque data
*/ */
export function loadWallet(kind: WalletKind, data: string | undefined) { export async function loadWallet(kind: WalletKind, data: string | undefined) {
switch (kind) { switch (kind) {
case WalletKind.LNC: { case WalletKind.LNC: {
const { LNCWallet } = await import("./LNCWallet");
return LNCWallet.Empty(); return LNCWallet.Empty();
} }
case WalletKind.WebLN: { case WalletKind.WebLN: {
@ -147,9 +150,10 @@ export function loadWallet(kind: WalletKind, data: string | undefined) {
return new AlbyWallet(JSON.parse(unwrap(data))); return new AlbyWallet(JSON.parse(unwrap(data)));
} }
case WalletKind.Cashu: { case WalletKind.Cashu: {
return new CashuWallet(JSON.parse(unwrap(data))); //const { CashuWallet } = await import("./Cashu");
//return new CashuWallet(JSON.parse(unwrap(data)));
} }
} }
} }
export { LNCWallet, WebLNWallet, LNDHubWallet, NostrConnectWallet, AlbyWallet, CashuWallet }; export { LNCWallet, WebLNWallet, LNDHubWallet, NostrConnectWallet, AlbyWallet };

View File

@ -14,5 +14,5 @@
"skipLibCheck": true "skipLibCheck": true
}, },
"include": ["./src/**/*.ts"], "include": ["./src/**/*.ts"],
"exclude": ["**/*.test.ts"] "exclude": ["**/*.test.ts", "./src/Cashu.ts"]
} }

View File

@ -3236,6 +3236,7 @@ __metadata:
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "@snort/app@workspace:packages/app" resolution: "@snort/app@workspace:packages/app"
dependencies: dependencies:
"@cashu/cashu-ts": "npm:^1.0.0-rc.3"
"@formatjs/cli": "npm:^6.1.3" "@formatjs/cli": "npm:^6.1.3"
"@here/maps-api-for-javascript": "npm:^1.50.0" "@here/maps-api-for-javascript": "npm:^1.50.0"
"@noble/curves": "npm:^1.0.0" "@noble/curves": "npm:^1.0.0"