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

feat: handle close drawer error #92

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
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;
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you add handled: true here

}

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 @@ -22,6 +22,7 @@ import {
} from "./api";
import {
CompleteExchangeError,
DrawerClosedError,
IgnoredSignatureStepError,
NonceStepError,
NotEnoughFunds,
Expand Down Expand Up @@ -213,8 +214,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 @@ -343,10 +349,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
Loading