aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Amount.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/Amount.svelte')
0 files changed, 0 insertions, 0 deletions
>
542c24b1 ^
32fcc461 ^
1f63848c ^




542c24b1 ^
f99bd15f ^
1f63848c ^






6ec41bac ^
1f63848c ^
6ec41bac ^
1f63848c ^







6ec41bac ^

1f63848c ^
542c24b1 ^
1f63848c ^
1f63848c ^


1f63848c ^
1f63848c ^
542c24b1 ^


1f63848c ^
542c24b1 ^




1f63848c ^
32fcc461 ^
1f63848c ^
1f63848c ^
6ec41bac ^
1f63848c ^

1f63848c ^




6ec41bac ^
1f63848c ^










1f63848c ^
542c24b1 ^

542c24b1 ^



32fcc461 ^
6ec41bac ^








































1f63848c ^

002cd913 ^


1f63848c ^

542c24b1 ^
1f63848c ^




6ec41bac ^







1f63848c ^

af280fa3 ^








1f63848c ^
f99bd15f ^
1f63848c ^

acc3dee4 ^
1f63848c ^



542c24b1 ^

1f63848c ^

6ec41bac ^






002cd913 ^



af280fa3 ^
002cd913 ^



1f63848c ^

542c24b1 ^




f99bd15f ^

542c24b1 ^



f99bd15f ^
542c24b1 ^









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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
        
                                             
                                     
 




                                                        
                                           
                                                         






                                                            
                       
                 
                                              







                                                  

                                
 
                         
                


                        
                                       
 


                          
 




                                                                    
 
                                     
 
                                  
                       

                                        




                           
                                             










                                                      
   

                 



                          
     








































                                                             

         


                                                                                    

                                                                      
                                                     




                                                 







                                                                 

                                                      








                                        
 
                                                                               

                                               
                                                                           



                                              

                                                      

             






                                                              



                                                      
                                                                                            



                              

         




                                                                                     

                           



                                                                                    
                                                                        









                                             
<script>
  import { browser } from "$app/environment";
  import handler from "$lib/handler";

  import { onMount } from "svelte";
  import { applyAction, deserialize } from "$app/forms";
  import { tick } from "svelte";
  import { fly } from "svelte/transition";
  import { enhance } from "$app/forms";
  import Pinpad from "$comp/Pinpad.svelte";
  import PasswordInput from "$comp/PasswordInput.svelte";
  import { focus, fail } from "$lib/utils";
  import { password, pin, loginRedirect } from "$lib/store";
  import { t } from "$lib/translations";
  import { page } from "$app/stores";
  import { generate } from "$lib/nostr";
  import { invalidateAll } from "$app/navigation";

  let nostr = $state();
  onMount(() => {
    if (browser && window.nostr) nostr = true;
    $pin = undefined;
    localStorage.clear();
    sessionStorage.clear();

    let lang = $page.url.searchParams.get("lang");
    if (lang) document.cookie = `lang=${lang} ;`;
  });

  let { data, form } = $props();
  let { id } = $derived(data);

  let token = $state("");
  let code = [];

  $password = undefined;

  let cancel = () => (need2fa = false);

  let username = $state(),
    email,
    btn = $state();

  $effect(() => form && ({ username, password: $password } = form));
  let need2fa = $derived(form?.message === "2fa");
  $effect(() => {
    if (need2fa && form.token === token) token = "";
  });

  let revealPassword = $state(false);

  async function handleSubmit(e) {
    e.preventDefault();
    let data = new FormData(this);
    let user = Object.fromEntries(data);

    for (let k in user) {
      data.set(k, user[k]);
    }

    const response = await fetch("?/login", {
      method: "POST",
      body: data,
    });

    const result = deserialize(await response.text());

    if (result.type === "success") {
      await invalidateAll();
    }

    applyAction(result);
  }

  $effect(() => {
    token?.length === 6 &&
      tick().then(() => {
        btn.click();
      });
  });

  let nostrLogin = async () => {
    let pubkey = await window.nostr.getPublicKey();
    const formData = new FormData();

    let ev = {
      kind: 1,
      pubkey,
      created_at: Date.now(),
      content: id,
      tags: [],
    };

    try {
      let signedEvent = await window.nostr.signEvent(ev);

      formData.append("loginRedirect", redirect);
      formData.append("token", token);
      formData.append("event", JSON.stringify(signedEvent));
      formData.append("id", id);

      let response = await fetch("?/nostr", {
        method: "POST",
        body: formData,
      });

      const result = deserialize(await response.text());

      if (result.type === "success") {
        await invalidateAll();
      }

      applyAction(result);
    } catch (e) {
      fail(e.message);
    }
  };

  let redirect = $derived(
    $loginRedirect || $page.url.searchParams.get("redirect"),
  );
</script>

<div
  class="mx-auto md:shadow-xl rounded-3xl max-w-xl w-full md:w-[480px] md:p-8 mb-20"
>
  <h1 class="text-2xl font-bold text-center">{$t("login.signIn")}</h1>

  {#if form?.error && !form?.message.includes("2fa")}
    <div class="text-red-600 text-center" in:fly>
      {form.error}
    </div>
  {/if}

  <form
    use:enhance
    class="space-y-5"
    onsubmit={handleSubmit}
    method="POST"
    action="?/login"
  >
    <input type="hidden" name="loginRedirect" value={redirect} />
    <input type="hidden" name="token" value={token} />

    <input
      name="username"
      type="text"
      required
      bind:value={username}
      use:focus
      autocapitalize="none"
      placeholder={$t("login.username")}
    />

    <PasswordInput bind:value={$password} placeholder={$t("login.password")} />

    <div class="flex justify-end items-center">
      <a href="/forgot" class="underline underline-offset-4 text-secondary"
        >{$t("login.forgotUserOrPassword")}</a
      >
    </div>

    <button type="submit" class="btn" bind:this={btn}>
      {$t("login.signIn")}
    </button>

    {#if nostr}
      <button type="button" class="btn" onclick={nostrLogin}>
        <img src="/images/nostr.png" class="w-8" />
        <div class="my-auto">{$t("user.settings.nostr")}</div>
      </button>
    {/if}

    <p class="text-secondary text-center font-medium">
      {$t("login.noAccount")}
      <a
        href={"/register"}
        class="block md:inline text-secondary underline underline-offset-4 hover:opacity-80"
      >
        {$t("login.register")}
      </a>
    </p>
  </form>
</div>

{#if need2fa && token.length < 6}
  <div
    class="fixed bg-base-100 bg-opacity-90 inset-0 h-full w-full z-50 cursor-default"
    onclick={(e) => e.stopPropagation()}
    role="dialog"
    aria-labelledby="title"
  >
    <div
      class="mx-auto p-5 border shadow-lg rounded-md bg-base-100 space-y-5 max-w-lg"
    >
      <h1 id="title" class="text-center text-2xl font-semibold">2FA</h1>
      <Pinpad bind:v={token} {cancel} />

      <div class="w-full flex">
        <button class="btn" onclick={cancel}>
          <div class="my-auto">Cancel</div>
        </button>
      </div>
    </div>
  </div>
{/if}