Skip to content

Commit

Permalink
mobile: do not double handle initalURL (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
nalinbhardwaj authored Jan 27, 2024
1 parent 8b64ddf commit faf26a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions apps/daimo-mobile/src/logic/deeplink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ import { getInitialURL } from "expo-linking";
import { Platform } from "react-native";
import NfcManager, { Ndef, NdefRecord } from "react-native-nfc-manager";

// If an initialURL previously triggered app launch in onboarding state,
// we don't want to trigger it again.
let hasHandledInitialInOnboarding = false;

// User opened app via deeplink or scanning an NFC tag: return URL, otherwise null.
export async function getInitialURLOrTag() {
export async function getInitialURLOrTag(isOnboarding: boolean) {
if (hasHandledInitialInOnboarding && !isOnboarding) return null;
if (isOnboarding) hasHandledInitialInOnboarding = true;

const deeplinkURL = await getInitialURL();
if (deeplinkURL) return deeplinkURL;
if (deeplinkURL) {
return deeplinkURL;
}

if (Platform.OS === "android") {
const tag = await NfcManager.getLaunchTagEvent();
Expand Down
2 changes: 1 addition & 1 deletion apps/daimo-mobile/src/view/screen/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function useInitNavLinks() {

console.log(`[NAV] listening for deep links, account ${account.name}`);
deepLinkInitialised = true;
getInitialURLOrTag().then((url) => {
getInitialURLOrTag(false).then((url) => {
if (url == null) return;
handleDeepLink(nav, url);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function OnboardingScreen({

// During onboarding, listen for payment or invite link invites
useEffect(() => {
getInitialURLOrTag().then((url) => {
getInitialURLOrTag(true).then((url) => {
if (url == null) return;
processLink(url);
});
Expand Down

0 comments on commit faf26a5

Please sign in to comment.