diff --git a/@l10n/ja/translations.yaml b/@l10n/ja/translations.yaml index 12837bc1fe..e49cc10f32 100644 --- a/@l10n/ja/translations.yaml +++ b/@l10n/ja/translations.yaml @@ -139,6 +139,10 @@ footer.community.report-a-scam: 詐欺の報告 component.tryit: 試してみる component.queryexampletx: トランザクションの例を確認 +component.amendment-status.requires.1: " " +component.amendment-status.requires.2: が必要です。 +component.amendment-status.added.1: " " +component.amendment-status.added.2: により追加されました。 # Amendment tracker translations amendment.loading: ロード中Amendments... diff --git a/@theme/markdoc/components.tsx b/@theme/markdoc/components.tsx index be35ac1f74..58af8f2391 100644 --- a/@theme/markdoc/components.tsx +++ b/@theme/markdoc/components.tsx @@ -380,3 +380,92 @@ function AmendmentBadge(props: { amendment: Amendment }) { return {status}; } + +export function AmendmentDisclaimer(props: { + name: string, +}) { + const [amendmentStatus, setStatus] = React.useState(null); + const [loading, setLoading] = React.useState(true); + const [error, setError] = React.useState(null); + const { useTranslate } = useThemeHooks(); + const { translate } = useTranslate(); + + const link = () => {props.name} amendment + + React.useEffect(() => { + const fetchAmendments = async () => { + try { + setLoading(true); + const response = await fetch(`https://vhs.prod.ripplex.io/v1/network/amendments/vote/main/`); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const data: AmendmentsResponse = await response.json() + console.log("data.amendments is:", data.amendments) + + let found_amendment = false + for (const amendment of data.amendments) { + if (amendment.name == props.name) { + setStatus(amendment) + found_amendment = true + break + } + } + if (!found_amendment) { + throw new Error(`Couldn't find ${props.name} amendment in status table.`) + } + } catch (err) { + setError(err instanceof Error ? err.message : 'Failed to fetch amendments'); + } finally { + setLoading(false) + } + } + fetchAmendments() + }, []) + + if (loading) { + return ( +

+ {translate("component.amendment-status.requires.1", "Requires the ")}{link()}{translate("component.amendment-status.requires.2", ".")} + {" "} + + {translate("amendment.loading_status", "Loading...")} + +

+ ) + } + + if (error) { + return ( +

+ {translate("component.amendment-status.requires.1", "Requires the ")}{link()}{translate("component.amendment-status.requires.2", ".")} + {" "} + + {translate("amendment.error_status", "Error loading amendment status")}: {error} + +

+ ) + } + + return ( +

( + { + amendmentStatus.date ? ( + <> + {translate("component.amendment-status.added.1", "Added by the ")}{link()} + {translate("component.amendment-status.added.2", ".")} + {" "} + + + ) : ( + <> + {translate("component.amendment-status.requires.1", "Requires the ")}{link()} + {translate("component.amendment-status.requires.2", ".")} + {" "} + + + ) + } + )

+ ) +} diff --git a/@theme/markdoc/schema.ts b/@theme/markdoc/schema.ts index 6fd58b2fe9..d75840f85b 100644 --- a/@theme/markdoc/schema.ts +++ b/@theme/markdoc/schema.ts @@ -221,3 +221,15 @@ export const amendmentsTable: Schema & { tagName: string } = { render: 'AmendmentsTable', selfClosing: true } + +export const amendmentDisclaimer: Schema & { tagName: string } = { + tagName: 'amendment-disclaimer', + attributes: { + name: { + type: 'String', + required: true + }, + }, + render: 'AmendmentDisclaimer', + selfClosing: true +}