kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Update create-wallet and fetch wallet data
rodzic
1ea2ceb048
commit
39bc0635ba
|
@ -89,7 +89,7 @@ const ZapsModal: React.FC<IZapsModal> = ({ onClose, statusId }) => {
|
|||
return (
|
||||
<div key={index}>
|
||||
<Text weight='bold'>
|
||||
{account.type === 'lightning' ? shortNumberFormat(account.amount / 1000) : shortNumberFormat(account.amount)}
|
||||
{account.type === 'zap' ? shortNumberFormat(account.amount / 1000) : shortNumberFormat(account.amount)}
|
||||
</Text>
|
||||
<AccountContainer id={account.id} note={account.comment} emoji='⚡' />
|
||||
</div>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import moreIcon from '@tabler/icons/outline/dots-circle-horizontal.svg';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
import List, { ListItem } from 'soapbox/components/list.tsx';
|
||||
|
@ -7,6 +8,7 @@ import { Card, CardBody, CardHeader, CardTitle } from 'soapbox/components/ui/car
|
|||
import { Column } from 'soapbox/components/ui/column.tsx';
|
||||
import Spinner from 'soapbox/components/ui/spinner.tsx';
|
||||
import Stack from 'soapbox/components/ui/stack.tsx';
|
||||
import Text from 'soapbox/components/ui/text.tsx';
|
||||
import { SelectDropdown } from 'soapbox/features/forms/index.tsx';
|
||||
import Balance from 'soapbox/features/wallet/components/balance.tsx';
|
||||
import CreateWallet from 'soapbox/features/wallet/components/create-wallet.tsx';
|
||||
|
@ -23,6 +25,10 @@ const messages = defineMessages({
|
|||
management: { id: 'wallet.management', defaultMessage: 'Wallet Management' },
|
||||
mints: { id: 'wallet.mints', defaultMessage: 'Mints' },
|
||||
more: { id: 'wallet.transactions.more', defaultMessage: 'More' },
|
||||
loading: { id: 'wallet.loading', defaultMessage: 'Loading…' },
|
||||
error: { id: 'wallet.loading_error', defaultMessage: 'An unexpected error occurred while loading your wallet data.' },
|
||||
retrying: { id: 'wallet.retrying', defaultMessage: 'Retrying in {seconds}s…' },
|
||||
retry: { id: 'wallet.retry', defaultMessage: 'Retry Now' },
|
||||
});
|
||||
|
||||
const paymentMethods = {
|
||||
|
@ -30,25 +36,92 @@ const paymentMethods = {
|
|||
cashu: 'cashu',
|
||||
};
|
||||
|
||||
const RETRY_DELAY = 5000;
|
||||
|
||||
/** User Wallet page. */
|
||||
const Wallet = () => {
|
||||
const intl = useIntl();
|
||||
const [isRetrying, setIsRetrying] = useState(false);
|
||||
const [retrySeconds, setRetrySeconds] = useState(RETRY_DELAY / 1000);
|
||||
const [retryTimer, setRetryTimer] = useState<NodeJS.Timeout | null>(null);
|
||||
|
||||
const { account } = useOwnAccount();
|
||||
const { wallet: walletData, isLoading } = useWallet();
|
||||
const { wallet: walletData, isLoading, error, getWallet } = useWallet();
|
||||
const { method, changeMethod } = usePaymentMethod();
|
||||
const { transactions } = useTransactions();
|
||||
const hasTransactions = transactions && transactions.length > 0;
|
||||
|
||||
// Function to handle manual retry
|
||||
const handleRetry = () => {
|
||||
// Clear any existing timer
|
||||
if (retryTimer) {
|
||||
clearInterval(retryTimer);
|
||||
setRetryTimer(null);
|
||||
}
|
||||
|
||||
setIsRetrying(false);
|
||||
getWallet(true); // Trigger wallet reload with error messages
|
||||
};
|
||||
|
||||
// Setup automatic retry when there's an error
|
||||
useEffect(() => {
|
||||
if (error && !isLoading && !isRetrying) {
|
||||
setIsRetrying(true);
|
||||
setRetrySeconds(RETRY_DELAY / 1000);
|
||||
|
||||
// Start countdown timer
|
||||
const timer = setInterval(() => {
|
||||
setRetrySeconds(prevSeconds => {
|
||||
if (prevSeconds <= 1) {
|
||||
clearInterval(timer);
|
||||
handleRetry();
|
||||
return RETRY_DELAY / 1000;
|
||||
}
|
||||
return prevSeconds - 1;
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
setRetryTimer(timer);
|
||||
|
||||
// Cleanup timer on unmount
|
||||
return () => {
|
||||
clearInterval(timer);
|
||||
};
|
||||
}
|
||||
}, [error, isLoading, isRetrying]);
|
||||
|
||||
// Cleanup timer on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (retryTimer) {
|
||||
clearInterval(retryTimer);
|
||||
}
|
||||
};
|
||||
}, [retryTimer]);
|
||||
|
||||
if (!account) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
{isLoading ? (
|
||||
{isLoading && (
|
||||
<Stack className='h-screen items-center justify-center'>
|
||||
<Spinner size={50} withText={false} />
|
||||
<Text>{intl.formatMessage(messages.loading)}</Text>
|
||||
</Stack>
|
||||
) : (
|
||||
)}
|
||||
{error && !isLoading && (
|
||||
<Stack className='h-screen items-center justify-center space-y-4'>
|
||||
<Text size='xl' weight='bold' theme='danger'>{intl.formatMessage(messages.error)}</Text>
|
||||
<Text>{error}</Text>
|
||||
{isRetrying && (
|
||||
<Text>{intl.formatMessage(messages.retrying, { seconds: retrySeconds })}</Text>
|
||||
)}
|
||||
<Button onClick={handleRetry} theme='primary'>
|
||||
{intl.formatMessage(messages.retry)}
|
||||
</Button>
|
||||
</Stack>
|
||||
)}
|
||||
{!isLoading && !error && (
|
||||
<Column label={intl.formatMessage(messages.wallet)} transparent withHeader={false} slim>
|
||||
<Card className='space-y-4 overflow-hidden'>
|
||||
<CardHeader>
|
||||
|
|
|
@ -714,6 +714,8 @@
|
|||
"edit_profile.success": "Your profile has been successfully saved!",
|
||||
"email_confirmation.success": "Your email has been confirmed!",
|
||||
"embed.instructions": "Embed this post on your website by copying the code below.",
|
||||
"emoji.cashu": "Cashu",
|
||||
"emoji.lightning": "Lightning",
|
||||
"emoji_button.activity": "Activity",
|
||||
"emoji_button.add_custom": "Add custom emoji",
|
||||
"emoji_button.custom": "Custom",
|
||||
|
@ -1296,10 +1298,14 @@
|
|||
"patron.donate": "Donate",
|
||||
"patron.title": "Funding Goal",
|
||||
"payment_method.button.text.raw": "Zap {amount} sats",
|
||||
"payment_method.button.zap_sats": "Zap sats",
|
||||
"payment_method.cashu": "Cashu",
|
||||
"payment_method.cashu.split_disabled": "Switch to ⚡ for splits",
|
||||
"payment_method.comment_input.placeholder": "Optional comment",
|
||||
"payment_method.lightning": "Lightning",
|
||||
"payment_method.send_to": "Send sats via {method} to {target}",
|
||||
"payment_method.split_message.deducted": "{amountDeducted} sats will deducted*",
|
||||
"payment_method.unit": "sats",
|
||||
"pinned_accounts.title": "{name}’s choices",
|
||||
"pinned_statuses.none": "No pins to show.",
|
||||
"poll.choose_multiple": "Choose as many as you'd like.",
|
||||
|
@ -1724,6 +1730,7 @@
|
|||
"wallet.button.withdraw": "Withdraw",
|
||||
"wallet.create_wallet.question": "Do you want create one?",
|
||||
"wallet.create_wallet.title": "You don't have a wallet",
|
||||
"wallet.hidden.balance": "••••••",
|
||||
"wallet.invalid_url": "All strings must be valid URLs.",
|
||||
"wallet.loading": "Loading…",
|
||||
"wallet.loading_error": "An unexpected error occurred while loading your wallet data.",
|
||||
|
@ -1737,6 +1744,8 @@
|
|||
"wallet.relays.empty": "At least one relay is required.",
|
||||
"wallet.relays.error": "Failed to update relays.",
|
||||
"wallet.relays.success": "Relays updated with success!",
|
||||
"wallet.retry": "Retry Now",
|
||||
"wallet.retrying": "Retrying in {seconds}s…",
|
||||
"wallet.sats": "{amount} sats",
|
||||
"wallet.title": "Wallet",
|
||||
"wallet.transactions": "Transactions",
|
||||
|
|
Ładowanie…
Reference in New Issue