Skip to content

Commit

Permalink
remove zustand selectors that return objects (#6355)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Wall <[email protected]>
  • Loading branch information
benisgold and walmat authored Dec 23, 2024
1 parent 5e92d8e commit 56d15e3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
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

0 comments on commit 56d15e3

Please sign in to comment.