diff options
| author | Adam Soltys <[email protected]> | 2023-02-25 06:52:08 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-02-25 06:52:08 -0800 |
| commit | 1ac4c9f8dafc12cc247ce301d76f45fddeac477f (patch) | |
| tree | 200a01737e649722bcf93ad208c18365bc1f1201 /src/components | |
| parent | 0b9e3e5edf9f37e3cd692f2db801fa2bd5720314 (diff) | |
| parent | 0dd7eab893bb4aad5853ea92cdb8e70e421dc1b8 (diff) | |
| download | coinos-ui-1ac4c9f8dafc12cc247ce301d76f45fddeac477f.tar.gz coinos-ui-1ac4c9f8dafc12cc247ce301d76f45fddeac477f.zip | |
Merge branch 'master' into hashme
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/Lnurlp.svelte | 2 | ||||
| -rw-r--r-- | src/components/Numpad.svelte | 55 | ||||
| -rw-r--r-- | src/components/Slider.svelte | 56 | ||||
| -rw-r--r-- | src/components/index.js | 1 |
4 files changed, 86 insertions, 28 deletions
diff --git a/src/components/Lnurlp.svelte b/src/components/Lnurlp.svelte index 22364fcf..ab0c50ce 100644 --- a/src/components/Lnurlp.svelte +++ b/src/components/Lnurlp.svelte @@ -8,7 +8,7 @@ let { currency } = data.user; let { minSendable, maxSendable, callback, metadata } = data; - let amount = minSendable, + let amount = Math.round(minSendable / 1000), loading; let submit = () => (loading = true); </script> diff --git a/src/components/Numpad.svelte b/src/components/Numpad.svelte index 5ffaa2ea..47bd9375 100644 --- a/src/components/Numpad.svelte +++ b/src/components/Numpad.svelte @@ -9,11 +9,18 @@ fiat = !amount, submit = undefined; - export let amountFiat = amount ? amount * ($selectedRate / sats) : 0; - + let amountFiat = 0; let arrow = '<'; - let amountSats = amount; + $: update(amount, amountFiat); + let update = (a, f) => { + if (fiat) { + amount = Math.round(f / ($selectedRate / sats)); + } else { + amountFiat = ((a * $selectedRate) / sats).toFixed(2); + } + }; + let loading = false; let symbol = @@ -33,14 +40,6 @@ KRW: '₩' }[currency] || ''; - $: amount = parseInt(fiat ? Math.round(amountFiat / ($selectedRate / sats)) : amountSats); - - $: amountSatsFormatted = s(amountSats); - - $: amountFiatConverted = f(amountSats * ($selectedRate / sats), currency); - - $: amountSatsConverted = sat(amountFiat / ($selectedRate / sats)); - const numPad = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '0', '<']; const handleInput = (value) => { @@ -58,7 +57,7 @@ amountFiat = amountFiat.slice(0, amountFiat.length - 1); if (amountFiat.length === 0) { amountFiat = 0; - amountSats = 0; + amount = 0; } } } else if (value !== '.' && value !== '<' && parseInt(amountFiat + value) > $selectedRate) { @@ -71,25 +70,27 @@ } else { if (value === '.') { return; - } else if (!amountSats && value !== '<' && value !== '0') { - amountSats = parseInt(value); + } else if (!amount && value !== '<' && value !== '0') { + amount = parseInt(value); } else if (value === '<') { - if (amountSats !== 0) { - amountSats = Math.floor(amountSats / 10); - if (amountSats.length === 0) { - amountSats = 0; + if (amount !== 0) { + amount = Math.floor(amount / 10); + if (amount.length === 0) { + amount = 0; amountFiat = 0; } } - } else if (value !== '<' && parseInt(amountSats + value) > sats) { + } else if (value !== '<' && parseInt(amount + value) > sats) { warning($t('user.receive.lessThan1BTCWarning')); } else { - amountSats = parseInt(amountSats + value); + console.log('CLICK', amount.toString(), value); + amount = parseInt(amount.toString() + value); + console.log('AMOUNT', amount); } } }; - $: html = fiat ? amountFiat : s(amountSats); + $: html = fiat ? amountFiat : s(amount); let prev = ''; @@ -124,10 +125,10 @@ if (fiat) { amountFiat = html; } else { - amountSats = parseInt(html.replace(/,/g, '')); + amount = parseInt(html.replace(/,/g, '')); } - if (!amountSats) amountSats = null; + if (!amount) amount = null; setTimeout(() => { if (!fiat) { @@ -178,16 +179,16 @@ /> </div> <div class="mt-2"> - <span class="text-secondary mr-1">{fiat ? amountSatsConverted : amountFiatConverted}</span> + <span class="text-secondary mr-1">{fiat ? sat(amount) : f(amountFiat, currency)}</span> <button type="button" on:click={() => { if (fiat) { - amountSats = parseInt((amountFiat / ($selectedRate / sats)).toFixed(0)); + amount = parseInt((amountFiat / ($selectedRate / sats)).toFixed(0)); } else { amountFiat = - (amountSats * ($selectedRate / sats)).toFixed(2) > 0.0 - ? (amountSats * ($selectedRate / sats)).toFixed(2) + (amount * ($selectedRate / sats)).toFixed(2) > 0.0 + ? (amount * ($selectedRate / sats)).toFixed(2) : 0; } fiat = !fiat; diff --git a/src/components/Slider.svelte b/src/components/Slider.svelte new file mode 100644 index 00000000..3c94d127 --- /dev/null +++ b/src/components/Slider.svelte @@ -0,0 +1,56 @@ +<script> + export let value, + handle, + min = 0, + max = 100; +</script> + +<input + id="slider" + type="range" + {min} + {max} + bind:value + class="px-0 py-0 my-5" + style="--bgPercent: {((value - min) * 100) / (max - min)}%;" + on:input={handle} +/> + +<style> + #slider { + -webkit-appearance: none; + width: 100%; + height: 6px; + border-radius: 5px; + background: linear-gradient( + to right, + black 0%, + black var(--bgPercent), + #f5f7fa var(--bgPercent), + #f5f7fa 100% + ); + outline: none; + } + + #slider:active { + background-color: black; + } + + #slider::-webkit-slider-thumb { + -webkit-appearance: none; + appearance: none; + width: 30px; + height: 30px; + border-radius: 50%; + background: black; + cursor: pointer; + } + + #slider::-moz-range-thumb { + width: 30px; + height: 30px; + border-radius: 50%; + background: black; + cursor: pointer; + } +</style> diff --git a/src/components/index.js b/src/components/index.js index ab54e09f..0d1d8d1d 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -1,3 +1,4 @@ +export { default as Slider } from './Slider.svelte'; export { default as Pinpad } from './Pinpad.svelte'; export { default as Balance } from './Balance.svelte'; export { default as Lnurlp } from './Lnurlp.svelte'; |
