-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add token search and user asset search
- Loading branch information
Showing
18 changed files
with
507 additions
and
164 deletions.
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
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
44 changes: 44 additions & 0 deletions
44
src/__swaps__/screens/Swap/components/TokenList/TokenToBuyList.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as i18n from '@/languages'; | ||
import React, { useMemo } from 'react'; | ||
import { useAssetsToBuySections } from '../../hooks/useAssetsToBuy'; | ||
import { TokenToBuySection } from './TokenToBuySection'; | ||
import { Box, Stack, Text } from '@/design-system'; | ||
import { useSwapAssetStore } from '../../state/assets'; | ||
import { isL2Chain } from '../../utils/chains'; | ||
|
||
export const TokenToBuyList = () => { | ||
const { outputChainId } = useSwapAssetStore(); | ||
const sections = useAssetsToBuySections(); | ||
|
||
const isL2 = useMemo(() => outputChainId && isL2Chain(outputChainId), [outputChainId]); | ||
|
||
const assetsCount = useMemo(() => sections?.reduce((count, section) => count + section.data.length, 0), [sections]); | ||
|
||
return ( | ||
<Stack space="20px"> | ||
{sections.map(section => ( | ||
<TokenToBuySection key={section.id} section={section} /> | ||
))} | ||
|
||
{!assetsCount && ( | ||
<Box alignItems="center" style={{ paddingTop: 91 }}> | ||
<Box paddingHorizontal="44px"> | ||
<Stack space="16px"> | ||
<Text color="label" size="26pt" weight="bold" align="center"> | ||
{'👻'} | ||
</Text> | ||
|
||
<Text color="labelTertiary" size="20pt" weight="semibold" align="center"> | ||
{i18n.t(i18n.l.swap.tokens_input.nothing_found)} | ||
</Text> | ||
|
||
<Text color="labelQuaternary" size="14px / 19px (Deprecated)" weight="regular" align="center"> | ||
{i18n.t(i18n.l.swap.tokens_input[isL2 ? 'nothing_found_description_l2' : 'nothing_found_description'])} | ||
</Text> | ||
</Stack> | ||
</Box> | ||
</Box> | ||
)} | ||
</Stack> | ||
); | ||
}; |
134 changes: 134 additions & 0 deletions
134
src/__swaps__/screens/Swap/components/TokenList/TokenToBuySection.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import * as i18n from '@/languages'; | ||
import React, { useCallback, useMemo } from 'react'; | ||
import { CoinRow } from '../CoinRow'; | ||
import { useSwapAssetStore } from '../../state/assets'; | ||
import { SearchAsset } from '../../types/search'; | ||
import { Box, Inline, Inset, Stack, Text } from '@/design-system'; | ||
import { TextStyle } from 'react-native'; | ||
import { AssetToBuySection, AssetToBuySectionId } from '../../hooks/useSearchCurrencyLists'; | ||
import { ChainId } from '../../types/chains'; | ||
import { BackgroundColor, TextColor } from '@/design-system/color/palettes'; | ||
|
||
interface SectionProp { | ||
backgroundColor?: BackgroundColor; | ||
gradient?: React.ReactNode; | ||
color: TextStyle['color']; | ||
symbol: string; | ||
title: string; | ||
} | ||
|
||
const sectionProps: { [id in AssetToBuySectionId]: SectionProp } = { | ||
favorites: { | ||
title: i18n.t(i18n.l.token_search.section_header.favorites), | ||
symbol: 'star.fill', | ||
color: 'yellow', | ||
gradient: undefined, | ||
backgroundColor: undefined, | ||
}, | ||
bridge: { | ||
title: i18n.t(i18n.l.token_search.section_header.bridge), | ||
symbol: 'shuffle', | ||
color: 'label', | ||
gradient: undefined, | ||
backgroundColor: undefined, | ||
}, | ||
verified: { | ||
title: i18n.t(i18n.l.token_search.section_header.verified), | ||
symbol: 'checkmark.seal.fill', | ||
color: 'labelTertiary', | ||
// gradient: rainbowGradient, | ||
backgroundColor: undefined, | ||
}, | ||
unverified: { | ||
title: i18n.t(i18n.l.token_search.section_header.unverified), | ||
symbol: 'exclamationmark.triangle.fill', | ||
color: 'labelTertiary', | ||
gradient: undefined, | ||
backgroundColor: undefined, | ||
}, | ||
other_networks: { | ||
title: i18n.t(i18n.l.token_search.section_header.on_other_networks), | ||
symbol: 'network', | ||
color: 'labelTertiary', | ||
gradient: undefined, | ||
backgroundColor: undefined, | ||
}, | ||
}; | ||
|
||
const bridgeSectionsColorsByChain = { | ||
[ChainId.mainnet]: 'mainnet' as TextStyle['color'], | ||
[ChainId.arbitrum]: 'arbitrum' as TextStyle['color'], | ||
[ChainId.optimism]: 'optimism' as TextStyle['color'], | ||
[ChainId.polygon]: 'polygon' as TextStyle['color'], | ||
[ChainId.base]: 'base' as TextStyle['color'], | ||
[ChainId.zora]: 'zora' as TextStyle['color'], | ||
[ChainId.bsc]: 'bsc' as TextStyle['color'], | ||
[ChainId.avalanche]: 'avalanche' as TextStyle['color'], | ||
}; | ||
|
||
export const TokenToBuySection = ({ section }: { section: AssetToBuySection }) => { | ||
const { outputChainId, setAssetToBuy } = useSwapAssetStore(); | ||
|
||
const handleSelectToken = useCallback( | ||
(token: SearchAsset) => { | ||
setAssetToBuy(token); | ||
// TODO: Close the input dropdown and open the output token dropdown | ||
}, | ||
[setAssetToBuy] | ||
); | ||
|
||
const { backgroundColor, gradient, symbol, title } = sectionProps[section.id]; | ||
|
||
const color = useMemo(() => { | ||
if (section.id !== 'bridge') { | ||
return sectionProps[section.id].color as TextColor; | ||
} | ||
return bridgeSectionsColorsByChain[outputChainId || ChainId.mainnet] as TextColor; | ||
}, [section.id, outputChainId]); | ||
|
||
if (!section.data.length) return null; | ||
|
||
return ( | ||
<Box key={section.id} testID={`${section.id}-token-to-buy-section`}> | ||
<Stack space="20px"> | ||
{section.id === 'other_networks' ? ( | ||
<Box borderRadius={12} height={{ custom: 52 }}> | ||
<Inset horizontal="20px" vertical="8px"> | ||
<Inline space="8px" alignVertical="center"> | ||
{/* <SwapCoinIcon /> */} | ||
<Text size="icon 14px" weight="semibold" color={'labelQuaternary'}> | ||
{i18n.t(i18n.l.swap.tokens_input.nothing_found)} | ||
</Text> | ||
</Inline> | ||
</Inset> | ||
</Box> | ||
) : null} | ||
<Box paddingHorizontal={{ custom: 15 }}> | ||
<Box paddingHorizontal={{ custom: 5 }} width="full"> | ||
<Inline space="4px" alignVertical="center"> | ||
{/* <Symbol symbol={symbol} color={color} weight="semibold" size={14} gradient={gradient} /> */} | ||
<Box background={backgroundColor} style={{ width: 225 }}> | ||
<Text size="14px / 19px (Deprecated)" weight="semibold" color={color}> | ||
{title} | ||
</Text> | ||
</Box> | ||
</Inline> | ||
</Box> | ||
</Box> | ||
|
||
{section.data.map(token => ( | ||
<CoinRow | ||
key={token.uniqueId} | ||
address={token.address} | ||
balance={''} | ||
name={token.name} | ||
onPress={() => handleSelectToken(token)} | ||
nativeBalance={''} | ||
output | ||
symbol={token.symbol} | ||
/> | ||
))} | ||
</Stack> | ||
</Box> | ||
); | ||
}; |
39 changes: 39 additions & 0 deletions
39
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { useCallback } from 'react'; | ||
import { CoinRow } from '../CoinRow'; | ||
import { useAssetsToSell } from '../../hooks/useAssetsToSell'; | ||
import { ParsedSearchAsset } from '../../types/assets'; | ||
import { useSwapAssetStore } from '../../state/assets'; | ||
import { Stack } from '@/design-system'; | ||
import { useSwapContext } from '../../providers/swap-provider'; | ||
|
||
export const TokenToSellList = () => { | ||
const { setAssetToSell } = useSwapAssetStore(); | ||
const { SwapInputController } = useSwapContext(); | ||
const assets = useAssetsToSell(); | ||
|
||
const handleSelectToken = useCallback( | ||
(token: ParsedSearchAsset) => { | ||
setAssetToSell(token); | ||
SwapInputController.formattedInputAmount; | ||
// TODO: Close the input dropdown and open the output token dropdown | ||
}, | ||
[setAssetToSell] | ||
); | ||
|
||
return ( | ||
<Stack space="20px"> | ||
{assets.map((token: ParsedSearchAsset) => ( | ||
<CoinRow | ||
key={token.uniqueId} | ||
address={token.address} | ||
balance={token.balance.display} | ||
name={token.name} | ||
onPress={() => handleSelectToken(token)} | ||
nativeBalance={token.native.balance.display} | ||
output={false} | ||
symbol={token.symbol} | ||
/> | ||
))} | ||
</Stack> | ||
); | ||
}; |
Oops, something went wrong.