Compare commits
1 Commits
redesign
...
954df262e7
| Author | SHA1 | Date | |
|---|---|---|---|
| 954df262e7 |
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import cx from "classnames"
|
||||||
import type {NativeEmoji} from "emoji-picker-element/shared"
|
import type {NativeEmoji} from "emoji-picker-element/shared"
|
||||||
import {signer, deriveZapperForPubkey} from "@welshman/app"
|
import {signer, deriveZapperForPubkey} from "@welshman/app"
|
||||||
import {load} from "@welshman/net"
|
import {load} from "@welshman/net"
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
import {errorMessage} from "@lib/util"
|
import {errorMessage} from "@lib/util"
|
||||||
import ProfileLink from "@app/components/ProfileLink.svelte"
|
import ProfileLink from "@app/components/ProfileLink.svelte"
|
||||||
import {payInvoice} from "@app/lightning"
|
import {payInvoice} from "@app/lightning"
|
||||||
|
import {zapAmounts} from "@app/settings"
|
||||||
import {pushToast} from "@app/toast"
|
import {pushToast} from "@app/toast"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -30,31 +32,14 @@
|
|||||||
|
|
||||||
const {url, pubkey, eventId}: Props = $props()
|
const {url, pubkey, eventId}: Props = $props()
|
||||||
|
|
||||||
const minPos = 1
|
|
||||||
const maxPos = 1000
|
|
||||||
const minVal = 21
|
|
||||||
const maxVal = 1000000
|
|
||||||
const zapperStore = deriveZapperForPubkey(pubkey)
|
const zapperStore = deriveZapperForPubkey(pubkey)
|
||||||
|
|
||||||
const posToAmount = (pos: number) => {
|
|
||||||
const normalizedPos = (pos - minPos) / (maxPos - minPos)
|
|
||||||
const logMin = Math.log(minVal)
|
|
||||||
const logMax = Math.log(maxVal)
|
|
||||||
const logValue = logMin + normalizedPos * (logMax - logMin)
|
|
||||||
return Math.round(Math.exp(logValue))
|
|
||||||
}
|
|
||||||
|
|
||||||
const amountToPos = (amount: number) => {
|
|
||||||
const clampedAmount = Math.max(minVal, Math.min(maxVal, amount))
|
|
||||||
const logMin = Math.log(minVal)
|
|
||||||
const logMax = Math.log(maxVal)
|
|
||||||
const logValue = Math.log(clampedAmount)
|
|
||||||
const normalizedPos = (logValue - logMin) / (logMax - logMin)
|
|
||||||
return Math.round(minPos + normalizedPos * (maxPos - minPos))
|
|
||||||
}
|
|
||||||
|
|
||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
|
const selectAmount = (preset: number) => {
|
||||||
|
amount = preset
|
||||||
|
}
|
||||||
|
|
||||||
const onEmoji = (emoji: NativeEmoji) => {
|
const onEmoji = (emoji: NativeEmoji) => {
|
||||||
content = emoji.unicode
|
content = emoji.unicode
|
||||||
}
|
}
|
||||||
@@ -97,21 +82,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let pos = $state(minPos)
|
let amount = $state(zapAmounts.get()[0])
|
||||||
let amount = $state(minVal)
|
|
||||||
let content = $state("⚡️")
|
let content = $state("⚡️")
|
||||||
let loading = $state(false)
|
let loading = $state(false)
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
amount = posToAmount(pos)
|
|
||||||
})
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
const newPos = amountToPos(amount)
|
|
||||||
if (newPos !== pos) {
|
|
||||||
pos = newPos
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal>
|
<Modal>
|
||||||
@@ -145,12 +118,15 @@
|
|||||||
</div>
|
</div>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</FieldInline>
|
</FieldInline>
|
||||||
<input
|
<div class="flex flex-wrap justify-end gap-2">
|
||||||
class="range range-primary -mt-2"
|
{#each $zapAmounts as preset}
|
||||||
type="range"
|
<Button
|
||||||
min={minPos}
|
class={cx("btn btn-sm rounded-full", preset === amount ? "btn-primary" : "btn-neutral")}
|
||||||
max={maxPos}
|
onclick={() => selectAmount(preset)}>
|
||||||
bind:value={pos} />
|
{preset}
|
||||||
|
</Button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button class="btn btn-link" onclick={back}>
|
<Button class="btn btn-link" onclick={back}>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {onDestroy} from "svelte"
|
import {onDestroy} from "svelte"
|
||||||
|
import cx from "classnames"
|
||||||
import type {NativeEmoji} from "emoji-picker-element/shared"
|
import type {NativeEmoji} from "emoji-picker-element/shared"
|
||||||
import {signer, deriveZapperForPubkey} from "@welshman/app"
|
import {signer, deriveZapperForPubkey} from "@welshman/app"
|
||||||
import {request} from "@welshman/net"
|
import {request} from "@welshman/net"
|
||||||
@@ -24,6 +25,7 @@
|
|||||||
import QRCode from "@app/components/QRCode.svelte"
|
import QRCode from "@app/components/QRCode.svelte"
|
||||||
import WalletConnect from "@app/components/WalletConnect.svelte"
|
import WalletConnect from "@app/components/WalletConnect.svelte"
|
||||||
import {pushModal} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
|
import {zapAmounts} from "@app/settings"
|
||||||
import {clip, pushToast} from "@app/toast"
|
import {clip, pushToast} from "@app/toast"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -34,31 +36,14 @@
|
|||||||
|
|
||||||
const {url, pubkey, eventId}: Props = $props()
|
const {url, pubkey, eventId}: Props = $props()
|
||||||
|
|
||||||
const minPos = 1
|
|
||||||
const maxPos = 1000
|
|
||||||
const minVal = 21
|
|
||||||
const maxVal = 1000000
|
|
||||||
const zapperStore = deriveZapperForPubkey(pubkey)
|
const zapperStore = deriveZapperForPubkey(pubkey)
|
||||||
|
|
||||||
const posToAmount = (pos: number) => {
|
|
||||||
const normalizedPos = (pos - minPos) / (maxPos - minPos)
|
|
||||||
const logMin = Math.log(minVal)
|
|
||||||
const logMax = Math.log(maxVal)
|
|
||||||
const logValue = logMin + normalizedPos * (logMax - logMin)
|
|
||||||
return Math.round(Math.exp(logValue))
|
|
||||||
}
|
|
||||||
|
|
||||||
const amountToPos = (amount: number) => {
|
|
||||||
const clampedAmount = Math.max(minVal, Math.min(maxVal, amount))
|
|
||||||
const logMin = Math.log(minVal)
|
|
||||||
const logMax = Math.log(maxVal)
|
|
||||||
const logValue = Math.log(clampedAmount)
|
|
||||||
const normalizedPos = (logValue - logMin) / (logMax - logMin)
|
|
||||||
return Math.round(minPos + normalizedPos * (maxPos - minPos))
|
|
||||||
}
|
|
||||||
|
|
||||||
const back = () => history.back()
|
const back = () => history.back()
|
||||||
|
|
||||||
|
const selectAmount = (preset: number) => {
|
||||||
|
amount = preset
|
||||||
|
}
|
||||||
|
|
||||||
const onEmoji = (emoji: NativeEmoji) => {
|
const onEmoji = (emoji: NativeEmoji) => {
|
||||||
content = emoji.unicode
|
content = emoji.unicode
|
||||||
}
|
}
|
||||||
@@ -120,8 +105,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let pos = $state(minPos)
|
let amount = $state(zapAmounts.get()[0])
|
||||||
let amount = $state(minVal)
|
|
||||||
let content = $state("⚡️")
|
let content = $state("⚡️")
|
||||||
let loading = $state(false)
|
let loading = $state(false)
|
||||||
let invoice = $state<string>()
|
let invoice = $state<string>()
|
||||||
@@ -130,17 +114,6 @@
|
|||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
paymentController?.abort()
|
paymentController?.abort()
|
||||||
})
|
})
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
amount = posToAmount(pos)
|
|
||||||
})
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
const newPos = amountToPos(amount)
|
|
||||||
if (newPos !== pos) {
|
|
||||||
pos = newPos
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal>
|
<Modal>
|
||||||
@@ -189,12 +162,15 @@
|
|||||||
</div>
|
</div>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</FieldInline>
|
</FieldInline>
|
||||||
<input
|
<div class="flex flex-wrap justify-end gap-2">
|
||||||
class="range range-primary -mt-2"
|
{#each $zapAmounts as preset}
|
||||||
type="range"
|
<Button
|
||||||
min={minPos}
|
class={cx("btn btn-sm rounded-full", preset === amount ? "btn-primary" : "btn-neutral")}
|
||||||
max={maxPos}
|
onclick={() => selectAmount(preset)}>
|
||||||
bind:value={pos} />
|
{preset}
|
||||||
|
</Button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
<p class="card2 card-sm bg-alt text-center flex justify-between items-center">
|
<p class="card2 card-sm bg-alt text-center flex justify-between items-center">
|
||||||
Want to zap directly?
|
Want to zap directly?
|
||||||
<Button class="btn btn-neutral btn-sm" onclick={connectWallet}>
|
<Button class="btn btn-neutral btn-sm" onclick={connectWallet}>
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ export const notificationSettings = withGetter(
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const defaultZapAmounts = [21, 210, 2100, 21000]
|
||||||
|
|
||||||
|
export const zapAmounts = withGetter(writable([...defaultZapAmounts]))
|
||||||
|
|
||||||
export const makeSettings = async (params: Partial<SettingsValues>) => {
|
export const makeSettings = async (params: Partial<SettingsValues>) => {
|
||||||
const json = JSON.stringify({...get(userSettingsValues), ...params})
|
const json = JSON.stringify({...get(userSettingsValues), ...params})
|
||||||
const content = await signer.get().nip44.encrypt(pubkey.get()!, json)
|
const content = await signer.get().nip44.encrypt(pubkey.get()!, json)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
import {authPolicy, blockPolicy, trustPolicy, mostlyRestrictedPolicy} from "@app/policies"
|
import {authPolicy, blockPolicy, trustPolicy, mostlyRestrictedPolicy} from "@app/policies"
|
||||||
import {db, kv, ss} from "@app/storage"
|
import {db, kv, ss} from "@app/storage"
|
||||||
import {device} from "@app/device"
|
import {device} from "@app/device"
|
||||||
import {getSetting, userSettingsValues, notificationSettings} from "@app/settings"
|
import {getSetting, userSettingsValues, notificationSettings, zapAmounts} from "@app/settings"
|
||||||
import {DUFFLEPUD_URL, INDEXER_RELAYS, POMADE_SIGNERS} from "@app/env"
|
import {DUFFLEPUD_URL, INDEXER_RELAYS, POMADE_SIGNERS} from "@app/env"
|
||||||
import {pushState} from "@app/push/adapters/common"
|
import {pushState} from "@app/push/adapters/common"
|
||||||
import {syncApplicationData} from "@app/sync"
|
import {syncApplicationData} from "@app/sync"
|
||||||
@@ -200,6 +200,11 @@
|
|||||||
store: notificationSettings,
|
store: notificationSettings,
|
||||||
storage: kv,
|
storage: kv,
|
||||||
}),
|
}),
|
||||||
|
sync({
|
||||||
|
key: "zapAmounts",
|
||||||
|
store: zapAmounts,
|
||||||
|
storage: kv,
|
||||||
|
}),
|
||||||
sync({
|
sync({
|
||||||
key: "notificationState",
|
key: "notificationState",
|
||||||
store: pushState,
|
store: pushState,
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import cx from "classnames"
|
import cx from "classnames"
|
||||||
import {LOCALE, always, call, sleep} from "@welshman/lib"
|
import {LOCALE, always, call, removeAt, replaceAt, sleep} from "@welshman/lib"
|
||||||
import {WalletType, displayRelayUrl, isNWCWallet, fromMsats} from "@welshman/util"
|
import {WalletType, displayRelayUrl, isNWCWallet, fromMsats} from "@welshman/util"
|
||||||
import {session, pubkey, profilesByPubkey} from "@welshman/app"
|
import {session, pubkey, profilesByPubkey} from "@welshman/app"
|
||||||
import DownloadMinimalistic from "@assets/icons/download-minimalistic.svg?dataurl"
|
import DownloadMinimalistic from "@assets/icons/download-minimalistic.svg?dataurl"
|
||||||
import UploadMinimalistic from "@assets/icons/upload-minimalistic.svg?dataurl"
|
import UploadMinimalistic from "@assets/icons/upload-minimalistic.svg?dataurl"
|
||||||
|
import Bolt from "@assets/icons/bolt.svg?dataurl"
|
||||||
|
import AddCircle from "@assets/icons/add-circle.svg?dataurl"
|
||||||
|
import TrashBin2 from "@assets/icons/trash-bin-2.svg?dataurl"
|
||||||
|
import {preventDefault} from "@lib/html"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
|
import Spinner from "@lib/components/Spinner.svelte"
|
||||||
import WalletPay from "@app/components/WalletPay.svelte"
|
import WalletPay from "@app/components/WalletPay.svelte"
|
||||||
import WalletReceive from "@app/components/WalletReceive.svelte"
|
import WalletReceive from "@app/components/WalletReceive.svelte"
|
||||||
import WalletConnect from "@app/components/WalletConnect.svelte"
|
import WalletConnect from "@app/components/WalletConnect.svelte"
|
||||||
@@ -14,9 +19,10 @@
|
|||||||
import WalletUpdateReceivingAddress from "@app/components/WalletUpdateReceivingAddress.svelte"
|
import WalletUpdateReceivingAddress from "@app/components/WalletUpdateReceivingAddress.svelte"
|
||||||
import {pushModal} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
import {getNwcClient, getWebLn} from "@app/lightning"
|
import {getNwcClient, getWebLn} from "@app/lightning"
|
||||||
|
import {zapAmounts} from "@app/settings"
|
||||||
|
import {pushToast} from "@app/toast"
|
||||||
import Wallet2 from "@assets/icons/wallet.svg?dataurl"
|
import Wallet2 from "@assets/icons/wallet.svg?dataurl"
|
||||||
import CheckCircle from "@assets/icons/check-circle.svg?dataurl"
|
import CheckCircle from "@assets/icons/check-circle.svg?dataurl"
|
||||||
import AddCircle from "@assets/icons/add-circle.svg?dataurl"
|
|
||||||
import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
|
import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
|
||||||
import InfoCircle from "@assets/icons/info-circle.svg?dataurl"
|
import InfoCircle from "@assets/icons/info-circle.svg?dataurl"
|
||||||
|
|
||||||
@@ -78,6 +84,52 @@
|
|||||||
$effect(() => {
|
$effect(() => {
|
||||||
startWalletStatusCheck($session?.wallet)
|
startWalletStatusCheck($session?.wallet)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const resetZapAmounts = () => {
|
||||||
|
zapAmountDraft = [...zapAmounts.get()]
|
||||||
|
}
|
||||||
|
|
||||||
|
const addZapAmount = () => {
|
||||||
|
zapAmountDraft = [...zapAmountDraft, zapAmountDraft.at(-1) || 21]
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeZapAmount = (index: number) => {
|
||||||
|
if (zapAmountDraft.length > 1) {
|
||||||
|
zapAmountDraft = removeAt(index, zapAmountDraft)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onZapAmountInput = (e: Event) => {
|
||||||
|
const target = e.currentTarget as HTMLInputElement
|
||||||
|
const index = Number(target.dataset.index)
|
||||||
|
|
||||||
|
zapAmountDraft = replaceAt(index, Number(target.value), zapAmountDraft)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onZapAmountsSubmit = preventDefault(() => {
|
||||||
|
zapAmountsLoading = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
const amounts = zapAmountDraft.filter(amount => amount > 0)
|
||||||
|
|
||||||
|
if (amounts.length === 0) {
|
||||||
|
return pushToast({
|
||||||
|
theme: "error",
|
||||||
|
message: "Add at least one zap amount greater than zero.",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
zapAmounts.set(amounts)
|
||||||
|
zapAmountDraft = [...amounts]
|
||||||
|
|
||||||
|
pushToast({message: "Your zap amounts have been saved!"})
|
||||||
|
} finally {
|
||||||
|
zapAmountsLoading = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let zapAmountDraft = $state([...zapAmounts.get()])
|
||||||
|
let zapAmountsLoading = $state(false)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="content column gap-4">
|
<div class="content column gap-4">
|
||||||
@@ -206,4 +258,50 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
<form class="card2 bg-alt flex flex-col gap-6 shadow-md" onsubmit={onZapAmountsSubmit}>
|
||||||
|
<strong class="flex items-center gap-3 text-lg">
|
||||||
|
<Icon icon={Bolt} />
|
||||||
|
Zap Amounts
|
||||||
|
</strong>
|
||||||
|
<p class="text-sm opacity-75">Preset amounts shown when sending a zap.</p>
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
{#each zapAmountDraft as amount, index}
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<Button
|
||||||
|
class="btn btn-ghost btn-sm"
|
||||||
|
type="button"
|
||||||
|
onclick={() => removeZapAmount(index)}
|
||||||
|
disabled={zapAmountDraft.length === 1}>
|
||||||
|
<Icon icon={TrashBin2} />
|
||||||
|
</Button>
|
||||||
|
<label class="input input-bordered flex grow items-center gap-2">
|
||||||
|
<Icon icon={Bolt} />
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
class="grow"
|
||||||
|
min="1"
|
||||||
|
data-index={index}
|
||||||
|
value={amount}
|
||||||
|
oninput={onZapAmountInput} />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
<Button class="btn btn-link w-fit px-0" type="button" onclick={addZapAmount}>
|
||||||
|
<Icon icon={AddCircle} size={5} />
|
||||||
|
Add amount
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-row items-center justify-between gap-4">
|
||||||
|
<Button
|
||||||
|
class="btn btn-neutral"
|
||||||
|
type="button"
|
||||||
|
onclick={resetZapAmounts}
|
||||||
|
disabled={zapAmountsLoading}>
|
||||||
|
Discard Changes
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" class="btn btn-primary" disabled={zapAmountsLoading}>
|
||||||
|
<Spinner loading={zapAmountsLoading}>Save Changes</Spinner>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user