mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-06 08:47:23 +00:00
address testing errors
This commit is contained in:
1 parent
460a4777ee
commit
61fc4957e0
15 files changed
+45
-88
No files matched your search
@@ -4,6 +4,11 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta http-equiv="content-security-policy" content="default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; frame-src 'self' https:; font-src 'self'; base-uri 'self'; manifest-src 'self'; connect-src 'self' blob: https: wss:; img-src 'self' data: blob: https:; media-src 'self' https:">
|
<meta http-equiv="content-security-policy" content="default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; frame-src 'self' https:; font-src 'self'; base-uri 'self'; manifest-src 'self'; connect-src 'self' blob: https: wss:; img-src 'self' data: blob: https:; media-src 'self' https:">
|
||||||
|
<title>NutStack</title>
|
||||||
|
<meta name="description" content="A Bitcoin wallet powered by Nostr">
|
||||||
|
<meta property="og:type" content="website">
|
||||||
|
<meta property="og:title" content="NutStack">
|
||||||
|
<meta property="og:description" content="A Bitcoin wallet powered by Nostr">
|
||||||
<link rel="manifest" href="/manifest.webmanifest">
|
<link rel="manifest" href="/manifest.webmanifest">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { User, UserPlus } from 'lucide-react';
|
import { User } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import LoginDialog from './LoginDialog';
|
import LoginDialog from './LoginDialog';
|
||||||
import SignupDialog from './SignupDialog';
|
import SignupDialog from './SignupDialog';
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ export function CashuWallet() {
|
|||||||
balances,
|
balances,
|
||||||
mints,
|
mints,
|
||||||
getEncodedToken,
|
getEncodedToken,
|
||||||
clearError,
|
|
||||||
refreshMints,
|
refreshMints,
|
||||||
} = useCashu();
|
} = useCashu();
|
||||||
|
|
||||||
@@ -55,8 +54,6 @@ export function CashuWallet() {
|
|||||||
const {
|
const {
|
||||||
setMint: setNpubCashMint,
|
setMint: setNpubCashMint,
|
||||||
getUserInfo: getNpubCashUserInfo,
|
getUserInfo: getNpubCashUserInfo,
|
||||||
getAllQuotes,
|
|
||||||
refreshQuotes,
|
|
||||||
syncQuotesWithWallet,
|
syncQuotesWithWallet,
|
||||||
isLoggedIn: isNpubCashLoggedIn,
|
isLoggedIn: isNpubCashLoggedIn,
|
||||||
isLoading: isNpubCashLoading,
|
isLoading: isNpubCashLoading,
|
||||||
@@ -84,7 +81,6 @@ export function CashuWallet() {
|
|||||||
handleRemoveMintClick,
|
handleRemoveMintClick,
|
||||||
handleConfirmRemoveMint,
|
handleConfirmRemoveMint,
|
||||||
mintToRemove,
|
mintToRemove,
|
||||||
setMintToRemove,
|
|
||||||
showRemoveMintModal,
|
showRemoveMintModal,
|
||||||
setShowRemoveMintModal,
|
setShowRemoveMintModal,
|
||||||
getCleanMintLabel,
|
getCleanMintLabel,
|
||||||
@@ -96,7 +92,6 @@ export function CashuWallet() {
|
|||||||
isNpubCashLoggedIn,
|
isNpubCashLoggedIn,
|
||||||
setNpubCashMint: handleSetNpubCashMint,
|
setNpubCashMint: handleSetNpubCashMint,
|
||||||
refreshMints,
|
refreshMints,
|
||||||
toast,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wrapper for setActiveMintUrl to handle the async nature
|
// Wrapper for setActiveMintUrl to handle the async nature
|
||||||
@@ -129,7 +124,6 @@ export function CashuWallet() {
|
|||||||
showInvoiceModal,
|
showInvoiceModal,
|
||||||
setShowInvoiceModal,
|
setShowInvoiceModal,
|
||||||
currentInvoice,
|
currentInvoice,
|
||||||
setCurrentInvoice,
|
|
||||||
handleReceive,
|
handleReceive,
|
||||||
handleSend,
|
handleSend,
|
||||||
handleConfirmInvoicePayment,
|
handleConfirmInvoicePayment,
|
||||||
@@ -137,10 +131,7 @@ export function CashuWallet() {
|
|||||||
} = useWalletTransactions({
|
} = useWalletTransactions({
|
||||||
coco,
|
coco,
|
||||||
activeMintUrl,
|
activeMintUrl,
|
||||||
isNpubCashLoggedIn,
|
|
||||||
repositories,
|
|
||||||
generateQRCode,
|
generateQRCode,
|
||||||
toast,
|
|
||||||
getEncodedToken,
|
getEncodedToken,
|
||||||
getLightningInvoice,
|
getLightningInvoice,
|
||||||
});
|
});
|
||||||
@@ -148,8 +139,6 @@ export function CashuWallet() {
|
|||||||
const {
|
const {
|
||||||
historyEntries,
|
historyEntries,
|
||||||
isLoadingHistory,
|
isLoadingHistory,
|
||||||
isHistoryExpanded,
|
|
||||||
setIsHistoryExpanded,
|
|
||||||
} = useHistoryManager({
|
} = useHistoryManager({
|
||||||
coco,
|
coco,
|
||||||
isInitialized,
|
isInitialized,
|
||||||
@@ -167,8 +156,6 @@ export function CashuWallet() {
|
|||||||
denominations: { [key: number]: number };
|
denominations: { [key: number]: number };
|
||||||
totalBalance: number;
|
totalBalance: number;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
const [showLightningQR, setShowLightningQR] = useState(false);
|
|
||||||
const [lightningQRCode, setLightningQRCode] = useState<string>('');
|
|
||||||
const [showLightningAddressQR, setShowLightningAddressQR] = useState(false);
|
const [showLightningAddressQR, setShowLightningAddressQR] = useState(false);
|
||||||
const [lightningAddressQRCode, setLightningAddressQRCode] = useState<string>('');
|
const [lightningAddressQRCode, setLightningAddressQRCode] = useState<string>('');
|
||||||
const [npubCashUserInfo, setNpubCashUserInfo] = useState<NpubCashUserInfo | null>(null);
|
const [npubCashUserInfo, setNpubCashUserInfo] = useState<NpubCashUserInfo | null>(null);
|
||||||
@@ -272,7 +259,7 @@ export function CashuWallet() {
|
|||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: "Bitcoin Sent!",
|
title: "Bitcoin Sent!",
|
||||||
description: `Transaction ${txId.slice(0, 8)}... confirmed`,
|
description: `Transaction ${txId.slice(0, 8)}... confirmed (Fee: ${fee} sats)`,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reset form and refresh balance
|
// Reset form and refresh balance
|
||||||
@@ -390,7 +377,7 @@ export function CashuWallet() {
|
|||||||
let unsubscribe: (() => void) | null = null;
|
let unsubscribe: (() => void) | null = null;
|
||||||
|
|
||||||
const setupSync = async () => {
|
const setupSync = async () => {
|
||||||
unsubscribe = await syncQuotesWithWallet(coco, toast);
|
unsubscribe = await syncQuotesWithWallet(coco);
|
||||||
};
|
};
|
||||||
|
|
||||||
setupSync();
|
setupSync();
|
||||||
@@ -505,9 +492,6 @@ export function CashuWallet() {
|
|||||||
mintToRemove={mintToRemove}
|
mintToRemove={mintToRemove}
|
||||||
onConfirmRemoveMint={handleConfirmRemoveMint}
|
onConfirmRemoveMint={handleConfirmRemoveMint}
|
||||||
isLoading={isLoading || isNpubCashLoading}
|
isLoading={isLoading || isNpubCashLoading}
|
||||||
showLightningQR={showLightningQR}
|
|
||||||
setShowLightningQR={setShowLightningQR}
|
|
||||||
lightningQRCode={lightningQRCode}
|
|
||||||
showLightningAddressQR={showLightningAddressQR}
|
showLightningAddressQR={showLightningAddressQR}
|
||||||
setShowLightningAddressQR={setShowLightningAddressQR}
|
setShowLightningAddressQR={setShowLightningAddressQR}
|
||||||
lightningAddressQRCode={lightningAddressQRCode}
|
lightningAddressQRCode={lightningAddressQRCode}
|
||||||
|
|||||||
@@ -31,9 +31,6 @@ interface WalletModalProps {
|
|||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
|
||||||
// QR Modals
|
// QR Modals
|
||||||
showLightningQR: boolean;
|
|
||||||
setShowLightningQR: (show: boolean) => void;
|
|
||||||
lightningQRCode: string;
|
|
||||||
showLightningAddressQR: boolean;
|
showLightningAddressQR: boolean;
|
||||||
setShowLightningAddressQR: (show: boolean) => void;
|
setShowLightningAddressQR: (show: boolean) => void;
|
||||||
lightningAddressQRCode: string;
|
lightningAddressQRCode: string;
|
||||||
@@ -66,9 +63,6 @@ export function WalletModals({
|
|||||||
mintToRemove,
|
mintToRemove,
|
||||||
onConfirmRemoveMint,
|
onConfirmRemoveMint,
|
||||||
isLoading,
|
isLoading,
|
||||||
showLightningQR,
|
|
||||||
setShowLightningQR,
|
|
||||||
lightningQRCode,
|
|
||||||
showLightningAddressQR,
|
showLightningAddressQR,
|
||||||
setShowLightningAddressQR,
|
setShowLightningAddressQR,
|
||||||
lightningAddressQRCode,
|
lightningAddressQRCode,
|
||||||
@@ -207,16 +201,6 @@ export function WalletModals({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* QR Modals */}
|
{/* QR Modals */}
|
||||||
<QRModal
|
|
||||||
isOpen={showLightningQR}
|
|
||||||
onClose={() => setShowLightningQR(false)}
|
|
||||||
title="Lightning Address QR Code"
|
|
||||||
description="Scan to send Lightning payments"
|
|
||||||
qrCodeUrl={lightningQRCode}
|
|
||||||
content={''}
|
|
||||||
icon="qr"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<QRModal
|
<QRModal
|
||||||
isOpen={showLightningAddressQR}
|
isOpen={showLightningAddressQR}
|
||||||
onClose={() => setShowLightningAddressQR(false)}
|
onClose={() => setShowLightningAddressQR(false)}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Slider } from '@/components/ui/slider';
|
import { Slider } from '@/components/ui/slider';
|
||||||
import { Send, Download, ArrowRight, Zap, Loader2, X } from 'lucide-react';
|
import { Send, Download, ArrowRight, Zap, X } from 'lucide-react';
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
|
|
||||||
interface TransactionCardProps {
|
interface TransactionCardProps {
|
||||||
@@ -86,9 +86,6 @@ export function TransactionCard({
|
|||||||
const [addressSliderValue, setAddressSliderValue] = useState([0]);
|
const [addressSliderValue, setAddressSliderValue] = useState([0]);
|
||||||
const [bitcoinSliderValue, setBitcoinSliderValue] = useState([0]);
|
const [bitcoinSliderValue, setBitcoinSliderValue] = useState([0]);
|
||||||
|
|
||||||
// State to track which slider is being actively held
|
|
||||||
const [activeSlider, setActiveSlider] = useState<string | null>(null);
|
|
||||||
|
|
||||||
// Handle slider value changes and auto-submit at 100%
|
// Handle slider value changes and auto-submit at 100%
|
||||||
const handleInvoiceSliderChange = (value: number[]) => {
|
const handleInvoiceSliderChange = (value: number[]) => {
|
||||||
setInvoiceSliderValue(value);
|
setInvoiceSliderValue(value);
|
||||||
@@ -111,15 +108,7 @@ export function TransactionCard({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reset sliders when states change
|
|
||||||
const resetSliders = () => {
|
|
||||||
setInvoiceSliderValue([0]);
|
|
||||||
setAddressSliderValue([0]);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Handle slider release (reset on mouse/touch up)
|
|
||||||
const handleSliderMouseUp = (sliderId: string) => {
|
const handleSliderMouseUp = (sliderId: string) => {
|
||||||
setActiveSlider(null);
|
|
||||||
// Reset the slider if it hasn't reached 100
|
// Reset the slider if it hasn't reached 100
|
||||||
if (sliderId === 'invoice' && invoiceSliderValue[0] !== 100) {
|
if (sliderId === 'invoice' && invoiceSliderValue[0] !== 100) {
|
||||||
setInvoiceSliderValue([0]);
|
setInvoiceSliderValue([0]);
|
||||||
@@ -130,11 +119,7 @@ export function TransactionCard({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSliderMouseDown = (sliderId: string) => {
|
// Reset sliders when states change
|
||||||
setActiveSlider(sliderId);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Reset sliders when pending states change
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!pendingInvoice) {
|
if (!pendingInvoice) {
|
||||||
setInvoiceSliderValue([0]);
|
setInvoiceSliderValue([0]);
|
||||||
@@ -266,7 +251,6 @@ export function TransactionCard({
|
|||||||
<div className="mt-6">
|
<div className="mt-6">
|
||||||
<div className="relative w-full">
|
<div className="relative w-full">
|
||||||
<div
|
<div
|
||||||
onMouseDown={() => handleSliderMouseDown('bitcoin')}
|
|
||||||
onMouseUp={() => handleSliderMouseUp('bitcoin')}
|
onMouseUp={() => handleSliderMouseUp('bitcoin')}
|
||||||
onMouseLeave={() => handleSliderMouseUp('bitcoin')}
|
onMouseLeave={() => handleSliderMouseUp('bitcoin')}
|
||||||
onTouchEnd={() => handleSliderMouseUp('bitcoin')}
|
onTouchEnd={() => handleSliderMouseUp('bitcoin')}
|
||||||
@@ -352,7 +336,6 @@ export function TransactionCard({
|
|||||||
<div className="mt-6">
|
<div className="mt-6">
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<div
|
<div
|
||||||
onMouseDown={() => handleSliderMouseDown('invoice')}
|
|
||||||
onMouseUp={() => handleSliderMouseUp('invoice')}
|
onMouseUp={() => handleSliderMouseUp('invoice')}
|
||||||
onMouseLeave={() => handleSliderMouseUp('invoice')}
|
onMouseLeave={() => handleSliderMouseUp('invoice')}
|
||||||
onTouchEnd={() => handleSliderMouseUp('invoice')}
|
onTouchEnd={() => handleSliderMouseUp('invoice')}
|
||||||
@@ -393,7 +376,6 @@ export function TransactionCard({
|
|||||||
<div className="mt-6">
|
<div className="mt-6">
|
||||||
<div className="relative w-full">
|
<div className="relative w-full">
|
||||||
<div
|
<div
|
||||||
onMouseDown={() => handleSliderMouseDown('address')}
|
|
||||||
onMouseUp={() => handleSliderMouseUp('address')}
|
onMouseUp={() => handleSliderMouseUp('address')}
|
||||||
onMouseLeave={() => handleSliderMouseUp('address')}
|
onMouseLeave={() => handleSliderMouseUp('address')}
|
||||||
onTouchEnd={() => handleSliderMouseUp('address')}
|
onTouchEnd={() => handleSliderMouseUp('address')}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { nip19 } from 'nostr-tools';
|
|
||||||
import { Zap, Coins, Copy, Check, QrCode, Link } from 'lucide-react';
|
import { Zap, Coins, Copy, Check, QrCode, Link } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { exchangeRateService } from '@/lib/exchangeRateService';
|
import { exchangeRateService } from '@/lib/exchangeRateService';
|
||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
import { LoginIcon } from '@/components/auth/LoginIcon';
|
import { LoginIcon } from '@/components/auth/LoginIcon';
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ export function CashuProvider({ children }: { children: ReactNode }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useCashu(): UseCashuReturn {
|
export function useCashuContext(): UseCashuReturn {
|
||||||
const context = useContext(CashuContext);
|
const context = useContext(CashuContext);
|
||||||
|
|
||||||
if (!context) {
|
if (!context) {
|
||||||
throw new Error('useCashu must be used within a CashuProvider');
|
throw new Error('useCashuContext must be used within a CashuProvider');
|
||||||
}
|
}
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import * as bip39 from '@scure/bip39';
|
|||||||
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
||||||
import { initializeCoco, ConsoleLogger, getEncodedToken, type Repositories } from 'coco-cashu-core';
|
import { initializeCoco, ConsoleLogger, getEncodedToken, type Repositories } from 'coco-cashu-core';
|
||||||
import { IndexedDbRepositories } from 'coco-cashu-indexeddb';
|
import { IndexedDbRepositories } from 'coco-cashu-indexeddb';
|
||||||
|
import type { Mint } from 'coco-cashu-core';
|
||||||
|
|
||||||
// Types from coco-cashu-core
|
// Types from coco-cashu-core
|
||||||
type CocoManager = Awaited<ReturnType<typeof initializeCoco>>;
|
type CocoManager = Awaited<ReturnType<typeof initializeCoco>>;
|
||||||
@@ -71,7 +72,7 @@ export function useCashu(): UseCashuReturn {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const mintList = await coco.mint.getAllMints();
|
const mintList = await coco.mint.getAllMints();
|
||||||
setMints(mintList.map((m: any) => ({
|
setMints(mintList.map((m: Mint) => ({
|
||||||
url: m.mintUrl,
|
url: m.mintUrl,
|
||||||
name: m.name,
|
name: m.name,
|
||||||
info: m.mintInfo
|
info: m.mintInfo
|
||||||
@@ -197,7 +198,7 @@ export function useCashu(): UseCashuReturn {
|
|||||||
const newBalances = await coco.wallet.getBalances();
|
const newBalances = await coco.wallet.getBalances();
|
||||||
setBalances(newBalances);
|
setBalances(newBalances);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Silent failure - errors are handled by the manager
|
console.log('Failed to refresh balances:', err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { useState, useCallback, useEffect } from 'react';
|
import { useState, useCallback, useEffect } from 'react';
|
||||||
import type { HistoryEntry } from 'coco-cashu-core';
|
import type { HistoryEntry, Manager } from 'coco-cashu-core';
|
||||||
|
|
||||||
interface UseHistoryManagerProps {
|
interface UseHistoryManagerProps {
|
||||||
coco: any; // Coco instance
|
coco: Manager | null;
|
||||||
isInitialized: boolean;
|
isInitialized: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { useState, useCallback, useEffect } from 'react';
|
import { useState, useCallback, useEffect } from 'react';
|
||||||
import { getCleanMintLabel } from './walletUtils';
|
import { getCleanMintLabel } from './walletUtils';
|
||||||
|
import type { Manager, Repositories } from 'coco-cashu-core';
|
||||||
|
import { toast } from '@/hooks/useToast';
|
||||||
|
|
||||||
export interface CashuMint {
|
export interface CashuMint {
|
||||||
url: string;
|
url: string;
|
||||||
@@ -7,13 +9,12 @@ export interface CashuMint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface UseMintManagerProps {
|
interface UseMintManagerProps {
|
||||||
coco: any; // Coco instance
|
coco: Manager | null;
|
||||||
mints: CashuMint[];
|
mints: CashuMint[];
|
||||||
repositories: any; // Repositories instance
|
repositories: Repositories | null;
|
||||||
isNpubCashLoggedIn: boolean;
|
isNpubCashLoggedIn: boolean;
|
||||||
setNpubCashMint: (mintUrl: string) => Promise<boolean>;
|
setNpubCashMint: (mintUrl: string) => Promise<boolean>;
|
||||||
refreshMints: () => Promise<void>;
|
refreshMints: () => Promise<void>;
|
||||||
toast: any; // Toast function
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useMintManager({
|
export function useMintManager({
|
||||||
@@ -23,7 +24,6 @@ export function useMintManager({
|
|||||||
isNpubCashLoggedIn,
|
isNpubCashLoggedIn,
|
||||||
setNpubCashMint,
|
setNpubCashMint,
|
||||||
refreshMints,
|
refreshMints,
|
||||||
toast,
|
|
||||||
}: UseMintManagerProps) {
|
}: UseMintManagerProps) {
|
||||||
const [activeMintUrl, setActiveMintUrl] = useState<string | null>(null);
|
const [activeMintUrl, setActiveMintUrl] = useState<string | null>(null);
|
||||||
const [mintDropdownOpen, setMintDropdownOpen] = useState(false);
|
const [mintDropdownOpen, setMintDropdownOpen] = useState(false);
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import { useState, useCallback, useRef, useEffect } from 'react';
|
import { useState, useCallback, useRef, useEffect } from 'react';
|
||||||
import { isUnknownMintError, extractMintUrlFromError } from './walletUtils';
|
import { isUnknownMintError, extractMintUrlFromError } from './walletUtils';
|
||||||
import { decodeBolt11Amount, isValidBolt11Invoice } from '@/lib/bolt11Decoder';
|
import { decodeBolt11Amount, isValidBolt11Invoice } from '@/lib/bolt11Decoder';
|
||||||
|
import type { Manager } from 'coco-cashu-core';
|
||||||
|
import type { Token } from '@cashu/cashu-ts';
|
||||||
|
import { useToast } from '@/hooks/useToast';
|
||||||
|
|
||||||
interface UseWalletTransactionsProps {
|
interface UseWalletTransactionsProps {
|
||||||
coco: any; // Coco instance
|
coco: Manager | null;
|
||||||
activeMintUrl: string | null;
|
activeMintUrl: string | null;
|
||||||
isNpubCashLoggedIn: boolean;
|
|
||||||
repositories: any; // Repositories instance
|
|
||||||
generateQRCode: (text: string) => Promise<string>;
|
generateQRCode: (text: string) => Promise<string>;
|
||||||
toast: any; // Toast function
|
getEncodedToken: (token: Token | string) => string;
|
||||||
getEncodedToken: (token: any) => string;
|
|
||||||
getLightningInvoice: (params: {
|
getLightningInvoice: (params: {
|
||||||
lightningAddress: string;
|
lightningAddress: string;
|
||||||
amountSats: number;
|
amountSats: number;
|
||||||
@@ -19,13 +19,11 @@ interface UseWalletTransactionsProps {
|
|||||||
export function useWalletTransactions({
|
export function useWalletTransactions({
|
||||||
coco,
|
coco,
|
||||||
activeMintUrl,
|
activeMintUrl,
|
||||||
isNpubCashLoggedIn,
|
|
||||||
repositories,
|
|
||||||
generateQRCode,
|
generateQRCode,
|
||||||
toast,
|
|
||||||
getEncodedToken,
|
getEncodedToken,
|
||||||
getLightningInvoice,
|
getLightningInvoice,
|
||||||
}: UseWalletTransactionsProps) {
|
}: UseWalletTransactionsProps) {
|
||||||
|
const { toast } = useToast();
|
||||||
// Receive state
|
// Receive state
|
||||||
const [tokenInput, setTokenInput] = useState('');
|
const [tokenInput, setTokenInput] = useState('');
|
||||||
const [quoteAmount, setQuoteAmount] = useState('');
|
const [quoteAmount, setQuoteAmount] = useState('');
|
||||||
|
|||||||
@@ -10,14 +10,15 @@ export const getCleanMintLabel = (mint: { name?: string; url: string }): string
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const isUnknownMintError = (err: unknown): boolean => {
|
export const isUnknownMintError = (err: unknown): boolean => {
|
||||||
const errorMessage = (err as any)?.message || err?.toString() || '';
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
||||||
return (err as any)?.constructor?.name === 'UnknownMintError' ||
|
const errorName = err instanceof Error ? err.constructor.name : '';
|
||||||
|
return errorName === 'UnknownMintError' ||
|
||||||
errorMessage.includes('UnknownMintError') ||
|
errorMessage.includes('UnknownMintError') ||
|
||||||
(errorMessage.includes('Mint') && errorMessage.includes('is not known'));
|
(errorMessage.includes('Mint') && errorMessage.includes('is not known'));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const extractMintUrlFromError = (err: unknown): string | null => {
|
export const extractMintUrlFromError = (err: unknown): string | null => {
|
||||||
const errorMessage = (err as any)?.message || err?.toString() || '';
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
||||||
const mintUrlMatch = errorMessage.match(/Mint (https?:\/\/[^\s]+)/);
|
const mintUrlMatch = errorMessage.match(/Mint (https?:\/\/[^\s]+)/);
|
||||||
return mintUrlMatch?.[1] || null;
|
return mintUrlMatch?.[1] || null;
|
||||||
};
|
};
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
import { useCallback, useState, useMemo, useEffect, useRef } from 'react';
|
import { useCallback, useState, useMemo, useRef } from 'react';
|
||||||
import { useNIP98 } from './useNIP98';
|
import { useNIP98 } from './useNIP98';
|
||||||
import { NPCClient, JWTAuthProvider } from 'npubcash-sdk';
|
import { NPCClient, JWTAuthProvider } from 'npubcash-sdk';
|
||||||
import type { User, Quote } from 'npubcash-types';
|
import type { Quote } from 'npubcash-types';
|
||||||
|
import type { Manager } from 'coco-cashu-core';
|
||||||
|
import type { EventTemplate, Event } from 'nostr-tools';
|
||||||
|
import { useToast } from './useToast';
|
||||||
|
|
||||||
const NPUBCASH_BASE_URL = 'https://npubx.cash';
|
const NPUBCASH_BASE_URL = 'https://npubx.cash';
|
||||||
|
|
||||||
@@ -17,6 +20,7 @@ export interface NpubCashUserInfo {
|
|||||||
*/
|
*/
|
||||||
export function useNpubCash() {
|
export function useNpubCash() {
|
||||||
const { createAuthHeader, signer, isLoggedIn, pubkey } = useNIP98();
|
const { createAuthHeader, signer, isLoggedIn, pubkey } = useNIP98();
|
||||||
|
const { toast } = useToast();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
@@ -27,7 +31,7 @@ export function useNpubCash() {
|
|||||||
const npcClient = useMemo(() => {
|
const npcClient = useMemo(() => {
|
||||||
if (!isLoggedIn || !signer) return null;
|
if (!isLoggedIn || !signer) return null;
|
||||||
// Adapt NostrSigner to JWTAuthProvider's expected SigningFunc signature
|
// Adapt NostrSigner to JWTAuthProvider's expected SigningFunc signature
|
||||||
const signingFunc = async (eventTemplate: any) => {
|
const signingFunc = async (eventTemplate: EventTemplate): Promise<Event> => {
|
||||||
return await signer.signEvent(eventTemplate);
|
return await signer.signEvent(eventTemplate);
|
||||||
};
|
};
|
||||||
const auth = new JWTAuthProvider(NPUBCASH_BASE_URL, signingFunc);
|
const auth = new JWTAuthProvider(NPUBCASH_BASE_URL, signingFunc);
|
||||||
@@ -105,7 +109,7 @@ export function useNpubCash() {
|
|||||||
return npcClient.subscribe(onUpdate, onError);
|
return npcClient.subscribe(onUpdate, onError);
|
||||||
}, [npcClient]);
|
}, [npcClient]);
|
||||||
|
|
||||||
const refreshQuotes = useCallback(async (coco: any, toast: any): Promise<void> => {
|
const refreshQuotes = useCallback(async (coco: Manager): Promise<void> => {
|
||||||
if (!npcClient || !coco) return;
|
if (!npcClient || !coco) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -176,12 +180,12 @@ export function useNpubCash() {
|
|||||||
description: err instanceof Error ? err.message : 'Failed to refresh quotes',
|
description: err instanceof Error ? err.message : 'Failed to refresh quotes',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [npcClient, getAllQuotes]);
|
}, [npcClient, getAllQuotes, toast]);
|
||||||
|
|
||||||
const clearError = useCallback(() => setError(null), []);
|
const clearError = useCallback(() => setError(null), []);
|
||||||
|
|
||||||
// Subscribe to quote updates and sync to wallet automatically
|
// Subscribe to quote updates and sync to wallet automatically
|
||||||
const syncQuotesWithWallet = useCallback(async (coco: any, toast: any): Promise<() => void> => {
|
const syncQuotesWithWallet = useCallback(async (coco: Manager): Promise<() => void> => {
|
||||||
if (!npcClient || !coco) return () => {};
|
if (!npcClient || !coco) return () => {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -291,7 +295,7 @@ export function useNpubCash() {
|
|||||||
});
|
});
|
||||||
return () => {};
|
return () => {};
|
||||||
}
|
}
|
||||||
}, [npcClient, getAllQuotes, getQuotesSince, subscribeToQuotes]);
|
}, [npcClient, getAllQuotes, getQuotesSince, subscribeToQuotes, toast]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// Core methods
|
// Core methods
|
||||||
|
|||||||
+2
-2
@@ -7,8 +7,8 @@ import { ErrorBoundary } from '@/components/ErrorBoundary';
|
|||||||
import App from './App.tsx';
|
import App from './App.tsx';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
|
|
||||||
// FIXME: a custom font should be used. Eg:
|
// TODO: Add custom font from @fontsource-variable
|
||||||
// import '@fontsource-variable/<font-name>';
|
// Example: import '@fontsource-variable/<font-name>';
|
||||||
|
|
||||||
createRoot(document.getElementById("root")!).render(
|
createRoot(document.getElementById("root")!).render(
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import { useSeoMeta } from '@unhead/react';
|
import { useSeoMeta } from '@unhead/react';
|
||||||
|
|
||||||
// FIXME: Update this page (the content is just a fallback if you fail to update the page)
|
// TODO: Customize this index page with specific content
|
||||||
|
|
||||||
const Index = () => {
|
const Index = () => {
|
||||||
useSeoMeta({
|
useSeoMeta({
|
||||||
|
|||||||
Reference in new issue
Block a user