BlueWallet/screen/wallets/details.js

184 lines
5.2 KiB
JavaScript
Raw Normal View History

2018-01-30 23:42:38 +01:00
import React, { Component } from 'react';
2018-06-29 00:17:14 +02:00
import { ActivityIndicator, View } from 'react-native';
2018-01-30 23:42:38 +01:00
import {
2018-03-17 21:39:21 +01:00
BlueFormInput,
BlueButton,
SafeBlueArea,
BlueCard,
BlueText,
BlueFormLabel,
2018-05-06 19:12:14 +02:00
BlueFormInputAddress,
2018-06-28 03:43:28 +02:00
BlueHeaderDefaultSub,
2018-03-17 21:39:21 +01:00
} from '../../BlueComponents';
2018-03-18 03:48:23 +01:00
import PropTypes from 'prop-types';
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 = {
header: ({ navigation }) => {
return <BlueHeaderDefaultSub leftText={loc.wallets.details.title} onClose={() => navigation.goBack(null)} />;
},
2018-03-17 21:39:21 +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;
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 = {
confirmDelete: false,
isLoading: true,
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-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(text) {
2018-06-28 03:43:28 +02:00
this.state.wallet.setLabel(text);
if (this.timeout) {
clearTimeout(this.timeout);
}
this.timeout = setTimeout(() => {
BlueApp.saveToDisk();
}, 3000);
2018-01-30 23:42:38 +01:00
this.setState({
2018-03-17 21:39:21 +01:00
labelChanged: true,
}); /* also, a hack to make screen update new typed text */
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-06-28 03:43:28 +02:00
<BlueCard style={{ alignItems: 'center', flex: 1 }}>
{(() => {
if (this.state.wallet.getAddress()) {
return (
<View>
<BlueFormLabel>{loc.wallets.details.address}:</BlueFormLabel>
<BlueFormInputAddress value={this.state.wallet.getAddress()} editable />
</View>
);
}
})()}
2018-01-30 23:42:38 +01:00
2018-05-28 21:18:11 +02:00
<BlueFormLabel>{loc.wallets.details.type}:</BlueFormLabel>
2018-07-07 15:04:32 +02:00
<BlueFormInput value={this.state.wallet.getTypeReadable()} editable={false} />
2018-01-30 23:42:38 +01:00
2018-05-28 21:18:11 +02:00
<BlueFormLabel>{loc.wallets.details.label}:</BlueFormLabel>
2018-01-30 23:42:38 +01:00
<BlueFormInput
2018-03-17 21:39:21 +01:00
value={this.state.wallet.getLabel()}
onChangeText={text => {
this.setLabel(text);
}}
2018-01-30 23:42:38 +01:00
/>
</BlueCard>
{(() => {
if (this.state.confirmDelete) {
return (
2018-03-17 21:39:21 +01:00
<View style={{ alignItems: 'center' }}>
2018-05-28 21:18:11 +02:00
<BlueText>{loc.wallets.details.are_you_sure}</BlueText>
2018-05-12 22:27:34 +02:00
<View style={{ flex: 0, flexDirection: 'row' }}>
<View style={{ flex: 0.5 }}>
<BlueButton
2018-06-25 00:22:46 +02:00
icon={{
name: 'stop',
type: 'octicon',
color: BlueApp.settings.buttonTextColor,
}}
2018-05-12 22:27:34 +02:00
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.goBack();
}}
2018-05-28 21:18:11 +02:00
title={loc.wallets.details.yes_delete}
2018-05-12 22:27:34 +02:00
/>
</View>
<View style={{ flex: 0.5 }}>
<BlueButton
onPress={async () => {
this.setState({ confirmDelete: false });
}}
2018-05-28 21:18:11 +02:00
title={loc.wallets.details.no_cancel}
2018-05-12 22:27:34 +02:00
/>
</View>
</View>
2018-01-30 23:42:38 +01:00
</View>
);
} else {
return (
<View>
2018-03-17 21:39:21 +01:00
<BlueButton
2018-06-25 00:22:46 +02:00
icon={{
name: 'stop',
type: 'octicon',
color: BlueApp.settings.buttonTextColor,
}}
2018-03-17 21:39:21 +01:00
onPress={async () => {
this.setState({ confirmDelete: true });
}}
2018-05-28 21:18:11 +02:00
title={loc.wallets.details.delete_this_wallet}
2018-03-17 21:39:21 +01:00
/>
2018-05-12 22:27:34 +02:00
<BlueButton
onPress={() =>
this.props.navigation.navigate('WalletExport', {
address: this.state.wallet.getAddress(),
secret: this.state.wallet.getSecret(),
})
2018-01-30 23:42:38 +01:00
}
title={loc.wallets.details.export_backup}
/>
2018-01-30 23:42:38 +01:00
</View>
2018-03-17 21:39:21 +01:00
);
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,
}),
};