diff options
Diffstat (limited to 'src')
9 files changed, 38 insertions, 26 deletions
diff --git a/src/components/Lnurlp.svelte b/src/components/Lnurlp.svelte index ab0c50ce..9918a3f4 100644 --- a/src/components/Lnurlp.svelte +++ b/src/components/Lnurlp.svelte @@ -6,7 +6,9 @@ export let data, form; let { currency } = data.user; - let { minSendable, maxSendable, callback, metadata } = data; + let { minSendable, maxSendable, callback, metadata, rates } = data; + + $: rate = rates[currency]; let amount = Math.round(minSendable / 1000), loading; @@ -33,7 +35,7 @@ </div> {/if} - <Numpad bind:amount {currency} /> + <Numpad bind:amount bind:rate {currency} /> <form action="?/pay" method="POST" use:enhance on:submit={submit}> <input name="amount" value={amount} type="hidden" /> diff --git a/src/components/Lnurlw.svelte b/src/components/Lnurlw.svelte index f2855b53..f780d755 100644 --- a/src/components/Lnurlw.svelte +++ b/src/components/Lnurlw.svelte @@ -7,7 +7,8 @@ export let data, form; let { currency, username } = data.user; - let { defaultDescription, minWithdrawable, maxWithdrawable, k1, callback } = data; + let { defaultDescription, minWithdrawable, maxWithdrawable, k1, callback, rates } = data; + $: rate = rates[currency]; let amount = Math.round(maxWithdrawable / 1000), loading; @@ -28,7 +29,7 @@ </div> {/if} - <Numpad bind:amount {currency} /> + <Numpad bind:amount {currency} bind:rate /> <form action="?/withdraw" method="POST" use:enhance on:submit={submit}> <input name="amount" value={amount} type="hidden" /> diff --git a/src/components/Numpad.svelte b/src/components/Numpad.svelte index 77a4f38b..20bfe561 100644 --- a/src/components/Numpad.svelte +++ b/src/components/Numpad.svelte @@ -7,17 +7,19 @@ export let amount, currency, fiat = !amount, + rate, submit = undefined; export let amountFiat = 0; + let arrow = '<'; $: update(amount, amountFiat); let update = (a, f) => { if (fiat) { - amount = Math.round(f / ($selectedRate / sats)); + amount = Math.round(f / (rate / sats)); } else { - amountFiat = ((a * $selectedRate) / sats).toFixed(2); + amountFiat = ((a * rate) / sats).toFixed(2); } }; @@ -60,7 +62,7 @@ amount = 0; } } - } else if (value !== '.' && value !== '<' && parseInt(amountFiat + value) > $selectedRate) { + } else if (value !== '.' && value !== '<' && parseInt(amountFiat + value) > rate) { warning($t('user.receive.lessThan1BTCWarning')); } else if (amountFiat !== 0 && amountFiat.match(/\.../)) { return; @@ -184,12 +186,10 @@ type="button" on:click={() => { if (fiat) { - amount = parseInt((amountFiat / ($selectedRate / sats)).toFixed(0)); + amount = parseInt((amountFiat / (rate / sats)).toFixed(0)); } else { amountFiat = - (amount * ($selectedRate / sats)).toFixed(2) > 0.0 - ? (amount * ($selectedRate / sats)).toFixed(2) - : 0; + (amount * (rate / sats)).toFixed(2) > 0.0 ? (amount * (rate / sats)).toFixed(2) : 0; } fiat = !fiat; }}><Icon icon="swap" style="inline hover:opacity-80" /></button diff --git a/src/routes/(app)/[username]/receive/[...param]/+page.svelte b/src/routes/(app)/[username]/receive/[...param]/+page.svelte index 95495368..27b339aa 100644 --- a/src/routes/(app)/[username]/receive/[...param]/+page.svelte +++ b/src/routes/(app)/[username]/receive/[...param]/+page.svelte @@ -18,9 +18,10 @@ let lightning = true; let { currency, username, prompt } = data.subject; - let { user } = data; + let { rates, user } = data; let submit; + $: rate = rates[currency]; $: type = lightning ? 'lightning' : 'bitcoin'; </script> @@ -37,7 +38,7 @@ <input type="hidden" name="prompt" value={prompt} /> <div class="space-y-3 w-[300px] mx-auto"> - <Numpad bind:amount bind:currency {submit} /> + <Numpad bind:amount bind:currency bind:rate {submit} /> <button bind:this={submit} type="submit" diff --git a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte index 77d5fde6..342eeebe 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/bitcoin/[address]/[...amount]/+page.svelte @@ -5,15 +5,18 @@ import { Toggle, Slider, Icon, Numpad, Spinner } from '$comp'; import { page } from '$app/stores'; import { fiat as toFiat, f, back, s, sat } from '$lib/utils'; - import { pin, selectedRate } from '$lib/store'; + import { pin } from '$lib/store'; export let data; export let form; + let { rates } = data; let { address, amount } = $page.params; let { balance, currency } = data.user; let loading, submit, fiat, confirmed, feeRate, min, max, fee, ourfee, stale, subtract, adjusting; + $: rate = rates[currency]; + let toggle = () => (loading = true); let toggleAdjusting = () => (adjusting = !adjusting); @@ -64,7 +67,7 @@ {#if confirmed} <div class="text-center"> <h2 class="text-2xl md:text-3xl font-semibold"> - {f(toFiat(amount, $selectedRate), currency)} + {f(toFiat(amount, rate), currency)} </h2> <h3 class="text-secondary md:text-lg mb-6 mt-1">⚡️{s(amount)}</h3> </div> @@ -74,7 +77,7 @@ <div class="relative"> <h2 class="text-xl font-semibold"> - {f(toFiat(fee + ourfee, $selectedRate), currency)} + {f(toFiat(fee + ourfee, rate), currency)} </h2> <h3 class="text-secondary mb-6 mt-1">⚡️{s(fee + ourfee)}</h3> <button class="absolute right-1/4 top-0 text-secondary p-4" on:click={toggleAdjusting} @@ -83,7 +86,7 @@ </div> </div> {:else} - <Numpad bind:amount bind:fiat {currency} {submit} /> + <Numpad bind:amount bind:fiat {currency} {submit} bind:rate /> {/if} <form method="POST" use:enhance on:submit={toggle}> diff --git a/src/routes/(app)/send/lightning/[payreq]/+page.svelte b/src/routes/(app)/send/lightning/[payreq]/+page.svelte index af07a565..cb1b539e 100644 --- a/src/routes/(app)/send/lightning/[payreq]/+page.svelte +++ b/src/routes/(app)/send/lightning/[payreq]/+page.svelte @@ -10,13 +10,14 @@ export let form; let { payreq } = $page.params; - let { alias } = data; + let { alias, rates } = data; let { currency } = data.user; let a; let maxfee = 100; $: amount = form?.amount || data.amount; + $: rate = rates[currency]; let loading; let submit = () => (loading = true); @@ -91,7 +92,7 @@ {:else} <form method="POST" action="?/setAmount" class="w-[300px] mx-auto" use:enhance> <input type="hidden" value={a} name="amount" /> - <Numpad bind:amount={a} {currency} /> + <Numpad bind:amount={a} {currency} {rate} /> <button type="submit" class="bg-black text-white rounded-xl h-[48px] flex w-full justify-center items-center font-semibold diff --git a/src/routes/(app)/send/pot/[name]/[...amount]/+page.svelte b/src/routes/(app)/send/pot/[name]/[...amount]/+page.svelte index da761cc2..6aecf8f3 100644 --- a/src/routes/(app)/send/pot/[name]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/pot/[name]/[...amount]/+page.svelte @@ -10,9 +10,12 @@ export let form; let { amount, name } = $page.params; + let { rates } = data; let { currency } = data.user; let loading; + $: rate = rates[currency]; + let submit = () => (loading = true); $: update(form); let update = () => { @@ -32,7 +35,7 @@ {/if} <div class="container px-4 mt-20 max-w-xl mx-auto"> - <Numpad bind:amount {currency} /> + <Numpad bind:amount {currency} bind:rate /> <form method="POST" use:enhance on:submit={submit}> <input name="name" value={name} type="hidden" /> 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 ba758036..a01cdcfc 100644 --- a/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js +++ b/src/routes/(app)/send/user/[username]/[...amount]/+page.server.js @@ -10,8 +10,9 @@ export async function load({ cookies, params, parent }) { if (subject.username === user?.username) throw error(500, { message: 'Cannot send to self' }); + let rate; if (amount) { - let rate = rates[currency ? currency.toUpperCase() : subject.currency]; + rate = rates[currency ? currency.toUpperCase() : subject.currency]; if (!rate) throw error(500, 'Invalid currency symbol'); if (currency) amount = (amount * sats) / rate; @@ -27,7 +28,7 @@ export async function load({ cookies, params, parent }) { throw redirect(307, `/${username}/invoice/${hash}`); } - return { amount, subject }; + return { amount, rate, 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 6562de8a..2f59f492 100644 --- a/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte +++ b/src/routes/(app)/send/user/[username]/[...amount]/+page.svelte @@ -10,18 +10,18 @@ export let data; export let form; - let { subject, rates, user } = data; - let currency = subject.currency || 'USD'; + let { subject, rate, rates, user } = data; + let currency = user.currency || subject.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))); + $: r = rate || rates[user.currency || subject.currency]; let setAmount = async () => { amount = a; @@ -60,7 +60,7 @@ {/if} <div class="container px-4 mt-20 max-w-xl mx-auto space-y-8"> - <Numpad bind:amount={a} bind:amountFiat={af} {currency} bind:fiat /> + <Numpad bind:amount={a} bind:amountFiat={af} {currency} bind:fiat bind:rate={r} /> <form method="POST" use:enhance on:submit={submit}> <input name="amount" value={amount} type="hidden" /> |
