Simpler custom zap selection

This commit is contained in:
Bojan Mojsilovic 2024-04-23 12:16:08 +02:00
parent c18249d067
commit 96349c65a8

View File

@ -34,7 +34,6 @@ const CustomZap: Component<{
const settings = useSettingsContext(); const settings = useSettingsContext();
const [selectedValue, setSelectedValue] = createSignal(settings?.availableZapOptions[0] || defaultZapOptions[0]); const [selectedValue, setSelectedValue] = createSignal(settings?.availableZapOptions[0] || defaultZapOptions[0]);
const [comment, setComment] = createSignal(defaultZapOptions[0].message || '');
createEffect(() => { createEffect(() => {
setSelectedValue(settings?.availableZapOptions[0] || defaultZapOptions[0]) setSelectedValue(settings?.availableZapOptions[0] || defaultZapOptions[0])
@ -49,12 +48,16 @@ const CustomZap: Component<{
const amount = parseInt(value.replaceAll(',', '')); const amount = parseInt(value.replaceAll(',', ''));
if (isNaN(amount)) { if (isNaN(amount)) {
setSelectedValue(() => ({ amount: 0 })) setSelectedValue((v) => ({ ...v, amount: 0 }))
}; };
setSelectedValue(()=> ({ amount })); setSelectedValue((v)=> ({ ...v, amount }));
}; };
const updateComment = (message: string) => {
setSelectedValue((v) => ({ ...v, message }))
}
const truncateNumber = (amount: number) => { const truncateNumber = (amount: number) => {
const t = 1000; const t = 1000;
@ -101,7 +104,7 @@ const CustomZap: Component<{
note, note,
account.publicKey, account.publicKey,
selectedValue().amount || 0, selectedValue().amount || 0,
comment(), selectedValue().message,
account.relays, account.relays,
); );
@ -115,7 +118,7 @@ const CustomZap: Component<{
props.profile, props.profile,
account.publicKey, account.publicKey,
selectedValue().amount || 0, selectedValue().amount || 0,
comment(), selectedValue().message,
account.relays, account.relays,
); );
@ -170,8 +173,7 @@ const CustomZap: Component<{
<button <button
class={`${styles.zapOption} ${isSelected(value) ? styles.selected : ''}`} class={`${styles.zapOption} ${isSelected(value) ? styles.selected : ''}`}
onClick={() => { onClick={() => {
setComment(value.message || '') setSelectedValue(() => ({...value}));
setSelectedValue(value);
}} }}
> >
<div> <div>
@ -204,9 +206,9 @@ const CustomZap: Component<{
<TextInput <TextInput
type="text" type="text"
value={comment()} value={selectedValue().message || ''}
placeholder={intl.formatMessage(tPlaceholders.addComment)} placeholder={intl.formatMessage(tPlaceholders.addComment)}
onChange={setComment} onChange={updateComment}
noExtraSpace={true} noExtraSpace={true}
/> />