Skip to content

Commit

Permalink
Fix network check (#42)
Browse files Browse the repository at this point in the history
* Fix network
* Remove unused code
  • Loading branch information
putuadityabayu authored Aug 14, 2021
1 parent 6d38bcd commit ed87995
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions activity/auth/AuthProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {PortalProvider} from'@gorhom/portal'
import RNFS from 'react-native-fs'
import {addEventListener as ExpoAddListener,removeEventListener as ExpoRemoveListener,getInitialURL} from 'expo-linking'
import {requestPermissionsAsync as AdsRequest} from 'expo-ads-admob'

import verifyApps from '@pn/utils/VerifyApps'
import * as Notifications from 'expo-notifications'
import {FontAwesomeIconsPack} from '../../components/utils/FontAwesomeIconsPack'
import {IoniconsPack} from '../../components/utils/IoniconsPack'
Expand Down Expand Up @@ -101,6 +101,7 @@ const AuthProviderFunc = (props) => {
useEffect(()=>{
async function asyncTask(){
try {
await verifyApps();
let [res,lang,ads] = await Promise.all([AsyncStorage.getItem("theme"),AsyncStorage.getItem("lang"),AsyncStorage.getItem("ads")])

if(res !== null) {
Expand All @@ -117,7 +118,6 @@ const AuthProviderFunc = (props) => {
}
}
} catch(e){}

await refreshToken();
return Promise.resolve();
} catch(err){
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Portalnesia",
"slug": "portalnesia",
"scheme": "pn",
"version": "2.9.1",
"version": "2.9.2",
"orientation": "portrait",
"icon": "./assets/icon.png",
"backgroundColor": "#ffffff",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
},
"private": true,
"name": "portal-native",
"version": "2.9.1",
"version": "2.9.2",
"author": "Putu Aditya <aditya@portalnesia.com>",
"license": "MIT"
}
4 changes: 2 additions & 2 deletions provider/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import {default as en_locale} from '@pn/locale/en.json'
import {default as id_locale} from '@pn/locale/id.json'
import loadResources from '@pn/utils/Assets'
import { logError,log } from '@pn/utils/log';
import { UserType } from '@pn/types/UserTypes';
import { TokenResponse } from 'expo-auth-session';
//import { UserType } from '@pn/types/UserTypes';
//import { TokenResponse } from 'expo-auth-session';

const customMap = (mapping as any)
LogBox.ignoreLogs(['Setting a timer for a long period of time']);
Expand Down
9 changes: 7 additions & 2 deletions utils/VerifyApps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import i18n from 'i18n-js'
import { log, logError } from './log'
import * as Secure from 'expo-secure-store'
import moment from 'moment'
import NetInfo from '@react-native-community/netinfo'

async function alertWarning(msg: string) {
return new Promise<void>(res=>{
Expand Down Expand Up @@ -55,6 +56,10 @@ async function checkRemoteVerification(force=true): Promise<RemoteResult> {

type LocalResult = {verify:boolean,signature?:string}
async function checkLocalVerification() {
const netinfo = await NetInfo.fetch();
if(!netinfo.isConnected) {
throw new Error(i18n.t("net_offline"));
}
const local = await Secure.getItemAsync('signature');
let result: LocalResult = {verify:false,signature:null};
if(local !== null) {
Expand Down Expand Up @@ -120,8 +125,8 @@ export default async function verifyApps() {
}
return Promise.resolve();
} catch(e) {
log(`Safety verification ${e?.message}`);
logError(e,"Verification error");
//log(`Safety verification ${e?.message}`);
//logError(e,"Verification error");
await alertWarning(e?.message)
}
}

0 comments on commit ed87995

Please sign in to comment.