diff --git a/.changeset/fuzzy-dryers-speak.md b/.changeset/fuzzy-dryers-speak.md new file mode 100644 index 000000000..2d908cd68 --- /dev/null +++ b/.changeset/fuzzy-dryers-speak.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/device-management-kit-sample": patch +--- + +Pretty print buffers in device actions logs diff --git a/apps/sample/src/components/DeviceActionsView/DeviceActionResponse.tsx b/apps/sample/src/components/DeviceActionsView/DeviceActionResponse.tsx index 4c30add87..3417253fc 100644 --- a/apps/sample/src/components/DeviceActionsView/DeviceActionResponse.tsx +++ b/apps/sample/src/components/DeviceActionsView/DeviceActionResponse.tsx @@ -1,5 +1,6 @@ import React from "react"; import { + bufferToHexaString, type DeviceActionIntermediateValue, type DeviceActionState, DeviceActionStatus, @@ -38,6 +39,14 @@ const TooltipTitle = styled(Text).attrs({ flex-grow: 0; `; +function bufferStringifyReplacer(_key: string, value: unknown): unknown { + // Pretty-print buffers to make signatures or public keys readable + if (value instanceof Uint8Array) { + return bufferToHexaString(value); + } + return value; +} + /** * Component to display an event emitted by a device action. */ @@ -69,7 +78,7 @@ export function DeviceActionResponse< content={ Arguments:{"\n"} - {JSON.stringify(args, null, 2)} + {JSON.stringify(args, bufferStringifyReplacer, 2)} } > @@ -96,7 +105,11 @@ export function DeviceActionResponse< ? inspect(props.error, { depth: null }) : props.deviceActionState.status === DeviceActionStatus.Error ? inspect(props.deviceActionState.error, { depth: null }) - : JSON.stringify(props.deviceActionState, null, 2)} + : JSON.stringify( + props.deviceActionState, + bufferStringifyReplacer, + 2, + )} {!isError && props.deviceActionState.status === DeviceActionStatus.Pending ? (