Skip to content

Commit

Permalink
fix: deeplink is not opening the site in the inapp-browser when the w…
Browse files Browse the repository at this point in the history
…allet is locked (MetaMask#9843)

This PR addresses the issue where deeplinks were not opening the site in
the in-app browser when the wallet was locked.

Solution:
The logic handling deeplinks has been moved from running after the
`appTriggeredAuth` function to the after `postInit` method of the
SDKConnect instance.
This ensures that the deeplink functions are executed only after the
user has logged in and unlocked the wallet.

This is a Fix to this issues =>
MetaMask#9632

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

## **Related issues**

Fixes: MetaMask#9632 

## **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/7aec8835-37e1-45e9-a3e9-e4c50de65913


<!-- [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 completed the PR template to the best of my ability
- [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.

## **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 Jun 21, 2024
1 parent aa1e1a4 commit b480b9b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
36 changes: 20 additions & 16 deletions app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,9 @@ const App = ({ userLoggedIn }) => {
animationNameRef?.current?.play();
}
};
appTriggeredAuth()
.then(() => {
queueOfHandleDeeplinkFunctions.current.forEach((func) => func());

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

const handleDeeplink = useCallback(({ error, params, uri }) => {
Expand Down Expand Up @@ -415,9 +409,11 @@ const App = ({ userLoggedIn }) => {
handleDeeplink(opts);
} else {
queueOfHandleDeeplinkFunctions.current =
queueOfHandleDeeplinkFunctions.current.concat(() => {
handleDeeplink(opts);
});
queueOfHandleDeeplinkFunctions.current.concat([
() => {
handleDeeplink(opts);
},
]);
}
});
}
Expand Down Expand Up @@ -456,17 +452,25 @@ const App = ({ userLoggedIn }) => {
try {
const sdkConnect = SDKConnect.getInstance();
await sdkConnect.init({ navigation: navigator, context: 'Nav/App' });
await SDKConnect.getInstance().postInit();
await SDKConnect.getInstance().postInit(() => {
setTimeout(() => {
queueOfHandleDeeplinkFunctions.current = [];
}, 1000);
});
sdkInit.current = true;
} catch (err) {
sdkInit.current = undefined;
console.error(`Cannot initialize SDKConnect`, err);
}
}
}
initSDKConnect().catch((err) => {
Logger.error(err, 'Error initializing SDKConnect');
});
initSDKConnect()
.then(() => {
queueOfHandleDeeplinkFunctions.current.forEach((func) => func());
})
.catch((err) => {
Logger.error(err, 'Error initializing SDKConnect');
});
}, [navigator, onboarded, userLoggedIn]);

useEffect(() => {
Expand Down
4 changes: 3 additions & 1 deletion app/core/SDKConnect/InitializationManagement/postInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
waitForKeychainUnlocked,
} from '../utils/wait.util';

async function postInit(instance: SDKConnect) {
async function postInit(instance: SDKConnect, callback?: () => void) {
if (!instance.state._initialized) {
throw new Error(`SDKConnect::postInit() - not initialized`);
}
Expand Down Expand Up @@ -53,6 +53,8 @@ async function postInit(instance: SDKConnect) {

instance.state._postInitialized = true;
DevLogger.log(`SDKConnect::postInit() - done`);

callback?.();
}

export default postInit;
1 change: 0 additions & 1 deletion app/core/SDKConnect/SDKConnect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ describe('SDKConnect', () => {
await sdkConnect.postInit();

expect(mockPostInit).toHaveBeenCalledTimes(1);
expect(mockPostInit).toHaveBeenCalledWith(sdkConnect);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions app/core/SDKConnect/SDKConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ export class SDKConnect {
return init({ navigation, context, instance: this });
}

async postInit() {
return postInit(this);
async postInit(callback?: () => void) {
return postInit(this, callback);
}

hasInitialized() {
Expand Down

0 comments on commit b480b9b

Please sign in to comment.