Skip to content

Commit 92725c6

Browse files
authored
Enhance value formatting in WalletConnectConfirmDialog (#2827)
* Enhance value formatting in WalletConnectConfirmDialog for better error handling and display * fix: bump tar override for latest advisory
1 parent 38433d1 commit 92725c6

3 files changed

Lines changed: 36 additions & 9 deletions

File tree

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"tmp": "0.2.5",
7878
"qs": "6.14.1",
7979
"schema-utils": "3.3.0",
80-
"tar": "7.5.3"
80+
"tar": "7.5.6"
8181
},
8282
"version": "1.2.10-dev132"
8383
}

packages/gui/src/components/walletConnect/WalletConnectConfirmDialog.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,28 @@ const StyledPre = styled(Typography)(() => ({
1515
whiteSpace: 'pre-wrap',
1616
}));
1717

18+
function formatValue(value: unknown): ReactNode {
19+
if (value === null || value === undefined) {
20+
return <Trans>Not Available</Trans>;
21+
}
22+
23+
const valueType = typeof value;
24+
if (valueType === 'string' || valueType === 'number' || valueType === 'boolean' || valueType === 'bigint') {
25+
return value.toString();
26+
}
27+
28+
if (valueType === 'object') {
29+
try {
30+
const formatted = JSON.stringify(value, null, 2);
31+
return <StyledPre variant="body2">{formatted}</StyledPre>;
32+
} catch (error) {
33+
return value.toString();
34+
}
35+
}
36+
37+
return value.toString();
38+
}
39+
1840
function formatStackTrace(stack: StackFrame[]) {
1941
const stackTrace = stack.map(
2042
({ fileName, columnNumber, lineNumber, functionName }) =>
@@ -133,15 +155,20 @@ export default function WalletConnectConfirmDialog(props: WalletConnectConfirmDi
133155
}
134156

135157
const value = values[name];
158+
const valueNode = displayComponent
159+
? displayComponent(value, params, values, handleChangeValues)
160+
: formatValue(value);
136161
return (
137162
<LocalErrorBoundary onError={onError}>
138163
<Flex flexDirection="column" key={name}>
139164
<Typography color="textPrimary">{label ?? name}</Typography>
140-
<Typography color="textSecondary">
141-
{displayComponent
142-
? displayComponent(value, params, values, handleChangeValues)
143-
: (value?.toString() ?? <Trans>Not Available</Trans>)}
144-
</Typography>
165+
{typeof valueNode === 'string' ? (
166+
<Typography color="textSecondary">{valueNode}</Typography>
167+
) : (
168+
<Typography color="textSecondary" component="div">
169+
{valueNode}
170+
</Typography>
171+
)}
145172
</Flex>
146173
</LocalErrorBoundary>
147174
);

0 commit comments

Comments
 (0)