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

fix: wait and skip Ledger Pending review if needed #360

Merged
merged 2 commits into from
Jan 25, 2024
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
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"url": "https://github.com/zondax/zemu/issues"
},
"dependencies": {
"@grpc/grpc-js": "^1.9.13",
"@grpc/grpc-js": "^1.9.14",
"@grpc/proto-loader": "^0.7.10",
"@ledgerhq/hw-transport-http": "^6.29.1",
"axios": "^1.6.5",
"@ledgerhq/hw-transport-http": "^6.29.2",
"axios": "^1.6.6",
"axios-retry": "^4.0.0",
"dockerode": "^4.0.2",
"elfy": "^1.0.0",
Expand All @@ -44,27 +44,27 @@
"randomstring": "^1.3.0"
},
"devDependencies": {
"@ledgerhq/hw-transport": "^6.30.1",
"@ledgerhq/hw-transport": "^6.30.2",
"@types/dockerode": "^3.3.23",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.11",
"@types/node": "^20.11.0",
"@types/node": "^20.11.6",
"@types/pngjs": "^6.0.4",
"@types/randomstring": "^1.1.11",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"@zondax/ledger-substrate": "^0.41.3",
"copyfiles": "^2.4.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard-with-typescript": "^43.0.0",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1",
"jest": "^29.7.0",
"prettier": "^3.1.1",
"prettier": "^3.2.4",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.1",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "5.2.2"
},
Expand Down
35 changes: 29 additions & 6 deletions src/Zemu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ import {
DEFAULT_WAIT_TIMEOUT,
DEFAULT_STAX_START_TEXT,
DEFAULT_NANO_START_TEXT,
DEFAULT_PENDING_REVIEW_TEXT,
} from "./constants";

import EmuContainer from "./emulator";
import GRPCRouter from "./grpc";

import { scheduleToNavElement, TouchNavigation } from "./actions";
import { ClickNavigation, scheduleToNavElement, TouchNavigation } from "./actions";
import { dummyButton, tapContinueButton, TouchElements } from "./buttons";
import {
ActionKind,
Expand Down Expand Up @@ -199,11 +200,33 @@ export default class Zemu {
this.startOptions.startText =
this.startOptions.model === "stax" ? DEFAULT_STAX_START_TEXT : DEFAULT_NANO_START_TEXT;
}
await this.waitForText(
this.startOptions.startText,
this.startOptions.startTimeout,
this.startOptions.caseSensitive,
);
const start = new Date();
let found = false;
let reviewPendingFound = false;
const flags = !this.startOptions.caseSensitive ? "i" : "";
const startRegex = new RegExp(this.startOptions.startText, flags);
const reviewPendingRegex = new RegExp(DEFAULT_PENDING_REVIEW_TEXT, flags);

while (!found) {
const currentTime = new Date();
const elapsed = currentTime.getTime() - start.getTime();
if (elapsed > this.startOptions.startTimeout) {
throw new Error(
`Timeout (${this.startOptions.startTimeout}) waiting for text (${this.startOptions.startText})`,
);
}
const events = await this.getEvents();
if (!reviewPendingFound && events.some((event: IEvent) => reviewPendingRegex.test(event.text))) {
const nav =
this.startOptions.model === "stax"
? new TouchNavigation([ButtonKind.ConfirmYesButton])
: new ClickNavigation([0]);
await this.navigate("", "", nav.schedule, true, false);
reviewPendingFound = true;
}
found = events.some((event: IEvent) => startRegex.test(event.text));
await Zemu.sleep();
}

this.log(`Get initial snapshot and events`);
this.mainMenuSnapshot = await this.snapshot();
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const DEFAULT_EMU_IMG = "zondax/builder-zemu:speculos-e262a0ca9d2b37810d0
export const DEFAULT_MODEL = "nanos";
export const DEFAULT_NANO_START_TEXT = "Ready";
export const DEFAULT_STAX_START_TEXT = "This application enables";
export const DEFAULT_PENDING_REVIEW_TEXT = "Ledger review"
export const DEFAULT_START_DELAY = 20000;
export const DEFAULT_KEY_DELAY = 250;
export const DEFAULT_HOST = "127.0.0.1";
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"declaration": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"outDir": "./dist"
"outDir": "./dist",
},
"include": ["src"]
"include": ["src"],
}
Loading
Loading