Skip to content

Commit

Permalink
Merge pull request #339 from GridPlus/skip-wrong-wallet-retry
Browse files Browse the repository at this point in the history
Skip wrong wallet retry
  • Loading branch information
alex-miller-0 authored Mar 22, 2022
2 parents 537b5e9 + 9a420ea commit 8b5a7eb
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class Client {
private privKey: Buffer;
private retryCount: number;
private fwVersion: Buffer;
private skipRetryOnWrongWallet: boolean;

/** Temporary secret that is generated by the Lattice device */
private ephemeralPub: KeyPair;
Expand Down Expand Up @@ -105,20 +106,25 @@ export class Client {
/**
* @param params - Parameters are passed as an object.
*/
constructor({ baseUrl, name, privKey, stateData, timeout, retryCount }: {
/** The base URL of the signing server. */
baseUrl?: string;
/** The name of the client. */
name?: string;
/** The private key of the client.*/
privKey?: Buffer;
/** Number of times to retry a request if it fails. */
retryCount?: number;
/** The time to wait for a response before cancelling. */
timeout?: number;
/** User can pass in previous state data to rehydrate connected session */
stateData?: string;
}) {
constructor({
baseUrl, name, privKey, stateData, timeout, retryCount, skipRetryOnWrongWallet
}: {
/** The base URL of the signing server. */
baseUrl?: string;
/** The name of the client. */
name?: string;
/** The private key of the client.*/
privKey?: Buffer;
/** Number of times to retry a request if it fails. */
retryCount?: number;
/** The time to wait for a response before cancelling. */
timeout?: number;
/** User can pass in previous state data to rehydrate connected session */
stateData?: string;
/** If true we will not retry if we get a wrong wallet error code */
skipRetryOnWrongWallet: boolean;
}
) {
// Default state params
// -----
this.ephemeralPub = null;
Expand All @@ -138,6 +144,7 @@ export class Client {
external: true,
},
};
this.skipRetryOnWrongWallet = skipRetryOnWrongWallet || false;

// The user may pass in state data to rehydrate a session that was previously cached
// -----
Expand Down Expand Up @@ -1105,7 +1112,7 @@ export class Client {
}
this._request(payload, encReqCode, cb, retryCount - 1);
});
} else if (canRetry && wrongWallet) {
} else if (canRetry && wrongWallet && !this.skipRetryOnWrongWallet) {
// Incorrect wallet being requested. Clear wallet state.
this._resetActiveWallets();
// Refetch the active wallet.
Expand Down

0 comments on commit 8b5a7eb

Please sign in to comment.