kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Update create-wallet
rodzic
a2213c90a5
commit
094dba97a6
|
@ -3,7 +3,6 @@ import plusIcon from '@tabler/icons/outline/square-rounded-plus.svg';
|
|||
import { useState } from 'react';
|
||||
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
|
||||
import Button from 'soapbox/components/ui/button.tsx';
|
||||
import FormActions from 'soapbox/components/ui/form-actions.tsx';
|
||||
import Form from 'soapbox/components/ui/form.tsx';
|
||||
|
@ -17,8 +16,8 @@ import { useCreateWallet } from 'soapbox/features/wallet/hooks/useHooks.ts';
|
|||
import { useOwnAccount } from 'soapbox/hooks/useOwnAccount.ts';
|
||||
|
||||
const messages = defineMessages({
|
||||
title: { id: 'wallet.create_wallet.title', defaultMessage: 'You don\'t have a wallet' },
|
||||
question: { id: 'wallet.create_wallet.question', defaultMessage: 'Do you want create one?' },
|
||||
title: { id: 'wallet.create.title', defaultMessage: 'You don\'t have a wallet' },
|
||||
question: { id: 'wallet.create.question', defaultMessage: 'Do you want create one?' },
|
||||
button: { id: 'wallet.button.create_wallet', defaultMessage: 'Create' },
|
||||
mints: { id: 'wallet.mints', defaultMessage: 'Mints' },
|
||||
});
|
||||
|
|
|
@ -9,6 +9,7 @@ import toast from 'soapbox/toast.tsx';
|
|||
import type { Account as AccountEntity, Status as StatusEntity } from 'soapbox/types/entities.ts';
|
||||
|
||||
const messages = defineMessages({
|
||||
createWallet: { id: 'wallet.create.success', defaultMessage: 'Wallet created successfully!' },
|
||||
success: { id: 'wallet.success', defaultMessage: 'Data updated with success!' },
|
||||
error: { id: 'wallet.error', defaultMessage: 'Failed to update.' },
|
||||
});
|
||||
|
@ -81,6 +82,7 @@ const useWalletStore = create<WalletState>((set) => ({
|
|||
|
||||
const useCreateWallet = () => {
|
||||
const api = useApi();
|
||||
const intl = useIntl();
|
||||
const queryClient = useQueryClient();
|
||||
const { setWallet } = useWalletStore();
|
||||
|
||||
|
@ -91,7 +93,7 @@ const useCreateWallet = () => {
|
|||
return baseWalletSchema.parse(data);
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
toast.success('Wallet created successfully');
|
||||
toast.success(intl.formatMessage(messages.createWallet));
|
||||
setWallet(data);
|
||||
queryClient.invalidateQueries({ queryKey: ['wallet'] });
|
||||
},
|
||||
|
@ -136,35 +138,37 @@ const useWallet = () => {
|
|||
|
||||
const useTransactions = () => {
|
||||
const api = useApi();
|
||||
const { transactions, nextTransaction, setTransactions } = useWalletStore();
|
||||
const { setTransactions } = useWalletStore();
|
||||
|
||||
const getTransactions = useQuery({
|
||||
queryKey: ['transactions'],
|
||||
queryFn: async () => {
|
||||
const response = await api.get('/api/v1/ditto/cashu/transactions');
|
||||
const { prev, next } = response.pagination();
|
||||
const { prev, next: nextPag } = response.pagination();
|
||||
const data = await response.json();
|
||||
const normalizedData = transactionsSchema.parse(data);
|
||||
|
||||
setTransactions(normalizedData, prev, next);
|
||||
setTransactions(normalizedData, prev, nextPag);
|
||||
return normalizedData;
|
||||
},
|
||||
});
|
||||
|
||||
const expandTransactions = useMutation({
|
||||
mutationFn: async () => {
|
||||
const { transactions, nextTransaction } = useWalletStore.getState();
|
||||
|
||||
if (!nextTransaction || !transactions) {
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await api.get(nextTransaction);
|
||||
const { prev, next } = response.pagination();
|
||||
const { prev, next: nextPag } = response.pagination();
|
||||
const data = await response.json();
|
||||
|
||||
const normalizedData = transactionsSchema.parse(data);
|
||||
const newTransactions = [...transactions, ...normalizedData];
|
||||
|
||||
setTransactions(newTransactions, prev, next);
|
||||
setTransactions(newTransactions, prev, nextPag);
|
||||
},
|
||||
onError: (error: any) => {
|
||||
toast.error(error?.message || 'Error expanding transactions');
|
||||
|
|
|
@ -1729,8 +1729,9 @@
|
|||
"wallet.button.create_wallet": "Create",
|
||||
"wallet.button.mint": "Mint",
|
||||
"wallet.button.withdraw": "Withdraw",
|
||||
"wallet.create_wallet.question": "Do you want create one?",
|
||||
"wallet.create_wallet.title": "You don't have a wallet",
|
||||
"wallet.create.question": "Do you want create one?",
|
||||
"wallet.create.success": "Wallet created successfully!",
|
||||
"wallet.create.title": "You don't have a wallet",
|
||||
"wallet.error": "Failed to update.",
|
||||
"wallet.hidden.balance": "••••••",
|
||||
"wallet.invalid_url": "All strings must be valid URLs.",
|
||||
|
|
Ładowanie…
Reference in New Issue