Skip to content

Commit 37f5b62

Browse files
authored
Merge pull request #3833 from IntersectMBO/staging
v2.0.27
2 parents c68e473 + 40e12d4 commit 37f5b62

File tree

10 files changed

+543
-152
lines changed

10 files changed

+543
-152
lines changed

govtool/frontend/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

govtool/frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"bech32": "^2.0.0",
4242
"blakejs": "^1.2.1",
4343
"buffer": "^6.0.3",
44+
"cbor-web": "^10.0.3",
4445
"date-fns": "^2.30.0",
4546
"esbuild": "^0.25.0",
4647
"i18next": "^23.7.19",

govtool/frontend/src/components/molecules/GovernanceActionCardElement.tsx

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import { useModal } from "@/context";
1515

1616
type BaseProps = {
1717
label: string;
18-
text?: React.ReactNode;
18+
text?: string | number;
1919
dataTestId?: string;
2020
isSliderCard?: boolean;
2121
tooltipProps?: Omit<TooltipProps, "children">;
2222
marginBottom?: number;
2323
isSemiTransparent?: boolean;
2424
isValidating?: boolean;
25+
children?: React.ReactNode;
2526
};
2627

2728
type VariantProps = BaseProps & {
@@ -44,10 +45,11 @@ export const GovernanceActionCardElement = ({
4445
isMarkdown = false,
4546
isSemiTransparent = false,
4647
isValidating = false,
48+
children,
4749
}: VariantProps) => {
4850
const { openModal } = useModal();
4951

50-
if (!text) return null;
52+
if (text == null && children == null) return null;
5153

5254
const renderTooltip = () =>
5355
tooltipProps && (
@@ -108,11 +110,13 @@ export const GovernanceActionCardElement = ({
108110
...(isSemiTransparent && { opacity: 0.75 }),
109111
}}
110112
>
111-
{typeof text === "string" && isMarkdown ? removeMarkdown(text) : text}
113+
{isMarkdown ? removeMarkdown(text) : text}
112114
</Typography>
113115
);
114116

115-
const renderMarkdownText = ({ children }: PropsWithChildren) => (
117+
const renderMarkdownText = ({
118+
children: markdownChildren,
119+
}: PropsWithChildren) => (
116120
<Typography
117121
sx={{
118122
fontSize: 16,
@@ -121,17 +125,18 @@ export const GovernanceActionCardElement = ({
121125
maxWidth: "auto",
122126
}}
123127
>
124-
{children}
128+
{markdownChildren}
125129
</Typography>
126130
);
127131

128132
const markdownComponents = {
129-
p: ({ children }: PropsWithChildren) => renderMarkdownText({ children }),
133+
p: ({ children: markdownChildren }: PropsWithChildren) =>
134+
renderMarkdownText({ children: markdownChildren }),
130135
br: () => <br />,
131136
};
132137

133-
const renderMarkdown = () => {
134-
const formattedText = text
138+
const renderMarkdown = (markdownText: string | number) => {
139+
const formattedText = markdownText
135140
.toString()
136141
.replace(/\r\n|\r/g, "\n")
137142
.replace(
@@ -157,14 +162,14 @@ export const GovernanceActionCardElement = ({
157162
);
158163
};
159164

160-
const renderCopyButton = () =>
165+
const renderCopyButton = (copyText: string | number) =>
161166
isCopyButton && (
162167
<Box ml={1}>
163-
<CopyButton text={text.toString()} variant="blueThin" />
168+
<CopyButton text={copyText.toString()} variant="blueThin" />
164169
</Box>
165170
);
166171

167-
const renderLinkButton = () =>
172+
const renderLinkButton = (linkText: string | number) =>
168173
isLinkButton && (
169174
<Box ml={1}>
170175
<img
@@ -175,13 +180,32 @@ export const GovernanceActionCardElement = ({
175180
onClick={() =>
176181
openModal({
177182
type: "externalLink",
178-
state: { externalLink: text.toString() },
183+
state: { externalLink: linkText.toString() },
179184
})
180185
}
181186
/>
182187
</Box>
183188
);
184189

190+
const renderTextOrChildren = () => {
191+
if (text != null) {
192+
return (
193+
<>
194+
{textVariant === "pill"
195+
? renderPillText()
196+
: isMarkdown && !isSliderCard
197+
? renderMarkdown(text)
198+
: renderStandardText()}
199+
{renderCopyButton(text)}
200+
{renderLinkButton(text)}
201+
</>
202+
);
203+
}
204+
if (children != null) {
205+
return children;
206+
}
207+
};
208+
185209
return (
186210
<Box
187211
data-testid={dataTestId}
@@ -220,13 +244,7 @@ export const GovernanceActionCardElement = ({
220244
flexDirection={isMarkdown ? "column" : "row"}
221245
fontFamily="Poppins, Arial"
222246
>
223-
{textVariant === "pill"
224-
? renderPillText()
225-
: isMarkdown && !isSliderCard
226-
? renderMarkdown()
227-
: renderStandardText()}
228-
{renderCopyButton()}
229-
{renderLinkButton()}
247+
{renderTextOrChildren()}
230248
</Box>
231249
)}
232250
</Box>

govtool/frontend/src/components/organisms/GovernanceActionDetailsCardData.tsx

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -374,44 +374,43 @@ export const GovernanceActionDetailsCardData = ({
374374
)}
375375
<GovernanceActionCardElement
376376
label={t("govActions.authors.title")}
377-
text={
378-
<Box sx={{ display: "flex", gap: 2, flexWrap: "wrap" }}>
379-
{(authors ?? []).length <= 0
380-
? t("govActions.authors.noDataAvailable")
381-
: (authors ?? []).map((author) => (
382-
<Box
383-
key={author.publicKey}
384-
sx={{ display: "flex", gap: 0.5, alignItems: "center" }}
385-
>
386-
<AuthorSignatureStatus
387-
signature={author.signature}
388-
publicKey={author.publicKey}
389-
algorithm={author.witnessAlgorithm}
390-
jsonContent={jsonContent}
391-
/>
392-
<span>{author.name}</span>
393-
<Tooltip
394-
heading={`${t("govActions.authors.witnessAlgorithm")}: ${
395-
author.witnessAlgorithm
396-
}`}
397-
paragraphOne={`${t("govActions.authors.publicKey")}: ${
398-
author.publicKey
399-
}`}
400-
paragraphTwo={`${t("govActions.authors.signature")}: ${
401-
author.signature
402-
}`}
403-
placement="bottom-end"
404-
arrow
405-
>
406-
<InfoOutlinedIcon fontSize="small" />
407-
</Tooltip>
408-
</Box>
409-
))}
410-
</Box>
411-
}
412377
textVariant="longText"
413378
dataTestId="authors"
414-
/>
379+
>
380+
<Box sx={{ display: "flex", gap: 2, flexWrap: "wrap" }}>
381+
{(authors ?? []).length <= 0
382+
? t("govActions.authors.noDataAvailable")
383+
: (authors ?? []).map((author) => (
384+
<Box
385+
key={author.publicKey}
386+
sx={{ display: "flex", gap: 0.5, alignItems: "center" }}
387+
>
388+
<AuthorSignatureStatus
389+
signature={author.signature}
390+
publicKey={author.publicKey}
391+
algorithm={author.witnessAlgorithm}
392+
jsonContent={jsonContent}
393+
/>
394+
<span>{author.name}</span>
395+
<Tooltip
396+
heading={`${t("govActions.authors.witnessAlgorithm")}: ${
397+
author.witnessAlgorithm
398+
}`}
399+
paragraphOne={`${t("govActions.authors.publicKey")}: ${
400+
author.publicKey
401+
}`}
402+
paragraphTwo={`${t("govActions.authors.signature")}: ${
403+
author.signature
404+
}`}
405+
placement="bottom-end"
406+
arrow
407+
>
408+
<InfoOutlinedIcon fontSize="small" />
409+
</Tooltip>
410+
</Box>
411+
))}
412+
</Box>
413+
</GovernanceActionCardElement>
415414

416415
<GovernanceActionDetailsCardLinks links={references} />
417416
</Box>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
type CBORDecoded = Map<number | string, any> | any[];
3+
4+
type BufferLike =
5+
| string
6+
| Buffer
7+
| ArrayBuffer
8+
| ArrayBufferView
9+
| DataView
10+
| stream.Readable;
11+
12+
declare module "cbor-web" {
13+
export function encode(input: any): Buffer;
14+
export function decode(input: BufferLike): CBORDecoded;
15+
16+
export function encodeAsync(input: any): Promise<Buffer>;
17+
export function decodeAsync(
18+
input: BufferLike,
19+
): Promise<CBORDecoded>;
20+
}

0 commit comments

Comments
 (0)