Skip to content

Commit

Permalink
Merge branch 'develop' into wallet-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
wolverineks committed Feb 7, 2023
2 parents 9771ced + 591e8a5 commit 5380a7e
Show file tree
Hide file tree
Showing 65 changed files with 407 additions and 250 deletions.
1 change: 1 addition & 0 deletions android/app/src/dev/res/xml/network_security_config.xml
Expand Up @@ -6,6 +6,7 @@
<domain includeSubdomains="false">10.0.3.2</domain>
<domain includeSubdomains="false">192.168.86.21</domain>
<domain includeSubdomains="false">192.168.2.21</domain>
<domain includeSubdomains="false">192.168.2.25</domain>
<domain includeSubdomains="false">192.168.0.101</domain>
<domain includeSubdomains="false">192.168.1.101</domain>
</domain-config>
Expand Down
48 changes: 22 additions & 26 deletions src/Send/ScannerButton.tsx
@@ -1,36 +1,32 @@
import {useNavigation} from '@react-navigation/native'
import React from 'react'
import {StyleSheet} from 'react-native'
import {TouchableOpacity} from 'react-native'

import iconQR from '../assets/img/qr_code.png'
import {Button} from '../components'
import {Icon} from '../components'

export const ScannerButton = () => {
const navigation = useNavigation()
const navigateTo = useNavigateTo()

return (
<Button
style={styles.scannerButton}
onPress={() => {
navigation.navigate('app-root', {
screen: 'main-wallet-routes',
params: {
screen: 'history',
params: {
screen: 'address-reader-qr',
},
},
})
}}
iconImage={iconQR}
title=""
withoutBackground
/>
<TouchableOpacity onPress={navigateTo.reader}>
<Icon.Qr color="black" size={30} />
</TouchableOpacity>
)
}

