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

feat: add better handling when play key fails to fetch #275

Merged
merged 7 commits into from
Feb 23, 2022

Conversation

JLaferri
Copy link
Member

Previously when the user had no internet access or Slippi servers were down we would show the online activation step which was pretty confusing to users.

New behavior:
https://user-images.githubusercontent.com/1534726/153937946-e748898c-87fd-4f17-a0fc-5bd83fbbaacb.mp4

this could happen in the case where someone has no internet access or Slippi is down. Previously it would show the online activation step which was pretty confusing to users.
Copy link
Member

@NikhilNarayana NikhilNarayana left a comment

Choose a reason for hiding this comment

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

drop the is prefix on variables, nothing else in the launcher does it that way

loading: boolean;
}> = ({ uid, displayName, playKey, loading }) => {
}> = ({ uid, displayName, playKey, isServerError, loading }) => {
const isErrorText = isServerError || !playKey;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const isErrorText = isServerError || !playKey;
const showErrorText = serverError || !playKey;

.catch((err) => {
console.warn("Error fetching play key: ", err);
set({ playKey: null });
set({ playKey: null, isServerError: true });
Copy link
Member

Choose a reason for hiding this comment

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

Ok so we actually need to think of another way to do this. A user with a brand new account triggers this bit of code and thus they are never able to set their connect code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Huh interesting. In all likelihood I feel like an account without a play key should return a successful result with an empty play key, not an error. I can take a look tomorrow too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed by ac47b41

The connectCode and private objects on getUser were null for a new user.

@@ -100,12 +100,20 @@ export async function fetchPlayKey(): Promise<PlayKey> {

handleErrors(res.errors);

const connectCode = res.data.getUser?.connectCode?.code;
const playKey = res.data.getUser?.private?.playKey;
if (!connectCode || !playKey) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (!connectCode || !playKey) {
const displayName = res.data.getUser?.displayName;
const latestVersion = res.data.getLatestDolphin?.version;
if (!connectCode || !playKey || !displayName || !latestVersion) {

The current use of optional chaining means that displayName and latestVersion can be undefined. This does not actually meet the PlayKey interface as defined:

export interface PlayKey {
  uid: string;
  playKey: string;
  connectCode: string;
  displayName: string;
  latestVersion: string;
}

So we should ensure those values also exist.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with this from a type perspective, but not a functionality perspective. If we fail to get the version, we shouldn't be telling the user that they need to initialize their connect code.

I'd rather add null as a possible type for latest version and handle that correctly in the code.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right. In that case the type needs to be updated to latestVersion: string | null

Copy link
Member Author

Choose a reason for hiding this comment

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

If an optional chain like that fails, does the value become null or undefined? Do ts types differentiate between the two?

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed by fdabb24

Comment on lines 113 to 116
connectCode: connectCode,
playKey: playKey,
displayName: res.data.getUser?.displayName,
latestVersion: res.data.getLatestDolphin?.version,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
connectCode: connectCode,
playKey: playKey,
displayName: res.data.getUser?.displayName,
latestVersion: res.data.getLatestDolphin?.version,
connectCode,
playKey,
displayName,
latestVersion,

This repo uses object shorthand notation so we should stick with that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed by fdabb24

Copy link
Member

@vinceau vinceau left a comment

Choose a reason for hiding this comment

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

Not a big fan of how type-unsafe the GQL endpoints are but maybe we can fix that later. Also we should probably eventually fix the prop drilling that's happening in the UserInfo component but won't block the PR for it.

@JLaferri
Copy link
Member Author

Not a big fan of how type-unsafe the GQL endpoints are but maybe we can fix that later. Also we should probably eventually fix the prop drilling that's happening in the UserInfo component but won't block the PR for it.

GQL is never type unsafe by definition.

@@ -11,6 +11,7 @@ export const useAccount = create(
user: null as firebase.User | null,
loading: false,
playKey: null as PlayKey | null,
serverError: false as boolean | null,
Copy link
Member

Choose a reason for hiding this comment

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

I don't see serverError ever being set to null or being set ambiguously, can we remove that extra type?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably

Copy link
Member

@NikhilNarayana NikhilNarayana left a comment

Choose a reason for hiding this comment

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

LGTM

@NikhilNarayana NikhilNarayana merged commit 7dd2698 into main Feb 23, 2022
@vinceau vinceau deleted the feature/server-downtime branch February 27, 2022 03:48
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