@@ -2,7 +2,7 @@ import { AudiusSdk } from '@audius/sdk'
22import { QueryClient , useQuery , useQueryClient } from '@tanstack/react-query'
33
44import { accountFromSDK } from '~/adapters/user'
5- import { primeUserData , useQueryContext } from '~/api/tan-query/utils'
5+ import { useQueryContext } from '~/api/tan-query/utils'
66import { useAppContext } from '~/context/appContext'
77import { Status } from '~/models'
88import { UserMetadata } from '~/models/User'
@@ -11,7 +11,6 @@ import { AccountState } from '~/store'
1111
1212import { QUERY_KEYS } from '../../queryKeys'
1313import { QueryKey , SelectableQueryOptions } from '../../types'
14- import { getUserQueryKey } from '../useUser'
1514
1615import { getAccountStatusQueryKey } from './useAccountStatus'
1716import { useWalletAddresses } from './useWalletAddresses'
@@ -22,20 +21,11 @@ export const getCurrentAccountQueryKey = () =>
2221 QUERY_KEYS . accountUser
2322 ] as unknown as QueryKey < AccountState >
2423
25- const getLocalAccount = (
26- localStorage : LocalStorage ,
27- queryClient : QueryClient
28- ) => {
24+ const getLocalAccount = ( localStorage : LocalStorage ) => {
2925 const localAccount = localStorage . getAudiusAccountSync ?.( )
3026 const localAccountUser =
3127 localStorage . getAudiusAccountUserSync ?.( ) as UserMetadata
3228 if ( localAccount && localAccountUser ) {
33- if (
34- localAccountUser &&
35- ! queryClient . getQueryData ( getUserQueryKey ( localAccountUser . user_id ) )
36- ) {
37- primeUserData ( { users : [ localAccountUser ] , queryClient } )
38- }
3929 // feature-tan-query TODO: when removing account sagas,
4030 // need to add wallets and local account user from local storage
4131 return {
@@ -57,15 +47,9 @@ const getLocalAccount = (
5747
5848export const getCurrentAccountQueryFn = async (
5949 sdk : AudiusSdk ,
60- localStorage : LocalStorage ,
6150 currentUserWallet : string | null ,
6251 queryClient : QueryClient
6352) : Promise < AccountState | null | undefined > => {
64- const localAccount = getLocalAccount ( localStorage , queryClient )
65- if ( localAccount ) {
66- return localAccount
67- }
68-
6953 if ( ! currentUserWallet ) {
7054 return null
7155 }
@@ -83,7 +67,6 @@ export const getCurrentAccountQueryFn = async (
8367
8468 if ( account ) {
8569 queryClient . setQueryData ( getAccountStatusQueryKey ( ) , Status . SUCCESS )
86- primeUserData ( { users : [ account . user ] , queryClient } )
8770 } else {
8871 queryClient . setQueryData ( getAccountStatusQueryKey ( ) , Status . ERROR )
8972 }
@@ -120,11 +103,12 @@ export const useCurrentAccount = <TResult = AccountState | null | undefined>(
120103 queryFn : async ( ) =>
121104 getCurrentAccountQueryFn (
122105 await audiusSdk ( ) ,
123- localStorage ,
124106 currentUserWallet ! ,
125107 queryClient
126108 ) ,
127109 staleTime : Infinity ,
110+ // Use function form so localStorage is only accessed once on initial mount
111+ initialData : ( ) => getLocalAccount ( localStorage ) ?? undefined ,
128112 gcTime : Infinity ,
129113 enabled : options ?. enabled !== false && ! ! currentUserWallet ,
130114 ...options
0 commit comments