aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/invoice.ts7
-rw-r--r--src/lib/store.ts1
-rw-r--r--src/lib/utils.ts41
3 files changed, 43 insertions, 6 deletions
diff --git a/src/lib/invoice.ts b/src/lib/invoice.ts
index 3c885346..0ab0a9af 100644
--- a/src/lib/invoice.ts
+++ b/src/lib/invoice.ts
@@ -1,13 +1,14 @@
-import { auth, get, post } from "$lib/utils";
+import { auth, get, post, setAccount } from "$lib/utils";
import { redirect } from "@sveltejs/kit";
-export default async ({ cookies, request }) => {
+export default async ({ cookies, request, url }) => {
let form = await request.formData();
let rates = await get("/rates");
let amount = parseInt(form.get("amount"));
let invoice = {
+ account,
amount,
items: JSON.parse(form.get("items")),
memo: form.get("memo"),
@@ -16,7 +17,7 @@ export default async ({ cookies, request }) => {
type: form.get("type"),
prompt: form.get("prompt") === "true",
rate: parseFloat(form.get("rate")) || rates[form.get("currency")],
- id: undefined
+ id: undefined,
};
let user = { username: form.get("username"), currency: form.get("currency") };
diff --git a/src/lib/store.ts b/src/lib/store.ts
index 3c1ff321..42b41127 100644
--- a/src/lib/store.ts
+++ b/src/lib/store.ts
@@ -38,6 +38,7 @@ let persistLocal = (key, defaultValue: any = undefined) => {
return s;
};
+export let account = writable();
export let amountPrompt = persistLocal("amountPrompt");
export let avatar = writable();
export let banner = writable();
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index 69e0f949..c20a7d29 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -1,7 +1,7 @@
import { browser } from "$app/environment";
import { toast } from "@zerodevx/svelte-toast";
import { goto } from "$app/navigation";
-import { PUBLIC_COINOS_URL } from "$env/static/public";
+import { PUBLIC_COINOS_NETWORK, PUBLIC_COINOS_URL } from "$env/static/public";
import { page } from "$app/stores";
import { get as getStore } from "svelte/store";
@@ -41,7 +41,11 @@ export let get = (url: string, headers = {}) => {
});
};
-export let post = async (url: string, body: object, headers: HeadersInit | undefined = undefined) => {
+export let post = async (
+ url: string,
+ body: object,
+ headers: HeadersInit | undefined = undefined
+) => {
headers = {
"content-type": "application/json",
accept: "application/json",
@@ -242,7 +246,11 @@ export let select = (el: HTMLInputElement): any =>
export let sleep = (n: number): Promise<void> =>
new Promise((r) => setTimeout(r, n));
-export let wait = async (f: () => boolean | Promise<boolean>, n: number = 100, s: number = 300): Promise<boolean> => {
+export let wait = async (
+ f: () => boolean | Promise<boolean>,
+ n: number = 100,
+ s: number = 300
+): Promise<boolean> => {
let i = 0;
while (!(await f()) && i < s) {
await sleep(n);
@@ -327,3 +335,30 @@ export function setCookie(name: string, value: string, seconds: number): void {
const expires = "expires=" + now.toUTCString();
document.cookie = name + "=" + value + ";" + expires + ";path=/";
}
+
+export let network = {
+ bitcoin: {
+ bech32: "bc",
+ pubKeyHash: 0x00,
+ scriptHash: 0x05,
+ wif: 0x80,
+ },
+ regtest: {
+ bech32: "bcrt",
+ pubKeyHash: 0x6f,
+ scriptHash: 0xc4,
+ wif: 0xef,
+ },
+}[PUBLIC_COINOS_NETWORK];
+
+export let versions = {
+ bitcoin: {
+ private: 0x0488ade4,
+ public: 0x0488b21e,
+ },
+ regtest: {
+ private: 0x04358394,
+ public: 0x043587cf,
+ },
+}[PUBLIC_COINOS_NETWORK];
+