-
Notifications
You must be signed in to change notification settings - Fork 531
Add webhooks feature to Insight dashboard #6929
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
Open
AmineAfia
wants to merge
1
commit into
main
Choose a base branch
from
Add_webhooks_feature_to_Insight_dashboard
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.
+2,519
−79
Open
Changes from all commits
Commits
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 hidden or 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,157 @@ | ||
"use server"; | ||
|
||
import { getAuthToken } from "app/(app)/api/lib/getAuthToken"; | ||
import { THIRDWEB_INSIGHT_API_DOMAIN } from "constants/urls"; | ||
|
||
export interface WebhookResponse { | ||
id: string; | ||
name: string; | ||
team_id: string; | ||
project_id: string; | ||
webhook_url: string; | ||
webhook_secret: string; | ||
filters: WebhookFilters; | ||
suspended_at: string | null; | ||
suspended_reason: string | null; | ||
disabled: boolean; | ||
created_at: string; | ||
updated_at: string | null; | ||
} | ||
|
||
export interface WebhookFilters { | ||
"v1.events"?: { | ||
chain_ids?: string[]; | ||
addresses?: string[]; | ||
signatures?: Array<{ | ||
sig_hash: string; | ||
abi?: string; | ||
params?: Record<string, unknown>; | ||
}>; | ||
}; | ||
"v1.transactions"?: { | ||
chain_ids?: string[]; | ||
from_addresses?: string[]; | ||
to_addresses?: string[]; | ||
signatures?: Array<{ | ||
sig_hash: string; | ||
abi?: string; | ||
params?: string[]; | ||
}>; | ||
}; | ||
} | ||
|
||
interface CreateWebhookPayload { | ||
name: string; | ||
webhook_url: string; | ||
filters: WebhookFilters; | ||
} | ||
|
||
interface WebhooksListResponse { | ||
data: WebhookResponse[]; | ||
} | ||
|
||
interface WebhookSingleResponse { | ||
data: WebhookResponse; | ||
} | ||
|
||
interface TestWebhookPayload { | ||
webhook_url: string; | ||
type?: "event" | "transaction"; | ||
} | ||
|
||
interface TestWebhookResponse { | ||
success: boolean; | ||
} | ||
|
||
export async function createWebhook( | ||
payload: CreateWebhookPayload, | ||
clientId: string, | ||
): Promise<WebhookSingleResponse> { | ||
const authToken = await getAuthToken(); | ||
const response = await fetch(`${THIRDWEB_INSIGHT_API_DOMAIN}/v1/webhooks`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"x-client-id": clientId, | ||
Authorization: `Bearer ${authToken}`, | ||
}, | ||
body: JSON.stringify(payload), | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorText = await response.text(); | ||
throw new Error(`Failed to create webhook: ${errorText}`); | ||
} | ||
|
||
return await response.json(); | ||
} | ||
|
||
export async function getWebhooks( | ||
clientId: string, | ||
): Promise<WebhooksListResponse> { | ||
const authToken = await getAuthToken(); | ||
const response = await fetch(`${THIRDWEB_INSIGHT_API_DOMAIN}/v1/webhooks`, { | ||
method: "GET", | ||
headers: { | ||
"x-client-id": clientId, | ||
Authorization: `Bearer ${authToken}`, | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorText = await response.text(); | ||
throw new Error(`Failed to get webhooks: ${errorText}`); | ||
} | ||
|
||
return await response.json(); | ||
} | ||
|
||
export async function deleteWebhook( | ||
webhookId: string, | ||
clientId: string, | ||
): Promise<WebhookSingleResponse> { | ||
const authToken = await getAuthToken(); | ||
const response = await fetch( | ||
`${THIRDWEB_INSIGHT_API_DOMAIN}/v1/webhooks/${webhookId}`, | ||
{ | ||
method: "DELETE", | ||
headers: { | ||
"x-client-id": clientId, | ||
Authorization: `Bearer ${authToken}`, | ||
}, | ||
}, | ||
); | ||
|
||
if (!response.ok) { | ||
const errorText = await response.text(); | ||
throw new Error(`Failed to delete webhook: ${errorText}`); | ||
} | ||
|
||
return await response.json(); | ||
} | ||
|
||
export async function testWebhook( | ||
payload: TestWebhookPayload, | ||
clientId: string, | ||
): Promise<TestWebhookResponse> { | ||
const authToken = await getAuthToken(); | ||
const response = await fetch( | ||
`${THIRDWEB_INSIGHT_API_DOMAIN}/v1/webhooks/test`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"x-client-id": clientId, | ||
Authorization: `Bearer ${authToken}`, | ||
}, | ||
body: JSON.stringify(payload), | ||
}, | ||
); | ||
|
||
if (!response.ok) { | ||
const errorText = await response.text(); | ||
throw new Error(`Failed to test webhook: ${errorText}`); | ||
} | ||
|
||
return await response.json(); | ||
} |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -165,7 +165,9 @@ export const MultiSelect = forwardRef<HTMLButtonElement, MultiSelectProps>( | |
{props.customTrigger || ( | ||
<Button | ||
ref={ref} | ||
{...props} | ||
{...(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this added? |
||
return { ...props }; | ||
})()} | ||
onClick={handleTogglePopover} | ||
className={cn( | ||
"flex h-auto min-h-10 w-full items-center justify-between rounded-md border border-border bg-inherit p-3 hover:bg-inherit", | ||
|
108 changes: 108 additions & 0 deletions
108
apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/insight/InsightPageLayout.tsx
This file contains hidden or 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,108 @@ | ||
"use client"; | ||
|
||
import { TabPathLinks } from "@/components/ui/tabs"; | ||
import { FooterLinksSection } from "../components/footer/FooterLinksSection"; | ||
|
||
export function InsightPageLayout(props: { | ||
projectSlug: string; | ||
projectId: string; | ||
teamSlug: string; | ||
children: React.ReactNode; | ||
}) { | ||
const insightLayoutSlug = `/team/${props.teamSlug}/${props.projectSlug}/insight`; | ||
|
||
return ( | ||
<div className="flex grow flex-col"> | ||
{/* header */} | ||
<div className="pt-4 lg:pt-6"> | ||
<div className="container flex max-w-7xl flex-col gap-4"> | ||
<div> | ||
<h1 className="mb-1 font-semibold text-2xl tracking-tight lg:text-3xl"> | ||
Insight | ||
</h1> | ||
<p className="text-muted-foreground text-sm"> | ||
APIs to retrieve blockchain data from any EVM chain, enrich it | ||
with metadata, and transform it using custom logic | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<div className="h-4" /> | ||
|
||
{/* Nav */} | ||
<TabPathLinks | ||
scrollableClassName="container max-w-7xl" | ||
links={[ | ||
{ | ||
name: "Overview", | ||
path: `${insightLayoutSlug}`, | ||
exactMatch: true, | ||
}, | ||
{ | ||
name: "Webhooks", | ||
path: `${insightLayoutSlug}/webhooks`, | ||
}, | ||
]} | ||
/> | ||
</div> | ||
|
||
{/* content */} | ||
<div className="h-6" /> | ||
<div className="container flex max-w-7xl grow flex-col gap-6"> | ||
<div>{props.children}</div> | ||
</div> | ||
<div className="h-20" /> | ||
|
||
{/* footer */} | ||
<div className="border-border border-t"> | ||
<div className="container max-w-7xl"> | ||
<InsightFooter /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
function InsightFooter() { | ||
return ( | ||
<FooterLinksSection | ||
left={{ | ||
title: "Documentation", | ||
links: [ | ||
{ | ||
label: "Overview", | ||
href: "https://portal.thirdweb.com/insight", | ||
}, | ||
{ | ||
label: "API Reference", | ||
href: "https://insight-api.thirdweb.com/reference", | ||
}, | ||
], | ||
}} | ||
center={{ | ||
title: "Tutorials", | ||
links: [ | ||
{ | ||
label: | ||
"Blockchain Data on Any EVM - Quick and Easy REST APIs for Onchain Data", | ||
href: "https://www.youtube.com/watch?v=U2aW7YIUJVw", | ||
}, | ||
{ | ||
label: "Build a Whale Alerts Telegram Bot with Insight", | ||
href: "https://www.youtube.com/watch?v=HvqewXLVRig", | ||
}, | ||
], | ||
}} | ||
right={{ | ||
title: "Demos", | ||
links: [ | ||
{ | ||
label: "API Playground", | ||
href: "https://playground.thirdweb.com/insight", | ||
}, | ||
], | ||
}} | ||
trackingCategory="insight" | ||
/> | ||
); | ||
} |
34 changes: 34 additions & 0 deletions
34
apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/insight/layout.tsx
This file contains hidden or 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,34 @@ | ||
import { getProject } from "@/api/projects"; | ||
import { getTeamBySlug } from "@/api/team"; | ||
import { redirect } from "next/navigation"; | ||
import { InsightPageLayout } from "./InsightPageLayout"; | ||
|
||
export default async function Layout(props: { | ||
params: Promise<{ team_slug: string; project_slug: string }>; | ||
children: React.ReactNode; | ||
}) { | ||
const { team_slug, project_slug } = await props.params; | ||
|
||
const [team, project] = await Promise.all([ | ||
getTeamBySlug(team_slug), | ||
getProject(team_slug, project_slug), | ||
]); | ||
|
||
if (!team) { | ||
redirect("/team"); | ||
} | ||
|
||
if (!project) { | ||
redirect(`/team/${team_slug}`); | ||
} | ||
|
||
return ( | ||
<InsightPageLayout | ||
projectSlug={project.slug} | ||
teamSlug={team_slug} | ||
projectId={project.id} | ||
> | ||
{props.children} | ||
</InsightPageLayout> | ||
); | ||
} |
Oops, something went wrong.
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.
Don't throw errors in server actions - You won't be able to see them in client component (you will only be able to see errors in local dev server but not in vercel preview or production environments)
If you want to return error message, you have to return the error message manually
Example: