Skip to content

Commit

Permalink
Fix asset selector (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey authored Jul 30, 2024
1 parent 3cf8ebf commit 87fb41c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/lib/token/AssetSelector.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const _ConnectMassaWallet = {
<AssetSelector
selectedAsset={selectedAsset}
assets={assets}
setSelectedAsset={console.log}
onAssetChange={console.log}
isAssetsLoading={false}
/>
),
Expand Down
27 changes: 3 additions & 24 deletions src/lib/token/AssetSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
import { useEffect } from 'react';

import { Dropdown, getAssetIcons, IOption } from '../../components';

import Intl from './i18n';
import { formatAmount } from '../util/parseAmount';
import { Asset } from './models/AssetModel';

interface AssetSelectorProps {
selectedAsset: Asset | undefined;
setSelectedAsset: (asset: Asset) => void;
onAssetChange: (asset: Asset) => void;
selectSymbol?: string;
assets: Asset[] | undefined;
isAssetsLoading: boolean;
}

export function AssetSelector(props: AssetSelectorProps) {
const {
selectedAsset,
setSelectedAsset,
selectSymbol,
assets,
isAssetsLoading,
} = props;

useEffect(() => {
if (selectSymbol) {
const selectedAsset = assets?.find(
(asset) => asset.symbol === selectSymbol,
);
if (selectedAsset) setSelectedAsset(selectedAsset);
}
if (!selectedAsset && assets && assets?.length > 0) {
setSelectedAsset(assets?.[0]);
}
}, [assets, setSelectedAsset, selectedAsset, selectSymbol]);
const { assets, selectedAsset, onAssetChange, isAssetsLoading } = props;

let options: IOption[] = [];

Expand All @@ -56,7 +35,7 @@ export function AssetSelector(props: AssetSelectorProps) {
</div>
),
icon: getAssetIcons(asset.symbol, asset.originChainId, false, 28),
onClick: () => setSelectedAsset(asset),
onClick: () => onAssetChange(asset),
};
});
}
Expand Down

0 comments on commit 87fb41c

Please sign in to comment.