BlueWallet/screen/wallets/selectWallet.js

151 lines
5.0 KiB
JavaScript
Raw Normal View History

2020-01-02 06:32:35 +01:00
/* eslint-disable react/prop-types */
import React, { useEffect, useState } from 'react';
2018-12-24 01:44:31 +01:00
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 { 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';
2020-01-02 06:32:35 +01:00
import { useNavigationParam } from 'react-navigation-hooks';
2018-12-24 01:44:31 +01:00
/** @type {AppStorage} */
2020-01-02 06:32:35 +01:00
const BlueApp = require('../../BlueApp');
const loc = require('../../loc');
2018-12-24 01:44:31 +01:00
2020-01-02 06:32:35 +01:00
const SelectWallet = () => {
2020-01-19 19:10:06 +01:00
const chainType = useNavigationParam('chainType');
2020-01-02 06:32:35 +01:00
const onWalletSelect = useNavigationParam('onWalletSelect');
const [isLoading, setIsLoading] = useState(true);
const data = chainType
? BlueApp.getWallets().filter(item => item.chain === chainType && item.allowSend())
: BlueApp.getWallets().filter(item => item.allowSend()) || [];
2020-01-02 06:32:35 +01:00
useEffect(() => {
setIsLoading(false);
});
2018-12-24 01:44:31 +01:00
2020-01-02 06:32:35 +01:00
const renderItem = ({ item }) => {
2018-12-24 01:44:31 +01:00
return (
<TouchableOpacity
onPress={() => {
2019-05-03 14:36:11 +02:00
ReactNativeHapticFeedback.trigger('selection', { ignoreAndroidSystemSettings: false });
2020-01-02 06:32:35 +01:00
onWalletSelect(item);
2018-12-24 01:44:31 +01:00
}}
>
<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={
(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>
);
};
2020-01-02 06:32:35 +01:00
if (isLoading) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignContent: 'center', paddingTop: 20 }}>
<ActivityIndicator />
</View>
);
} else if (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>
2018-12-24 01:44:31 +01:00
</View>
2020-01-02 06:32:35 +01:00
</SafeBlueArea>
);
} else {
2018-12-24 01:44:31 +01:00
return (
2020-01-02 06:32:35 +01:00
<SafeBlueArea style={{ flex: 1 }}>
<FlatList extraData={data} data={data} renderItem={renderItem} keyExtractor={(_item, index) => `${index}`} />
2018-12-24 01:44:31 +01:00
</SafeBlueArea>
);
}
};
2020-01-02 06:32:35 +01:00
SelectWallet.navigationOptions = ({ navigation }) => ({
...BlueNavigationStyle(navigation, true, () => navigation.goBack(null)),
title: loc.wallets.select_wallet,
});
export default SelectWallet;