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: transient label of selected profile name #1640

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/extension-polkagate/src/hooks/useSelectedProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { useEffect, useState } from 'react';

import { getStorage, watchStorage } from '../components/Loading';

export default function useSelectedProfile (): string | undefined {
const [selectedProfile, setSelectedProfile] = useState<string>();
export default function useSelectedProfile (): string | undefined | null {
const [selectedProfile, setSelectedProfile] = useState<string | null>();

useEffect(() => {
/** set profile text in local storage and watch its change to apply on the UI */
getStorage('profile')
.then((res) => {
setSelectedProfile(res as string);
setSelectedProfile(res as string | undefined ?? null);
})
.catch(console.error);

Expand Down
4 changes: 4 additions & 0 deletions packages/extension-polkagate/src/popup/home/AccountLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export function AccountLabel ({ account, ml, parentName }: Props): React.ReactEl
const profiles = useMemo(() => {
const profileSet = new Set(accountProfiles);

if (selectedProfile === undefined) {
return [];
}

Comment on lines +76 to +79
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consider handling both undefined and null cases.

The condition only checks for undefined, but according to the changes in useSelectedProfile hook, it can now return null as well. This might lead to unexpected behavior when selectedProfile is null.

Apply this diff to handle both cases:

-    if (selectedProfile === undefined) {
+    if (selectedProfile === undefined || selectedProfile === null) {
       return [];
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (selectedProfile === undefined) {
return [];
}
if (selectedProfile === undefined || selectedProfile === null) {
return [];
}

if (maybeAccountDefaultProfile) {
profileSet.add(maybeAccountDefaultProfile);
}
Expand Down
Loading