-
Notifications
You must be signed in to change notification settings - Fork 637
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
Swaps: Input List #5728
Closed
+310
−220
Closed
Swaps: Input List #5728
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0cafd83
progress n such
benisgold 47ebdb7
done
benisgold b28bba8
fixes
benisgold 04befa6
migration
benisgold c53fe40
memo
benisgold 80889d6
network filter
benisgold 407b5a9
split up coin row into cells
walmat 9dfc9be
Merge branch '@benisgold/inputlist' of https://github.com/rainbow-me/…
walmat 12373a0
search tweaks
benisgold 9f579df
lots of refactoring
benisgold c65cfc6
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
benisgold 9901c88
separate search queries in zustand
benisgold db52c0b
need to remove useAssetsToSell
benisgold 0334e97
cleanup
benisgold 8113d4c
coin icon
benisgold 5fae5a8
cleanup
benisgold 0a2e5d4
memo
benisgold File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import React, { useCallback, useMemo } from 'react'; | ||
import { ButtonPressAnimation } from '@/components/animations'; | ||
import { Box, HitSlop, Inline, Stack, Text } from '@/design-system'; | ||
import { TextColor } from '@/design-system/color/palettes'; | ||
import { CoinRowButton } from '@/__swaps__/screens/Swap/components/CoinRowButton'; | ||
import { BalancePill } from '@/__swaps__/screens/Swap/components/BalancePill'; | ||
import Animated from 'react-native-reanimated'; | ||
import { StyleSheet } from 'react-native'; | ||
import { useSwapContext } from '@/__swaps__/screens/Swap/providers/swap-provider'; | ||
import { UniqueId } from '@/__swaps__/types/assets'; | ||
import { userAssetsStore } from '@/state/assets/userAssets'; | ||
import { parseSearchAsset } from '@/__swaps__/utils/assets'; | ||
import { SwapAssetType } from '@/__swaps__/types/swap'; | ||
|
||
const CoinName = ({ assetId }: { assetId: UniqueId }) => { | ||
const name = userAssetsStore(state => state.getUserAsset(assetId).name); | ||
return ( | ||
<Text color="label" size="17pt" weight="semibold"> | ||
{name} | ||
</Text> | ||
); | ||
}; | ||
|
||
const CoinUserBalance = ({ assetId }: { assetId: UniqueId }) => { | ||
const balance = userAssetsStore(state => state.getUserAsset(assetId).balance.display); | ||
return ( | ||
<Text color="labelTertiary" size="13pt" weight="semibold"> | ||
{balance} | ||
</Text> | ||
); | ||
}; | ||
|
||
const CoinSymbol = ({ assetId }: { assetId: UniqueId }) => { | ||
const symbol = userAssetsStore(state => state.getUserAsset(assetId).symbol); | ||
return ( | ||
<Text color="labelTertiary" size="13pt" weight="semibold"> | ||
{symbol} | ||
</Text> | ||
); | ||
}; | ||
|
||
const CoinPercentChange = ({ assetId }: { assetId: UniqueId }) => { | ||
const isTrending = false; // fix this when implementing token to sell list | ||
|
||
const percentChange = useMemo(() => { | ||
if (isTrending) { | ||
const rawChange = Math.random() * 30; | ||
const isNegative = Math.random() < 0.2; | ||
const prefix = isNegative ? '-' : '+'; | ||
const color: TextColor = isNegative ? 'red' : 'green'; | ||
const change = `${rawChange.toFixed(1)}%`; | ||
|
||
return { change, color, prefix }; | ||
} | ||
}, [isTrending]); | ||
|
||
if (!isTrending || !percentChange) return null; | ||
|
||
return ( | ||
<Inline alignVertical="center" space={{ custom: 1 }}> | ||
<Text align="center" color={percentChange.color} size="12pt" weight="bold"> | ||
{percentChange.prefix} | ||
</Text> | ||
<Text color={percentChange.color} size="13pt" weight="semibold"> | ||
{percentChange.change} | ||
</Text> | ||
</Inline> | ||
); | ||
}; | ||
|
||
const CoinIcon = ({ assetId }: { assetId: UniqueId }) => { | ||
const { AnimatedSwapStyles } = useSwapContext(); | ||
return ( | ||
<Box | ||
as={Animated.View} | ||
borderRadius={18} | ||
height={{ custom: 36 }} | ||
style={[styles.solidColorCoinIcon, AnimatedSwapStyles.assetToSellIconStyle]} | ||
width={{ custom: 36 }} | ||
/> | ||
); | ||
}; | ||
|
||
const CoinInfoButton = ({ assetId }: { assetId: UniqueId }) => { | ||
return <CoinRowButton icon="" outline size="icon 14px" />; | ||
}; | ||
|
||
const CoinFavoriteButton = ({ assetId }: { assetId: UniqueId }) => { | ||
const address = userAssetsStore(state => state.getUserAsset(assetId).address); | ||
const isFavorited = userAssetsStore(state => state.isFavorite(assetId)); | ||
return ( | ||
<CoinRowButton | ||
color={isFavorited ? '#FFCB0F' : undefined} | ||
onPress={() => userAssetsStore.getState().toggleFavorite(address)} | ||
icon="" | ||
weight="black" | ||
/> | ||
); | ||
}; | ||
|
||
const CoinActions = ({ assetId }: { assetId: UniqueId }) => { | ||
return ( | ||
<Inline space="8px"> | ||
<CoinInfoButton assetId={assetId} /> | ||
<CoinFavoriteButton assetId={assetId} /> | ||
</Inline> | ||
); | ||
}; | ||
|
||
const CoinBalance = ({ assetId }: { assetId: UniqueId }) => { | ||
const nativeBalance = userAssetsStore(state => state.getUserAsset(assetId).native.balance.display); | ||
return <BalancePill balance={nativeBalance} />; | ||
}; | ||
|
||
export const CoinRow2 = React.memo(({ assetId, output = false }: { assetId: string; output?: boolean }) => { | ||
const { setAsset } = useSwapContext(); | ||
|
||
const handleSelectToken = useCallback(() => { | ||
const userAsset = userAssetsStore.getState().getUserAsset(assetId); | ||
const parsedAsset = parseSearchAsset({ | ||
assetWithPrice: undefined, | ||
searchAsset: userAsset, | ||
userAsset, | ||
}); | ||
|
||
setAsset({ | ||
type: SwapAssetType.inputAsset, | ||
asset: parsedAsset, | ||
}); | ||
}, [assetId, setAsset]); | ||
|
||
return ( | ||
<ButtonPressAnimation disallowInterruption onPress={handleSelectToken} scaleTo={0.95}> | ||
<HitSlop vertical="10px"> | ||
<Box | ||
alignItems="center" | ||
paddingVertical="10px" | ||
paddingHorizontal="20px" | ||
flexDirection="row" | ||
justifyContent="space-between" | ||
width="full" | ||
> | ||
<Inline alignVertical="center" space="10px"> | ||
<CoinIcon assetId={assetId} /> | ||
<Stack space="10px"> | ||
<CoinName assetId={assetId} /> | ||
<Inline alignVertical="center" space={{ custom: 5 }}> | ||
{!output ? <CoinUserBalance assetId={assetId} /> : <CoinSymbol assetId={assetId} />} | ||
<CoinPercentChange assetId={assetId} /> | ||
</Inline> | ||
</Stack> | ||
</Inline> | ||
{output ? <CoinActions assetId={assetId} /> : <CoinBalance assetId={assetId} />} | ||
</Box> | ||
</HitSlop> | ||
</ButtonPressAnimation> | ||
); | ||
}); | ||
|
||
CoinRow2.displayName = 'CoinRow'; | ||
|
||
export const styles = StyleSheet.create({ | ||
solidColorCoinIcon: { | ||
opacity: 0.4, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 13 additions & 49 deletions
62
src/__swaps__/screens/Swap/components/TokenList/TokenToSellList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { EthereumAddress } from '@rainbow-me/swaps'; | ||
import { Migration, MigrationName } from '../types'; | ||
import { RainbowToken } from '@/entities'; | ||
import { queryClient } from '@/react-query'; | ||
import { favoritesQueryKey } from '@/resources/favorites'; | ||
import { Hex } from 'viem'; | ||
import { userAssetsStore } from '@/state/assets/userAssets'; | ||
|
||
export function migrateFavoritesToZustand(): Migration { | ||
return { | ||
name: MigrationName.migrateFavoritesToZustand, | ||
async migrate() { | ||
const favorites = queryClient.getQueryData<Record<EthereumAddress, RainbowToken>>(favoritesQueryKey); | ||
|
||
if (favorites) { | ||
const favoriteAddresses: Hex[] = []; | ||
Object.keys(favorites).forEach((address: string) => { | ||
favoriteAddresses.push(address as Hex); | ||
}); | ||
|
||
userAssetsStore.setState({ | ||
favorites: new Set(favoriteAddresses), | ||
}); | ||
} | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the change here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh hmm i see nvm, good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can prob improve later also. for example, rank
startsWith
matches for name higher thanincludes
matches for name, if that makes sense.