Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.3.0-0.3.0: Feature - URL Protocol Handlers #101

Merged
merged 3 commits into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4.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"
}
]
}