Skip to content

Commit

Permalink
refactor: extract wallet system
Browse files Browse the repository at this point in the history
  • Loading branch information
v0l committed Apr 11, 2024
1 parent d109584 commit 8137317
Show file tree
Hide file tree
Showing 33 changed files with 5,240 additions and 4,904 deletions.
874 changes: 0 additions & 874 deletions .yarn/releases/yarn-3.6.3.cjs

This file was deleted.

893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.1.1.cjs

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
yarnPath: .yarn/releases/yarn-3.6.3.cjs
compressionLevel: mixed

enableGlobalCache: false

npmScopes:
"here":
here:
npmRegistryServer: "https://repo.platform.here.com/artifactory/api/npm/maps-api-for-javascript/"

yarnPath: .yarn/releases/yarn-4.1.1.cjs
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"packages/*"
],
"scripts": {
"build": "yarn workspace @snort/shared build && yarn workspace @snort/worker-relay build && yarn workspace @snort/system build && yarn workspace @snort/system-web build && yarn workspace @snort/system-react build && yarn workspace @snort/app build",
"build": "yarn workspace @snort/shared build && yarn workspace @snort/wallet build && yarn workspace @snort/worker-relay build && yarn workspace @snort/system build && yarn workspace @snort/system-web build && yarn workspace @snort/system-react build && yarn workspace @snort/app build",
"start": "yarn build && yarn workspace @snort/app start",
"test": "yarn build && yarn workspace @snort/app test && yarn workspace @snort/system test",
"pre:commit": "yarn workspace @snort/app intl-extract && yarn workspace @snort/app intl-compile && yarn prettier --write .",
Expand All @@ -18,7 +18,7 @@
"trailingComma": "all",
"endOfLine": "lf"
},
"packageManager": "yarn@3.6.3",
"packageManager": "yarn@4.1.1",
"dependencies": {
"@cloudflare/workers-types": "^4.20230307.0",
"@tauri-apps/cli": "^1.2.3",
Expand Down
5 changes: 2 additions & 3 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"name": "@snort/app",
"version": "0.2.0",
"dependencies": {
"@cashu/cashu-ts": "0.6.1",
"@here/maps-api-for-javascript": "^1.50.0",
"@lightninglabs/lnc-web": "^0.2.8-alpha",
"@noble/curves": "^1.0.0",
"@noble/hashes": "^1.3.3",
"@scure/base": "^1.1.1",
Expand All @@ -15,6 +13,7 @@
"@snort/system-react": "workspace:*",
"@snort/system-wasm": "workspace:*",
"@snort/system-web": "workspace:*",
"@snort/wallet": "workspace:*",
"@snort/worker-relay": "workspace:*",
"@szhsin/react-menu": "^3.3.1",
"@uidotdev/usehooks": "^2.4.1",
Expand Down Expand Up @@ -119,7 +118,7 @@
"tailwindcss": "^3.3.3",
"tinybench": "^2.5.1",
"typescript": "^5.2.2",
"vite": "^5.1.5",
"vite": "^5.2.8",
"vite-plugin-pwa": "^0.19.2",
"vite-plugin-version-mark": "^0.0.10",
"vitest": "^0.34.6"
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/Components/Embed/PubkeyList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LNURL } from "@snort/shared";
import { NostrEvent } from "@snort/system";
import { WalletInvoiceState } from "@snort/wallet";
import { FormattedMessage, FormattedNumber } from "react-intl";

import { UserCache } from "@/Cache";
Expand All @@ -10,7 +11,6 @@ import useEventPublisher from "@/Hooks/useEventPublisher";
import useLogin from "@/Hooks/useLogin";
import { dedupe, findTag, getDisplayName, hexToBech32 } from "@/Utils";
import { useWallet } from "@/Wallet";
import { WalletInvoiceState } from "@/Wallet";

export default function PubkeyList({ ev, className }: { ev: NostrEvent; className?: string }) {
const wallet = useWallet();
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/Components/ZapModal/ZapModalInvoice.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { LNWallet } from "@snort/wallet";
import React, { ReactNode } from "react";
import { FormattedMessage } from "react-intl";

import Copy from "@/Components/Copy/Copy";
import QrCode from "@/Components/QrCode";
import { ZapTargetResult } from "@/Utils/Zapper";
import { LNWallet } from "@/Wallet";

export function ZapModalInvoice(props: {
invoice: Array<ZapTargetResult>;
Expand Down
5 changes: 3 additions & 2 deletions packages/app/src/Pages/settings/WalletSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BlueWallet from "@/Components/Icons/BlueWallet";
import Icon from "@/Components/Icons/Icon";
import NostrIcon from "@/Components/Icons/Nostrich";
import { getAlbyOAuth } from "@/Pages/settings/wallet/utils";
import CashuIcon from "@/Components/Icons/Cashu";

const WalletRow = (props: {
logo: ReactNode;
Expand Down Expand Up @@ -70,12 +71,12 @@ const WalletSettings = () => {
url="/settings/wallet/lndhub"
desc={<FormattedMessage defaultMessage="Generic LNDHub wallet (BTCPayServer / Alby / LNBits)" id="0MndVW" />}
/>
{/*<WalletRow
<WalletRow
logo={<CashuIcon size={64} />}
name="Cashu"
url="/settings/wallet/cashu"
desc={<FormattedMessage defaultMessage="Cashu mint wallet" id="3natuV" />}
/>*/}
/>
{CONFIG.alby && (
<WalletRow
logo={<AlbyIcon size={64} />}
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/Pages/settings/wallet/Alby.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AlbyWallet, WalletKind } from "@snort/wallet";
import { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import { v4 as uuid } from "uuid";

import PageSpinner from "@/Components/PageSpinner";
import { getAlbyOAuth } from "@/Pages/settings/wallet/utils";
import { WalletConfig, WalletKind, Wallets } from "@/Wallet";
import AlbyWallet from "@/Wallet/AlbyWallet";
import { WalletConfig, Wallets } from "@/Wallet";

export default function AlbyOAuth() {
const navigate = useNavigate();
Expand All @@ -16,7 +16,7 @@ export default function AlbyOAuth() {
async function setupWallet(token: string) {
try {
const auth = await alby.getToken(token);
const connection = new AlbyWallet(auth, () => {});
const connection = new AlbyWallet(auth);
const info = await connection.getInfo();

const newWallet = {
Expand Down
5 changes: 2 additions & 3 deletions packages/app/src/Pages/settings/wallet/Cashu.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { CashuWallet, WalletKind } from "@snort/wallet";
import { useState } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { useNavigate } from "react-router-dom";
import { v4 as uuid } from "uuid";

import AsyncButton from "@/Components/Button/AsyncButton";
import { unwrap } from "@/Utils";
import { WalletConfig, WalletKind, Wallets } from "@/Wallet";
import { WalletConfig, Wallets } from "@/Wallet";

const ConnectCashu = () => {
const navigate = useNavigate();
Expand All @@ -19,15 +20,13 @@ const ConnectCashu = () => {
throw new Error("Mint URL is required");
}

const { CashuWallet } = await import("@/Wallet/Cashu");
const connection = new CashuWallet(
{
url: config,
keys: {},
proofs: [],
keysets: [],
},
() => {},
);
await connection.login();
const info = await connection.getInfo();
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/Pages/settings/wallet/LNC.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { LNCWallet, LNWallet, WalletInfo, WalletKind } from "@snort/wallet";
import { useState } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { useNavigate } from "react-router-dom";
import { v4 as uuid } from "uuid";

import AsyncButton from "@/Components/Button/AsyncButton";
import { unwrap } from "@/Utils";
import { LNWallet, WalletInfo, WalletKind, Wallets } from "@/Wallet";
import { Wallets } from "@/Wallet";

const ConnectLNC = () => {
const { formatMessage } = useIntl();
Expand All @@ -18,7 +19,6 @@ const ConnectLNC = () => {

async function tryConnect(cfg: string) {
try {
const { LNCWallet } = await import("@/Wallet/LNCWallet");
const lnc = await LNCWallet.Initialize(cfg);
const info = await lnc.getInfo();

Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/Pages/settings/wallet/LNDHub.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { LNDHubWallet, WalletKind } from "@snort/wallet";
import { useState } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { useNavigate } from "react-router-dom";
import { v4 as uuid } from "uuid";

import AsyncButton from "@/Components/Button/AsyncButton";
import { unwrap } from "@/Utils";
import { WalletConfig, WalletKind, Wallets } from "@/Wallet";
import LNDHubWallet from "@/Wallet/LNDHub";
import { WalletConfig, Wallets } from "@/Wallet";

const ConnectLNDHub = () => {
const navigate = useNavigate();
Expand All @@ -16,7 +16,7 @@ const ConnectLNDHub = () => {

async function tryConnect(config: string) {
try {
const connection = new LNDHubWallet(config, () => {});
const connection = new LNDHubWallet(config);
await connection.login();
const info = await connection.getInfo();

Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/Pages/settings/wallet/NWC.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NostrConnectWallet, WalletKind } from "@snort/wallet";
import { useState } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { Link, useNavigate } from "react-router-dom";
import { v4 as uuid } from "uuid";

import AsyncButton from "@/Components/Button/AsyncButton";
import { unwrap } from "@/Utils";
import { WalletConfig, WalletKind, Wallets } from "@/Wallet";
import { NostrConnectWallet } from "@/Wallet/NostrWalletConnect";
import { WalletConfig, Wallets } from "@/Wallet";

const ConnectNostrWallet = () => {
const navigate = useNavigate();
Expand All @@ -16,7 +16,7 @@ const ConnectNostrWallet = () => {

async function tryConnect(config: string) {
try {
const connection = new NostrConnectWallet(config, () => {});
const connection = new NostrConnectWallet(config);
await connection.login();
const info = await connection.getInfo();

Expand Down
4 changes: 3 additions & 1 deletion packages/app/src/Pages/settings/wallet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function getAlbyOAuth() {

const data = await req.json();
if (req.ok) {
return { ...data, created_at: unixNow() } as OAuthToken;
return { ...data, created_at: unixNow(), clientId, clientSecret } as OAuthToken;
} else {
throw new Error(data.error_description as string);
}
Expand All @@ -74,4 +74,6 @@ export interface OAuthToken {
refresh_token: string;
scope: string;
token_type: string;
clientId: string;
clientSecret: string;
}
3 changes: 2 additions & 1 deletion packages/app/src/Pages/wallet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable max-lines */
import { LNWallet,Sats, WalletInvoice } from "@snort/wallet";
import classNames from "classnames";
import { useEffect, useState } from "react";
import { FormattedMessage, FormattedNumber, useIntl } from "react-intl";
Expand All @@ -10,7 +11,7 @@ import NoteTime from "@/Components/Event/Note/NoteTime";
import Icon from "@/Components/Icons/Icon";
import { useRates } from "@/Hooks/useRates";
import { unwrap } from "@/Utils";
import { LNWallet, Sats, useWallet, WalletInvoice, Wallets } from "@/Wallet";
import { useWallet, Wallets } from "@/Wallet";

export default function WalletPage(props: { showHistory: boolean }) {
const navigate = useNavigate();
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/Utils/ZapPoolController.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ExternalStore, LNURL, unixNow } from "@snort/shared";
import { LNWallet, WalletInvoiceState } from "@snort/wallet";
import debug from "debug";

import { UserCache } from "@/Cache";
import { Toastore } from "@/Components/Toaster/Toaster";
import { SnortPubKey } from "@/Utils/Const";
import { bech32ToHex, getDisplayName, trackEvent } from "@/Utils/index";
import { LNWallet, WalletInvoiceState, Wallets } from "@/Wallet";
import { Wallets } from "@/Wallet";

export enum ZapPoolRecipientType {
Generic = 0,
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/Utils/Zapper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isHex, LNURL } from "@snort/shared";
import { EventPublisher, NostrEvent, NostrLink, SystemInterface } from "@snort/system";
import { LNWallet, WalletInvoiceState } from "@snort/wallet";

import { generateRandomKey } from "@/Utils/Login";
import { LNWallet, WalletInvoiceState } from "@/Wallet";

export interface ZapTarget {
type: "lnurl" | "pubkey";
Expand Down
Loading

0 comments on commit 8137317

Please sign in to comment.