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

Swap failed events: only reject committed txs with code !== 0 #3301

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 2 additions & 6 deletions packages/web/components/swap-tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,8 @@ export const SwapTool: FunctionComponent<SwapToolProps> = observer(
});
}
})
.catch((error) => {
console.error("swap failed", error);
if (error instanceof Error && error.message === "Request rejected") {
// don't log when the user rejects in wallet
return;
}
.catch(() => {
console.log("reject sig");
logEvent([EventName.Swap.swapFailed, baseEvent]);
})
.finally(() => {
Expand Down
21 changes: 15 additions & 6 deletions packages/web/hooks/use-swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,15 @@ export function useSwap(
tokenOutMinAmount,
undefined,
signOptions,
() => {
resolve(pools.length === 1 ? "exact-in" : "multihop");
({ code }) => {
if (code)
reject("Failed to send swap exact amount in message");
else resolve(pools.length === 1 ? "exact-in" : "multihop");
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor error handling for clarity and maintainability.

The error handling in the sendTradeTokenInTx function could be made clearer by using a more descriptive error message. Consider including details about the error code when the transaction fails.

- reject("Failed to send swap exact amount in message");
+ reject(`Failed to send swap exact amount in message with error code: ${code}`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
({ code }) => {
if (code)
reject("Failed to send swap exact amount in message");
else resolve(pools.length === 1 ? "exact-in" : "multihop");
({ code }) => {
if (code)
reject(`Failed to send swap exact amount in message with error code: ${code}`);
else resolve(pools.length === 1 ? "exact-in" : "multihop");

}
)
.catch((reason) => {
reject(reason);
// broadcast error or tx rejection
console.error(reason);
});
return pools.length === 1 ? "exact-in" : "multihop";
} else if (routes.length > 1) {
Expand All @@ -389,14 +392,20 @@ export function useSwap(
tokenOutMinAmount,
undefined,
signOptions,
() => {
resolve("multiroute");
({ code }) => {
if (code)
reject(
"Failed to send split route swap exact amount in message"
);
else resolve("multiroute");
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor error handling for clarity and maintainability.

Similar to the previous comment, the error handling here can be improved by providing more information about the failure.

- reject("Failed to send split route swap exact amount in message");
+ reject(`Failed to send split route swap exact amount in message with error code: ${code}`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
({ code }) => {
if (code)
reject(
"Failed to send split route swap exact amount in message"
);
else resolve("multiroute");
({ code }) => {
if (code)
reject(`Failed to send split route swap exact amount in message with error code: ${code}`);
else resolve("multiroute");

}
)
.catch((reason) => {
reject(reason);
// broadcast error or tx rejection
console.error(reason);
});
} else {
// should not be possible because button should be disabled
jonator marked this conversation as resolved.
Show resolved Hide resolved
reject("No routes given");
}
}
Expand Down
Loading