diff --git a/.changeset/fix-fan-club-locked-content.md b/.changeset/fix-fan-club-locked-content.md new file mode 100644 index 00000000000..bbca890985b --- /dev/null +++ b/.changeset/fix-fan-club-locked-content.md @@ -0,0 +1,5 @@ +--- +"@audius/common": patch +--- + +Invalidate fan club feed and comment queries after coin swaps so locked content unlocks without requiring a page refresh diff --git a/packages/common/src/api/tan-query/jupiter/useSwapCoins.ts b/packages/common/src/api/tan-query/jupiter/useSwapCoins.ts index f1b8608bc49..857007ea29a 100644 --- a/packages/common/src/api/tan-query/jupiter/useSwapCoins.ts +++ b/packages/common/src/api/tan-query/jupiter/useSwapCoins.ts @@ -6,8 +6,10 @@ import { getArtistCoinQueryKey, updateAudioBalanceOptimistically, useCurrentAccountUser, - useQueryContext + useQueryContext, + getFanClubFeedQueryKey } from '~/api' +import { QUERY_KEYS } from '~/api/tan-query/queryKeys' import type { QueryContextType } from '~/api/tan-query/utils/QueryContext' import { Feature } from '~/models' import type { User } from '~/models/User' @@ -189,6 +191,22 @@ export const optimisticallyUpdateSwapBalances = ( }) } + // Invalidate fan club feed and comment queries so locked content is re-evaluated + if (inputMint && !isInputAudio) { + queryClient.invalidateQueries({ + queryKey: getFanClubFeedQueryKey({ mint: inputMint }) + }) + } + if (outputMint && !isOutputAudio) { + queryClient.invalidateQueries({ + queryKey: getFanClubFeedQueryKey({ mint: outputMint }) + }) + } + // Invalidate individual comment queries so locked posts refetch with access + queryClient.invalidateQueries({ + queryKey: [QUERY_KEYS.comment] + }) + // Invalidate user query to ensure user data is fresh after swap queryClient.invalidateQueries({ queryKey: getUserQueryKey(user?.user_id) diff --git a/packages/common/src/store/ui/buy-sell/useBuySellSwap.ts b/packages/common/src/store/ui/buy-sell/useBuySellSwap.ts index a2c6a6f295d..169867717b8 100644 --- a/packages/common/src/store/ui/buy-sell/useBuySellSwap.ts +++ b/packages/common/src/store/ui/buy-sell/useBuySellSwap.ts @@ -6,7 +6,8 @@ import { SLIPPAGE_BPS, useArtistCoin, useCurrentAccountUser, - getArtistCoinQueryKey + getArtistCoinQueryKey, + getFanClubFeedQueryKey } from '~/api' import { SwapStatus, SwapTokensResult } from '~/api/tan-query/jupiter/types' import { TQTrack } from '~/api/tan-query/models' @@ -132,6 +133,22 @@ export const useBuySellSwap = (props: UseBuySellSwapProps) => { }) } + // Invalidate fan club feed and comment queries so locked content is re-evaluated + if (baseCoin?.mint) { + queryClient.invalidateQueries({ + queryKey: getFanClubFeedQueryKey({ mint: baseCoin.mint }) + }) + } + if (quoteCoin?.mint) { + queryClient.invalidateQueries({ + queryKey: getFanClubFeedQueryKey({ mint: quoteCoin.mint }) + }) + } + // Invalidate individual comment queries so locked posts refetch with access + queryClient.invalidateQueries({ + queryKey: [QUERY_KEYS.comment] + }) + // Invalidate track queries to provide track access if the user has traded the artist coin const baseOwnerId = baseCoin?.ownerId ?? null const quoteOwnerId = quoteCoin?.ownerId ?? null