Merge branch 'main' of github.com:v0l/snort into svg-proposal

This commit is contained in:
Jeremy Karlsson
2023-03-02 19:46:15 +01:00
32 changed files with 12408 additions and 15511 deletions

View File

@ -12,11 +12,11 @@ import ProfileImage from "Element/ProfileImage";
import Modal from "Element/Modal";
import QrCode from "Element/QrCode";
import Copy from "Element/Copy";
import useWebln from "Hooks/useWebln";
import { LNURL, LNURLError, LNURLErrorCode, LNURLInvoice, LNURLSuccessAction } from "LNURL";
import { debounce } from "Util";
import messages from "./messages";
import { useWallet } from "Wallet";
enum ZapType {
PublicZap = 1,
@ -74,10 +74,11 @@ export default function SendSats(props: SendSatsProps) {
const [zapType, setZapType] = useState(ZapType.PublicZap);
const [paying, setPaying] = useState<boolean>(false);
const webln = useWebln(props.show);
const { formatMessage } = useIntl();
const publisher = useEventPublisher();
const canComment = handler ? (handler.canZap && zapType !== ZapType.NonZap) || handler.maxCommentLength > 0 : false;
const walletState = useWallet();
const wallet = walletState.wallet;
useEffect(() => {
if (props.show) {
@ -152,7 +153,7 @@ export default function SendSats(props: SendSatsProps) {
const rsp = await handler.getInvoice(amount, comment, zap);
if (rsp.pr) {
setInvoice(rsp.pr);
await payWebLNIfEnabled(rsp);
await payWithWallet(rsp);
}
} catch (e) {
handleLNURLError(e, formatMessage(messages.InvoiceFail));
@ -202,11 +203,11 @@ export default function SendSats(props: SendSatsProps) {
);
}
async function payWebLNIfEnabled(invoice: LNURLInvoice) {
async function payWithWallet(invoice: LNURLInvoice) {
try {
if (webln?.enabled) {
if (wallet?.isReady) {
setPaying(true);
const res = await webln.sendPayment(invoice?.pr ?? "");
const res = await wallet.payInvoice(invoice?.pr ?? "");
console.log(res);
setSuccess(invoice?.successAction ?? {});
}
@ -304,7 +305,12 @@ export default function SendSats(props: SendSatsProps) {
{props.notice && <b className="error">{props.notice}</b>}
{paying ? (
<h4>
<FormattedMessage defaultMessage="Paying with WebLN" />
<FormattedMessage
defaultMessage="Paying with {wallet}"
values={{
wallet: walletState.config?.info.alias,
}}
/>
...
</h4>
) : (