Skip to content

Commit

Permalink
💄 (smpl) [NO-ISSUE]: Pretty print buffers in device actions logs (#611)
Browse files Browse the repository at this point in the history
  • Loading branch information
paoun-ledger authored Jan 15, 2025
2 parents b9c01ed + 5a62a98 commit e0e2be7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-dryers-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/device-management-kit-sample": patch
---

Pretty print buffers in device actions logs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import {
bufferToHexaString,
type DeviceActionIntermediateValue,
type DeviceActionState,
DeviceActionStatus,
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -69,7 +78,7 @@ export function DeviceActionResponse<
content={
<Text color="neutral.c00" whiteSpace="pre-wrap">
Arguments:{"\n"}
{JSON.stringify(args, null, 2)}
{JSON.stringify(args, bufferStringifyReplacer, 2)}
</Text>
}
>
Expand All @@ -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,
)}
</Text>
{!isError &&
props.deviceActionState.status === DeviceActionStatus.Pending ? (
Expand Down

0 comments on commit e0e2be7

Please sign in to comment.