Skip to content

Commit 0d8d44e

Browse files
committed
Merge branch 'main' of github.com:AudiusProject/audius-protocol into jd/perf-optimizations
2 parents 049bde8 + 26db394 commit 0d8d44e

File tree

59 files changed

+1515
-620
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1515
-620
lines changed

package-lock.json

Lines changed: 19 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/common/src/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export * from './tan-query/useRemixes'
8080
export * from './tan-query/useTrackRank'
8181
export * from './tan-query/useWalletOwner'
8282
export * from './tan-query/useTokenPrice'
83+
export * from './tan-query/useUSDCBalance'
8384

8485
export * from './tan-query/useStems'
8586
export * from './tan-query/useFileSizes'

packages/common/src/api/tan-query/queryKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,6 @@ export const QUERY_KEYS = {
8787
eventsByEntityId: 'eventsByEntityId',
8888
walletOwner: 'walletOwner',
8989
tokenPrice: 'tokenPrice',
90+
usdcBalance: 'usdcBalance',
9091
fileSizes: 'fileSizes'
9192
} as const
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { Commitment } from '@solana/web3.js'
2+
import { useQuery } from '@tanstack/react-query'
3+
import BN from 'bn.js'
4+
import { useDispatch, useSelector } from 'react-redux'
5+
6+
import { useAudiusQueryContext } from '~/audius-query'
7+
import { Status } from '~/models/Status'
8+
import { BNUSDC, StringUSDC } from '~/models/Wallet'
9+
import { getUserbankAccountInfo } from '~/services/index'
10+
import { getRecoveryStatus } from '~/store/buy-usdc/selectors'
11+
import { setUSDCBalance } from '~/store/wallet/slice'
12+
13+
import { useGetCurrentUser } from '../index'
14+
15+
import { QUERY_KEYS } from './queryKeys'
16+
import { QueryOptions, type QueryKey } from './types'
17+
18+
export const getUSDCBalanceQueryKey = (
19+
ethAddress: string | null,
20+
commitment: Commitment
21+
) =>
22+
[
23+
QUERY_KEYS.usdcBalance,
24+
ethAddress,
25+
commitment
26+
] as unknown as QueryKey<BNUSDC | null>
27+
28+
/**
29+
* Hook to get the USDC balance for the current user.
30+
* Uses TanStack Query for data fetching and caching.
31+
*
32+
* @param options Options for the query and polling
33+
* @returns Object with status, data, refresh, and cancelPolling
34+
*/
35+
export const useUSDCBalance = ({
36+
isPolling,
37+
pollingInterval = 1000,
38+
commitment = 'processed',
39+
...queryOptions
40+
}: {
41+
isPolling?: boolean
42+
pollingInterval?: number
43+
commitment?: Commitment
44+
} & QueryOptions = {}) => {
45+
const { audiusSdk } = useAudiusQueryContext()
46+
const { data: user } = useGetCurrentUser({})
47+
const ethAddress = user?.wallet ?? null
48+
const dispatch = useDispatch()
49+
const recoveryStatus = useSelector(getRecoveryStatus)
50+
51+
const result = useQuery({
52+
queryKey: getUSDCBalanceQueryKey(ethAddress, commitment),
53+
queryFn: async () => {
54+
const sdk = await audiusSdk()
55+
if (!ethAddress) {
56+
return null
57+
}
58+
59+
try {
60+
const account = await getUserbankAccountInfo(
61+
sdk,
62+
{
63+
ethAddress,
64+
mint: 'USDC'
65+
},
66+
commitment
67+
)
68+
const balance = (account?.amount ?? new BN(0)) as BNUSDC
69+
70+
// Still update Redux for compatibility with existing code
71+
dispatch(setUSDCBalance({ amount: balance.toString() as StringUSDC }))
72+
73+
return balance
74+
} catch (e) {
75+
console.error('Error fetching USDC balance:', e)
76+
throw e
77+
}
78+
},
79+
enabled: !!ethAddress,
80+
...queryOptions
81+
})
82+
83+
// Map TanStack Query states to the Status enum for API compatibility
84+
let status = Status.IDLE
85+
if (result.isLoading) {
86+
status = Status.LOADING
87+
} else if (result.isError) {
88+
status = Status.ERROR
89+
} else if (result.isSuccess) {
90+
status = Status.SUCCESS
91+
}
92+
93+
// For compatibility with existing code
94+
const data = result.data ?? null
95+
96+
// If we're actively recovering, then we will be in loading state regardless
97+
if (recoveryStatus === Status.LOADING) {
98+
status = Status.LOADING
99+
}
100+
101+
return {
102+
status,
103+
data,
104+
refresh: result.refetch
105+
}
106+
}

