Skip to content

Commit

Permalink
Merge branch 'next' into T-23290/js-action-create-all-the-app-queries
Browse files Browse the repository at this point in the history
  • Loading branch information
juangm committed Dec 18, 2024
2 parents fba1e3c + 38ef35c commit 668ecca
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Viem Onboarding Example
# Create an App

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/lens-protocol/lens-sdk/tree/next/examples/viem-onboarding)
[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/lens-protocol/lens-sdk/tree/next/examples/create-app)
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
</head>
<body>
<h1>Viem Onboarding Example</h1>
<h1>Create an App</h1>
<div id="app">Loading...</div>
<script type="module">
import out from './index.ts';
Expand Down
66 changes: 66 additions & 0 deletions examples/create-app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'viem/window';

import { chains } from '@lens-network/sdk/viem';
import { PublicClient, testnet as protocolTestnet } from '@lens-protocol/client';
import { createApp, fetchApp } from '@lens-protocol/client/actions';
import { handleWith } from '@lens-protocol/client/viem';
import { Platform, app } from '@lens-protocol/metadata';
import { StorageClient, testnet as storageTestnet } from '@lens-protocol/storage-node-client';
import { type Address, createWalletClient, custom } from 'viem';

const chain = chains.testnet;

// hoist account
const [address] = (await window.ethereum!.request({ method: 'eth_requestAccounts' })) as [Address];

const walletClient = createWalletClient({
account: address,
chain,
transport: custom(window.ethereum!),
});

const client = PublicClient.create({
environment: protocolTestnet,
});

const sessionClient = await client
.login({
builder: {
address: walletClient.account.address,
},
signMessage: async (message) => walletClient.signMessage({ message }),
})
.match(
(result) => result,
(error) => {
throw error;
},
);

const storageClient = StorageClient.create(storageTestnet);

const metadata = app({
name: 'My App',
url: 'https://example.com',
description: 'My app description',
platforms: [Platform.WEB],
developer: '[email protected]',
});

const { uri } = await storageClient.uploadAsJson(metadata);

const created = await createApp(sessionClient, {
metadataUri: uri,
verification: false, // will become optional soon
})
.andThen(handleWith(walletClient))
.andThen(sessionClient.waitForTransaction)
.andThen((txHash) => fetchApp(sessionClient, { txHash }))
.match(
(result) => result,
(error) => {
throw error;
},
);

