Skip to content
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

fix(wallet-mobile): portfolio ui issues #3329

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import {useTheme} from '@yoroi/theme'
import * as React from 'react'
import {FlatList, Image, StyleSheet, Text, TouchableOpacity, TouchableOpacityProps, View} from 'react-native'
import {
FlatList,
Image,
StyleSheet,
Text,
TouchableOpacity,
TouchableOpacityProps,
useWindowDimensions,
View,
} from 'react-native'

import nftPlaceholder from '../../../../../assets/img/nft-placeholder.png'
import {Icon, Spacer} from '../../../../../components'
Expand All @@ -11,7 +20,7 @@ import {useNavigateTo} from '../../../common/useNavigateTo'
import {useStrings} from '../../../common/useStrings'

export const DashboardNFTsList = () => {
const {styles} = useStyles()
const {styles, cardItemWidth} = useStyles()
const navigationTo = useNavigateTo()

const {wallet} = useSelectedWallet()
Expand Down Expand Up @@ -42,8 +51,8 @@ export const DashboardNFTsList = () => {
showsHorizontalScrollIndicator={false}
keyExtractor={(item) => item.info.id}
renderItem={({item}) => (
<View>
<MediaPreview info={item.info} width={164} height={164} style={styles.image} />
<View style={[styles.nftItemContainer, {width: cardItemWidth}]}>
<MediaPreview info={item.info} width={cardItemWidth} height={cardItemWidth} style={styles.image} />
</View>
)}
/>
Expand Down Expand Up @@ -79,6 +88,13 @@ const TouchNFTsList = ({onPress}: TouchableOpacityProps) => {

const useStyles = () => {
const {atoms, color} = useTheme()
const {width: SCREEN_WIDTH} = useWindowDimensions()
const PADDING_LEFT_SIDE = 16
const PADDING_RIGHT_SIDE_FOR_ITEMS = 15
const GAP_ITEMS = 8
const initCardWidth = SCREEN_WIDTH - PADDING_LEFT_SIDE
const cardItemWidth = (initCardWidth - PADDING_RIGHT_SIDE_FOR_ITEMS - GAP_ITEMS) / 2

const styles = StyleSheet.create({
container: {
...atoms.px_lg,
Expand All @@ -104,10 +120,13 @@ const useStyles = () => {
width: 164,
height: 164,
},
nftItemContainer: {
aspectRatio: 1 / 1,
},
})
const colors = {
gray_800: color.gray_c800,
}

return {styles, colors} as const
return {styles, colors, cardItemWidth} as const
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ export const DashboardTokenItem = ({tokenInfo}: Props) => {
const {quantityChangePercent, variantPnl} = useQuantityChange({previousQuantity, quantity, decimals: info.decimals})

return (
<TouchableOpacity onPress={() => navigationTo.tokenDetail({id: info.id})}>
<View style={styles.root}>
<TouchableOpacity onPress={() => navigationTo.tokenDetail({id: info.id})} style={styles.root}>
<View style={styles.container}>
<TokenInfo info={info} />

<Spacer height={16} />
<Spacer fill />

<View style={styles.quantityContainer}>
<PnlTag variant={variantPnl} withIcon>
<Text>{quantityChangePercent}%</Text>
</PnlTag>

<Text style={styles.tokenValue}>{formattedQuantity}</Text>
<Text ellipsizeMode="tail" numberOfLines={1} style={styles.tokenValue}>
{formattedQuantity}
</Text>

<PairedBalance textStyle={styles.pairedTokenValue} amount={tokenInfo} />
</View>
Expand Down Expand Up @@ -77,14 +79,16 @@ const useStyles = () => {
const {atoms, color} = useTheme()
const styles = StyleSheet.create({
root: {
...atoms.h_full,
},
container: {
...atoms.p_lg,
...atoms.rounded_sm,
...atoms.flex_col,
...atoms.align_start,
...atoms.border,
...atoms.flex_1,
borderColor: color.gray_c300,
width: 164,
...atoms.h_full,
},
symbol: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,33 @@ export const DashboardTokenSkeletonItem = () => {
const {color, styles} = useStyles()

return (
<SkeletonPlaceholder backgroundColor={color.gray_c100}>
<View style={styles.fullSize}>
<View style={styles.root}>
<SkeletonPlaceholder.Item flexDirection="row" gap={12} alignItems="center">
<SkeletonPlaceholder.Item width={40} height={40} borderRadius={8} />
<SkeletonPlaceholder backgroundColor={color.gray_c100}>
<SkeletonPlaceholder.Item flexDirection="row" gap={12} alignItems="center">
<SkeletonPlaceholder.Item width={40} height={40} borderRadius={8} />

<SkeletonPlaceholder.Item flexDirection="column" gap={6}>
<SkeletonPlaceholder.Item width={39} height={16} borderRadius={8} />
<SkeletonPlaceholder.Item flexDirection="column" gap={6}>
<SkeletonPlaceholder.Item width={39} height={16} borderRadius={8} />

<SkeletonPlaceholder.Item width={53} height={12} borderRadius={8} />
<SkeletonPlaceholder.Item width={53} height={12} borderRadius={8} />
</SkeletonPlaceholder.Item>
</SkeletonPlaceholder.Item>
</SkeletonPlaceholder.Item>
</SkeletonPlaceholder>

<Spacer height={16} />
<Spacer fill />

<SkeletonPlaceholder.Item>
<SkeletonPlaceholder.Item width={64} height={20} borderRadius={8} marginBottom={7} />
<SkeletonPlaceholder backgroundColor={color.gray_c100}>
<SkeletonPlaceholder.Item>
<SkeletonPlaceholder.Item width={64} height={20} borderRadius={8} marginBottom={7} />

<SkeletonPlaceholder.Item width={128} height={16} borderRadius={8} marginBottom={7} />
<SkeletonPlaceholder.Item width={128} height={16} borderRadius={8} marginBottom={7} />

<SkeletonPlaceholder.Item width={75} height={12} borderRadius={8} marginVertical={3} />
</SkeletonPlaceholder.Item>
<SkeletonPlaceholder.Item width={75} height={12} borderRadius={8} marginVertical={3} />
</SkeletonPlaceholder.Item>
</SkeletonPlaceholder>
</View>
</SkeletonPlaceholder>
</View>
)
}
const useStyles = () => {
Expand All @@ -43,8 +47,13 @@ const useStyles = () => {
...atoms.flex_col,
...atoms.align_start,
...atoms.border,
...atoms.w_full,
...atoms.h_full,
borderColor: color.gray_c300,
width: 164,
},
fullSize: {
...atoms.w_full,
...atoms.h_full,
},
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import {isPrimaryToken} from '@yoroi/portfolio'
import {useTheme} from '@yoroi/theme'
import * as React from 'react'
import {FlatList, StyleSheet, Text, TouchableOpacity, TouchableOpacityProps, View} from 'react-native'
import {
FlatList,
StyleSheet,
Text,
TouchableOpacity,
TouchableOpacityProps,
useWindowDimensions,
View,
} from 'react-native'

import {Icon, Spacer} from '../../../../../components'
import {makeList} from '../../../../../kernel/utils'
Expand All @@ -17,7 +25,7 @@ import {DashboardTokenSkeletonItem} from './DashboardTokenSkeletonItem'
import {TradeTokensBanner} from './TradeTokensBanner'

export const DashboardTokensList = () => {
const {styles} = useStyles()
const {styles, cardItemWidth, cardItemWidthForJustAda} = useStyles()
const navigationTo = useNavigateTo()
const isZeroADABalance = useZeroBalance()
const {isLoading} = useGetTokensWithBalance()
Expand Down Expand Up @@ -45,48 +53,64 @@ export const DashboardTokensList = () => {
<View />

{makeList(3).map((_, index) => (
<DashboardTokenSkeletonItem key={index} />
<View style={[styles.tokenItemContainer, {width: cardItemWidth}]} key={index}>
<DashboardTokenSkeletonItem />
</View>
))}

<Spacer width={8} />
</View>
)

return (
<View style={styles.tradeTokensContainer}>
{isJustADA && (
<View style={styles.tradeTokensContainer}>
<Spacer width={16} />
return <Spacer width={16} />
}

const renderTokensList = () => {
if (isZeroADABalance) {
return (
<View style={styles.container}>
<BuyADABanner />
</View>
)
}

if (isJustADA) {
return (
<View style={styles.justAdaContainer}>
<View style={[styles.tokenItemContainer, {width: cardItemWidthForJustAda}]}>
<DashboardTokenItem tokenInfo={tokensList[0]} />
</View>

<View style={[styles.tokenItemContainer, {width: cardItemWidthForJustAda}]}>
<TradeTokensBanner />
</View>
)}
</View>
)
}

<Spacer width={16} />
</View>
return (
<FlatList
horizontal
data={tokensList}
ListHeaderComponent={<Spacer width={16} />}
ListFooterComponent={renderFooterList()}
ItemSeparatorComponent={() => <Spacer width={8} />}
showsHorizontalScrollIndicator={false}
keyExtractor={(item) => item.info.id}
renderItem={({item}) => (
<View style={[styles.tokenItemContainer, {width: cardItemWidth}]}>
<DashboardTokenItem tokenInfo={item} />
</View>
)}
/>
)
}

return (
<View style={styles.root}>
<Heading countTokens={tokensList.length} onPress={handleDirectTokensList} isFirstUser={isFirstUser} />

{isZeroADABalance ? (
<View style={styles.container}>
<BuyADABanner />
</View>
) : (
<FlatList
horizontal
data={tokensList}
ListHeaderComponent={<Spacer width={16} />}
ListFooterComponent={renderFooterList()}
ItemSeparatorComponent={() => <Spacer width={8} />}
showsHorizontalScrollIndicator={false}
keyExtractor={(item) => item.info.id}
renderItem={({item}) => <DashboardTokenItem key={item?.info?.id} tokenInfo={item} />}
/>
)}
{renderTokensList()}
</View>
)
}
Expand Down Expand Up @@ -121,6 +145,16 @@ const TouchTokensList = ({onPress}: TouchableOpacityProps) => {

const useStyles = () => {
const {atoms, color} = useTheme()
const {width: SCREEN_WIDTH} = useWindowDimensions()
const PADDING_LEFT_SIDE = 16
const PADDING_RIGHT_SIDE_FOR_ITEMS = 15
const PADDING_RIGHT_SIDE_FOR_JUST_ADA = 16
const GAP_ITEMS = 8
const GAP_FOR_JUST_ADA = 16
const initCardWidth = SCREEN_WIDTH - PADDING_LEFT_SIDE
const cardItemWidth = (initCardWidth - PADDING_RIGHT_SIDE_FOR_ITEMS - GAP_ITEMS) / 2
const cardItemWidthForJustAda = (initCardWidth - PADDING_RIGHT_SIDE_FOR_JUST_ADA - GAP_FOR_JUST_ADA) / 2

const styles = StyleSheet.create({
container: {
...atoms.px_lg,
Expand All @@ -138,19 +172,27 @@ const useStyles = () => {
...atoms.body_1_lg_medium,
color: color.gray_c900,
},
tradeTokensContainer: {
...atoms.flex_row,
...atoms.flex_1,
},
containerLoading: {
...atoms.flex_row,
...atoms.gap_sm,
},
justAdaContainer: {
...atoms.flex_row,
...atoms.gap_lg,
...atoms.overflow_hidden,
...atoms.w_full,
...atoms.pl_lg,
paddingRight: 15,
...atoms.align_start,
},
tokenItemContainer: {
aspectRatio: 195 / 186,
},
})

const colors = {
gray_800: color.gray_c800,
}

return {styles, colors} as const
return {styles, colors, cardItemWidth, cardItemWidthForJustAda} as const
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const useStyles = () => {
const {atoms, color} = useTheme()
const styles = StyleSheet.create({
root: {
width: 164,
...atoms.flex_1,
...atoms.h_full,
},
gradientRoot: {
...atoms.p_lg,
Expand Down