const styles = StyleSheet.create({
scannerButton: {
height: '80%',
},
})
const useNavigateTo = () => {
const navigation = useNavigation()

return {
reader: () =>
navigation.navigate('app-root', {
screen: 'main-wallet-routes',
params: {
screen: 'history',
params: {
screen: 'address-reader-qr',
},
},
}),
}
}
2 changes: 2 additions & 0 deletions src/Send/SendScreen/SendScreen.tsx
Expand Up @@ -21,6 +21,7 @@ import type {
BalanceValidationErrors,
} from '../../yoroi-wallets/utils/validators'
import {useSend} from '../Context/SendContext'
import {ScannerButton} from '../ScannerButton'
import {AmountField} from './../AmountField'
import {AvailableAmountBanner} from './AvailableAmountBanner'
import {BalanceAfterTransaction} from './BalanceAfterTransaction'
Expand Down Expand Up @@ -157,6 +158,7 @@ export const SendScreen = () => {

<TextInput
value={receiver}
right={<ScannerButton />}
multiline
errorOnMount
onChangeText={receiverChanged}
Expand Down
30 changes: 30 additions & 0 deletions src/TxHistory/AssetList/AssetItem/AssetItem.stories.tsx
@@ -0,0 +1,30 @@
import {action} from '@storybook/addon-actions'
import {storiesOf} from '@storybook/react-native'
import React from 'react'
import {Text, View} from 'react-native'

import {mocks, QueryProvider} from '../../../../storybook'
import {Spacer} from '../../../components'
import {SelectedWalletProvider} from '../../../SelectedWallet'
import {AssetItem} from './AssetItem'

storiesOf('AssetItem', module).add('Gallery', () => (
<QueryProvider>
<SelectedWalletProvider wallet={mocks.wallet}>
<View style={{flex: 1, justifyContent: 'center', padding: 16}}>
<Text>Fungible primary token</Text>

<AssetItem tokenInfo={mocks.wallet.primaryTokenInfo} onPress={action('onPress')} />

<Spacer height={40} />

<Text>Fungible non-primary token</Text>

<AssetItem
tokenInfo={mocks.tokenInfos['698a6ea0ca99f315034072af31eaac6ec11fe8558d3f48e9775aab9d.7444524950']}
onPress={action('onPress')}
/>
</View>
</SelectedWalletProvider>
</QueryProvider>
))
114 changes: 114 additions & 0 deletions src/TxHistory/AssetList/AssetItem/AssetItem.tsx
@@ -0,0 +1,114 @@
import * as React from 'react'
import {Image, StyleSheet, TouchableOpacity, View, ViewProps} from 'react-native'

import NoImage from '../../../assets/img/asset_no_image.png'
import {Icon} from '../../../components'
import {Text} from '../../../components/Text'
import {useBalance} from '../../../hooks'
import {useSelectedWallet} from '../../../SelectedWallet'
import {COLORS} from '../../../theme'
import {TokenInfo} from '../../../yoroi-wallets/types'
import {Quantities} from '../../../yoroi-wallets/utils'
import {PairedBalance} from '../../PairedBalance'

type AssetItemProps = {
tokenInfo: TokenInfo
onPress?(): void
}
export const AssetItem = ({tokenInfo, onPress}: AssetItemProps) => {
const wallet = useSelectedWallet()
const balance = useBalance({wallet, tokenId: tokenInfo.id})

const isPrimary = tokenInfo.id === wallet.primaryTokenInfo.id
const name = tokenInfo.ticker ?? tokenInfo.name ?? '-'
const detail = isPrimary ? tokenInfo.description : tokenInfo.fingerprint
const quantity = Quantities.denominated(balance, tokenInfo.decimals)

return (
<TouchableOpacity onPress={onPress} style={styles.button} testID="assetItem">
<Left>{isPrimary ? <PrimaryTokenIcon /> : <TokenIcon source={NoImage} />}</Left>

<Middle>
<Text numberOfLines={1} ellipsizeMode="middle" style={styles.name} testID="tokenInfoText">
{name}
</Text>

<Text numberOfLines={1} ellipsizeMode="middle" style={styles.detail} testID="tokenFingerprintText">
{detail}
</Text>
</Middle>

<Right>
<Text style={styles.quantity} testID="tokenAmountText">
{quantity}
</Text>

{isPrimary && <PairedBalance primaryAmount={{quantity: balance, tokenId: tokenInfo.id}} />}
</Right>
</TouchableOpacity>
)
}

const Left = ({style, ...props}: ViewProps) => <View style={[style, {padding: 4}]} {...props} />
const Middle = ({style, ...props}: ViewProps) => (
<View style={[style, {flex: 1, justifyContent: 'center', padding: 4}]} {...props} />
)
const Right = ({style, ...props}: ViewProps) => <View style={[style, {padding: 4}]} {...props} />

type IconProps = {
source: {uri: string}
}
const TokenIcon = ({source}: IconProps) => <Image source={source} style={styles.tokenIcon} />
const PrimaryTokenIcon = () => (
<View style={styles.primaryTokenIcon}>
<Icon.Cardano color="white" height={35} width={35} />
</View>
)

const styles = StyleSheet.create({
primaryTokenIcon: {
width: 40,
height: 40,
borderRadius: 8,
backgroundColor: COLORS.SHELLEY_BLUE,
alignItems: 'center',
justifyContent: 'center',
},
tokenIcon: {
width: 40,
height: 40,
borderRadius: 8,
backgroundColor: 'transparent',
alignItems: 'center',
justifyContent: 'center',
},
button: {
flexDirection: 'row',
justifyContent: 'space-between',
borderRadius: 8,
elevation: 2,
shadowOffset: {width: 0, height: -2},
shadowRadius: 10,
shadowOpacity: 0.08,
shadowColor: '#181a1e',
backgroundColor: '#fff',
paddingHorizontal: 12,
paddingVertical: 12,
},
name: {
color: COLORS.DARK_TEXT,
fontSize: 14,
lineHeight: 22,
fontWeight: '500',
fontFamily: 'Rubik-Medium',
},
detail: {
color: COLORS.TEXT_INPUT,
fontSize: 12,
lineHeight: 18,
},
quantity: {
color: COLORS.DARK_TEXT,
textAlign: 'right',
},
})
1 change: 1 addition & 0 deletions src/TxHistory/AssetList/AssetItem/index.ts
@@ -0,0 +1 @@
export * from './AssetItem'
88 changes: 5 additions & 83 deletions src/TxHistory/AssetList/AssetList.tsx
@@ -1,21 +1,18 @@
import React from 'react'
import {defineMessages} from 'react-intl'
import {useIntl} from 'react-intl'
import {Alert, FlatList, FlatListProps, StyleSheet, TouchableOpacity, View, ViewProps} from 'react-native'
import {Avatar} from 'react-native-paper'
import {Alert, FlatList, FlatListProps, StyleSheet, View} from 'react-native'

import AdaImage from '../../assets/img/asset_ada.png'
import NoImage from '../../assets/img/asset_no_image.png'
import {Boundary, Text} from '../../components'
import {Boundary} from '../../components'
import {Spacer} from '../../components/Spacer'
import {useBalance, useBalances, useTokenInfos} from '../../hooks'
import {useBalances, useTokenInfos} from '../../hooks'
import globalMessages, {actionMessages} from '../../i18n/global-messages'
import {useSelectedWallet} from '../../SelectedWallet'
import {COLORS} from '../../theme'
import {sortTokenInfos} from '../../utils'
import {TokenInfo} from '../../yoroi-wallets/types'
import {Amounts, Quantities} from '../../yoroi-wallets/utils'
import {Amounts} from '../../yoroi-wallets/utils'
import {ActionsBanner} from './ActionsBanner'
import {AssetItem} from './AssetItem'

type ListProps = FlatListProps<TokenInfo>
type Props = Partial<ListProps> & {
Expand Down Expand Up @@ -63,85 +60,10 @@ export const AssetList = (props: Props) => {
)
}

type AssetItemProps = {
tokenInfo: TokenInfo
onPress?: () => void
}

const AssetItem = ({tokenInfo, onPress}: AssetItemProps) => {
const wallet = useSelectedWallet()
const balance = useBalance({wallet, tokenId: tokenInfo.id})
const isPrimary = tokenInfo.id === wallet.primaryTokenInfo.id

return (
<TouchableOpacity onPress={onPress} style={styles.button} testID="assetItem">
<Left>
<Icon source={isPrimary ? AdaImage : NoImage} />
</Left>

<Middle>
<Text numberOfLines={1} ellipsizeMode="middle" style={styles.tokenInfo} testID="tokenInfoText">
{tokenInfo.ticker ?? tokenInfo.name ?? '-'}
</Text>

<Text numberOfLines={1} ellipsizeMode="middle" style={styles.tokenName} testID="tokenFingerprintText">
{isPrimary ? '' : tokenInfo.fingerprint}
</Text>
</Middle>

<Right>
<Text style={styles.tokenAmount} testID="tokenAmountText">
{Quantities.denominated(balance, tokenInfo.decimals)}
</Text>
</Right>
</TouchableOpacity>
)
}

const Left = ({style, ...props}: ViewProps) => <View style={[style, {padding: 4}]} {...props} />
const Middle = ({style, ...props}: ViewProps) => (
<View style={[style, {flex: 1, justifyContent: 'center', padding: 4}]} {...props} />
)
const Right = ({style, ...props}: ViewProps) => <View style={[style, {padding: 4}]} {...props} />

const styles = StyleSheet.create({
assetList: {flex: 1},
button: {
flexDirection: 'row',
justifyContent: 'space-between',
borderRadius: 8,
elevation: 2,
shadowOffset: {width: 0, height: -2},
shadowRadius: 10,
shadowOpacity: 0.08,
shadowColor: '#181a1e',
backgroundColor: '#fff',
paddingHorizontal: 12,
paddingVertical: 12,
},
tokenInfo: {
color: COLORS.DARK_TEXT,
fontSize: 14,
lineHeight: 22,
},
tokenName: {
color: COLORS.TEXT_INPUT,
fontSize: 12,
lineHeight: 18,
},
tokenAmount: {
color: COLORS.DARK_TEXT,
},
})

const Icon = (props) => (
<Avatar.Image
{...props}
size={32}
style={{alignItems: 'center', justifyContent: 'center', backgroundColor: 'transparent'}}
/>
)

const messages = defineMessages({
unknownAsset: {
id: 'components.send.assetselectorscreen.unknownAsset',
Expand Down

0 comments on commit 5380a7e

Please sign in to comment.