Skip to content

Commit 7dc85cd

Browse files
CP-11837: Branch Integration (#3251)
Co-authored-by: An Nguyen <[email protected]>
1 parent 0d36ef5 commit 7dc85cd

File tree

25 files changed

+350
-9
lines changed

25 files changed

+350
-9
lines changed

packages/core-mobile/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ ANALYTICS_ENCRYPTION_KEY_ID=
5454
# required for gasless
5555
GAS_STATION_URL=
5656

57+
BRANCH_KEY=

packages/core-mobile/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,7 @@ GoogleService-Info.plist*
9393
# The following patterns were generated by expo-cli
9494

9595
expo-env.d.ts
96-
# @end expo-cli
96+
# @end expo-cli
97+
98+
# Branch
99+
/ios/config.xcconfig

packages/core-mobile/android/app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ android {
150150
internal {
151151
applicationIdSuffix ".internal"
152152
buildConfigField "boolean", "ENABLE_FLAG_SECURE", "false"
153+
manifestPlaceholders = [BRANCH_TEST_MODE:"true", BRANCH_KEY: project.env.get("BRANCH_KEY")]
153154
}
154155
external {
155156
buildConfigField "boolean", "ENABLE_FLAG_SECURE", "false"
157+
manifestPlaceholders = [BRANCH_TEST_MODE:"false", BRANCH_KEY: project.env.get("BRANCH_KEY")]
156158
}
157159
}
158160

@@ -169,6 +171,8 @@ dependencies {
169171
// The version of react-native is set by the React Native Gradle Plugin
170172
implementation("com.facebook.react:react-android")
171173

174+
implementation "com.google.android.gms:play-services-ads-identifier:18.0.1"
175+
172176
if (hermesEnabled.toBoolean()) {
173177
implementation("com.facebook.react:hermes-android")
174178
} else {

packages/core-mobile/android/app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:node="remove" tools:ignore="QueryAllPackagesPermission" />
1111
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove" />
1212
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
13+
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
1314

1415
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
1516
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
@@ -33,6 +34,11 @@
3334
<meta-data
3435
android:name="com.google.firebase.messaging.default_notification_icon"
3536
android:resource="@drawable/notification_icon" />
37+
<!-- Branch init -->
38+
<meta-data android:name="io.branch.sdk.BranchKey" android:value="${BRANCH_KEY}" />
39+
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="${BRANCH_KEY}" />
40+
<!-- Set to `true` to use `BranchKey.test` -->
41+
<meta-data android:name="io.branch.sdk.TestMode" android:value="${BRANCH_TEST_MODE}" />
3642
<activity
3743
android:name=".MainActivity"
3844
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"

packages/core-mobile/android/app/src/main/java/com/avaxwallet/MainActivity.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnable
99
import com.facebook.react.defaults.DefaultReactActivityDelegate
1010
import com.zoontek.rnbootsplash.RNBootSplash
1111
import expo.modules.ReactActivityDelegateWrapper
12+
import io.branch.rnbranch.*
13+
import android.content.Intent
1214

1315
class MainActivity : ReactActivity() {
1416

@@ -29,6 +31,11 @@ class MainActivity : ReactActivity() {
2931
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
3032
)
3133

34+
override fun onStart() {
35+
super.onStart()
36+
RNBranchModule.initSession(getIntent().getData(), this)
37+
}
38+
3239
override fun onCreate(savedInstanceState: Bundle?) {
3340
RNBootSplash.init(this, R.style.BootTheme)
3441
super.onCreate(null)
@@ -42,4 +49,10 @@ class MainActivity : ReactActivity() {
4249
)
4350
}
4451
}
52+
53+
override fun onNewIntent(intent: Intent?) {
54+
super.onNewIntent(intent)
55+
setIntent(intent)
56+
RNBranchModule.reInitSession(this)
57+
}
4558
}

packages/core-mobile/android/app/src/main/java/com/avaxwallet/MainApplication.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.facebook.react.modules.network.OkHttpClientProvider
1818
import com.facebook.react.soloader.OpenSourceMergedSoMapping
1919
import com.facebook.soloader.SoLoader
2020
import java.lang.reflect.Field
21+
import io.branch.rnbranch.*
2122

2223
class MainApplication : Application(), ReactApplication {
2324

@@ -45,7 +46,8 @@ class MainApplication : Application(), ReactApplication {
4546
super.onCreate()
4647

4748
increaseWindowCursorSize()
48-
49+
RNBranchModule.getAutoInstance(this);
50+
4951
// Manually set user agent to our format. This helps avoid getting identified as a bot and rate limited by cloudflare
5052
// the default format is usually okhttp/x.x.x
5153
// while our format is

packages/core-mobile/android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ allprojects {
6161
mavenCentral()
6262
maven { url "$rootDir/../node_modules/expo-camera/android/maven" }
6363
maven { url 'https://www.jitpack.io' }
64+
maven { url 'https://maven.google.com/' }
6465
}
6566

6667
configurations.all {

packages/core-mobile/app/contexts/DeeplinkContext/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export interface DeepLink {
1414
export enum DeepLinkOrigin {
1515
ORIGIN_DEEPLINK = 'deeplink',
1616
ORIGIN_QR_CODE = 'qr-code',
17-
ORIGIN_NOTIFICATION = 'notification'
17+
ORIGIN_NOTIFICATION = 'notification',
18+
ORIGIN_BRANCH = 'branch'
1819
}
1920

2021
export const PROTOCOLS = {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// import { useEffect } from 'react'
2+
// import branch, { BranchParams } from 'react-native-branch'
3+
// import { useDeeplink } from 'contexts/DeeplinkContext/DeeplinkContext'
4+
// import { DeepLink, DeepLinkOrigin } from 'contexts/DeeplinkContext/types'
5+
// import { useSelector } from 'react-redux'
6+
// import { selectDistinctID } from 'store/posthog'
7+
// import Logger from 'utils/Logger'
8+
9+
// function handleBranchDeeplink(
10+
// setPendingDeepLink: (deepLink: DeepLink) => void,
11+
// params?: BranchParams | undefined
12+
// ): void {
13+
// if (params?.$deeplink_path) {
14+
// setPendingDeepLink({
15+
// url: params.$deeplink_path as string,
16+
// origin: DeepLinkOrigin.ORIGIN_BRANCH
17+
// })
18+
// }
19+
// }
20+
21+
// export function useBranchDeeplinkObserver(): void {
22+
// const { setPendingDeepLink } = useDeeplink()
23+
// const distinctID = useSelector(selectDistinctID)
24+
25+
// useEffect(() => {
26+
// branch.setRequestMetadata('$posthog_distinct_id', distinctID)
27+
28+
// branch
29+
// .getLatestReferringParams()
30+
// .then((params?: BranchParams) =>
31+
// handleBranchDeeplink(setPendingDeepLink, params)
32+
// )
33+
// .catch(Logger.error)
34+
35+
// const unsubscribe = branch.subscribe(({ params }) =>
36+
// handleBranchDeeplink(setPendingDeepLink, params)
37+
// )
38+
39+
// return () => {
40+
// unsubscribe()
41+
// }
42+
// }, [distinctID, setPendingDeepLink])
43+
// }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './listener'

0 commit comments

Comments
 (0)