Skip to content

Commit

Permalink
Support RPC's new flag to enable response in JSON (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeesunikim authored Oct 9, 2024
1 parent e599c0f commit 2034f5d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/app/(sidebar)/endpoints/[[...pages]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export default function Endpoints() {
return {
...defaultRpcRequestBody,
params: {
xdrFormat: params.xdrFormat || "base64",
startLedger: Number(params.startLedger) || null,
pagination: {
cursor: params.cursor || "",
Expand All @@ -193,6 +194,7 @@ export default function Endpoints() {
(params.ledgerKeyEntries &&
JSON.parse(params.ledgerKeyEntries)) ??
[],
xdrFormat: params.xdrFormat || "base64",
},
};
}
Expand All @@ -202,6 +204,7 @@ export default function Endpoints() {
...defaultRpcRequestBody,
params: {
hash: params.transaction ?? "",
xdrFormat: params.xdrFormat || "base64",
},
};
}
Expand All @@ -215,6 +218,7 @@ export default function Endpoints() {
cursor: params.cursor,
limit: Number(params.limit) || undefined,
}),
xdrFormat: params.xdrFormat || "base64",
},
};
}
Expand All @@ -224,6 +228,7 @@ export default function Endpoints() {
...defaultRpcRequestBody,
params: {
transaction: params.tx ?? "",
xdrFormat: params.xdrFormat || "base64",
},
};
}
Expand All @@ -236,6 +241,7 @@ export default function Endpoints() {
resourceConfig: sanitizeObject({
instructionLeeway: Number(params.resourceConfig) || undefined,
}),
xdrFormat: params.xdrFormat || "base64",
},
};
}
Expand Down
25 changes: 25 additions & 0 deletions src/components/formComponentTemplateEndpoints.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,31 @@ export const formComponentTemplateEndpoints = (
),
validate: validate.getPositiveIntError,
};
case "xdrFormat":
return {
render: (templ: {
value: string | undefined;
error: string | undefined;
onChange: (val: any) => void;
}) => (
<Select
key={id}
id={id}
fieldSize="md"
label="XDR Format"
value={templ.value || ""}
onChange={templ.onChange}
>
<option id="base64" value="base64">
base64
</option>
<option id="json" value="json">
json
</option>
</Select>
),
validate: null,
};
default:
return null;
}
Expand Down
12 changes: 6 additions & 6 deletions src/constants/endpointsPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const ENDPOINTS_PAGES_RPC: EndpointsPagesProps = {
docsUrl:
"https://developers.stellar.org/docs/data/rpc/api-reference/methods/getEvents",
docsLabel: "getEvents",
endpointUrlTemplate: "{?startLedger,cursor,limit,filters}",
endpointUrlTemplate: "{?startLedger,cursor,limit,filters,xdrFormat}",
requestMethod: "POST",
requiredParams: "startLedger,filters",
rpcMethod: "getEvents",
Expand Down Expand Up @@ -92,7 +92,7 @@ export const ENDPOINTS_PAGES_RPC: EndpointsPagesProps = {
docsUrl:
"https://developers.stellar.org/docs/data/rpc/api-reference/methods/getLedgerEntries",
docsLabel: "getLedgerEntries",
endpointUrlTemplate: "{?ledgerKeyEntries}",
endpointUrlTemplate: "{?ledgerKeyEntries,xdrFormat}",
requestMethod: "POST",
requiredParams: "ledgerKeyEntries",
rpcMethod: "getLedgerEntries",
Expand All @@ -119,7 +119,7 @@ export const ENDPOINTS_PAGES_RPC: EndpointsPagesProps = {
docsUrl:
"https://developers.stellar.org/docs/data/rpc/api-reference/methods/getTransaction",
docsLabel: "getTransaction",
endpointUrlTemplate: "{?transaction}",
endpointUrlTemplate: "{?transaction,xdrFormat}",
requestMethod: "POST",
requiredParams: "transaction",
rpcMethod: "getTransaction",
Expand All @@ -133,7 +133,7 @@ export const ENDPOINTS_PAGES_RPC: EndpointsPagesProps = {
docsUrl:
"https://developers.stellar.org/docs/data/rpc/api-reference/methods/getTransactions",
docsLabel: "getTransactions",
endpointUrlTemplate: "{?startLedger,cursor,limit}",
endpointUrlTemplate: "{?startLedger,cursor,limit,xdrFormat}",
requestMethod: "POST",
requiredParams: "startLedger",
rpcMethod: "getTransactions",
Expand All @@ -160,7 +160,7 @@ export const ENDPOINTS_PAGES_RPC: EndpointsPagesProps = {
docsUrl:
"https://developers.stellar.org/docs/data/rpc/api-reference/methods/sendTransaction",
docsLabel: "sendTransaction",
endpointUrlTemplate: "{?tx}",
endpointUrlTemplate: "{?tx,xdrFormat}",
requestMethod: "POST",
requiredParams: "tx",
rpcMethod: "sendTransaction",
Expand All @@ -174,7 +174,7 @@ export const ENDPOINTS_PAGES_RPC: EndpointsPagesProps = {
docsUrl:
"https://developers.stellar.org/docs/data/rpc/api-reference/methods/simulateTransaction",
docsLabel: "simulateTransaction",
endpointUrlTemplate: "{?tx,resourceConfig}",
endpointUrlTemplate: "{?tx,resourceConfig,xdrFormat}",
requestMethod: "POST",
requiredParams: "tx",
rpcMethod: "simulateTransaction",
Expand Down

0 comments on commit 2034f5d

Please sign in to comment.