address testing errors

This commit is contained in:
lemonknowsall committed 2025-10-20 22:58:42 -07:00
1 parent 460a4777ee
commit 61fc4957e0
15 files changed
+45 -88

No files matched your search

+3 -2
View File
@@ -4,6 +4,7 @@ import * as bip39 from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english.js';
import { initializeCoco, ConsoleLogger, getEncodedToken, type Repositories } from 'coco-cashu-core';
import { IndexedDbRepositories } from 'coco-cashu-indexeddb';
import type { Mint } from 'coco-cashu-core';
// Types from coco-cashu-core
type CocoManager = Awaited<ReturnType<typeof initializeCoco>>;
@@ -71,7 +72,7 @@ export function useCashu(): UseCashuReturn {
try {
const mintList = await coco.mint.getAllMints();
setMints(mintList.map((m: any) => ({
setMints(mintList.map((m: Mint) => ({
url: m.mintUrl,
name: m.name,
info: m.mintInfo
@@ -197,7 +198,7 @@ export function useCashu(): UseCashuReturn {
const newBalances = await coco.wallet.getBalances();
setBalances(newBalances);
} catch (err) {
// Silent failure - errors are handled by the manager
console.log('Failed to refresh balances:', err);
}
};
+2 -2
View File
@@ -1,8 +1,8 @@
import { useState, useCallback, useEffect } from 'react';
import type { HistoryEntry } from 'coco-cashu-core';
import type { HistoryEntry, Manager } from 'coco-cashu-core';
interface UseHistoryManagerProps {
coco: any; // Coco instance
coco: Manager | null;
isInitialized: boolean;
}
+4 -4
View File
@@ -1,5 +1,7 @@
import { useState, useCallback, useEffect } from 'react';
import { getCleanMintLabel } from './walletUtils';
import type { Manager, Repositories } from 'coco-cashu-core';
import { toast } from '@/hooks/useToast';
export interface CashuMint {
url: string;
@@ -7,13 +9,12 @@ export interface CashuMint {
}
interface UseMintManagerProps {
coco: any; // Coco instance
coco: Manager | null;
mints: CashuMint[];
repositories: any; // Repositories instance
repositories: Repositories | null;
isNpubCashLoggedIn: boolean;
setNpubCashMint: (mintUrl: string) => Promise<boolean>;
refreshMints: () => Promise<void>;
toast: any; // Toast function
}
export function useMintManager({
@@ -23,7 +24,6 @@ export function useMintManager({
isNpubCashLoggedIn,
setNpubCashMint,
refreshMints,
toast,
}: UseMintManagerProps) {
const [activeMintUrl, setActiveMintUrl] = useState<string | null>(null);
const [mintDropdownOpen, setMintDropdownOpen] = useState(false);
+6 -8
View File
@@ -1,15 +1,15 @@
import { useState, useCallback, useRef, useEffect } from 'react';
import { isUnknownMintError, extractMintUrlFromError } from './walletUtils';
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 {
coco: any; // Coco instance
coco: Manager | null;
activeMintUrl: string | null;
isNpubCashLoggedIn: boolean;
repositories: any; // Repositories instance
generateQRCode: (text: string) => Promise<string>;
toast: any; // Toast function
getEncodedToken: (token: any) => string;
getEncodedToken: (token: Token | string) => string;
getLightningInvoice: (params: {
lightningAddress: string;
amountSats: number;
@@ -19,13 +19,11 @@ interface UseWalletTransactionsProps {
export function useWalletTransactions({
coco,
activeMintUrl,
isNpubCashLoggedIn,
repositories,
generateQRCode,
toast,
getEncodedToken,
getLightningInvoice,
}: UseWalletTransactionsProps) {
const { toast } = useToast();
// Receive state
const [tokenInput, setTokenInput] = useState('');
const [quoteAmount, setQuoteAmount] = useState('');
+4 -3
View File
@@ -10,14 +10,15 @@ export const getCleanMintLabel = (mint: { name?: string; url: string }): string
};
export const isUnknownMintError = (err: unknown): boolean => {
const errorMessage = (err as any)?.message || err?.toString() || '';
return (err as any)?.constructor?.name === 'UnknownMintError' ||
const errorMessage = err instanceof Error ? err.message : String(err);
const errorName = err instanceof Error ? err.constructor.name : '';
return errorName === 'UnknownMintError' ||
errorMessage.includes('UnknownMintError') ||
(errorMessage.includes('Mint') && errorMessage.includes('is not known'));
};
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]+)/);
return mintUrlMatch?.[1] || null;
};