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