Skip to content

Commit

Permalink
need to remove useAssetsToSell
Browse files Browse the repository at this point in the history
  • Loading branch information
benisgold committed May 25, 2024
1 parent 9901c88 commit db52c0b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 31 deletions.
1 change: 0 additions & 1 deletion src/__swaps__/screens/Swap/components/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export const SearchInput = ({
animatedProps={searchInputValue}
onChange={onSearchQueryChange}
onBlur={() => {
console.log('here');
onSearchQueryChange({
nativeEvent: {
text: '',
Expand Down
18 changes: 3 additions & 15 deletions src/__swaps__/screens/Swap/components/SwapInputAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import { TokenList } from '@/__swaps__/screens/Swap/components/TokenList/TokenLi
import { BASE_INPUT_WIDTH, INPUT_INNER_WIDTH, INPUT_PADDING, THICK_BORDER_WIDTH } from '@/__swaps__/screens/Swap/constants';
import { IS_ANDROID } from '@/env';
import { useSwapContext } from '@/__swaps__/screens/Swap/providers/swap-provider';
import { useAssetsToSell } from '@/__swaps__/screens/Swap/hooks/useAssetsToSell';
import { isSameAssetWorklet } from '@/__swaps__/utils/assets';
import { AmimatedSwapCoinIcon } from './AnimatedSwapCoinIcon';
import { swapsStore } from '@/state/swaps/swapsStore';

function SwapInputActionButton() {
const { isDarkMode } = useColorMode();
Expand Down Expand Up @@ -80,21 +79,10 @@ function SwapInputIcon() {
}

function InputAssetBalanceBadge() {
const { internalSelectedInputAsset } = useSwapContext();

const userAssets = useAssetsToSell();
const selectedAssetBalance = swapsStore(state => state.inputAsset?.balance.display);

const label = useDerivedValue(() => {
const asset = internalSelectedInputAsset.value;
if (!asset) return 'No balance';

const userAsset = userAssets.find(userAsset =>
isSameAssetWorklet(userAsset, {
address: asset.address,
chainId: asset.chainId,
})
);
return userAsset?.balance.display ?? 'No balance';
return selectedAssetBalance || 'No Balance';
});

return <BalanceBadge label={label} />;
Expand Down
22 changes: 7 additions & 15 deletions src/__swaps__/screens/Swap/components/SwapOutputAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import { TokenList } from '@/__swaps__/screens/Swap/components/TokenList/TokenLi
import { BASE_INPUT_WIDTH, INPUT_INNER_WIDTH, INPUT_PADDING, THICK_BORDER_WIDTH } from '@/__swaps__/screens/Swap/constants';
import { IS_ANDROID } from '@/env';
import { useSwapContext } from '@/__swaps__/screens/Swap/providers/swap-provider';
import { isSameAssetWorklet } from '@/__swaps__/utils/assets';
import { useAssetsToSell } from '@/__swaps__/screens/Swap/hooks/useAssetsToSell';
import { AmimatedSwapCoinIcon } from './AnimatedSwapCoinIcon';
import { swapsStore } from '@/state/swaps/swapsStore';
import { userAssetsStore } from '@/state/assets/userAssets';

function SwapOutputActionButton() {
const { isDarkMode } = useColorMode();
Expand Down Expand Up @@ -80,21 +80,13 @@ function SwapInputIcon() {
}

function OutputAssetBalanceBadge() {
const { internalSelectedOutputAsset } = useSwapContext();

const userAssets = useAssetsToSell();
const selectedAssetId = swapsStore(state => state.outputAsset?.uniqueId);
const selectedAssetBalance = userAssetsStore(state =>
selectedAssetId && state.hasUserAsset(selectedAssetId) ? state.getUserAsset(selectedAssetId).balance.display : undefined
);

const label = useDerivedValue(() => {
const asset = internalSelectedOutputAsset.value;
if (!asset) return 'No balance';

const userAsset = userAssets.find(userAsset =>
isSameAssetWorklet(userAsset, {
address: asset.address,
chainId: asset.chainId,
})
);
return userAsset?.balance.display ?? 'No balance';
return selectedAssetBalance || 'No Balance';
});

return <BalanceBadge label={label} />;
Expand Down
2 changes: 2 additions & 0 deletions src/state/assets/userAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RainbowError, logger } from '@/logger';
export interface UserAssetsState {
userAssets: Map<UniqueId, ParsedSearchAsset>;

hasUserAsset: (uniqueId: UniqueId) => boolean;
getUserAsset: (uniqueId: UniqueId) => ParsedSearchAsset;
}

Expand Down Expand Up @@ -65,6 +66,7 @@ export const userAssetsStore = createRainbowStore<UserAssetsState>(
userAssets: new Map(),

getUserAsset: (uniqueId: UniqueId) => get().userAssets.get(uniqueId) as ParsedSearchAsset,
hasUserAsset: (uniqueId: UniqueId) => get().userAssets.has(uniqueId),
}),
{
storageKey: 'userAssets',
Expand Down

0 comments on commit db52c0b

Please sign in to comment.