Skip to content

Commit

Permalink
[C-2813] Catch collectibles runtime errors (#3675)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Jun 29, 2023
1 parent 29233ea commit 2064212
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 26 deletions.
50 changes: 27 additions & 23 deletions packages/mobile/src/screens/profile-screen/CollectiblesCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { useDispatch, useSelector } from 'react-redux'
import IconPlay from 'app/assets/images/pbIconPlay.svg'
import { ChainLogo, Tile } from 'app/components/core'
import { makeStyles } from 'app/styles'

import { CollectiblesCardErrorBoundary } from './CollectiblesCardErrorBoundary'
const { setVisibility } = modalsActions
const { setCollectible } = collectibleDetailsUIActions
const getUserId = accountSelectors.getUserId
Expand Down Expand Up @@ -119,28 +121,30 @@ export const CollectiblesCard = (props: CollectiblesCardProps) => {
const url = frameUrl ?? gifUrl

return (
<Tile
styles={{ root: style, content: styles.content }}
onPress={handlePress}
>
{url ? (
<View>
<CollectibleImage style={styles.image} uri={url}>
{mediaType === 'VIDEO' ? (
<View style={styles.iconPlay}>
<IconPlay
height={48}
width={48}
fill='none'
fillSecondary='hsla(0,0%,100%,.6)'
/>
</View>
) : null}
<ChainLogo chain={chain} style={styles.chain} />
</CollectibleImage>
</View>
) : null}
<Text style={styles.title}>{name}</Text>
</Tile>
<CollectiblesCardErrorBoundary>
<Tile
styles={{ root: style, content: styles.content }}
onPress={handlePress}
>
{url ? (
<View>
<CollectibleImage style={styles.image} uri={url}>
{mediaType === 'VIDEO' ? (
<View style={styles.iconPlay}>
<IconPlay
height={48}
width={48}
fill='none'
fillSecondary='hsla(0,0%,100%,.6)'
/>
</View>
) : null}
<ChainLogo chain={chain} style={styles.chain} />
</CollectibleImage>
</View>
) : null}
<Text style={styles.title}>{name}</Text>
</Tile>
</CollectiblesCardErrorBoundary>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { ReactNode } from 'react'
import { PureComponent } from 'react'

import * as Sentry from '@sentry/react-native'

type CollectiblesCardErrorBoundaryProps = {
children: ReactNode
}

export class CollectiblesCardErrorBoundary extends PureComponent<CollectiblesCardErrorBoundaryProps> {
state = {
error: null
}

componentDidCatch(error: Error | null, errorInfo: any) {
this.setState({ error: error?.message })

Sentry.withScope((scope) => {
scope.setExtras(errorInfo)
Sentry.captureException(error)
})
}

render() {
const { error } = this.state
const { children } = this.props

if (error) return null
return <>{children}</>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ export const CollectiblesTab = () => {
</View>
}
renderItem={({ item }) => (
<View style={styles.collectibleListItem}>
<CollectiblesCard collectible={item} ownerId={profile.user_id} />
</View>
<CollectiblesCard
collectible={item}
ownerId={profile.user_id}
style={styles.collectibleListItem}
/>
)}
/>
)
Expand Down

0 comments on commit 2064212

Please sign in to comment.