Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 58 additions & 51 deletions apps/dashboard/src/@3rdweb-sdk/react/hooks/useEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import type { ResultItem } from "components/engine/system-metrics/components/StatusCodes";
import { THIRDWEB_API_HOST } from "constants/urls";
import type { EngineBackendWalletType } from "lib/engine";
import { useState } from "react";
import { useActiveAccount, useActiveWalletChain } from "thirdweb/react";
import invariant from "tiny-invariant";
Expand Down Expand Up @@ -111,10 +112,16 @@ export function useEngineBackendWallets(instance: string) {
});
}

type EngineFeature =
| "KEYPAIR_AUTH"
| "CONTRACT_SUBSCRIPTIONS"
| "IP_ALLOWLIST"
| "HETEROGENEOUS_WALLET_TYPES";

interface EngineSystemHealth {
status: string;
engineVersion?: string;
features?: string[];
features?: EngineFeature[];
}

export function useEngineSystemHealth(
Expand All @@ -138,6 +145,18 @@ export function useEngineSystemHealth(
});
}

// Helper function to check if a feature is supported.
export function useHasEngineFeature(
instanceUrl: string,
feature: EngineFeature,
) {
const query = useEngineSystemHealth(instanceUrl);
return {
query,
isSupported: !!query.data?.features?.includes(feature),
};
}

interface EngineSystemQueueMetrics {
result: {
queued: number;
Expand Down Expand Up @@ -188,17 +207,15 @@ export function useEngineLatestVersion() {
}

interface UpdateVersionInput {
engineId: string;
deploymentId: string;
serverVersion: string;
}

export function useEngineUpdateServerVersion() {
return useMutation({
mutationFn: async (input: UpdateVersionInput) => {
invariant(input.engineId, "engineId is required");

const res = await fetch(
`${THIRDWEB_API_HOST}/v2/engine/${input.engineId}/infrastructure`,
`${THIRDWEB_API_HOST}/v2/engine/deployments/${input.deploymentId}/infrastructure`,
{
method: "PUT",
headers: {
Expand Down Expand Up @@ -401,29 +418,22 @@ export function useEngineTransactions(instance: string, autoUpdate: boolean) {
});
}

type WalletConfig =
| {
type: "local";
}
| {
type: "aws-kms";
awsAccessKeyId: string;
awsSecretAccessKey: string;
awsRegion: string;
}
| {
type: "gcp-kms";
gcpApplicationProjectId: string;
gcpKmsLocationId: string;
gcpKmsKeyRingId: string;
gcpApplicationCredentialEmail: string;
gcpApplicationCredentialPrivateKey: string;
};
export interface WalletConfigResponse {
type: EngineBackendWalletType;

awsAccessKeyId?: string | null;
awsRegion?: string | null;

gcpApplicationProjectId?: string | null;
gcpKmsLocationId?: string | null;
gcpKmsKeyRingId?: string | null;
gcpApplicationCredentialEmail?: string | null;
}

export function useEngineWalletConfig(instance: string) {
const token = useLoggedInUser().user?.jwt ?? null;

return useQuery({
return useQuery<WalletConfigResponse>({
queryKey: engineKeys.walletConfig(instance),
queryFn: async () => {
const res = await fetch(`${instance}configuration/wallets`, {
Expand All @@ -432,8 +442,7 @@ export function useEngineWalletConfig(instance: string) {
});

const json = await res.json();

return (json.result as WalletConfig) || {};
return json.result;
},
enabled: !!instance && !!token,
});
Expand Down Expand Up @@ -799,9 +808,6 @@ export function useEngineWebhooks(instance: string) {

// POST REQUESTS
export type SetWalletConfigInput =
| {
type: "local";
}
| {
type: "aws-kms";
awsAccessKeyId: string;
Expand All @@ -821,8 +827,8 @@ export function useEngineSetWalletConfig(instance: string) {
const token = useLoggedInUser().user?.jwt ?? null;
const queryClient = useQueryClient();

return useMutation({
mutationFn: async (input: SetWalletConfigInput) => {
return useMutation<WalletConfigResponse, void, SetWalletConfigInput>({
mutationFn: async (input) => {
invariant(instance, "instance is required");

const res = await fetch(`${instance}configuration/wallets`, {
Expand All @@ -847,6 +853,7 @@ export function useEngineSetWalletConfig(instance: string) {
}

export type CreateBackendWalletInput = {
type: EngineBackendWalletType;
label?: string;
};

Expand Down Expand Up @@ -913,25 +920,20 @@ export function useEngineUpdateBackendWallet(instance: string) {
});
}

export type ImportBackendWalletInput =
| {
awsKmsKeyId: string;
awsKmsArn: string;
}
| {
gcpKmsKeyId: string;
gcpKmsKeyVersionId: string;
}
| {
privateKey?: string;
}
| {
mnemonic?: string;
}
| {
encryptedJson?: string;
password?: string;
};
// The backend determines the wallet imported based on the provided fields.
export type ImportBackendWalletInput = {
label?: string;

awsKmsArn?: string;

gcpKmsKeyId?: string;
gcpKmsKeyVersionId?: string;

privateKey?: string;
mnemonic?: string;
encryptedJson?: string;
password?: string;
};

export function useEngineImportBackendWallet(instance: string) {
const token = useLoggedInUser().user?.jwt ?? null;
Expand Down Expand Up @@ -1639,6 +1641,9 @@ export function useEngineCreateNotificationChannel(engineId: string) {
`${THIRDWEB_API_HOST}/v1/engine/${engineId}/notification-channels`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(input),
},
);
Expand Down Expand Up @@ -1667,7 +1672,9 @@ export function useEngineDeleteNotificationChannel(engineId: string) {

const res = await fetch(
`${THIRDWEB_API_HOST}/v1/engine/${engineId}/notification-channels/${notificationChannelId}`,
{ method: "DELETE" },
{
method: "DELETE",
},
);
if (!res.ok) {
throw new Error(`Unexpected status ${res.status}: ${await res.text()}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function Page(props: EngineInstancePageProps) {
return (
<WithEngineInstance
engineId={props.params.engineId}
content={(res) => <EngineOverview instanceUrl={res.instance.url} />}
content={(res) => <EngineOverview instance={res.instance} />}
rootPath={`/team/${props.params.team_slug}/${props.params.project_slug}/engine`}
/>
);
Expand Down
5 changes: 4 additions & 1 deletion apps/dashboard/src/components/engine/badges/version.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "@/components/ui/dialog";
import { TrackedLinkTW } from "@/components/ui/tracked-link";
import { toast } from "sonner";
import invariant from "tiny-invariant";

export const EngineVersionBadge = ({
instance,
Expand Down Expand Up @@ -119,9 +120,11 @@ const UpdateVersionModal = (props: {
}

const onClick = async () => {
invariant(instance.deploymentId, "Engine is missing deploymentId.");

try {
const promise = updateEngineServerMutation.mutateAsync({
engineId: instance.id,
deploymentId: instance.deploymentId,
serverVersion: latestVersion,
});
toast.promise(promise, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const EngineConfiguration: React.FC<EngineConfigurationProps> = ({
}) => {
return (
<div className="flex flex-col gap-12">
<EngineWalletConfig instanceUrl={instance.url} />
<EngineWalletConfig instance={instance} />
<EngineCorsConfig instanceUrl={instance.url} />
<EngineIpAllowlistConfig instanceUrl={instance.url} />
<EngineSystem instance={instance} />
Expand Down
Loading
Loading