kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Update fetch wallet data
rodzic
92aa009de9
commit
f3873b55ba
|
@ -48,7 +48,7 @@ import DropdownMenu from 'soapbox/components/dropdown-menu/index.ts';
|
|||
import PureStatusReactionWrapper from 'soapbox/components/pure-status-reaction-wrapper.tsx';
|
||||
import StatusActionButton from 'soapbox/components/status-action-button.tsx';
|
||||
import HStack from 'soapbox/components/ui/hstack.tsx';
|
||||
import { useZapCashuRequest, useWallet } from 'soapbox/features/zap/hooks/useHooks.ts';
|
||||
import { useZapCashuRequest, useWalletStore } from 'soapbox/features/zap/hooks/useHooks.ts';
|
||||
import { useAppDispatch } from 'soapbox/hooks/useAppDispatch.ts';
|
||||
import { useAppSelector } from 'soapbox/hooks/useAppSelector.ts';
|
||||
import { useDislike } from 'soapbox/hooks/useDislike.ts';
|
||||
|
@ -180,7 +180,7 @@ const PureStatusActionBar: React.FC<IPureStatusActionBar> = ({
|
|||
const features = useFeatures();
|
||||
const { boostModal, deleteModal } = useSettings();
|
||||
|
||||
const { wallet } = useWallet();
|
||||
const { acceptsZapsCashu } = useWalletStore();
|
||||
const { zapCashuList } = useZapCashuRequest();
|
||||
const isZappedCashu = zapCashuList.some((zapCashu)=> zapCashu === status.id);
|
||||
|
||||
|
@ -764,7 +764,6 @@ const PureStatusActionBar: React.FC<IPureStatusActionBar> = ({
|
|||
|
||||
const canShare = ('share' in navigator) && (status.visibility === 'public' || status.visibility === 'group');
|
||||
const acceptsZaps = status.account.ditto.accepts_zaps === true;
|
||||
const hasWallet = wallet !== null;
|
||||
|
||||
const spacing: {
|
||||
[key: string]: React.ComponentProps<typeof HStack>['space'];
|
||||
|
@ -848,7 +847,7 @@ const PureStatusActionBar: React.FC<IPureStatusActionBar> = ({
|
|||
/>
|
||||
)}
|
||||
|
||||
{(acceptsZaps || hasWallet) && (
|
||||
{(acceptsZaps || acceptsZapsCashu) && (
|
||||
<StatusActionButton
|
||||
title={intl.formatMessage(messages.zap)}
|
||||
icon={boltIcon}
|
||||
|
|
|
@ -49,7 +49,7 @@ import DropdownMenu from 'soapbox/components/dropdown-menu/index.ts';
|
|||
import StatusActionButton from 'soapbox/components/status-action-button.tsx';
|
||||
import StatusReactionWrapper from 'soapbox/components/status-reaction-wrapper.tsx';
|
||||
import HStack from 'soapbox/components/ui/hstack.tsx';
|
||||
import { useZapCashuRequest, useWallet } from 'soapbox/features/zap/hooks/useHooks.ts';
|
||||
import { useZapCashuRequest, useWalletStore } from 'soapbox/features/zap/hooks/useHooks.ts';
|
||||
import { useAppDispatch } from 'soapbox/hooks/useAppDispatch.ts';
|
||||
import { useAppSelector } from 'soapbox/hooks/useAppSelector.ts';
|
||||
import { useFeatures } from 'soapbox/hooks/useFeatures.ts';
|
||||
|
@ -175,7 +175,7 @@ const StatusActionBar: React.FC<IStatusActionBar> = ({
|
|||
const features = useFeatures();
|
||||
const { boostModal, deleteModal } = useSettings();
|
||||
|
||||
const { wallet } = useWallet();
|
||||
const { acceptsZapsCashu } = useWalletStore();
|
||||
const { zapCashuList } = useZapCashuRequest();
|
||||
const isZappedCashu = zapCashuList.some((zapCashu)=> zapCashu === status.id);
|
||||
|
||||
|
@ -754,7 +754,6 @@ const StatusActionBar: React.FC<IStatusActionBar> = ({
|
|||
|
||||
const canShare = ('share' in navigator) && (status.visibility === 'public' || status.visibility === 'group');
|
||||
const acceptsZaps = status.account.ditto.accepts_zaps === true;
|
||||
const hasWallet = wallet !== null;
|
||||
|
||||
const spacing: {
|
||||
[key: string]: React.ComponentProps<typeof HStack>['space'];
|
||||
|
@ -838,7 +837,7 @@ const StatusActionBar: React.FC<IStatusActionBar> = ({
|
|||
/>
|
||||
)}
|
||||
|
||||
{(acceptsZaps || hasWallet) && (
|
||||
{(acceptsZaps || acceptsZapsCashu) && (
|
||||
<StatusActionButton
|
||||
title={intl.formatMessage(messages.zap)}
|
||||
icon={boltIcon}
|
||||
|
|
|
@ -9,13 +9,19 @@ import type { Account as AccountEntity, Status as StatusEntity } from 'soapbox/t
|
|||
|
||||
interface WalletState {
|
||||
wallet: WalletData | null;
|
||||
acceptsZapsCashu: boolean;
|
||||
transactions: Transactions | null;
|
||||
zapCashuList: string[];
|
||||
prevTransaction?: string | null;
|
||||
nextTransaction?: string | null;
|
||||
hasFetchedWallet: boolean;
|
||||
hasFetchedTransactions: boolean;
|
||||
|
||||
setAcceptsZapsCashu: (acceptsZapsCashu: boolean) => void;
|
||||
setWallet: (wallet: WalletData | null) => void;
|
||||
setHasFetchedWallet: (hasFetchedWallet: boolean) => void;
|
||||
setTransactions: (transactions: Transactions | null, prevTransaction?: string | null, nextTransaction?: string | null) => void;
|
||||
setHasFetchedTransactions: (hasFetched: boolean) => void;
|
||||
addZapCashu: (statusId: string) => void;
|
||||
}
|
||||
|
||||
|
@ -26,13 +32,19 @@ interface IWalletInfo {
|
|||
|
||||
const useWalletStore = create<WalletState>((set) => ({
|
||||
wallet: null,
|
||||
acceptsZapsCashu: false,
|
||||
transactions: null,
|
||||
prevTransaction: null,
|
||||
nextTransaction: null,
|
||||
zapCashuList: [],
|
||||
hasFetchedWallet: false,
|
||||
hasFetchedTransactions: false,
|
||||
|
||||
setAcceptsZapsCashu: (acceptsZapsCashu) => set({ acceptsZapsCashu }),
|
||||
setWallet: (wallet) => set({ wallet }),
|
||||
setHasFetchedWallet: (hasFetchedWallet) => set({ hasFetchedWallet }),
|
||||
setTransactions: (transactions, prevTransaction, nextTransaction) => set({ transactions, prevTransaction, nextTransaction }),
|
||||
setHasFetchedTransactions: (hasFetched) => set({ hasFetchedTransactions: hasFetched }),
|
||||
addZapCashu: (statusId) =>
|
||||
set((state) => ({
|
||||
zapCashuList: [
|
||||
|
@ -44,7 +56,7 @@ const useWalletStore = create<WalletState>((set) => ({
|
|||
|
||||
const useWallet = () => {
|
||||
const api = useApi();
|
||||
const { wallet, setWallet } = useWalletStore();
|
||||
const { wallet, setWallet, setAcceptsZapsCashu, hasFetchedWallet, setHasFetchedWallet } = useWalletStore();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
|
@ -74,6 +86,8 @@ const useWallet = () => {
|
|||
const data = await response.json();
|
||||
if (data) {
|
||||
const normalizedData = baseWalletSchema.parse(data);
|
||||
setAcceptsZapsCashu(true);
|
||||
|
||||
setWallet(normalizedData);
|
||||
}
|
||||
} catch (err) {
|
||||
|
@ -82,11 +96,13 @@ const useWallet = () => {
|
|||
setError(messageError);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
setHasFetchedWallet(true);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!wallet) {
|
||||
if (!hasFetchedWallet) {
|
||||
setHasFetchedWallet(true);
|
||||
getWallet(false);
|
||||
}
|
||||
}, []);
|
||||
|
@ -96,7 +112,7 @@ const useWallet = () => {
|
|||
|
||||
const useTransactions = () => {
|
||||
const api = useApi();
|
||||
const { transactions, nextTransaction, setTransactions } = useWalletStore();
|
||||
const { transactions, nextTransaction, setTransactions, hasFetchedTransactions, setHasFetchedTransactions } = useWalletStore();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
|
@ -144,7 +160,8 @@ const useTransactions = () => {
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!transactions) {
|
||||
if (!hasFetchedTransactions) {
|
||||
setHasFetchedTransactions(true);
|
||||
getTransactions();
|
||||
}
|
||||
}, []);
|
||||
|
@ -192,4 +209,4 @@ const useZapCashuRequest = () => {
|
|||
return { zapCashuList, isLoading, error, zapCashuRequest };
|
||||
};
|
||||
|
||||
export { useWallet, useTransactions, useZapCashuRequest };
|
||||
export { useWalletStore, useWallet, useTransactions, useZapCashuRequest };
|
|
@ -23,7 +23,7 @@ const ExplorePage: React.FC<IExplorePage> = ({ children }) => {
|
|||
const me = useAppSelector(state => state.me);
|
||||
const features = useFeatures();
|
||||
const accountsPath = useLocation().pathname === '/explore/accounts';
|
||||
const wallet = useWallet();
|
||||
const { wallet } = useWallet();
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
Ładowanie…
Reference in New Issue