/
AssetList.js
110 lines (100 loc) · 2.95 KB
/
AssetList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// @flow
import React from 'react'
import {Text, View, FlatList, TouchableOpacity} from 'react-native'
import {injectIntl} from 'react-intl'
import type {Node, ComponentType} from 'react'
import {getAssetNameOrUnknown, formatTokenAmount, getAssetDenomination} from '../../../utils/format'
import baseStyle from './styles/Base.style'
import assetListTransactionStyle from './styles/AssetListTransaction.style'
import assetListSendStyle from './styles/AssetListSend.style'
import globalMessages, {
txLabels,
} from '../../../i18n/global-messages'
import type {TokenEntry} from '../../../crypto/MultiToken'
import type {Token} from '../../../types/HistoryTransaction'
type NodeStyle = typeof baseStyle | typeof assetListTransactionStyle | typeof assetListSendStyle
type Props = {
assets: Array<TokenEntry>,
assetsMetadata: Dict<Token>,
styles: NodeStyle,
onSelect?: (TokenEntry) => any,
intl: any,
}
const AssetRow: ({|
styles: NodeStyle,
asset: TokenEntry,
assetMetadata: Token,
isLast: boolean,
backColor: {|backgroundColor: string|},
onSelect?: (TokenEntry) => any,
intl: injectIntl,
|}) => Node = ({styles, asset, assetMetadata, backColor, onSelect, intl}) => {
const item = (
<>
<View style={styles.tokenMeta}>
<Text style={styles.assetName}>
{getAssetNameOrUnknown(
assetMetadata,
intl,
)}
</Text>
<Text style={styles.assetMeta}>{getAssetDenomination(assetMetadata, 'fingerprint')}</Text>
</View>
<View>
<Text style={styles.assetBalance}>
{formatTokenAmount(asset.amount, assetMetadata)}
</Text>
</View>
</>
)
if (onSelect == null) {
return (
<View style={[styles.assetRow, styles.py5, styles.px5, backColor]}>
{item}
</View>
)
} else {
return (
<TouchableOpacity
onPress={() => onSelect(asset)}
style={[styles.assetRow, styles.py5, styles.px5, backColor]}
>
{item}
</TouchableOpacity>
)
}
}
const AssetList: (props: Props) => Node = ({
assets,
assetsMetadata,
styles,
onSelect,
intl,
}) => {
const colors = [styles.rowColor1, styles.rowColor2]
return (
<View>
<View style={styles.assetTitle}>
<Text style={styles.assetHeading}>{intl.formatMessage(globalMessages.assetsLabel)}</Text>
<Text style={styles.assetHeading}>{intl.formatMessage(txLabels.amount)}</Text>
</View>
<View>
<FlatList
data={assets}
keyExtractor={(item, index) => index.toString()}
renderItem={({item, index}) => (
<AssetRow
asset={item}
assetMetadata={assetsMetadata[item.identifier]}
styles={styles}
backColor={colors[index % colors.length]}
onSelect={onSelect}
intl={intl}
/>)
}
/>
</View>
</View>
)
}
export default injectIntl((AssetList: ComponentType<Props>))