diff options
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/[username]/dashboard.svelte | 49 | ||||
| -rw-r--r-- | src/routes/withdraw.js | 10 |
2 files changed, 51 insertions, 8 deletions
diff --git a/src/routes/[username]/dashboard.svelte b/src/routes/[username]/dashboard.svelte index 11295728..7fab2125 100644 --- a/src/routes/[username]/dashboard.svelte +++ b/src/routes/[username]/dashboard.svelte @@ -1,7 +1,29 @@ <script> + import { post, failure } from '$lib/utils'; + import { tick } from 'svelte'; import { AppHeader } from '$comp'; import { rate, user, preferredCurrency } from '$lib/store'; + let payreq = '', + payreqField, + withdrawing; + + let toggle = async () => { + withdrawing = !withdrawing; + await tick(); + if (withdrawing) payreqField.focus(); + }; + + let withdraw = async () => { + try { + await post('/withdraw', { payreq }); + withdrawing = false; + } catch (e) { + console.log(e); + failure("Withdrawal failed, please contact support."); + } + }; + $: btcPrice = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' @@ -18,7 +40,7 @@ $user.account.balance ); - $: feeAmount = new Intl.NumberFormat('en-US', { + $: feepayreq = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(($user.account.balance * ($rate / 100000000)) / 100); @@ -55,14 +77,25 @@ >{$rate ? accountBalanceFiat : 'fetching rate...'}</span > - <span class="text-secondary text-xl block" - >{accountBalanceSats} SATS - </span> + <span class="text-secondary text-xl block">{accountBalanceSats} SATS </span> + + <button class="rounded-full border py-2 font-bold w-28 mt-4" on:click={toggle} + >Withdraw</button + > + <p class="text-secondary mt-2">You will be charged a 1% withdrawal fee on the payreq.</p> - <button class="rounded-full border py-2 font-bold w-28 mt-4">Withdraw</button> - <p class="text-secondary mt-2"> - You will be charged a 1% withdrawal fee on the amount. - </p> + {#if withdrawing} + <input + bind:this={payreqField} + type="text" + name="payreq" + bind:value={payreq} + class="block border rounded-xl p-3 w-full" + /> + <button class="rounded-full border py-2 font-bold w-28 mt-4" on:click={withdraw} + >Submit</button + > + {/if} </div> </div> {/if} diff --git a/src/routes/withdraw.js b/src/routes/withdraw.js new file mode 100644 index 00000000..aaed2250 --- /dev/null +++ b/src/routes/withdraw.js @@ -0,0 +1,10 @@ +import { post } from '$lib/utils'; +export async function POST({ locals, request }) { + let { token } = locals; + let body = await request.json(); + console.log(body) + body = await post('/lightning/send', body, { + authorization: `Bearer ${token}` + }); + return { body }; +} |
