Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 11 additions & 3 deletions src/runtime/http/express-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,19 +575,27 @@ export class AnchorExpressRouter {
return;
}

const serverConfig = this.config.get('server');
const selectedAsset = this.config.getAsset(transaction.assetCode);
sendJson(res, 200, {
const responseData: Record<string, unknown> & { more_info_url?: string } = {
id: transaction.id,
kind: transaction.kind,
status: transaction.status,
amount: transaction.amount,
asset_code: transaction.assetCode,
asset_issuer: selectedAsset?.issuer,
account: transaction.account,
interactive_url: `${this.config.get('server').interactiveDomain ?? 'http://localhost:3000'}/deposit/${transaction.id}`,
interactive_url: `${serverConfig.interactiveDomain ?? 'http://localhost:3000'}/deposit/${transaction.id}`,
created_at: transaction.createdAt,
updated_at: transaction.updatedAt,
});
};

// Add more_info_url only when interactive domain is configured
if (serverConfig.interactiveDomain) {
responseData.more_info_url = `${serverConfig.interactiveDomain}/deposit/${transaction.id}`;
}
Comment on lines +578 to +596
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve maintainability and type safety, I suggest a small refactor here:

  • Avoid using any for responseData. Record<string, unknown> is a more type-safe alternative that aligns with the sendJson function's signature.
  • Extract the URL components into constants to avoid repetition and make the code DRY (Don't Repeat Yourself). This makes it easier to update the URL structure in the future.
Suggested change
const serverConfig = this.config.get('server');
const responseData: any = {
id: transaction.id,
kind: transaction.kind,
status: transaction.status,
amount: transaction.amount,
asset_code: transaction.assetCode,
account: transaction.account,
interactive_url: `${this.config.get('server').interactiveDomain ?? 'http://localhost:3000'}/deposit/${transaction.id}`,
interactive_url: `${serverConfig.interactiveDomain ?? 'http://localhost:3000'}/deposit/${transaction.id}`,
created_at: transaction.createdAt,
updated_at: transaction.updatedAt,
});
};
// Add more_info_url only when interactive domain is configured
if (serverConfig.interactiveDomain) {
responseData.more_info_url = `${serverConfig.interactiveDomain}/deposit/${transaction.id}`;
}
const serverConfig = this.config.get('server');
const interactiveDomain = serverConfig.interactiveDomain;
const depositUrlPath = `/deposit/${transaction.id}`;
const responseData: Record<string, unknown> = {
id: transaction.id,
kind: transaction.kind,
status: transaction.status,
amount: transaction.amount,
asset_code: transaction.assetCode,
account: transaction.account,
interactive_url: `${interactiveDomain ?? 'http://localhost:3000'}${depositUrlPath}`,
created_at: transaction.createdAt,
updated_at: transaction.updatedAt,
};
// Add more_info_url only when interactive domain is configured
if (interactiveDomain) {
responseData.more_info_url = `${interactiveDomain}${depositUrlPath}`;
}


sendJson(res, 200, responseData);
return;
}

Expand Down
1 change: 1 addition & 0 deletions tests/mvp-express.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ describe('MVP Express-mounted integration', () => {
expect(response.body.interactive_url).toBe(
`https://anchor.example.com/deposit/${transactionId}`,
);
expect(response.body.more_info_url).toBe(`https://anchor.example.com/deposit/${transactionId}`);
});

it('7b) transaction lookup returns 404 for non-existent ID', async () => {
Expand Down
Loading