2018-12-24 01:44:31 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { View, ActivityIndicator, Image, Text, TouchableOpacity, FlatList } from 'react-native';
|
2019-08-03 23:29:15 +02:00
|
|
|
import { SafeBlueArea, BlueNavigationStyle, BlueText, BlueSpacing20, BluePrivateBalance } from '../../BlueComponents';
|
2018-12-24 01:44:31 +01:00
|
|
|
import LinearGradient from 'react-native-linear-gradient';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet';
|
|
|
|
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
2019-01-25 05:46:03 +01:00
|
|
|
import WalletGradient from '../../class/walletGradient';
|
2018-12-24 01:44:31 +01:00
|
|
|
/** @type {AppStorage} */
|
|
|
|
let BlueApp = require('../../BlueApp');
|
|
|
|
let loc = require('../../loc');
|
|
|
|
|
|
|
|
export default class SelectWallet extends Component {
|
2019-10-02 00:12:59 +02:00
|
|
|
static navigationOptions = ({ navigation }) => ({
|
|
|
|
...BlueNavigationStyle(navigation, true, navigation.getParam('dismissAcion')),
|
2018-12-24 01:44:31 +01:00
|
|
|
title: loc.wallets.select_wallet,
|
|
|
|
});
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2019-10-02 00:12:59 +02:00
|
|
|
props.navigation.setParams({ dismissAcion: this.dismissComponent });
|
2018-12-24 01:44:31 +01:00
|
|
|
this.state = {
|
|
|
|
isLoading: true,
|
|
|
|
data: [],
|
|
|
|
};
|
2019-10-03 05:06:47 +02:00
|
|
|
this.chainType = props.navigation.getParam('chainType');
|
2018-12-24 01:44:31 +01:00
|
|
|
}
|
|
|
|
|
2019-10-02 00:12:59 +02:00
|
|
|
dismissComponent = () => {
|
|
|
|
this.props.navigation.goBack(null);
|
|
|
|
};
|
|
|
|
|
2018-12-24 01:44:31 +01:00
|
|
|
componentDidMount() {
|
2019-10-03 05:06:47 +02:00
|
|
|
const wallets = this.chainType
|
|
|
|
? BlueApp.getWallets().filter(item => item.chain === this.chainType && item.allowSend())
|
|
|
|
: BlueApp.getWallets();
|
2018-12-24 01:44:31 +01:00
|
|
|
this.setState({
|
|
|
|
data: wallets,
|
|
|
|
isLoading: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderItem = ({ item }) => {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
onPress={() => {
|
2019-05-03 14:36:11 +02:00
|
|
|
ReactNativeHapticFeedback.trigger('selection', { ignoreAndroidSystemSettings: false });
|
2018-12-24 01:44:31 +01:00
|
|
|
this.props.navigation.getParam('onWalletSelect')(item);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<View
|
|
|
|
shadowOpacity={40 / 100}
|
|
|
|
shadowOffset={{ width: 0, height: 0 }}
|
|
|
|
shadowRadius={5}
|
|
|
|
style={{ backgroundColor: 'transparent', padding: 10, marginVertical: 17 }}
|
|
|
|
>
|
|
|
|
<LinearGradient
|
|
|
|
shadowColor="#000000"
|
2019-01-25 05:46:03 +01:00
|
|
|
colors={WalletGradient.gradientsFor(item.type)}
|
2018-12-24 01:44:31 +01:00
|
|
|
style={{
|
|
|
|
padding: 15,
|
|
|
|
borderRadius: 10,
|
|
|
|
minHeight: 164,
|
|
|
|
elevation: 5,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Image
|
|
|
|
source={
|
2018-12-28 16:52:06 +01:00
|
|
|
(LightningCustodianWallet.type === item.type && require('../../img/lnd-shape.png')) || require('../../img/btc-shape.png')
|
2018-12-24 01:44:31 +01:00
|
|
|
}
|
|
|
|
style={{
|
|
|
|
width: 99,
|
|
|
|
height: 94,
|
|
|
|
position: 'absolute',
|
|
|
|
bottom: 0,
|
|
|
|
right: 0,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Text style={{ backgroundColor: 'transparent' }} />
|
|
|
|
<Text
|
|
|
|
numberOfLines={1}
|
|
|
|
style={{
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
fontSize: 19,
|
|
|
|
color: '#fff',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{item.getLabel()}
|
|
|
|
</Text>
|
2019-08-03 23:29:15 +02:00
|
|
|
{item.hideBalance ? (
|
|
|
|
<BluePrivateBalance />
|
|
|
|
) : (
|
|
|
|
<Text
|
|
|
|
numberOfLines={1}
|
|
|
|
adjustsFontSizeToFit
|
|
|
|
style={{
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
fontWeight: 'bold',
|
|
|
|
fontSize: 36,
|
|
|
|
color: '#fff',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{loc.formatBalance(Number(item.getBalance()), item.getPreferredBalanceUnit(), true)}
|
|
|
|
</Text>
|
|
|
|
)}
|
2018-12-24 01:44:31 +01:00
|
|
|
<Text style={{ backgroundColor: 'transparent' }} />
|
|
|
|
<Text
|
|
|
|
numberOfLines={1}
|
|
|
|
style={{
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
fontSize: 13,
|
|
|
|
color: '#fff',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{loc.wallets.list.latest_transaction}
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
numberOfLines={1}
|
|
|
|
style={{
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
fontWeight: 'bold',
|
|
|
|
fontSize: 16,
|
|
|
|
color: '#fff',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{loc.transactionTimeToReadable(item.getLatestTransactionTime())}
|
|
|
|
</Text>
|
|
|
|
</LinearGradient>
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2019-01-05 02:47:26 +01:00
|
|
|
if (this.state.isLoading) {
|
2018-12-24 01:44:31 +01:00
|
|
|
return (
|
2019-01-05 02:47:26 +01:00
|
|
|
<View style={{ flex: 1, justifyContent: 'center', alignContent: 'center', paddingTop: 20 }}>
|
2018-12-24 01:44:31 +01:00
|
|
|
<ActivityIndicator />
|
|
|
|
</View>
|
|
|
|
);
|
2019-01-05 02:47:26 +01:00
|
|
|
} else if (this.state.data.length <= 0) {
|
|
|
|
return (
|
|
|
|
<SafeBlueArea style={{ flex: 1 }}>
|
|
|
|
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', paddingTop: 20 }}>
|
|
|
|
<BlueText style={{ textAlign: 'center' }}>There are currently no Bitcoin wallets available.</BlueText>
|
|
|
|
<BlueSpacing20 />
|
|
|
|
<BlueText style={{ textAlign: 'center' }}>
|
|
|
|
A Bitcoin wallet is required to refill Lightning wallets. Please, create or import one.
|
|
|
|
</BlueText>
|
|
|
|
</View>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
2018-12-24 01:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<SafeBlueArea>
|
|
|
|
<FlatList
|
|
|
|
style={{ flex: 1 }}
|
|
|
|
extraData={this.state.data}
|
|
|
|
data={this.state.data}
|
|
|
|
renderItem={this._renderItem}
|
|
|
|
keyExtractor={(_item, index) => `${index}`}
|
|
|
|
/>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectWallet.propTypes = {
|
|
|
|
navigation: PropTypes.shape({
|
|
|
|
navigate: PropTypes.func,
|
2019-10-02 00:12:59 +02:00
|
|
|
goBack: PropTypes.func,
|
2018-12-24 01:44:31 +01:00
|
|
|
setParams: PropTypes.func,
|
|
|
|
getParam: PropTypes.func,
|
|
|
|
}),
|
|
|
|
};
|