mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 08:23:35 +00:00
remove walletUtil file and put mint utils in mintManager
This commit is contained in:
1 parent
7d6ca0f71e
commit
604d13f847
3 files changed
+27
-26
No files matched your search
@@ -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[];
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
Reference in new issue
Block a user