Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
281 changes: 0 additions & 281 deletions packages/common/src/api/account.ts

This file was deleted.

7 changes: 6 additions & 1 deletion packages/common/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Audius query
// TODO: migrate all of these to tan-query
export * from './account'
export * from './authorizedApps'
export * from './developerApps'
export * from './library'
Expand Down Expand Up @@ -119,6 +118,12 @@ export * from './tan-query/users/useUserCollectibles'
export * from './tan-query/users/useUserPlaylists'
export * from './tan-query/users/useUsers'
export * from './tan-query/users/useUserTracksByHandle'
export * from './tan-query/users/account/useResetPassword'
export * from './tan-query/users/account/useManagedAccounts'
export * from './tan-query/users/account/useManagers'
export * from './tan-query/users/account/useRequestAddManager'
export * from './tan-query/users/account/useApproveManagedAccount'
export * from './tan-query/users/account/useRemoveManager'

// Wallet logic
export * from './tan-query/wallets/useAudioBalance'
Expand Down
2 changes: 0 additions & 2 deletions packages/common/src/api/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { combineReducers } from 'redux'

import { accountApiReducer } from './account'
import { authorizedAppsApiReducer } from './authorizedApps'
import { developerAppsApiReducer } from './developerApps'
import { favoritesApiReducer } from './favorites'
Expand All @@ -12,7 +11,6 @@ import { trendingApiReducer } from './trending'
import { userApiReducer } from './user'

export default combineReducers({
accountApi: accountApiReducer,
authorizedAppsApi: authorizedAppsApiReducer,
developerAppsApi: developerAppsApiReducer,
favoritesApi: favoritesApiReducer,
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/api/tan-query/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,7 @@ export const QUERY_KEYS = {
walletOwner: 'walletOwner',
tokenPrice: 'tokenPrice',
usdcBalance: 'usdcBalance',
fileSizes: 'fileSizes'
fileSizes: 'fileSizes',
managedAccounts: 'managedAccounts',
userManagers: 'userManagers'
} as const
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Id } from '@audius/sdk'
import { useMutation, useQueryClient } from '@tanstack/react-query'

import { useAudiusQueryContext } from '~/audius-query'
import { User, UserMetadata } from '~/models'

import { getManagedAccountsQueryKey } from './useManagedAccounts'

type ApproveManagedAccountPayload = {
userId: number
grantorUser: UserMetadata | User
}

export const useApproveManagedAccount = () => {
const { audiusSdk } = useAudiusQueryContext()
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (payload: ApproveManagedAccountPayload) => {
const { grantorUser, userId } = payload
const grantorUserId = grantorUser.user_id
const encodedUserId = Id.parse(userId)
const encodedGrantorUserId = Id.parse(grantorUserId)
const sdk = await audiusSdk()
await sdk.grants.approveGrant({
userId: encodedUserId,
grantorUserId: encodedGrantorUserId
})
return payload
},
onSuccess: (data) => {
queryClient.invalidateQueries({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this as an alternative to optimistic updates, just wondering if the grant will have been indexed fast enough for this to work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was working fine in my testing, but I'm open to exploring more if you think theres potential for issues here out in the wild.
I assume this SDK call waits for confirmation before returning, but what you're saying is there's still potential for indexing being behind still, right?
Maybe an optimistic update is the way to go then? 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's testing fine on stage, maybe we can leave it unless we see issues. I believe you're correct that SDK will confirm it.
Alternatively we write something that polls until it finds the new manager?
Optimistic usually seems to get us in more trouble than it's worth :-D

queryKey: getManagedAccountsQueryKey(data.userId)
})
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const useCurrentAccount = <
},
staleTime: options?.staleTime ?? Infinity,
gcTime: Infinity,
enabled: options?.enabled !== false && !!currentUserWallet
enabled: options?.enabled !== false && !!currentUserWallet,
...options
})
}
Loading