feat: fast zap donate
This commit is contained in:
parent
f31f44400f
commit
3fd4e471f1
@ -21,7 +21,7 @@ import { UserPreferences, setPinned, setBookmarked } from "State/Login";
|
|||||||
import useModeration from "Hooks/useModeration";
|
import useModeration from "Hooks/useModeration";
|
||||||
import { TranslateHost } from "Const";
|
import { TranslateHost } from "Const";
|
||||||
import { LNURL } from "LNURL";
|
import { LNURL } from "LNURL";
|
||||||
|
import { DonateLNURL } from "Pages/DonatePage";
|
||||||
import { useWallet } from "Wallet";
|
import { useWallet } from "Wallet";
|
||||||
|
|
||||||
import messages from "./messages";
|
import messages from "./messages";
|
||||||
@ -114,11 +114,17 @@ export default function NoteFooter(props: NoteFooterProps) {
|
|||||||
if (wallet?.isReady() && lnurl) {
|
if (wallet?.isReady() && lnurl) {
|
||||||
setZapping(true);
|
setZapping(true);
|
||||||
try {
|
try {
|
||||||
const handler = new LNURL(lnurl);
|
if (prefs.fastZapDonate > 0) {
|
||||||
await handler.load();
|
// spin off donate
|
||||||
const zap = handler.canZap ? await publisher.zap(prefs.defaultZapAmount * 1000, ev.PubKey, ev.Id) : undefined;
|
const donateAmount = Math.floor(prefs.defaultZapAmount * prefs.fastZapDonate);
|
||||||
const invoice = await handler.getInvoice(prefs.defaultZapAmount, undefined, zap);
|
if (donateAmount > 0) {
|
||||||
await wallet.payInvoice(unwrap(invoice.pr));
|
console.debug(`Donating ${donateAmount} sats to ${DonateLNURL}`);
|
||||||
|
fastZapInner(DonateLNURL, donateAmount)
|
||||||
|
.then(() => console.debug("Donation sent! Thank You!"))
|
||||||
|
.catch(() => console.debug("Failed to donate"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await fastZapInner(lnurl, prefs.defaultZapAmount);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Fast zap failed", e);
|
console.warn("Fast zap failed", e);
|
||||||
if (!(e instanceof Error) || e.message !== "User rejected") {
|
if (!(e instanceof Error) || e.message !== "User rejected") {
|
||||||
@ -132,6 +138,16 @@ export default function NoteFooter(props: NoteFooterProps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fastZapInner(lnurl: string, amount: number) {
|
||||||
|
if (wallet?.isReady() && lnurl) {
|
||||||
|
const handler = new LNURL(lnurl);
|
||||||
|
await handler.load();
|
||||||
|
const zap = handler.canZap ? await publisher.zap(amount * 1000, ev.PubKey, ev.Id) : undefined;
|
||||||
|
const invoice = await handler.getInvoice(amount, undefined, zap);
|
||||||
|
await wallet.payInvoice(unwrap(invoice.pr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function tipButton() {
|
function tipButton() {
|
||||||
const service = author?.lud16 || author?.lud06;
|
const service = author?.lud16 || author?.lud06;
|
||||||
if (service) {
|
if (service) {
|
||||||
|
@ -38,6 +38,8 @@ const Translators = [
|
|||||||
bech32ToHex("npub10529hxckjm5t5mchss5lnpsqrmavulglxhrmu5quuu4hs6yuyh3qc9gxd5"), // aadbitcoin - ID
|
bech32ToHex("npub10529hxckjm5t5mchss5lnpsqrmavulglxhrmu5quuu4hs6yuyh3qc9gxd5"), // aadbitcoin - ID
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const DonateLNURL = "donate@snort.social";
|
||||||
|
|
||||||
interface Splits {
|
interface Splits {
|
||||||
pubKey: string;
|
pubKey: string;
|
||||||
split: number;
|
split: number;
|
||||||
@ -105,7 +107,7 @@ const DonatePage = () => {
|
|||||||
<div className="mr10">
|
<div className="mr10">
|
||||||
<FormattedMessage defaultMessage="Lightning Donation: " />
|
<FormattedMessage defaultMessage="Lightning Donation: " />
|
||||||
</div>
|
</div>
|
||||||
<ZapButton pubkey={bech32ToHex(SnortPubKey)} lnurl={"donate@snort.social"} />
|
<ZapButton pubkey={bech32ToHex(SnortPubKey)} lnurl={DonateLNURL} />
|
||||||
</div>
|
</div>
|
||||||
{today && (
|
{today && (
|
||||||
<small>
|
<small>
|
||||||
|
@ -2,6 +2,7 @@ import "./Preferences.css";
|
|||||||
|
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
import emoji from "@jukben/emoji-search";
|
import emoji from "@jukben/emoji-search";
|
||||||
|
|
||||||
import { DefaultImgProxy, setPreferences, UserPreferences } from "State/Login";
|
import { DefaultImgProxy, setPreferences, UserPreferences } from "State/Login";
|
||||||
@ -154,6 +155,42 @@ const PreferencesPage = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="card flex">
|
||||||
|
<div className="flex f-col f-grow">
|
||||||
|
<div>
|
||||||
|
<FormattedMessage defaultMessage="Fast Zap Donation" />
|
||||||
|
</div>
|
||||||
|
<small>
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="For each Fast Zap an additional {percentage}% ({amount} sats) of the zap amount will be sent to the Snort developers as a donation."
|
||||||
|
values={{
|
||||||
|
percentage: perf.fastZapDonate * 100,
|
||||||
|
amount: Math.floor(perf.defaultZapAmount * perf.fastZapDonate),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<br />
|
||||||
|
<FormattedMessage
|
||||||
|
defaultMessage="For more information about donations see {link}."
|
||||||
|
values={{
|
||||||
|
link: (
|
||||||
|
<Link to="/donate">
|
||||||
|
<FormattedMessage defaultMessage="Donate Page" />
|
||||||
|
</Link>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={perf.fastZapDonate * 100}
|
||||||
|
min={0}
|
||||||
|
max={100}
|
||||||
|
onChange={e => dispatch(setPreferences({ ...perf, fastZapDonate: parseInt(e.target.value) / 100 }))}
|
||||||
|
/>
|
||||||
|
</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">
|
||||||
|
@ -80,6 +80,11 @@ export interface UserPreferences {
|
|||||||
* Default zap amount
|
* Default zap amount
|
||||||
*/
|
*/
|
||||||
defaultZapAmount: number;
|
defaultZapAmount: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For each fast zap an additional X% will be sent to Snort donate address
|
||||||
|
*/
|
||||||
|
fastZapDonate: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoginStore {
|
export interface LoginStore {
|
||||||
@ -234,6 +239,7 @@ export const InitState = {
|
|||||||
imgProxyConfig: DefaultImgProxy,
|
imgProxyConfig: DefaultImgProxy,
|
||||||
defaultRootTab: "posts",
|
defaultRootTab: "posts",
|
||||||
defaultZapAmount: 500,
|
defaultZapAmount: 500,
|
||||||
|
fastZapDonate: 0.0,
|
||||||
},
|
},
|
||||||
} as LoginStore;
|
} as LoginStore;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user