refactor: move zapper to @snort/wallet
This commit is contained in:
parent
38b9d132d5
commit
7350acce95
@ -2,6 +2,7 @@
|
|||||||
import { fetchNip05Pubkey, unixNow } from "@snort/shared";
|
import { fetchNip05Pubkey, unixNow } from "@snort/shared";
|
||||||
import { EventBuilder, EventKind, NostrLink, NostrPrefix, TaggedNostrEvent, tryParseNostrLink } from "@snort/system";
|
import { EventBuilder, EventKind, NostrLink, NostrPrefix, TaggedNostrEvent, tryParseNostrLink } from "@snort/system";
|
||||||
import { useUserProfile } from "@snort/system-react";
|
import { useUserProfile } from "@snort/system-react";
|
||||||
|
import { ZapTarget } from "@snort/wallet";
|
||||||
import { Menu, MenuItem } from "@szhsin/react-menu";
|
import { Menu, MenuItem } from "@szhsin/react-menu";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { ClipboardEventHandler, DragEvent, useEffect } from "react";
|
import { ClipboardEventHandler, DragEvent, useEffect } from "react";
|
||||||
@ -29,7 +30,6 @@ import { useNoteCreator } from "@/State/NoteCreator";
|
|||||||
import { openFile, trackEvent } from "@/Utils";
|
import { openFile, trackEvent } from "@/Utils";
|
||||||
import useFileUpload, { addExtensionToNip94Url, nip94TagsToIMeta, readNip94Tags } from "@/Utils/Upload";
|
import useFileUpload, { addExtensionToNip94Url, nip94TagsToIMeta, readNip94Tags } from "@/Utils/Upload";
|
||||||
import { GetPowWorker } from "@/Utils/wasm";
|
import { GetPowWorker } from "@/Utils/wasm";
|
||||||
import { ZapTarget } from "@/Utils/Zapper";
|
|
||||||
|
|
||||||
import { OkResponseRow } from "./OkResponseRow";
|
import { OkResponseRow } from "./OkResponseRow";
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { barrierQueue } from "@snort/shared";
|
import { barrierQueue } from "@snort/shared";
|
||||||
import { NostrLink, ParsedZap, TaggedNostrEvent } from "@snort/system";
|
import { NostrLink, ParsedZap, TaggedNostrEvent } from "@snort/system";
|
||||||
import { useUserProfile } from "@snort/system-react";
|
import { useUserProfile } from "@snort/system-react";
|
||||||
|
import { Zapper, ZapTarget } from "@snort/wallet";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
import { useLongPress } from "use-long-press";
|
import { useLongPress } from "use-long-press";
|
||||||
@ -13,7 +14,6 @@ import useEventPublisher from "@/Hooks/useEventPublisher";
|
|||||||
import useLogin from "@/Hooks/useLogin";
|
import useLogin from "@/Hooks/useLogin";
|
||||||
import usePreferences from "@/Hooks/usePreferences";
|
import usePreferences from "@/Hooks/usePreferences";
|
||||||
import { getDisplayName } from "@/Utils";
|
import { getDisplayName } from "@/Utils";
|
||||||
import { Zapper, ZapTarget } from "@/Utils/Zapper";
|
|
||||||
import { ZapPoolController } from "@/Utils/ZapPoolController";
|
import { ZapPoolController } from "@/Utils/ZapPoolController";
|
||||||
import { useWallet } from "@/Wallet";
|
import { useWallet } from "@/Wallet";
|
||||||
|
|
||||||
@ -140,13 +140,7 @@ export const FooterZapButton = ({ ev, zaps, onClickZappers }: ZapIconProps) => {
|
|||||||
<ZapsSummary zaps={zaps} onClick={onClickZappers ?? (() => {})} />
|
<ZapsSummary zaps={zaps} onClick={onClickZappers ?? (() => {})} />
|
||||||
</div>
|
</div>
|
||||||
{showZapModal && (
|
{showZapModal && (
|
||||||
<ZapModal
|
<ZapModal targets={getZapTarget()} onClose={() => setShowZapModal(false)} show={true} allocatePool={true} />
|
||||||
targets={getZapTarget()}
|
|
||||||
onClose={() => setShowZapModal(false)}
|
|
||||||
note={ev.id}
|
|
||||||
show={true}
|
|
||||||
allocatePool={true}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -2,11 +2,11 @@ import "./ZapButton.css";
|
|||||||
|
|
||||||
import { HexKey, NostrLink } from "@snort/system";
|
import { HexKey, NostrLink } from "@snort/system";
|
||||||
import { useUserProfile } from "@snort/system-react";
|
import { useUserProfile } from "@snort/system-react";
|
||||||
|
import { ZapTarget } from "@snort/wallet";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
import Icon from "@/Components/Icons/Icon";
|
import Icon from "@/Components/Icons/Icon";
|
||||||
import ZapModal from "@/Components/ZapModal/ZapModal";
|
import ZapModal from "@/Components/ZapModal/ZapModal";
|
||||||
import { ZapTarget } from "@/Utils/Zapper";
|
|
||||||
|
|
||||||
const ZapButton = ({
|
const ZapButton = ({
|
||||||
pubkey,
|
pubkey,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import "./ZapGoal.css";
|
import "./ZapGoal.css";
|
||||||
|
|
||||||
import { NostrEvent, NostrLink } from "@snort/system";
|
import { NostrEvent, NostrLink } from "@snort/system";
|
||||||
|
import { Zapper } from "@snort/wallet";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { FormattedNumber } from "react-intl";
|
import { FormattedNumber } from "react-intl";
|
||||||
|
|
||||||
@ -10,7 +11,6 @@ import ZapModal from "@/Components/ZapModal/ZapModal";
|
|||||||
import useZapsFeed from "@/Feed/ZapsFeed";
|
import useZapsFeed from "@/Feed/ZapsFeed";
|
||||||
import { findTag } from "@/Utils";
|
import { findTag } from "@/Utils";
|
||||||
import { formatShort } from "@/Utils/Number";
|
import { formatShort } from "@/Utils/Number";
|
||||||
import { Zapper } from "@/Utils/Zapper";
|
|
||||||
|
|
||||||
export function ZapGoal({ ev }: { ev: NostrEvent }) {
|
export function ZapGoal({ ev }: { ev: NostrEvent }) {
|
||||||
const [zap, setZap] = useState(false);
|
const [zap, setZap] = useState(false);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import "./ZapModal.css";
|
import "./ZapModal.css";
|
||||||
|
|
||||||
import { LNURLSuccessAction } from "@snort/shared";
|
import { LNURLSuccessAction } from "@snort/shared";
|
||||||
|
import { Zapper, ZapTarget, ZapTargetResult } from "@snort/wallet";
|
||||||
import { ReactNode, useEffect, useState } from "react";
|
import { ReactNode, useEffect, useState } from "react";
|
||||||
|
|
||||||
import CloseButton from "@/Components/Button/CloseButton";
|
import CloseButton from "@/Components/Button/CloseButton";
|
||||||
@ -12,7 +13,6 @@ import { ZapModalTitle } from "@/Components/ZapModal/ZapModalTitle";
|
|||||||
import { ZapType } from "@/Components/ZapModal/ZapType";
|
import { ZapType } from "@/Components/ZapModal/ZapType";
|
||||||
import useEventPublisher from "@/Hooks/useEventPublisher";
|
import useEventPublisher from "@/Hooks/useEventPublisher";
|
||||||
import { debounce } from "@/Utils";
|
import { debounce } from "@/Utils";
|
||||||
import { Zapper, ZapTarget, ZapTargetResult } from "@/Utils/Zapper";
|
|
||||||
import { useWallet } from "@/Wallet";
|
import { useWallet } from "@/Wallet";
|
||||||
|
|
||||||
export interface SendSatsProps {
|
export interface SendSatsProps {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { Zapper } from "@snort/wallet";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
@ -9,7 +10,6 @@ import { ZapTypeSelector } from "@/Components/ZapModal/ZapTypeSelector";
|
|||||||
import useLogin from "@/Hooks/useLogin";
|
import useLogin from "@/Hooks/useLogin";
|
||||||
import usePreferences from "@/Hooks/usePreferences";
|
import usePreferences from "@/Hooks/usePreferences";
|
||||||
import { formatShort } from "@/Utils/Number";
|
import { formatShort } from "@/Utils/Number";
|
||||||
import { Zapper } from "@/Utils/Zapper";
|
|
||||||
|
|
||||||
export interface SendSatsInputSelection {
|
export interface SendSatsInputSelection {
|
||||||
amount: number;
|
amount: number;
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import { LNWallet } from "@snort/wallet";
|
import { LNWallet, ZapTargetResult } from "@snort/wallet";
|
||||||
import { 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";
|
||||||
import QrCode from "@/Components/QrCode";
|
import QrCode from "@/Components/QrCode";
|
||||||
import { ZapTargetResult } from "@/Utils/Zapper";
|
|
||||||
|
|
||||||
export function ZapModalInvoice(props: {
|
export function ZapModalInvoice(props: {
|
||||||
invoice: Array<ZapTargetResult>;
|
invoice: Array<ZapTargetResult>;
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import React from "react";
|
import { Zapper, ZapTarget } from "@snort/wallet";
|
||||||
import { FormattedMessage } from "react-intl";
|
import { FormattedMessage } from "react-intl";
|
||||||
|
|
||||||
import ProfileImage from "@/Components/User/ProfileImage";
|
import ProfileImage from "@/Components/User/ProfileImage";
|
||||||
import { SendSatsInputSelection } from "@/Components/ZapModal/ZapModalInput";
|
import { SendSatsInputSelection } from "@/Components/ZapModal/ZapModalInput";
|
||||||
import { formatShort } from "@/Utils/Number";
|
import { formatShort } from "@/Utils/Number";
|
||||||
import { Zapper, ZapTarget } from "@/Utils/Zapper";
|
|
||||||
|
|
||||||
export function ZapModalTitle({
|
export function ZapModalTitle({
|
||||||
targets,
|
targets,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { LNURL } from "@snort/shared";
|
import { LNURL } from "@snort/shared";
|
||||||
import { CachedMetadata, encodeTLVEntries, NostrLink, NostrPrefix, TLVEntryType } from "@snort/system";
|
import { CachedMetadata, encodeTLVEntries, NostrLink, NostrPrefix, TLVEntryType } from "@snort/system";
|
||||||
|
import { ZapTarget } from "@snort/wallet";
|
||||||
import React, { useMemo, useState } from "react";
|
import React, { useMemo, useState } from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
@ -19,7 +20,6 @@ import ZapModal from "@/Components/ZapModal/ZapModal";
|
|||||||
import useModeration from "@/Hooks/useModeration";
|
import useModeration from "@/Hooks/useModeration";
|
||||||
import { hexToBech32 } from "@/Utils";
|
import { hexToBech32 } from "@/Utils";
|
||||||
import { LoginSessionType, LoginStore } from "@/Utils/Login";
|
import { LoginSessionType, LoginStore } from "@/Utils/Login";
|
||||||
import { ZapTarget } from "@/Utils/Zapper";
|
|
||||||
|
|
||||||
const AvatarSection = ({
|
const AvatarSection = ({
|
||||||
user,
|
user,
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { ExternalStore } from "@snort/shared";
|
import { ExternalStore } from "@snort/shared";
|
||||||
import { NostrEvent, TaggedNostrEvent } from "@snort/system";
|
import { NostrEvent, TaggedNostrEvent } from "@snort/system";
|
||||||
|
import { ZapTarget } from "@snort/wallet";
|
||||||
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector";
|
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector";
|
||||||
|
|
||||||
import { ZapTarget } from "@/Utils/Zapper";
|
|
||||||
|
|
||||||
interface NoteCreatorDataSnapshot {
|
interface NoteCreatorDataSnapshot {
|
||||||
show: boolean;
|
show: boolean;
|
||||||
note: string;
|
note: string;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@snort/shared": "^1.0.17",
|
"@snort/shared": "^1.0.17",
|
||||||
"@snort/system": "^1.5.0",
|
"@snort/system": "^1.5.1",
|
||||||
"react": "^18.2.0"
|
"react": "^18.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@snort/system",
|
"name": "@snort/system",
|
||||||
"version": "1.5.0",
|
"version": "1.5.1",
|
||||||
"description": "Snort nostr system package",
|
"description": "Snort nostr system package",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -59,7 +59,7 @@ export class EventPublisher {
|
|||||||
/**
|
/**
|
||||||
* Create an EventPublisher for a private key
|
* Create an EventPublisher for a private key
|
||||||
*/
|
*/
|
||||||
static privateKey(privateKey: string) {
|
static privateKey(privateKey: string | Uint8Array) {
|
||||||
const signer = new PrivateKeySigner(privateKey);
|
const signer = new PrivateKeySigner(privateKey);
|
||||||
return new EventPublisher(signer, signer.getPubKey());
|
return new EventPublisher(signer, signer.getPubKey());
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@snort/wallet",
|
"name": "@snort/wallet",
|
||||||
"version": "0.1.8",
|
"version": "0.2.0",
|
||||||
"description": "Snort wallet system package",
|
"description": "Snort wallet system package",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -23,7 +23,7 @@
|
|||||||
"@lightninglabs/lnc-web": "^0.3.1-alpha",
|
"@lightninglabs/lnc-web": "^0.3.1-alpha",
|
||||||
"@scure/base": "^1.1.6",
|
"@scure/base": "^1.1.6",
|
||||||
"@snort/shared": "^1.0.17",
|
"@snort/shared": "^1.0.17",
|
||||||
"@snort/system": "^1.5.0",
|
"@snort/system": "^1.5.1",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"eventemitter3": "^5.0.1"
|
"eventemitter3": "^5.0.1"
|
||||||
},
|
},
|
||||||
|
@ -7,6 +7,8 @@ import { NostrConnectWallet } from "./NostrWalletConnect";
|
|||||||
import { WebLNWallet } from "./WebLN";
|
import { WebLNWallet } from "./WebLN";
|
||||||
import EventEmitter from "eventemitter3";
|
import EventEmitter from "eventemitter3";
|
||||||
|
|
||||||
|
export * from "./zapper";
|
||||||
|
|
||||||
export const enum WalletKind {
|
export const enum WalletKind {
|
||||||
LNDHub = 1,
|
LNDHub = 1,
|
||||||
LNC = 2,
|
LNC = 2,
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { isHex, LNURL } from "@snort/shared";
|
import { isHex, LNURL } from "@snort/shared";
|
||||||
import { EventPublisher, NostrEvent, NostrLink, SystemInterface } from "@snort/system";
|
import { EventPublisher, NostrEvent, NostrLink, SystemInterface } from "@snort/system";
|
||||||
import { LNWallet, WalletInvoiceState } from "@snort/wallet";
|
import { LNWallet, WalletInvoiceState } from ".";
|
||||||
|
|
||||||
import { generateRandomKey } from "@/Utils/Login";
|
|
||||||
|
|
||||||
export interface ZapTarget {
|
export interface ZapTarget {
|
||||||
type: "lnurl" | "pubkey";
|
type: "lnurl" | "pubkey";
|
||||||
@ -105,7 +103,12 @@ export class Zapper {
|
|||||||
throw new Error(`Failed to get invoice from ${t.value}`);
|
throw new Error(`Failed to get invoice from ${t.value}`);
|
||||||
}
|
}
|
||||||
const relays = [...this.system.pool].filter(([, v]) => !v.ephemeral).map(([k]) => k);
|
const relays = [...this.system.pool].filter(([, v]) => !v.ephemeral).map(([k]) => k);
|
||||||
const pub = t.zap?.anon ?? false ? EventPublisher.privateKey(generateRandomKey().privateKey) : this.publisher;
|
let pub = this.publisher;
|
||||||
|
if (t.zap?.anon ?? false) {
|
||||||
|
const newKey = new Uint8Array(32);
|
||||||
|
crypto.getRandomValues(newKey);
|
||||||
|
pub = EventPublisher.privateKey(newKey);
|
||||||
|
}
|
||||||
const zap =
|
const zap =
|
||||||
t.zap && svc.canZap
|
t.zap && svc.canZap
|
||||||
? await pub?.zap(toSend * 1000, t.zap.pubkey, relays, t.zap?.event, t.memo, eb => {
|
? await pub?.zap(toSend * 1000, t.zap.pubkey, relays, t.zap?.event, t.memo, eb => {
|
Loading…
x
Reference in New Issue
Block a user