export default [`<h2>${created?.metadata?.name}</h2>`, `<p>Address: ${await created?.address}</p>`];
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "example-viem-onboarding",
"name": "example-create-app",
"private": true,
"type": "module",
"scripts": {
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions examples/user-onboarding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# User Onboarding

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/lens-protocol/lens-sdk/tree/next/examples/user-onboarding)
18 changes: 18 additions & 0 deletions examples/user-onboarding/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
</head>
<body>
<h1>User Onboarding Example</h1>
<div id="app">Loading...</div>
<script type="module">
import out from './index.ts';
document.querySelector('#app').innerHTML = Array.isArray(out)
? out.map((x) => `<div style="margin-bottom: 16px;">${x}</div>`).join('')
: out;
</script>
</body>
</html>
File renamed without changes.
19 changes: 19 additions & 0 deletions examples/user-onboarding/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "example-user-onboarding",
"private": true,
"type": "module",
"scripts": {
"dev": "vite"
},
"dependencies": {
"@lens-network/sdk": "canary",
"@lens-protocol/client": "canary",
"@lens-protocol/metadata": "next",
"@lens-protocol/storage-node-client": "next",
"viem": "^2.21.55"
},
"devDependencies": {
"typescript": "^5.6.3",
"vite": "^5.4.11"
}
}
19 changes: 19 additions & 0 deletions examples/user-onboarding/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["ESNext", "DOM"],
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true
},
"include": ["./"]
}
4 changes: 2 additions & 2 deletions packages/client/src/actions/timeline.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
AnyPost,
Paginated,
Post,
TimelineHighlightsRequest,
TimelineItem,
TimelineRequest,
Expand Down Expand Up @@ -47,6 +47,6 @@ export function fetchTimeline(
export function fetchTimelineHighlights(
client: AnyClient,
request: TimelineHighlightsRequest,
): ResultAsync<Paginated<Post> | null, UnexpectedError> {
): ResultAsync<Paginated<AnyPost>, UnexpectedError> {
return client.query(TimelineHighlightsQuery, { request });
}
34 changes: 23 additions & 11 deletions packages/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2222,18 +2222,31 @@ type GroupGatedFeedRule {
group: Group!
}

type GroupMember {
account: Account!
lastActiveAt: DateTime!
joinedAt: DateTime!
}

input GroupMembersFilterRequest {
"""The optional filter to narrow members by search query."""
searchBy: UsernameSearchInput
}

enum GroupMembersOrderBy {
LAST_JOINED
FIRST_JOINED
LAST_ACTIVE
ACCOUNT_SCORE
}

input GroupMembersRequest {
"""The group"""
group: EvmAddress!
filter: GroupMembersFilterRequest

"""The order by."""
orderBy: GroupMembersOrderBy! = LAST_JOINED
orderBy: GroupMembersOrderBy! = ACCOUNT_SCORE

"""The page size."""
pageSize: PageSize! = FIFTY
Expand Down Expand Up @@ -3672,8 +3685,6 @@ type NamespacesResult {
pageInfo: PaginatedResultInfo!
}

union NestedPost = Post | PostReference

type NetworkAddress {
address: EvmAddress!
chainId: Int!
Expand Down Expand Up @@ -3868,6 +3879,11 @@ type PaginatedGraphsResult {
pageInfo: PaginatedResultInfo!
}

type PaginatedGroupMembersResult {
items: [GroupMember!]!
pageInfo: PaginatedResultInfo!
}

type PaginatedGroupsResult {
"""The groups"""
items: [Group!]!
Expand Down Expand Up @@ -3975,9 +3991,9 @@ type Post {
timestamp: DateTime!
app: App
metadata: PostMetadata!
root: NestedPost
quoteOf: NestedPost
commentOn: NestedPost
root: Post
quoteOf: Post
commentOn: Post
actions: [PostAction!]!
operations: LoggedInPostOperations
stats: PostStats!
Expand Down Expand Up @@ -4113,10 +4129,6 @@ input PostReactionsRequest {
cursor: Cursor
}

type PostReference {
id: PostId!
}

enum PostReferenceType {
COMMENT_ON
REPOST_OF
Expand Down Expand Up @@ -4382,7 +4394,7 @@ type Query {
groups(request: GroupsRequest!): PaginatedGroupsResult!

"""Get the members of the group"""
groupMembers(request: GroupMembersRequest!): PaginatedAccountsResult!
groupMembers(request: GroupMembersRequest!): PaginatedGroupMembersResult!

"""Get the number of members in a Group"""
groupStats(request: GroupStatsRequest!): GroupStatsResponse!
Expand Down
28 changes: 4 additions & 24 deletions packages/graphql/src/fragments/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,6 @@ export const LoggedInPostOperationsFragment = graphql(
);
export type LoggedInPostOperations = FragmentOf<typeof LoggedInPostOperationsFragment>;

export const PostReferenceFragment = graphql(
`fragment PostReference on PostReference {
id
}`,
);
export type PostReference = FragmentOf<typeof PostReferenceFragment>;

export const ReferencedPostFragment = graphql(
`fragment ReferencedPost on Post {
__typename
Expand Down Expand Up @@ -219,19 +212,6 @@ export const ReferencedPostFragment = graphql(
],
);

export const NestedPostFragment = graphql(
`fragment NestedPost on NestedPost {
...on Post {
...ReferencedPost
}
...on PostReference {
...PostReference
}
}`,
[PostReferenceFragment, ReferencedPostFragment],
);
export type NestedPost = FragmentOf<typeof NestedPostFragment>;

export const PostFragment = graphql(
`fragment Post on Post {
__typename
Expand All @@ -250,13 +230,13 @@ export const PostFragment = graphql(
...PostMetadata
}
root {
...NestedPost
...ReferencedPost
}
quoteOf {
...NestedPost
...ReferencedPost
}
commentOn {
...NestedPost
...ReferencedPost
}
actions {
...PostAction
Expand All @@ -272,7 +252,7 @@ export const PostFragment = graphql(
FeedFragment,
PostMetadataFragment,
PostActionFragment,
NestedPostFragment,
ReferencedPostFragment,
LoggedInPostOperationsFragment,
],
);
Expand Down
Loading

0 comments on commit 668ecca

Please sign in to comment.