remove walletUtil file and put mint utils in mintManager

This commit is contained in:
lemonknowsall committed 2025-11-03 13:10:20 -08:00
1 parent 7d6ca0f71e
commit 604d13f847
3 files changed
+27 -26

No files matched your search

+26 -1
View File
@@ -1,5 +1,4 @@
import { useState, useCallback } from 'react'; import { useState, useCallback } from 'react';
import { getCleanMintLabel } from './walletUtils';
import type { Manager, Repositories } from 'coco-cashu-core'; import type { Manager, Repositories } from 'coco-cashu-core';
import { toast } from '@/hooks/useToast'; import { toast } from '@/hooks/useToast';
@@ -8,6 +7,32 @@ export interface CashuMint {
name?: string; 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 { interface UseMintManagerProps {
coco: Manager | null; coco: Manager | null;
mints: CashuMint[]; mints: CashuMint[];
+1 -1
View File
@@ -1,5 +1,5 @@
import { useState, useCallback } from 'react'; import { useState, useCallback } from 'react';
import { isUnknownMintError, extractMintUrlFromError } from './walletUtils'; import { isUnknownMintError, extractMintUrlFromError } from './useMintManager';
import type { Manager } from 'coco-cashu-core'; import type { Manager } from 'coco-cashu-core';
import type { Token } from '@cashu/cashu-ts'; import type { Token } from '@cashu/cashu-ts';
import { useToast } from '@/hooks/useToast'; import { useToast } from '@/hooks/useToast';
-24
View File
@@ -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;
};