Skip to content

Commit

Permalink
refactor: more granular error boundaries
Browse files Browse the repository at this point in the history
Let other stake position display as normal event if some other positions has errors
  • Loading branch information
tien committed Jul 4, 2023
1 parent 0c0ca54 commit 42d2683
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/components/widgets/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const ErrorBoundaryDebuggerChildren = (props: PropsWithChildren<{ error?: Error;

return (
<div
css={{ border: '1px dotted red' }}
css={{ 'display': 'contents', '> *': { outline: '1px dotted red' } }}
onContextMenu={event => {
event.preventDefault()
event.stopPropagation()
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/components/widgets/staking/PoolStakes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { selectedSubstrateAccountsState } from '@domains/accounts'
import { usePoolStakes } from '@domains/nominationPools/hooks'
import { useRecoilValue } from 'recoil'
import PoolStakeItem from './PoolStakeItem'
import ErrorBoundary from '../ErrorBoundary'

const PoolStakes = () => {
const pools = usePoolStakes(useRecoilValue(selectedSubstrateAccountsState))

return (
<>
{pools?.map((pool, index) => (
<PoolStakeItem key={index} item={pool} />
<ErrorBoundary key={index} orientation="horizontal">
<PoolStakeItem item={pool} />
</ErrorBoundary>
))}
</>
)
Expand Down
12 changes: 8 additions & 4 deletions apps/web/src/components/widgets/staking/Stakes.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import SectionHeader from '@components/molecules/SectionHeader'
import StakeItem from '@components/recipes/StakeItem'
import { ChainProvider, chainsState } from '@domains/chains'
import { Button, HiddenDetails, Text } from '@talismn/ui'
import { Suspense, useId } from 'react'
import { Link } from 'react-router-dom'
import { useRecoilValue } from 'recoil'

import { ChainProvider, chainsState } from '@domains/chains'
import ErrorBoundary from '../ErrorBoundary'
import PoolStakes from './PoolStakes'
import ValidatorStakes from './ValidatorStakes'

Expand Down Expand Up @@ -59,8 +59,12 @@ const Stakes = () => {
fallback={<StakeItem.Skeleton className={skeletonId} css={{ order: 1, display: 'none' }} />}
>
<ChainProvider value={chain}>
<PoolStakes />
<ValidatorStakes />
<ErrorBoundary orientation="horizontal">
<PoolStakes />
</ErrorBoundary>
<ErrorBoundary orientation="horizontal">
<ValidatorStakes />
</ErrorBoundary>
</ChainProvider>
</Suspense>
))}
Expand Down
9 changes: 7 additions & 2 deletions apps/web/src/components/widgets/staking/ValidatorStakes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useDeriveState, useQueryMultiState, useQueryState } from '@talismn/reac
import { useMemo } from 'react'
import { useRecoilValue, useRecoilValueLoadable, waitForAll } from 'recoil'
import ValidatorStakeItem from './ValidatorStakeItem'
import ErrorBoundary from '../ErrorBoundary'

const useStakes = () => {
const accounts = useRecoilValue(selectedSubstrateAccountsState)
Expand Down Expand Up @@ -79,7 +80,9 @@ const BaseValidatorStakes = () => {
return (
<>
{stakes.map((props, index) => (
<ValidatorStakeItem key={index} {...props} />
<ErrorBoundary key={index} orientation="horizontal">
<ValidatorStakeItem {...props} />
</ErrorBoundary>
))}
</>
)
Expand All @@ -95,7 +98,9 @@ const ValidatorStakesWithFastUnstake = () => {
return (
<>
{stakes.map((props, index) => (
<ValidatorStakeItem key={index} {...props} />
<ErrorBoundary key={index} orientation="horizontal">
<ValidatorStakeItem key={index} {...props} />
</ErrorBoundary>
))}
</>
)
Expand Down

0 comments on commit 42d2683

Please sign in to comment.