From 3fad16baf5a36479ae2d064dcccbcc515692c4c1 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Wed, 19 Feb 2025 13:28:58 -0300 Subject: [PATCH] mint the mint and get wallet --- src/features/cashu/hooks/useCashu.ts | 16 +++++ src/features/cashu/index.tsx | 94 +++++++++++++++++++++++++++- src/locales/en.json | 1 + 3 files changed, 110 insertions(+), 1 deletion(-) diff --git a/src/features/cashu/hooks/useCashu.ts b/src/features/cashu/hooks/useCashu.ts index 628002aee..5d13c4d9b 100644 --- a/src/features/cashu/hooks/useCashu.ts +++ b/src/features/cashu/hooks/useCashu.ts @@ -41,7 +41,23 @@ function useCashu() { }, }); + const { mutate: getWallet } = useMutation({ + mutationFn: () => api.get('/api/v1/ditto/cashu/wallet'), + onSuccess: () => { + queryClient.refetchQueries({ queryKey: ['cashu', 'nutzap', 'info'] }); + }, + }); + + const { mutate: mintTheMint } = useMutation({ + mutationFn: (quote_id: string) => api.post(`/api/v1/ditto/cashu/mint/${quote_id}`), + onSuccess: () => { + queryClient.refetchQueries({ queryKey: ['cashu', 'nutzap', 'info'] }); + }, + }); + return { + getWallet, + mintTheMint, getQuoteState, createQuote, createWallet, diff --git a/src/features/cashu/index.tsx b/src/features/cashu/index.tsx index 0ba463df8..6e3c4f66b 100644 --- a/src/features/cashu/index.tsx +++ b/src/features/cashu/index.tsx @@ -22,11 +22,13 @@ const messages = defineMessages({ submit_success: { id: 'generic.saved', defaultMessage: 'Saved!' }, create_cashu_quote: { id: 'cashu.quote', defaultMessage: 'Create Cashu Quote' }, get_cashu_quote_state: { id: 'cashu.quote.state', defaultMessage: 'Create Cashu Quote' }, + mint_the_mint: { id: 'cashu.quote.mint', defaultMessage: 'Mint the Mint' }, + get_wallet: { id: 'cashu.get_wallet', defaultMessage: 'Get wallet' }, }); const Cashu = () => { const intl = useIntl(); - const { createWallet, createNutzapInfo, swapCashuToWallet, createQuote, getQuoteState } = useCashu(); + const { createWallet, createNutzapInfo, swapCashuToWallet, createQuote, getQuoteState, mintTheMint, getWallet } = useCashu(); const [mints, setMints] = useState([]); @@ -157,6 +159,48 @@ const Cashu = () => { }); }; + const handleMintTheMintQuoteState: React.FormEventHandler = async (event) => { + event.preventDefault(); + mintTheMint(mints[0], { + onSuccess: async () => { + toast.success(messages.submit_success); + }, + onError: async (err) => { + if (err instanceof HTTPError) { + try { + const { error } = await err.response.json(); + if (typeof error === 'string') { + toast.error(error); + return; + } + } catch { /* empty */ } + } + toast.error(err.message); + }, + }); + }; + + const handleGetWallet: React.FormEventHandler = async (event) => { + event.preventDefault(); + getWallet(undefined, { + onSuccess: async () => { + toast.success(messages.submit_success); + }, + onError: async (err) => { + if (err instanceof HTTPError) { + try { + const { error } = await err.response.json(); + if (typeof error === 'string') { + toast.error(error); + return; + } + } catch { /* empty */ } + } + toast.error(err.message); + }, + }); + }; + return (
@@ -276,6 +320,54 @@ const Cashu = () => {
+ +
+ + + + + + + + + + +
+ +
+ + + + + + + + + + +
); }; diff --git a/src/locales/en.json b/src/locales/en.json index 333dc2926..e7b416bb8 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1165,6 +1165,7 @@ "cashu.quote": "Create Cashu Quote", "cashu.quote.state": "Get Cashu Quote State", "cashu.wallet.mints": "Your mints", + "cashu.quote.mint": "Mint the Mint", "cashu.wallet.mint_placeholder": "https://", "nostr_extension.found": "Sign in with browser extension.", "nostr_extension.not_found": "Browser extension not found.",