diff options
| author | Adam Soltys <[email protected]> | 2023-03-21 11:55:58 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-03-21 11:55:58 -0700 |
| commit | d3db47e4e32adb9da6f56420cf7acb7448f9099c (patch) | |
| tree | 3c6be386ce2250b0ce16585ba94f115ad0f30915 | |
| parent | 067054f780e2f6f8acd9c950cbc2227783f6208b (diff) | |
| download | coinos-ui-send-fiat.tar.gz coinos-ui-send-fiat.zip | |
wipsend-fiat
3 files changed, 33 insertions, 14 deletions
diff --git a/src/routes/(app)/[username]/invoice/[hash]/+layout.server.js b/src/routes/(app)/[username]/invoice/[hash]/+layout.server.js index 7cf87e14..df22400a 100644 --- a/src/routes/(app)/[username]/invoice/[hash]/+layout.server.js +++ b/src/routes/(app)/[username]/invoice/[hash]/+layout.server.js @@ -9,6 +9,8 @@ export async function load({ depends, params, url, parent }) { let { hash } = params; let invoice = await get(`/invoice/${hash}`); + console.log("HI", invoice) + if (user && invoice.uid !== user.id && !url.pathname.includes('tip')) throw redirect(307, `/send/invoice/${hash}`); diff --git a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js index c63328e2..a2ce4e04 100644 --- a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js +++ b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js @@ -3,10 +3,11 @@ import { fd, auth, get, post } from '$lib/utils'; export async function load({ params, parent }) { let { user } = await parent(); - let { amount } = params; + let [amount, currency] = params.amount.split('/'); + let subject = await get(`/users/${params.username}`); if (subject.username === user?.username) throw error(500, { message: 'Cannot send to self' }); - return { amount, subject }; + return { amount, currency, subject }; } export const actions = { diff --git a/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte b/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte index af6a6368..ea59ffed 100644 --- a/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte @@ -1,7 +1,7 @@ <script> import { t } from '$lib/translations'; import { goto } from '$app/navigation'; - import { pin, selectedRate } from '$lib/store'; + import { pin, selectedRate, rate as huh } from '$lib/store'; import { enhance } from '$app/forms'; import { AppHeader, Avatar, Icon, Numpad, Spinner } from '$comp'; import { page } from '$app/stores'; @@ -11,25 +11,17 @@ export let form; let { subject, rates, user } = data; - let currency = user?.currency || 'USD'; - - let amount = form?.amount || data.amount; - let a, - af, - fiat = !amount, - hash, - rate, - amountFiat = 0; - - selectedRate.subscribe((r) => rate || (amountFiat = amount * (r / sats))); + let currency = data.currency || user?.currency || 'USD'; let setAmount = async () => { + try { amount = a; amountFiat = parseFloat(af).toFixed(2); rate = fiat ? (sats * amountFiat) / amount : $selectedRate; ({ hash } = await post(`/${subject.username}/invoice`, { invoice: { amount, + currency, hash: 'internal', rate: rates[subject.currency], prompt: subject.prompt, @@ -39,8 +31,30 @@ })); goto(`/${subject.username}/invoice/${hash}`); + } catch(e) { + console.log(e) + } }; + let amount = form?.amount || (!data.currency && data.amount) || 0; + let a = amount, + af = data.currency ? data.amount : undefined, + fiat = data.currency || !amount, + hash, + rate, + amountFiat = 0; + + selectedRate.subscribe((r) => { + if (rate) return; + if (data.currency) { + a = Math.round((af / r) * sats); + } else { + af = amount * (r / sats); + } + + setAmount(); + }); + let loading; let submit = () => (loading = true); @@ -60,6 +74,8 @@ {/if} <div class="container px-4 mt-20 max-w-xl mx-auto space-y-8"> + {af}<br /> + {a} <Numpad bind:amount={a} bind:amountFiat={af} {currency} bind:fiat /> <form method="POST" use:enhance on:submit={submit}> |
