-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Waiting] mod: Lit protocol token gated casts #92
Draft
davidfurlong
wants to merge
6
commits into
main
Choose a base branch
from
feat/token-gated-casts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49543ce
feat: add select element, add lit-protocol miniapps, add metadata by …
davidfurlong 076b879
chore: commit progress
davidfurlong fc19161
miniapp(zora-minter): initial commit
stephancill 0cafd6d
chore: commit progress
davidfurlong 4344462
chore: add combobox, textarea, token gating mvp
davidfurlong 3543d13
fix: pr comment
davidfurlong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"typescript.disableAutomaticTypeAcquisition": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
module.exports = { | ||
reactStrictMode: true, | ||
transpilePackages: ["@mod-protocol/react"], | ||
transpilePackages: [ | ||
"@mod-protocol/react", | ||
// Fixes https://discord.com/channels/896185694857343026/1174716239508156496 | ||
"@lit-protocol/bls-sdk", | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
examples/api/src/app/api/cast-embeds-metadata/by-url/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
export const dynamic = "force-dynamic"; | ||
|
||
import { NextResponse, NextRequest } from "next/server"; | ||
import { NFTMetadata, UrlMetadata } from "@mod-protocol/core"; | ||
import { db } from "../lib/db"; | ||
import { chainById } from "../lib/chain-index"; | ||
|
||
export async function POST(request: NextRequest) { | ||
try { | ||
const urls = await request.json(); | ||
|
||
// todo: consider normalizing urls here? currently clients are responsible for doing this. | ||
|
||
// Fetch metadata for each url | ||
const metadata = await db | ||
.selectFrom("url_metadata") | ||
.where("url_metadata.url", "in", urls) | ||
.leftJoin( | ||
"nft_metadata", | ||
"nft_metadata.id", | ||
"url_metadata.nft_metadata_id" | ||
) | ||
.leftJoin( | ||
"nft_collections", | ||
"url_metadata.nft_collection_id", | ||
"nft_collections.id" | ||
) | ||
.select([ | ||
/* Select all columns with aliases to prevent collisions */ | ||
|
||
// URL metadata | ||
"url_metadata.image_url as url_image_url", | ||
"url_metadata.image_height as url_image_height", | ||
"url_metadata.image_width as url_image_width", | ||
"url_metadata.alt as url_alt", | ||
"url_metadata.url as url_url", | ||
"url_metadata.description as url_description", | ||
"url_metadata.title as url_title", | ||
"url_metadata.publisher as url_publisher", | ||
"url_metadata.logo_url as url_logo_url", | ||
"url_metadata.mime_type as url_mime_type", | ||
"url_metadata.nft_collection_id as nft_collection_id", | ||
"url_metadata.nft_metadata_id as nft_metadata_id", | ||
|
||
// NFT Collection metadata | ||
"nft_collections.creator_address as collection_creator_address", | ||
"nft_collections.description as collection_description", | ||
"nft_collections.image_url as collection_image_url", | ||
"nft_collections.item_count as collection_item_count", | ||
"nft_collections.mint_url as collection_mint_url", | ||
"nft_collections.name as collection_name", | ||
"nft_collections.open_sea_url as collection_open_sea_url", | ||
"nft_collections.owner_count as collection_owner_count", | ||
|
||
// NFT metadata | ||
"nft_metadata.token_id as nft_token_id", | ||
"nft_metadata.media_url as nft_media_url", | ||
]) | ||
.execute(); | ||
|
||
const rowsFormatted = metadata.map((row) => { | ||
let nftMetadata: NFTMetadata | undefined; | ||
|
||
if (row.nft_collection_id) { | ||
const [, , prefixAndChainId, prefixAndContractAddress, tokenId] = | ||
row.nft_collection_id.split("/"); | ||
|
||
const [, chainId] = prefixAndChainId.split(":"); | ||
const [, contractAddress] = prefixAndContractAddress.split(":"); | ||
|
||
const chain = chainById[chainId]; | ||
|
||
nftMetadata = { | ||
mediaUrl: row.nft_media_url || undefined, | ||
tokenId: row.nft_token_id || undefined, | ||
collection: { | ||
chain: chain.network, | ||
contractAddress, | ||
creatorAddress: row.collection_creator_address, | ||
description: row.collection_description, | ||
id: row.nft_collection_id, | ||
imageUrl: row.collection_image_url, | ||
itemCount: row.collection_item_count, | ||
mintUrl: row.collection_mint_url, | ||
name: row.collection_name, | ||
openSeaUrl: row.collection_open_sea_url || undefined, | ||
ownerCount: row.collection_owner_count || undefined, | ||
creator: undefined, // TODO: Look up farcaster user by FID | ||
}, | ||
}; | ||
} | ||
|
||
const urlMetadata: UrlMetadata = { | ||
image: row.url_image_url | ||
? { | ||
url: row.url_image_url, | ||
height: row.url_image_height || undefined, | ||
width: row.url_image_width || undefined, | ||
} | ||
: undefined, | ||
alt: row.url_alt || undefined, | ||
description: row.url_description || undefined, | ||
title: row.url_title || undefined, | ||
publisher: row.url_publisher || undefined, | ||
logo: row.url_logo_url ? { url: row.url_logo_url } : undefined, | ||
mimeType: row.url_mime_type || undefined, | ||
nft: nftMetadata, | ||
}; | ||
|
||
return { | ||
url: row.url_url, | ||
urlMetadata, | ||
}; | ||
}); | ||
|
||
const metadataByUrl: { | ||
[key: string]: UrlMetadata; | ||
} = rowsFormatted.reduce((acc, cur) => { | ||
return { | ||
...acc, | ||
[cur.url]: cur.urlMetadata, | ||
}; | ||
}, {}); | ||
|
||
return NextResponse.json(metadataByUrl); | ||
} catch (err) { | ||
console.error(err); | ||
return NextResponse.json({ message: err.message }, { status: err.status }); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider renaming these endpoints. I suggest
/embed-metadata/by-casts
and/embed-metadata/by-urls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, but that means no backwards compat; will have to let integrators know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, but that means no backwards compat; will have to let integrators know