Skip to content

Commit

Permalink
Merge branch 'lens-v2' into fix/set-profile-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
reecejohnson committed Oct 20, 2023
2 parents aff3a6f + 0687207 commit 9b37358
Show file tree
Hide file tree
Showing 96 changed files with 3,331 additions and 248 deletions.
6 changes: 6 additions & 0 deletions .changeset/loud-poets-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@lens-protocol/react": minor
"@lens-protocol/react-web": minor
---

refactors hook arguments to be passed to the callback
7 changes: 7 additions & 0 deletions .changeset/many-jeans-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lens-protocol/api-bindings": minor
"@lens-protocol/react": minor
"@lens-protocol/react-web": minor
---

adds `useNotInterestedToggle` hook
9 changes: 8 additions & 1 deletion .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"react-web-v1": "1.3.1"
},
"changesets": [
"breezy-lizards-sell",
"brown-bears-repair",
"brown-flies-pump",
"brown-points-rhyme",
Expand All @@ -36,6 +37,7 @@
"cyan-radios-sniff",
"dirty-tools-hammer",
"early-spiders-scream",
"five-seals-tap",
"fluffy-apricots-provide",
"fresh-lamps-explain",
"friendly-pumpkins-turn",
Expand All @@ -50,20 +52,25 @@
"lemon-drinks-exercise",
"lemon-schools-decide",
"long-carpets-marry",
"loud-pets-decide",
"nervous-papayas-design",
"new-doors-sip",
"odd-cougars-poke",
"old-carrots-breathe",
"olive-beans-double",
"popular-pants-look",
"serious-bats-shake",
"shaggy-carrots-cry",
"shy-pugs-taste",
"six-feet-sparkle",
"six-tigers-serve",
"slow-cats-dance",
"slow-melons-fail",
"tasty-houses-admire",
"tasty-yaks-destroy",
"tricky-planets-share",
"violet-ads-warn"
"two-geese-protect",
"violet-ads-warn",
"violet-impalas-grab"
]
}
5 changes: 5 additions & 0 deletions .changeset/swift-hornets-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lens-protocol/client": patch
---

Added profile.fetchDefault and profile.setDefault methods
7 changes: 7 additions & 0 deletions .changeset/tidy-kangaroos-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lens-protocol/api-bindings": minor
"@lens-protocol/react": minor
"@lens-protocol/react-web": minor
---

Added useOwnedHandles hook
10 changes: 9 additions & 1 deletion examples/node/scripts/profile/createLinkHandleTypedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ import { setupWallet } from '../shared/setupWallet';
async function main() {
const wallet = setupWallet();
const client = await getAuthenticatedClientFromEthersWallet(wallet);
const profileId = await client.authentication.getProfileId();

const ownedHandles = await client.wallet.ownedHandles({
for: wallet.address,
});

console.log(`Handles owned by ${wallet.address}:`, ownedHandles);

const linkHandleToProfileTypedData = await client.profile.createLinkHandleTypedData({
handle: 'HANDLE',
handle: ownedHandles.items[0].handle,
});

const data = linkHandleToProfileTypedData.unwrap();
Expand All @@ -19,6 +26,7 @@ async function main() {
data.typedData.value,
);

console.log(`Linking handle ${ownedHandles.items[0].handle} to profile ${profileId}`);
const broadcastResult = await client.transaction.broadcastOnchain({
id: data.id,
signature: signedTypedData,
Expand Down
22 changes: 22 additions & 0 deletions examples/node/scripts/profile/fetchDefault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { LensClient, development } from '@lens-protocol/client';

import { setupWallet } from '../shared/setupWallet';

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

const wallet = setupWallet();

const defaultProfile = await client.profile.fetchDefault({
for: wallet.address,
});

console.log(`Default profile for wallet ${wallet.address}: `, {
id: defaultProfile?.id,
handle: defaultProfile?.handle,
});
}

main();
12 changes: 11 additions & 1 deletion examples/node/scripts/profile/linkHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ async function main() {
const wallet = setupWallet();
const client = await getAuthenticatedClientFromEthersWallet(wallet);

const ownedHandles = await client.wallet.ownedHandles({
for: wallet.address,
});

const profileId = await client.authentication.getProfileId();

console.log(`Handles owned by ${wallet.address}:`, ownedHandles);

console.log(`Linking handle ${ownedHandles.items[0].handle} to profile ${profileId}`);

await client.profile.linkHandle({
handle: 'HANDLE',
handle: ownedHandles.items[0].handle,
});
}

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

import { setupWallet } from '../../shared/setupWallet';

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

const wallet = setupWallet();

const allOwnedProfiles = await client.profile.fetchAll({
where: { ownedBy: [wallet.address] },
});

console.log(
`Profiles owned by address: ${wallet.address}: `,
allOwnedProfiles.items.map((i) => ({ id: i.id, handle: i.handle })),
);
}

main();
25 changes: 25 additions & 0 deletions examples/node/scripts/profile/setDefault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getAuthenticatedClientFromEthersWallet } from '../shared/getAuthenticatedClient';
import { getOwnedProfileId } from '../shared/getOwnedProfileId';
import { setupWallet } from '../shared/setupWallet';

async function main() {
const wallet = setupWallet();
const client = await getAuthenticatedClientFromEthersWallet(wallet);
const profileId = await getOwnedProfileId(client, wallet.address);

console.log(`Setting default profile for wallet ${wallet.address} to ${profileId}`);
await client.profile.setDefault({
profileId,
});

const defaultProfile = await client.profile.fetchDefault({
for: wallet.address,
});

console.log(`Default profile for wallet ${wallet.address}: `, {
id: defaultProfile?.id,
handle: defaultProfile?.handle,
});
}

