-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add error reporting component, INTEGRATION ERROR type, and Missing pr…
…ovider error (#3107)
- Loading branch information
1 parent
ac962fb
commit ac2642f
Showing
6 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useAtomValue } from 'jotai/utils' | ||
import { providerAtom } from 'lib/state/web3' | ||
import { useEffect } from 'react' | ||
import { EMPTY } from 'widgets-web3-react/empty' | ||
|
||
class IntegrationError extends Error { | ||
constructor(message: string) { | ||
super(message) | ||
this.name = 'INTEGRATION ERROR' | ||
} | ||
} | ||
|
||
const missingProviderError = new IntegrationError('Missing provider') | ||
|
||
export default function ErrorReporter() { | ||
const [connector] = useAtomValue(providerAtom) | ||
useEffect(() => { | ||
if (connector === EMPTY) { | ||
throw missingProviderError | ||
} | ||
}, [connector]) | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { WidgetProps } from 'lib/components/Widget' | ||
import { missingProviderError } from 'lib/errors' | ||
import { useEffect } from 'react' | ||
|
||
export function useEnsureCorrectProps(props: WidgetProps) { | ||
useEffect(() => { | ||
if (!props.provider) { | ||
throw missingProviderError | ||
} | ||
}, [props]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters