Skip to content

Commit

Permalink
feat: add explorer + token page
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatteo23 committed Nov 28, 2024
1 parent d2886f8 commit f38e4cb
Show file tree
Hide file tree
Showing 29 changed files with 1,415 additions and 19 deletions.
Binary file modified bun.lockb
Binary file not shown.
13 changes: 13 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require("dotenv").config();

import type { Config } from "drizzle-kit";

export default {
schema: "./src/utils/schemas/db.schema.ts",
out: "./migrations",
dialect: "turso",
dbCredentials: {
url: process.env.TURSO_DATABASE_URL!,
authToken: process.env.TURSO_AUTH_TOKEN,
},
} satisfies Config;
30 changes: 30 additions & 0 deletions migrations/0000_groovy_shard.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- Current sql file was generated after introspecting the database
-- If you want to run this migration please uncomment this code before executing migrations
/*
CREATE TABLE `brianker_requests` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`status` text DEFAULT 'pending' NOT NULL,
`error_message` text,
`input_cast` text,
`brian_input_origin_wallet` text,
`brian_response` text,
`grok_response` text,
`redis_operation_id` text,
`created_at` text DEFAULT (CURRENT_TIMESTAMP),
`updated_at` text DEFAULT (CURRENT_TIMESTAMP)
);
--> statement-breakpoint
CREATE TABLE `token` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`address` text NOT NULL,
`name` text NOT NULL,
`ticker` text NOT NULL,
`requestedBy` integer NOT NULL,
`image` text NOT NULL,
`date_time` text NOT NULL,
`created_at` text DEFAULT (CURRENT_TIMESTAMP),
`updated_at` text DEFAULT (CURRENT_TIMESTAMP)
);
--> statement-breakpoint
CREATE UNIQUE INDEX `token_address_unique` ON `token` (`address`);
*/
181 changes: 181 additions & 0 deletions migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
{
"id": "00000000-0000-0000-0000-000000000000",
"prevId": "",
"version": "6",
"dialect": "sqlite",
"tables": {
"brianker_requests": {
"name": "brianker_requests",
"columns": {
"id": {
"autoincrement": true,
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"status": {
"default": "'pending'",
"autoincrement": false,
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true
},
"error_message": {
"autoincrement": false,
"name": "error_message",
"type": "text",
"primaryKey": false,
"notNull": false
},
"input_cast": {
"autoincrement": false,
"name": "input_cast",
"type": "text",
"primaryKey": false,
"notNull": false
},
"brian_input_origin_wallet": {
"autoincrement": false,
"name": "brian_input_origin_wallet",
"type": "text",
"primaryKey": false,
"notNull": false
},
"brian_response": {
"autoincrement": false,
"name": "brian_response",
"type": "text",
"primaryKey": false,
"notNull": false
},
"grok_response": {
"autoincrement": false,
"name": "grok_response",
"type": "text",
"primaryKey": false,
"notNull": false
},
"redis_operation_id": {
"autoincrement": false,
"name": "redis_operation_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"default": "(CURRENT_TIMESTAMP)",
"autoincrement": false,
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": false
},
"updated_at": {
"default": "(CURRENT_TIMESTAMP)",
"autoincrement": false,
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"compositePrimaryKeys": {},
"indexes": {},
"foreignKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"token": {
"name": "token",
"columns": {
"id": {
"autoincrement": true,
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true
},
"address": {
"autoincrement": false,
"name": "address",
"type": "text",
"primaryKey": false,
"notNull": true
},
"name": {
"autoincrement": false,
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"ticker": {
"autoincrement": false,
"name": "ticker",
"type": "text",
"primaryKey": false,
"notNull": true
},
"requestedBy": {
"autoincrement": false,
"name": "requestedBy",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"image": {
"autoincrement": false,
"name": "image",
"type": "text",
"primaryKey": false,
"notNull": true
},
"date_time": {
"autoincrement": false,
"name": "date_time",
"type": "text",
"primaryKey": false,
"notNull": true
},
"created_at": {
"default": "(CURRENT_TIMESTAMP)",
"autoincrement": false,
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": false
},
"updated_at": {
"default": "(CURRENT_TIMESTAMP)",
"autoincrement": false,
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"compositePrimaryKeys": {},
"indexes": {
"token_address_unique": {
"name": "token_address_unique",
"columns": [
"address"
],
"isUnique": true
}
},
"foreignKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
13 changes: 13 additions & 0 deletions migrations/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "6",
"when": 1732809637063,
"tag": "0000_groovy_shard",
"breakpoints": true
}
]
}
3 changes: 3 additions & 0 deletions migrations/relations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { relations } from "drizzle-orm/relations";
import { } from "./schema";

33 changes: 33 additions & 0 deletions migrations/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { sqliteTable, AnySQLiteColumn, integer, text, uniqueIndex } from "drizzle-orm/sqlite-core"
import { sql } from "drizzle-orm"

export const briankerRequests = sqliteTable("brianker_requests", {
id: integer().primaryKey({ autoIncrement: true }).notNull(),
status: text().default("pending").notNull(),
errorMessage: text("error_message"),
inputCast: text("input_cast"),
brianInputOriginWallet: text("brian_input_origin_wallet"),
brianResponse: text("brian_response"),
grokResponse: text("grok_response"),
redisOperationId: text("redis_operation_id"),
createdAt: text("created_at").default("sql`(CURRENT_TIMESTAMP)`"),
updatedAt: text("updated_at").default("sql`(CURRENT_TIMESTAMP)`"),
});

export const token = sqliteTable("token", {
id: integer().primaryKey({ autoIncrement: true }).notNull(),
address: text().notNull(),
name: text().notNull(),
ticker: text().notNull(),
requestedBy: integer().notNull(),
image: text().notNull(),
dateTime: text("date_time").notNull(),
createdAt: text("created_at").default("sql`(CURRENT_TIMESTAMP)`"),
updatedAt: text("updated_at").default("sql`(CURRENT_TIMESTAMP)`"),
},
(table) => {
return {
addressUnique: uniqueIndex("token_address_unique").on(table.address),
}
});

14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:studio": "drizzle-kit studio",
"db:push": "drizzle-kit push",
"db:pull": "drizzle-kit pull"
},
"dependencies": {
"@lens-protocol/client": "^2.0.0",
"@libsql/client": "^0.14.0",
"@radix-ui/react-select": "^2.1.2",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.4",
"@tanstack/react-table": "^8.20.5",
"@vercel/kv": "^1.0.1",
"@xmtp/frames-validator": "^0.6.1",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"drizzle-orm": "^0.36.4",
"framer-motion": "^11.12.0",
"frames.js": "^0.20.0",
"lucide-react": "^0.462.0",
"maiton": "^0.0.2",
"mini-svg-data-uri": "^1.4.4",
"next": "^14.1.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
59 changes: 59 additions & 0 deletions src/app/api/token/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { getTokenFromAddress } from "@/utils/db";
import { NextRequest, NextResponse } from "next/server";

export const GET = async (req: NextRequest) => {
try {
const url = new URL(req.url);
const searchParams = new URLSearchParams(url.searchParams);

const tokenAddress = searchParams.get("address");

if (!tokenAddress) {
return NextResponse.json(
{
status: "nok",
error: {
message: "Address missing",
},
},
{
status: 400,
statusText: "Bad Request",
}
);
}

const token = await getTokenFromAddress(tokenAddress);
if (!token) {
return NextResponse.json(
{
status: "nok",
error: {
message: "Token not found",
},
},
{
status: 404,
statusText: "Not Found",
}
);
}
return NextResponse.json({
status: "ok",
data: token,
});
} catch (error) {
return NextResponse.json(
{
status: "nok",
error: {
message: "Internal Server Error",
},
},
{
status: 500,
statusText: "Internal Server Error",
}
);
}
};
Loading

0 comments on commit f38e4cb

Please sign in to comment.