Skip to content

Commit 46ef129

Browse files
committed
proper noCancel pass
1 parent 0309c2b commit 46ef129

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/app/components/Modals/ErrorModal.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const ErrorModal: React.FC<ErrorModalProps> = ({
2222
errorMessage,
2323
errorState,
2424
noCancel,
25-
errorTime,
25+
// errorTime, // This prop is not used in the component
2626
}) => {
2727
const { error, retryErrorAction } = useError();
2828

@@ -95,7 +95,7 @@ export const ErrorModal: React.FC<ErrorModalProps> = ({
9595
<p className="text-center">{getErrorMessage()}</p>
9696
</div>
9797
<div className="mt-4 flex justify-around gap-4">
98-
{noCancel && (
98+
{!noCancel && ( // Only show the cancel button if noCancel is false or undefined
9999
<button
100100
className="btn btn-outline flex-1 rounded-lg px-2"
101101
onClick={() => onClose()}

src/app/context/Error/ErrorContext.tsx

+13-5
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ interface ErrorContextType {
2020
retryErrorAction?: () => void;
2121
showError: (showErrorParams: ShowErrorParams) => void;
2222
hideError: () => void;
23+
noCancel?: boolean;
2324
}
2425

2526
export const ErrorProvider: React.FC<ErrorProviderProps> = ({ children }) => {
2627
const [isErrorOpen, setIsErrorOpen] = useState(false);
28+
const [isNoCancel, setIsNoCancel] = useState(false);
2729
const [error, setError] = useState<ErrorType>({
2830
message: "",
2931
errorTime: new Date(),
@@ -33,11 +35,15 @@ export const ErrorProvider: React.FC<ErrorProviderProps> = ({ children }) => {
3335
(() => void) | undefined
3436
>();
3537

36-
const showError = useCallback(({ error, retryAction }: ShowErrorParams) => {
37-
setError(error);
38-
setIsErrorOpen(true);
39-
setRetryErrorAction(() => retryAction);
40-
}, []);
38+
const showError = useCallback(
39+
({ error, retryAction, noCancel }: ShowErrorParams) => {
40+
setError(error);
41+
setIsErrorOpen(true);
42+
setIsNoCancel(noCancel ?? false);
43+
setRetryErrorAction(() => retryAction);
44+
},
45+
[],
46+
);
4147

4248
const hideError = useCallback(() => {
4349
setIsErrorOpen(false);
@@ -48,6 +54,7 @@ export const ErrorProvider: React.FC<ErrorProviderProps> = ({ children }) => {
4854
errorState: undefined,
4955
});
5056
setRetryErrorAction(undefined);
57+
setIsNoCancel(false);
5158
}, 300);
5259
}, []);
5360

@@ -57,6 +64,7 @@ export const ErrorProvider: React.FC<ErrorProviderProps> = ({ children }) => {
5764
showError,
5865
hideError,
5966
retryErrorAction,
67+
noCancel: isNoCancel,
6068
};
6169

6270
return (

src/app/page.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ const Home: React.FC<HomeProps> = () => {
5151
const [publicKeyNoCoord, setPublicKeyNoCoord] = useState("");
5252

5353
const [address, setAddress] = useState("");
54-
const { error, isErrorOpen, showError, hideError, retryErrorAction } =
55-
useError();
54+
const {
55+
error,
56+
isErrorOpen,
57+
showError,
58+
hideError,
59+
retryErrorAction,
60+
noCancel,
61+
} = useError();
5662
const { isTermsOpen, closeTerms } = useTerms();
5763

5864
const {
@@ -470,6 +476,7 @@ const Home: React.FC<HomeProps> = () => {
470476
errorTime={error.errorTime}
471477
onClose={hideError}
472478
onRetry={retryErrorAction}
479+
noCancel={noCancel}
473480
/>
474481
<TermsModal open={isTermsOpen} onClose={closeTerms} />
475482
</main>

0 commit comments

Comments
 (0)