aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/parse.js
blob: e503a72358d611ed6e7edae73e98f61ef39ddaf1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// import bolt11 from 'bolt11';
import validate from 'bitcoin-address-validation';
import bip21 from 'bip21';
import { get } from '$lib/utils';
import { goto } from '$app/navigation';

let debounce;
export default async (text) => {
	if (!text) return;
	console.log('parsing');

	// lightning
	if (text.startsWith('ln')) {
		try {
			console.log('lightning');
		} catch (e) {}
	}

	// bitcoin
	if (validate(text)) {
		console.log('bitcoin');
		goto(`/send/bitcoin/${text}`);
	}

	// ln address
	if (text.includes('@') && text.includes('.')) {
		console.log('ln address');
		let [name, domain] = text.split('@');
		try {
			clearTimeout(debounce);
			await new Promise((r) => (debounce = setTimeout(r, 1500)));
			let lnurl = await get(`/encode?domain=${domain}&name=${name}`);
			console.log('lnurl', lnurl);
		} catch (e) {}
	}

	// user
	console.log('username');
};