Skip to content

Commit 5ce4f64

Browse files
committed
Refactor code.
Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>
1 parent ee74f72 commit 5ce4f64

File tree

2 files changed

+16
-43
lines changed

2 files changed

+16
-43
lines changed

src/components/ParserOpenRPC/CollapseBox/CollapseBox.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import styles from './styles.module.scss'
88

99
interface CollapseBoxProps {
1010
children: JSX.Element
11-
isInitCollapsed?: boolean
11+
isInitExpanded?: boolean
1212
}
1313

14-
export const CollapseBox = ({ children, isInitCollapsed = false }: CollapseBoxProps) => {
14+
export const CollapseBox = ({ children, isInitExpanded = false }: CollapseBoxProps) => {
1515
const { collapsed, toggleCollapsed } = useCollapsible({ initialState: true })
1616
useEffect(() => {
17-
if (isInitCollapsed) {
17+
if (isInitExpanded) {
1818
toggleCollapsed()
1919
}
20-
}, [isInitCollapsed])
20+
}, [isInitExpanded])
2121
return (
2222
<div className={clsx(styles.collapseWrapper, !collapsed && styles.collapsedWrapperView)}>
2323
<button

src/components/ParserOpenRPC/DetailsBox/RenderParams.tsx

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -45,44 +45,17 @@ const getArrayTypeDescription = (items, schemas) => {
4545
return 'array'
4646
}
4747

48-
// Handle basic types
49-
const itemType = items.type || items.schema?.type
50-
if (itemType) {
51-
switch (itemType) {
52-
case 'string':
53-
return 'array of strings'
54-
case 'number':
55-
return 'array of numbers'
56-
case 'integer':
57-
return 'array of integers'
58-
case 'boolean':
59-
return 'array of booleans'
60-
case 'null':
61-
return 'array of null values'
62-
default:
63-
return 'array'
64-
}
65-
}
66-
67-
// Handle case where items is just a type string (fallback)
68-
if (typeof items === 'string') {
69-
switch (items) {
70-
case 'string':
71-
return 'array of strings'
72-
case 'number':
73-
return 'array of numbers'
74-
case 'integer':
75-
return 'array of integers'
76-
case 'boolean':
77-
return 'array of booleans'
78-
case 'null':
79-
return 'array of null values'
80-
default:
81-
return 'array'
82-
}
48+
// Handle basic types with lookup table
49+
const typeLabels: Record<string, string> = {
50+
string: 'array of strings',
51+
number: 'array of numbers',
52+
integer: 'array of integers',
53+
boolean: 'array of booleans',
54+
null: 'array of null values',
8355
}
8456

85-
return 'array'
57+
const type = typeof items === 'string' ? items : items.type || items.schema?.type
58+
return typeLabels[type] || 'array'
8659
}
8760

8861
const renderSchema = (
@@ -121,7 +94,7 @@ const renderSchema = (
12194
showRequired={showRequired}
12295
/>
12396
<div className="padding-bottom--md">
124-
<CollapseBox isInitCollapsed={isExpandedByDefault}>
97+
<CollapseBox isInitExpanded={isExpandedByDefault}>
12598
<>
12699
{Object.entries(item.properties).map(([key, value]: [string, SchemaPropertyType]) => (
127100
<div key={key} className={styles.paramItemWrapper}>
@@ -207,7 +180,7 @@ const renderSchema = (
207180
/>
208181
{shouldShowDetails && (
209182
<div className="padding-bottom--md">
210-
<CollapseBox isInitCollapsed={isExpandedByDefault}>
183+
<CollapseBox isInitExpanded={isExpandedByDefault}>
211184
{(() => {
212185
// Check if array items are objects - if so, render properties directly (flatter structure)
213186
if (arrayType === 'array of objects') {
@@ -258,7 +231,7 @@ const renderSchema = (
258231
showRequired={showRequired}
259232
/>
260233
<div className="padding-bottom--md">
261-
<CollapseBox isInitCollapsed={false}>
234+
<CollapseBox isInitExpanded={false}>
262235
{item[type].map((option, index) => (
263236
<div key={`${index}`} className={styles.paramItemWrapper}>
264237
{renderSchema(option, schemas, option.title, showRequired, isExpandedByDefault)}

0 commit comments

Comments
 (0)