aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/SignIn.vue
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-09-08 14:29:03 -0700
committerAdam Soltys <[email protected]>2022-09-08 14:29:03 -0700
commit07d4d426f67e2a97162062c1803fb2a333c5cb24 (patch)
tree7122191e8b83b29465927ac15bad9be84b34915a /src/components/SignIn.vue
parent42e811cc4bdba99fa8cd40385ed6aed67521d643 (diff)
downloadcoinos-server-07d4d426f67e2a97162062c1803fb2a333c5cb24.tar.gz
coinos-server-07d4d426f67e2a97162062c1803fb2a333c5cb24.zip
remove pm2
Diffstat (limited to 'src/components/SignIn.vue')
0 files changed, 0 insertions, 0 deletions
ce/[id]/tip/+page.svelte?h=nip17dm-fixes&id=d694907f1f6706694a9a159ef68c14456664c17e'>^
b1ad1273 ^
916f331e ^
50b270db ^
7bd39ca6 ^




264f76bf ^
7bd39ca6 ^


























7bd39ca6 ^




264f76bf ^
7bd39ca6 ^









7bd39ca6 ^


7da52f0c ^
7bd39ca6 ^

f5eaf3ea ^
f7d9ec75 ^
7bd39ca6 ^













4abcb74a ^

7bd39ca6 ^


f5eaf3ea ^
f7d9ec75 ^
7bd39ca6 ^



7da52f0c ^
7bd39ca6 ^




7da52f0c ^
b51467da ^
7da52f0c ^
7bd39ca6 ^

7bd39ca6 ^




7331eb11 ^
7782f0c2 ^
7bd39ca6 ^

7bd39ca6 ^




048766bc ^
7bd39ca6 ^
f7d9ec75 ^
f5eaf3ea ^

7331eb11 ^
7bd39ca6 ^




50b270db ^
7bd39ca6 ^
2af4a989 ^
7bd39ca6 ^
8d90bfd0 ^
7bd39ca6 ^
8d90bfd0 ^

7bd39ca6 ^

2af4a989 ^


7bd39ca6 ^




8d90bfd0 ^

7bd39ca6 ^





7bd39ca6 ^





8d90bfd0 ^
7bd39ca6 ^




















cf29dcc0 ^
7bd39ca6 ^













7bd39ca6 ^


8d90bfd0 ^



7bd39ca6 ^
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
        
                                         
                                                   
                                                             
                                                                                      
                                             




                                               
                                                       


























                                                                                            




                                                        
                                      









                                                                  


                         
                                                

                       
                     
                     













                                            

                            


                                         
                             
                             



                                 
                                          




                                                  
                                                         
                                                                             
 

                                                         




                                                                        
 
                                              

         




                                                                        
                                                                        
                                                                   
                                                                

                                                                
                                                                                     




                                                                                    
                                                                               
 
                                                       
                                     
                                                           
                                                                         

                                                                                                            

                                      


                                                                                      




                                      

                                                                                                              





                                                                                         





                                                                                                              
                                                                                                                




















                                                                                                         
                                                 













                                                                                                                                    


                                             



                                                                                                                             
        
