Skip to content

Commit

Permalink
fix native assets outside of eth not working with preferred network (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat authored Nov 4, 2024
1 parent 68f5b65 commit e7844a2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/__swaps__/screens/Swap/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const useMountSignal = () => {
const useCleanupOnUnmount = () => {
useEffect(() => {
return () => {
const highestValueEth = userAssetsStore.getState().getHighestValueEth();
const highestValueEth = userAssetsStore.getState().getHighestValueNativeAsset();
const preferredNetwork = swapsStore.getState().preferredNetwork;
const parsedAsset = highestValueEth
? parseSearchAsset({
Expand Down Expand Up @@ -139,7 +139,7 @@ const WalletAddressObserver = () => {
const { setAsset } = useSwapContext();

const setNewInputAsset = useCallback(() => {
const newHighestValueEth = userAssetsStore.getState().getHighestValueEth();
const newHighestValueEth = userAssetsStore.getState().getHighestValueNativeAsset();

if (userAssetsStore.getState().filter !== 'all') {
userAssetsStore.setState({ filter: 'all' });
Expand Down
4 changes: 2 additions & 2 deletions src/components/DappBrowser/control-panel/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ const HomePanel = ({
if (!valid) return;

swapsStore.setState({
inputAsset: userAssetsStore.getState().getHighestValueEth(),
inputAsset: userAssetsStore.getState().getHighestValueNativeAsset(),
});
InteractionManager.runAfterInteractions(() => {
navigate(Routes.SWAP);
Expand All @@ -454,7 +454,7 @@ const HomePanel = ({
if (!valid) return;

swapsStore.setState({
inputAsset: userAssetsStore.getState().getHighestValueEth(),
inputAsset: userAssetsStore.getState().getHighestValueNativeAsset(),
});
InteractionManager.runAfterInteractions(() => {
navigate(Routes.SWAP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function SwapButton() {
category: 'home screen',
});
swapsStore.setState({
inputAsset: userAssetsStore.getState().getHighestValueEth(),
inputAsset: userAssetsStore.getState().getHighestValueNativeAsset(),
});
InteractionManager.runAfterInteractions(() => {
navigate(Routes.SWAP);
Expand Down
2 changes: 1 addition & 1 deletion src/components/context-menu-buttons/ChainContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const ChainContextMenu = ({
actionTitle: chainsLabel[chainId],
icon: {
iconType: 'ASSET',
iconValue: `${chainsName[chainId]}Badge${chainId === ChainId.mainnet ? '' : 'NoShadow'}`,
iconValue: chainId === ChainId.mainnet ? 'ethereumBadge' : `${chainsName[chainId]}BadgeNoShadow`,
},
};
});
Expand Down
10 changes: 5 additions & 5 deletions src/state/assets/userAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ParsedSearchAsset, UniqueId, UserAssetFilter } from '@/__swaps__/types/
import { Address } from 'viem';
import { RainbowError, logger } from '@/logger';
import reduxStore, { AppState } from '@/redux/store';
import { ETH_ADDRESS, supportedNativeCurrencies } from '@/references';
import { supportedNativeCurrencies } from '@/references';
import { createRainbowStore } from '@/state/internal/createRainbowStore';
import { useStore } from 'zustand';
import { swapsStore } from '@/state/swaps/swapsStore';
Expand Down Expand Up @@ -38,7 +38,7 @@ export interface UserAssetsState {
getBalanceSortedChainList: () => ChainId[];
getChainsWithBalance: () => ChainId[];
getFilteredUserAssetIds: () => UniqueId[];
getHighestValueEth: () => ParsedSearchAsset | null;
getHighestValueNativeAsset: () => ParsedSearchAsset | null;
getUserAsset: (uniqueId: UniqueId) => ParsedSearchAsset | null;
getUserAssets: () => ParsedSearchAsset[];
selectUserAssetIds: (selector: (asset: ParsedSearchAsset) => boolean, filter?: UserAssetFilter) => Generator<UniqueId, void, unknown>;
Expand All @@ -60,7 +60,7 @@ type UserAssetsStateToPersist = Omit<
| 'getBalanceSortedChainList'
| 'getChainsWithBalance'
| 'getFilteredUserAssetIds'
| 'getHighestValueEth'
| 'getHighestValueNativeAsset'
| 'getUserAsset'
| 'getUserAssets'
| 'selectUserAssetIds'
Expand Down Expand Up @@ -219,14 +219,14 @@ export const createUserAssetsStore = (address: Address | string) =>
return filteredIds;
}
},
getHighestValueEth: () => {
getHighestValueNativeAsset: () => {
const preferredNetwork = swapsStore.getState().preferredNetwork;
const assets = get().userAssets;

let highestValueEth = null;

for (const [, asset] of assets) {
if (asset.mainnetAddress !== ETH_ADDRESS) continue;
if (!asset.isNativeAsset) continue;

if (preferredNetwork && asset.chainId === preferredNetwork) {
return asset;
Expand Down
2 changes: 1 addition & 1 deletion src/state/sync/UserAssetsSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const UserAssetsSync = function UserAssetsSync() {
if (!isSwapsOpen || isUserAssetsStoreMissingData) {
userAssetsStore.getState().setUserAssets(data as ParsedSearchAsset[]);

const inputAsset = userAssetsStore.getState().getHighestValueEth();
const inputAsset = userAssetsStore.getState().getHighestValueNativeAsset();
useSwapsStore.setState({
inputAsset,
selectedOutputChainId: inputAsset?.chainId ?? ChainId.mainnet,
Expand Down

0 comments on commit e7844a2

Please sign in to comment.