-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: improve linking * fix: improve linking * fix: cleanup * fix: wip * fix: receiver component * fix: loading state for qr scanner * fix: cleanup * fix: lowercase payment info * fix: improve handle linking hook * fix: reset navigation stack * fix: handle linking * fix: comment * fix: add exp scheme only for dev builds * fix: remove console log
- Loading branch information
Showing
11 changed files
with
176 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from "react"; | ||
import { View } from "react-native"; | ||
import { Text } from "~/components/ui/text"; | ||
|
||
interface ReceiverProps { | ||
originalText: string; | ||
invoice?: string; | ||
} | ||
|
||
export function Receiver({ originalText, invoice }: ReceiverProps) { | ||
const shouldShowReceiver = | ||
originalText !== invoice && | ||
originalText.toLowerCase().replace("lightning:", "").includes("@"); | ||
|
||
if (!shouldShowReceiver) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<View className="flex flex-col gap-2"> | ||
<Text className="text-muted-foreground text-center font-semibold2"> | ||
To | ||
</Text> | ||
<Text className="text-center text-foreground text-2xl font-medium2"> | ||
{originalText.toLowerCase().replace("lightning:", "")} | ||
</Text> | ||
</View> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,38 +1,87 @@ | ||
import * as Linking from "expo-linking"; | ||
import { getInitialURL } from "expo-linking"; | ||
import { router, useRootNavigationState } from "expo-router"; | ||
import React from "react"; | ||
import { useEffect, useCallback, useRef } from "react"; | ||
|
||
const SUPPORTED_SCHEMES = ["lightning:", "bitcoin:", "alby:"]; | ||
// TESTING: ["lightning:", "bitcoin:", "alby:", "exp:"] | ||
const SUPPORTED_SCHEMES = ["lightning", "bitcoin", "alby"]; | ||
|
||
// Register exp scheme for testing during development | ||
// https://docs.expo.dev/guides/linking/#creating-urls | ||
if (process.env.NODE_ENV === "development") { | ||
SUPPORTED_SCHEMES.push("exp"); | ||
} | ||
|
||
export function useHandleLinking() { | ||
const rootNavigationState = useRootNavigationState(); | ||
let url = Linking.useURL(); | ||
let hasNavigationState = !!rootNavigationState?.key; | ||
const navigationState = useRootNavigationState(); | ||
const pendingLinkRef = useRef<string | null>(null); | ||
|
||
React.useEffect(() => { | ||
if (!hasNavigationState) { | ||
return; | ||
} | ||
console.log("Received linking URL", url); | ||
const handleLink = useCallback( | ||
(url: string) => { | ||
if (!url) return; | ||
|
||
const { hostname, path, queryParams, scheme } = Linking.parse(url); | ||
|
||
for (const scheme of SUPPORTED_SCHEMES) { | ||
if (url?.startsWith(scheme)) { | ||
console.log("Linking URL matched scheme", url, scheme); | ||
if (url.startsWith(scheme + "//")) { | ||
url = url.replace(scheme + "//", scheme); | ||
if (!scheme) return; | ||
|
||
if (SUPPORTED_SCHEMES.indexOf(scheme) > -1) { | ||
let fullUrl = scheme === "exp" ? path : `${scheme}:${hostname}`; | ||
|
||
// Add query parameters to the URL if they exist | ||
if (queryParams && Object.keys(queryParams).length > 0) { | ||
const queryString = new URLSearchParams( | ||
queryParams as Record<string, string>, | ||
).toString(); | ||
fullUrl += `?${queryString}`; | ||
} | ||
|
||
// TODO: it should not always navigate to send, | ||
// but that's the only linking functionality supported right now | ||
router.dismissAll(); | ||
router.navigate({ | ||
if (router.canDismiss()) { | ||
router.dismissAll(); | ||
} | ||
router.push({ | ||
pathname: "/send", | ||
params: { | ||
url, | ||
url: fullUrl, | ||
}, | ||
}); | ||
break; | ||
return; | ||
} | ||
|
||
// Redirect the user to the home screen | ||
// if no match was found | ||
router.replace({ | ||
pathname: "/", | ||
}); | ||
}, | ||
[navigationState?.key], | ||
); | ||
|
||
useEffect(() => { | ||
const processInitialURL = async () => { | ||
const url = await getInitialURL(); | ||
if (url) pendingLinkRef.current = url; | ||
}; | ||
|
||
processInitialURL(); | ||
|
||
const subscription = Linking.addEventListener( | ||
"url", | ||
(event: { url: string }) => { | ||
if (navigationState?.key) { | ||
handleLink(event.url); | ||
} else { | ||
pendingLinkRef.current = event.url; | ||
} | ||
}, | ||
); | ||
|
||
return () => subscription.remove(); | ||
}, [handleLink]); | ||
|
||
useEffect(() => { | ||
if (navigationState?.key && pendingLinkRef.current) { | ||
handleLink(pendingLinkRef.current); | ||
pendingLinkRef.current = null; | ||
} | ||
}, [url, hasNavigationState]); | ||
}, [navigationState?.key, handleLink]); | ||
} |
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
Oops, something went wrong.