Skip to content

Commit

Permalink
feat: create profile & reactions (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
reecejohnson authored Sep 13, 2023
1 parent 063dc9c commit 5425cf4
Show file tree
Hide file tree
Showing 15 changed files with 364 additions and 186 deletions.
42 changes: 0 additions & 42 deletions examples/node/scripts/addReaction.ts

This file was deleted.

60 changes: 29 additions & 31 deletions examples/node/scripts/bookmarks.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { isRelaySuccess, LensClient, ProfileFragment } from "@lens-protocol/client";
import { getAuthenticatedClient } from "./shared/getAuthenticatedClient";
import { getAuthenticatedClientFromEthersWallet } from "./shared/getAuthenticatedClient";
import { setupWallet } from "./shared/setupWallet";

async function createProfile(client: LensClient): Promise<ProfileFragment> {
const handle = Date.now().toString();

console.log(`Creating ${handle}.test...`);

const profileCreateResult = await client.profile.create({ handle });
const profileCreateResult = await client.profile.create({ handle, to: "EVM_ADDRESS" });

const profileCreateResultValue = profileCreateResult.unwrap();

if (!isRelaySuccess(profileCreateResultValue)) {
console.log(`Something went wrong`, profileCreateResultValue);
if (!isRelaySuccess(profileCreateResult)) {
console.log(`Something went wrong`, profileCreateResult);
return;
}

console.log(`Waiting for the transaction ${profileCreateResultValue.txHash} to be indexed...`);
await client.transaction.waitForIsIndexed(profileCreateResultValue.txId);
console.log(`Waiting for the transaction ${profileCreateResult.txHash} to be indexed...`);
await client.transaction.waitUntilComplete({ txId: profileCreateResult.txId });

return client.profile.fetch({ handle: `${handle}.test` });
}
Expand All @@ -26,41 +24,41 @@ async function main() {
// setup
const wallet = setupWallet();
const address = await wallet.getAddress();
const client = await getAuthenticatedClient(wallet);
const client = await getAuthenticatedClientFromEthersWallet(wallet);

const profile = await createProfile(client);

const before = await client.bookmarks.fetch({ profileId: profile.id });
// const before = await client.bookmarks.fetch({ profileId: profile.id });

console.log(`Initial ${profile.handle} bookmarks: `, before.items.length);
// console.log(`Initial ${profile.handle} bookmarks: `, before.items.length);

const addResult = await client.bookmarks.add({
profileId: profile.id,
publicationId: "0x0635-0x0f",
});
// const addResult = await client.bookmarks.add({
// profileId: profile.id,
// publicationId: "0x0635-0x0f",
// });

if (addResult.isFailure()) {
console.log(`Something went wrong`, addResult.unwrap());
return;
}
// if (addResult.isFailure()) {
// console.log(`Something went wrong`, addResult.unwrap());
// return;
// }

const after = await client.bookmarks.fetch({ profileId: profile.id });
// const after = await client.bookmarks.fetch({ profileId: profile.id });

console.log(`${profile.handle} bookmarks after adding one: `, after.items.length);
// console.log(`${profile.handle} bookmarks after adding one: `, after.items.length);

const removeResult = await client.bookmarks.remove({
profileId: profile.id,
publicationId: "0x0635-0x0f",
});
// const removeResult = await client.bookmarks.remove({
// profileId: profile.id,
// publicationId: "0x0635-0x0f",
// });

if (removeResult.isFailure()) {
console.log(`Something went wrong`, removeResult.unwrap());
return;
}
// if (removeResult.isFailure()) {
// console.log(`Something went wrong`, removeResult.unwrap());
// return;
// }

const ultimately = await client.bookmarks.fetch({ profileId: profile.id });
// const ultimately = await client.bookmarks.fetch({ profileId: profile.id });

console.log(`${profile.handle} bookmarks after removing one: `, ultimately.items.length);
// console.log(`${profile.handle} bookmarks after removing one: `, ultimately.items.length);
}

main();
3 changes: 1 addition & 2 deletions examples/node/scripts/profile/createProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function main() {
console.log(`Creating a new profile for ${address} with handle "${handle}"`);

const profileCreateResult = await lensClient.profile.create({
handle: "CHOSEN_HANDLE",
handle: handle,
to: "YOUR_EVM_ADDRESS",
});

Expand All @@ -28,7 +28,6 @@ async function main() {
`Transaction to create a new profile with handle "${handle}" was successfuly broadcasted with txId ${profileCreateResultValue.txId}`
);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
await lensClient.transaction.waitUntilComplete({ txId: profileCreateResultValue.txId });

Expand Down
26 changes: 26 additions & 0 deletions examples/node/scripts/profile/interests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { LensClient, development } from "@lens-protocol/client";

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

// add interests
await lensClient.profile.addInterests({
interests: ["TECHNOLOGY", "HEALTH_FITNESS__EXERCISE"],
});

// fetch all interests
const { interests } = await lensClient.profile.fetch({
profileId: "PROFILE_ID",
});

console.log(`Profile interests`, interests);

// remove interests
await lensClient.profile.removeInterests({
interests: ["HEALTH_FITNESS__EXERCISE"],
});
}

main();
33 changes: 33 additions & 0 deletions examples/node/scripts/publication/reactions/addReaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { LensClient, PublicationReactionType, development } from "@lens-protocol/client";

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

const feedResult = await lensClient.feed.fetch({
where: {
for: "PROFILE_ID",
},
limit: 20,
});

const feedItems = feedResult.unwrap().items;

// find first item without a reaction
const feedItem = feedItems.find((item) => !item.reactions);

if (!feedItem) {
throw new Error(`You reacted to all feed items`);
}

// add reaction
await lensClient.publication.reactions.add({
for: "PUBLICATION_ID",
reaction: PublicationReactionType.Upvote,
});

console.log(`You added a reaction to ${feedItem.root.id}`);
}

main();
33 changes: 33 additions & 0 deletions examples/node/scripts/publication/reactions/removeReaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { LensClient, PublicationReactionType, development } from "@lens-protocol/client";

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

const feedResult = await lensClient.feed.fetch({
where: {
for: "PROFILE_ID",
},
limit: 20,
});

const feedItems = feedResult.unwrap().items;

// find first item with a reaction
const feedItem = feedItems.find((item) => item.reactions);

if (!feedItem) {
throw new Error(`You haven't reacted to anything`);
}

// add reaction
await lensClient.publication.reactions.remove({
for: "PUBLICATION_ID",
reaction: PublicationReactionType.Upvote,
});

console.log(`You remove a reaction from ${feedItem.root.id}`);
}

main();
41 changes: 41 additions & 0 deletions examples/node/scripts/publication/reactions/whoReacted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
ExplorePublicationsOrderByType,
LensClient,
PublicationReactionType,
development,
} from "@lens-protocol/client";

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

const profilesWhoReacted = await lensClient.publication.reactions.fetch({
for: "PUBLICATION_ID",
limit: 20,
});

console.log(
`Profiles who reacted to publication: ${JSON.stringify(profilesWhoReacted, null, 2)}`
);

await lensClient.publication.reactions.add({
for: "PUBLICATION_ID",
reaction: PublicationReactionType.Upvote,
});

const profilesWhoReactedAfterUpvote = await lensClient.publication.reactions.fetch({
for: "PUBLICATION_ID",
limit: 20,
});

console.log(
`Profiles who reacted to publication after upvote: ${JSON.stringify(
profilesWhoReactedAfterUpvote,
null,
2
)}`
);
}

main();
2 changes: 2 additions & 0 deletions packages/client/codegen-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ config:
URL: string
Void: string
OnchainPublicationId: string
EncryptedPath: string
UUID: string

avoidOptionals:
field: true
Expand Down
Loading

0 comments on commit 5425cf4

Please sign in to comment.