From 5a751617d30ee2e3841e7f40f42872cd382f3ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Rodriguez=20Ve=CC=81lez?= Date: Sun, 6 Jan 2019 22:50:33 -0500 Subject: [PATCH] ADD: Alert user if they are trying to create a lightning wallet without a bitcoin wallet --- BlueComponents.js | 5 +++ loc/cs_CZ.js | 3 ++ loc/da_DK.js | 3 ++ loc/de_DE.js | 4 ++ loc/en.js | 3 ++ loc/es.js | 4 ++ loc/fr_FR.js | 4 ++ loc/nl_NL.js | 3 ++ loc/pt_BR.js | 4 ++ loc/pt_PT.js | 4 ++ loc/ru.js | 4 ++ loc/th_TH.js | 4 ++ loc/ua.js | 4 ++ screen/wallets/add.js | 89 +++++++++++++++++++++++++++++++------------ 14 files changed, 113 insertions(+), 25 deletions(-) diff --git a/BlueComponents.js b/BlueComponents.js index ea176b61..dbf8d479 100644 --- a/BlueComponents.js +++ b/BlueComponents.js @@ -106,6 +106,7 @@ export class LightningButton extends Component { render() { return ( { // eslint-disable-next-line if (this.props.onPress) this.props.onPress(); @@ -136,6 +137,10 @@ export class LightningButton extends Component { } } +LightningButton.propTypes = { + disabled: PropTypes.bool, +}; + export class BlueButtonLink extends Component { render() { // eslint-disable-next-line diff --git a/loc/cs_CZ.js b/loc/cs_CZ.js index 1f302a11..e554fa50 100644 --- a/loc/cs_CZ.js +++ b/loc/cs_CZ.js @@ -8,10 +8,13 @@ module.exports = { hours_ago: 'hodin', minutes_ago: 'minut', never: 'nikdy', + continue: 'Continue', + ok: 'OK', }, wallets: { select_wallet: 'Vyberte peněženku', options: 'možnosti', + createBitcoinWallet: 'In order to use a Lightning wallet, a Bitcoin wallet is needed to fund it. Would you like to continue anyway?', list: { app_name: 'Blue Wallet', title: 'peněženky', diff --git a/loc/da_DK.js b/loc/da_DK.js index 7e1a1936..a9ba4157 100644 --- a/loc/da_DK.js +++ b/loc/da_DK.js @@ -8,10 +8,13 @@ module.exports = { hours_ago: 'timer siden', minutes_ago: 'minutter siden', never: 'aldrig', + continue: 'Continue', + ok: 'OK', }, wallets: { select_wallet: 'Vælg wallet', options: 'valgmuligheder', + createBitcoinWallet: 'In order to use a Lightning wallet, a Bitcoin wallet is needed to fund it. Would you like to continue anyway?', list: { app_name: 'Blue Wallet', title: 'wallets', diff --git a/loc/de_DE.js b/loc/de_DE.js index aea5def9..f1efb20a 100644 --- a/loc/de_DE.js +++ b/loc/de_DE.js @@ -8,10 +8,14 @@ module.exports = { hours_ago: 'Stunden zurück', minutes_ago: 'Minuten zurück', never: 'nie', + continue: 'Continue', + ok: 'OK', }, wallets: { select_wallet: 'Wähle Wallet', options: 'Einstellungen', + createBitcoinWallet: + 'In order to use a Lightning wallet, a Bitcoin wallet is needed in order to fund it. Please, create or import a Bitcoin wallet.', list: { app_name: 'Blue Wallet', title: 'Wallets', diff --git a/loc/en.js b/loc/en.js index b8dcf696..f65014e3 100644 --- a/loc/en.js +++ b/loc/en.js @@ -8,10 +8,13 @@ module.exports = { hours_ago: 'hours ago', minutes_ago: 'minutes ago', never: 'never', + continue: 'Continue', + ok: 'OK', }, wallets: { select_wallet: 'Select Wallet', options: 'options', + createBitcoinWallet: 'In order to use a Lightning wallet, a Bitcoin wallet is needed to fund it. Would you like to continue anyway?', list: { app_name: 'Blue Wallet', title: 'wallets', diff --git a/loc/es.js b/loc/es.js index 16461363..77741ea3 100644 --- a/loc/es.js +++ b/loc/es.js @@ -8,10 +8,14 @@ module.exports = { hours_ago: 'horas atras', minutes_ago: 'minutos atras', never: 'nunca', + continue: 'Continua', + ok: 'OK', }, wallets: { options: 'opciones', select_wallet: 'Selecciona billetera', + createBitcoinWallet: + 'In order to use a Lightning wallet, a Bitcoin wallet is needed in order to fund it. Would you like to continue anyway?', list: { app_name: 'Blue Wallet', title: 'billeteras', diff --git a/loc/fr_FR.js b/loc/fr_FR.js index 2aacd81a..c05c4590 100644 --- a/loc/fr_FR.js +++ b/loc/fr_FR.js @@ -8,10 +8,14 @@ module.exports = { hours_ago: 'heures', minutes_ago: 'minutes', never: 'jamais', + continue: 'Continue', + ok: 'OK', }, wallets: { select_wallet: 'Choix du portefeuille', options: 'options', + createBitcoinWallet: 'In order to use a Lightning wallet, a Bitcoin wallet is needed to fund it. Would you like to continue anyway?', + list: { app_name: 'Blue Wallet', title: 'portefeuilles', diff --git a/loc/nl_NL.js b/loc/nl_NL.js index fece8cae..0badccb4 100644 --- a/loc/nl_NL.js +++ b/loc/nl_NL.js @@ -8,10 +8,13 @@ module.exports = { hours_ago: 'uur geleden', minutes_ago: 'minuten geleden', never: 'nooit', + continue: 'Continue', + ok: 'OK', }, wallets: { select_wallet: 'Selecteer portemonnee', options: 'opties', + createBitcoinWallet: 'In order to use a Lightning wallet, a Bitcoin wallet is needed to fund it. Would you like to continue anyway?', list: { app_name: 'Blue Wallet', title: 'portemonnees', diff --git a/loc/pt_BR.js b/loc/pt_BR.js index d57185f0..786a36e5 100644 --- a/loc/pt_BR.js +++ b/loc/pt_BR.js @@ -8,10 +8,14 @@ module.exports = { hours_ago: 'horas atrás', minutes_ago: 'minutos atrás', never: 'nunca', + continue: 'Continue', + ok: 'OK', }, wallets: { options: 'opções', select_wallet: 'Escolher carteira', + createBitcoinWallet: 'In order to use a Lightning wallet, a Bitcoin wallet is needed to fund it. Would you like to continue anyway?', + list: { tabBarLabel: 'Carteiras', app_name: 'Blue Wallet', diff --git a/loc/pt_PT.js b/loc/pt_PT.js index 9e77c683..f5d79977 100644 --- a/loc/pt_PT.js +++ b/loc/pt_PT.js @@ -8,10 +8,14 @@ module.exports = { hours_ago: 'hours ago', minutes_ago: 'minutes ago', never: 'never', + continue: 'Continue', + ok: 'OK', }, wallets: { options: 'options', select_wallet: 'Select Wallet', + createBitcoinWallet: 'In order to use a Lightning wallet, a Bitcoin wallet is needed to fund it. Would you like to continue anyway?', + list: { app_name: 'Blue Wallet', title: 'wallets', diff --git a/loc/ru.js b/loc/ru.js index eeeac1c9..34c3d8e4 100644 --- a/loc/ru.js +++ b/loc/ru.js @@ -8,10 +8,14 @@ module.exports = { hours_ago: 'часов назад', minutes_ago: 'минут назад', never: 'никогда', + continue: 'Continue', + ok: 'OK', }, wallets: { options: 'options', select_wallet: 'Select Wallet', + createBitcoinWallet: 'In order to use a Lightning wallet, a Bitcoin wallet is needed to fund it. Would you like to continue anyway?', + list: { app_name: 'BlueWallet', title: 'кошельки', diff --git a/loc/th_TH.js b/loc/th_TH.js index c83c217a..afe36e77 100644 --- a/loc/th_TH.js +++ b/loc/th_TH.js @@ -8,10 +8,14 @@ module.exports = { hours_ago: 'ชั่วโมงที่แล้ว', minutes_ago: 'นาทีที่แล้ว', never: 'ไม่เคย', + continue: 'Continue', + ok: 'OK', }, wallets: { select_wallet: 'เลือกกระเป๋าสตางค์', options: 'ทางเลือก', + createBitcoinWallet: 'In order to use a Lightning wallet, a Bitcoin wallet is needed to fund it. Would you like to continue anyway?', + list: { app_name: 'บูลวอลเล็ต', title: 'กระเป๋าสตางค์', diff --git a/loc/ua.js b/loc/ua.js index b5c6d51e..28283d1a 100644 --- a/loc/ua.js +++ b/loc/ua.js @@ -8,10 +8,14 @@ module.exports = { hours_ago: 'часів тому', minutes_ago: 'мінут тому', never: 'ніколи', + continue: 'Continue', + ok: 'OK', }, wallets: { options: 'options', select_wallet: 'Select Wallet', + createBitcoinWallet: 'In order to use a Lightning wallet, a Bitcoin wallet is needed to fund it. Would you like to continue anyway?', + list: { app_name: 'BlueWallet', title: 'гаманці', diff --git a/screen/wallets/add.js b/screen/wallets/add.js index efb38c5f..9058844b 100644 --- a/screen/wallets/add.js +++ b/screen/wallets/add.js @@ -1,6 +1,6 @@ /* global alert */ import React, { Component } from 'react'; -import { AsyncStorage, ActivityIndicator, Keyboard, Dimensions, View, TextInput, TouchableWithoutFeedback } from 'react-native'; +import { Alert, AsyncStorage, ActivityIndicator, Keyboard, Dimensions, View, TextInput, TouchableWithoutFeedback } from 'react-native'; import { BlueTextCentered, BlueText, @@ -140,6 +140,7 @@ export default class WalletsAdd extends Component { height: (width - 60) / 3, }} title={loc.wallets.add.create} + disabled={BlueApp.getWallets().some(wallet => wallet.type === LightningCustodianWallet.type)} /> @@ -193,33 +194,70 @@ export default class WalletsAdd extends Component { let w; if (this.state.activeLightning) { - // lightning was selected // eslint-disable-next-line -for (let t of BlueApp.getWallets()) { + let hasBitcoinWallet = false; + for (let t of BlueApp.getWallets()) { if (t.type === LightningCustodianWallet.type) { // already exist this.setState({ isLoading: false }); return alert('Only 1 Lightning wallet allowed for now'); + } else if (t.type !== LightningCustodianWallet.type) { + hasBitcoinWallet = true; } } - w = new LightningCustodianWallet(); - w.setLabel(this.state.label || w.typeReadable); + this.createLightningWallet = async () => { + w = new LightningCustodianWallet(); + w.setLabel(this.state.label || w.typeReadable); - try { - let lndhub = await AsyncStorage.getItem(AppStorage.LNDHUB); - if (lndhub) { - w.setBaseURI(lndhub); - w.init(); + try { + let lndhub = await AsyncStorage.getItem(AppStorage.LNDHUB); + if (lndhub) { + w.setBaseURI(lndhub); + w.init(); + } + await w.createAccount(); + await w.authorize(); + } catch (Err) { + this.setState({ isLoading: false }); + console.warn('lnd create failure', Err); + // giving app, not adding anything } - await w.createAccount(); - await w.authorize(); - } catch (Err) { - this.setState({ isLoading: false }); - console.warn('lnd create failure', 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', false); + this.props.navigation.dismiss(); + }; + + if (!hasBitcoinWallet) { + Alert.alert( + loc.wallets.add.lightning, + loc.wallets.createBitcoinWallet, + [ + { + text: loc.send.details.cancel, + style: 'cancel', + onPress: () => { + this.setState({ isLoading: false }); + }, + }, + { + text: loc._.ok, + style: 'default', + onPress: () => { + this.createLightningWallet(); + }, + }, + ], + { cancelable: false }, + ); + } else { + this.createLightningWallet(); } - A(A.ENUM.CREATED_LIGHTNING_WALLET); } else if (this.state.selectedIndex === 1) { // btc was selected // index 1 radio - segwit single address @@ -230,14 +268,15 @@ for (let t of BlueApp.getWallets()) { w = new HDSegwitP2SHWallet(); w.setLabel((this.state.label || loc.wallets.add.label_new_segwit) + ' HD'); } - - await w.generate(); - BlueApp.wallets.push(w); - await BlueApp.saveToDisk(); - EV(EV.enum.WALLETS_COUNT_CHANGED); - A(A.ENUM.CREATED_WALLET); - ReactNativeHapticFeedback.trigger('notificationSuccess', false); - this.props.navigation.dismiss(); + 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', false); + this.props.navigation.dismiss(); + } }, 1, );