Skip to content

Commit

Permalink
feat: support new Shared Revenue Collect module
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarenaldi committed May 9, 2024
1 parent 59aba76 commit 6901c33
Show file tree
Hide file tree
Showing 25 changed files with 6,407 additions and 243 deletions.
10 changes: 10 additions & 0 deletions .changeset/weak-hairs-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@lens-protocol/client": minor
"@lens-protocol/react-native": minor
"@lens-protocol/react-web": minor
"@lens-protocol/react": minor
"@lens-protocol/api-bindings": patch
"@lens-protocol/domain": patch
---

**feat:** support new Shared Revenue Collect module
56 changes: 36 additions & 20 deletions examples/web/src/discovery/UseExplorePublications.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
CollectFee,
ExplorePublication,
ExplorePublicationsOrderByType,
MultirecipientCollectFee,
isMultirecipientCollectFee,
resolveCollectPolicy,
useExplorePublications,
Expand All @@ -10,7 +12,31 @@ import { PublicationCard } from '../components/cards';
import { ErrorMessage } from '../components/error/ErrorMessage';
import { Loading } from '../components/loading/Loading';
import { useInfiniteScroll } from '../hooks/useInfiniteScroll';
import { formatAmount, formatFiatAmount } from '../utils/formatAmount';
import { formatAmount } from '../utils/formatAmount';

export function formatCollectFee({ amount, rate }: CollectFee | MultirecipientCollectFee) {
if (rate) {
const fiat = amount.convert(rate);
return `${formatAmount(amount)} (${formatAmount(fiat)})`;
}
return formatAmount(amount);
}

export function CollectFeeDetails({ fee }: { fee: CollectFee | MultirecipientCollectFee }) {
return (
<div>
<p>{`Paid collect: ${formatCollectFee(fee)}`}</p>

{fee.referralFee > 0 && <div>{`Referral fee: ${fee.referralFee}%`}</div>}

{isMultirecipientCollectFee(fee) ? (
<p>{`Recipients: ${fee.recipients.map((r) => r.recipient).join(', ')}`}</p>
) : (
<p>{`Recipient: ${fee.recipient}`}</p>
)}
</div>
);
}

function PublicationCollectPolicy({ publication }: { publication: ExplorePublication }) {
const policy = resolveCollectPolicy(publication);
Expand All @@ -19,25 +45,15 @@ function PublicationCollectPolicy({ publication }: { publication: ExplorePublica

return (
<div>
{policy.followerOnly === true && <div>Only followers can collect</div>}
{policy.collectLimit && <div>{`Collect limit: ${policy.collectLimit}`}</div>}
{policy.endsAt && <div>{`Ends at: ${policy.endsAt}`}</div>}
{!policy.fee ? (
<div>Free collect</div>
) : (
<>
<div>{`Paid collect: ${formatAmount(policy.fee.amount)} (${formatFiatAmount(
policy.fee.amount,
policy.fee.rate,
)})`}</div>
{policy.fee.referralFee > 0 && <div>{`Referral fee: ${policy.fee.referralFee}%`}</div>}
{!isMultirecipientCollectFee(policy.fee) ? (
<div>{`Recipient: ${policy.fee.recipient}`}</div>
) : (
<div>{`Recipients: ${policy.fee.recipients.map((r) => r.recipient).join(', ')}`}</div>
)}
</>
)}
{policy.followerOnly === true && <p>Only followers can collect</p>}

{policy.collectLimit && <p>{`Collect limit: ${policy.collectLimit}`}</p>}

{policy.endsAt && <p>{`Ends at: ${policy.endsAt}`}</p>}

{policy.fee === null && <p>Free collect</p>}

{policy.fee && <CollectFeeDetails fee={policy.fee} />}
</div>
);
}
Expand Down
12 changes: 4 additions & 8 deletions packages/api-bindings/src/apollo/cache/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import {
UnlinkHandleRequest,
} from '@lens-protocol/domain/use-cases/profile';
import {
OpenActionRequest,
AllOpenActionType,
CreateQuoteRequest,
CreateMirrorRequest,
CreateCommentRequest,
CollectRequest,
isCollectRequest,
} from '@lens-protocol/domain/use-cases/publications';
import { AnyTransactionRequest } from '@lens-protocol/domain/use-cases/transactions';

Expand Down Expand Up @@ -68,14 +68,10 @@ export function useRecentTransactionsVar() {

function isCollectTransaction(
transaction: TransactionState<AnyTransactionRequest>,
): transaction is TransactionState<OpenActionRequest> {
): transaction is TransactionState<CollectRequest> {
return (
transaction.request.kind === TransactionKind.ACT_ON_PUBLICATION &&
[
AllOpenActionType.LEGACY_COLLECT,
AllOpenActionType.SIMPLE_COLLECT,
AllOpenActionType.MULTIRECIPIENT_COLLECT,
].includes(transaction.request.type)
isCollectRequest(transaction.request)
);
}

Expand Down
27 changes: 27 additions & 0 deletions packages/api-bindings/src/lens/graphql/fragments.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,24 @@ fragment SimpleCollectOpenActionSettings on SimpleCollectOpenActionSettings {
endsAt
}

fragment ProtocolSharedRevenueCollectOpenActionSettings on ProtocolSharedRevenueCollectOpenActionSettings {
__typename
type
contract {
...NetworkAddress
}
collectNft
amount {
...Amount
}
recipient
referralFee
followerOnly
collectLimit
endsAt
creatorClient
}

# purposefully renamed Recipient to have a better narrative
fragment Recipient on RecipientDataOutput {
# __typename not include to hide RecipientDataOutput not needed anyway here
Expand Down Expand Up @@ -1639,6 +1657,9 @@ fragment Post on Post {
... on MultirecipientFeeCollectOpenActionSettings {
...MultirecipientFeeCollectOpenActionSettings
}
... on ProtocolSharedRevenueCollectOpenActionSettings {
...ProtocolSharedRevenueCollectOpenActionSettings
}
... on SimpleCollectOpenActionSettings {
...SimpleCollectOpenActionSettings
}
Expand Down Expand Up @@ -1778,6 +1799,9 @@ fragment CommentFields on Comment {
... on MultirecipientFeeCollectOpenActionSettings {
...MultirecipientFeeCollectOpenActionSettings
}
... on ProtocolSharedRevenueCollectOpenActionSettings {
...ProtocolSharedRevenueCollectOpenActionSettings
}
... on SimpleCollectOpenActionSettings {
...SimpleCollectOpenActionSettings
}
Expand Down Expand Up @@ -1961,6 +1985,9 @@ fragment QuoteFields on Quote {
... on MultirecipientFeeCollectOpenActionSettings {
...MultirecipientFeeCollectOpenActionSettings
}
... on ProtocolSharedRevenueCollectOpenActionSettings {
...ProtocolSharedRevenueCollectOpenActionSettings
}
... on SimpleCollectOpenActionSettings {
...SimpleCollectOpenActionSettings
}
Expand Down
Loading

0 comments on commit 6901c33

Please sign in to comment.