Merge branch 'main' into enhance-lightning-design
This commit is contained in:
commit
a4df1c53cb
|
@ -12,7 +12,7 @@ import { openModal } from './modals';
|
||||||
import { expandGroupFeaturedTimeline } from './timelines';
|
import { expandGroupFeaturedTimeline } from './timelines';
|
||||||
|
|
||||||
import type { AppDispatch, RootState } from 'soapbox/store';
|
import type { AppDispatch, RootState } from 'soapbox/store';
|
||||||
import type { APIEntity, Group, Status as StatusEntity } from 'soapbox/types/entities';
|
import type { Account as AccountEntity, APIEntity, Group, Status as StatusEntity } from 'soapbox/types/entities';
|
||||||
|
|
||||||
const REBLOG_REQUEST = 'REBLOG_REQUEST';
|
const REBLOG_REQUEST = 'REBLOG_REQUEST';
|
||||||
const REBLOG_SUCCESS = 'REBLOG_SUCCESS';
|
const REBLOG_SUCCESS = 'REBLOG_SUCCESS';
|
||||||
|
@ -314,26 +314,26 @@ const undislikeFail = (status: StatusEntity, error: unknown) => ({
|
||||||
skipLoading: true,
|
skipLoading: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const zap = (status: StatusEntity, amount: number, comment: string) => (dispatch: AppDispatch, getState: () => RootState) => {
|
const zap = (account: AccountEntity, status: StatusEntity | undefined, amount: number, comment: string) => (dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
if (!isLoggedIn(getState)) return;
|
if (!isLoggedIn(getState)) return;
|
||||||
|
|
||||||
dispatch(zapRequest(status));
|
if (status) dispatch(zapRequest(status));
|
||||||
|
|
||||||
return api(getState).post(`/api/v1/statuses/${status.id}/zap`, { amount, comment: comment ?? '' }).then(async function(response) {
|
return api(getState).post('/api/v1/ditto/zap', { amount, comment, account_id: account.id, status_id: status?.id }).then(async function(response) {
|
||||||
const invoice = response.headers['ln-invoice'];
|
const { invoice } = response.data;
|
||||||
if (!invoice) throw Error('Could not generate invoice');
|
if (!invoice) throw Error('Could not generate invoice');
|
||||||
if (!window.webln) return invoice;
|
if (!window.webln) return invoice;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await window.webln?.enable();
|
await window.webln?.enable();
|
||||||
await window.webln?.sendPayment(invoice);
|
await window.webln?.sendPayment(invoice);
|
||||||
dispatch(zapSuccess(status));
|
if (status) dispatch(zapSuccess(status));
|
||||||
return undefined;
|
return undefined;
|
||||||
} catch (e) { // In case it fails we just return the invoice so the QR code can be created
|
} catch (e) { // In case it fails we just return the invoice so the QR code can be created
|
||||||
return invoice;
|
return invoice;
|
||||||
}
|
}
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
dispatch(zapFail(status, e));
|
if (status) dispatch(zapFail(status, e));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,7 @@ const messages = defineMessages({
|
||||||
profileExternal: { id: 'account.profile_external', defaultMessage: 'View profile on {domain}' },
|
profileExternal: { id: 'account.profile_external', defaultMessage: 'View profile on {domain}' },
|
||||||
header: { id: 'account.header.alt', defaultMessage: 'Profile header' },
|
header: { id: 'account.header.alt', defaultMessage: 'Profile header' },
|
||||||
subscribeFeed: { id: 'account.rss_feed', defaultMessage: 'Subscribe to RSS feed' },
|
subscribeFeed: { id: 'account.rss_feed', defaultMessage: 'Subscribe to RSS feed' },
|
||||||
|
zap: { id: 'zap.send_to', defaultMessage: 'Send zaps to {target}' },
|
||||||
});
|
});
|
||||||
|
|
||||||
interface IHeader {
|
interface IHeader {
|
||||||
|
@ -282,6 +283,10 @@ const Header: React.FC<IHeader> = ({ account }) => {
|
||||||
copy(nip19.npubEncode(account.nostr.pubkey!));
|
copy(nip19.npubEncode(account.nostr.pubkey!));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleZapAccount: React.EventHandler<React.MouseEvent> = (e) => {
|
||||||
|
dispatch(openModal('ZAP_PAY_REQUEST', { account }));
|
||||||
|
};
|
||||||
|
|
||||||
const makeMenu = () => {
|
const makeMenu = () => {
|
||||||
const menu: Menu = [];
|
const menu: Menu = [];
|
||||||
|
|
||||||
|
@ -621,8 +626,22 @@ const Header: React.FC<IHeader> = ({ account }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderZapAccount = () => {
|
||||||
|
return (
|
||||||
|
<IconButton
|
||||||
|
src={require('@tabler/icons/outline/bolt.svg')}
|
||||||
|
onClick={handleZapAccount}
|
||||||
|
title={intl.formatMessage(messages.zap, { target: account.display_name })}
|
||||||
|
theme='outlined'
|
||||||
|
className='px-2'
|
||||||
|
iconClassName='h-4 w-4'
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const info = makeInfo();
|
const info = makeInfo();
|
||||||
const menu = makeMenu();
|
const menu = makeMenu();
|
||||||
|
const acceptsZaps = account.ditto.accepts_zaps === true;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='-mx-4 -mt-4 sm:-mx-6 sm:-mt-6'>
|
<div className='-mx-4 -mt-4 sm:-mx-6 sm:-mt-6'>
|
||||||
|
@ -664,6 +683,7 @@ const Header: React.FC<IHeader> = ({ account }) => {
|
||||||
<SubscriptionButton account={account} />
|
<SubscriptionButton account={account} />
|
||||||
{renderMessageButton()}
|
{renderMessageButton()}
|
||||||
{renderShareButton()}
|
{renderShareButton()}
|
||||||
|
{acceptsZaps && renderZapAccount()}
|
||||||
|
|
||||||
{menu.length > 0 && (
|
{menu.length > 0 && (
|
||||||
<DropdownMenu items={menu} placement='bottom-end'>
|
<DropdownMenu items={menu} placement='bottom-end'>
|
||||||
|
|
|
@ -29,9 +29,7 @@ const ZapPayRequestForm = ({ account, status }: IZapPayRequestForm) => {
|
||||||
|
|
||||||
const handleSubmit = async (e?: React.FormEvent<Element>) => {
|
const handleSubmit = async (e?: React.FormEvent<Element>) => {
|
||||||
e?.preventDefault();
|
e?.preventDefault();
|
||||||
if (status) {
|
const invoice = await dispatch(zap(account, status, zapAmount * 1000, zapComment));
|
||||||
// multiply by 1000 to convert from satoshi to millisatoshi
|
|
||||||
const invoice = await dispatch(zap(status, zapAmount * 1000, zapComment));
|
|
||||||
// If invoice is undefined it means the user has paid through his extension
|
// If invoice is undefined it means the user has paid through his extension
|
||||||
// In this case, we simply close the modal
|
// In this case, we simply close the modal
|
||||||
if (!invoice) {
|
if (!invoice) {
|
||||||
|
@ -40,7 +38,6 @@ const ZapPayRequestForm = ({ account, status }: IZapPayRequestForm) => {
|
||||||
}
|
}
|
||||||
// open QR code modal
|
// open QR code modal
|
||||||
dispatch(openModal('ZAP_INVOICE', { invoice, account }));
|
dispatch(openModal('ZAP_INVOICE', { invoice, account }));
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCustomAmount = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleCustomAmount = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
|
Loading…
Reference in New Issue