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