Skip to content

Commit 2e2e1f4

Browse files
authored
Merge pull request #2222 from IntersectMBO/staging
fix(#2191): protocol parameter change ga is not displayed correctly
2 parents 18c2df9 + 2322303 commit 2e2e1f4

File tree

12 files changed

+156
-23
lines changed

12 files changed

+156
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ changes.
3838
- Fix duplicate testIds for reference errors and hints in DRep metadata form [Issue 1965](https://github.com/IntersectMBO/govtool/issues/1965)
3939
- Eliminate duplicate DReps in the DRep Directory [Issue 2171](https://github.com/IntersectMBO/govtool/issues/2171)
4040
- Handle script based DReps [Issue 1951](https://github.com/IntersectMBO/govtool/issues/1951)
41+
- Fix displaying protocol parameter cost models [Issue 2191](https://github.com/IntersectMBO/govtool/issues/2191)
4142

4243
### Changed
4344

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
select ROW_TO_JSON(epoch_param) from epoch_param order by epoch_no desc limit 1;
1+
SELECT
2+
jsonb_set(
3+
ROW_TO_JSON(epoch_param)::jsonb,
4+
'{cost_model}',
5+
CASE
6+
WHEN cost_model.id IS NOT NULL THEN
7+
ROW_TO_JSON(cost_model)::jsonb
8+
ELSE
9+
'null'::jsonb
10+
END
11+
) AS epoch_param
12+
FROM
13+
epoch_param
14+
LEFT JOIN
15+
cost_model ON epoch_param.cost_model_id = cost_model.id
16+
ORDER BY
17+
epoch_no DESC
18+
LIMIT 1;

govtool/backend/sql/list-proposals.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,16 @@ SELECT
6464
creator_block.epoch_no,
6565
voting_anchor.url,
6666
encode(voting_anchor.data_hash, 'hex'),
67-
ROW_TO_JSON(proposal_params),
67+
jsonb_set(
68+
ROW_TO_JSON(proposal_params)::jsonb,
69+
'{cost_model}',
70+
CASE
71+
WHEN cost_model.id IS NOT NULL THEN
72+
ROW_TO_JSON(cost_model)::jsonb
73+
ELSE
74+
'null'::jsonb
75+
END
76+
) AS proposal_params,
6877
off_chain_vote_gov_action_data.title,
6978
off_chain_vote_gov_action_data.abstract,
7079
off_chain_vote_gov_action_data.motivation,
@@ -104,6 +113,7 @@ FROM
104113
JOIN block AS creator_block ON creator_block.id = creator_tx.block_id
105114
LEFT JOIN voting_anchor ON voting_anchor.id = gov_action_proposal.voting_anchor_id
106115
LEFT JOIN param_proposal as proposal_params ON gov_action_proposal.param_proposal = proposal_params.id
116+
LEFT JOIN cost_model AS cost_model ON proposal_params.cost_model_id = cost_model.id
107117
LEFT JOIN off_chain_vote_data ON off_chain_vote_data.voting_anchor_id = voting_anchor.id
108118
LEFT JOIN off_chain_vote_gov_action_data ON off_chain_vote_gov_action_data.off_chain_vote_data_id = off_chain_vote_data.id
109119
LEFT JOIN voting_procedure ON voting_procedure.gov_action_proposal_id = gov_action_proposal.id

govtool/frontend/src/components/atoms/VotePill.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ export const VotePill = ({
3232
minWidth="50px"
3333
maxWidth={maxWidth ? `${maxWidth}px` : "auto"}
3434
width={width ? `${width}px` : "auto"}
35-
maxHeight="14px"
3635
>
3736
<Typography
3837
textTransform="uppercase"
3938
fontSize={12}
4039
fontWeight={400}
4140
lineHeight="16px"
41+
whiteSpace="nowrap"
42+
textOverflow="ellipsis"
43+
overflow="hidden"
4244
>
4345
{t(
4446
`votes.${

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ export const DataMissingHeader = ({
3636
>
3737
<Typography
3838
sx={{
39-
overflow: "hidden",
4039
textOverflow: "ellipsis",
41-
whiteSpace: "nowrap",
4240
fontWeight: 600,
4341
...(isDataMissing && { color: "errorRed" }),
4442
...titleStyle,

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
filterUpdatableProtocolParams,
2020
filterOutNullParams,
2121
getFullGovActionId,
22+
mapArrayToObjectByKeys,
2223
} from "@utils";
2324
import { MetadataValidationStatus, ProposalData } from "@models";
2425
import { GovernanceActionType } from "@/types/governanceAction";
@@ -92,20 +93,34 @@ export const GovernanceActionDetailsCardData = ({
9293
const { screenWidth } = useScreenDimension();
9394
const { isMobile } = useScreenDimension();
9495

95-
const updatableProtocolParams = useMemo(
96+
const mappedArraysToObjectsProtocolParams = useMemo(
9697
() =>
97-
filterUpdatableProtocolParams(epochParams, protocolParams, [
98-
"id",
99-
"registered_tx_id",
100-
"key",
98+
mapArrayToObjectByKeys(protocolParams, [
99+
"PlutusV1",
100+
"PlutusV2",
101+
"PlutusV3",
101102
]),
102-
[epochParams, protocolParams],
103+
[protocolParams],
104+
);
105+
106+
const updatableProtocolParams = useMemo(
107+
() =>
108+
filterUpdatableProtocolParams(
109+
epochParams,
110+
mappedArraysToObjectsProtocolParams,
111+
["id", "registered_tx_id", "key"],
112+
),
113+
[epochParams, mappedArraysToObjectsProtocolParams],
103114
);
104115

105116
const nonNullProtocolParams = useMemo(
106117
() =>
107-
filterOutNullParams(protocolParams, ["id", "registered_tx_id", "key"]),
108-
[updatableProtocolParams, protocolParams],
118+
filterOutNullParams(mappedArraysToObjectsProtocolParams, [
119+
"id",
120+
"registered_tx_id",
121+
"key",
122+
]),
123+
[updatableProtocolParams, mappedArraysToObjectsProtocolParams],
109124
);
110125

111126
const isModifiedPadding =

govtool/frontend/src/main.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { QueryClient, QueryClientProvider } from "react-query";
55
import { ReactQueryDevtools } from "react-query/devtools";
66
import TagManager from "react-gtm-module";
77
import { ThemeProvider } from "@emotion/react";
8+
import { CssBaseline } from "@mui/material";
89
import * as Sentry from "@sentry/react";
910

1011
import { ContextProviders, UsersnapProvider } from "@context";
@@ -51,6 +52,7 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
5152
<React.StrictMode>
5253
<QueryClientProvider client={queryClient}>
5354
<ThemeProvider theme={theme}>
55+
<CssBaseline />
5456
<UsersnapProvider>
5557
<BrowserRouter>
5658
<ContextProviders>

govtool/frontend/src/theme.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { createTheme } from "@mui/material/styles";
22
import {
3-
cyan, errorRed, orange, primaryBlue, progressYellow, successGreen,
3+
cyan,
4+
errorRed,
5+
orange,
6+
primaryBlue,
7+
progressYellow,
8+
successGreen,
49
} from "./consts";
510

611
export type Theme = typeof theme;
@@ -17,12 +22,19 @@ export const theme = createTheme({
1722
},
1823
},
1924
components: {
25+
MuiCssBaseline: {
26+
styleOverrides: {
27+
":root": {
28+
fonfFamily: "Poppins, Arial",
29+
},
30+
},
31+
},
2032
MuiAccordion: {
2133
styleOverrides: {
2234
root: {
2335
borderRadius: `12px !important`,
24-
}
25-
}
36+
},
37+
},
2638
},
2739
MuiInputBase: {
2840
styleOverrides: {
@@ -52,7 +64,7 @@ export const theme = createTheme({
5264
{
5365
props: { color: "default", variant: "filled" },
5466
style: {
55-
backgroundColor: primaryBlue.c50
67+
backgroundColor: primaryBlue.c50,
5668
},
5769
},
5870
{
@@ -110,7 +122,7 @@ export const theme = createTheme({
110122
MuiPopover: {
111123
defaultProps: {
112124
elevation: 2,
113-
}
125+
},
114126
},
115127
},
116128
typography: {

govtool/frontend/src/utils/filterOutNullParams.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
export const filterOutNullParams = (
99
originalObject?: Record<string, unknown> | undefined | null,
1010
filterOutKeys?: string[],
11-
) => {
11+
): Record<string, unknown> | null => {
1212
if (!originalObject) {
1313
return null;
1414
}
@@ -20,12 +20,27 @@ export const filterOutNullParams = (
2020
value !== undefined &&
2121
!filterOutKeys?.includes(key)
2222
) {
23-
acc[key] = value;
23+
if (
24+
typeof value === "object" &&
25+
!Array.isArray(value) &&
26+
value !== null
27+
) {
28+
// Recursively filter the nested object
29+
const nestedFiltered = filterOutNullParams(
30+
value as Record<string, unknown>,
31+
filterOutKeys,
32+
);
33+
if (nestedFiltered && Object.keys(nestedFiltered).length > 0) {
34+
acc[key] = nestedFiltered;
35+
}
36+
} else {
37+
acc[key] = value;
38+
}
2439
}
2540
return acc;
2641
},
2742
{},
2843
);
2944

30-
return finalObject;
45+
return Object.keys(finalObject).length > 0 ? finalObject : null;
3146
};

govtool/frontend/src/utils/filterUpdatableProtocolParams.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,36 @@ export const filterUpdatableProtocolParams = (
1919
const finalObject = Object.entries(referenceObject).reduce<
2020
Record<string, unknown>
2121
>((acc, [key, referenceValue]) => {
22+
const originalValue = originalObject[key];
23+
2224
const isValid =
2325
!filterOutKeys?.includes(key) &&
2426
originalObject.hasOwnProperty(key) &&
2527
referenceValue !== undefined &&
2628
referenceValue !== null;
2729

28-
if (isValid) acc[key] = originalObject[key];
30+
if (isValid) {
31+
if (
32+
typeof originalValue === "object" &&
33+
originalValue !== null &&
34+
typeof referenceValue === "object" &&
35+
referenceValue !== null
36+
) {
37+
const nestedFiltered = filterUpdatableProtocolParams(
38+
originalValue as Record<string, unknown>,
39+
referenceValue as Record<string, unknown>,
40+
filterOutKeys,
41+
);
42+
if (nestedFiltered && Object.keys(nestedFiltered).length > 0) {
43+
acc[key] = nestedFiltered;
44+
}
45+
} else {
46+
acc[key] = originalValue;
47+
}
48+
}
2949

3050
return acc;
3151
}, {});
3252

33-
return finalObject;
53+
return Object.keys(finalObject).length > 0 ? finalObject : null;
3454
};

0 commit comments

Comments
 (0)