-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PKG -- [fcl] Add VIEW/DEEPLINK (#1763)
- Loading branch information
Showing
10 changed files
with
102 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@onflow/fcl": minor | ||
--- | ||
|
||
Add VIEW/DEEPLINK |
Empty file.
Empty file.
1 change: 0 additions & 1 deletion
1
packages/fcl/src/current-user/exec-service/strategies/utils/poll.js
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,49 @@ | ||
import * as Linking from "expo-linking" | ||
import {AppState} from "react-native" | ||
import {URL} from "../url" | ||
|
||
/** | ||
* Renders a deeplink view (i.e. deep links to a wallet app) | ||
* | ||
* @param {URL} src | ||
* @param {object} opts | ||
* @param {() => void} [opts.onClose] | ||
* @returns {[null, () => void]} | ||
*/ | ||
export function renderDeeplink(src, opts = {}) { | ||
const url = new URL(src.toString()) | ||
|
||
// Custom schemes (i.e mywallet://) are not supported for | ||
// security reasons. These schemes can be hijacked by malicious | ||
// apps and impersonate the wallet. | ||
// | ||
// Wallet developers should register a universal link instead. | ||
// (i.e https://mywallet.com/ or https://link.mywallet.com/) | ||
// | ||
// Additionally this allows the wallet to redirect to the app | ||
// store/show custom web content if the wallet is not installed. | ||
if (url.protocol !== "https:") { | ||
throw new Error( | ||
"Deeplink must be https scheme. Custom schemes are not supported, please use a universal link/app link instead." | ||
) | ||
} | ||
|
||
// Link to the target url | ||
Linking.openURL(url.toString()) | ||
|
||
const onClose = opts.onClose || (() => {}) | ||
|
||
const onAppStateChange = state => { | ||
if (state === "active") { | ||
unmount() | ||
onClose() | ||
} | ||
} | ||
AppState.addEventListener("change", onAppStateChange) | ||
|
||
const unmount = () => { | ||
AppState.removeEventListener("change", onAppStateChange) | ||
} | ||
|
||
return [null, unmount] | ||
} |
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