Skip to content

Commit

Permalink
ref docs for revenue module
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysu committed Sep 20, 2023
1 parent 3929c40 commit 028461f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 80 deletions.
12 changes: 5 additions & 7 deletions examples/node/scripts/revenue/fromFollow.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { LensClient, development } from '@lens-protocol/client';

async function main() {
const lensClient = new LensClient({
const client = new LensClient({
environment: development,
});

const profileId = 'PROFILE_ID';
const profileId = '0x01';

const followRevenue = await lensClient.revenue.fromFollow({
for: 'PROFILE_ID',
const result = await client.revenue.fromFollow({
for: profileId,
});

console.log(
`Follow revenue for profile with id: ${profileId} - ${JSON.stringify(followRevenue)}`,
);
console.log(`Follow revenue for profile with id: ${profileId}`, result);
}

main();
24 changes: 15 additions & 9 deletions examples/node/scripts/revenue/fromPublication.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { LensClient, development } from '@lens-protocol/client';

async function main() {
const lensClient = new LensClient({
const client = new LensClient({
environment: development,
});

const publicationRevenue = await lensClient.revenue.fromPublication({
for: 'PUBLICATION_ID',
});
try {
const publications = await client.publication.fetchAll();

const firstPublication = publications.items[0];

const publicationRevenue = await client.revenue.fromPublication({
for: firstPublication.id,
});

console.log(
`Publication revenue for publication with id: ${
publicationRevenue.publication.id
} - ${JSON.stringify(publicationRevenue.revenue)}`,
);
console.log(`Revenue for publication with id: ${firstPublication.id}`, publicationRevenue);
} catch (e) {
if (e instanceof Error) {
console.log(e.message);
}
}
}

main();
54 changes: 5 additions & 49 deletions examples/node/scripts/revenue/fromPublications.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,17 @@
import { LensClient, development } from '@lens-protocol/client';

async function main() {
const lensClient = new LensClient({
const client = new LensClient({
environment: development,
});

const collectRevenue = await lensClient.revenue.fromPublications({
for: 'PROFILE_ID',
// where: {
// fromCollects: true,
// },
});

collectRevenue.items.map((item) => {
console.log(
`Collect revenue for publication with id: ${item.publication.id} - ${JSON.stringify(
item.revenue,
)}`,
);
});

const revenueFromQuoteCollects = await lensClient.revenue.fromPublications({
for: 'PROFILE_ID',
// where: {
// fromCollects: true,
// publicationTypes: [PublicationType.Quote],
// },
});

revenueFromQuoteCollects.items.map((item) => {
console.log(
`Collect revenue for quote publication with id: ${item.publication.id} - ${JSON.stringify(
item.revenue,
)}`,
);
});
const profileId = '0x01';

const revenueFromOpenAction = await lensClient.revenue.fromPublications({
for: 'PROFILE_ID',
// where: {
// fromCollects: false,
// anyOf: [
// {
// address: '0x000',
// category: OpenActionCategoryType.Collect,
// },
// ],
// },
const result = await client.revenue.fromPublications({
for: profileId,
});

revenueFromOpenAction.items.map((item) => {
console.log(
`Open action revenue for publication with id: ${item.publication.id} - ${JSON.stringify(
item.revenue,
)}`,
);
});
console.log(`Follow revenue for profile with id: ${profileId}`, result);
}

main();
2 changes: 1 addition & 1 deletion packages/client/src/submodules/publication/Publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class Publication {
* ```
*/
async fetchAll(
request: PublicationsRequest,
request: PublicationsRequest = {},
): Promise<PaginatedResult<AnyPublicationFragment | null>> {
return buildPaginatedQueryResult(async (currRequest) => {
const result = await this.sdk.Publications({
Expand Down
66 changes: 52 additions & 14 deletions packages/client/src/submodules/revenue/Revenue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from './graphql/revenue.generated';

/**
* With built-in ways to earn on Lens Protocol, see the breakdown of what you have earned.
* Fetch a profile's or publication's revenue.
*
* @group LensClient Modules
*/
Expand All @@ -35,19 +35,19 @@ export class Revenue {
this.sdk = getSdk(client, sdkAuthHeaderWrapper(authentication));
}

async fromPublications(
request: RevenueFromPublicationsRequest,
): Promise<PaginatedResult<PublicationRevenueFragment>> {
return buildPaginatedQueryResult(async (currRequest) => {
const result = await this.sdk.RevenueFromPublications({
request: currRequest,
...buildImageTransformsFromConfig(this.config.mediaTransforms),
});

return result.data.result;
}, request);
}

/**
* Fetch a revenue from all follow actions.
*
* @param request - Request object for the query
* @returns Aggregated revenue
*
* @example
* ```ts
* const result = await client.revenue.fromFollow({
* for: '0x123',
* });
* ```
*/
async fromFollow(request: FollowRevenueRequest): Promise<RevenueAggregateFragment[]> {
const result = await this.sdk.FollowRevenues({
request,
Expand All @@ -56,6 +56,18 @@ export class Revenue {
return result.data.result.revenues;
}

/**
* Fetch a profile's revenue from a single publication.
* @param request - Request object for the query
* @returns Publication revenue
*
* @example
* ```ts
* const result = await client.revenue.fromPublication({
* for: '0x123-0x456',
* });
* ```
*/
async fromPublication(
request: RevenueFromPublicationRequest,
): Promise<PublicationRevenueFragment | null> {
Expand All @@ -66,4 +78,30 @@ export class Revenue {

return result.data.result;
}

/**
* Fetch a profile's revenue from all publications.
*
* @param request - Request object for the query
* @returns {@link PublicationRevenueFragment} wrapped in {@link PaginatedResult}
*
* @example
* ```ts
* const result = await client.revenue.fromPublications({
* for: '0x123',
* });
* ```
*/
async fromPublications(
request: RevenueFromPublicationsRequest,
): Promise<PaginatedResult<PublicationRevenueFragment>> {
return buildPaginatedQueryResult(async (currRequest) => {
const result = await this.sdk.RevenueFromPublications({
request: currRequest,
...buildImageTransformsFromConfig(this.config.mediaTransforms),
});

return result.data.result;
}, request);
}
}

0 comments on commit 028461f

Please sign in to comment.