BlueWallet/screen/wallets/details.js

210 lines
7.1 KiB
JavaScript
Raw Normal View History

/* global alert */
2018-01-30 23:42:38 +01:00
import React, { Component } from 'react';
import { ActivityIndicator, View, Text, TextInput, Alert, TouchableOpacity, Keyboard, TouchableWithoutFeedback } from 'react-native';
import { BlueButton, SafeBlueArea, BlueCard, BlueSpacing20, BlueNavigationStyle } from '../../BlueComponents';
2018-03-18 03:48:23 +01:00
import PropTypes from 'prop-types';
import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet';
2018-03-17 21:39:21 +01:00
let EV = require('../../events');
2018-03-18 03:48:23 +01:00
/** @type {AppStorage} */
let BlueApp = require('../../BlueApp');
2018-05-28 21:18:11 +02:00
let loc = require('../../loc');
2018-01-30 23:42:38 +01:00
export default class WalletDetails extends Component {
static navigationOptions = ({ navigation }) => ({
...BlueNavigationStyle(),
title: loc.wallets.details.title,
headerRight: (
2018-11-10 00:44:34 +01:00
<TouchableOpacity
style={{ marginHorizontal: 16 }}
onPress={() => {
navigation.getParam('saveAction')();
}}
2018-11-10 00:44:34 +01:00
>
<Text style={{ color: '#0c2550' }}>{loc.wallets.details.save}</Text>
</TouchableOpacity>
),
});
2018-01-30 23:42:38 +01:00
constructor(props) {
super(props);
2018-03-17 21:39:21 +01:00
let address = props.navigation.state.params.address;
let secret = props.navigation.state.params.secret;
2018-01-30 23:42:38 +01:00
/** @type {AbstractWallet} */
2018-03-17 21:39:21 +01:00
let wallet;
2018-01-30 23:42:38 +01:00
2018-03-17 21:39:21 +01:00
for (let w of BlueApp.getWallets()) {
if ((address && w.getAddress() === address) || w.getSecret() === secret) {
2018-03-17 21:39:21 +01:00
// found our wallet
wallet = w;
2018-01-30 23:42:38 +01:00
}
}
this.state = {
isLoading: true,
walletName: wallet.getLabel(),
2018-03-17 21:39:21 +01:00
wallet,
2018-06-28 03:43:28 +02:00
address,
2018-03-17 21:39:21 +01:00
};
this.props.navigation.setParams({ saveAction: () => this.setLabel() });
2018-01-30 23:42:38 +01:00
}
async componentDidMount() {
this.setState({
isLoading: false,
2018-03-17 21:39:21 +01:00
});
2018-01-30 23:42:38 +01:00
}
async setLabel() {
this.state.wallet.setLabel(this.state.walletName);
BlueApp.saveToDisk();
alert('Wallet updated.');
this.props.navigation.goBack(null);
2018-01-30 23:42:38 +01:00
}
render() {
if (this.state.isLoading) {
return (
2018-05-12 22:27:34 +02:00
<View style={{ flex: 1 }}>
2018-01-30 23:42:38 +01:00
<ActivityIndicator />
</View>
);
}
return (
2018-05-12 22:27:34 +02:00
<SafeBlueArea style={{ flex: 1 }}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<View style={{ flex: 1 }}>
<BlueCard style={{ alignItems: 'center', flex: 1 }}>
{(() => {
if (this.state.wallet.getAddress()) {
return (
<React.Fragment>
<Text style={{ color: '#0c2550', fontWeight: '500', fontSize: 14, marginVertical: 12 }}>
{loc.wallets.details.address.toLowerCase()}
</Text>
<Text style={{ color: '#81868e', fontWeight: '500', fontSize: 14 }}>{this.state.wallet.getAddress()}</Text>
</React.Fragment>
);
}
})()}
<Text style={{ color: '#0c2550', fontWeight: '500', fontSize: 14, marginVertical: 16 }}>
{loc.wallets.add.wallet_name.toLowerCase()}
</Text>
<View
style={{
flexDirection: 'row',
borderColor: '#d2d2d2',
borderBottomColor: '#d2d2d2',
borderWidth: 1.0,
borderBottomWidth: 0.5,
backgroundColor: '#f5f5f5',
minHeight: 44,
height: 44,
alignItems: 'center',
borderRadius: 4,
}}
>
<TextInput
placeholder={loc.send.details.note_placeholder}
value={this.state.walletName}
onChangeText={text => this.setState({ walletName: text })}
numberOfLines={1}
style={{ flex: 1, marginHorizontal: 8, minHeight: 33 }}
editable={!this.state.isLoading}
underlineColorAndroid="transparent"
/>
</View>
<Text style={{ color: '#0c2550', fontWeight: '500', fontSize: 14, marginVertical: 12 }}>
{loc.wallets.details.type.toLowerCase()}
</Text>
<Text style={{ color: '#81868e', fontWeight: '500', fontSize: 14 }}>{this.state.wallet.getTypeReadable()}</Text>
</BlueCard>
<View>
<BlueSpacing20 />
<BlueButton
icon={{
name: 'cloud-upload',
type: 'octicon',
color: BlueApp.settings.buttonTextColor,
}}
onPress={() =>
this.props.navigation.navigate('WalletExport', {
address: this.state.wallet.getAddress(),
secret: this.state.wallet.getSecret(),
})
}
title={loc.wallets.details.export_backup}
/>
<BlueSpacing20 />
{this.state.wallet.type !== new LightningCustodianWallet().type && (
<BlueButton
icon={{
name: 'shopping-cart',
type: 'font-awesome',
color: BlueApp.settings.buttonTextColor,
}}
onPress={() =>
this.props.navigation.navigate('BuyBitcoin', {
address: this.state.wallet.getAddress(),
secret: this.state.wallet.getSecret(),
})
}
title={loc.wallets.details.buy_bitcoin}
/>
)}
<BlueSpacing20 />
<TouchableOpacity
style={{ alignItems: 'center' }}
onPress={() =>
Alert.alert(
loc.wallets.details.delete + ' ' + loc.wallets.details.title,
loc.wallets.details.are_you_sure,
[
{
text: loc.wallets.details.yes_delete,
onPress: async () => {
BlueApp.deleteWallet(this.state.wallet);
await BlueApp.saveToDisk();
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED);
EV(EV.enum.WALLETS_COUNT_CHANGED);
this.props.navigation.navigate('Wallets');
},
style: 'destructive',
},
{ text: loc.wallets.details.no_cancel, onPress: () => {}, style: 'cancel' },
],
{ cancelable: false },
)
}
>
<Text style={{ color: '#d0021b', fontSize: 15, fontWeight: '500' }}>{loc.wallets.details.delete}</Text>
</TouchableOpacity>
</View>
</View>
</TouchableWithoutFeedback>
2018-01-30 23:42:38 +01:00
</SafeBlueArea>
);
}
}
2018-03-18 03:48:23 +01:00
WalletDetails.propTypes = {
navigation: PropTypes.shape({
state: PropTypes.shape({
params: PropTypes.shape({
address: PropTypes.string,
secret: PropTypes.string,
2018-03-18 03:48:23 +01:00
}),
}),
navigate: PropTypes.func,
goBack: PropTypes.func,
setParams: PropTypes.func,
2018-03-18 03:48:23 +01:00
}),
};