aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-09-29 15:05:13 -0700
committerAdam Soltys <[email protected]>2022-09-29 15:05:13 -0700
commit64911388f80d52d6dd53d707457a37fe386c194e (patch)
treeb96d7c1b85857459d6a91673e5ac6598eed7bd98 /src/lib
parent9e07792fcdd0ba0b7c07a20fe83db54597388e26 (diff)
downloadcoinos-ui-64911388f80d52d6dd53d707457a37fe386c194e.tar.gz
coinos-ui-64911388f80d52d6dd53d707457a37fe386c194e.zip
address parsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/parse.js296
-rw-r--r--src/lib/utils.js4
2 files changed, 35 insertions, 265 deletions
diff --git a/src/lib/parse.js b/src/lib/parse.js
index 2a827956..2abc2cba 100644
--- a/src/lib/parse.js
+++ b/src/lib/parse.js
@@ -1,271 +1,39 @@
-export default (text) => {
+// 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")
- if (text.includes('@') && text.includes('.')) {
- let [name, domain] = text.split('@');
- try {
- clearTimeout(debounce);
- await new Promise((r) => (debounce = setTimeout(r, 1500)));
- ({ data: text } = await Vue.axios.get(
- `/encode?domain=${domain}&name=${name}`
- ));
- } catch (e) {}
+ // lightning
+ if (text.startsWith('ln')) {
+ try {
+ console.log('lightning');
+ } catch (e) {}
}
- try {
- if (text.toLowerCase().slice(0, 10) === 'lightning:')
- text = text.slice(10);
- let payreq = text.toLowerCase();
- payment.payreq = payreq;
- payment.payobj = bolt11.decode(payment.payreq);
- let {
- network: { bech32 },
- } = payment.payobj;
-
- if (!networks.includes('lightning'))
- return commit('error', 'Lightning not supported in this account');
-
- if (bech32 !== process.env.VUE_APP_NETWORK_BECH32) {
- dispatch('clearPayment');
- commit(
- 'error',
- `Wrong network prefix '${bech32}' instead of '${process.env.VUE_APP_NETWORK_BECH32}'`
- );
- throw new Error('Wrong network');
- }
-
- if (user.account.ticker !== 'BTC')
- await dispatch(
- 'shiftAccount',
- user.accounts.find((a) => a.asset === BTC).id
- );
-
- let { tags, satoshis, millisatoshis } = payment.payobj;
- let description = tags.find((t) => t.tagName === 'description');
- if (description) payment.memo = description.data;
- payment.amount = millisatoshis
- ? Math.round(millisatoshis / 1000)
- : satoshis;
- payment.fiatAmount = ((payment.amount * getters.rate) / SATS).toFixed(
- 2
- );
- payment.network = 'lightning';
+ // bitcoin
+ if (validate(text)) {
+ console.log('bitcoin');
+ goto(`/send/bitcoin/${text}`);
+ }
- await Vue.axios.post('/lightning/query', { payreq });
- if (!getters.payment.recipient)
- go({ name: 'send', params: { keep: true } });
+ // 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) {}
+ }
- return;
- } catch (e) {
- if (e.response) commit('error', e.response.data);
- }
- //
- // let url;
- // try {
- // if (nodes.includes('bitcoin')) {
- // url = bip21.decode(text);
- // if (!networks.includes('bitcoin'))
- // return commit('error', 'Bitcoin not supported in this account');
- // payment.network = 'bitcoin';
- // url.options.asset = BTC;
- // }
- // } catch (e) {
- // if (nodes.includes('liquid')) {
- // try {
- // url = bip21.decode(text, 'liquidnetwork');
- // if (!networks.includes('liquid'))
- // return commit('error', 'Liquid not supported in this account');
- // payment.network = 'liquid';
- // } catch (e) {
- // /**/
- // }
- // }
- // }
- //
- // if (url) {
- // let { amount, asset, assetid, message } = url.options;
- // if (assetid) asset = assetid;
- // if (!asset) asset = BTC;
- // let account = user.accounts.find((a) => a.asset === asset);
- // if (account) {
- // if (account.asset !== user.account.asset)
- // await dispatch('shiftAccount', account.id);
- // } else return commit('error', 'Unrecognized asset');
- //
- // payment.address = url.address;
- //
- // if (message) payment.memo = message;
- //
- // if (amount) {
- // payment.amount = parseInt((amount * SATS).toFixed(0));
- // payment.fiatAmount = ((payment.amount * getters.rate) / SATS).toFixed(
- // 2
- // );
- // }
- //
- // await dispatch('isInternal');
- // await dispatch('estimateFee');
- // go({ name: 'send', params: { keep: true } });
- // return;
- // }
- //
- // if (nodes.includes('bitcoin') && validate(text)) {
- // if (!networks.includes('bitcoin'))
- // return commit('error', 'Bitcoin not supported in this account');
- // payment.address = text;
- // payment.network = 'bitcoin';
- // await dispatch('isInternal');
- // go({ name: 'send', params: { keep: true } });
- // return;
- // }
- //
- // // Liquid
- // if (nodes.includes('liquid') && isLiquid(text)) {
- // if (!networks.includes('liquid'))
- // return commit('error', 'Liquid not supported in this account');
- // payment.address = text;
- // payment.network = 'liquid';
- // await dispatch('isInternal');
- // go({ name: 'send', params: { keep: true } });
- // return;
- // }
- //
- // if (text.startsWith('6P')) {
- // commit('text', text);
- // return go('/decrypt');
- // }
- //
- // try {
- // let ecpair = ECPair.fromWIF(text, {
- // ...this._vm.$network,
- // confidentialPrefix: 1,
- // assetHash: '',
- // });
- // commit('ecpair', ecpair);
- // go('/sweep');
- // } catch (e) {
- // /* */
- // }
- //
- // if (text.toLowerCase().startsWith('lnurl:')) {
- // try {
- // const { data: lnurl } = await Vue.axios.get(`/url?code=${text}`);
- // await dispatch('handleScan', lnurl);
- // return;
- // } catch (e) {
- // commit('error', e.response ? e.response.data : e.message);
- // }
- // }
- //
- // if (text.toLowerCase().includes('lnurl')) {
- // commit('loading', true);
- // let txt = text.toLowerCase().match(/lnurl[a-z0-9]+/);
- //
- // try {
- // const { data: params } = await Vue.axios.get(`/decode?text=${txt}`);
- // if (params.status === 'ERROR') {
- // let { reason } = params;
- // try {
- // ({ reason } = JSON.parse(reason.replace(/.*{/, '{')));
- // } catch {
- // /**/
- // }
- //
- // commit('loading', false);
- // return commit('error', reason);
- // }
- //
- // let { seed } = getters;
- //
- // switch (params.tag) {
- // case 'channelRequest':
- // await dispatch('openChannel', params);
- // break;
- // case 'login':
- // if (!seed) ({ seed } = await dispatch('passwordPrompt'));
- // try {
- // const key = linkingKey(params.domain, seed);
- // const signedMessage = secp256k1.ecdsaSign(
- // hexToUint8Array(params.k1),
- // key.privateKey
- // );
- // const signedMessageDER = secp256k1.signatureExport(
- // signedMessage.signature
- // );
- // const linkingKeyPub = secp256k1.publicKeyCreate(
- // key.privateKey,
- // true
- // );
- // const sig = bytesToHexString(signedMessageDER);
- //
- // const response = await Vue.axios.post('/login', {
- // params,
- // sig,
- // key: bytesToHexString(linkingKeyPub),
- // });
- //
- // if (response.data.status === 'OK') {
- // commit('snack', 'Login success');
- // } else {
- // commit('error', response.status);
- // }
- //
- // go('/home');
- // } catch (e) {
- // commit('error', e.response ? e.response.data : e.message);
- // }
- // break;
- //
- // case 'withdrawRequest':
- // commit('lnurl', params);
- // go('/withdraw');
- // break;
- // case 'payRequest':
- // commit('lnurl', params);
- // go('/pay');
- // break;
- // }
- // } catch (e) {
- // commit('error', e.response ? e.response.data : e.message);
- // }
- //
- // commit('loading', false);
- // }
- //
- // if (isUuid(text)) {
- // try {
- // const { data: payment } = await Vue.axios.post('/checkRedeemCode', {
- // redeemcode: text,
- // });
- //
- // if (payment) {
- // window.location.href = `${window.location.protocol}//${window.location.host}/redeem/${text}`;
- // return;
- // }
- // } catch (e) {
- // commit('error', e.response ? e.response.data : e.message);
- // }
- //
- // try {
- // const { data: invoice } = await Vue.axios.get(
- // `/invoice?uuid=${text}`
- // );
- // await dispatch('handleScan', invoice.text);
- // return;
- // } catch (e) {
- // commit('error', e.response ? e.response.data : e.message);
- // }
- // }
- //
- // if (
- // text.startsWith(
- // `${window.location.protocol}//${window.location.host}/redeem`
- // )
- // ) {
- // window.location.href = text;
- // }
- //
- // commit('stopScanning', true);
- //
- // return 'no';
+ // user
+ console.log("username")
};
diff --git a/src/lib/utils.js b/src/lib/utils.js
index 61e2ddac..514e3adb 100644
--- a/src/lib/utils.js
+++ b/src/lib/utils.js
@@ -146,6 +146,8 @@ export const toggleFullscreen = (el) =>
export const sats = 100000000;
-export const goBack = () => {
+export const back = () => {
browser && history.go(-1);
};
+
+export const focus = (el) => setTimeout(() => el.focus());