Skip to content

Commit 67ddb80

Browse files
author
Llorenç
committed
CR changes
1 parent 1453560 commit 67ddb80

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/ledger/identity.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,12 @@ export class LedgerIdentity extends SignIdentity {
107107
derivePath: string
108108
): Promise<Secp256k1PublicKey> {
109109
const resp = await app.getAddressAndPubKey(derivePath);
110-
// @ts-ignore
111-
if (resp.returnCode == 28161) {
110+
// Code references: https://github.com/Zondax/ledger-js/blob/799b056c0ed40af06d375b2b6220c0316f272fe7/src/consts.ts#L31
111+
if (resp.returnCode == 0x6e01) {
112112
throw "Please open the Internet Computer app on your wallet and try again.";
113-
} else if (resp.returnCode == 65535) {
113+
} else if (resp.returnCode == 0x5515) {
114114
throw "Ledger Wallet is locked. Unlock it and try again.";
115-
// @ts-ignore
116-
} else if (resp.returnCode == 65535) {
115+
} else if (resp.returnCode == 0xffff) {
117116
throw "Unable to fetch the public key. Please try again.";
118117
} else if (isNullish(resp.publicKey)) {
119118
throw "Public key not available. Please try again.";
@@ -154,11 +153,21 @@ export class LedgerIdentity extends SignIdentity {
154153
public async getVersion(): Promise<Version> {
155154
return this._executeWithApp(async (app: LedgerApp) => {
156155
const res = await app.getVersion();
157-
// TODO: What would it mean if there is no version? Should we throw an error?
156+
if (
157+
isNullish(res.major) ||
158+
isNullish(res.minor) ||
159+
isNullish(res.patch)
160+
) {
161+
throw new Error(
162+
`A ledger error happened during version fetch:
163+
Code: ${res.returnCode}
164+
Message: ${JSON.stringify(res.errorMessage)}`
165+
);
166+
}
158167
return {
159-
major: res.major ?? 0,
160-
minor: res.minor ?? 0,
161-
patch: res.patch ?? 0,
168+
major: res.major,
169+
minor: res.minor,
170+
patch: res.patch,
162171
};
163172
});
164173
}

0 commit comments

Comments
 (0)