Skip to content

Commit

Permalink
fixed qr reference
Browse files Browse the repository at this point in the history
  • Loading branch information
free-bots committed Dec 29, 2020
1 parent 59ee37f commit b68b439
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
Expand Down
17 changes: 10 additions & 7 deletions views/pages/login/connection/ServerAuthenticationQr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Button from '../../../components/buttons/Button';
import {BaseScreen} from '../../base/BaseScreen';

export const ServerAuthenticationQr = () => {
let qr: QRCodeScanner | null;

const [camera, setCamera] = useState<'back' | 'front'>('back');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [loading, code, setCode, signUp] = useSignUp();
Expand All @@ -17,30 +19,28 @@ export const ServerAuthenticationQr = () => {
setCamera(camera === 'back' ? 'front' : 'back');
};

const onCode = (data: string) => {
const onCode = (qrRef: QRCodeScanner, data: string) => {
Alert.alert(
'Scanned QR code',
`Is ${data} your code?`,
[
{
text: 'Yes',
onPress: () => {
signUp()
signUp(data)
.then(() => {
loggedIn();
})
.catch(() => {
// state is cleared
// try again
qrRef.reactivate();
});
// navigate
},
},
{
text: 'No',
onPress: () => {
setCode('');
// retry scan
qrRef.reactivate();
},
},
],
Expand All @@ -61,6 +61,7 @@ export const ServerAuthenticationQr = () => {
justifyContent: 'space-between',
}}>
<QRCodeScanner
ref={(node) => (qr = node)}
topViewStyle={{
flex: 1,
}}
Expand All @@ -73,7 +74,9 @@ export const ServerAuthenticationQr = () => {
vibrate={true}
onRead={(e) => {
console.log(e);
onCode(e.data);
if (qr) {
onCode(qr, e.data);
}
}}
/>
<Button
Expand Down
8 changes: 4 additions & 4 deletions views/pages/login/connection/hooks/SignUpHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ export const useSignUp = (): [
boolean,
string,
Dispatch<SetStateAction<string>>,
() => Promise<void>,
(codeRef?: string) => Promise<void>,
] => {
const [code, setCode] = useState<string>('');
const [loading, setLoading] = useState<boolean>(false);

const signUp = () => {
const signUp = (codeRef?: string) => {
setLoading(true);
if (!code) {
if (!code && !codeRef) {
return Promise.reject('no code!');
}

return AuthenticationService.signUp({
deviceId: '',
qrCode: code,
qrCode: codeRef || code,
})
.then((response) => {
console.log(response);
Expand Down

0 comments on commit b68b439

Please sign in to comment.