Skip to content

Commit

Permalink
feat: handle close drawer error (#92)
Browse files Browse the repository at this point in the history
* feat: add drawer error type

* fix: add handling for swap
  • Loading branch information
sergiubreban authored Nov 13, 2024
1 parent 2dfb242 commit 1b23f91
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
9 changes: 9 additions & 0 deletions lib/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export class NonceStepError extends ExchangeError {
}
}

export class DrawerClosedError extends ExchangeError {
handled: boolean;
constructor(nestedError?: Error) {
super("ll001", nestedError);
this.name = "DrawerClosedError";
this.handled = true;
}
}

export class PayloadStepError extends ExchangeError {
constructor(nestedError?: Error) {
super("swap002", nestedError);
Expand Down
1 change: 1 addition & 0 deletions lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export {
ListAccountError,
ListCurrencyError,
NonceStepError,
DrawerClosedError,
NotEnoughFunds,
PayloadStepError,
SignatureStepError,
Expand Down
22 changes: 17 additions & 5 deletions lib/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from "./api";
import {
CompleteExchangeError,
DrawerClosedError,
IgnoredSignatureStepError,
NonceStepError,
NotEnoughFunds,
Expand Down Expand Up @@ -218,8 +219,13 @@ export class ExchangeSDK {
tokenCurrency: toNewTokenId || "",
})
.catch((error: Error) => {
const err = new NonceStepError(error);
this.logger.error(err);
let err;
if (error instanceof Error && error.name === "DrawerClosedError") {
err = new DrawerClosedError(error);
} else {
err = new NonceStepError(error);
}
this.logger.error(err as Error);
throw err;
});
this.logger.debug("DeviceTransactionId retrieved:", deviceTransactionId);
Expand Down Expand Up @@ -355,10 +361,16 @@ export class ExchangeSDK {
provider: this.providerId,
})
.catch((error: Error) => {
const err = new NonceStepError(error);
this.logger.error(err);
let err;
if (error instanceof Error && error.name === "DrawerClosedError") {
err = new DrawerClosedError(error);
} else {
err = new NonceStepError(error);
}
this.logger.error(err as Error);
throw err;
});
})

this.logger.debug("DeviceTransactionId retrieved:", deviceTransactionId);

// Step 2: Ask for payload creation
Expand Down

0 comments on commit 1b23f91

Please sign in to comment.