Skip to content

Commit a4d1da1

Browse files
committed
Enhance error handling in confirmation screens for insufficient funds
- Added specific error messages for insufficient native funds in both `SwapConfirmationScreen` and `TransferConfirmationScreen`. - Improved user feedback by providing clear titles and messages when transactions cannot be approved or confirmed due to lack of funds for gas.
1 parent 3a32f3f commit a4d1da1

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ export function SwapConfirmationScreen(props: {
7878
message: "Your wallet rejected the approval request.",
7979
};
8080
}
81+
if (error.toLowerCase().includes("insufficient funds for gas")) {
82+
return {
83+
title: "Insufficient Native Funds",
84+
message:
85+
"You do not have enough native funds to approve the transaction.",
86+
};
87+
}
8188
return {
8289
title: "Failed to Approve",
8390
message:
@@ -96,6 +103,13 @@ export function SwapConfirmationScreen(props: {
96103
message: "Your wallet rejected the confirmation request.",
97104
};
98105
}
106+
if (error.toLowerCase().includes("insufficient funds for gas")) {
107+
return {
108+
title: "Insufficient Native Funds",
109+
message:
110+
"You do not have enough native funds to confirm the transaction.",
111+
};
112+
}
99113
return {
100114
title: "Failed to Confirm",
101115
message:
@@ -333,6 +347,7 @@ export function SwapConfirmationScreen(props: {
333347
} catch (e) {
334348
console.error(e);
335349
setStatus("error");
350+
setError((e as Error).message);
336351
}
337352
}
338353
}}

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/TransferConfirmationScreen.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ export function TransferConfirmationScreen(
126126
message: "Your wallet rejected the approval request.",
127127
};
128128
}
129+
if (status.error.toLowerCase().includes("insufficient funds for gas")) {
130+
return {
131+
title: "Insufficient Native Funds",
132+
message:
133+
"You do not have enough native funds to approve the transaction.",
134+
};
135+
}
129136
return {
130137
title: "Failed to Approve",
131138
message:
@@ -138,12 +145,23 @@ export function TransferConfirmationScreen(
138145
status.id === "error" &&
139146
status.error
140147
) {
141-
if (status.error.toLowerCase().includes("user rejected")) {
148+
if (
149+
status.error.toLowerCase().includes("user rejected") ||
150+
status.error.toLowerCase().includes("user closed modal") ||
151+
status.error.toLowerCase().includes("user denied")
152+
) {
142153
return {
143154
title: "Failed to Confirm",
144155
message: "Your wallet rejected the confirmation request.",
145156
};
146157
}
158+
if (status.error.toLowerCase().includes("insufficient funds for gas")) {
159+
return {
160+
title: "Insufficient Native Funds",
161+
message:
162+
"You do not have enough native funds to confirm the transaction.",
163+
};
164+
}
147165
return {
148166
title: "Failed to Confirm",
149167
message:

0 commit comments

Comments
 (0)