Skip to content
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

feat: blazingly fast initial accounts load #7822

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
87a2daf
feat: rm request queue
gomesalexandre Sep 26, 2024
44630f9
feat: rm upsertOnFetch
gomesalexandre Sep 26, 2024
ce1172b
feat: don't mark upsertPortfolio as low prio action
gomesalexandre Sep 26, 2024
06ca68f
feat: rm prepare
gomesalexandre Sep 26, 2024
57a04c8
fix: isPortfolioLoaded heuristics
gomesalexandre Sep 26, 2024
190de45
feat: make metadata upsertion blazingly fast
gomesalexandre Sep 26, 2024
3507515
fix: multi-account derp
gomesalexandre Sep 26, 2024
eee8fd7
fix: incremental load
gomesalexandre Sep 26, 2024
10189e6
fix: filter out chains without history for account number, and revert
gomesalexandre Sep 26, 2024
fb7f97d
Merge remote-tracking branch 'origin/develop' into blazingly_fast_ini…
gomesalexandre Sep 27, 2024
da7d405
feat: improve chunks grouping
gomesalexandre Sep 27, 2024
b6dc216
feat: bring back upsertOnFetch
gomesalexandre Sep 27, 2024
2b4defc
feat: fetch txHistory *after* all are done
gomesalexandre Sep 27, 2024
2746284
feat: split getAllTxHistory by AccountIds
gomesalexandre Sep 27, 2024
ed84af5
fix: upsert only per-chain accounts
gomesalexandre Sep 27, 2024
847369c
chore: rm logs and debugger
gomesalexandre Sep 27, 2024
84303c3
feat: revert DegradedStateBanner refetch failed
gomesalexandre Sep 27, 2024
6df58ff
feat: importAccounts revert upsertOnFetch
gomesalexandre Sep 27, 2024
150ae0f
feat: update comment
gomesalexandre Sep 27, 2024
64e8c63
Merge branch 'develop' into blazingly_fast_initial
gomesalexandre Sep 30, 2024
5a3b1ae
feat: rm paranoia
gomesalexandre Sep 30, 2024
ac172d0
feat: opt-chain selector
gomesalexandre Sep 30, 2024
5c094cc
feat: remove chunk terminology and fix grouping of UTXO scriptTypes
gomesalexandre Sep 30, 2024
81b6e9b
feat: set over array for cleanliness
gomesalexandre Sep 30, 2024
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
4 changes: 2 additions & 2 deletions src/components/Equity/Equity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
selectAssetEquityItemsByFilter,
selectAssets,
selectEquityTotalBalance,
selectIsPortfolioLoading,
selectOpportunityApiPending,
selectPortfolioLoading,
selectUnderlyingLpAssetsWithBalancesAndIcons,
} from 'state/slices/selectors'
import { useAppSelector } from 'state/store'
Expand All @@ -41,7 +41,7 @@ const stackDividerStyle = { marginLeft: 14 }

