aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-19 10:51:07 -0700
committerAdam Soltys <[email protected]>2024-08-19 10:51:07 -0700
commitea5b11fed877895884ae5d6471a8daa47dbc1b36 (patch)
tree997c67995e13d1d3f0c5283d65834249e6ca57ad /src/routes/(app)
parent1fe91e3275423311a0ef87444bac2a82735bc671 (diff)
downloadcoinos-ui-ea5b11fed877895884ae5d6471a8daa47dbc1b36.tar.gz
coinos-ui-ea5b11fed877895884ae5d6471a8daa47dbc1b36.zip
rm voucher page
Diffstat (limited to 'src/routes/(app)')
-rw-r--r--src/routes/(app)/voucher/+page.svelte90
1 files changed, 0 insertions, 90 deletions
diff --git a/src/routes/(app)/voucher/+page.svelte b/src/routes/(app)/voucher/+page.svelte
deleted file mode 100644
index 5e21b3be..00000000
--- a/src/routes/(app)/voucher/+page.svelte
+++ /dev/null
@@ -1,90 +0,0 @@
-<script>
- import { page } from "$app/stores";
- import { fly } from "svelte/transition";
- import { enhance } from "$app/forms";
- import { tick } from "svelte";
- import { browser } from "$app/environment";
- import { t } from "$lib/translations";
- import AppHeader from "$comp/AppHeader.svelte";
- import Avatar from "$comp/Avatar.svelte";
- import Icon from "$comp/Icon.svelte";
- import Spinner from "$comp/Spinner.svelte";
- import { back, fail, focus } from "$lib/utils";
-
- export let data;
- export let form;
- data.subject = data.user;
-
- let el, text, pasted, w;
-
- let keypress = (e) => e.key === "Enter" && (e.preventDefault() || el.click());
-
- let paste = async () => {
- text = await navigator.clipboard.readText();
- };
-
- $: if (browser && pasted && text) el.click() && (pasted = false);
-</script>
-
-<svelte:window bind:innerWidth={w} />
-
-<AppHeader {data} />
-<div class="container px-4 max-w-lg mx-auto space-y-5 mt-20">
- <h1 class="px-3 md:px-0 text-center text-3xl md:text-4xl font-semibold">
- {$t("payments.voucher")}
- </h1>
-
- <form method="POST" use:enhance class="space-y-2 text-xl">
- {#if form?.error}
- <div class="mb-5">
- <div class="text-red-600">
- {form.error === "default"
- ? $t("error.unrecognizedInput")
- : form.error}
- </div>
- </div>
- {/if}
-
- <div class="mb-2">
- <textarea
- use:focus
- name="text"
- placeholder={$t("payments.voucherText")}
- on:keypress={keypress}
- class="w-full p-4 border rounded-xl h-48 text-xl"
- bind:value={text}
- on:paste={() => (pasted = true)}
- autocapitalize="none"
- />
- </div>
-
- <div class="flex gap-2">
- <a href="/scan" class="w-full">
- <button
- type="button"
- class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full bg-primary justify-center"
- >
- <Icon icon="camera" style="mr-2 w-6 my-auto" />
- <div class="my-auto">{$t("user.send.scan")}</div>
- </button>
- </a>
-
- <button
- type="button"
- class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full bg-primary justify-center"
- on:click={paste}
- >
- <Icon icon="paste" style="mr-2 w-6 my-auto" />
- <div class="my-auto">{$t("user.send.paste")}</div>
- </button>
- </div>
-
- <button
- bind:this={el}
- type="submit"
- class="bg-black text-white border rounded-2xl px-6 py-5 w-full font-bold"
- >
- {$t("user.send.next")}
- </button>
- </form>
-</div>
href='/coinos-server.git/commit/lib/invoices.js?h=cashreq&id=692315c0d4259a274322ca579a7b6118d033bf7a'>692315c0 ^
db38e8f3 ^

692315c0 ^

3aa200db ^

48fd5545 ^
3aa200db ^
10e93dc5 ^
b67ca07b ^
a89b891a ^
3aa200db ^
692315c0 ^
3aa200db ^
692315c0 ^




db38e8f3 ^
692315c0 ^




692315c0 ^
5955ff69 ^
692315c0 ^
ea794b2a ^
db38e8f3 ^
a7322928 ^
692315c0 ^
a650cf9a ^
ea794b2a ^

6610eae3 ^
4b5c6dde ^
ea794b2a ^
692315c0 ^
ea794b2a ^
4b5c6dde ^
b67ca07b ^
692315c0 ^

a89b891a ^
692315c0 ^
db38e8f3 ^


692315c0 ^


204cf9ed ^

db38e8f3 ^
204cf9ed ^
692315c0 ^
204cf9ed ^

692315c0 ^



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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101



                                    
                                                        





                                      
                                                                  

             
           
         






               
           
              
 
                                 
                              
 

                                                         
                                       
 

                                          
                                                      

                                         

                

                                 

                                                         
                
                              
                                          
                         
              
       
 
                    




                                       
              




                              
           
                        
             
         
       
         
         
               

                
           
           
         
        
         
                 
            

    
                                                                                   
 


                                            


                                                   

                                         
                              
                                                
 

                                                                



                 
import store from "$lib/store";
import { l } from "$lib/logging";
import { emit } from "$lib/sockets";
import { db, g, s } from "$lib/db";
import { getUser, bip21, fail, SATS } from "$lib/utils";
import { types } from "$lib/payments";
import { v4 } from "uuid";

import bc from "$lib/bitcoin";
import ln from "$lib/ln";

export let generate = async ({ invoice, user, sender, memo }) => {
  let {
    currency,
    expiry,
    fiat,
    tip,
    amount,
    rate,
    request_id,
    prompt,
    type,
    webhook,
    secret,
  } = invoice;

  amount = parseInt(amount || 0);
  tip = parseInt(tip) || null;

  if (user) user = await getUser(user.username);
  else if (sender) user = await getUser(sender.username);
  if (!user) fail("user not provided");

  if (!currency) currency = user.currency;
  if (!rate) rate = store.rates[currency];
  if (fiat) amount = Math.round((SATS * fiat) / rate);
  if (amount < 0) fail("invalid amount");

  let id = v4();

  let hash, text;
  if (type === types.lightning) {
    let r = await ln.invoice({
      amount_msat: amount ? `${amount + tip}sat` : "any",
      label: id,
      description: memo || "",
      expiry: expiry || 60 * 60 * 24 * 30,
      deschashonly: true,
      cltv: 19
    });

    hash = r.bolt11;
    text = r.bolt11;
  } else if (type === types.bitcoin) {
    hash = await bc.getNewAddress();
    text = bip21(hash, invoice);
  } else if (type === types.internal) {
    hash = id;
  } else {
    fail("unrecognized type");
  }

  invoice = {
    amount,
    created: Date.now(),
    currency,
    hash,
    id,
    memo,
    rate,
    pending: 0,
    received: 0,
    request_id,
    prompt,
    secret,
    text,
    tip,
    type,
    uid: user.id,
    webhook,
  };

  if (!user.username === 'lightningins') l(type, "invoice", user.username, amount);

  await s(`invoice:${hash}`, id);
  await s(`invoice:${id}`, invoice);
  await db.lPush(`${user.id}:invoices`, id);

  if (request_id) {
    let request = await g(`request:${request_id}`);
    if (request) {
      let { invoice_id: prev } = request;
      request.invoice_id = id;
      await s(`request:${request_id}`, request);

      if (!prev) emit(request.requester_id, "invoice", invoice);
    }
  }

  return invoice;
};