Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ (core) [DSDK-337]: Command signature: pass params to command constructor #99

Merged
merged 2 commits into from
Jun 12, 2024

Conversation

ofreyssinet-ledger
Copy link
Contributor

@ofreyssinet-ledger ofreyssinet-ledger commented Jun 12, 2024

📝 Description

Instead of doing

command = new MyCommand()
sdk.sendCommand({ sessionId, command, params: myParams });

change to

command = new MyCommand(myParams);
sdk.sendCommand({ sessionId, command });

The reasoning is that parameters are part of a command itself, not something living next to it.

❓ Context

✅ Checklist

Pull Requests must pass the CI and be code reviewed. Set as Draft if the PR is not ready.

  • Covered by automatic tests.
  • Impact of the changes:
    • All implemented commands
    • Send command use case

🧐 Checklist for the PR Reviewers

  • The code aligns with the requirements described in the linked JIRA or GitHub issue.
  • The PR description clearly documents the changes made and explains any technical trade-offs or design decisions.
  • There are no undocumented trade-offs, technical debt, or maintainability issues.
  • The PR has been tested thoroughly, and any potential edge cases have been considered and handled.
  • Any new dependencies have been justified and documented.

Copy link

vercel bot commented Jun 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
device-sdk-ts-sample ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2024 11:55am

Comment on lines -107 to -115
it("should not parse the response when getApdu not called", () => {
const PERCENTAGE_RESPONSE = new ApduResponse({
statusCode: PERCENTAGE_RESPONSE_HEX.slice(-2),
data: PERCENTAGE_RESPONSE_HEX.slice(0, -2),
});
expect(() => command.parseResponse(PERCENTAGE_RESPONSE)).toThrow(
InvalidBatteryStatusTypeError,
);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this test was solely needed because there was no constructor initialising the arguments, so if getApdu(params) wasn't called) then some internal prop was not initialised.

@@ -10,6 +10,8 @@ import { ApduResponse } from "@api/device-session/ApduResponse";
* The command to close a runnint application on the device.
*/
export class CloseAppCommand implements Command<void> {
args: void = undefined;
Copy link
Contributor

@aussedatlo aussedatlo Jun 12, 2024

Choose a reason for hiding this comment

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

[ASK] why specifying void here but not in the other commands ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah it's a mistake, I was trying out different stuff and forgot to remove this

@@ -10,6 +10,8 @@ import { ApduResponse } from "@api/device-session/ApduResponse";
* The command to close a runnint application on the device.
*/
export class CloseAppCommand implements Command<void> {
args = undefined;
Copy link
Member

Choose a reason for hiding this comment

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

i think you can just

args;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can't:
Screenshot 2024-06-12 at 14 13 29

@@ -28,6 +28,8 @@ export type GetAppAndVersionResponse = {
export class GetAppAndVersionCommand
implements Command<GetAppAndVersionResponse>
{
args = undefined;
Copy link
Member

Choose a reason for hiding this comment

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

same here

@@ -64,6 +64,8 @@ export type GetOsVersionResponse = {
* Command to get information about the device firmware.
*/
export class GetOsVersionCommand implements Command<GetOsVersionResponse> {
args = undefined;
Copy link
Member

Choose a reason for hiding this comment

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

same here

Copy link
Contributor

@aussedatlo aussedatlo left a comment

Choose a reason for hiding this comment

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

LGTM ✅

@ofreyssinet-ledger ofreyssinet-ledger merged commit 950859f into develop Jun 12, 2024
10 checks passed
@ofreyssinet-ledger ofreyssinet-ledger deleted the refacto/dsdk-337-command-params branch June 12, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants