Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deep links #1327

Merged
merged 3 commits into from
Nov 23, 2024
Merged

Conversation

bryce-mcmath
Copy link
Contributor

Summary of Changes

This PR will fix the deeplink issues (and may also fix the one-message-at-a-time after backgrounding issue)

Related Issues

N/A

Pull Request Checklist

Tick all boxes below to demonstrate that you have completed the respective task. If the item does not apply to your this PR check it anyway to make it apparent that there's nothing to do.

  • All commits contain a DCO Signed-off-by line (we use the DCO GitHub app to enforce this);
  • Updated LICENSE-3RD-PARTY.md for any added dependencies or vendored components;
  • Updated documentation as needed for changed code and new or modified features;
  • Added sufficient tests so that overall code coverage is not reduced.

If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!

Pro Tip 🤓

  • Read our contribution guide at least once; it will save you a few review cycles!
  • Your PR will likely not be reviewed until all the above boxes are checked and all automated tests have passed.

PR template adapted from the Python attrs project.

@bryce-mcmath bryce-mcmath marked this pull request as ready for review November 22, 2024 22:20
@bryce-mcmath bryce-mcmath requested a review from jleach November 22, 2024 22:21
Copy link
Contributor Author

@bryce-mcmath bryce-mcmath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments to aid reviewers

@@ -171,14 +171,13 @@ export class MainContainer implements Container {
loadState<StoreOnboardingState>(LocalStorageKeys.Onboarding, (val) => (onboarding = val)),
])

const state: State = {
...defaultState,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the defaultState spread on state load was sometimes causing the newest values to be overwritten if it got called after state had changed. ie. didAuthenticate gets set to true and then loadState gets called and it gets overwritten with false.

loginAttempt: { ...defaultState.loginAttempt, ...loginAttempt },
preferences: { ...defaultState.preferences, ...preferences },
migration: { ...defaultState.migration, ...migration },
tours: { ...defaultState.tours, ...tours },
onboarding: { ...defaultState.onboarding, ...onboarding },
}
} as State
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typing change here takes it from being "must be a complete state object" to "must be a subset of state type"

@@ -67,7 +67,6 @@ export const defaultState: State = {
seenCredentialOfferTour: false,
seenProofRequestTour: false,
},
loading: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was leftover unused code

Comment on lines +12 to +15
const ready = useMemo(
() => store.authentication.didAuthenticate && ['active', 'inactive'].includes(appStateStatus),
[store.authentication.didAuthenticate, appStateStatus]
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically checking "are you logged in and in the foreground" before we attempt to handle a deeplink

Comment on lines -141 to -145
if (agent) {
await restartExistingAgent()
return agent
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting a new agent every time we log in fixed some issues with improper teardown/restart. My opinion is that until agent.shutdown can reliably finish completely, we shouldn't attempt to restart the agent between logins.

Comment on lines -89 to -91
// handle deeplink events
useEffect(() => {
async function handleDeepLink(deepLink: string) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handling the deeplinks from the TabStack rather than the Rootstack prevented attempts to navigate to the Connection screen before the current stack and navigation is ready

Comment on lines -176 to -197
if (currentState === 'background') {
agent.mediationRecipient
.stopMessagePickup()
.then(() => {
logger.info('Stopped agent message pickup')
})
.catch((err) => {
logger.error(`Error stopping agent message pickup, ${err}`)
})

return
}

if (currentState === 'active') {
agent.mediationRecipient
.initiateMessagePickup()
.then(() => {
logger.info('Resuming agent message pickup')
})
.catch((err) => {
logger.error(`Error resuming agent message pickup, ${err}`)
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Centralized this logic by moving it to the ActivityContext so we're only using AppState listeners in one place

Comment on lines +125 to +128
// stop the tour when the screen unmounts
useEffect(() => {
return stop
}, [stop])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These cleanups are for if the deeplink gets handled when a tour is active, we stop the tour when we navigate away to the connection screen.

@@ -11,7 +11,7 @@ export const AttestationEventTypes = {
export interface AttestationMonitor {
readonly attestationWorkflowInProgress: boolean
shouldHandleProofRequestAutomatically: boolean
start(agent: Agent): Promise<void>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was unnecessarily a promise (had no asynchronous calls) so I just cleaned this up a bit

@@ -68,7 +68,6 @@ export interface State {
tours: Tours
deepLink?: string
migration: Migration
loading: boolean
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, leftover unused code

@@ -86,120 +76,6 @@ const RootStack: React.FC = () => {
})
}, [dispatch, loadState, t])

// handle deeplink events
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chefs kiss

@bryce-mcmath bryce-mcmath merged commit 9484bf8 into openwallet-foundation:main Nov 23, 2024
7 checks passed
@bryce-mcmath bryce-mcmath deleted the fix/deep-links branch November 23, 2024 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants