Simpler custom zap selection

This commit is contained in:
Bojan Mojsilovic 2024-04-23 12:16:08 +02:00
parent c18249d067
commit 96349c65a8
1 changed files with 11 additions and 9 deletions

View File

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