fix: show error message correctly (#2705)

This commit is contained in:
Dexter Edwards 2023-01-24 11:29:42 +00:00 committed by GitHub
parent e883ef5c5e
commit 01e7b8caee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 10 deletions

View File

@ -5,12 +5,14 @@ interface StakeFailureProps {
nodeName: string;
isDialogVisible: boolean;
toggleDialog: () => void;
error: Error | null;
}
export const StakeFailure = ({
nodeName,
isDialogVisible,
toggleDialog,
error,
}: StakeFailureProps) => {
const { t } = useTranslation();
return (
@ -20,11 +22,15 @@ export const StakeFailure = ({
open={isDialogVisible}
onChange={toggleDialog}
>
<p>
{t('stakeFailed', {
node: nodeName,
})}
</p>
{error ? (
<p>{error.message}</p>
) : (
<p>
{t('stakeFailed', {
node: nodeName,
})}
</p>
)}
</Dialog>
);
};

View File

@ -13,6 +13,7 @@ interface StakeFormTxStatusesProps {
removeType: RemoveType;
isDialogVisible: boolean;
toggleDialog: () => void;
error: Error | null;
}
export const StakingFormTxStatuses = ({
@ -23,6 +24,7 @@ export const StakingFormTxStatuses = ({
removeType,
isDialogVisible,
toggleDialog,
error,
}: StakeFormTxStatusesProps) => {
switch (formState) {
case FormState.Requested:
@ -59,6 +61,7 @@ export const StakingFormTxStatuses = ({
nodeName={nodeName}
isDialogVisible={isDialogVisible}
toggleDialog={toggleDialog}
error={error}
/>
);
default:

View File

@ -70,6 +70,7 @@ export const StakingForm = ({
const { appState } = useAppState();
const { sendTx } = useVegaWallet();
const [formState, setFormState] = React.useState(FormState.Default);
const [error, setError] = useState<Error | null>(null);
const [isDialogVisible, setIsDialogVisible] = useState(false);
const { t } = useTranslation();
const [action, setAction] = React.useState<StakeAction>(
@ -135,12 +136,15 @@ export const StakingForm = ({
// await success via poll
} catch (err) {
if (err instanceof Error) {
setError(err);
}
setFormState(FormState.Failure);
Sentry.captureException(err);
}
}
const [delegationSearch, { data, error }] = usePartyDelegationsLazyQuery({
const [delegationSearch, { data }] = usePartyDelegationsLazyQuery({
variables: {
partyId: pubKey,
},
@ -170,10 +174,6 @@ export const StakingForm = ({
clearInterval(interval);
}
}
if (error) {
Sentry.captureException(error);
}
}, 1000);
}
@ -306,6 +306,7 @@ export const StakingForm = ({
removeType={removeType}
isDialogVisible={isDialogVisible}
toggleDialog={toggleDialog}
error={error}
/>
</>
);