BlueWallet/screen/wallets/details.js

172 lines
4.7 KiB
JavaScript
Raw Normal View History

2018-01-30 23:42:38 +01:00
/** @type {AppStorage} */
2018-03-17 21:39:21 +01:00
let BlueApp = require('../../BlueApp');
2018-01-30 23:42:38 +01:00
import React, { Component } from 'react';
2018-03-17 21:39:21 +01:00
import { ActivityIndicator, TextInput, View } from 'react-native';
2018-01-30 23:42:38 +01:00
import Ionicons from 'react-native-vector-icons/Ionicons';
2018-03-17 21:39:21 +01:00
import { SafeAreaView } from 'react-navigation';
import { Icon, Card, Header } from 'react-native-elements';
import { List, Button, ListItem } from 'react-native-elements';
import { FormInput, Text, FormValidationMessage } from 'react-native-elements';
2018-01-30 23:42:38 +01:00
import {
2018-03-17 21:39:21 +01:00
BlueSpacing,
BlueFormInput,
BlueButton,
SafeBlueArea,
BlueCard,
BlueText,
BlueListItem,
BlueHeader,
BlueFormLabel,
BlueListView,
} from '../../BlueComponents';
let EV = require('../../events');
2018-01-30 23:42:38 +01:00
let BigNumber = require('bignumber.js');
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() {
2018-03-17 21:39:21 +01:00
const { navigate } = this.props.navigation;
2018-01-30 23:42:38 +01:00
if (this.state.isLoading) {
return (
2018-03-17 21:39:21 +01:00
<View style={{ flex: 1, paddingTop: 20 }}>
2018-01-30 23:42:38 +01:00
<ActivityIndicator />
</View>
);
}
return (
2018-03-17 21:39:21 +01:00
<SafeBlueArea style={{ flex: 1, paddingTop: 20 }}>
<BlueSpacing />
<BlueCard
title={'Wallet Details'}
style={{ alignItems: 'center', flex: 1 }}
>
2018-01-30 23:42:38 +01:00
<BlueFormLabel>Address:</BlueFormLabel>
2018-03-17 21:39:21 +01:00
<BlueFormInput
value={this.state.wallet.getAddress()}
editable={false}
/>
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-01-30 23:42:38 +01:00
<BlueText h4>Are you sure?</BlueText>
<BlueButton
2018-03-17 21:39:21 +01:00
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();
}}
2018-01-30 23:42:38 +01:00
title="Yes, delete"
/>
<BlueButton
onPress={async () => {
2018-03-17 21:39:21 +01:00
this.setState({ confirmDelete: false });
2018-01-30 23:42:38 +01:00
}}
title="No, cancel"
/>
</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-01-30 23:42:38 +01:00
<BlueButton
onPress={() =>
2018-03-17 21:39:21 +01:00
this.props.navigation.navigate('WalletExport', {
address: this.state.wallet.getAddress(),
})
2018-01-30 23:42:38 +01:00
}
title="Export / backup"
/>
<BlueButton
2018-03-17 21:39:21 +01:00
icon={{ name: 'arrow-left', type: 'octicon' }}
onPress={async () => {
2018-01-30 23:42:38 +01:00
if (this.state.labelChanged) {
2018-03-17 21:39:21 +01:00
await BlueApp.saveToDisk();
EV(EV.enum.WALLETS_COUNT_CHANGED); // TODO: some other event type?
2018-01-30 23:42:38 +01:00
}
2018-03-17 21:39:21 +01:00
this.props.navigation.goBack();
}}
2018-01-30 23:42:38 +01:00
title="Go back"
/>
</View>
2018-03-17 21:39:21 +01:00
);
2018-01-30 23:42:38 +01:00
}
})()}
</SafeBlueArea>
);
}
}