Skip to content

Commit 174dad4

Browse files
committed
Add API and cURL support to code overview component
Enhanced the CodeOverview component to display API and cURL usage instructions and code snippets. Added a message for API/cURL environments indicating no SDK install is required and updated snippet generation logic to include API and cURL commands if available.
1 parent 34f2fc4 commit 174dad4

File tree

1 file changed

+67
-17
lines changed

1 file changed

+67
-17
lines changed

apps/dashboard/src/@/components/contracts/code-overview.tsx

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,13 @@ export function CodeOverview(props: {
849849
</div>
850850
)}
851851
<div className="flex flex-col gap-2">
852-
{environment === "react-native" || environment === "unity" ? (
852+
{environment === "api" || environment === "curl" ? (
853+
<p className="text-sm text-muted-foreground">
854+
No SDK install required for API/cURL. Call the HTTP endpoints
855+
directly. Keep your secret key server-side; use client IDs in
856+
frontends.
857+
</p>
858+
) : environment === "react-native" || environment === "unity" ? (
853859
<p className="text-sm text-muted-foreground">
854860
Install the latest version of the SDK.{" "}
855861
<UnderlineLink
@@ -972,32 +978,76 @@ export function CodeOverview(props: {
972978
<CodeSegment
973979
environment={environment}
974980
setEnvironment={setEnvironment}
975-
snippet={formatSnippet(
976-
// biome-ignore lint/suspicious/noExplicitAny: FIXME
977-
COMMANDS[tab as keyof typeof COMMANDS] as any,
978-
{
981+
snippet={(() => {
982+
const selectedFn =
983+
tab === "read" ? read : tab === "write" ? write : event;
984+
const commandsKey = tab as "read" | "write" | "events";
985+
986+
const baseSnippet = formatSnippet(COMMANDS[commandsKey], {
979987
args:
980988
abi
981989
?.filter(
982990
(f) => f.type === "function" || f.type === "event",
983991
)
984-
?.find(
985-
(f) =>
986-
f.name ===
987-
(tab === "read"
988-
? read?.name
989-
: tab === "write"
990-
? write?.name
991-
: event?.name),
992-
)
992+
?.find((f) => f.name === selectedFn?.name)
993993
?.inputs.map((i) => i.name || "") || [],
994994

995995
chainId,
996996
contractAddress,
997997
extensionNamespace,
998-
fn: tab === "read" ? read : tab === "write" ? write : event,
999-
},
1000-
)}
998+
fn: selectedFn,
999+
});
1000+
1001+
// Add API snippet if it exists
1002+
const apiSnippet = COMMANDS.api[commandsKey]
1003+
? formatSnippet(
1004+
{ api: COMMANDS.api[commandsKey] },
1005+
{
1006+
args:
1007+
abi
1008+
?.filter(
1009+
(f) =>
1010+
f.type === "function" || f.type === "event",
1011+
)
1012+
?.find((f) => f.name === selectedFn?.name)
1013+
?.inputs.map((i) => i.name || "") || [],
1014+
1015+
chainId,
1016+
contractAddress,
1017+
extensionNamespace,
1018+
fn: selectedFn,
1019+
},
1020+
)
1021+
: {};
1022+
1023+
// Add cURL snippet if it exists
1024+
const curlSnippet = COMMANDS.curl[commandsKey]
1025+
? formatSnippet(
1026+
{ curl: COMMANDS.curl[commandsKey] },
1027+
{
1028+
args:
1029+
abi
1030+
?.filter(
1031+
(f) =>
1032+
f.type === "function" || f.type === "event",
1033+
)
1034+
?.find((f) => f.name === selectedFn?.name)
1035+
?.inputs.map((i) => i.name || "") || [],
1036+
1037+
chainId,
1038+
contractAddress,
1039+
extensionNamespace,
1040+
fn: selectedFn,
1041+
},
1042+
)
1043+
: {};
1044+
1045+
return {
1046+
...baseSnippet,
1047+
...apiSnippet,
1048+
...curlSnippet,
1049+
};
1050+
})()}
10011051
/>
10021052
</div>
10031053
</div>

0 commit comments

Comments
 (0)