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 13, 2024
1 parent 59aba76 commit 7272721
Show file tree
Hide file tree
Showing 51 changed files with 9,292 additions and 663 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
9 changes: 9 additions & 0 deletions packages/api-bindings/src/lens/__helpers__/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ export function mockSimpleCollectOpenActionSettingsFragment(
});
}

export function mockProtocolSharedRevenueCollectOpenActionSettingsFragment(
overrides?: Partial<gql.ProtocolSharedRevenueCollectOpenActionSettings>,
) {
return mock<gql.ProtocolSharedRevenueCollectOpenActionSettings>({
...overrides,
__typename: 'ProtocolSharedRevenueCollectOpenActionSettings',
});
}

export function mockMultirecipientFeeCollectOpenActionSettingsFragment(
overrides?: Partial<gql.MultirecipientFeeCollectOpenActionSettings>,
) {
Expand Down
30 changes: 30 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 @@ -720,6 +738,9 @@ fragment PublicationOperations on PublicationOperations {
fragment PublicationMetadataLitEncryption on PublicationMetadataLitEncryption {
__typename
encryptionKey
accessControlContract {
...NetworkAddress
}
accessCondition {
...RootCondition
}
Expand Down Expand Up @@ -1639,6 +1660,9 @@ fragment Post on Post {
... on MultirecipientFeeCollectOpenActionSettings {
...MultirecipientFeeCollectOpenActionSettings
}
... on ProtocolSharedRevenueCollectOpenActionSettings {
...ProtocolSharedRevenueCollectOpenActionSettings
}
... on SimpleCollectOpenActionSettings {
...SimpleCollectOpenActionSettings
}
Expand Down Expand Up @@ -1778,6 +1802,9 @@ fragment CommentFields on Comment {
... on MultirecipientFeeCollectOpenActionSettings {
...MultirecipientFeeCollectOpenActionSettings
}
... on ProtocolSharedRevenueCollectOpenActionSettings {
...ProtocolSharedRevenueCollectOpenActionSettings
}
... on SimpleCollectOpenActionSettings {
...SimpleCollectOpenActionSettings
}
Expand Down Expand Up @@ -1961,6 +1988,9 @@ fragment QuoteFields on Quote {
... on MultirecipientFeeCollectOpenActionSettings {
...MultirecipientFeeCollectOpenActionSettings
}
... on ProtocolSharedRevenueCollectOpenActionSettings {
...ProtocolSharedRevenueCollectOpenActionSettings
}
... on SimpleCollectOpenActionSettings {
...SimpleCollectOpenActionSettings
}
Expand Down
Loading

0 comments on commit 7272721

Please sign in to comment.