diff --git a/package.json b/package.json index 0040bd5a..b44fe8c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "browser-app", - "version": "1.3.0-0.2.0", + "version": "1.3.0-0.3.0", "scripts": { "dev": "vite dev", "dev-http": "vite dev --mode http", diff --git a/src/lib/utils.ts b/src/lib/utils.ts index bbbf47d2..35d18290 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -330,7 +330,10 @@ export async function getBitcoinExchangeRate(): Promise {} export function isPWA(): boolean { - return window.matchMedia('(display-mode: standalone)').matches + return ( + window.matchMedia('(display-mode: standalone)').matches || + window.matchMedia('(display-mode: fullscreen)').matches + ) } export function parseNodeAddress(address: string): ParsedNodeAddress { diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index db441f5f..c0c54a0b 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,7 +2,7 @@ import { fade } from 'svelte/transition' import { translate } from '$lib/i18n/translations' import { funds$, nodeInfo$, settings$ } from '$lib/streams' - import { calculateBalance } from '$lib/utils' + import { calculateBalance, isPWA, logger } from '$lib/utils' import Spinner from '$lib/elements/Spinner.svelte' import Value from '$lib/components/Value.svelte' import { convertValue } from '$lib/conversion' @@ -11,6 +11,7 @@ import ClamsLogo from '$lib/icons/ClamsLogo.svelte' import arrow from '$lib/icons/arrow' import qr from '$lib/icons/qr' + import { browser } from '$app/environment' const buttons = [ { key: 'send', icon: arrow, styles: 'rotate-180' }, @@ -35,6 +36,15 @@ from: BitcoinDenomination.msats, to: $settings$.secondaryDenomination }) + + if (browser && !isPWA()) { + try { + logger.info('Attemptin to register protocol handler') + navigator.registerProtocolHandler('bitcoin', '/send?destination=%s') + } catch (error) { + logger.warn('Could not register bitcoin protocol handler') + } + } diff --git a/src/routes/send/+page.svelte b/src/routes/send/+page.svelte index c141b89c..efc9bbc0 100644 --- a/src/routes/send/+page.svelte +++ b/src/routes/send/+page.svelte @@ -13,10 +13,12 @@ import { translate } from '$lib/i18n/translations' import lightning from '$lib/lightning' import { createRandomHex, splitDestination } from '$lib/utils' + import type { PageData } from './$types' + + export let data: PageData let previousSlide = 0 let slide = 0 - let errorMsg = '' function next() { @@ -46,8 +48,8 @@ } const sendPayment$ = new SvelteSubject({ - destination: '', - type: null, + destination: data.destination || '', + type: data.type || null, description: '', expiry: null, timestamp: null, diff --git a/src/routes/send/+page.ts b/src/routes/send/+page.ts new file mode 100644 index 00000000..dddbce3c --- /dev/null +++ b/src/routes/send/+page.ts @@ -0,0 +1,20 @@ +import { getPaymentType, splitDestination } from '$lib/utils' +import type { PageLoad } from './$types' + +export const load: PageLoad = async ({ url }) => { + const destination = url.searchParams.get('destination') + + if (destination) { + const strippedDestination = destination.includes('//') + ? destination.replace('//', '') + : destination + + const [prefix, formattedDestination] = splitDestination(strippedDestination) + const type = getPaymentType(prefix, formattedDestination) + + return { + destination: formattedDestination, + type + } + } +} diff --git a/static/manifest.webmanifest b/static/manifest.webmanifest index b71bad80..f85fbb72 100644 --- a/static/manifest.webmanifest +++ b/static/manifest.webmanifest @@ -24,5 +24,22 @@ } ], "theme_color": "#6305f0", - "background_color": "#fafafa" + "background_color": "#fafafa", + "protocol_handlers": [ + { + "name": "Clams", + "protocol": "bitcoin", + "url": "/send?destination=%s" + }, + { + "name": "Clams", + "protocol": "web+lightning", + "url": "/send?destination=%s" + }, + { + "name": "Clams", + "protocol": "web+lnurl", + "url": "/send?destination=%s" + } + ] }