Skip to content

Commit

Permalink
feat: show real error if it's a validation error in error modal (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertfolch-redeemeum authored Jun 20, 2024
1 parent 826f7e8 commit a507424
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Typography } from "../../../../ui/Typography";
import { ProfileFormFields } from "../ProfileFormFields";

interface Props {
onBlurName?: () => void;
logoSubtitle?: string;
coverSubtitle?: string;
disableHandle?: boolean;
Expand All @@ -18,7 +17,6 @@ interface Props {
}

export default function LensFormFields({
onBlurName,
logoSubtitle,
coverSubtitle,
disableHandle,
Expand All @@ -42,7 +40,6 @@ export default function LensFormFields({
<div>{children}</div>
</Grid>
<ProfileFormFields
onBlurName={onBlurName}
logoSubtitle={logoSubtitle}
coverSubtitle={coverSubtitle}
handleComponent={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { GridContainer } from "../../../ui/GridContainer";
import { ProfilePreview } from "./ProfilePreview";

interface Props {
onBlurName?: () => void;
logoSubtitle?: string;
coverSubtitle?: string;
handleComponent?: ReactNode;
Expand All @@ -23,7 +22,6 @@ interface Props {
}

export function ProfileFormFields({
onBlurName,
logoSubtitle,
coverSubtitle,
handleComponent: HandleComponent,
Expand Down Expand Up @@ -97,12 +95,7 @@ export function ProfileFormFields({
</FormField>
</GridContainer>
<FormField title="Your brand / name" required>
<Input
name="name"
placeholder="Name"
onBlur={onBlurName}
disabled={disableName}
/>
<Input name="name" placeholder="Name" disabled={disableName} />
</FormField>
{HandleComponent}
<FormField title="Description" required>
Expand Down
24 changes: 20 additions & 4 deletions src/pages/batch-create-offers/BatchCreateOffers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ function BatchCreateOffers() {
setOffersList([]);
setInvalidFile(false);
}
if (e.target) {
// reset value so the same file can be uploaded again (in case the file was modified)
e.target.value = "";
}
};

const sellerOffers = useOffers(
Expand Down Expand Up @@ -232,12 +236,24 @@ function BatchCreateOffers() {
if (hasUserRejectedTx) {
showModal("TRANSACTION_FAILED");
} else {
const defaultError = "Please retry this action";
const userFriendlyError = await extractUserFriendlyError(error, {
txResponse: txResponse as providers.TransactionResponse,
provider: signer?.provider as Provider,
defaultError
});
const isValidationError =
error &&
typeof error === "object" &&
"errors" in error &&
Array.isArray(error.errors) &&
Object.values(error.errors).every((err) => typeof err === "string");
showModal("TRANSACTION_FAILED", {
errorMessage: "Something went wrong",
detailedErrorMessage: await extractUserFriendlyError(error, {
txResponse: txResponse as providers.TransactionResponse,
provider: signer?.provider as Provider
})
detailedErrorMessage:
defaultError === userFriendlyError && isValidationError
? (error?.errors as string[])?.join("\n") || defaultError
: defaultError
});
}
}
Expand Down

0 comments on commit a507424

Please sign in to comment.