diff --git a/src/hooks/cashu/useMintManager.ts b/src/hooks/cashu/useMintManager.ts index eb69b9b..6cdb002 100644 --- a/src/hooks/cashu/useMintManager.ts +++ b/src/hooks/cashu/useMintManager.ts @@ -1,5 +1,4 @@ import { useState, useCallback } from 'react'; -import { getCleanMintLabel } from './walletUtils'; import type { Manager, Repositories } from 'coco-cashu-core'; import { toast } from '@/hooks/useToast'; @@ -8,6 +7,32 @@ export interface CashuMint { name?: string; } +// Mint utility functions +export const getCleanMintLabel = (mint: { name?: string; url: string }): string => { + if (mint.name && mint.name.trim().length > 0) { + return mint.name.replace(/^https?:\/\//, ''); + } + try { + return new URL(mint.url).host; + } catch { + return mint.url.replace(/^https?:\/\//, ''); + } +}; + +export const isUnknownMintError = (err: unknown): boolean => { + 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 instanceof Error ? err.message : String(err); + const mintUrlMatch = errorMessage.match(/Mint (https?:\/\/[^\s]+)/); + return mintUrlMatch?.[1] || null; +}; + interface UseMintManagerProps { coco: Manager | null; mints: CashuMint[]; diff --git a/src/hooks/cashu/useTokenOperations.ts b/src/hooks/cashu/useTokenOperations.ts index d93fe55..d89a37c 100644 --- a/src/hooks/cashu/useTokenOperations.ts +++ b/src/hooks/cashu/useTokenOperations.ts @@ -1,5 +1,5 @@ import { useState, useCallback } from 'react'; -import { isUnknownMintError, extractMintUrlFromError } from './walletUtils'; +import { isUnknownMintError, extractMintUrlFromError } from './useMintManager'; import type { Manager } from 'coco-cashu-core'; import type { Token } from '@cashu/cashu-ts'; import { useToast } from '@/hooks/useToast'; diff --git a/src/hooks/cashu/walletUtils.ts b/src/hooks/cashu/walletUtils.ts deleted file mode 100644 index 186c573..0000000 --- a/src/hooks/cashu/walletUtils.ts +++ /dev/null @@ -1,24 +0,0 @@ -export const getCleanMintLabel = (mint: { name?: string; url: string }): string => { - if (mint.name && mint.name.trim().length > 0) { - return mint.name.replace(/^https?:\/\//, ''); - } - try { - return new URL(mint.url).host; - } catch { - return mint.url.replace(/^https?:\/\//, ''); - } -}; - -export const isUnknownMintError = (err: unknown): boolean => { - 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 instanceof Error ? err.message : String(err); - const mintUrlMatch = errorMessage.match(/Mint (https?:\/\/[^\s]+)/); - return mintUrlMatch?.[1] || null; -};