Skip to content

Commit 6c79528

Browse files
committed
fix: do not cut off game sync username for some profiles
1 parent 1b41a26 commit 6c79528

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/hooks/useStore.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import { flattenedNodes, planetJunctionsMap } from "../utils/nodes";
2727
import { createWithEqualityFn } from "zustand/traditional";
2828
import { shallow } from "zustand/shallow";
29-
import { getGameProfile } from "../utils/profile";
29+
import { getGameProfile, getUsernameFromProfile } from "../utils/profile";
3030
import { assignGroup } from "../utils/hash";
3131

3232
export const useStore = createWithEqualityFn(
@@ -557,10 +557,7 @@ export const useStore = createWithEqualityFn(
557557
)
558558
return;
559559

560-
const accountUsername = gameProfile.DisplayName.slice(
561-
0,
562-
gameProfile.DisplayName.length - 1
563-
);
560+
const accountUsername = getUsernameFromProfile(gameProfile);
564561
if (accountUsername !== gameSyncUsername) {
565562
set({ gameSyncUsername: accountUsername });
566563
updateFirestore({
@@ -656,10 +653,7 @@ export const useStore = createWithEqualityFn(
656653
enableGameSync: async (accountId, platform) => {
657654
const response = await getGameProfile(accountId, platform);
658655
const gameProfile = response?.Results?.[0];
659-
const accountUsername = gameProfile.DisplayName.slice(
660-
0,
661-
gameProfile.DisplayName.length - 1
662-
);
656+
const accountUsername = getUsernameFromProfile(gameProfile);
663657

664658
get().updateFirestore({
665659
gameSyncUsername: accountUsername,

src/utils/profile.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,13 @@ export async function getGameProfile(accountId, platform) {
6868
return json;
6969
}
7070

71+
export function getUsernameFromProfile(profile) {
72+
if (profile.PlatformNames) {
73+
// If the profile is linked to an account from a different platform,
74+
// there is a platform icon character appended to the username.
75+
return profile.DisplayName.slice(0, profile.DisplayName.length - 1);
76+
}
77+
78+
return profile.DisplayName;
79+
}
80+

0 commit comments

Comments
 (0)