-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support intent URL to start a new WalletConnect session (#271)
## Description Closes: DPM-190 This PR adds support for a new intent URI to start a new WalletConnect session from an external application. The new intent URI has the following schema: `dpm://wcV2?uri=${WALLET_CONNECT_URI}&returnToApp=${true | false}`. Here are the details about the query parameters: * `uri` - The URL-encoded WalletConnect URI to start the new session; * `returnToApp` - Indicates whether the application should return to the application that has triggered the session start after the session is established. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] provided a link to the relevant issue or specification - [x] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed all author checklist items have been addressed ## Summary by CodeRabbit - **New Features** - Added support for custom URL schemes to enhance app interoperability. - Enhanced URI action handling with new parsing and caching capabilities. - Improved WalletConnect functionality with new hooks for session management and action handling. - Introduced a more flexible GraphQL client setup to support child components. - Updated theme provider to support child components for better theme management. - **Enhancements** - Refined navigation logic to better handle cached URI actions and return to the current screen accurately. - Streamlined the handling of received actions and WalletConnect session proposals with updated logic and hooks. - Enhanced loading modal styling for better user experience. - **Bug Fixes** - Fixed issues related to WalletConnect session establishment tracking and proposal handling. - **Refactor** - Simplified WalletConnect hooks and removed unnecessary dependencies to streamline the codebase. - Updated the `UnlockApplication` and `WalletConnectRequest` components for improved logic and user flow. - **Documentation** - Added comments to clarify the logic in WalletConnect session request handling.
- Loading branch information
Showing
26 changed files
with
419 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { setCachedUriAction, parseNativeActionUri } from 'lib/UriActions'; | ||
import React from 'react'; | ||
import { Linking } from 'react-native'; | ||
|
||
/** | ||
* Hook that initialize the logic to handle the | ||
* actions received from the Linking library. | ||
*/ | ||
const useInitLinkingUriActions = () => { | ||
const handleLinkingUrl = React.useCallback((url: string | null) => { | ||
if (url) { | ||
const action = parseNativeActionUri(url); | ||
if (action) { | ||
setCachedUriAction(action); | ||
} | ||
} | ||
}, []); | ||
|
||
React.useEffect(() => { | ||
// Handle the uri that has triggered the app open. | ||
Linking.getInitialURL().then(handleLinkingUrl); | ||
|
||
// Handle the uri received while the app was | ||
// in the background. | ||
const listener = Linking.addEventListener('url', ({ url }) => { | ||
handleLinkingUrl(url); | ||
}); | ||
|
||
return () => listener.remove(); | ||
}, [handleLinkingUrl]); | ||
}; | ||
|
||
export default useInitLinkingUriActions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { useAppState } from '@recoil/appState'; | ||
import { useUriAction } from '@recoil/uriaction'; | ||
import { useAllWalletConnectSessionsRequests } from '@recoil/walletConnectRequests'; | ||
import React from 'react'; | ||
import { useNavigation } from '@react-navigation/native'; | ||
import { RootNavigatorParamList } from 'navigation/RootNavigator'; | ||
import { StackNavigationProp } from '@react-navigation/stack'; | ||
import ROUTES from 'navigation/routes'; | ||
import useHandleUriAction from './uriactions/useHandleUriAction'; | ||
|
||
/** | ||
* Hook that provides the logic to handle the requests received | ||
* while the application was in background. | ||
* The actions that the app can receive while in background are: | ||
* - URIActions triggered by a deep link or from a system intent; | ||
* - WalletConnect session requests. | ||
*/ | ||
export default function useHandleReceivedActions() { | ||
const appState = useAppState(); | ||
|
||
const uriAction = useUriAction(); | ||
const handlingUriAction = React.useRef(false); | ||
const handleUriAction = useHandleUriAction(); | ||
|
||
const walletConnectRequests = useAllWalletConnectSessionsRequests(); | ||
const handlingWalletConnectRequests = React.useRef(false); | ||
const navigation = useNavigation<StackNavigationProp<RootNavigatorParamList>>(); | ||
|
||
React.useEffect(() => { | ||
// Prevent the execution if we are already handling an action. | ||
if (handlingUriAction.current) { | ||
if (uriAction === undefined) { | ||
handlingUriAction.current = false; | ||
} else { | ||
return; | ||
} | ||
} | ||
|
||
// Prevent the execution if we are handling the WalletConnect requests. | ||
if (handlingWalletConnectRequests.current) { | ||
if (walletConnectRequests.length === 0) { | ||
handlingWalletConnectRequests.current = false; | ||
} else { | ||
return; | ||
} | ||
} | ||
|
||
// Ensure that the app is active and unlocked before performing any operation. | ||
if (appState.locked === false && appState.lastObBlur === undefined) { | ||
// We give priority to uri actions received from a deep link | ||
// or a system intent. | ||
if (uriAction !== undefined) { | ||
handleUriAction(uriAction); | ||
handlingUriAction.current = true; | ||
return; | ||
} | ||
|
||
if (walletConnectRequests.length > 0) { | ||
// Navigate to the screen that handle the WalletConnect requests. | ||
navigation.navigate(ROUTES.WALLET_CONNECT_REQUEST); | ||
handlingWalletConnectRequests.current = true; | ||
} | ||
} | ||
}, [ | ||
appState.lastObBlur, | ||
appState.locked, | ||
handleUriAction, | ||
navigation, | ||
uriAction, | ||
walletConnectRequests, | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.