Skip to content

Commit

Permalink
Merge pull request #446 from ourzora/frame-transactions
Browse files Browse the repository at this point in the history
Add frame transactions
  • Loading branch information
neokry authored Mar 9, 2024
2 parents 7c06b66 + 1f78d48 commit 3c9156e
Show file tree
Hide file tree
Showing 5 changed files with 2,154 additions and 728 deletions.
1 change: 1 addition & 0 deletions apps/web/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
14 changes: 8 additions & 6 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@fontsource/inter": "4.5.10",
"@fontsource/londrina-solid": "^4.5.9",
"@rainbow-me/rainbowkit": "^1.3.1",
"@sentry/nextjs": "^7.15.0",
"@sentry/nextjs": "^7.105.0",
"@types/lodash": "^4.14.186",
"@types/react-portal": "^4.0.4",
"@types/tinycolor2": "^1.4.3",
Expand All @@ -39,28 +39,30 @@
"flatpickr": "^4.6.13",
"formik": "^2.2.9",
"framer-motion": "^6.3.3",
"frog": "^0.5.5",
"graphql": "^16.6.0",
"graphql-request": "^4.3.0",
"graphql-tag": "^2.12.6",
"hono": "^4.0.9",
"html-react-parser": "^3.0.9",
"ioredis": "^5.2.3",
"ipfs-http-client": "^59.0.0",
"ipfs-service": "workspace:*",
"lanyard": "^1.1.2",
"lodash": "^4.17.21",
"multiformats": "9.9.0",
"next": "^13.0.3",
"next": "^14.1.2",
"nextjs-progressbar": "^0.0.16",
"raw-loader": "^4.0.2",
"react": "^18.2.0",
"react-content-loader": "^6.0.2",
"react-dom": "^18.2.0",
"react-markdown": "^8.0.5",
"react-markdown": "^9.0.1",
"react-mde": "^11.5.0",
"react-portal": "^4.2.2",
"rehype-raw": "^6.1.1",
"rehype-sanitize": "^5.0.1",
"remark-gfm": "^3.0.1",
"rehype-raw": "^7.0.0",
"rehype-sanitize": "^6.0.0",
"remark-gfm": "^4.0.0",
"sharp": "^0.32.6",
"swr": "^1.3.0",
"tinycolor2": "^1.4.2",
Expand Down
113 changes: 113 additions & 0 deletions apps/web/src/app/api/frames/[[...routes]]/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/** @jsxImportSource frog/jsx */
import { Frog } from 'frog'
import { handle } from 'frog/next'
import { isAddress, parseEther } from 'viem'

import { auctionAbi, governorAbi } from 'src/data/contract/abis'
import { AddressType, BytesType, CHAIN_ID } from 'src/typings'

const app = new Frog({
basePath: '/api/frames',
})

app.transaction('/bid', async (c) => {
try {
const { inputText, req } = c
const { chainId, auctionContract, tokenId, amount, referral } = req.query()

if (!tokenId) return new Response('Invalid tokenId', { status: 400 })

const tokenIdParsed = BigInt(tokenId)
const chainIdParsed = parseInt(chainId)

let bidAmount: bigint | undefined

if (amount) bidAmount = parseEther(amount)
else if (inputText) bidAmount = parseEther(inputText)

if (!bidAmount) return new Response('Invalid bid amount', { status: 400 })

if (
chainIdParsed !== CHAIN_ID.OPTIMISM &&
chainIdParsed !== CHAIN_ID.ZORA &&
chainIdParsed !== CHAIN_ID.BASE
)
return new Response('Invalid chain id', { status: 400 })

const contract = {
abi: auctionAbi,
chainId: `eip155:${chainIdParsed}`,
to: auctionContract as AddressType,
} as const

if (referral) {
if (!isAddress(referral)) return new Response('Invalid referral', { status: 400 })

return c.contract({
...contract,
functionName: 'createBidWithReferral',
value: bidAmount,
args: [tokenIdParsed, referral as AddressType],
})
}

return c.contract({
...contract,
functionName: 'createBid',
value: bidAmount,
args: [tokenIdParsed],
})
} catch (err) {
return new Response((err as Error).message, { status: 500 })
}
})

app.transaction('/vote', async (c) => {
try {
const { inputText, req } = c
const { chainId, governorContract, support, proposalId, reason } = req.query()
const chainIdParsed = parseInt(chainId)

let reasonText
if (reason) reasonText = reason
else if (inputText) reasonText = inputText

const supportParsed = BigInt(support)

// 0 = Against, 1 = For, 2 = Abstain
if (supportParsed !== 0n && supportParsed !== 1n && supportParsed !== 2n)
return new Response('Invalid support value', { status: 400 })

if (
chainIdParsed !== CHAIN_ID.OPTIMISM &&
chainIdParsed !== CHAIN_ID.ZORA &&
chainIdParsed !== CHAIN_ID.BASE
)
return new Response('Invalid chain id', { status: 400 })

const contract = {
abi: governorAbi,
chainId: `eip155:${chainIdParsed}`,
to: governorContract as AddressType,
} as const

if (reasonText) {
return c.contract({
...contract,
functionName: 'castVoteWithReason',
args: [proposalId as BytesType, supportParsed, reasonText],
})
}

return c.contract({
...contract,
functionName: 'castVote',
args: [proposalId as BytesType, supportParsed],
})
} catch (err) {
return new Response((err as Error).message, { status: 500 })
}
})

export const GET = handle(app)
export const POST = handle(app)
16 changes: 13 additions & 3 deletions apps/web/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"exclude": ["node_modules"],
"exclude": [
"node_modules"
],
"extends": "tsconfig/nextjs.json",
"compilerOptions": {
"strict": true,
Expand All @@ -8,13 +10,21 @@
"noUnusedLocals": false,
"skipLibCheck": true,
"noUnusedParameters": false,
"types": ["vitest/globals"]
"types": [
"vitest/globals"
],
"plugins": [
{
"name": "next"
}
]
},
"include": [
"typings",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"node_modules/eslint-plugin-react/lib/types.d.ts"
"node_modules/eslint-plugin-react/lib/types.d.ts",
".next/types/**/*.ts"
]
}
Loading

0 comments on commit 3c9156e

Please sign in to comment.