This commit is contained in:
ncoelho 2020-04-04 18:17:07 +02:00 committed by Overtorment
parent a39a357a72
commit 9a6bfd6dec

View file

@ -95,246 +95,247 @@ export default class WalletsAdd extends Component {
<SafeBlueArea ref="myScrollView">
<KeyboardAvoidingView enabled behavior={Platform.OS === 'ios' ? 'padding' : null} keyboardVerticalOffset={62}>
<ScrollView>
<BlueFormLabel>{loc.wallets.add.wallet_name}</BlueFormLabel>
<View
style={{
flexDirection: 'row',
borderColor: '#d2d2d2',
borderBottomColor: '#d2d2d2',
borderWidth: 1.0,
borderBottomWidth: 0.5,
backgroundColor: '#f5f5f5',
minHeight: 44,
height: 44,
marginHorizontal: 20,
alignItems: 'center',
marginVertical: 16,
borderRadius: 4,
<BlueFormLabel>{loc.wallets.add.wallet_name}</BlueFormLabel>
<View
style={{
flexDirection: 'row',
borderColor: '#d2d2d2',
borderBottomColor: '#d2d2d2',
borderWidth: 1.0,
borderBottomWidth: 0.5,
backgroundColor: '#f5f5f5',
minHeight: 44,
height: 44,
marginHorizontal: 20,
alignItems: 'center',
marginVertical: 16,
borderRadius: 4,
}}
>
<TextInput
testID="WalletNameInput"
value={this.state.label}
placeholderTextColor="#81868e"
placeholder="my first wallet"
onChangeText={text => {
this.setLabel(text);
}}
>
<TextInput
testID="WalletNameInput"
value={this.state.label}
placeholderTextColor="#81868e"
placeholder="my first wallet"
onChangeText={text => {
this.setLabel(text);
}}
style={{ flex: 1, marginHorizontal: 8, color: '#81868e' }}
editable={!this.state.isLoading}
underlineColorAndroid="transparent"
/>
</View>
<BlueFormLabel>{loc.wallets.add.wallet_type}</BlueFormLabel>
style={{ flex: 1, marginHorizontal: 8, color: '#81868e' }}
editable={!this.state.isLoading}
underlineColorAndroid="transparent"
/>
</View>
<BlueFormLabel>{loc.wallets.add.wallet_type}</BlueFormLabel>
<View
style={{
flexDirection: 'row',
justifyContent: 'space-between',
paddingTop: 10,
marginHorizontal: 20,
borderWidth: 0,
minHeight: 100,
<View
style={{
flexDirection: 'row',
justifyContent: 'space-between',
paddingTop: 10,
marginHorizontal: 20,
borderWidth: 0,
minHeight: 100,
}}
>
<BitcoinButton
testID="ActivateBitcoinButton"
active={this.state.activeBitcoin}
onPress={() => {
Keyboard.dismiss();
this.setState({
activeBitcoin: true,
activeLightning: false,
});
}}
>
<BitcoinButton
testID="ActivateBitcoinButton"
active={this.state.activeBitcoin}
onPress={() => {
Keyboard.dismiss();
this.setState({
activeBitcoin: true,
activeLightning: false,
});
}}
style={{
width: '45%',
height: 88,
}}
/>
<View style={{ borderWidth: 0, justifyContent: 'center', marginHorizontal: 8, alignSelf: 'center' }}>
<BlueTextCentered style={{ color: '#0c2550' }}>{loc.wallets.add.or}</BlueTextCentered>
</View>
<LightningButton
active={this.state.activeLightning}
onPress={() => {
Keyboard.dismiss();
this.setState({
activeBitcoin: false,
activeLightning: true,
});
}}
style={{
width: '45%',
height: 88,
}}
/>
style={{
width: '45%',
height: 88,
}}
/>
<View style={{ borderWidth: 0, justifyContent: 'center', marginHorizontal: 8, alignSelf: 'center' }}>
<BlueTextCentered style={{ color: '#0c2550' }}>{loc.wallets.add.or}</BlueTextCentered>
</View>
<LightningButton
active={this.state.activeLightning}
onPress={() => {
Keyboard.dismiss();
this.setState({
activeBitcoin: false,
activeLightning: true,
});
}}
style={{
width: '45%',
height: 88,
}}
/>
</View>
<View style={{ marginHorizontal: 20 }}>
{(() => {
if (this.state.activeBitcoin && this.state.isAdvancedOptionsEnabled) {
return (
<View>
<BlueSpacing20 />
<Text style={{ color: '#0c2550', fontWeight: '500' }}>{loc.settings.advanced_options}</Text>
<RadioGroup onSelect={(index, value) => this.onSelect(index, value)} selectedIndex={0}>
<RadioButton value={HDSegwitBech32Wallet.type}>
<BlueText>{HDSegwitBech32Wallet.typeReadable} - Multiple addresses</BlueText>
</RadioButton>
<RadioButton value={SegwitP2SHWallet.type}>
<BlueText>{SegwitP2SHWallet.typeReadable} - Single address</BlueText>
</RadioButton>
<RadioButton value={HDSegwitP2SHWallet.type}>
<BlueText>{HDSegwitP2SHWallet.typeReadable} - Multiple addresses</BlueText>
</RadioButton>
</RadioGroup>
</View>
);
} else if (this.state.activeLightning && this.state.isAdvancedOptionsEnabled) {
return (
<React.Fragment>
<BlueSpacing20 />
<Text style={{ color: '#0c2550', fontWeight: '500' }}>{loc.settings.advanced_options}</Text>
<BlueSpacing20 />
<BlueText>Connect to your LNDHub</BlueText>
<View
style={{
flexDirection: 'row',
borderColor: '#d2d2d2',
borderBottomColor: '#d2d2d2',
borderWidth: 1.0,
borderBottomWidth: 0.5,
backgroundColor: '#f5f5f5',
minHeight: 44,
height: 44,
alignItems: 'center',
marginVertical: 16,
borderRadius: 4,
<View style={{ marginHorizontal: 20 }}>
{(() => {
if (this.state.activeBitcoin && this.state.isAdvancedOptionsEnabled) {
return (
<View>
<BlueSpacing20 />
<Text style={{ color: '#0c2550', fontWeight: '500' }}>{loc.settings.advanced_options}</Text>
<RadioGroup onSelect={(index, value) => this.onSelect(index, value)} selectedIndex={0}>
<RadioButton value={HDSegwitBech32Wallet.type}>
<BlueText>{HDSegwitBech32Wallet.typeReadable} - Multiple addresses</BlueText>
</RadioButton>
<RadioButton value={SegwitP2SHWallet.type}>
<BlueText>{SegwitP2SHWallet.typeReadable} - Single address</BlueText>
</RadioButton>
<RadioButton value={HDSegwitP2SHWallet.type}>
<BlueText>{HDSegwitP2SHWallet.typeReadable} - Multiple addresses</BlueText>
</RadioButton>
</RadioGroup>
</View>
);
} else if (this.state.activeLightning && this.state.isAdvancedOptionsEnabled) {
return (
<React.Fragment>
<BlueSpacing20 />
<Text style={{ color: '#0c2550', fontWeight: '500' }}>{loc.settings.advanced_options}</Text>
<BlueSpacing20 />
<BlueText>Connect to your LNDHub</BlueText>
<View
style={{
flexDirection: 'row',
borderColor: '#d2d2d2',
borderBottomColor: '#d2d2d2',
borderWidth: 1.0,
borderBottomWidth: 0.5,
backgroundColor: '#f5f5f5',
minHeight: 44,
height: 44,
alignItems: 'center',
marginVertical: 16,
borderRadius: 4,
}}
>
<TextInput
value={this.state.walletBaseURI}
onChangeText={text => {
this.setState({ walletBaseURI: text });
}}
>
<TextInput
value={this.state.walletBaseURI}
onChangeText={text => {
this.setState({ walletBaseURI: text });
}}
onSubmitEditing={Keyboard.dismiss}
placeholder="your node address"
clearButtonMode="while-editing"
autoCapitalize="none"
placeholderTextColor="#81868e"
style={{ flex: 1, marginHorizontal: 8, color: '#81868e' }}
editable={!this.state.isLoading}
underlineColorAndroid="transparent"
/>
</View>
</React.Fragment>
);
} else if (this.state.activeBitcoin === undefined && this.state.isAdvancedOptionsEnabled) {
return <View />;
}
})()}
<View
style={{
alignItems: 'center',
flex: 1,
marginTop: 32,
}}
>
{!this.state.isLoading ? (
<BlueButton
testID="Create"
title={loc.wallets.add.create}
disabled={this.state.activeBitcoin === undefined}
onPress={() => {
this.setState({ isLoading: true }, async () => {
let w;
onSubmitEditing={Keyboard.dismiss}
placeholder="your node address"
clearButtonMode="while-editing"
autoCapitalize="none"
placeholderTextColor="#81868e"
style={{ flex: 1, marginHorizontal: 8, color: '#81868e' }}
editable={!this.state.isLoading}
underlineColorAndroid="transparent"
/>
</View>
</React.Fragment>
);
} else if (this.state.activeBitcoin === undefined && this.state.isAdvancedOptionsEnabled) {
return <View />;
}
})()}
<View
style={{
alignItems: 'center',
flex: 1,
marginTop: 32,
}}
>
{!this.state.isLoading ? (
<BlueButton
testID="Create"
title={loc.wallets.add.create}
disabled={this.state.activeBitcoin === undefined}
onPress={() => {
this.setState({ isLoading: true }, async () => {
let w;
if (this.state.activeLightning) {
// eslint-disable-next-line
if (this.state.activeLightning) {
// eslint-disable-next-line
this.createLightningWallet = async () => {
w = new LightningCustodianWallet();
w.setLabel(this.state.label || loc.wallets.details.title);
this.createLightningWallet = async () => {
w = new LightningCustodianWallet();
w.setLabel(this.state.label || loc.wallets.details.title);
try {
let lndhub =
this.state.walletBaseURI.trim().length > 0
? this.state.walletBaseURI
: LightningCustodianWallet.defaultBaseUri;
if (lndhub) {
const isValidNodeAddress = await LightningCustodianWallet.isValidNodeAddress(lndhub);
if (isValidNodeAddress) {
w.setBaseURI(lndhub);
w.init();
} else {
throw new Error('The provided node address is not valid LNDHub node.');
}
try {
let lndhub =
this.state.walletBaseURI.trim().length > 0
? this.state.walletBaseURI
: LightningCustodianWallet.defaultBaseUri;
if (lndhub) {
const isValidNodeAddress = await LightningCustodianWallet.isValidNodeAddress(lndhub);
if (isValidNodeAddress) {
w.setBaseURI(lndhub);
w.init();
} else {
throw new Error('The provided node address is not valid LNDHub node.');
}
await w.createAccount();
await w.authorize();
} catch (Err) {
this.setState({ isLoading: false });
console.warn('lnd create failure', Err);
return alert(Err);
// giving app, not adding anything
}
A(A.ENUM.CREATED_LIGHTNING_WALLET);
await w.generate();
BlueApp.wallets.push(w);
await BlueApp.saveToDisk();
EV(EV.enum.WALLETS_COUNT_CHANGED);
A(A.ENUM.CREATED_WALLET);
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
this.props.navigation.navigate('PleaseBackupLNDHub', {
wallet: w,
});
};
this.createLightningWallet();
} else if (this.state.selectedIndex === 2) {
// zero index radio - HD segwit
w = new HDSegwitP2SHWallet();
w.setLabel(this.state.label || loc.wallets.details.title);
} else if (this.state.selectedIndex === 1) {
// btc was selected
// index 1 radio - segwit single address
w = new SegwitP2SHWallet();
w.setLabel(this.state.label || loc.wallets.details.title);
} else {
// btc was selected
// index 2 radio - hd bip84
w = new HDSegwitBech32Wallet();
w.setLabel(this.state.label || loc.wallets.details.title);
}
if (this.state.activeBitcoin) {
await w.createAccount();
await w.authorize();
} catch (Err) {
this.setState({ isLoading: false });
console.warn('lnd create failure', Err);
return alert(Err);
// giving app, not adding anything
}
A(A.ENUM.CREATED_LIGHTNING_WALLET);
await w.generate();
BlueApp.wallets.push(w);
await BlueApp.saveToDisk();
EV(EV.enum.WALLETS_COUNT_CHANGED);
A(A.ENUM.CREATED_WALLET);
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
if (w.type === HDSegwitP2SHWallet.type || w.type === HDSegwitBech32Wallet.type) {
this.props.navigation.navigate('PleaseBackup', {
secret: w.getSecret(),
});
} else {
this.props.navigation.dismiss();
}
this.props.navigation.navigate('PleaseBackupLNDHub', {
wallet: w,
});
};
this.createLightningWallet();
} else if (this.state.selectedIndex === 2) {
// zero index radio - HD segwit
w = new HDSegwitP2SHWallet();
w.setLabel(this.state.label || loc.wallets.details.title);
} else if (this.state.selectedIndex === 1) {
// btc was selected
// index 1 radio - segwit single address
w = new SegwitP2SHWallet();
w.setLabel(this.state.label || loc.wallets.details.title);
} else {
// btc was selected
// index 2 radio - hd bip84
w = new HDSegwitBech32Wallet();
w.setLabel(this.state.label || loc.wallets.details.title);
}
if (this.state.activeBitcoin) {
await w.generate();
BlueApp.wallets.push(w);
await BlueApp.saveToDisk();
EV(EV.enum.WALLETS_COUNT_CHANGED);
A(A.ENUM.CREATED_WALLET);
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
if (w.type === HDSegwitP2SHWallet.type || w.type === HDSegwitBech32Wallet.type) {
this.props.navigation.navigate('PleaseBackup', {
secret: w.getSecret(),
});
} else {
this.props.navigation.dismiss();
}
});
}}
/>
) : (
<ActivityIndicator />
)}
</View>
<BlueButtonLink style={{ marginBottom: 0, marginTop: 24 }}
title={loc.wallets.add.import_wallet}
onPress={() => {
this.props.navigation.navigate('ImportWallet');
}}
/>
}
});
}}
/>
) : (
<ActivityIndicator />
)}
</View>
<BlueButtonLink
style={{ marginBottom: 0, marginTop: 24 }}
title={loc.wallets.add.import_wallet}
onPress={() => {
this.props.navigation.navigate('ImportWallet');
}}
/>
</View>
</ScrollView>
</KeyboardAvoidingView>
</SafeBlueArea>