Skip to content

Commit

Permalink
chore(wallet-core): slowdown updating of bsc, pol, op, arb, base
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasklim authored and martykan committed Feb 5, 2025
1 parent 46e5551 commit a47b24d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 8 additions & 0 deletions suite-common/wallet-config/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ export const normalizeNetworkAccounts = (network: Network): NormalizedNetworkAcc
export const isBlockbookBasedNetwork = (symbol: NetworkSymbol) =>
networks[symbol]?.backendTypes.some(backend => backend === 'blockbook');

// TODO: move to networksConfig
export const externalBackendTypeNetworks: NetworkSymbol[] = ['bsc', 'pol', 'op', 'arb', 'base'];

export const isTrezorInfraBasedNetwork = (symbol: NetworkSymbol) =>
networks[symbol]?.backendTypes.some(
backend => backend === 'blockbook' && !externalBackendTypeNetworks.includes(symbol),
);

export const getNetworkType = (symbol: NetworkSymbol) => networks[symbol]?.networkType;

// Takes into account just network features, not features for specific accountTypes.
Expand Down
15 changes: 8 additions & 7 deletions suite-common/wallet-core/src/blockchain/blockchainThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { createThunk } from '@suite-common/redux-utils';
import { notificationsActions } from '@suite-common/toast-notifications';
import {
NetworkSymbol,
externalBackendTypeNetworks,
getNetworkOptional,
isBlockbookBasedNetwork,
isNetworkSymbol,
isTrezorInfraBasedNetwork,
networksCollection,
} from '@suite-common/wallet-config';
import type { Account, CustomBackend, NetworksFees } from '@suite-common/wallet-types';
Expand Down Expand Up @@ -359,13 +360,13 @@ export const syncAccountsWithBlockchainThunk = createThunk(
// First clear, to cancel last planned sync
tryClearTimeout(blockchain[symbol].syncTimeout);

// non-blockbook networks will not be updated when app window is not active
const shouldSync = isWindowVisible || isBlockbookBasedNetwork(symbol);
// non-blockbook + networks using external nodes will not be updated when app window is not active
const shouldSync = isWindowVisible || isTrezorInfraBasedNetwork(symbol);

if (shouldSync) {
// non-blockbook networks will not update periodically if not visible in UI (sidebar)
// non-blockbook + networks using external nodes will not update periodically if not visible in UI (sidebar)
const visibleAccounts = findAccountsByNetwork(symbol, accounts).filter(
account => isBlockbookBasedNetwork(symbol) || account.visible,
account => isTrezorInfraBasedNetwork(symbol) || account.visible,
);

await Promise.all(
Expand Down Expand Up @@ -416,8 +417,8 @@ export const onBlockMinedThunk = createThunk(

// Don't sync fast networks because a new block is emitted every few seconds.
// Accounts are updated via account subscription or also by the timer in syncAccountsWithBlockchainThunk.
// Solana - new block every 800ms
if (network?.networkType === 'solana') {
// Solana - new block every ~333ms, EVMs 0.3s-3s
if (network?.networkType === 'solana' || externalBackendTypeNetworks.includes(symbol)) {
return;
}

Expand Down

0 comments on commit a47b24d

Please sign in to comment.