diff --git a/ui/hooks/snaps/useSnapRequest.ts b/ui/hooks/snaps/useSnapRequest.ts deleted file mode 100644 index 8f3109f73780..000000000000 --- a/ui/hooks/snaps/useSnapRequest.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { HandlerType } from '@metamask/snaps-utils'; -import { useEffect, useState } from 'react'; -import { useDispatch } from 'react-redux'; -import { - forceUpdateMetamaskState, - handleSnapRequest, -} from '../../store/actions'; - -type SnapRequest = { - snapId: string; - handler: HandlerType; - request: { - method: string; - params?: Record; - }; -}; - -export const useSnapRequest = (request: SnapRequest) => { - const dispatch = useDispatch(); - const [loading, setLoading] = useState(true); - const [data, setData] = useState(undefined); - const [error, setError] = useState(undefined); - - useEffect(() => { - let cancelled = false; - - async function fetchData() { - try { - setError(undefined); - setLoading(true); - - const newData = await handleSnapRequest({ - ...request, - origin: '', - request: { - jsonrpc: '2.0', - ...request.request, - }, - }); - - if (!cancelled) { - setData(newData); - forceUpdateMetamaskState(dispatch); - } - } catch (err: unknown) { - if (!cancelled) { - setError(err); - } - } finally { - if (!cancelled) { - setLoading(false); - } - } - } - - fetchData(); - - return () => { - cancelled = true; - }; - }, [request]); - - return { loading, data, error }; -};