Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
ac2642fe
Unverified
Commit
ac2642fe
authored
Jan 12, 2022
by
Jordan Frankfurt
Committed by
GitHub
Jan 12, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add error reporting component, INTEGRATION ERROR type, and Missing provider error (#3107)
parent
ac962fb0
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
2 deletions
+42
-2
ErrorDialog.tsx
src/lib/components/Error/ErrorDialog.tsx
+3
-1
ErrorReporter.tsx
src/lib/components/Error/ErrorReporter.tsx
+23
-0
Widget.tsx
src/lib/components/Widget.tsx
+2
-0
useEnsureCorrectProps.ts
src/lib/hooks/useEnsureCorrectProps.ts
+11
-0
index.tsx
src/lib/index.tsx
+1
-1
web3.ts
src/lib/state/web3.ts
+2
-0
No files found.
src/lib/components/Error/ErrorDialog.tsx
View file @
ac2642fe
...
@@ -117,7 +117,9 @@ export default function ErrorDialog({ header, error, action, onAction }: ErrorDi
...
@@ -117,7 +117,9 @@ export default function ErrorDialog({ header, error, action, onAction }: ErrorDi
<
Rule
/>
<
Rule
/>
<
ErrorColumn
>
<
ErrorColumn
>
<
Column
gap=
{
0.5
}
ref=
{
setDetails
}
css=
{
scrollbar
}
>
<
Column
gap=
{
0.5
}
ref=
{
setDetails
}
css=
{
scrollbar
}
>
<
ThemedText
.
Code
>
{
error
.
message
}
</
ThemedText
.
Code
>
<
ThemedText
.
Code
>
{
error
.
name
}
:
{
error
.
message
}
</
ThemedText
.
Code
>
</
Column
>
</
Column
>
</
ErrorColumn
>
</
ErrorColumn
>
<
ActionButton
onClick=
{
onAction
}
>
{
action
}
</
ActionButton
>
<
ActionButton
onClick=
{
onAction
}
>
{
action
}
</
ActionButton
>
...
...
src/lib/components/Error/ErrorReporter.tsx
0 → 100644
View file @
ac2642fe
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
}
src/lib/components/Widget.tsx
View file @
ac2642fe
...
@@ -8,6 +8,7 @@ import { Provider as EthProvider } from 'widgets-web3-react/types'
...
@@ -8,6 +8,7 @@ import { Provider as EthProvider } from 'widgets-web3-react/types'
import
{
Provider
as
DialogProvider
}
from
'
./Dialog
'
import
{
Provider
as
DialogProvider
}
from
'
./Dialog
'
import
ErrorBoundary
,
{
ErrorHandler
}
from
'
./Error/ErrorBoundary
'
import
ErrorBoundary
,
{
ErrorHandler
}
from
'
./Error/ErrorBoundary
'
import
ErrorReporter
from
'
./Error/ErrorReporter
'
import
Web3Provider
from
'
./Web3Provider
'
import
Web3Provider
from
'
./Web3Provider
'
const
slideDown
=
keyframes
`
const
slideDown
=
keyframes
`
...
@@ -100,6 +101,7 @@ export default function Widget({
...
@@ -100,6 +101,7 @@ export default function Widget({
<
ErrorBoundary
onError=
{
onError
}
>
<
ErrorBoundary
onError=
{
onError
}
>
<
AtomProvider
>
<
AtomProvider
>
<
Web3Provider
provider=
{
provider
}
jsonRpcEndpoint=
{
jsonRpcEndpoint
}
>
<
Web3Provider
provider=
{
provider
}
jsonRpcEndpoint=
{
jsonRpcEndpoint
}
>
<
ErrorReporter
/>
{
children
}
{
children
}
</
Web3Provider
>
</
Web3Provider
>
</
AtomProvider
>
</
AtomProvider
>
...
...
src/lib/hooks/useEnsureCorrectProps.ts
0 → 100644
View file @
ac2642fe
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
])
}
src/lib/index.tsx
View file @
ac2642fe
...
@@ -3,7 +3,7 @@ import Widget, { WidgetProps } from './components/Widget'
...
@@ -3,7 +3,7 @@ import Widget, { WidgetProps } from './components/Widget'
export
type
SwapWidgetProps
=
WidgetProps
<
typeof
Swap
>
export
type
SwapWidgetProps
=
WidgetProps
<
typeof
Swap
>
export
function
SwapWidget
(
{
...
props
}
:
SwapWidgetProps
)
{
export
function
SwapWidget
(
props
:
SwapWidgetProps
)
{
return
(
return
(
<
Widget
{
...
props
}
>
<
Widget
{
...
props
}
>
<
Swap
{
...
props
}
/>
<
Swap
{
...
props
}
/>
...
...
src/lib/state/web3.ts
View file @
ac2642fe
import
{
createMulticall
}
from
'
@uniswap/redux-multicall
'
import
{
createMulticall
}
from
'
@uniswap/redux-multicall
'
import
{
atom
}
from
'
jotai
'
import
{
atomWithStore
}
from
'
jotai/redux
'
import
{
atomWithStore
}
from
'
jotai/redux
'
import
{
atomWithDefault
}
from
'
jotai/utils
'
import
{
atomWithDefault
}
from
'
jotai/utils
'
import
{
createStore
}
from
'
redux
'
import
{
createStore
}
from
'
redux
'
...
@@ -12,6 +13,7 @@ export type Web3ReactState = [Connector, Web3ReactHooks]
...
@@ -12,6 +13,7 @@ export type Web3ReactState = [Connector, Web3ReactHooks]
export
const
urlAtom
=
atomWithDefault
<
Web3ReactState
>
(()
=>
EMPTY_CONNECTOR
)
export
const
urlAtom
=
atomWithDefault
<
Web3ReactState
>
(()
=>
EMPTY_CONNECTOR
)
export
const
injectedAtom
=
atomWithDefault
<
Web3ReactState
>
(()
=>
EMPTY_CONNECTOR
)
export
const
injectedAtom
=
atomWithDefault
<
Web3ReactState
>
(()
=>
EMPTY_CONNECTOR
)
export
const
providerAtom
=
atom
((
get
)
=>
get
(
injectedAtom
)
||
get
(
urlAtom
))
export
const
multicall
=
createMulticall
()
export
const
multicall
=
createMulticall
()
const
multicallStore
=
createStore
(
multicall
.
reducer
)
const
multicallStore
=
createStore
(
multicall
.
reducer
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment