diff --git a/src/components/ErrorDialog.tsx b/src/components/ErrorDialog.tsx deleted file mode 100644 index ae848b75..00000000 --- a/src/components/ErrorDialog.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import { Button } from '@/components/ui/button'; -import { - Dialog, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, -} from '@/components/ui/dialog'; -import { Error } from '../bindings'; - -export interface ErrorDialogProps { - error: Error | null; - setError: (error: Error | null) => void; -} - -export default function ErrorDialog({ error, setError }: ErrorDialogProps) { - let kind: string | null; - - switch (error?.kind) { - case 'api': - kind = 'API'; - break; - - case 'internal': - kind = 'Internal'; - break; - - case 'not_found': - kind = 'Not Found'; - break; - - case 'unauthorized': - kind = 'Auth'; - break; - - case 'wallet': - kind = 'Wallet'; - break; - - default: - kind = null; - } - - return ( - setError(null)}> - - - {kind ? `${kind} ` : ''}Error - {error?.reason} - - - - - - - ); -} diff --git a/src/contexts/ErrorContext.tsx b/src/contexts/ErrorContext.tsx index 19f65905..0f02f9b7 100644 --- a/src/contexts/ErrorContext.tsx +++ b/src/contexts/ErrorContext.tsx @@ -1,7 +1,9 @@ +import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, + DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; @@ -41,23 +43,62 @@ export function ErrorProvider({ children }: { children: ReactNode }) { {children} - 0} - onOpenChange={(open) => { - if (!open) { - setErrors([]); - } - }} - > - - - Errors - - There are {errors.length} errors. - - - - + {errors.length > 0 && ( + setErrors(errors.slice(1))} + /> + )} ); } + +export interface ErrorDialogProps { + error: Error | null; + setError: (error: Error | null) => void; +} + +export default function ErrorDialog({ error, setError }: ErrorDialogProps) { + let kind: string | null; + + switch (error?.kind) { + case 'api': + kind = 'API'; + break; + + case 'internal': + kind = 'Internal'; + break; + + case 'not_found': + kind = 'Not Found'; + break; + + case 'unauthorized': + kind = 'Auth'; + break; + + case 'wallet': + kind = 'Wallet'; + break; + + default: + kind = null; + } + + return ( + setError(null)}> + + + {kind ? `${kind} ` : ''}Error + {error?.reason} + + + + + + + ); +} diff --git a/src/pages/CreateProfile.tsx b/src/pages/CreateProfile.tsx index 769017ec..c367b4c4 100644 --- a/src/pages/CreateProfile.tsx +++ b/src/pages/CreateProfile.tsx @@ -18,9 +18,8 @@ import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { useNavigate } from 'react-router-dom'; import * as z from 'zod'; -import { commands, Error, TransactionResponse } from '../bindings'; +import { commands, TransactionResponse } from '../bindings'; import Container from '../components/Container'; -import ErrorDialog from '../components/ErrorDialog'; import { useWalletState } from '../state'; export default function CreateProfile() { @@ -29,7 +28,6 @@ export default function CreateProfile() { const navigate = useNavigate(); const walletState = useWalletState(); - const [error, setError] = useState(null); const [response, setResponse] = useState(null); const formSchema = z.object({ @@ -108,7 +106,6 @@ export default function CreateProfile() { - setResponse(null)} diff --git a/src/pages/MintNft.tsx b/src/pages/MintNft.tsx index c71e22f0..829041b4 100644 --- a/src/pages/MintNft.tsx +++ b/src/pages/MintNft.tsx @@ -27,9 +27,8 @@ import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { useNavigate } from 'react-router-dom'; import * as z from 'zod'; -import { commands, Error, TransactionResponse } from '../bindings'; +import { commands, TransactionResponse } from '../bindings'; import Container from '../components/Container'; -import ErrorDialog from '../components/ErrorDialog'; import { useWalletState } from '../state'; export default function MintNft() { @@ -39,7 +38,6 @@ export default function MintNft() { const { dids } = useDids(); const { addError } = useErrors(); - const [error, setError] = useState(null); const [pending, setPending] = useState(false); const [response, setResponse] = useState(null); @@ -273,7 +271,6 @@ export default function MintNft() { - setResponse(null)} diff --git a/src/pages/Send.tsx b/src/pages/Send.tsx index fec5213e..9f3b6d8f 100644 --- a/src/pages/Send.tsx +++ b/src/pages/Send.tsx @@ -22,13 +22,11 @@ import * as z from 'zod'; import { CatRecord, commands, - Error, events, SendXch, TransactionResponse, } from '../bindings'; import Container from '../components/Container'; -import ErrorDialog from '../components/ErrorDialog'; export default function Send() { const { asset_id: assetId } = useParams(); @@ -42,7 +40,6 @@ export default function Send() { const [asset, setAsset] = useState<(CatRecord & { decimals: number }) | null>( null, ); - const [error, setError] = useState(null); const [response, setResponse] = useState(null); const updateCat = useCallback( @@ -226,7 +223,6 @@ export default function Send() { - setResponse(null)} diff --git a/src/pages/ViewOffer.tsx b/src/pages/ViewOffer.tsx index eb108d8a..964eedd1 100644 --- a/src/pages/ViewOffer.tsx +++ b/src/pages/ViewOffer.tsx @@ -1,7 +1,6 @@ -import { commands, Error, OfferSummary, TakeOfferResponse } from '@/bindings'; +import { commands, OfferSummary, TakeOfferResponse } from '@/bindings'; import ConfirmationDialog from '@/components/ConfirmationDialog'; import Container from '@/components/Container'; -import ErrorDialog from '@/components/ErrorDialog'; import Header from '@/components/Header'; import { OfferCard } from '@/components/OfferCard'; import { Button } from '@/components/ui/button'; @@ -23,7 +22,6 @@ export function ViewOffer() { const [summary, setSummary] = useState(null); const [response, setResponse] = useState(null); - const [error, setError] = useState(null); const [fee, setFee] = useState(''); useEffect(() => { @@ -97,14 +95,6 @@ export function ViewOffer() { - - { - setError(error); - if (error === null) navigate('/offers'); - }} - /> (null); - const [error, setError] = useState(null); useEffect(() => { if (!offerId) return; @@ -29,17 +25,7 @@ export function ViewSavedOffer() { <>
- - {record && } - - { - setError(error); - if (error === null) navigate('/offers'); - }} - /> - + {record && } ); }