<script>
	import { onMount } from 'svelte';
	import { browser } from '$app/environment';
	import { invoice as inv, request } from '$lib/store';
	import { copy, focus, f, sat, get, reverseFormat, s, sats } from '$lib/utils';
	import { Icon, Slider } from '$comp';
	import { goto } from '$app/navigation';
	import { t } from '$lib/translations';
	import { enhance } from '$app/forms';
	import { tick } from 'svelte';

	const tipAmounts = ['No', '10%', '15%', '20%'];
	let showCustomAmount;

	let customInput;
	let customTipAmount;

	let apply = async () => {
		if (customTipAmount > 0) {
			tipPercent = (customTipAmount / amountFiat) * 100;
			showCustomAmount = false;
		}
	};

	let active = (amount) =>
		!customTipAmount && Math.round(tipPercent) === parseInt(amount.slice(0, 2));

	const handleCustomTipAmount = (e) => {
		tipPercent = 0;
		customTipAmount = e.target.value;
	};

	let timeout;
	const handleSlide = (e) => {
		customTipAmount = '';
		if (customInput) {
			customInput.value = '';
		}
		tipPercent = e.target.value;
	};

	let submitting;
	const handleTipButtonClick = async (amount) => {
		submitting = true;
		if (amount === 'No') {
			tipPercent = 0;
		} else {
			tipPercent = parseInt(amount.slice(0, 2));
		}

		await tick();
		submit.click();
	};

	let submit;

	export let data;
	$: refresh(data);
	let { invoice, id, user, rates } = data;
	let {
		amount,
		hash,
		type,
		rate,
		received,
		prompt,
		text,
		tip,
		user: { username, currency }
	} = invoice;

	let qr;
	let tipPercent = 0;

	let fullscreen;

	let refresh = (data) => {
		$inv = null;

		({ invoice, id } = data);
		({
			amount,
			hash,
			type,
			received,
			prompt,
			text,
			tip,
			user: { username }
		} = invoice);

		tipPercent = (tip / amount) * 100;
	};

	$: currency = user?.currency || invoice.currency;
	$: rate = invoice.rate * (rates[currency] / rates[invoice.currency]);

	$: tip = Math.round((amount / 100) * tipPercent);

	$: amountFiat = parseFloat(((amount * rate) / sats).toFixed(2));

	$: tipAmount = ((tip * rate) / sats).toFixed(2);

	$: invoiceAmountFiatFormatted = f(amountFiat, currency);

	onMount(() => ($request = undefined));
</script>

<div class="container px-4 max-w-lg text-center mx-auto">
	<form method="POST" use:enhance class:invisible={submitting}>
		<input type="hidden" name="amount" value={amount} />
		<input type="hidden" name="tip" value={tip} />
		<input type="hidden" name="username" value={username} />
		<input type="hidden" name="rate" value={invoice.rate} />
		<input type="hidden" name="prompt" value="false" />
		<input type="hidden" name="type" value={type} />
		<input type="hidden" name="hash" value={hash} />

		<input type="hidden" name="request_id" value={invoice.request?.id} />

		<h1 class="text-4xl font-semibold my-8">{$t('invoice.addTipq')}</h1>
		{#if !showCustomAmount}
			<div class="my-2 text-xl">{Math.round(tipPercent)}%</div>

			<Slider handle={handleSlide} bind:value={tipPercent} />

			<div class="flex mb-8 text-lg">
				<div>
					<span class="mr-1">
						{f(amountFiat, currency)}
						<span class="font-semibold">+{f(tipAmount, currency)}</span>
					</span>
				</div>

				<div class="ml-auto text-lg">
					{sat(amount)}
					<span class="font-semibold">+{sat(tip)}</span>
				</div>
			</div>

			{#if tip}
				<div>
					<button type="button" on:click={() => submit.click()}>Next</button>
					<button type="button" on:click={() => (tipPercent = 0)}>Reset</button>
				</div>
			{:else}
				{#each tipAmounts as amount}
					<button
						type="button"
						class:active={active(amount, tipPercent)}
						on:click={() => handleTipButtonClick(amount)}>{amount}</button
					>
				{/each}
			{/if}

			<div>
				<button type="button" on:click={() => (showCustomAmount = true)}>Custom</button>
			</div>
		{/if}

		<button type="submit" bind:this={submit} />
	</form>

	{#if showCustomAmount}
		<form on:submit|preventDefault={apply}>
			<div class="relative">
				<span
					class="absolute top-[18px] left-5 font-semibold {!customTipAmount
						? 'opacity-50'
						: 'opacity-100'}">$</span
				>
				<input
					bind:this={customInput}
					type="number"
					step="0.01"
					on:input={(e) => handleCustomTipAmount(e)}
					class="pl-10"
					placeholder="Custom amount"
					use:focus
				/>
				<button
					type="submit"
					class="w-full mt-2 bg-black text-white font-semibold py-3 px-7 rounded-2xl {!customTipAmount
						? 'opacity-50'
						: 'opacity-100 hover:opacity-80'}"
					disabled={!customTipAmount}>Apply</button
				>
			</div>
		</form>
	{/if}
</div>

<style>
	.active {
		@apply !bg-black !text-white;
	}

	.container button[type='button'] {
		@apply w-full mt-2 bg-primary text-black hover:bg-black hover:text-white font-semibold py-5 px-7 rounded-2xl;
	}
</style>