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

chore: zustand usage optimizations #6355

Merged
merged 2 commits into from
Dec 23, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ export const ChainSelection = memo(function ChainSelection({ allText, output }:
const backendNetworks = useBackendNetworksStore(state => state.backendNetworksSharedValue);

// chains sorted by balance on output, chains without balance hidden on input
const { balanceSortedChainList, filter } = useUserAssetsStore(state => ({
balanceSortedChainList: output ? state.getBalanceSortedChainList() : state.getChainsWithBalance(),
filter: state.filter,
}));
const balanceSortedChainList = useUserAssetsStore(state => (output ? state.getBalanceSortedChainList() : state.getChainsWithBalance()));
const filter = useUserAssetsStore(state => state.filter);

const inputListFilter = useSharedValue(filter);

const accentColor = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ export function SyncGasStateToSharedValues() {

const gasSettings = useSelectedGas(chainId);

const { userNativeNetworkAsset, isLoadingNativeNetworkAsset } = useUserAssetsStore(state => {
const { address: nativeCurrencyAddress } = useBackendNetworksStore.getState().getChainsNativeAsset()[chainId];
const uniqueId = getUniqueId(nativeCurrencyAddress, chainId);
return { userNativeNetworkAsset: state.getLegacyUserAsset(uniqueId), isLoadingNativeNetworkAsset: state.isLoadingUserAssets };
});
const { address: nativeCurrencyAddress } = useBackendNetworksStore.getState().getChainsNativeAsset()[chainId];

const isLoadingNativeNetworkAsset = useUserAssetsStore(state => state.isLoadingUserAssets);
const userNativeNetworkAsset = useUserAssetsStore(state => state.getLegacyUserAsset(getUniqueId(nativeCurrencyAddress, chainId)));

const { data: estimatedGasLimit } = useSwapEstimatedGasLimit({ chainId, assetToSell, quote });

const gasFeeRange = useSharedValue<[string, string] | null>(null);
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useWalletSectionsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ export default function useWalletSectionsData({
} = {}) {
const { accountAddress, language, network, nativeCurrency } = useAccountSettings();
const { selectedWallet, isReadOnlyWallet } = useWallets();
const { isLoadingUserAssets, sortedAssets = [] } = useUserAssetsStore(state => ({
sortedAssets: state.legacyUserAssets,
isLoadingUserAssets: state.isLoadingUserAssets,
}));
const isLoadingUserAssets = useUserAssetsStore(state => state.isLoadingUserAssets);
const sortedAssets = useUserAssetsStore(state => state.legacyUserAssets);
const isWalletEthZero = useIsWalletEthZero();

const { nftSort, nftSortDirection } = useNftSort();
Expand Down
7 changes: 3 additions & 4 deletions src/hooks/useWatchPendingTxs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import { useConnectedToAnvilStore } from '@/state/connectedToAnvil';
import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks';

export const useWatchPendingTransactions = ({ address }: { address: string }) => {
const { storePendingTransactions, setPendingTransactions } = usePendingTransactionsStore(state => ({
storePendingTransactions: state.pendingTransactions,
setPendingTransactions: state.setPendingTransactions,
}));
const storePendingTransactions = usePendingTransactionsStore(state => state.pendingTransactions);
const setPendingTransactions = usePendingTransactionsStore(state => state.setPendingTransactions);

const { connectedToAnvil } = useConnectedToAnvilStore();

const pendingTransactions = useMemo(() => storePendingTransactions[address] || [], [address, storePendingTransactions]);
Expand Down
Loading