2018-10-30 10:35:24 +01:00
|
|
|
/* global alert */
|
2018-01-30 23:42:38 +01:00
|
|
|
import React, { Component } from 'react';
|
2018-12-11 23:52:46 +01:00
|
|
|
import { ActivityIndicator, View, Text, TextInput, Alert, TouchableOpacity, Keyboard, TouchableWithoutFeedback } from 'react-native';
|
2018-11-01 20:44:39 +01:00
|
|
|
import { BlueButton, SafeBlueArea, BlueCard, BlueSpacing20, BlueNavigationStyle } from '../../BlueComponents';
|
2018-03-18 03:48:23 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2018-10-30 10:35:24 +01:00
|
|
|
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 {
|
2018-10-29 23:11:48 +01:00
|
|
|
static navigationOptions = ({ navigation }) => ({
|
2018-10-30 10:35:24 +01:00
|
|
|
...BlueNavigationStyle(),
|
2018-10-29 23:11:48 +01:00
|
|
|
title: loc.wallets.details.title,
|
2018-10-30 10:35:24 +01:00
|
|
|
headerRight: (
|
2018-11-10 00:44:34 +01:00
|
|
|
<TouchableOpacity
|
|
|
|
style={{ marginHorizontal: 16 }}
|
2018-10-30 10:35:24 +01:00
|
|
|
onPress={() => {
|
|
|
|
navigation.getParam('saveAction')();
|
|
|
|
}}
|
2018-11-10 00:44:34 +01:00
|
|
|
>
|
|
|
|
<Text style={{ color: '#0c2550' }}>{loc.wallets.details.save}</Text>
|
|
|
|
</TouchableOpacity>
|
2018-10-30 10:35:24 +01:00
|
|
|
),
|
2018-10-29 23:11:48 +01:00
|
|
|
});
|
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;
|
2018-07-22 16:49:59 +02:00
|
|
|
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()) {
|
2018-07-22 16:49:59 +02:00
|
|
|
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,
|
2018-10-30 10:35:24 +01:00
|
|
|
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
|
|
|
};
|
2018-10-30 10:35:24 +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
|
|
|
}
|
|
|
|
|
2018-10-30 10:35:24 +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 }}>
|
2018-12-11 23:52:46 +01:00
|
|
|
<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>
|
2018-10-30 10:35:24 +01:00
|
|
|
</View>
|
2018-12-11 23:52:46 +01:00
|
|
|
</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,
|
2018-07-22 16:49:59 +02:00
|
|
|
secret: PropTypes.string,
|
2018-03-18 03:48:23 +01:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
navigate: PropTypes.func,
|
|
|
|
goBack: PropTypes.func,
|
2018-10-30 10:35:24 +01:00
|
|
|
setParams: PropTypes.func,
|
2018-03-18 03:48:23 +01:00
|
|
|
}),
|
|
|
|
};
|