packages/common/src/hooks/useFormattedUSDCBalance.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import { useMemo } from 'react'
33
import { USDC } from '@audius/fixed-decimal'
44
import BN from 'bn.js'
55

6+
import { useUSDCBalance } from '../api/tan-query/useUSDCBalance'
67
import { BNUSDC, Status } from '../models'
78

8-
import { useUSDCBalance } from './useUSDCBalance'
9-
109
type UseFormattedUSDCBalanceReturn = {
1110
balance: BNUSDC | null
1211
balanceFormatted: string

packages/common/src/utils/challenges.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ export const challengeRewardsConfig: Record<
300300
shortTitle: 'Co-signed Remix',
301301
title: 'Co-signed Remix',
302302
description: () =>
303-
'If your remix is co-signed by a verified artist you will earn a reward!',
303+
'If a remix you’ve uploaded is co-signed by a verified artist, you may earn a reward!',
304304
fullDescription: () =>
305-
'If your remix is co-signed by a verified artist you will earn a reward!',
305+
'If a remix you’ve uploaded is co-signed by a verified artist, you may earn a reward!',
306306
panelButtonText: 'cosign description',
307307
id: ChallengeName.Cosign,
308308
progressLabel: 'Available',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"version": "0.7.140",
2+
"version": "0.7.141",
33
"service": "discovery-node"
44
}

packages/discovery-provider/plugins/notifications/src/processNotifications/mappers/rewardInCooldown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const challengeMessages = {
8484
cs: {
8585
title: 'Co-signed Remix',
8686
description:
87-
'If your remix is co-signed by a verified artist you will earn a reward!',
87+
'If a remix you’ve uploaded is co-signed by a verified artist, you may earn a reward!',
8888
imageUrl: 'recycle-trophy.png'
8989
}
9090
}

packages/mobile/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"react-native-blob-util": "0.19.4",
124124
"react-native-bootsplash": "6.3.2",
125125
"react-native-code-push": "9.0.0",
126-
"react-native-collapsible-tab-view": "2.0.2",
126+
"react-native-collapsible-tab-view": "8.0.1",
127127
"react-native-config": "1.5.1",
128128
"react-native-create-thumbnail": "2.0.0",
129129
"react-native-document-picker": "9.1.0",

packages/mobile/src/components/collection-list/CollectionList.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createElement, memo, useCallback, useMemo } from 'react'
22

3-
import type { Collection, UserCollection, ID } from '@audius/common/models'
3+
import type { Collection, ID } from '@audius/common/models'
44
import { CreatePlaylistSource } from '@audius/common/models'
55
import type { ListRenderItem } from 'react-native'
66

@@ -13,11 +13,17 @@ import { CollectionCardSkeleton } from './CollectionCardSkeleton'
1313

1414
const MemoizedCollectionCard = memo(CollectionCard)
1515

16-
type FullListProps = Omit<CardListProps<UserCollection>, 'data' | 'renderItem'>
16+
type FullListProps = Omit<
17+
CardListProps<Collection>,
18+
'data' | 'renderItem' | 'FlatListComponent'
19+
>
1720
type IDCardListItem = {
1821
id: ID
1922
}
20-
type IDListProps = Omit<CardListProps<IDCardListItem>, 'data' | 'renderItem'>
23+
type IDListProps = Omit<
24+
CardListProps<IDCardListItem>,
25+
'data' | 'renderItem' | 'FlatListComponent'
26+
>
2127
type CreateCard = { _create: boolean }
2228

2329
// Props to show and setup tile for creating new playlists

0 commit comments

Comments
 (0)