feat: default zap amount

This commit is contained in:
Kieran 2023-02-24 23:03:01 +00:00
parent 8939b1dad2
commit 44b29b777d
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
3 changed files with 27 additions and 3 deletions

View File

@ -1,10 +1,12 @@
import "./SendSats.css"; import "./SendSats.css";
import { useEffect, useMemo, useState } from "react"; import { useEffect, useMemo, useState } from "react";
import { useIntl, FormattedMessage } from "react-intl"; import { useIntl, FormattedMessage } from "react-intl";
import { useSelector } from "react-redux";
import { formatShort } from "Number"; import { formatShort } from "Number";
import { bech32ToText } from "Util"; import { bech32ToText } from "Util";
import { HexKey, Tag } from "@snort/nostr"; import { HexKey, Tag } from "@snort/nostr";
import { RootState } from "State/Store";
import Check from "Icons/Check"; import Check from "Icons/Check";
import Zap from "Icons/Zap"; import Zap from "Icons/Zap";
import Close from "Icons/Close"; import Close from "Icons/Close";
@ -72,7 +74,8 @@ export default function LNURLTip(props: LNURLTipProps) {
const service = props.svc; const service = props.svc;
const show = props.show || false; const show = props.show || false;
const { note, author, target } = props; const { note, author, target } = props;
const amounts = [500, 1_000, 5_000, 10_000, 20_000, 50_000, 100_000, 1_000_000]; const defaultZapAmount = useSelector((s: RootState) => s.login.preferences.defaultZapAmount);
const amounts = [defaultZapAmount, 1_000, 5_000, 10_000, 20_000, 50_000, 100_000, 1_000_000];
const emojis: Record<number, string> = { const emojis: Record<number, string> = {
1_000: "👍", 1_000: "👍",
5_000: "💜", 5_000: "💜",
@ -83,7 +86,7 @@ export default function LNURLTip(props: LNURLTipProps) {
1_000_000: "🤯", 1_000_000: "🤯",
}; };
const [payService, setPayService] = useState<LNURLService>(); const [payService, setPayService] = useState<LNURLService>();
const [amount, setAmount] = useState<number>(500); const [amount, setAmount] = useState<number>(defaultZapAmount);
const [customAmount, setCustomAmount] = useState<number>(); const [customAmount, setCustomAmount] = useState<number>();
const [invoice, setInvoice] = useState<LNURLInvoice>(); const [invoice, setInvoice] = useState<LNURLInvoice>();
const [comment, setComment] = useState<string>(); const [comment, setComment] = useState<string>();
@ -104,7 +107,7 @@ export default function LNURLTip(props: LNURLTipProps) {
setPayService(undefined); setPayService(undefined);
setError(undefined); setError(undefined);
setInvoice(props.invoice ? { pr: props.invoice } : undefined); setInvoice(props.invoice ? { pr: props.invoice } : undefined);
setAmount(500); setAmount(defaultZapAmount);
setComment(undefined); setComment(undefined);
setSuccess(undefined); setSuccess(undefined);
setZapType(ZapType.PublicZap); setZapType(ZapType.PublicZap);

View File

@ -111,6 +111,21 @@ const PreferencesPage = () => {
</div> </div>
</div> </div>
</div> </div>
<div className="card flex">
<div className="flex f-col f-grow">
<div>
<FormattedMessage defaultMessage="Default Zap amount" />
</div>
</div>
<div>
<input
type="number"
value={perf.defaultZapAmount}
min={1}
onChange={e => dispatch(setPreferences({ ...perf, defaultZapAmount: parseInt(e.target.value) }))}
/>
</div>
</div>
<div className="card flex f-col"> <div className="card flex f-col">
<div className="flex w-max"> <div className="flex w-max">
<div className="flex f-col f-grow"> <div className="flex f-col f-grow">

View File

@ -70,6 +70,11 @@ export interface UserPreferences {
* Default page to select on load * Default page to select on load
*/ */
defaultRootTab: "posts" | "conversations" | "global"; defaultRootTab: "posts" | "conversations" | "global";
/**
* Default zap amount
*/
defaultZapAmount: number;
} }
export type DbType = "indexdDb" | "redux"; export type DbType = "indexdDb" | "redux";
@ -231,6 +236,7 @@ export const InitState = {
fileUploader: "void.cat", fileUploader: "void.cat",
imgProxyConfig: DefaultImgProxy, imgProxyConfig: DefaultImgProxy,
defaultRootTab: "posts", defaultRootTab: "posts",
defaultZapAmount: 500,
}, },
} as LoginStore; } as LoginStore;