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
40 changes: 37 additions & 3 deletions components/GenericMethod/GenericMethod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { RequestResponseJSON } from "./params/RequestResponseJSON";
import Head from "next/head";
import { ReqResParam } from "./params/types";
import { RequestParams } from "./params/RequestParams";
import { PathParams } from "./params/PathParams";
import { QueryParams } from "./params/QueryParams";
import { ResponseParams } from "./params/ResponseParams";

const inter = Inter({ subsets: ["latin"] });
Expand All @@ -22,14 +24,22 @@ export type GenericMethodProps = {
network: string;
cu: number;
description: string;
url?: string | string[];
useCases: string[];
constraints: string[];
responseJSON: string;

// Complex types
codeSnippets: CodeSnippetObject[];

pathParams?: ReqResParam[];
pathParamsType?: TParamType;

queryParams?: ReqResParam[];
queryParamsType?: TParamType;

requestParams: ReqResParam[];
requestParamsType: TParamType;
requestParamsType?: TParamType;

responseParams: ReqResParam[];
responseParamsType: TParamType;
Expand All @@ -55,10 +65,15 @@ export default function GenericMethod({
network,
cu,
description,
url,
useCases,
constraints,
codeSnippets,
responseJSON,
pathParams,
pathParamsType,
queryParams,
queryParamsType,
requestParams,
requestParamsType,
responseParams,
Expand All @@ -69,7 +84,7 @@ export default function GenericMethod({
isRESTApi,
}: GenericMethodProps) {
const [snippet, setSnippet] = React.useState<CodeSnippetObject["language"]>(
codeSnippets?.[0]?.language || null
codeSnippets?.[0]?.language || null,
);

const snippetCode = React.useMemo(() => {
Expand All @@ -84,7 +99,7 @@ export default function GenericMethod({
) {
return codeSnippetString.replaceAll(
replaceCodeSnippetsURLFrom,
replaceCodeSnippetsURLTo
replaceCodeSnippetsURLTo,
);
}
return codeSnippetString;
Expand Down Expand Up @@ -126,6 +141,13 @@ export default function GenericMethod({
{description}
</Text>
</Group>
{(Array.isArray(url) ? url : [url]).map((item, idx) => (
<Group justify="start" key={idx}>
<Text size="sm" color="gray">
{item}
</Text>
</Group>
))}
</Grid.Col>

<Grid.Col span={12}>
Expand Down Expand Up @@ -169,6 +191,18 @@ export default function GenericMethod({
<RequestResponseJSON json={responseJSON} />
</Grid.Col>

{isRESTApi && (
<Grid.Col span={12}>
<PathParams params={pathParams} paramsType={pathParamsType} />
</Grid.Col>
)}

{isRESTApi && (
<Grid.Col span={12}>
<QueryParams params={queryParams} paramsType={queryParamsType} />
</Grid.Col>
)}

<Grid.Col span={12}>
<RequestParams
requestParams={requestParams}
Expand Down
31 changes: 31 additions & 0 deletions components/GenericMethod/params/Params.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.root {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: flex-start;
background-color: #181818;
flex-wrap: wrap;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
}

.line {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
padding: 12px;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
width: 100%;
gap: 10px;
}

.params {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
padding: 12px;
width: 100%;
gap: 10px;
}
56 changes: 56 additions & 0 deletions components/GenericMethod/params/Params.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Grid } from "@mantine/core";
import classes from "./Params.module.css";
import { ParamsList } from "./ParamsList";
import { TParamType } from "../types";
import { getParamsType } from "../getParamsType";
import { Text } from "../../Text";
import { ReqResParam } from "./types";

export type Props = {
paramsType: TParamType;
params: ReqResParam[] | null;
title: string;
};

export function Params({
params,
paramsType,
title,
}: Props) {
return (
<Grid gutter={10}>
<Grid.Col span={12}>
<Text
uppercase
color={"grayLike"}
size="xs"
fontWeight="medium"
component="h2"
>
{title}
</Text>
</Grid.Col>

<Grid.Col span={12}>
<section className={classes.root}>

<section className={classes.params}>
<Text color="white" size="sm" fontWeight="medium">
Parameters
</Text>
<Text color="gray" size="xs" italic>
{getParamsType(paramsType)}
</Text>
</section>

{params && params.length > 0 ? (
<ParamsList
params={params}
paramsType={paramsType}
/>
) : null}
</section>
</Grid.Col>
</Grid>
);
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import { Group } from "@mantine/core";
import { Fira_Mono } from "next/font/google";
import { RequestParamProp } from "./types";
import classes from "./RequestParamsList.module.css";
import classes from "./ParamsList.module.css";
import { Text } from "../../Text";
import { TParamType } from "../types";
import { getParamsType } from "../getParamsType";
import cx from "clsx";

type Props = {
requestParams: RequestParamProp;
requestParamsType: TParamType;
params: RequestParamProp;
paramsType: TParamType;
isChild?: boolean;
};

const fira = Fira_Mono({ subsets: ["latin"], weight: ["400"] });

export function RequestParamsList({ requestParams, requestParamsType }: Props) {
export function ParamsList({ params, paramsType }: Props) {
const paramsTypeText = getParamsType(paramsType);
return (
<section className={classes.root}>
<div className={classes.line}>
{paramsTypeText && <div className={classes.line}>
<Text color="gray" size="xs" fontWeight="medium" italic>
{getParamsType(requestParamsType)}
{paramsTypeText}
</Text>
</div>
</div>}

{/* Iterate through and render each param */}
{requestParams?.map((param) => (
{params?.map((param) => (
<div key={param.paramName} className={classes.line}>
<Group gap={10} align="center">
<Text color="white" size="sm" fontWeight="medium">
Expand Down Expand Up @@ -75,9 +76,9 @@ export function RequestParamsList({ requestParams, requestParamsType }: Props) {
{/* If param has children params, render them */}
{param.childrenParams ? (
<div className={cx(classes.line, classes.children)}>
<RequestParamsList
requestParams={param.childrenParams}
requestParamsType={requestParamsType}
<ParamsList
params={param.childrenParams}
paramsType={paramsType}
isChild
/>
</div>
Expand Down
7 changes: 7 additions & 0 deletions components/GenericMethod/params/PathParams.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Params, type Props as ParamsProps } from "./Params";

type Props = Omit<ParamsProps, "title">;

export function PathParams(props: Props) {
return <Params {...props} title="Path params" />;
}
7 changes: 7 additions & 0 deletions components/GenericMethod/params/QueryParams.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Params, type Props as ParamsProps } from "./Params";

type Props = Omit<ParamsProps, "title">;

export function QueryParams(props: Props) {
return <Params {...props} title="Query params" />;
}
8 changes: 4 additions & 4 deletions components/GenericMethod/params/RequestParams.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Grid } from "@mantine/core";
import classes from "./RequestParams.module.css";
import { RequestParamsList } from "./RequestParamsList";
import { ParamsList } from "./ParamsList";
import { TParamType } from "../types";
import { getParamsType } from "../getParamsType";
import { Text } from "../../Text";
Expand Down Expand Up @@ -72,9 +72,9 @@ export function RequestParams({
</section>

{requestParams && requestParams.length > 0 ? (
<RequestParamsList
requestParams={requestParams}
requestParamsType={requestParamsType}
<ParamsList
params={requestParams}
paramsType={requestParamsType}
/>
) : null}
</section>
Expand Down
3 changes: 3 additions & 0 deletions components/GenericMethod/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export type TParamType =
| "none"
| "map[string]string"
| "numeric"
| "networth_period"
| "nft_info"
| "nullable"
| "uint64";

export type CodeSnippetObject = {
Expand Down
19 changes: 19 additions & 0 deletions components/WalletMethod/WalletMethod.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import GenericMethod, {
GenericMethodProps,
} from "../GenericMethod/GenericMethod";

type Props = Omit<
GenericMethodProps,
"network" | "isRESTApi" | "responseParamsDescription"
>;

export default function WalletMethod(props: Props) {
return (
<GenericMethod
isRESTApi={true}
network=""
responseParamsDescription=""
{...props}
/>
);
}
21 changes: 21 additions & 0 deletions components/WalletMethod/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export type TParamType =
| "string"
| "number"
| "integer"
| "boolean"
| "array"
| "object"
| "array_of_objects"
| "array_of_strings"
| "array_of_arrays_of_strings"
| "array_of_integers"
| "int64"
| "array_of_numbers"
| "none"
| "map[string]string"
| "uint64";

export type CodeSnippetObject = {
language: "js" | "shell" | "node" | "go" | "python" | "rust";
code: () => string;
};
Loading
Loading