This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
operations.ts
59 lines (54 loc) · 1.76 KB
/
operations.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Dispatch } from 'redux';
import { StorageProvider, STORAGE_KEYS } from '../../Providers/index';
import { clearError, pinError } from './actions';
import {
receiveIsSignedUp,
receiveLoggedIn,
} from '../../state/localUi/actions';
import * as RootNavigation from '../../AppNavigation';
/**
* Confirm pin matches, save it to localStorage and move to home screen
* @param userPin the user confirm pin
* @param expectedPin the users initial pin
*/
export const checkPinMatchAndSet = (
userPin: string,
expectedPin: string,
) => async (dispatch: Dispatch) => {
console.log('checkPinMatchAndSet', userPin, expectedPin);
if (userPin !== expectedPin) {
return dispatch(pinError('PIN did not match'));
}
await StorageProvider.set(STORAGE_KEYS.PIN, expectedPin)
.then(() => {
dispatch(clearError());
dispatch(receiveIsSignedUp(true));
dispatch(receiveLoggedIn(true));
RootNavigation.navigate('CredentialsFlow', { screen: 'CredentialsHome' });
})
.catch(error => {
console.log('error', error.message);
});
};
/**
* Check's the PIN against local Storage and on success, navigates to next screen
* @param userPin string User's Pin
*/
export const checkPinAndSignIn = (userPin: string) => async (dispatch: Dispatch) => {
await StorageProvider.get(STORAGE_KEYS.PIN)
.then(expectedPin => {
console.log(userPin, expectedPin);
if (userPin === expectedPin) {
dispatch(receiveLoggedIn(true));
RootNavigation.navigate('CredentialsFlow', {
screen: 'CredentialsHome',
});
} else {
dispatch(receiveLoggedIn(false, 'pin_is_incorrect'));
}
})
.catch(error => {
console.log(error);
dispatch(receiveLoggedIn(false, 'Count not get storage'));
});
};