Skip to content

Commit

Permalink
1.3.0-0.3.0: Feature - URL Protocol Handlers (#101)
Browse files Browse the repository at this point in the history
* Add url protocol handlers

* Add register method

* Fix versioning
  • Loading branch information
lnbc1QWFyb24 authored Feb 4, 2023
1 parent 046d396 commit b3accf9
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 4 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ export async function getBitcoinExchangeRate(): Promise<BitcoinExchangeRates | n
export const noop = () => {}

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 {
Expand Down
12 changes: 11 additions & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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' },
Expand All @@ -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')
}
}
</script>

<svelte:head>
Expand Down
8 changes: 5 additions & 3 deletions src/routes/send/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -46,8 +48,8 @@
}
const sendPayment$ = new SvelteSubject<SendPayment>({
destination: '',
type: null,
destination: data.destination || '',
type: data.type || null,
description: '',
expiry: null,
timestamp: null,
Expand Down
20 changes: 20 additions & 0 deletions src/routes/send/+page.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
}
19 changes: 18 additions & 1 deletion static/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}

0 comments on commit b3accf9

Please sign in to comment.