export const Equity = ({ assetId, accountId }: EquityProps) => {
const translate = useTranslate()
const portfolioLoading = useSelector(selectPortfolioLoading)
const portfolioLoading = useSelector(selectIsPortfolioLoading)
const opportunitiesLoading = useAppSelector(selectOpportunityApiPending)
const isLoading = portfolioLoading || opportunitiesLoading
const assets = useAppSelector(selectAssets)
Expand Down
7 changes: 1 addition & 6 deletions src/components/Layout/Header/DegradedStateBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ export const DegradedStateBanner = memo(() => {

const handleRetry = useCallback(() => {
erroredAccountIds.forEach(accountId =>
dispatch(
portfolioApi.endpoints.getAccount.initiate(
{ accountId, upsertOnFetch: true },
{ forceRefetch: true },
),
),
dispatch(portfolioApi.endpoints.getAccount.initiate({ accountId }, { forceRefetch: true })),
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved
)
}, [dispatch, erroredAccountIds])

Expand Down
4 changes: 2 additions & 2 deletions src/components/Layout/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { useWallet } from 'hooks/useWallet/useWallet'
import { isUtxoAccountId } from 'lib/utils/utxo'
import { portfolio } from 'state/slices/portfolioSlice/portfolioSlice'
import {
selectEnabledWalletAccountIds,
selectPortfolioDegradedState,
selectShowSnapsModal,
selectWalletAccountIds,
selectWalletId,
} from 'state/slices/selectors'
import { useAppDispatch } from 'state/store'
Expand Down Expand Up @@ -98,7 +98,7 @@ export const Header = memo(() => {
)

const currentWalletId = useSelector(selectWalletId)
const walletAccountIds = useSelector(selectWalletAccountIds)
const walletAccountIds = useSelector(selectEnabledWalletAccountIds)
const hasUtxoAccountIds = useMemo(
() => walletAccountIds.some(accountId => isUtxoAccountId(accountId)),
[walletAccountIds],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,7 @@ export const ImportAccounts = ({ chainId, onClose }: ImportAccountsProps) => {
if (isEnabled) {
return
}
await dispatch(
portfolioApi.endpoints.getAccount.initiate({ accountId, upsertOnFetch: true }),
)
await dispatch(portfolioApi.endpoints.getAccount.initiate({ accountId }))
gomesalexandre marked this conversation as resolved.
Show resolved Hide resolved
}),
)

Expand Down
4 changes: 2 additions & 2 deletions src/components/Modals/FiatRamps/views/FiatForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { parseAddressInputWithChainId } from 'lib/address/address'
import { useGetFiatRampsQuery } from 'state/apis/fiatRamps/fiatRamps'
import {
selectAssetsSortedByMarketCapUserCurrencyBalanceAndName,
selectEnabledWalletAccountIds,
selectHighestMarketCapFeeAsset,
selectPortfolioAccountMetadata,
selectWalletAccountIds,
selectWalletConnectedChainIds,
} from 'state/slices/selectors'
import { useAppSelector } from 'state/store'
Expand All @@ -35,7 +35,7 @@ export const FiatForm: React.FC<FiatFormProps> = ({
fiatRampAction,
accountId: selectedAccountId,
}) => {
const walletAccountIds = useSelector(selectWalletAccountIds)
const walletAccountIds = useSelector(selectEnabledWalletAccountIds)
const portfolioAccountMetadata = useSelector(selectPortfolioAccountMetadata)
const sortedAssets = useSelector(selectAssetsSortedByMarketCapUserCurrencyBalanceAndName)
const [accountId, setAccountId] = useState<AccountId | undefined>(selectedAccountId)
Expand Down
4 changes: 2 additions & 2 deletions src/components/Modals/Nfts/NftModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { nft, nftApi, useGetNftCollectionQuery } from 'state/apis/nft/nftApi'
import { selectNftById, selectNftCollectionById } from 'state/apis/nft/selectors'
import { chainIdToOpenseaNetwork } from 'state/apis/nft/utils'
import { getMediaType } from 'state/apis/zapper/validators'
import { selectWalletAccountIds, selectWalletId } from 'state/slices/common-selectors'
import { selectEnabledWalletAccountIds, selectWalletId } from 'state/slices/common-selectors'
import { selectAssetById } from 'state/slices/selectors'
import { useAppDispatch, useAppSelector } from 'state/store'
import { breakpoints } from 'theme/theme'
Expand Down Expand Up @@ -105,7 +105,7 @@ export const NftModal: React.FC<NftModalProps> = ({ nftAssetId }) => {
const modalHeaderBg = useColorModeValue('gray.50', 'gray.785')
const [isLargerThanMd] = useMediaQuery(`(min-width: ${breakpoints['md']})`)
const walletId = useAppSelector(selectWalletId)
const accountIds = useAppSelector(selectWalletAccountIds)
const accountIds = useAppSelector(selectEnabledWalletAccountIds)

useGetNftCollectionQuery(
{ accountIds, collectionId: nftItem.collectionId },
Expand Down
8 changes: 5 additions & 3 deletions src/components/Modals/Settings/ClearCache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { RawText } from 'components/Text'
import { reloadWebview } from 'context/WalletProvider/MobileWallet/mobileMessageHandlers'
import { useWallet } from 'hooks/useWallet/useWallet'
import { isMobile as isMobileApp } from 'lib/globals'
import { selectWalletAccountIds } from 'state/slices/selectors'
import { selectEnabledWalletAccountIds } from 'state/slices/selectors'
import { txHistory, txHistoryApi } from 'state/slices/txHistorySlice/txHistorySlice'
import { persistor, useAppDispatch, useAppSelector } from 'state/store'

Expand Down Expand Up @@ -56,7 +56,7 @@ const ClearCacheButton = ({

export const ClearCache = ({ appHistory }: ClearCacheProps) => {
const dispatch = useAppDispatch()
const requestedAccountIds = useAppSelector(selectWalletAccountIds)
const requestedAccountIds = useAppSelector(selectEnabledWalletAccountIds)
const translate = useTranslate()
const history = useHistory()
const { disconnect } = useWallet()
Expand All @@ -81,7 +81,9 @@ export const ClearCache = ({ appHistory }: ClearCacheProps) => {
const handleClearTxHistory = useCallback(() => {
dispatch(txHistory.actions.clear())
dispatch(txHistoryApi.util.resetApiState())
dispatch(txHistoryApi.endpoints.getAllTxHistory.initiate(requestedAccountIds))
requestedAccountIds.forEach(requestedAccountId =>
dispatch(txHistoryApi.endpoints.getAllTxHistory.initiate(requestedAccountId)),
)
}, [dispatch, requestedAccountIds])

return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/Nfts/hooks/useNfts.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useMemo } from 'react'
import { useGetNftUserTokensQuery } from 'state/apis/nft/nftApi'
import { selectWalletAccountIds } from 'state/slices/common-selectors'
import { selectEnabledWalletAccountIds } from 'state/slices/common-selectors'
import { useAppSelector } from 'state/store'

export const useNfts = () => {
const requestedAccountIds = useAppSelector(selectWalletAccountIds)
const requestedAccountIds = useAppSelector(selectEnabledWalletAccountIds)

const { isUninitialized, isLoading, isFetching, data } = useGetNftUserTokensQuery(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import {
useGetZapperUniV2PoolAssetIdsQuery,
} from 'state/apis/zapper/zapperApi'
import {
selectEnabledWalletAccountIds,
selectEvmAccountIds,
selectPortfolioAccounts,
selectPortfolioAssetIds,
selectPortfolioLoadingStatus,
selectWalletAccountIds,
} from 'state/slices/selectors'
import { useAppDispatch } from 'state/store'

export const useFetchOpportunities = () => {
const dispatch = useAppDispatch()
const portfolioLoadingStatus = useSelector(selectPortfolioLoadingStatus)
const requestedAccountIds = useSelector(selectWalletAccountIds)
const requestedAccountIds = useSelector(selectEnabledWalletAccountIds)
const evmAccountIds = useSelector(selectEvmAccountIds)
const portfolioAssetIds = useSelector(selectPortfolioAssetIds)
const portfolioAccounts = useSelector(selectPortfolioAccounts)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Asset } from '@shapeshiftoss/types'
import { useMemo } from 'react'
import { selectPortfolioLoading } from 'state/slices/selectors'
import { selectIsPortfolioLoading } from 'state/slices/selectors'
import { useAppSelector } from 'state/store'

import { useGetPopularAssetsQuery } from '../hooks/useGetPopularAssetsQuery'
Expand All @@ -17,7 +17,7 @@ export const DefaultAssetList = ({
popularAssets,
onAssetClick,
}: DefaultAssetListProps) => {
const isPortfolioLoading = useAppSelector(selectPortfolioLoading)
const isPortfolioLoading = useAppSelector(selectIsPortfolioLoading)
const { isLoading: isPopularAssetIdsLoading } = useGetPopularAssetsQuery()

const groupIsLoading = useMemo(() => {
Expand Down
Loading
Loading