-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90cee78
commit 68284a3
Showing
34 changed files
with
460 additions
and
283 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
apps/wallet-mobile/src/TxHistory/AssetList/ActionsBanner.stories.tsx
This file was deleted.
Oops, something went wrong.
75 changes: 0 additions & 75 deletions
75
apps/wallet-mobile/src/TxHistory/AssetList/ActionsBanner.tsx
This file was deleted.
Oops, something went wrong.
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
34 changes: 34 additions & 0 deletions
34
apps/wallet-mobile/src/TxHistory/AssetList/FilterBalancesByType.stories.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,34 @@ | ||
import {action} from '@storybook/addon-actions' | ||
import {storiesOf} from '@storybook/react-native' | ||
import React from 'react' | ||
|
||
import {FilterBalancesByType} from './FilterBalancesByType' | ||
|
||
storiesOf('TxHistory Filter Balances By Type', module).add('all (initial)', () => ( | ||
<FilterBalancesByType<'all' | 'assets' | 'tokens'> | ||
chips={[ | ||
{ | ||
label: 'All', | ||
value: 'all', | ||
onPress: () => { | ||
action('all') | ||
}, | ||
} as const, | ||
{ | ||
label: 'Assets', | ||
value: 'assets', | ||
onPress: () => { | ||
action('assets') | ||
}, | ||
} as const, | ||
{ | ||
label: 'Tokens', | ||
value: 'tokens', | ||
onPress: () => { | ||
action('tokens') | ||
}, | ||
} as const, | ||
]} | ||
selectedValue="all" | ||
/> | ||
)) |
53 changes: 53 additions & 0 deletions
53
apps/wallet-mobile/src/TxHistory/AssetList/FilterBalancesByType.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,53 @@ | ||
import {useTheme} from '@yoroi/theme' | ||
import * as React from 'react' | ||
import {StyleSheet, View} from 'react-native' | ||
|
||
import {Spacer} from '../../components/Spacer' | ||
import {ChipButton} from './ChipButton' | ||
|
||
type Props<T> = { | ||
selectedValue: T | ||
chips: ReadonlyArray<{ | ||
label: string | ||
value: T | ||
onPress: () => void | ||
disabled?: boolean | ||
}> | ||
} | ||
|
||
export const FilterBalancesByType = <T,>({chips, selectedValue}: Props<T>) => { | ||
const {styles} = useStyles() | ||
|
||
return ( | ||
<View style={styles.root}> | ||
{chips.map(({label, disabled, onPress, value}, index) => ( | ||
<> | ||
<ChipButton | ||
key={index} | ||
label={label} | ||
disabled={disabled} | ||
onPress={onPress} | ||
selected={selectedValue === value} | ||
/> | ||
|
||
{index != chips.length - 1 && <Spacer width={12} />} | ||
</> | ||
))} | ||
</View> | ||
) | ||
} | ||
|
||
const useStyles = () => { | ||
const {theme} = useTheme() | ||
const {padding} = theme | ||
const styles = StyleSheet.create({ | ||
root: { | ||
display: 'flex', | ||
...padding['x-l'], | ||
...padding['b-xxs'], | ||
justifyContent: 'flex-start', | ||
flexDirection: 'row', | ||
}, | ||
}) | ||
return {styles} | ||
} |
122 changes: 122 additions & 0 deletions
122
apps/wallet-mobile/src/TxHistory/AssetList/ListBalances.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,122 @@ | ||
import {useFocusEffect} from '@react-navigation/native' | ||
import {FlashList, FlashListProps} from '@shopify/flash-list' | ||
import {useTheme} from '@yoroi/theme' | ||
import {Portfolio} from '@yoroi/types' | ||
import * as React from 'react' | ||
import {useIntl} from 'react-intl' | ||
import {Linking, StyleSheet, TouchableOpacity, View} from 'react-native' | ||
|
||
import {Spacer} from '../../components/Spacer' | ||
import {TokenAmountItem, TokenAmountItemProps} from '../../components/TokenAmountItem/TokenAmountItem' | ||
import {useExplorers} from '../../features/Explorer/common/useExplorers' | ||
import {usePortfolioBalances} from '../../features/Portfolio/common/hooks/usePortfolioBalances' | ||
import {usePrivacyMode} from '../../features/Settings/PrivacyMode/PrivacyMode' | ||
import {useSelectedWallet} from '../../features/WalletManager/Context' | ||
import globalMessages from '../../i18n/global-messages' | ||
import {useMetrics} from '../../metrics/metricsManager' | ||
import {FilterBalancesByType} from './FilterBalancesByType' | ||
|
||
type ListProps = FlashListProps<Portfolio.Token.Amount> | ||
type Props = Partial<ListProps> & { | ||
onScroll: ListProps['onScroll'] | ||
refreshing: boolean | ||
onRefresh: () => void | ||
} | ||
export const ListBalances = (props: Props) => { | ||
const strings = useStrings() | ||
const styles = useStyles() | ||
const {track} = useMetrics() | ||
const wallet = useSelectedWallet() | ||
const balances = usePortfolioBalances({wallet}) | ||
const explorers = useExplorers(wallet.network) | ||
const {isPrivacyOff, privacyPlaceholder} = usePrivacyMode() | ||
|
||
const [filteringBy, setFilteringBy] = React.useState<keyof typeof balances>('all') | ||
const [isPending, startTransition] = React.useTransition() | ||
|
||
useFocusEffect( | ||
React.useCallback(() => { | ||
track.assetsPageViewed() | ||
}, [track]), | ||
) | ||
|
||
const handleOnPressNFTs = React.useCallback(() => startTransition(() => setFilteringBy('nfts')), []) | ||
const handleOnPressFTs = React.useCallback(() => startTransition(() => setFilteringBy('fts')), []) | ||
const handleOnPressAll = React.useCallback(() => startTransition(() => setFilteringBy('all')), []) | ||
const chips = [ | ||
{label: strings.tokens(balances.fts.length), onPress: handleOnPressFTs, value: 'fts', disabled: isPending}, | ||
{label: strings.nfts(balances.nfts.length), onPress: handleOnPressNFTs, value: 'nfts', disabled: isPending}, | ||
{label: strings.all, onPress: handleOnPressAll, value: 'all', disabled: isPending}, | ||
] | ||
|
||
return ( | ||
<View style={styles.assetList} testID="assetList"> | ||
<FilterBalancesByType selectedValue={filteringBy} chips={chips} /> | ||
|
||
<FlashList | ||
{...props} | ||
data={balances[filteringBy]} | ||
renderItem={({item: amount}) => ( | ||
<ExplorableAssetItem | ||
isMainnet={wallet.isMainnet} | ||
privacyPlaceholder={privacyPlaceholder} | ||
isPrivacyOff={isPrivacyOff} | ||
amount={amount} | ||
onPress={() => Linking.openURL(explorers.cardanoscan.token(amount.info.id))} | ||
/> | ||
)} | ||
ItemSeparatorComponent={() => <Spacer height={16} />} | ||
contentContainerStyle={styles.content} | ||
keyExtractor={(_, index) => index.toString()} | ||
estimatedItemSize={78} | ||
/> | ||
</View> | ||
) | ||
} | ||
|
||
type ExplorableAssetItemProps = TokenAmountItemProps & { | ||
onPress(): void | ||
} | ||
const ExplorableAssetItem = ({onPress, ...tokenAmountProps}: ExplorableAssetItemProps) => { | ||
const styles = useStyles() | ||
return ( | ||
<TouchableOpacity style={styles.button} onPress={onPress} testID="assetSelectorItem"> | ||
<TokenAmountItem {...tokenAmountProps} /> | ||
</TouchableOpacity> | ||
) | ||
} | ||
|
||
const useStyles = () => { | ||
const {theme} = useTheme() | ||
const {color, padding} = theme | ||
const styles = StyleSheet.create({ | ||
content: { | ||
...padding['t-l'], | ||
...padding['x-l'], | ||
...padding['b-s'], | ||
}, | ||
assetList: {flex: 1}, | ||
button: { | ||
...padding['m'], | ||
backgroundColor: color.gray.min, | ||
shadowColor: color.gray[100], | ||
borderRadius: 8, | ||
elevation: 2, | ||
shadowOffset: {width: 0, height: -2}, | ||
shadowRadius: 10, | ||
shadowOpacity: 0.08, | ||
}, | ||
}) | ||
|
||
return styles | ||
} | ||
|
||
const useStrings = () => { | ||
const intl = useIntl() | ||
|
||
return React.useRef({ | ||
tokens: (qty: number) => `${intl.formatMessage(globalMessages.tokens, {qty})} (${qty})`, | ||
nfts: (qty: number) => `${intl.formatMessage(globalMessages.nfts, {qty})} (${qty})`, | ||
all: intl.formatMessage(globalMessages.all), | ||
}).current | ||
} |
Oops, something went wrong.