kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
mint the mint and get wallet
rodzic
ecde1b9ebc
commit
3fad16baf5
|
@ -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,
|
||||
|
|
|
@ -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<string[]>([]);
|
||||
|
||||
|
@ -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 (
|
||||
<Column label={intl.formatMessage(messages.title)}>
|
||||
<Form onSubmit={handleCreateWalletSubmit}>
|
||||
|
@ -276,6 +320,54 @@ const Cashu = () => {
|
|||
</FormActions>
|
||||
</Stack>
|
||||
</Form>
|
||||
|
||||
<Form onSubmit={handleMintTheMintQuoteState}>
|
||||
<Stack space={4}>
|
||||
|
||||
<Streamfield
|
||||
label={intl.formatMessage(messages.mint_the_mint)}
|
||||
component={CashuInput}
|
||||
values={mints}
|
||||
onChange={handleStreamItemChange()}
|
||||
onAddItem={handleAddMint}
|
||||
onRemoveItem={deleteStreamItem()}
|
||||
/>
|
||||
|
||||
<FormActions>
|
||||
<Button to='/settings' theme='tertiary'>
|
||||
<FormattedMessage id='common.cancel' defaultMessage='Cancel' />
|
||||
</Button>
|
||||
|
||||
<Button theme='primary' type='submit'>
|
||||
<FormattedMessage id='edit_profile.save' defaultMessage='Save' />
|
||||
</Button>
|
||||
</FormActions>
|
||||
</Stack>
|
||||
</Form>
|
||||
|
||||
<Form onSubmit={handleGetWallet}>
|
||||
<Stack space={4}>
|
||||
|
||||
<Streamfield
|
||||
label={intl.formatMessage(messages.get_wallet)}
|
||||
component={CashuInput}
|
||||
values={mints}
|
||||
onChange={handleStreamItemChange()}
|
||||
onAddItem={handleAddMint}
|
||||
onRemoveItem={deleteStreamItem()}
|
||||
/>
|
||||
|
||||
<FormActions>
|
||||
<Button to='/settings' theme='tertiary'>
|
||||
<FormattedMessage id='common.cancel' defaultMessage='Cancel' />
|
||||
</Button>
|
||||
|
||||
<Button theme='primary' type='submit'>
|
||||
<FormattedMessage id='edit_profile.save' defaultMessage='Save' />
|
||||
</Button>
|
||||
</FormActions>
|
||||
</Stack>
|
||||
</Form>
|
||||
</Column>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -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://<mint-url>",
|
||||
"nostr_extension.found": "<link>Sign in</link> with browser extension.",
|
||||
"nostr_extension.not_found": "Browser extension not found.",
|
||||
|
|
Ładowanie…
Reference in New Issue