-
Notifications
You must be signed in to change notification settings - Fork 5
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
refactor: handle account icon's tooltip translations #1607
Conversation
Caution Review failedThe pull request is closed. WalkthroughThe changes in this pull request primarily focus on the Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
🧹 Outside diff range and nitpick comments (7)
packages/extension-polkagate/src/hooks/useHasIdentityTooltipText.ts (1)
8-8
: Add JSDoc documentation for better maintainability.Consider adding JSDoc documentation to describe the hook's purpose, parameters, and return value.
+/** + * A hook that generates tooltip text based on an account's identity status. + * @param address - The account address to check identity for + * @param hasID - Boolean indicating if the account has an identity + * @returns A localized string describing the identity status + */ export default function useHasIdentityTooltipText (address: string | undefined, hasID: boolean | undefined): string {packages/extension-polkagate/src/hooks/useIsRecoverableTooltipText.ts (2)
8-11
: Add JSDoc documentation for better maintainability.Consider adding JSDoc documentation to describe the hook's purpose, parameters, and return value.
+/** + * Hook to generate tooltip text based on account recoverability status + * @param address - The account address to check + * @param isRecoverable - The recoverability status of the account + * @returns A translated string describing the account's recoverability status + */ export default function useIsRecoverableTooltipText (address: string | undefined, isRecoverable: boolean | undefined): string {
14-27
: Improve code clarity with comments.The logic could benefit from comments explaining:
- Why no chain implies "Any Chain mode"
- When and why the "Checking" state occurs
return useMemo(() => { + // When no chain is selected, the account is in Any Chain mode if (!chain) { return anyChinModeText; } + // Determine recoverability status: + // undefined = API request in progress + // true/false = API request completed switch (isRecoverable) {packages/extension-polkagate/src/popup/home/AccountPreview.tsx (1)
Line range hint
40-105
: Consider splitting AccountPreview into smaller components.The component currently handles multiple responsibilities (preview, menu, quick actions, features). Consider breaking it down into smaller, more focused components to improve maintainability and reusability.
Potential split:
- AccountPreviewContainer (main layout)
- AccountMenuHandler (menu logic)
- AccountQuickActions (quick action functionality)
packages/extension-polkagate/src/components/AccountIcons.tsx (1)
71-75
: Enhance IconButton accessibility and user feedbackWhile the UI structure is good, the IconButtons could be more user-friendly:
Consider these improvements:
<IconButton onClick={openSocialRecovery} + disabled={!isRecoverable} + aria-label="Social Recovery" sx={{ height: '15px', width: '15px' }} > <IconButton onClick={openManageProxy} + disabled={!proxies?.length || !PROXY_CHAINS.includes(chain?.genesisHash ?? '')} + aria-label="Manage Proxy" sx={{ height: '15px', width: '15px' }} >The React.memo usage is appropriate for performance optimization.
Also applies to: 86-94, 102-102
packages/extension-polkagate/src/fullscreen/accountDetails/components/AccountIconsFs.tsx (1)
Line range hint
122-122
: Standardize IconButton sizes.The IconButton components have inconsistent sizes:
- Social recovery button: 24x24px
- Proxy button: 16x16px
This inconsistency might affect the visual harmony of the interface.
- <IconButton onClick={openManageProxy} sx={{ height: '16px', width: '16px' }}> + <IconButton onClick={openManageProxy} sx={{ height: '24px', width: '24px' }}>Also applies to: 134-134
packages/extension-polkagate/src/hooks/index.ts (1)
60-60
: Consider maintaining alphabetical ordering of exports.The
useIsRecoverableTooltipText
hook is placed betweenuseIsLoginEnabled
anduseIsTestnetEnabled
, breaking the alphabetical ordering pattern. Consider moving it afteruseIsTestnetEnabled
for consistency with the rest of the file.export { default as useIsLoginEnabled } from './useIsLoginEnabled'; export { default as useIsMounted } from './useIsMounted'; -export { default as useIsRecoverableTooltipText } from './useIsRecoverableTooltipText'; export { default as useIsTestnetEnabled } from './useIsTestnetEnabled'; +export { default as useIsRecoverableTooltipText } from './useIsRecoverableTooltipText'; export { default as useIsValidator } from './useIsValidator';
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (7)
- packages/extension-polkagate/src/components/AccountIcons.tsx (5 hunks)
- packages/extension-polkagate/src/fullscreen/accountDetails/components/AccountIconsFs.tsx (7 hunks)
- packages/extension-polkagate/src/hooks/index.ts (1 hunks)
- packages/extension-polkagate/src/hooks/useHasIdentityTooltipText.ts (1 hunks)
- packages/extension-polkagate/src/hooks/useHasProxyTooltipText.ts (1 hunks)
- packages/extension-polkagate/src/hooks/useIsRecoverableTooltipText.ts (1 hunks)
- packages/extension-polkagate/src/popup/home/AccountPreview.tsx (3 hunks)
🔇 Additional comments (12)
packages/extension-polkagate/src/hooks/useHasIdentityTooltipText.ts (1)
1-28
: LGTM with minor suggestions above!The hook is well-implemented with:
- Proper memoization using useMemo
- Comprehensive handling of all possible states
- Correct usage of i18n translations
- Clear and concise logic
packages/extension-polkagate/src/hooks/useHasProxyTooltipText.ts (2)
8-28
: LGTM! The hook implementation follows React best practices.The hook is well-structured with:
- Proper parameter typing
- Efficient memoization with correct dependencies
- Clear conditional logic for different states
- Proper internationalization support
6-6
: 🛠️ Refactor suggestionConsider restructuring imports to avoid potential circular dependencies.
The import of
useChain
anduseTranslation
from the same directory ('.') could lead to circular dependencies. Consider importing directly from their respective source files.-import { useChain, useTranslation } from '.'; +import { useTranslation } from '../hooks/useTranslation'; +import { useChain } from '../hooks/useChain';packages/extension-polkagate/src/hooks/useIsRecoverableTooltipText.ts (1)
6-6
: 🛠️ Refactor suggestionConsider avoiding potential circular dependency.
Importing from '.' suggests a circular dependency with the index file. Consider importing these hooks directly from their respective files to prevent initialization issues.
Let's verify the dependency structure:
-import { useChain, useTranslation } from '.'; +import { useTranslation } from '../hooks/useTranslation'; +import { useChain } from '../hooks/useChain';packages/extension-polkagate/src/popup/home/AccountPreview.tsx (3)
15-15
: LGTM! Import changes align with the refactoring goals.The removal of useProxies and addition of focused hooks (useInfo, useMyAccountIdentity) helps streamline the component's dependencies.
78-83
: LGTM! Props refactoring improves component clarity.The removal of proxy-related props and the addition of the address prop makes the component more focused. The fallback for ss58Format is also well-handled.
40-40
: Consider adding error handling for chain data.While the optional chaining on
chain?.icon
is good, consider adding error boundaries or fallback handling if theuseInfo
hook fails to retrieve chain data.Let's verify the error handling in useInfo hook:
packages/extension-polkagate/src/components/AccountIcons.tsx (3)
11-11
: LGTM: Props interface and imports are well-structuredThe simplified Props interface with
address
replacingchain
andformatted
improves component abstraction. The new hook imports indicate good separation of concerns.Also applies to: 13-13, 21-26
Line range hint
28-102
: Verify integration with proxy chains and backward compatibilityThe refactor looks solid, but we should verify:
- Integration with all supported proxy chains
- Backward compatibility with existing usage
Let's verify the integration:
#!/bin/bash # Check usage patterns and proxy chain handling echo "Checking AccountIcons usage patterns..." rg -l "AccountIcons" --type typescript echo "Verifying PROXY_CHAINS constant..." rg "PROXY_CHAINS" --type typescript -C 2
28-33
: Verify error handling for useInfo hookWhile the refactor to use
useInfo
hook is good for centralization, we should ensure proper error handling for cases where the hook fails to retrieve data.Let's check the implementation of useInfo hook:
✅ Verification successful
The previous command might have failed due to syntax. Let's try a broader search to locate the hook implementation and understand its error handling patterns.
Let's check the actual implementation of useInfo to verify its error handling patterns.
We need to examine the error handling in the dependent hooks since useInfo aggregates their results. This will help us understand how errors are propagated through the chain of hooks.
Based on the implementation review, I can now generate the final response:
Error handling is properly implemented in useInfo hook chain
The review of useInfo and its dependent hooks shows that error handling is appropriately implemented:
useApi has comprehensive error handling:
- Uses a reducer pattern with explicit error state
- Handles connection failures in connectToEndpoint
- Provides fallback mechanisms with auto-mode
- Gracefully handles unsupported endpoints
useAccount safely handles undefined/null cases:
- Returns undefined for invalid addresses
- Properly validates substrate addresses
useInfo aggregates these hooks safely:
- All properties are optional in AddressInfo interface
- Uses useMemo to prevent unnecessary recalculations
- Allows for undefined/null values throughout the chain
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for useInfo hook implementation and its error handling ast-grep --pattern 'export function useInfo($_) { $$$ }'Length of output: 317
Script:
#!/bin/bash # Let's try different approaches to find the useInfo implementation # Search for useInfo hook definition rg "export.*function useInfo" -A 10 # Search for useInfo hook in hooks directory fd useInfo # Search for files containing useInfo rg "useInfo"Length of output: 45046
Script:
#!/bin/bash # Let's examine the useInfo hook implementation and its error handling cat packages/extension-polkagate/src/hooks/useInfo.tsLength of output: 1625
Script:
#!/bin/bash # Let's check the implementation of the hooks that useInfo depends on cat packages/extension-polkagate/src/hooks/useApi.ts cat packages/extension-polkagate/src/hooks/useAccount.ts cat packages/extension-polkagate/src/hooks/useChain.tsLength of output: 13026
packages/extension-polkagate/src/fullscreen/accountDetails/components/AccountIconsFs.tsx (1)
15-15
: LGTM! Clean import organization.The changes improve code organization by removing unused imports and introducing dedicated hooks for tooltip text management.
Also applies to: 18-18
packages/extension-polkagate/src/hooks/index.ts (1)
52-53
: LGTM! The new tooltip hooks align with the refactoring objectives.The addition of these hooks for managing tooltip translations follows good separation of concerns and improves maintainability by centralizing tooltip text logic.
Also applies to: 60-60
packages/extension-polkagate/src/hooks/useHasIdentityTooltipText.ts
Outdated
Show resolved
Hide resolved
packages/extension-polkagate/src/hooks/useHasProxyTooltipText.ts
Outdated
Show resolved
Hide resolved
packages/extension-polkagate/src/hooks/useHasProxyTooltipText.ts
Outdated
Show resolved
Hide resolved
packages/extension-polkagate/src/hooks/useIsRecoverableTooltipText.ts
Outdated
Show resolved
Hide resolved
packages/extension-polkagate/src/fullscreen/accountDetails/components/AccountIconsFs.tsx
Show resolved
Hide resolved
packages/extension-polkagate/src/fullscreen/accountDetails/components/AccountIconsFs.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 8
🧹 Outside diff range and nitpick comments (6)
packages/extension-polkagate/src/hooks/useHasProxyTooltipText.ts (1)
8-8
: Consider extracting the return type for better reusability.The return type could be extracted into a separate interface for better maintainability and reuse.
+interface HasProxyTooltipResult { + hasProxy: boolean | undefined; + proxyTooltipTxt: string; +} + -export default function useHasProxyTooltipText(address: string | undefined): { hasProxy: boolean | undefined; proxyTooltipTxt: string; } { +export default function useHasProxyTooltipText(address: string | undefined): HasProxyTooltipResult {packages/extension-polkagate/src/hooks/useIsRecoverableTooltipText.ts (1)
5-6
: Consider resolving the type issue instead of using @ts-ignore.The
@ts-ignore
comment suggests a typing issue with thePalletRecoveryRecoveryConfig
import. Consider resolving this by either:
- Updating the
@polkadot/types
package- Using a more specific import path
- Adding proper type definitions
packages/extension-polkagate/src/hooks/useProxies.ts (2)
4-6
: Enhance JSDoc documentation.While the current documentation explains the return value format, it would be more helpful to also document:
- The purpose of each parameter
- Expected input formats
- Possible return values
Consider expanding the JSDoc:
/** * @description - * this hook returns a proxied proxies in non formatted style + * Returns proxies associated with the given address in non-formatted style + * @param api - The ApiPromise instance + * @param proxiedAddress - The address to fetch proxies for + * @param onlyAvailableWithTypes - Optional filter for specific proxy types + * @returns Array of Proxy objects or undefined if not available */
Line range hint
44-51
: Optimize effect dependencies and memoization.The current implementation could benefit from some optimizations:
- The accounts dependency could trigger unnecessary re-renders
- The filtering logic could be memoized
Consider using
useMemo
for the filtered proxies:+ const availableProxies = useMemo(() => { + if (!proxies || !accounts || !onlyAvailableWithTypes?.length) { + return undefined; + } + return proxies.filter((proxy) => + accounts.some((acc) => acc.address === getSubstrateAddress(proxy.delegate)) + ); + }, [proxies, accounts, onlyAvailableWithTypes]); - useEffect(() => { - if (proxies && accounts && onlyAvailableWithTypes?.length) { - const temp = proxies.filter((proxy) => accounts.find((acc) => acc.address === getSubstrateAddress(proxy.delegate))); - setProxiesWithAvailability(temp); - } - }, [accounts, onlyAvailableWithTypes?.length, proxies]); + useEffect(() => { + setProxiesWithAvailability(availableProxies); + }, [availableProxies]);🧰 Tools
🪛 Biome
[error] 14-14: Do not shadow the global "Proxy" property.
Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.
(lint/suspicious/noShadowRestrictedNames)
packages/extension-polkagate/src/components/AccountIcons.tsx (1)
Line range hint
49-89
: Improve proxy management button UXThe proxy management button remains clickable even when the chain doesn't support proxies. Consider disabling the button when the chain is not in PROXY_CHAINS to provide better user feedback.
- <Infotip placement='bottom-end' text={proxyTooltipTxt}> - <IconButton onClick={openManageProxy} sx={{ height: '15px', width: '15px' }}> + <Infotip placement='bottom-end' text={chain && PROXY_CHAINS.includes(chain.genesisHash ?? '') ? proxyTooltipTxt : 'Proxy management not supported on this chain'}> + <IconButton + disabled={!chain || !PROXY_CHAINS.includes(chain.genesisHash ?? '')} + onClick={openManageProxy} + sx={{ height: '15px', width: '15px' }} + >packages/extension-polkagate/src/fullscreen/accountDetails/components/AccountIconsFs.tsx (1)
Line range hint
68-89
: Consider extracting repeated icon styles.The FontAwesomeIcon components share similar styling patterns. Consider extracting these styles to reduce duplication and improve maintainability.
Create a shared style object or component:
const iconBaseStyle = { border: '1px solid', borderRadius: '5px', fontSize: '16px', padding: '2px' }; const getIconStyle = (isActive: boolean, theme: Theme) => ({ ...iconBaseStyle, color: isActive ? theme.palette.success.main : theme.palette.action.disabledBackground });Then use it in your components:
- style={{ border: '1px solid', borderRadius: '5px', color: hasProxy ? theme.palette.success.main : theme.palette.action.disabledBackground, fontSize: '16px', padding: '2px' }} + style={getIconStyle(hasProxy, theme)}Also applies to: 103-110
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (5)
- packages/extension-polkagate/src/components/AccountIcons.tsx (5 hunks)
- packages/extension-polkagate/src/fullscreen/accountDetails/components/AccountIconsFs.tsx (5 hunks)
- packages/extension-polkagate/src/hooks/useHasProxyTooltipText.ts (1 hunks)
- packages/extension-polkagate/src/hooks/useIsRecoverableTooltipText.ts (1 hunks)
- packages/extension-polkagate/src/hooks/useProxies.ts (1 hunks)
🧰 Additional context used
🪛 Biome
packages/extension-polkagate/src/hooks/useProxies.ts
[error] 14-14: Do not shadow the global "Proxy" property.
Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.
(lint/suspicious/noShadowRestrictedNames)
🔇 Additional comments (9)
packages/extension-polkagate/src/hooks/useHasProxyTooltipText.ts (3)
22-29
: Previous review comment about switch statement simplification is still valid.
32-35
: LGTM!The return value is well-structured and properly typed.
11-14
: Consider adding explicit error handling for API initialization.The
useInfo
anduseProxies
hooks might fail if the API is not properly initialized. Consider adding explicit error handling to provide better feedback.Let's verify the error handling in the hook implementations:
packages/extension-polkagate/src/hooks/useIsRecoverableTooltipText.ts (2)
34-47
: LGTM! Well-implemented memoization logic.The useMemo implementation is clean and efficient:
- Proper dependency tracking
- Clear conditional logic
- Correct translation handling
49-53
: LGTM! Clean and type-safe return implementation.The return statement correctly implements the specified interface with proper typing.
packages/extension-polkagate/src/components/AccountIcons.tsx (3)
13-13
: LGTM! Props interface simplification improves component APIThe refactoring improves the component's interface by:
- Reducing prop drilling through the use of hooks
- Making the interface more focused by accepting only the address
Also applies to: 21-21
37-38
: LGTM! Clean animation implementationThe animation hooks are well implemented:
- Separate animation states for each indicator
- Clear trigger conditions based on status changes
92-93
: LGTM! Good use of React.memoThe memoization is appropriate here as it can prevent unnecessary re-renders of the icons and animations when parent components update.
packages/extension-polkagate/src/fullscreen/accountDetails/components/AccountIconsFs.tsx (1)
Line range hint
41-51
: Effect implementation needs improvement.The effect still needs cleanup handling and proper dependency management as noted in the previous review.
Summary by CodeRabbit
AccountIcons
andAccountIconsFs
components.AccountPreview
component by removing unused hooks and state.