Skip to content

Commit

Permalink
fix: deeplink handling issue when the app is closed (#8469)
Browse files Browse the repository at this point in the history
## **Description**

This PR addresses a deeplink navigation issue found in MetaMask Mobile
v7.10.0 and above ([LINK TO THE
BUG](#7766)). The
update introduces key improvements for handling deeplinks:

**Issue Overview:**
Previously, deeplinks failed to function correctly when the MetaMask app
was not running in the background. This was caused by premature route
navigation attempts before the app completed its loading process.

**Implemented Solutions:**

**Conditional Deeplink Queueing**:
A queue system for deeplinks has been implemented. Deeplinks that are
triggered by [branch.io](http://branch.io/) events are queued if the app
is not fully initialized. This queued processing ensures that deeplinks
are handled correctly only once the app loads completely.

**Immediate Handling When the App Loaded:**
For instances where the app is already loaded, deeplinks from
[branch.io](http://branch.io/) events are processed immediately and
normally, without queuing. This ensures direct and standard handling of
deeplinks in an active app state.

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**


https://github.com/MetaMask/metamask-mobile/assets/61094771/629803d3-0dea-4dd8-95b0-c509d248b07a


<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [x] I've included screenshots/recordings if applicable
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [x] I’ve properly set the pull request status:
  - [x] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
omridan159 authored Jan 31, 2024
1 parent 3d44ffe commit f5d21bd
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ const App = ({ userLoggedIn }) => {
const [navigator, setNavigator] = useState(undefined);
const prevNavigator = useRef(navigator);
const [route, setRoute] = useState();
const queueOfHandleDeeplinkFunctions = useRef([]);
const [animationPlayed, setAnimationPlayed] = useState(false);
const { colors } = useTheme();
const { toastRef } = useContext(ToastContext);
Expand Down Expand Up @@ -285,10 +286,16 @@ const App = ({ userLoggedIn }) => {
animationNameRef?.current?.play();
}
};
appTriggeredAuth().catch((error) => {
Logger.error(error, 'App: Error in appTriggeredAuth');
});
}, [navigator]);
appTriggeredAuth()
.then(() => {
queueOfHandleDeeplinkFunctions.current.forEach((func) => func());

queueOfHandleDeeplinkFunctions.current = [];
})
.catch((error) => {
Logger.error(error, 'App: Error in appTriggeredAuth');
});
}, [navigator, queueOfHandleDeeplinkFunctions]);

const handleDeeplink = useCallback(({ error, params, uri }) => {
if (error) {
Expand Down Expand Up @@ -345,12 +352,19 @@ const App = ({ userLoggedIn }) => {
Logger.error('Error from Branch: ' + error);
}

handleDeeplink(opts);
if (sdkPostInit.current === true) {
handleDeeplink(opts);
} else {
queueOfHandleDeeplinkFunctions.current =
queueOfHandleDeeplinkFunctions.current.concat(() => {
handleDeeplink(opts);
});
}
});
}
prevNavigator.current = navigator;
}
}, [dispatch, handleDeeplink, navigator]);
}, [dispatch, handleDeeplink, navigator, queueOfHandleDeeplinkFunctions]);

useEffect(() => {
const initAnalytics = async () => {
Expand Down Expand Up @@ -401,7 +415,7 @@ const App = ({ userLoggedIn }) => {
handlePostInit().catch((err) => {
Logger.error(err, 'Error postInit SDKConnect');
});
}, [userLoggedIn, postInitReady]);
}, [userLoggedIn, postInitReady, queueOfHandleDeeplinkFunctions]);

useEffect(() => {
if (isWC2Enabled) {
Expand Down

0 comments on commit f5d21bd

Please sign in to comment.