BlueWallet/screen/wallets/transactions.js

842 lines
27 KiB
JavaScript
Raw Normal View History

/* global alert */
import React, { Component } from 'react';
import { Chain } from '../../models/bitcoinUnits';
2019-09-19 01:26:28 +02:00
import {
Text,
Platform,
2019-09-29 22:01:27 +02:00
StyleSheet,
2019-09-19 01:26:28 +02:00
View,
2019-09-29 22:01:27 +02:00
Keyboard,
2019-09-19 01:26:28 +02:00
ActivityIndicator,
InteractionManager,
FlatList,
Dimensions,
2019-11-02 21:58:55 +01:00
ScrollView,
2019-09-19 01:26:28 +02:00
RefreshControl,
TouchableOpacity,
StatusBar,
2019-09-29 22:01:27 +02:00
Linking,
KeyboardAvoidingView,
2020-01-01 04:31:04 +01:00
Alert,
Clipboard,
2019-09-19 01:26:28 +02:00
} from 'react-native';
import PropTypes from 'prop-types';
import ImagePicker from 'react-native-image-picker';
2019-09-29 22:01:27 +02:00
import {
BlueSendButtonIcon,
BlueListItem,
BlueReceiveButtonIcon,
BlueTransactionListItem,
BlueWalletNavigationHeader,
BlueAlertWalletExportReminder,
2019-09-29 22:01:27 +02:00
} from '../../BlueComponents';
import WalletGradient from '../../class/wallet-gradient';
import { Icon } from 'react-native-elements';
2020-02-26 15:39:19 +01:00
import { LightningCustodianWallet, WatchOnlyWallet } from '../../class';
2019-09-29 22:01:27 +02:00
import Modal from 'react-native-modal';
import * as NavigationService from '../../NavigationService';
2020-03-29 04:06:45 +02:00
import HandoffSettings from '../../class/handoff';
import Handoff from 'react-native-handoff';
2020-07-15 19:32:59 +02:00
import { BlueCurrentTheme } from '../../components/themes';
import ActionSheet from '../ActionSheet';
2020-07-20 15:38:46 +02:00
import loc from '../../loc';
/** @type {AppStorage} */
const BlueApp = require('../../BlueApp');
const EV = require('../../blue_modules/events');
const BlueElectrum = require('../../blue_modules/BlueElectrum');
const LocalQRCode = require('@remobile/react-native-qrcode-local-image');
const windowHeight = Dimensions.get('window').height;
const styles = StyleSheet.create({
flex: {
flex: 1,
},
scrollViewContent: {
flex: 1,
justifyContent: 'center',
paddingHorizontal: 16,
paddingVertical: 40,
},
modalContent: {
backgroundColor: '#FFFFFF',
padding: 22,
justifyContent: 'center',
alignItems: 'center',
borderTopLeftRadius: 16,
borderTopRightRadius: 16,
borderColor: 'rgba(0, 0, 0, 0.1)',
minHeight: 200,
height: 200,
},
advancedTransactionOptionsModalContent: {
2020-07-15 19:32:59 +02:00
backgroundColor: BlueCurrentTheme.colors.elevated,
padding: 22,
borderTopLeftRadius: 16,
borderTopRightRadius: 16,
borderColor: 'rgba(0, 0, 0, 0.1)',
minHeight: 130,
},
bottomModal: {
justifyContent: 'flex-end',
margin: 0,
},
walletDetails: {
marginHorizontal: 16,
minWidth: 150,
justifyContent: 'center',
alignItems: 'flex-end',
},
activityIndicator: {
marginVertical: 20,
},
listHeader: {
flexDirection: 'row',
margin: 16,
justifyContent: 'space-evenly',
},
listHeaderText: {
flex: 1,
marginLeft: 16,
marginTop: 8,
marginBottom: 8,
fontWeight: 'bold',
fontSize: 24,
2020-07-15 19:32:59 +02:00
color: BlueCurrentTheme.colors.foregroundColor,
},
marketplaceButton1: {
2020-07-15 19:32:59 +02:00
backgroundColor: BlueCurrentTheme.colors.lightButton,
borderRadius: 9,
minHeight: 49,
flex: 1,
paddingHorizontal: 8,
justifyContent: 'center',
flexDirection: 'row',
alignItems: 'center',
},
marketplaceButton2: {
marginLeft: 5,
2020-07-15 19:32:59 +02:00
backgroundColor: BlueCurrentTheme.colors.lightButton,
borderRadius: 9,
minHeight: 49,
flex: 1,
paddingHorizontal: 8,
justifyContent: 'center',
flexDirection: 'row',
alignItems: 'center',
},
marketpalceText1: {
2020-07-15 19:32:59 +02:00
color: BlueCurrentTheme.colors.cta2,
fontSize: 18,
},
marketpalceText2: {
2020-07-15 19:32:59 +02:00
color: BlueCurrentTheme.colors.cta2,
fontSize: 18,
marginHorizontal: 8,
},
list: {
2020-07-15 19:32:59 +02:00
backgroundColor: BlueCurrentTheme.colors.background,
flex: 1,
},
emptyTxs: {
fontSize: 18,
color: '#9aa0aa',
textAlign: 'center',
marginVertical: 16,
},
emptyTxsLightning: {
fontSize: 18,
color: '#9aa0aa',
textAlign: 'center',
fontWeight: '600',
},
buyBitcoin: {
backgroundColor: '#007AFF',
minWidth: 260,
borderRadius: 8,
alignSelf: 'center',
paddingVertical: 14,
paddingHorizontal: 32,
},
buyBitcoinText: {
fontSize: 15,
color: '#fff',
textAlign: 'center',
fontWeight: '600',
},
floatButtons: {
flexDirection: 'row',
alignSelf: 'center',
backgroundColor: 'transparent',
position: 'absolute',
bottom: 30,
borderRadius: 30,
minHeight: 48,
overflow: 'hidden',
},
});
export default class WalletTransactions extends Component {
walletBalanceText = null;
constructor(props) {
super(props);
// here, when we receive REMOTE_TRANSACTIONS_COUNT_CHANGED we fetch TXs and balance for current wallet
EV(EV.enum.REMOTE_TRANSACTIONS_COUNT_CHANGED, this.refreshTransactionsFunction.bind(this), true);
2020-05-27 13:12:17 +02:00
const wallet = props.route.params.wallet;
this.props.navigation.setParams({ wallet: wallet, isLoading: true });
this.state = {
2020-03-29 04:06:45 +02:00
isHandOffUseEnabled: false,
isLoading: true,
2019-09-29 22:01:27 +02:00
isManageFundsModalVisible: false,
2019-02-17 02:22:14 +01:00
showShowFlatListRefreshControl: false,
wallet: wallet,
2020-06-26 21:27:13 +02:00
itemPriceUnit: wallet.getPreferredBalanceUnit(),
dataSource: this.getTransactions(15),
2020-06-26 21:27:13 +02:00
timeElapsed: 0, // this is to force a re-render for FlatList items.
limit: 15,
pageSize: 20,
};
}
2020-06-03 04:04:18 +02:00
componentDidMount() {
this._unsubscribeFocus = this.props.navigation.addListener('focus', this.onFocus);
this.props.navigation.setParams({ isLoading: false });
2020-06-27 13:10:11 +02:00
this.interval = setInterval(() => {
this.setState(prev => ({ timeElapsed: prev.timeElapsed + 1 }));
}, 60000);
2020-06-03 04:04:18 +02:00
HandoffSettings.isHandoffUseEnabled().then(enabled => this.setState({ isHandOffUseEnabled: enabled }));
this.setState({ isLoading: false });
}
/**
* Forcefully fetches TXs and balance for wallet
*/
refreshTransactionsFunction() {
const that = this;
setTimeout(function () {
that.refreshTransactions();
}, 4000); // giving a chance to remote server to propagate
}
/**
* Simple wrapper for `wallet.getTransactions()`, where `wallet` is current wallet.
* Sorts. Provides limiting.
*
* @param limit {Integer} How many txs return, starting from the earliest. Default: all of them.
* @returns {Array}
*/
getTransactions(limit = Infinity) {
const wallet = this.props.route.params.wallet;
2019-12-25 21:53:53 +01:00
let txs = wallet.getTransactions();
for (const tx of txs) {
tx.sort_ts = +new Date(tx.received);
}
txs = txs.sort(function (a, b) {
return b.sort_ts - a.sort_ts;
});
return txs.slice(0, limit);
}
2019-02-17 02:22:14 +01:00
redrawScreen() {
InteractionManager.runAfterInteractions(async () => {
console.log('wallets/transactions redrawScreen()');
this.setState({
isLoading: false,
2019-02-17 02:22:14 +01:00
showShowFlatListRefreshControl: false,
dataSource: this.getTransactions(this.state.limit),
});
2019-02-17 02:22:14 +01:00
});
}
isLightning() {
const w = this.state.wallet;
2019-12-25 21:53:53 +01:00
if (w && w.chain === Chain.OFFCHAIN) {
return true;
}
return false;
}
/**
* Forcefully fetches TXs and balance for wallet
*/
refreshTransactions() {
2019-02-17 02:22:14 +01:00
if (this.state.isLoading) return;
this.setState(
{
2019-02-17 02:22:14 +01:00
showShowFlatListRefreshControl: true,
isLoading: true,
},
2019-02-17 02:22:14 +01:00
async () => {
let noErr = true;
let smthChanged = false;
try {
2019-07-13 17:21:03 +02:00
await BlueElectrum.ping();
await BlueElectrum.waitTillConnected();
2019-02-17 02:22:14 +01:00
/** @type {LegacyWallet} */
const wallet = this.state.wallet;
const balanceStart = +new Date();
2019-02-17 02:22:14 +01:00
const oldBalance = wallet.getBalance();
await wallet.fetchBalance();
if (oldBalance !== wallet.getBalance()) smthChanged = true;
const balanceEnd = +new Date();
2019-02-17 02:22:14 +01:00
console.log(wallet.getLabel(), 'fetch balance took', (balanceEnd - balanceStart) / 1000, 'sec');
const start = +new Date();
2019-02-17 02:22:14 +01:00
const oldTxLen = wallet.getTransactions().length;
await wallet.fetchTransactions();
if (wallet.fetchPendingTransactions) {
await wallet.fetchPendingTransactions();
}
2019-02-17 02:22:14 +01:00
if (wallet.fetchUserInvoices) {
await wallet.fetchUserInvoices();
}
if (oldTxLen !== wallet.getTransactions().length) smthChanged = true;
const end = +new Date();
2019-02-17 02:22:14 +01:00
console.log(wallet.getLabel(), 'fetch tx took', (end - start) / 1000, 'sec');
} catch (err) {
noErr = false;
alert(err.message);
2019-02-17 02:22:14 +01:00
this.setState({
isLoading: false,
showShowFlatListRefreshControl: false,
});
}
if (noErr && smthChanged) {
console.log('saving to disk');
await BlueApp.saveToDisk(); // caching
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED); // let other components know they should redraw
}
this.redrawScreen();
},
);
}
_keyExtractor = (_item, index) => index.toString();
renderListFooterComponent = () => {
// if not all txs rendered - display indicator
return (this.getTransactions(Infinity).length > this.state.limit && <ActivityIndicator style={styles.activityIndicator} />) || <View />;
};
renderListHeaderComponent = () => {
return (
<View style={styles.flex}>
<View style={styles.listHeader}>
{/*
2020-04-29 17:40:55 +02:00
Current logic - Onchain:
- Shows buy button on middle when empty
- Show buy button on top when not empty
- Shows Marketplace button on details screen, open in browser (iOS)
- Shows Marketplace button on details screen, open in in-app (android)
Current logic - Offchain:
- Shows Lapp Browser empty (iOS)
- Shows Lapp Browser with marketplace (android)
- Shows Marketplace button to open in browser (iOS)
The idea is to avoid showing on iOS an appstore/market style app that goes against the TOS.
2020-05-27 13:12:17 +02:00
*/}
2020-04-29 16:00:33 +02:00
{this.state.wallet.getTransactions().length > 0 &&
this.state.wallet.type !== LightningCustodianWallet.type &&
this.renderSellFiat()}
{this.state.wallet.type === LightningCustodianWallet.type && this.renderMarketplaceButton()}
2019-12-25 21:53:53 +01:00
{this.state.wallet.type === LightningCustodianWallet.type && Platform.OS === 'ios' && this.renderLappBrowserButton()}
</View>
2020-07-20 15:38:46 +02:00
<Text style={styles.listHeaderText}>{loc.transactions.list_title}</Text>
</View>
);
};
2019-09-29 22:01:27 +02:00
renderManageFundsModal = () => {
return (
<Modal
deviceHeight={windowHeight}
2019-09-29 22:01:27 +02:00
isVisible={this.state.isManageFundsModalVisible}
style={styles.bottomModal}
onBackdropPress={() => {
Keyboard.dismiss();
this.setState({ isManageFundsModalVisible: false });
}}
>
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'position' : null}>
<View style={styles.advancedTransactionOptionsModalContent}>
<BlueListItem
hideChevron
component={TouchableOpacity}
onPress={a => {
const wallets = [...BlueApp.getWallets().filter(item => item.chain === Chain.ONCHAIN && item.allowSend())];
if (wallets.length === 0) {
2020-07-20 15:38:46 +02:00
alert(loc.lnd.refill_create);
2019-09-29 22:01:27 +02:00
} else {
this.setState({ isManageFundsModalVisible: false });
2019-10-01 00:13:22 +02:00
this.props.navigation.navigate('SelectWallet', { onWalletSelect: this.onWalletSelect, chainType: Chain.ONCHAIN });
2019-09-29 22:01:27 +02:00
}
}}
2019-10-01 00:13:22 +02:00
title={loc.lnd.refill}
2019-09-29 22:01:27 +02:00
/>
<BlueListItem
hideChevron
component={TouchableOpacity}
onPress={a => {
2019-10-01 00:13:22 +02:00
this.setState({ isManageFundsModalVisible: false }, () =>
2019-09-29 22:01:27 +02:00
this.props.navigation.navigate('ReceiveDetails', {
secret: this.state.wallet.getSecret(),
2019-10-01 00:13:22 +02:00
}),
);
2019-09-29 22:01:27 +02:00
}}
2020-07-20 15:38:46 +02:00
title={loc.lnd.refill_external}
2019-09-29 22:01:27 +02:00
/>
<BlueListItem
hideChevron
component={TouchableOpacity}
onPress={a => {
this.setState({ isManageFundsModalVisible: false }, async () => {
this.props.navigation.navigate('BuyBitcoin', {
wallet: this.state.wallet,
});
});
}}
2020-07-20 15:38:46 +02:00
title={loc.lnd.refill_card}
/>
2019-09-29 22:01:27 +02:00
<BlueListItem
2020-06-16 17:08:25 +02:00
title={loc.lnd.exchange}
2019-09-29 22:01:27 +02:00
hideChevron
component={TouchableOpacity}
onPress={a => {
this.setState({ isManageFundsModalVisible: false });
Linking.openURL('https://zigzag.io/?utm_source=integration&utm_medium=bluewallet&utm_campaign=withdrawLink');
}}
/>
</View>
</KeyboardAvoidingView>
</Modal>
);
};
2019-10-17 03:51:22 +02:00
renderMarketplaceButton = () => {
return Platform.select({
android: (
<TouchableOpacity
onPress={() => {
2020-04-29 17:40:55 +02:00
if (this.state.wallet.type === LightningCustodianWallet.type) {
this.props.navigation.navigate('LappBrowser', { fromSecret: this.state.wallet.getSecret(), fromWallet: this.state.wallet });
} else {
this.props.navigation.navigate('Marketplace', { fromWallet: this.state.wallet });
}
2019-10-17 03:51:22 +02:00
}}
style={styles.marketplaceButton1}
2019-10-17 03:51:22 +02:00
>
<Text style={styles.marketpalceText1}>marketplace</Text>
2019-10-17 03:51:22 +02:00
</TouchableOpacity>
),
ios:
this.state.wallet.getBalance() > 0 ? (
<TouchableOpacity
onPress={async () => {
Linking.openURL('https://bluewallet.io/marketplace/');
2019-10-17 03:51:22 +02:00
}}
style={styles.marketplaceButton1}
2019-10-17 03:51:22 +02:00
>
2019-10-17 04:08:09 +02:00
<Icon name="external-link" size={18} type="font-awesome" color="#9aa0aa" />
<Text style={styles.marketpalceText2}>marketplace</Text>
2019-10-17 03:51:22 +02:00
</TouchableOpacity>
) : null,
});
};
2019-10-21 13:52:38 +02:00
renderLappBrowserButton = () => {
return (
<TouchableOpacity
onPress={() => {
this.props.navigation.navigate('LappBrowser', {
fromSecret: this.state.wallet.getSecret(),
fromWallet: this.state.wallet,
2019-10-23 23:54:09 +02:00
url: 'https://duckduckgo.com',
2019-10-21 13:52:38 +02:00
});
}}
style={styles.marketplaceButton2}
2019-10-21 13:52:38 +02:00
>
<Text style={styles.marketpalceText1}>LApp Browser</Text>
2019-10-21 13:52:38 +02:00
</TouchableOpacity>
);
};
renderSellFiat = () => {
return (
<TouchableOpacity
onPress={() =>
this.props.navigation.navigate('BuyBitcoin', {
2020-04-29 14:37:09 +02:00
wallet: this.state.wallet,
})
}
style={styles.marketplaceButton2}
>
2020-07-20 15:38:46 +02:00
<Text style={styles.marketpalceText1}>{loc.wallets.list_tap_here_to_buy}</Text>
</TouchableOpacity>
);
};
2019-09-29 22:01:27 +02:00
onWalletSelect = async wallet => {
if (wallet) {
NavigationService.navigate('WalletTransactions', {
key: `WalletTransactions-${wallet.getID()}`,
});
/** @type {LightningCustodianWallet} */
let toAddress = false;
if (this.state.wallet.refill_addressess.length > 0) {
2019-09-29 22:01:27 +02:00
toAddress = this.state.wallet.refill_addressess[0];
} else {
try {
await this.state.wallet.fetchBtcAddress();
toAddress = this.state.wallet.refill_addressess[0];
} catch (Err) {
return alert(Err.message);
}
2019-09-29 22:01:27 +02:00
}
2020-05-27 13:12:17 +02:00
this.props.navigation.navigate('SendDetailsRoot', {
screen: 'SendDetails',
params: {
memo: loc.lnd.refill_lnd_balance,
address: toAddress,
fromWallet: wallet,
},
2019-09-29 22:01:27 +02:00
});
}
};
onFocus = () => {
this.redrawScreen();
this.props.navigation.setParams({ isLoading: false });
};
componentWillUnmount() {
2020-06-26 21:27:13 +02:00
clearInterval(this.interval);
2020-05-27 13:12:17 +02:00
this._unsubscribeFocus();
}
2020-01-01 04:31:04 +01:00
navigateToSendScreen = () => {
2020-05-27 13:12:17 +02:00
this.props.navigation.navigate('SendDetailsRoot', {
screen: 'SendDetails',
params: {
fromWallet: this.state.wallet,
},
2020-01-01 04:31:04 +01:00
});
};
2020-06-26 21:27:13 +02:00
renderItem = item => (
<BlueTransactionListItem item={item.item} itemPriceUnit={this.state.itemPriceUnit} timeElapsed={this.state.timeElapsed} />
);
onBarCodeRead = ret => {
if (!this.state.isLoading) {
this.setState({ isLoading: true }, () => {
this.setState({ isLoading: false });
2020-05-27 13:12:17 +02:00
const params = {
fromSecret: this.state.wallet.getSecret(),
// ScanLndInvoice actrually uses `fromSecret` so keeping it for now
uri: ret.data ? ret.data : ret,
fromWallet: this.state.wallet,
2020-05-27 13:12:17 +02:00
};
if (this.state.wallet.chain === Chain.ONCHAIN) {
this.props.navigation.navigate('SendDetailsRoot', { screen: 'SendDetails', params });
} else {
this.props.navigation.navigate('ScanLndInvoiceRoot', { screen: 'ScanLndInvoice', params });
}
});
}
};
choosePhoto = () => {
ImagePicker.launchImageLibrary(
{
title: null,
mediaType: 'photo',
takePhotoButtonTitle: null,
},
response => {
if (response.uri) {
const uri = Platform.OS === 'ios' ? response.uri.toString().replace('file://', '') : response.path.toString();
LocalQRCode.decode(uri, (error, result) => {
if (!error) {
this.onBarCodeRead({ data: result });
} else {
2020-07-20 15:38:46 +02:00
alert(loc.send.qr_error_no_qrcode);
}
});
}
},
);
};
copyFromClipbard = async () => {
this.onBarCodeRead({ data: await Clipboard.getString() });
};
sendButtonLongPress = async () => {
const isClipboardEmpty = (await Clipboard.getString()).replace(' ', '').length === 0;
if (Platform.OS === 'ios') {
2020-07-20 15:38:46 +02:00
const options = [loc._.cancel, loc.wallets.list_long_choose, loc.wallets.list_long_scan];
if (!isClipboardEmpty) {
2020-07-20 15:38:46 +02:00
options.push(loc.wallets.list_long_clipboard);
}
ActionSheet.showActionSheetWithOptions({ options, cancelButtonIndex: 0 }, buttonIndex => {
if (buttonIndex === 1) {
this.choosePhoto();
} else if (buttonIndex === 2) {
this.props.navigation.navigate('ScanQRCode', {
launchedBy: this.props.route.name,
onBarScanned: this.onBarCodeRead,
showFileImportButton: false,
});
} else if (buttonIndex === 3) {
this.copyFromClipbard();
}
});
} else if (Platform.OS === 'android') {
const buttons = [
{
2020-07-20 15:38:46 +02:00
text: loc._.cancel,
onPress: () => {},
style: 'cancel',
},
{
2020-07-20 15:38:46 +02:00
text: loc.wallets.list_long_choose,
onPress: this.choosePhoto,
},
{
2020-07-20 15:38:46 +02:00
text: loc.wallets.list_long_scan,
onPress: () =>
this.props.navigation.navigate('ScanQRCode', {
2020-05-27 13:12:17 +02:00
launchedBy: this.props.route.name,
onBarScanned: this.onBarCodeRead,
showFileImportButton: false,
}),
},
];
if (!isClipboardEmpty) {
buttons.push({
2020-07-20 15:38:46 +02:00
text: loc.wallets.list_long_clipboard,
onPress: this.copyFromClipbard,
});
}
ActionSheet.showActionSheetWithOptions({
title: '',
message: '',
buttons,
});
}
};
render() {
const { navigate } = this.props.navigation;
return (
<View style={styles.flex}>
<StatusBar barStyle="light-content" backgroundColor={WalletGradient.headerColorFor(this.props.route.params.wallet.type)} />
2020-03-29 04:06:45 +02:00
{this.state.wallet.chain === Chain.ONCHAIN && this.state.isHandOffUseEnabled && (
<Handoff
title={`Bitcoin Wallet ${this.state.wallet.getLabel()}`}
type="io.bluewallet.bluewallet"
url={`https://blockpath.com/search/addr?q=${this.state.wallet.getXpub()}`}
/>
)}
2019-08-04 08:42:05 +02:00
<BlueWalletNavigationHeader
wallet={this.state.wallet}
onWalletUnitChange={wallet =>
InteractionManager.runAfterInteractions(async () => {
this.setState({ wallet, itemPriceUnit: wallet.getPreferredBalanceUnit() }, () =>
InteractionManager.runAfterInteractions(() => BlueApp.saveToDisk()),
);
2019-08-04 08:42:05 +02:00
})
}
onManageFundsPressed={() => {
if (this.state.wallet.getUserHasSavedExport()) {
this.setState({ isManageFundsModalVisible: true });
} else {
BlueAlertWalletExportReminder({
onSuccess: async () => {
this.state.wallet.setUserHasSavedExport(true);
await BlueApp.saveToDisk();
this.setState({ isManageFundsModalVisible: true });
},
onFailure: () =>
this.props.navigation.navigate('WalletExport', {
2020-03-12 18:26:05 +01:00
wallet: this.state.wallet,
}),
});
}
}}
2019-08-04 08:42:05 +02:00
/>
<View style={styles.list}>
<FlatList
2019-12-25 21:53:53 +01:00
ListHeaderComponent={this.renderListHeaderComponent}
onEndReachedThreshold={0.3}
2019-12-25 21:53:53 +01:00
onEndReached={async () => {
// pagination in works. in this block we will add more txs to flatlist
// so as user scrolls closer to bottom it will render mode transactions
if (this.getTransactions(Infinity).length < this.state.limit) {
// all list rendered. nop
return;
}
this.setState({
dataSource: this.getTransactions(this.state.limit + this.state.pageSize),
limit: this.state.limit + this.state.pageSize,
pageSize: this.state.pageSize * 2,
});
}}
ListFooterComponent={this.renderListFooterComponent}
ListEmptyComponent={
<ScrollView style={styles.flex} contentContainerStyle={styles.scrollViewContent}>
<Text numberOfLines={0} style={styles.emptyTxs}>
2020-07-20 15:38:46 +02:00
{(this.isLightning() && loc.wallets.list_empty_txs1_lightning) || loc.wallets.list_empty_txs1}
</Text>
2020-07-20 15:38:46 +02:00
{this.isLightning() && <Text style={styles.emptyTxsLightning}>{loc.wallets.list_empty_txs2_lightning}</Text>}
{!this.isLightning() && (
<TouchableOpacity
onPress={() =>
this.props.navigation.navigate('BuyBitcoin', {
wallet: this.state.wallet,
})
}
style={styles.buyBitcoin}
2018-10-10 21:36:32 +02:00
>
2020-07-20 15:38:46 +02:00
<Text style={styles.buyBitcoinText}>{loc.wallets.list_tap_here_to_buy}</Text>
</TouchableOpacity>
)}
</ScrollView>
}
2019-02-17 02:22:14 +01:00
refreshControl={
<RefreshControl onRefresh={() => this.refreshTransactions()} refreshing={this.state.showShowFlatListRefreshControl} />
}
data={this.state.dataSource}
2020-06-26 21:27:13 +02:00
extraData={this.state.timeElapsed}
keyExtractor={this._keyExtractor}
2019-01-30 03:13:45 +01:00
renderItem={this.renderItem}
contentInset={{ top: 0, left: 0, bottom: 90, right: 0 }}
/>
2019-09-29 22:01:27 +02:00
{this.renderManageFundsModal()}
</View>
<View style={styles.floatButtons}>
{(() => {
if (this.state.wallet.allowReceive()) {
return (
<BlueReceiveButtonIcon
onPress={() => {
2019-12-25 21:53:53 +01:00
if (this.state.wallet.chain === Chain.OFFCHAIN) {
2020-05-27 13:12:17 +02:00
navigate('LNDCreateInvoiceRoot', { screen: 'LNDCreateInvoice', params: { fromWallet: this.state.wallet } });
2018-12-25 17:34:51 +01:00
} else {
2019-09-27 16:49:56 +02:00
navigate('ReceiveDetails', { secret: this.state.wallet.getSecret() });
}
}}
/>
);
}
})()}
{(() => {
2020-01-01 04:31:04 +01:00
if (
this.state.wallet.allowSend() ||
2020-02-26 15:39:19 +01:00
(this.state.wallet.type === WatchOnlyWallet.type &&
this.state.wallet.isHd() &&
this.state.wallet.getSecret().startsWith('zpub'))
2020-01-01 04:31:04 +01:00
) {
return (
<BlueSendButtonIcon
onLongPress={this.sendButtonLongPress}
onPress={() => {
2019-12-25 21:53:53 +01:00
if (this.state.wallet.chain === Chain.OFFCHAIN) {
2020-05-27 13:12:17 +02:00
navigate('ScanLndInvoiceRoot', { screen: 'ScanLndInvoice', params: { fromSecret: this.state.wallet.getSecret() } });
} else {
2020-01-01 04:31:04 +01:00
if (
2020-02-26 15:39:19 +01:00
this.state.wallet.type === WatchOnlyWallet.type &&
this.state.wallet.isHd() &&
this.state.wallet.getSecret().startsWith('zpub')
2020-01-01 04:31:04 +01:00
) {
2020-02-26 15:39:19 +01:00
if (this.state.wallet.useWithHardwareWalletEnabled()) {
2020-01-01 04:31:04 +01:00
this.navigateToSendScreen();
} else {
Alert.alert(
2020-07-20 15:38:46 +02:00
loc.wallets.details_title,
loc.transactions.enable_hw,
2020-01-01 04:31:04 +01:00
[
{
text: loc._.ok,
2020-01-05 02:03:02 +01:00
onPress: () => {
const wallet = this.state.wallet;
2020-02-26 15:39:19 +01:00
wallet.setUseWithHardwareWalletEnabled(true);
2020-01-05 02:03:02 +01:00
this.setState({ wallet }, async () => {
await BlueApp.saveToDisk();
this.navigateToSendScreen();
2020-02-24 22:45:14 +01:00
});
2020-01-01 04:31:04 +01:00
},
style: 'default',
},
2020-07-20 15:38:46 +02:00
{ text: loc._.cancel, onPress: () => {}, style: 'cancel' },
2020-01-01 04:31:04 +01:00
],
{ cancelable: false },
);
}
} else {
this.navigateToSendScreen();
}
}
}}
/>
);
}
})()}
</View>
</View>
);
}
}
WalletTransactions.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
goBack: PropTypes.func,
setParams: PropTypes.func,
2020-05-27 13:12:17 +02:00
addListener: PropTypes.func,
}),
route: PropTypes.shape({
name: PropTypes.string,
params: PropTypes.object,
}),
};
2020-07-15 19:32:59 +02:00
WalletTransactions.navigationOptions = ({ navigation, route }) => {
return {
headerRight: () => (
<TouchableOpacity
disabled={route.params.isLoading === true}
style={styles.walletDetails}
onPress={() =>
navigation.navigate('WalletDetails', {
wallet: route.params.wallet,
})
}
>
<Icon name="kebab-horizontal" type="octicon" size={22} color="#FFFFFF" />
</TouchableOpacity>
),
headerTitle: () => null,
headerStyle: {
backgroundColor: WalletGradient.headerColorFor(route.params.wallet.type),
borderBottomWidth: 0,
elevation: 0,
// shadowRadius: 0,
shadowOffset: { height: 0, width: 0 },
},
headerTintColor: '#FFFFFF',
headerBackTitleVisible: false,
};
};