Skip to content

Commit

Permalink
views/handleAnythingQRScanner: add loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Mar 4, 2023
1 parent ea4069b commit 0a855af
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
4 changes: 2 additions & 2 deletions utils/handleAnything.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Alert } from 'react-native';
import { getParams as getlnurlParams, findlnurl, decodelnurl } from 'js-lnurl';
import ReactNativeBlobUtil from 'react-native-blob-util';
import { doTorRequest, RequestMethod } from './TorUtils';
import { doTorRequest, RequestMethod } from './../utils/TorUtils';

import stores from '../stores/Stores';
import AddressUtils from './../utils/AddressUtils';
Expand Down Expand Up @@ -198,7 +198,7 @@ const handleAnything = async (
);
// handle Tor LN addresses
if (value.endsWith('.onion')) {
doTorRequest(url, RequestMethod.GET)
await doTorRequest(url, RequestMethod.GET)
.then((response: any) => {
return [
'LnurlPay',
Expand Down
54 changes: 50 additions & 4 deletions views/handleAnythingQRScanner.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
import * as React from 'react';
import { Alert } from 'react-native';
import { Alert, View } from 'react-native';
import { Header } from 'react-native-elements';
import { observer } from 'mobx-react';

import QRCodeScanner from './../components/QRCodeScanner';

import handleAnything from './../utils/handleAnything';
import { localeString } from './../utils/LocaleUtils';
import { themeColor } from './../utils/ThemeUtils';
import LoadingIndicator from './../components/LoadingIndicator';

interface handleAnythingQRProps {
navigation: any;
}

interface handleAnythingQRState {
loading: boolean;
}

@observer
export default class handleAnythingQRScanner extends React.Component<
handleAnythingQRProps,
{}
handleAnythingQRState
> {
constructor(props: any) {
super(props);

this.state = {
useInternalScanner: false
loading: false
};
}

handleAnythingScanned = (data: string) => {
handleAnythingScanned = async (data: string) => {
const { navigation } = this.props;
this.setState({
loading: true
});
handleAnything(data)
.then(([route, props]) => {
this.setState({
loading: false
});
navigation.navigate(route, props);
})
.catch((err) => {
Expand All @@ -43,12 +56,45 @@ export default class handleAnythingQRScanner extends React.Component<
{ cancelable: false }
);

this.setState({
loading: false
});

navigation.navigate('Send');
});
};

render() {
const { navigation } = this.props;
const { loading } = this.state;

if (loading) {
return (
<View
style={{
flex: 1,
backgroundColor: themeColor('background')
}}
>
<Header
centerComponent={{
text: 'Loading',
style: {
color: themeColor('text'),
fontFamily: 'Lato-Regular'
}
}}
backgroundColor={themeColor('background')}
containerStyle={{
borderBottomWidth: 0
}}
/>
<View style={{ top: 40 }}>
<LoadingIndicator />
</View>
</View>
);
}

return (
<QRCodeScanner
Expand Down

0 comments on commit 0a855af

Please sign in to comment.