mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-09-30 00:41:09 +00:00
Proper subs from profile and article
This commit is contained in:
parent
4440e0d499
commit
a69f7d5950
@ -390,7 +390,7 @@ const Longform: Component< { naddr: string } > = (props) => {
|
||||
getAuthorSubscriptionTiers(author.pubkey, subId)
|
||||
}
|
||||
|
||||
const doSubscription = async (tier: Tier, cost: TierCost) => {
|
||||
const doSubscription = async (tier: Tier, cost: TierCost, exchangeRate?: Record<string, Record<string, number>>) => {
|
||||
const a = store.article?.user;
|
||||
|
||||
if (!a || !account || !cost) return;
|
||||
@ -412,10 +412,34 @@ const Longform: Component< { naddr: string } > = (props) => {
|
||||
const { success, note } = await sendEvent(subEvent, account.relays, account.relaySettings);
|
||||
|
||||
if (success && note) {
|
||||
await zapSubscription(note, a, account.publicKey, account.relays);
|
||||
const isZapped = await zapSubscription(note, a, account.publicKey, account.relays, exchangeRate);
|
||||
|
||||
if (!isZapped) {
|
||||
unsubscribe(note.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const unsubscribe = async (eventId: string) => {
|
||||
const a = store.article?.user;
|
||||
|
||||
if (!a || !account) return;
|
||||
|
||||
const unsubEvent = {
|
||||
kind: Kind.Unsubscribe,
|
||||
content: '',
|
||||
created_at: Math.floor((new Date()).getTime() / 1_000),
|
||||
|
||||
tags: [
|
||||
['p', a.pubkey],
|
||||
['e', eventId],
|
||||
],
|
||||
};
|
||||
|
||||
await sendEvent(unsubEvent, account.relays, account.relaySettings);
|
||||
|
||||
}
|
||||
|
||||
const openSubscribe = () => {
|
||||
app?.actions.openAuthorSubscribeModal(store.article?.user, doSubscription);
|
||||
};
|
||||
@ -602,8 +626,6 @@ const Longform: Component< { naddr: string } > = (props) => {
|
||||
getArticleThread(account?.publicKey, pubkey, identifier, kind, subId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const updatePage = (content: NostrEventContent) => {
|
||||
if (content.kind === Kind.Metadata) {
|
||||
const user = content as NostrUserContent;
|
||||
|
@ -547,7 +547,7 @@ const Profile: Component = () => {
|
||||
getAuthorSubscriptionTiers(author.pubkey, subId);
|
||||
}
|
||||
|
||||
const doSubscription = async (tier: Tier, cost: TierCost) => {
|
||||
const doSubscription = async (tier: Tier, cost: TierCost, exchangeRate?: Record<string, Record<string, number>>) => {
|
||||
const a = profile?.userProfile;
|
||||
|
||||
if (!a || !account || !cost) return;
|
||||
@ -569,10 +569,35 @@ const Profile: Component = () => {
|
||||
const { success, note } = await sendEvent(subEvent, account.relays, account.relaySettings);
|
||||
|
||||
if (success && note) {
|
||||
await zapSubscription(note, a, account.publicKey, account.relays);
|
||||
const isZapped = await zapSubscription(note, a, account.publicKey, account.relays, exchangeRate);
|
||||
|
||||
if (!isZapped) {
|
||||
unsubscribe(note.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const unsubscribe = async (eventId: string) => {
|
||||
const a = profile?.userProfile;;
|
||||
|
||||
if (!a || !account) return;
|
||||
|
||||
const unsubEvent = {
|
||||
kind: Kind.Unsubscribe,
|
||||
content: '',
|
||||
created_at: Math.floor((new Date()).getTime() / 1_000),
|
||||
|
||||
tags: [
|
||||
['p', a.pubkey],
|
||||
['e', eventId],
|
||||
],
|
||||
};
|
||||
|
||||
await sendEvent(unsubEvent, account.relays, account.relaySettings);
|
||||
|
||||
}
|
||||
|
||||
|
||||
const openSubscribe = () => {
|
||||
app?.actions.openAuthorSubscribeModal(profile?.userProfile, doSubscription);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user