BlueWallet/screen/wallets/details.js

195 lines
5.0 KiB
JavaScript
Raw Normal View History

2018-01-30 23:42:38 +01:00
import React, { Component } from 'react';
2018-05-12 22:27:34 +02:00
import { Dimensions, ActivityIndicator, View } from 'react-native';
2018-01-30 23:42:38 +01:00
import Ionicons from 'react-native-vector-icons/Ionicons';
import {
2018-03-17 21:39:21 +01:00
BlueSpacing,
2018-05-12 22:27:34 +02:00
BlueSpacing40,
2018-03-17 21:39:21 +01:00
BlueFormInput,
BlueButton,
SafeBlueArea,
BlueCard,
BlueText,
BlueFormLabel,
2018-05-06 19:12:14 +02:00
BlueFormInputAddress,
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-12 22:27:34 +02:00
const { height, width } = Dimensions.get('window');
const aspectRatio = height / width;
let isIpad;
if (aspectRatio > 1.6) {
isIpad = false;
} else {
isIpad = true;
}
2018-01-30 23:42:38 +01:00
export default class WalletDetails extends Component {
static navigationOptions = {
tabBarIcon: ({ tintColor, focused }) => (
<Ionicons
name={focused ? 'ios-briefcase' : 'ios-briefcase-outline'}
size={26}
style={{ color: tintColor }}
/>
),
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;
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 (w.getAddress() === address) {
// 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-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-03-17 21:39:21 +01:00
this.state.wallet.label = text;
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 }}>
{(() => {
if (isIpad) {
return <BlueSpacing40 />;
} else {
return <BlueSpacing />;
}
})()}
2018-03-17 21:39:21 +01:00
<BlueCard
title={'Wallet Details'}
style={{ alignItems: 'center', flex: 1 }}
>
2018-01-30 23:42:38 +01:00
<BlueFormLabel>Address:</BlueFormLabel>
2018-05-06 19:12:14 +02:00
<BlueFormInputAddress
2018-03-17 21:39:21 +01:00
value={this.state.wallet.getAddress()}
2018-05-06 19:12:14 +02:00
editable
2018-03-17 21:39:21 +01:00
/>
2018-01-30 23:42:38 +01:00
<BlueFormLabel>Type:</BlueFormLabel>
2018-03-17 21:39:21 +01:00
<BlueFormInput
value={this.state.wallet.getTypeReadable()}
editable={false}
/>
2018-01-30 23:42:38 +01:00
<BlueFormLabel>Label:</BlueFormLabel>
<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-12 22:27:34 +02:00
<BlueText>Are you sure?</BlueText>
<View style={{ flex: 0, flexDirection: 'row' }}>
<View style={{ flex: 0.5 }}>
<BlueButton
icon={{ name: 'stop', type: 'octicon' }}
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();
}}
title="Yes, delete"
/>
</View>
<View style={{ flex: 0.5 }}>
<BlueButton
onPress={async () => {
this.setState({ confirmDelete: false });
}}
title="No, cancel"
/>
</View>
</View>
2018-01-30 23:42:38 +01:00
</View>
);
} else {
return (
<View>
2018-03-17 21:39:21 +01:00
<BlueButton
icon={{ name: 'stop', type: 'octicon' }}
onPress={async () => {
this.setState({ confirmDelete: true });
}}
title="Delete this wallet"
/>
2018-05-12 22:27:34 +02:00
{(() => {
if (isIpad) {
return <View />;
} else {
return (
<BlueButton
onPress={() =>
this.props.navigation.navigate('WalletExport', {
address: this.state.wallet.getAddress(),
})
}
title="Export / backup"
/>
);
2018-01-30 23:42:38 +01:00
}
2018-05-12 22:27:34 +02:00
})()}
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,
}),
}),
navigate: PropTypes.func,
goBack: PropTypes.func,
}),
};