main();
2 changes: 1 addition & 1 deletion examples/web-wagmi/src/publications/UseHidePublication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function HidePublicationButton({ publication }: HidePublicationButtonProps) {
if (publication.hidden) return null;

return (
<button onClick={hide} disabled={isPending}>
<button onClick={() => hide()} disabled={isPending}>
Hide
</button>
);
Expand Down
4 changes: 4 additions & 0 deletions examples/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
UseUpdateProfileManagers,
UseWhoActedOnPublication,
UseSetProfileMetadata,
UseOwnedHandles,
} from './profiles';
import {
PublicationsPage,
Expand All @@ -56,6 +57,7 @@ import {
UseReportPublication,
UseWhoReactedToPublication,
} from './publications';
import { UseNotInterestedToggle } from './publications/UseNotInterestedToggle';
import {
RevenuePage,
UseRevenueFromFollow,
Expand Down Expand Up @@ -116,6 +118,7 @@ export function App() {
<Route path="useBookmarkToggle" element={<UseBookmarkToggle />} />
<Route path="useMyBookmarks" element={<UseMyBookmarks />} />
<Route path="useOpenAction" element={<UseOpenAction />} />
<Route path="useNotInterestedToggle" element={<UseNotInterestedToggle />} />
</Route>

<Route path="/profiles">
Expand All @@ -140,6 +143,7 @@ export function App() {
<Route path="useProfileActionHistory" element={<UseProfileActionHistory />} />
<Route path="useSetProfileMetadata" element={<UseSetProfileMetadata />} />
<Route path="useUpdateFollowPolicy" element={<UseUpdateFollowPolicy />} />
<Route path="useOwnedHandles" element={<UseOwnedHandles />} />
</Route>

<Route path="/discovery">
Expand Down
7 changes: 7 additions & 0 deletions examples/web/src/profiles/ProfilesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ const profileHooks = [
description: `Update the follow policy for the logged-in Profile.`,
path: '/profiles/useUpdateFollowPolicy',
},
{
label: 'useOwnedHandles',
// label: 'useOwnedHandles & useLinkHandle & useUnlinkHandle',
// description: `Link and unlink handle from a profile.`,
description: `Fetch all handles owned by a wallet.`,
path: '/profiles/useOwnedHandles',
},
];

export function ProfilesPage() {
Expand Down
144 changes: 144 additions & 0 deletions examples/web/src/profiles/UseOwnedHandles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import {
EvmAddress,
Profile,
useLinkHandle,
useOwnedHandles,
useProfiles,
useUnlinkHandle,
} from '@lens-protocol/react-web';

import { UnauthenticatedFallback, WhenLoggedIn, WhenLoggedOut } from '../components/auth';
import { ErrorMessage } from '../components/error/ErrorMessage';
import { Loading } from '../components/loading/Loading';

type LinkHandleButtonProps = {
handle: string;
};

function LinkHandleButton({ handle }: LinkHandleButtonProps) {
const { execute, error, loading } = useLinkHandle();

return (
<>
<button onClick={() => execute({ handle })} disabled={loading} style={{ padding: '1px 6px' }}>
Link
</button>
{error && <p>{error.message}</p>}
</>
);
}

type UnlinkHandleButtonProps = {
handle: string;
};

function UnlinkHandleButton({ handle }: UnlinkHandleButtonProps) {
const { execute, error, loading } = useUnlinkHandle();

return (
<>
<button onClick={() => execute({ handle })} disabled={loading} style={{ padding: '1px 6px' }}>
Unlink
</button>
{error && <p>{error.message}</p>}
</>
);
}

function UseOwnedProfiles({ address }: { address: EvmAddress }) {
const {
data: profiles,
loading,
error,
} = useProfiles({
where: {
ownedBy: [address],
},
});

if (loading) return <Loading />;

if (error) return <ErrorMessage error={error} />;

return (
<div>
<h4>Owned profiles</h4>
<ul>
{profiles.map((p, index) => (
<li key={index}>
{p.id} {p.handle || 'NOT LINKED'}
</li>
))}
</ul>
</div>
);
}

// eslint-disable-next-line
function UseOwnedHandlesInner({ address }: { address: EvmAddress }) {
const {
data: handleResult,
loading,
error,
} = useOwnedHandles({
for: address,
});

if (loading) return <Loading />;

if (error) return <ErrorMessage error={error} />;

return (
<div>
<h4>Owned handles</h4>
<ul>
{handleResult.map((handle, index) => (
<li key={index}>
<div>{handle.handle}</div>
<LinkHandleButton handle={handle.handle} />{' '}
<UnlinkHandleButton handle={handle.handle} />
</li>
))}
</ul>
</div>
);
}

type ContentProps = {
address: EvmAddress;
profile: Profile;
};

function Content({ address, profile }: ContentProps) {
return (
<div>
<p>Wallet address: {address}.</p>
<p>
Active profile: {profile.id}. Current handle {profile.handle || 'NOT LINKED'}
</p>
<div style={{ display: 'flex' }}>
<UseOwnedProfiles address={address} />
{/* <UseOwnedHandlesInner address={address} /> */}
</div>
</div>
);
}

export function UseOwnedHandles() {
return (
<div>
<h1>
{/* <code>useOwnedHandles & useLinkHandle & useUnlinkHandle</code> */}
<code>useOwnedHandles</code>
</h1>

<WhenLoggedIn>
{({ address, profile }) => <Content address={address} profile={profile} />}
</WhenLoggedIn>

<WhenLoggedOut>
<UnauthenticatedFallback />
</WhenLoggedOut>
</div>
);
}
Loading

0 comments on commit 9b37358

Please sign in to comment.