added link component with some tweaks to transaction list (#98)

This commit is contained in:
akinwale 2018-05-10 18:38:07 +01:00 committed by GitHub
parent fffa136b3f
commit 6abf511ef4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 89 additions and 17 deletions

View file

@ -3,7 +3,7 @@ import { Text, TouchableOpacity } from 'react-native';
import buttonStyle from '../../styles/button'; import buttonStyle from '../../styles/button';
import Icon from 'react-native-vector-icons/FontAwesome'; import Icon from 'react-native-vector-icons/FontAwesome';
export default class Button extends React.PureComponent<Props> { export default class Button extends React.PureComponent {
render() { render() {
const { const {
disabled, disabled,

View file

@ -0,0 +1,9 @@
import { connect } from 'react-redux';
import { doNotify } from 'lbry-redux';
import Link from './view';
const perform = dispatch => ({
notify: (data) => dispatch(doNotify(data))
});
export default connect(null, perform)(Link);

View file

@ -0,0 +1,38 @@
import React from 'react';
import { Linking, Text, TouchableOpacity } from 'react-native';
export default class Link extends React.PureComponent {
handlePress = () => {
const { error, href, navigation, notify } = this.props;
if (navigation && href.startsWith('#')) {
navigation.navigate(href.substring(1));
} else {
Linking.openURL(href).catch(err => notify({
message: error,
displayType: ['toast']
}));
}
}
render() {
const {
onPress,
style,
text
} = this.props;
let styles = [];
if (style.length) {
styles = styles.concat(style);
} else {
styles.push(style);
}
return (
<TouchableOpacity onPress={onPress ? onPress : this.handlePress}>
<Text style={styles}>{text}</Text>
</TouchableOpacity>
);
}
};

View file

@ -8,6 +8,4 @@ const select = state => ({
myClaims: selectAllMyClaimsByOutpoint(state), myClaims: selectAllMyClaimsByOutpoint(state),
}); });
const perform = dispatch => ({}); export default connect(select, null)(TransactionList);
export default connect(select, perform)(TransactionList);

View file

@ -1,7 +1,8 @@
// @flow // @flow
import React from 'react'; import React from 'react';
import { Text, View } from 'react-native'; import { Text, View, Linking } from 'react-native';
import { formatCredits } from 'lbry-redux'; import { buildURI, formatCredits } from 'lbry-redux';
import Link from '../../link';
import moment from 'moment'; import moment from 'moment';
import transactionListStyle from '../../../styles/transactionList'; import transactionListStyle from '../../../styles/transactionList';
@ -11,14 +12,20 @@ class TransactionListItem extends React.PureComponent {
} }
render() { render() {
const { transaction } = this.props; const { transaction, navigation } = this.props;
const { amount, claim_id: claimId, claim_name: name, date, fee, txid, type } = transaction; const { amount, claim_id: claimId, claim_name: name, date, fee, txid, type } = transaction;
return ( return (
<View style={transactionListStyle.listItem}> <View style={transactionListStyle.listItem}>
<View style={[transactionListStyle.row, transactionListStyle.topRow]}> <View style={[transactionListStyle.row, transactionListStyle.topRow]}>
<View style={transactionListStyle.col}> <View style={transactionListStyle.col}>
<Text style={transactionListStyle.text}>{this.capitalize(type)}</Text> <Text style={transactionListStyle.text}>{this.capitalize(type)}</Text>
{name && claimId && (
<Link
style={transactionListStyle.link}
onPress={() => navigation && navigation.navigate('File', { uri: buildURI({ claimName: name, claimId }) })}
text={name} />
)}
</View> </View>
<View style={transactionListStyle.col}> <View style={transactionListStyle.col}>
<Text style={[transactionListStyle.amount, transactionListStyle.text]}>{formatCredits(amount, 8)}</Text> <Text style={[transactionListStyle.amount, transactionListStyle.text]}>{formatCredits(amount, 8)}</Text>
@ -27,7 +34,10 @@ class TransactionListItem extends React.PureComponent {
</View> </View>
<View style={transactionListStyle.row}> <View style={transactionListStyle.row}>
<View style={transactionListStyle.col}> <View style={transactionListStyle.col}>
<Text style={[transactionListStyle.smallText, transactionListStyle.txid]}>{txid.substring(0, 8)}</Text> <Link style={transactionListStyle.smallLink}
text={txid.substring(0, 8)}
href={`https://explorer.lbry.io/tx/${txid}`}
error={'The transaction URL could not be opened'} />
</View> </View>
<View style={transactionListStyle.col}> <View style={transactionListStyle.col}>
{date ? ( {date ? (

View file

@ -40,7 +40,7 @@ class TransactionList extends React.PureComponent {
} }
render() { render() {
const { emptyMessage, rewards, transactions } = this.props; const { emptyMessage, rewards, transactions, navigation } = this.props;
const { filter } = this.state; const { filter } = this.state;
const transactionList = transactions.filter(this.filterTransaction); const transactionList = transactions.filter(this.filterTransaction);
@ -56,6 +56,7 @@ class TransactionList extends React.PureComponent {
<TransactionListItem <TransactionListItem
key={`${t.txid}:${t.nout}`} key={`${t.txid}:${t.nout}`}
transaction={t} transaction={t}
navigation={navigation}
reward={rewards && rewards[t.txid]} reward={rewards && rewards[t.txid]}
/> />
))} ))}

View file

@ -3,6 +3,7 @@ import React from 'react';
//import BusyIndicator from 'component/common/busy-indicator'; //import BusyIndicator from 'component/common/busy-indicator';
import { Text, View } from 'react-native'; import { Text, View } from 'react-native';
import Button from '../button'; import Button from '../button';
import Link from '../link';
import TransactionList from '../transactionList'; import TransactionList from '../transactionList';
import type { Transaction } from '../transactionList/view'; import type { Transaction } from '../transactionList/view';
import walletStyle from '../../styles/wallet'; import walletStyle from '../../styles/wallet';
@ -26,14 +27,17 @@ class TransactionListRecent extends React.PureComponent<Props> {
<View style={walletStyle.transactionsCard}> <View style={walletStyle.transactionsCard}>
<View style={[walletStyle.row, walletStyle.transactionsHeader]}> <View style={[walletStyle.row, walletStyle.transactionsHeader]}>
<Text style={walletStyle.transactionsTitle}>Recent Transactions</Text> <Text style={walletStyle.transactionsTitle}>Recent Transactions</Text>
<Button style={walletStyle.button} text={'View All'} <Link style={walletStyle.link}
onPress={() => navigation.navigate('TransactionHistory')} /> navigation={navigation}
text={'View All'}
href={'#TransactionHistory'} />
</View> </View>
{fetchingTransactions && ( {fetchingTransactions && (
<Text style={walletStyle.infoText}>Fetching transactions...</Text> <Text style={walletStyle.infoText}>Fetching transactions...</Text>
)} )}
{!fetchingTransactions && ( {!fetchingTransactions && (
<TransactionList <TransactionList
navigation={navigation}
transactions={transactions} transactions={transactions}
emptyMessage={"Looks like you don't have any recent transactions."} emptyMessage={"Looks like you don't have any recent transactions."}
/> />

View file

@ -9,7 +9,7 @@ class TransactionHistoryPage extends React.PureComponent {
} }
render() { render() {
const { fetchingTransactions, transactions } = this.props; const { fetchingTransactions, transactions, navigation } = this.props;
return ( return (
<ScrollView> <ScrollView>
@ -18,7 +18,7 @@ class TransactionHistoryPage extends React.PureComponent {
<Text style={walletStyle.infoText}>Loading transactions...</Text> <Text style={walletStyle.infoText}>Loading transactions...</Text>
)} )}
{transactions && transactions.length && ( {transactions && transactions.length && (
<TransactionList transactions={transactions} /> <TransactionList navigation={navigation} transactions={transactions} />
)} )}
</View> </View>
</ScrollView> </ScrollView>

View file

@ -24,17 +24,24 @@ const transactionListStyle = StyleSheet.create({
fontFamily: 'Metropolis-Regular', fontFamily: 'Metropolis-Regular',
fontSize: 14 fontSize: 14
}, },
link: {
color: Colors.LbryGreen,
fontFamily: 'Metropolis-Regular',
fontSize: 14
},
amount: { amount: {
textAlign: 'right' textAlign: 'right'
}, },
txid: {
color: Colors.LbryGreen
},
smallText: { smallText: {
fontFamily: 'Metropolis-Regular', fontFamily: 'Metropolis-Regular',
fontSize: 12, fontSize: 12,
color: '#aaaaaa' color: '#aaaaaa'
}, },
smallLink: {
color: Colors.LbryGreen,
fontFamily: 'Metropolis-Regular',
fontSize: 12
},
noTransactions: { noTransactions: {
fontFamily: 'Metropolis-Regular', fontFamily: 'Metropolis-Regular',
textAlign: 'center', textAlign: 'center',

View file

@ -57,6 +57,11 @@ const walletStyle = StyleSheet.create({
fontFamily: 'Metropolis-Regular', fontFamily: 'Metropolis-Regular',
fontSize: 14 fontSize: 14
}, },
link: {
color: Colors.LbryGreen,
fontFamily: 'Metropolis-Regular',
fontSize: 14
},
smallText: { smallText: {
fontFamily: 'Metropolis-Regular', fontFamily: 'Metropolis-Regular',
fontSize: 12 fontSize: 12