-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix account balance discrepancies #5959
Changes from 12 commits
415e800
2f82761
4ff91ef
d010309
50df200
cf6a796
2605a21
eb8bbe2
bc4c6e8
148a1eb
d5a2a67
1b4013f
a151992
207e811
1277e6d
9efc708
2c018d8
647d1b0
c05f854
4f05b85
bb5cd77
8061f7a
2aa197b
f9bf7ab
423f6df
5e81f25
fc10958
b0eb61b
943117b
7a11e75
38e9eb5
335bb0d
04069ba
4c6855d
4240c4e
cbf63df
e1349b0
6acff71
5e06f01
33c8024
3ada8f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { captureException } from '@sentry/react-native'; | ||
import delay from 'delay'; | ||
import { useCallback, useState } from 'react'; | ||
import { useCallback, useMemo, useState } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { getIsHardhatConnected } from '@/handlers/web3'; | ||
import { walletConnectLoadState } from '../redux/walletconnect'; | ||
|
@@ -10,34 +10,36 @@ import { PROFILES, useExperimentalFlag } from '@/config'; | |
import logger from '@/utils/logger'; | ||
import { queryClient } from '@/react-query'; | ||
import { userAssetsQueryKey } from '@/resources/assets/UserAssetsQuery'; | ||
import { userAssetsQueryKey as swapsUserAssetsQueryKey } from '@/__swaps__/screens/Swap/resources/assets/userAssets'; | ||
import { nftsQueryKey } from '@/resources/nfts'; | ||
import { positionsQueryKey } from '@/resources/defi/PositionsQuery'; | ||
import { Address } from 'viem'; | ||
import { addysSummaryQueryKey } from '@/resources/summary/summary'; | ||
import useWallets from './useWallets'; | ||
|
||
export default function useRefreshAccountData() { | ||
const dispatch = useDispatch(); | ||
const { accountAddress, nativeCurrency } = useAccountSettings(); | ||
const [isRefreshing, setIsRefreshing] = useState(false); | ||
const profilesEnabled = useExperimentalFlag(PROFILES); | ||
|
||
const { wallets } = useWallets(); | ||
|
||
const allAddresses = useMemo( | ||
() => Object.values(wallets || {}).flatMap(wallet => wallet.addresses.map(account => account.address as Address)), | ||
[wallets] | ||
); | ||
|
||
const fetchAccountData = useCallback(async () => { | ||
const connectedToHardhat = getIsHardhatConnected(); | ||
|
||
queryClient.invalidateQueries({ | ||
queryKey: nftsQueryKey({ address: accountAddress }), | ||
}); | ||
queryClient.invalidateQueries({ | ||
queryKey: positionsQueryKey({ | ||
address: accountAddress, | ||
currency: nativeCurrency, | ||
}), | ||
}); | ||
queryClient.invalidateQueries({ | ||
queryKey: userAssetsQueryKey({ | ||
address: accountAddress, | ||
currency: nativeCurrency, | ||
connectedToHardhat, | ||
}), | ||
}); | ||
queryClient.invalidateQueries(nftsQueryKey({ address: accountAddress })); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. Arrays were just not working.. |
||
queryClient.invalidateQueries(positionsQueryKey({ address: accountAddress as Address, currency: nativeCurrency })); | ||
queryClient.invalidateQueries(addysSummaryQueryKey({ addresses: allAddresses, currency: nativeCurrency })); | ||
queryClient.invalidateQueries(userAssetsQueryKey({ address: accountAddress, currency: nativeCurrency, connectedToHardhat })); | ||
queryClient.invalidateQueries( | ||
swapsUserAssetsQueryKey({ address: accountAddress as Address, currency: nativeCurrency, testnetMode: !!connectedToHardhat }) | ||
); | ||
|
||
try { | ||
const getWalletNames = dispatch(fetchWalletNames()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bulk of the changes to this file are to squash positions data in to the balance data when the bool is true (by default it is). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Important to note that we fetch positions for addresses independently, so this doesn't scale as well as I'd like but should work for the time being. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separated all of the instances of invalidateQueries out because Arrays weren't working for whatever reason.