Skip to content

Commit

Permalink
🔀Merge hotfix on Android sign in
Browse files Browse the repository at this point in the history
  • Loading branch information
nwingt authored Jan 15, 2020
2 parents 500df39 + 3dd0d59 commit e286b3b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# import { API_URL } from 'react-native-dotenv'

# Same as MARKETING_VERSION in iOS / version in Android
APP_MARKETING_VERSION=0.13.0
APP_MARKETING_VERSION=0.13.1

# Same as CURRENT_PROJECT_VERSION in iOS / version code in Android
APP_VERSION=155
APP_VERSION=156

# APP_VERSION must be greater or equal to the this value
# without forcing user to update the app
Expand Down
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ android {
applicationId "com.oice"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 155
versionName "0.13.0"
versionCode 156
versionName "0.13.1"
missingDimensionStrategy 'react-native-camera', 'general'
}
splits {
Expand Down
75 changes: 57 additions & 18 deletions app/screens/likerland-oauth-screen/likerland-oauth-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
} from "react-native"
import { NavigationScreenProps } from "react-navigation"
import { WebViewNavigation } from 'react-native-webview'
import {
WebViewErrorEvent,
WebViewHttpErrorEvent,
} from "react-native-webview/lib/WebViewTypes"
import { inject } from "mobx-react"

import { Style } from "./likerland-oauth-screen.style"
Expand All @@ -19,28 +23,18 @@ import { RootStore } from "../../models/root-store"

import { translate } from "../../i18n"
import { COMMON_API_CONFIG } from "../../services/api/api-config"
import { logError } from "../../utils/error"

export interface LikerLandOAuthScreenProps extends NavigationScreenProps<{}> {
rootStore: RootStore,
}

@inject("rootStore")
export class LikerLandOAuthScreen extends React.Component<LikerLandOAuthScreenProps, {}> {
private onNavigationStateChange = async (navState: WebViewNavigation) => {
const { url } = navState
const { rootStore } = this.props
if (url.includes("/following")) {
await Promise.all([
this.props.rootStore.userStore.fetchUserInfo(),
this.props.rootStore.userStore.fetchLikerLandUserInfo(),
])
this.props.navigation.navigate("App")

// Try to open the deferred deep link URL after sign in
rootStore.openDeepLink()
} else if (url.includes("/in/register")) {
this.handleError()
}
export class LikerLandOAuthScreen extends React.Component<LikerLandOAuthScreenProps> {
redirectTimer?: NodeJS.Timeout

state = {
hasHandledRedirect: false,
}

private handleError = async () => {
Expand All @@ -49,6 +43,39 @@ export class LikerLandOAuthScreen extends React.Component<LikerLandOAuthScreenPr
this.props.navigation.goBack()
}

private handlePostSignIn = async () => {
if (this.state.hasHandledRedirect) return
this.setState({ hasHandledRedirect: true })
if (this.redirectTimer) {
clearTimeout(this.redirectTimer)
this.redirectTimer = undefined
}
await Promise.all([
this.props.rootStore.userStore.fetchUserInfo(),
this.props.rootStore.userStore.fetchLikerLandUserInfo(),
])
this.props.navigation.navigate("App")

// Try to open the deferred deep link URL after sign in
this.props.rootStore.openDeepLink()
}

private handleURLChange = (url: string) => {
if (url.includes("/following")) {
this.handlePostSignIn()
} else if (url.includes("/oauth/redirect")) {
// Fallback to use timer if the above case not working
this.redirectTimer = setTimeout(this.handlePostSignIn, 2000)
} else if (url.includes("/in/register")) {
this.handleError()
logError("Error when signing in to liker.land, like.co shows register page")
}
}

private onNavigationStateChange = ({ url }: WebViewNavigation) => {
this.handleURLChange(url)
}

private onWebviewError = () => {
Alert.alert(
translate("signInScreen.error"),
Expand All @@ -62,6 +89,18 @@ export class LikerLandOAuthScreen extends React.Component<LikerLandOAuthScreenPr
)
}

private onError = (event: WebViewErrorEvent) => {
this.onWebviewError()
const { code, description, url } = event.nativeEvent
logError(`Error occurs inside webview when signing in to liker.land ${JSON.stringify({ code, description, url })}`)
}

private onHttpError = (event: WebViewHttpErrorEvent) => {
this.onWebviewError()
const { description, statusCode, url } = event.nativeEvent
logError(`HTTP error occurs inside webview when signing in to liker.land ${JSON.stringify({ description, statusCode, url })}`)
}

render () {
const {
signInURL,
Expand All @@ -81,8 +120,8 @@ export class LikerLandOAuthScreen extends React.Component<LikerLandOAuthScreenPr
{...{ applicationNameForUserAgent: COMMON_API_CONFIG.userAgent }}
renderError={this.renderLoadingOverlay}
onNavigationStateChange={this.onNavigationStateChange}
onError={this.onWebviewError}
onHttpError={this.onWebviewError}
onError={this.onError}
onHttpError={this.onHttpError}
/>
{this.renderLoadingOverlay()}
</View>
Expand Down
8 changes: 4 additions & 4 deletions ios/LikeCoinApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -703,12 +703,12 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = LikeCoinApp/LikeCoinApp.entitlements;
CURRENT_PROJECT_VERSION = 155;
CURRENT_PROJECT_VERSION = 156;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_TEAM = 76UMR894HH;
INFOPLIST_FILE = LikeCoinApp/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 0.13.0;
MARKETING_VERSION = 0.13.1;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand All @@ -727,11 +727,11 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = LikeCoinApp/LikeCoinApp.entitlements;
CURRENT_PROJECT_VERSION = 155;
CURRENT_PROJECT_VERSION = 156;
DEVELOPMENT_TEAM = 76UMR894HH;
INFOPLIST_FILE = LikeCoinApp/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 0.13.0;
MARKETING_VERSION = 0.13.1;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "likecoin-app",
"version": "0.13.0",
"version": "0.13.1",
"private": true,
"scripts": {
"start": "react-native start",
Expand Down

0 comments on commit e286b3b

Please sign in to comment.