Skip to content

Commit 6fbcb19

Browse files
authored
Merge pull request #1791 from cprussin/chore-api-reference-refactor
Update get-price description
2 parents 6f403e1 + bc1fbe3 commit 6fbcb19

File tree

15 files changed

+251
-235
lines changed

15 files changed

+251
-235
lines changed

apps/api-reference/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"scripts": {
1010
"build": "next build",
11-
"fix": "pnpm fix:format && pnpm fix:lint",
11+
"fix": "pnpm fix:lint && pnpm fix:format",
1212
"fix:format": "prettier --write .",
1313
"fix:lint": "eslint --fix .",
1414
"pull:env": "VERCEL_ORG_ID=team_BKQrg3JJFLxZyTqpuYtIY0rj VERCEL_PROJECT_ID=prj_gbljYVzp0m5EpCuOF6nZpM4WMFM6 vercel env pull",

apps/api-reference/src/apis/evm/get-price.ts

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,39 @@ export const getPrice = readApi<"id">({
55
name: "getPrice",
66
summary: "Get the **latest** price object for the requested price feed ID.",
77
description: `
8-
This method returns the latest price object for the requested price feed ID.
8+
This method returns the latest price object for the requested price feed ID.
99
10-
The \`Price\` object contains the following fields:
11-
1. \`price\`: The price of the asset.
12-
2. \`conf\`: The confidence level of the price.
13-
3. \`expo\`: The exponent of the price.
14-
4. \`publishTime\`: The timestamp of the price update.
10+
The \`price\` object contains the following fields:
11+
1. \`price\`: The latest price of the price feed.
12+
2. \`conf\`: The confidence level of the price feed.
13+
3. \`expo\`: The exponent of the price feed.
14+
4. \`publishtime\`: The time when the price feed was last updated.
1515
16-
Sample \`Price\` object:
17-
\`\`\`json
18-
{
19-
"price": "1234",
20-
"conf": "1000",
21-
"expo": "-2",
22-
"publishTime": 1626892800
23-
}
24-
\`\`\`
25-
Get the latest price and confidence interval for the requested price feed id.
26-
The price feed id is a 32-byte id written as a hexadecimal string; see the
27-
[price feed ids](https://pyth.network/developers/price-feed-ids) page to look up
28-
the id for a given symbol. The returned price and confidence are decimal numbers
29-
written in the form \`a * 10^e\`, where \`e\` is an exponent included in the
30-
result. For example, a price of 1234 with an exponent of -2 represents the
31-
number 12.34. The result also includes a \`publishTime\` which is the unix
32-
timestamp for the price update.
16+
Sample \`price\` object:
17+
\`\`\`json
18+
{
19+
price: 123456789,
20+
conf: 180726074,
21+
expo: -8,
22+
publishTime: 1721765108
23+
}
24+
\`\`\`
3325
34-
This function reverts with a \`StalePrice\` error if the on-chain price has not
35-
been updated within the last [getValidTimePeriod()](getValidTimePeriod)
36-
seconds. The default valid time period is set to a reasonable default on each
37-
chain and is typically around 1 minute. Call
38-
[updatePriceFeeds](updatePriceFeeds) to pull a fresh price on-chain and solve
39-
this problem. If you would like to configure the valid time period, see
40-
[getPriceNoOlderThan](getPriceNoOlderThan). If you want the latest price
41-
regardless of when it was updated, see [getPriceUnsafe](getPriceUnsafe).
26+
The price above is in the format of \`price * 10^expo\`. So, the price in above
27+
mentioned sample represents the number \`123456789 * 10(-8) = 1.23456789\` in
28+
this case.
4229
43-
This function reverts with a \`PriceFeedNotFound\` error if the requested feed
44-
id has never received a price update. This error could either mean that the
45-
provided price feed id is incorrect, or (more typically) that this is the first
46-
attempted use of that feed on-chain. In the second case, calling
47-
[updatePriceFeeds](updatePriceFeeds) will solve this problem.
48-
`,
30+
### Error Response
31+
32+
The above method returns the following error response:
33+
- \`StalePrice\`: The on-chain price has not been updated within the last
34+
[\`getValidTimePeriod()\`](getValidTimePeriod) seconds. Try calling
35+
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed with the
36+
latest price.
37+
- \`PriceFeedNotFound\`: The requested price feed has never received a price
38+
update or does not exist. Try calling
39+
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed.
40+
`,
4941
parameters: [
5042
{
5143
name: "id",

apps/api-reference/src/components/Code/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import { useMemo, useCallback, type HTMLAttributes } from "react";
55
import { useEffect, useState } from "react";
66
import type { OffsetOrPosition } from "shiki";
77

8-
import type { SupportedLanguage } from "./shiki";
98
import style from "./style.module.css";
9+
import type { SupportedLanguage } from "./supported-language";
1010
import { useHighlightedCode } from "./use-highlighted-code";
1111
import { getLogger } from "../../browser-logger";
1212
import { Button } from "../Button";
1313

14-
export type { SupportedLanguage } from "./shiki";
14+
export * from "./supported-language";
1515

1616
type CodeProps = {
17-
language: SupportedLanguage;
17+
language?: SupportedLanguage | undefined;
1818
children: string;
1919
dimRange?: readonly [OffsetOrPosition, OffsetOrPosition] | undefined;
2020
};
@@ -113,7 +113,7 @@ const CopyButton = ({ children, className, ...props }: CopyButtonProps) => {
113113
};
114114

115115
type HighlightedCodeProps = Omit<HTMLAttributes<HTMLElement>, "children"> & {
116-
language: SupportedLanguage;
116+
language?: SupportedLanguage | undefined;
117117
children: string;
118118
dimRange?: readonly [OffsetOrPosition, OffsetOrPosition] | undefined;
119119
};

apps/api-reference/src/components/Code/shiki.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,36 @@ import {
44
getHighlighterCore as shikiGetHighlighterCore,
55
} from "shiki/core";
66
import javascript from "shiki/langs/javascript.mjs";
7+
import json from "shiki/langs/json.mjs";
78
import solidity from "shiki/langs/solidity.mjs";
89
import darkPlus from "shiki/themes/dark-plus.mjs";
910
import lightPlus from "shiki/themes/light-plus.mjs";
1011
import loadWasm from "shiki/wasm";
1112

13+
import type { SupportedLanguage } from "./supported-language";
14+
1215
export type Highlighter = {
1316
highlight: (
14-
lang: SupportedLanguage,
17+
lang: SupportedLanguage | undefined,
1518
code: string,
1619
options?: HighlightOptions | undefined,
1720
) => string;
1821
};
1922

20-
export type SupportedLanguage = "javascript" | "solidity";
21-
2223
export type HighlightOptions = {
2324
decorations?: DecorationItem[] | undefined;
2425
};
2526

2627
export const getHighlighter = async (): Promise<Highlighter> => {
2728
const highlighterCore = await shikiGetHighlighterCore({
28-
langs: [javascript, solidity],
29+
langs: [javascript, solidity, json],
2930
themes: [darkPlus, lightPlus],
3031
loadWasm,
3132
});
3233

3334
return {
3435
highlight: (
35-
lang: SupportedLanguage,
36+
lang: SupportedLanguage | undefined,
3637
code: string,
3738
options?: HighlightOptions | undefined,
3839
) => highlight(highlighterCore, lang, code, options),
@@ -41,12 +42,12 @@ export const getHighlighter = async (): Promise<Highlighter> => {
4142

4243
const highlight = (
4344
highlighter: HighlighterCore,
44-
lang: SupportedLanguage,
45+
lang: SupportedLanguage | undefined,
4546
code: string,
4647
options?: HighlightOptions | undefined,
4748
) =>
4849
highlighter.codeToHtml(code, {
49-
lang,
50+
lang: lang ?? "text",
5051
themes: {
5152
light: "light-plus",
5253
dark: "dark-plus",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const SUPPORTED_LANGUAGES = ["javascript", "solidity", "json"] as const;
2+
3+
export type SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number];
4+
5+
export const isSupportedLanguage = (
6+
language: string,
7+
): language is SupportedLanguage =>
8+
(SUPPORTED_LANGUAGES as readonly string[]).includes(language);

apps/api-reference/src/components/Code/use-highlighted-code.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
} from "react";
1313
import type { OffsetOrPosition } from "shiki";
1414

15-
import type { Highlighter, SupportedLanguage } from "./shiki";
15+
import type { Highlighter } from "./shiki";
16+
import type { SupportedLanguage } from "./supported-language";
1617
import { getLogger } from "../../browser-logger";
1718

1819
const HighlighterContext = createContext<
@@ -45,7 +46,7 @@ const useHighlighter = () => {
4546
};
4647

4748
export const useHighlightedCode = (
48-
language: SupportedLanguage,
49+
language: SupportedLanguage | undefined,
4950
code: string,
5051
dimRange?: readonly [OffsetOrPosition, OffsetOrPosition] | undefined,
5152
) => {

0 commit comments

Comments
 (0)