FIX: currency crash

This commit is contained in:
Marcos Rodriguez Vélez 2018-12-29 13:58:22 -05:00
parent 66bce8874a
commit ca203785e6
4 changed files with 20 additions and 18 deletions

View file

@ -25,6 +25,7 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="bitcoin" /> <data android:scheme="bitcoin" />
<data android:scheme="lightning" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" /> <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

View file

@ -12,7 +12,6 @@ const STRUCT = {
}; };
async function updateExchangeRate() { async function updateExchangeRate() {
let preferredFiatCurrency;
try { try {
preferredFiatCurrency = JSON.parse(await AsyncStorage.getItem(AppStorage.PREFERREDCURRENCY)); preferredFiatCurrency = JSON.parse(await AsyncStorage.getItem(AppStorage.PREFERREDCURRENCY));
if (preferredFiatCurrency === null) { if (preferredFiatCurrency === null) {
@ -48,17 +47,16 @@ async function updateExchangeRate() {
async function startUpdater(force = false) { async function startUpdater(force = false) {
if (force) { if (force) {
await AsyncStorage.removeItem(AppStorage.CURRENCY); await AsyncStorage.removeItem(AppStorage.CURRENCY);
try {
preferredFiatCurrency = JSON.parse(await AsyncStorage.getItem(AppStorage.PREFERREDCURRENCY));
if (preferredFiatCurrency === null) {
throw Error();
}
} catch (_error) {
preferredFiatCurrency = FiatUnit.USD;
}
} }
lang = await AsyncStorage.getItem(AppStorage.CURRENCY); lang = await AsyncStorage.getItem(AppStorage.CURRENCY);
preferredFiatCurrency = JSON.parse(await AsyncStorage.getItem(AppStorage.PREFERREDCURRENCY)); try {
preferredFiatCurrency = JSON.parse(await AsyncStorage.getItem(AppStorage.PREFERREDCURRENCY));
if (preferredFiatCurrency === null) {
throw Error();
}
} catch (_error) {
preferredFiatCurrency = FiatUnit.USD;
}
try { try {
lang = JSON.parse(lang); lang = JSON.parse(lang);
} catch (Err) { } catch (Err) {

View file

@ -28,6 +28,7 @@ export default class ScanLndInvoice extends React.Component {
if (!BlueApp.getWallets().some(item => item.type === LightningCustodianWallet.type)) { if (!BlueApp.getWallets().some(item => item.type === LightningCustodianWallet.type)) {
alert('Before paying a Lightning invoice, you must first add a Lightning wallet.'); alert('Before paying a Lightning invoice, you must first add a Lightning wallet.');
props.navigation.dismiss()
} else { } else {
let fromSecret; let fromSecret;
if (props.navigation.state.params.fromSecret) fromSecret = props.navigation.state.params.fromSecret; if (props.navigation.state.params.fromSecret) fromSecret = props.navigation.state.params.fromSecret;
@ -77,7 +78,7 @@ export default class ScanLndInvoice extends React.Component {
}, 6000); }, 6000);
if (!this.state.fromWallet) { if (!this.state.fromWallet) {
alert('Error: cant find source wallet (this should never happen)'); alert('Before paying a Lightning invoice, you must first add a Lightning wallet.');
return this.props.navigation.goBack(); return this.props.navigation.goBack();
} }

View file

@ -14,7 +14,7 @@ import {
Text, Text,
} from 'react-native'; } from 'react-native';
import { Icon } from 'react-native-elements'; import { Icon } from 'react-native-elements';
import { BlueNavigationStyle, BlueButton } from '../../BlueComponents'; import { BlueNavigationStyle, BlueButton, BlueLoading } from '../../BlueComponents';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Modal from 'react-native-modal'; import Modal from 'react-native-modal';
import NetworkTransactionFees, { NetworkTransactionFee } from '../../models/networkTransactionFees'; import NetworkTransactionFees, { NetworkTransactionFee } from '../../models/networkTransactionFees';
@ -41,11 +41,12 @@ export default class SendDetails extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { isLoading: true };
const wallets = BlueApp.getWallets(); const wallets = BlueApp.getWallets();
if (!BlueApp.getWallets().some(item => item.type !== LightningCustodianWallet.type)) { if (!BlueApp.getWallets().some(item => item.type !== LightningCustodianWallet.type)) {
alert('Before sending Bitcoins, you must first add a Bitcoin wallet.'); alert('Before sending Bitcoins, you must first add a Bitcoin wallet.');
props.navigation.goBack(); props.navigation.dismiss();
} else { } else {
console.log('props.navigation.state.params=', props.navigation.state.params); console.log('props.navigation.state.params=', props.navigation.state.params);
let address; let address;
@ -130,7 +131,7 @@ export default class SendDetails extends Component {
fee: response.halfHourFee, fee: response.halfHourFee,
networkTransactionFees: response, networkTransactionFees: response,
feeSliderValue: response.halfHourFee, feeSliderValue: response.halfHourFee,
isLoading: false, isLoading: typeof this.state.fromWallet === 'object',
}); });
}); });
if (recommendedFees) { if (recommendedFees) {
@ -138,7 +139,7 @@ export default class SendDetails extends Component {
fee: recommendedFees.halfHourFee, fee: recommendedFees.halfHourFee,
networkTransactionFees: recommendedFees, networkTransactionFees: recommendedFees,
feeSliderValue: recommendedFees.halfHourFee, feeSliderValue: recommendedFees.halfHourFee,
isLoading: false, isLoading: typeof this.state.fromWallet === 'object',
}); });
if (this.props.navigation.state.params.uri) { if (this.props.navigation.state.params.uri) {
@ -478,10 +479,10 @@ export default class SendDetails extends Component {
}; };
render() { render() {
if (!this.state.fromWallet.getAddress) { if (this.state.isLoading || typeof this.state.fromWallet === 'undefined') {
return ( return (
<View style={{ flex: 1, paddingTop: 20 }}> <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>System error: Source wallet not found (this should never happen)</Text> <BlueLoading />
</View> </View>
); );
} }
@ -664,6 +665,7 @@ SendDetails.propTypes = {
navigation: PropTypes.shape({ navigation: PropTypes.shape({
goBack: PropTypes.function, goBack: PropTypes.function,
navigate: PropTypes.func, navigate: PropTypes.func,
dismiss: PropTypes.func,
state: PropTypes.shape({ state: PropTypes.shape({
params: PropTypes.shape({ params: PropTypes.shape({
address: PropTypes.string, address: PropTypes.string,