Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,19 +245,9 @@ async function processSingleField(
ctx.formatEmbeddedCalldata,
);

// Apply separator prefix for array elements (e.g. "Recipient {index}" → "Recipient 0")
let finalValue = rendered;
if (merged.separator && merged.path) {
const indexMatch = merged.path.match(/\.\[(\d+)\]/);
if (indexMatch) {
const sep = merged.separator.replace("{index}", indexMatch[1]);
finalValue = `${sep} ${rendered}`;
}
}

const displayField: DisplayField = {
label: merged.label,
value: finalValue,
value: rendered,
fieldType: argValue.type,
format: merged.format,
warning: fieldWarning,
Expand All @@ -267,7 +257,7 @@ async function processSingleField(
};

if (merged.path) {
ctx.renderedValues.set(stripStructuredRootPrefix(merged.path), finalValue);
ctx.renderedValues.set(stripStructuredRootPrefix(merged.path), rendered);
}
return { field: displayField };
}
Expand Down
16 changes: 8 additions & 8 deletions test/erc7730-test-cases/example-array-iteration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe("example-array-iteration.json — distribute", () => {
const recipient0 = group.fields[0];
assert(!isFieldGroup(recipient0));
expect(recipient0.label).toBe("Recipients");
expect(recipient0.value).toBe(`Recipient 0 ${RECIPIENT_1_NAME}`);
expect(recipient0.value).toBe(RECIPIENT_1_NAME);
expect(recipient0.fieldType).toBe("address");
expect(recipient0.format).toBe("addressName");
expect(recipient0.rawAddress).toBe(checksumRecipient1);
Expand All @@ -173,7 +173,7 @@ describe("example-array-iteration.json — distribute", () => {
const recipient1 = group.fields[2];
assert(!isFieldGroup(recipient1));
expect(recipient1.label).toBe("Recipients");
expect(recipient1.value).toBe(`Recipient 1 ${RECIPIENT_2_NAME}`);
expect(recipient1.value).toBe(RECIPIENT_2_NAME);
expect(recipient1.fieldType).toBe("address");
expect(recipient1.format).toBe("addressName");
expect(recipient1.rawAddress).toBe(checksumRecipient2);
Expand Down Expand Up @@ -206,7 +206,7 @@ describe("example-array-iteration.json — distribute", () => {

// interpolatedIntent expands array paths with " and " joining
expect(result.interpolatedIntent).toBe(
`Distribute fees 99.01% and 0.99% among recipients Recipient 0 ${RECIPIENT_1_NAME} and Recipient 1 ${RECIPIENT_2_NAME}`,
`Distribute fees 99.01% and 0.99% among recipients ${RECIPIENT_1_NAME} and ${RECIPIENT_2_NAME}`,
);
expect(result.warnings).toBeUndefined();
});
Expand Down Expand Up @@ -482,7 +482,7 @@ describe("example-array-iteration.json — batchExecute", () => {
const recipient = group.fields[0];
assert(!isFieldGroup(recipient));
expect(recipient.label).toBe("Recipients");
expect(recipient.value).toBe(`Recipient 0 ${recipientName}`);
expect(recipient.value).toBe(recipientName);
expect(recipient.fieldType).toBe("address");
expect(recipient.format).toBe("addressName");
expect(recipient.rawAddress).toBe(
Expand Down Expand Up @@ -516,7 +516,7 @@ describe("example-array-iteration.json — batchExecute", () => {
expect(nested.rawCalldataFallback).toBeUndefined();

expect(nested.interpolatedIntent).toBe(
`Distribute fees 100% among recipients Recipient 0 ${recipientName}`,
`Distribute fees 100% among recipients ${recipientName}`,
);
expect(nested.warnings).toBeUndefined();
}
Expand Down Expand Up @@ -546,7 +546,7 @@ describe("example-array-iteration.json — batchExecute", () => {
const calldataField = group.fields[0];
assert(!isFieldGroup(calldataField));
expect(calldataField.label).toBe("Nested Calls");
expect(calldataField.value).toBe(`Transaction 0 0x${INNER_DISTRIBUTE_1}`);
expect(calldataField.value).toBe(`0x${INNER_DISTRIBUTE_1}`);
expect(calldataField.fieldType).toBe("bytes");
expect(calldataField.format).toBe("calldata");
expect(calldataField.rawAddress).toBeUndefined();
Expand Down Expand Up @@ -609,7 +609,7 @@ describe("example-array-iteration.json — batchExecute", () => {
const field0 = group.fields[0];
assert(!isFieldGroup(field0));
expect(field0.label).toBe("Nested Calls");
expect(field0.value).toBe(`Transaction 0 0x${INNER_DISTRIBUTE_1}`);
expect(field0.value).toBe(`0x${INNER_DISTRIBUTE_1}`);
expect(field0.fieldType).toBe("bytes");
expect(field0.format).toBe("calldata");
expect(field0.rawAddress).toBeUndefined();
Expand All @@ -631,7 +631,7 @@ describe("example-array-iteration.json — batchExecute", () => {
const field1 = group.fields[1];
assert(!isFieldGroup(field1));
expect(field1.label).toBe("Nested Calls");
expect(field1.value).toBe(`Transaction 1 0x${INNER_DISTRIBUTE_2}`);
expect(field1.value).toBe(`0x${INNER_DISTRIBUTE_2}`);
expect(field1.fieldType).toBe("bytes");
expect(field1.format).toBe("calldata");
expect(field1.rawAddress).toBeUndefined();
Expand Down
8 changes: 5 additions & 3 deletions test/fields.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ describe("applyFieldFormats", () => {
});

describe("separator handling", () => {
it("prepends separator with interpolated {index} to array elements", async () => {
it("does not include separator text in rendered array values", async () => {
const format: DescriptorFormatSpec = {
fields: [
{
Expand Down Expand Up @@ -481,8 +481,10 @@ describe("applyFieldFormats", () => {
assert(!("warnings" in result));
const group = result.fields[0];
assert(isFieldGroup(group));
expect(group.fields[0].value).toBe("Item 0 10");
expect(group.fields[1].value).toBe("Item 1 20");
expect(group.fields[0].value).toBe("10");
expect(group.fields[1].value).toBe("20");
expect(result.renderedValues.get("vals.[]")).toBe("10 and 20");
expect(result.renderedValues.get("vals")).toBe("10 and 20");
});
});

Expand Down