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

#2070 replace Alert() with the in-app prompt dialog #2091

Merged
merged 11 commits into from
Jun 28, 2024

Conversation

SebinSong
Copy link
Collaborator

@SebinSong SebinSong commented Jun 18, 2024

work on #2070
closes #2096

Below are the screenshots of some places where I repalced the alert() instances.

prompt-task-1 prompt-task-2 prompt-task-3 prompt-task-4 prompt-tesk-5

@taoeffect
The report the error link tag currently doesn't navigate to Application log page and goes to the /dashboard instead. This can be investigated/worked on separately from this issue later on.

@SebinSong SebinSong self-assigned this Jun 18, 2024
Copy link

cypress bot commented Jun 18, 2024

Passing run #2487 ↗︎

0 114 8 0 Flakiness 0

Details:

Merge d193a69 into 5da85fd...
Project: group-income Commit: 54ee5b2ee7 ℹ️
Status: Passed Duration: 10:12 💡
Started: Jun 27, 2024 9:14 PM Ended: Jun 27, 2024 9:24 PM

Review all test suite changes for PR #2091 ↗︎

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

The report the error link tag currently doesn't navigate to Application log page and goes to the /dashboard instead. This can be investigated/worked on separately from this issue later on.

Why not fix it in this PR? FYI, similar problems relating to that link were fixed in #2005 that was just merged

@SebinSong
Copy link
Collaborator Author

@taoeffect

FYI, similar problems relating to that link were fixed in #2005 that was just merged

I've tried it again after merging this but it doesn't fix the issue either.

Why not fix it in this PR?

I actually already spent a few hours investigating this problem and the root cause is that, this block of navigation guard logic triggers before this block of silent login in main.js is complete.
To give more details, that navigation guard logic is there to prevent users from accessing any modal meant to be used in post-auth area if they are not signed in. Our current silent login logic actually involves fetching user-data from the DB and storing them to the Vuex store, which takes a bit of time. So that nav guard logic actually should either be registered after some delay or moved to somewhere else.

I couldn't come up with the best solution for it straight away and thought it deserves some more time alone. it's a typical little code updates but with longer effort kind of issue I think.

@SebinSong
Copy link
Collaborator Author

@taoeffect Just updated this PR for the fix of #2096 too

@SebinSong
Copy link
Collaborator Author

@taoeffect some comment re above :
I did not implement the requirement as part of the /pending-approval page because it was not that page that captures and console-log out the error. So I thought the in-app prompt UI we have would be a more suitable solution here and used it. Cheers,

corrideat
corrideat previously approved these changes Jun 27, 2024
Copy link
Member

@corrideat corrideat left a comment

Choose a reason for hiding this comment

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

Overall, I think this looks fine and is an improvement over alert(). There are two relatively small issues that I think should be addressed. I'm marking this as approved because I don't think either of the things I pointed out are blockers, but you should consider addressing my points.

primaryButton: L('Close')
}

await sbp('gi.ui/prompt', promptOptions)
Copy link
Member

Choose a reason for hiding this comment

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

If you look at how it was previously, it was written in a non-blocking way, which I believe is no longer the case. One reason not to await here is that now you've made an error handler that could potentially throw. Ideally, error handlers should not result in an error.

I'd make it non-blocking again because ideally contracts should not have code that depends on user interation, even when it doesn't block message processing. In this case, I think you can resolve it by removing the await and adding a .catch() handler (this is because not using a catch handler would result in an unhandled promise rejection, if the promise throws).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@corrideat fair point. I think we can just remove async / await here, because there is no required action followed by clicking on that 'Close' button on the prompt.

console.error('Error during contract sync upon login (syncing all contractIDs)', err)

const humanErr = L('Sync error during login: {msg}', { msg: err?.message || 'unknown error' })
throw new GIErrorUIRuntimeError(humanErr)
Copy link
Member

Choose a reason for hiding this comment

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

In cases where you throw, you should use the cause option including the original error (see example below). This allows error handlers access to the original error, which can be helpful for error handling and debugging.

throw new GIErrorUIRuntimeError(humanErr, { cause: err })

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Fantastic work @SebinSong! One minor change request made.

Comment on lines 485 to 494
const primaryClicked = await sbp('gi.ui/prompt', {
heading: L('Failed to join the group'),
question: L('Error details:{br_}{err}', { err: e.message, ...LTags() }),
primaryButton: L('Refresh')
})

if (primaryClicked) {
const url = (window.location.href).split('?')[0]
window.open(url, '_self')
}
Copy link
Member

Choose a reason for hiding this comment

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

In this PR, I think it's best to preserve the behavior of master as much as we can, as it will save both of us headaches on having to think through the consequences of changing the behavior.

Before there was no call to refresh the page, and no there shouldn't be either. It's good to change the behavior to have it show the error, but let's limit it to that for now unless there's a strong reason to do more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@taoeffect Will do so. I added the page refresh logic here as it was part of the suggested solution of the issue #2096, BTW.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, but isn't #2096 about updating the PendingApproval page? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@taoeffect
Yes, I started off looking at the PendingApproval.vue but then realised /pending-approval page is merely the place redirected to as a follow-up step of an actual async action where the error is thrown, meaning PendingApproval.vue cannot catch that error.

For example,
await sbp('gi.actions/group/joinWithInviteSecret') here leads to a chain of several sbp calls which involves sbp('gi.actions/group/join') (here in identity.js contract) down the line. that's actually where the target error mostly occurs. So I decided to add the prompt logic there instead.

So even after we land /pending-approval page, there is still a chain of async operations (which started before the page navigation) going on behind the scene. so the error thrown as part of that looks like it occurred within the pending approval page. This is what it appeared from my investigation.

@SebinSong
Copy link
Collaborator Author

@taoeffect
Updated the PR again according to the feedbacks

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Nice job @SebinSong !

@taoeffect taoeffect merged commit f0307d5 into master Jun 28, 2024
4 checks passed
@taoeffect taoeffect deleted the sebin/task/#2070-replace-alert-with-inapp-prompt branch June 28, 2024 15:37
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.

Poor handling of error when waiting to join group
3 participants