extract error messages

This commit is contained in:
2023-02-27 19:15:39 +00:00
parent a564dfc4e8
commit 3040dd46fa
6 changed files with 56 additions and 13 deletions

View File

@ -118,7 +118,7 @@ export default function NoteFooter(props: NoteFooterProps) {
}
}
async function zapClick(e: React.MouseEvent) {
async function fastZap(e: React.MouseEvent) {
if (zapping || e.isPropagationStopped()) return;
const lnurl = author?.lud16 || author?.lud06;
@ -149,7 +149,7 @@ export default function NoteFooter(props: NoteFooterProps) {
if (service) {
return (
<>
<div className={`reaction-pill ${didZap ? "reacted" : ""}`} {...longPress()} onClick={e => zapClick(e)}>
<div className={`reaction-pill ${didZap ? "reacted" : ""}`} {...longPress()} onClick={e => fastZap(e)}>
<div className="reaction-pill-icon">{zapping ? <Spinner /> : webln?.enabled ? <ZapFast /> : <Zap />}</div>
{zapTotal > 0 && <div className="reaction-pill-number">{formatShort(zapTotal)}</div>}
</div>

View File

@ -17,7 +17,7 @@ import Copy from "Element/Copy";
import useWebln from "Hooks/useWebln";
import messages from "./messages";
import { LNURL, LNURLInvoice, LNURLSuccessAction } from "LNURL";
import { LNURL, LNURLError, LNURLErrorCode, LNURLInvoice, LNURLSuccessAction } from "LNURL";
enum ZapType {
PublicZap = 1,
@ -96,7 +96,7 @@ export default function SendSats(props: SendSatsProps) {
try {
const h = new LNURL(props.lnurl);
setHandler(h);
h.load().catch(e => setError((e as Error).message));
h.load().catch(e => handleLNURLError(e, formatMessage(messages.InvoiceFail)));
} catch (e) {
if (e instanceof Error) {
setError(e.message);
@ -147,10 +147,26 @@ export default function SendSats(props: SendSatsProps) {
await payWebLNIfEnabled(rsp);
}
} catch (e) {
setError(formatMessage(messages.InvoiceFail));
handleLNURLError(e, formatMessage(messages.InvoiceFail));
}
}
function handleLNURLError(e: unknown, fallback: string) {
if (e instanceof LNURLError) {
switch (e.code) {
case LNURLErrorCode.ServiceUnavailable: {
setError(formatMessage(messages.LNURLFail));
return;
}
case LNURLErrorCode.InvalidLNURL: {
setError(formatMessage(messages.InvalidLNURL));
return;
}
}
}
setError(fallback);
}
function custom() {
if (!handler) return null;
const min = handler.min / 1000;

View File

@ -60,6 +60,7 @@ export default defineMessages({
Milliseconds: { defaultMessage: "{n} ms" },
ShowLatest: { defaultMessage: "Show latest {n} notes" },
LNURLFail: { defaultMessage: "Failed to load LNURL service" },
InvalidLNURL: { defaultMessage: "Invalid LNURL" },
InvoiceFail: { defaultMessage: "Failed to load invoice" },
Custom: { defaultMessage: "Custom" },
Confirm: { defaultMessage: "Confirm" },