diff --git a/native/community-settings/tag-farcaster-channel/tag-farcaster-channel.react.js b/native/community-settings/tag-farcaster-channel/tag-farcaster-channel.react.js --- a/native/community-settings/tag-farcaster-channel/tag-farcaster-channel.react.js +++ b/native/community-settings/tag-farcaster-channel/tag-farcaster-channel.react.js @@ -22,6 +22,10 @@ import { useSelector } from '../../redux/redux-utils.js'; import { useStyles, useColors } from '../../themes/colors.js'; +const tagFarcasterErrorMessages: { +[string]: string } = { + already_in_use: 'This Farcaster channel is already tagged to a community.', +}; + export type TagFarcasterChannelParams = { +communityID: string, }; @@ -50,6 +54,8 @@ $ReadOnlyArray, >([]); + const [error, setError] = React.useState(null); + const neynarClientContext = React.useContext(NeynarClientContext); invariant(neynarClientContext, 'NeynarClientContext is missing'); @@ -79,6 +85,7 @@ return; } + setError(null); setSelectedChannel(channelOptions[selectedIndex]); }, [channelOptions], @@ -129,7 +136,7 @@ farcasterChannelID: selectedChannel.id, }); } catch (e) { - console.log('error', e); // TODO: Improve error handling + setError(e.message); throw e; } }, [communityID, createOrUpdateFarcasterChannelTag, selectedChannel]); @@ -146,6 +153,18 @@ [styles.sectionContainer, styles.touchableSectionContainer], ); + const errorMessage = React.useMemo(() => { + if (!error) { + return null; + } + + return ( + + {tagFarcasterErrorMessages[error] ?? 'Unknown error.'} + + ); + }, [error, styles.error]); + const channelSelectionTextContent = selectedChannel?.name ? selectedChannel.name : 'No Farcaster channel tagged'; @@ -172,6 +191,7 @@ color={colors.panelForegroundSecondaryLabel} /> + {errorMessage}