Skip to content

Commit

Permalink
fix initial route for deeplink
Browse files Browse the repository at this point in the history
  • Loading branch information
bryzettler committed Jan 17, 2024
1 parent 0f01331 commit b4030a6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
21 changes: 19 additions & 2 deletions src/features/governance/GovernanceScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DelayedFadeIn } from '@components/FadeInOut'
import SafeAreaBox from '@components/SafeAreaBox'
import Text from '@components/Text'
import TokenPill from '@components/TokenPill'
import { useNavigation } from '@react-navigation/native'
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native'
import globalStyles from '@theme/globalStyles'
import React, { useEffect, useMemo, useRef } from 'react'
import { ScrollView, Animated } from 'react-native'
Expand All @@ -18,17 +18,34 @@ import { PublicKey } from '@solana/web3.js'
import { useAccountStorage } from '@storage/AccountStorageProvider'
import { ProposalsList } from './ProposalsList'
import { VotingPowerCard } from './VotingPowerCard'
import { GovernanceNavigationProp } from './governanceTypes'
import {
GovernanceStackParamList,
GovernanceNavigationProp,
} from './governanceTypes'

type Route = RouteProp<GovernanceStackParamList, 'GovernanceScreen'>
export const GovernanceScreen = () => {
const { t } = useTranslation()
const route = useRoute<Route>()
const navigation = useNavigation<GovernanceNavigationProp>()
const safeEdges = useMemo(() => ['top'] as Edge[], [])
const { currentAccount } = useAccountStorage()
const { loading, mint, setMint, proposalCountByMint, hasUnseenProposals } =
useGovernance()
const anim = useRef(new Animated.Value(1))

useEffect(() => {
// if we have a mint and proposal, navigate to the proposal screen
// this is used for deep linking and to maintain
// GovernanceScreen as the back button
if (route.params?.mint && route.params?.proposal) {
navigation.navigate('ProposalScreen', {
mint: route.params.mint,
proposal: route.params.proposal,
})
}
}, [route, navigation])

useEffect(() => {
if (!loading && hasUnseenProposals) {
const res = Animated.loop(
Expand Down
2 changes: 1 addition & 1 deletion src/features/governance/governanceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type ProposalFilter =

export type GovernanceStackParamList = {
GovernanceTutorialScreen: undefined
GovernanceScreen: undefined
GovernanceScreen: { mint?: string; proposal?: string }
VotingPowerScreen: { mint: string }
ProposalScreen: { mint: string; proposal: string }
}
Expand Down
3 changes: 1 addition & 2 deletions src/utils/linking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export const authenticatedLinking: LinkingOptions<RootStackParamList> = {
screens: {
Governance: {
screens: {
GovernanceScreen: 'governance',
ProposalScreen: 'governance/:mint/proposal/:proposal',
GovernanceScreen: 'governance/:mint/proposal/:proposal',
},
},
},
Expand Down

0 comments on commit b4030a6

Please sign in to comment.