Closed sebpalluel closed 7 months ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
back-office | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Apr 9, 2024 11:10am |
marketplace | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Apr 9, 2024 11:10am |
unlock | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Apr 9, 2024 11:10am |
PR Description updated to latest commit (https://github.com/OfflineHQ/marketplace/commit/8d0a4d254b4b9cdb5f7f8e1c889ac0885acd90b9)
⏱️ Estimated effort to review [1-5] | 4, due to the extensive changes across multiple files, including new components, refactoring, and localization support. The PR introduces significant enhancements and new features, requiring a thorough review of code quality, functionality, and integration with existing systems. |
🧪 Relevant tests | No |
🔍 Possible issues | Possible Bug: The use of `useEffect` hooks in `OffKeyProfile.tsx` without a dependency array might lead to unexpected behavior or infinite loops. Consider adding a dependency array to control the effect's execution. |
Code Duplication: Similar code patterns are observed in `OffKeyAuth.tsx` and `OffKeyProfile.tsx` for handling wallet connections. Consider abstracting common logic into reusable hooks or components to reduce duplication and improve maintainability. | |
Localization Consistency: Ensure that all user-facing text is included in the localization files and properly utilized in the components. This includes error messages and dynamic content that might not be currently covered. | |
Performance Concern: The extensive use of animations and dynamic content in components like `OffKeyGate.tsx` and `OffKeyHeaderConnected.tsx` might impact performance on lower-end devices. Consider optimizing animations and conditional rendering to improve the user experience across all devices. | |
🔒 Security concerns | No |
Category | Suggestions |
Best practice |
Use a more specific error type instead of
___
**Consider using a more specific error type in the |
Avoid using console.log in production code for better code quality.___ **It's a good practice to avoid direct console logging in production code, especially insuccess or error handlers of mutations. Consider using a more robust logging mechanism or remove the console logs if they were used for debugging purposes.** [libs/features/unlock/shopify/src/lib/OffKeyProfile/OffKeyProfile.tsx [54-69]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-4b035f23e367c8645366640c5b6355e6bdd60a52f6a10b88ef9f4f93db8a16ebR54-R69) ```diff -console.log('connected to wallet'); -console.log('error connecting to dapp', error); +// Use a logging library or remove the console.log statements ``` | |
Use a ternary operator for conditional rendering to improve readability.___ **To improve code readability and maintainability, consider using a ternary operator forconditional rendering based on walletInStorage.length > 1 . This change would make the component's structure clearer and more concise.** [libs/features/unlock/shopify/src/lib/OffKeyAuth/OffKeyAuthSignIn.tsx [34-70]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-a7a38c4ba86bbda1719d0fc1a196c2a6324076a0f3036bf2acb6e8612e42f923R34-R70) ```diff -return walletInStorage && walletInStorage.length > 1 ? ( -
- ...
-
-) : (
- | |
Use
___
**Replace the | |
Remove unused function parameters.___ **Consider removing the unusedcontainer parameter from the play function in your Storybook stories to adhere to best practices and improve code readability.** [libs/features/unlock/shopify/src/lib/OffKeyGate/OffKeyGate.stories.tsx [35-36]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-54f8a03cadd7b355809e667b7bfe2e620e4d830e84c59d40c8d9c6bb628c743cR35-R36) ```diff -play: async ({ container }) => { +play: async () => { await screen.findAllByText(/Unlocked/i); }, ``` | |
Use decorators or parameters for mocking in Storybook.___ **Instead of directly mocking the hooks usingcreateMock , consider using a more integrated testing approach with Storybook by utilizing decorators or parameters to provide mock data. This approach can improve maintainability and separation of concerns.** [libs/features/unlock/shopify/src/lib/OffKeyAuth/examples.tsx [36-38]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-073ecf024148eed78fbb8ff30bf2f628c971668ccac1c92296a29dbf19bb38e3R36-R38) ```diff -const mockWallet = createMock(walletApi, 'useWalletAuth'); -mockWallet.mockReturnValue(walletAuthMocks); +// Example using decorators for Storybook +export const decorators = [ + (Story) => ( + | |
Maintainability |
Extract mutation functions into separate named functions for better maintainability.___ **To improve code maintainability and readability, consider extracting the mutationfunctions ( mutationFn , onSuccess , onError ) into separate named functions outside of the component. This not only makes the component cleaner but also makes it easier to test these functions in isolation.** [libs/features/unlock/shopify/src/lib/OffKeyProfile/OffKeyProfile.tsx [51-60]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-4b035f23e367c8645366640c5b6355e6bdd60a52f6a10b88ef9f4f93db8a16ebR51-R60) ```diff +const handleConnectWallet = (newWallet: string) => connect(newWallet); +const onConnectWalletSuccess = () => { + console.log('connected to wallet'); + // Handle successful connection +}; +const onConnectWalletError = (error: Error) => { + // Handle connection error +}; const connectWalletMutation = useMutation({ - mutationFn: (newWallet: string) => connect(newWallet), - onSuccess: () => { - console.log('connected to wallet'); - // Handle successful connection - }, - onError: (error: any) => { - // Handle connection error - }, + mutationFn: handleConnectWallet, + onSuccess: onConnectWalletSuccess, + onError: onConnectWalletError, }); ``` |
Use ternary operator or separate function for conditional rendering for clarity.___ **For better code readability and maintainability, consider using a ternary operator or aseparate rendering function for conditional rendering instead of using the logical AND ( && ) operator. This can make the code easier to understand, especially for more complex conditional renderings.** [libs/features/unlock/shopify/src/lib/OffKeyAuth/OffKeyAuth.tsx [51-69]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-dd427743a002e3dad8c75f54ed95a9092983490a56a5fc378a0e3ec2a5d6bdf6R51-R69) ```diff -{existingWallet ? ( - | |
Improve variable naming for clarity.___ **Consider using a more descriptive variable name fort to improve code readability. For example, translate or tFunction would make it clearer that this variable is used for internationalization.** [libs/features/unlock/shopify/src/lib/OffKeyInfo/OffKeyInfo.tsx [40]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-afda0c3e7456144fe461301c4114afbbcca1583d473b3be76f8fc49bf2fd9ecbR40-R40) ```diff -const t = useTranslations('Shopify.OffKeyInfo'); +const translate = useTranslations('Shopify.OffKeyInfo'); ``` | |
Consolidate state mappings into a single mapping for simplicity.___ **Instead of hardcoding the translations keys and creating separate state mappings forsubtitles and main text, consider creating a single mapping that includes all the necessary information for each state. This approach reduces redundancy and simplifies the component's structure.** [libs/features/unlock/shopify/src/lib/OffKeyGate/OffKeyGate.tsx [29-39]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-b04caa7332ebff9c207f545552e87b6297915d203992f9e5bfe4f6569ecd2ed8R29-R39) ```diff -const stateToSubtitle = { - [OffKeyState.Unlocked]: t('unlocked-subtitle'), - ... -}; -const stateToMainText = { - [OffKeyState.Unlocked]: t('unlocked-text'), +const stateToContent = { + [OffKeyState.Unlocked]: { subtitle: t('unlocked-subtitle'), mainText: t('unlocked-text') }, ... }; ``` | |
Define mock functions externally for better modularity.___ **To improve the reusability and readability of your mock functions, consider defining themoutside of the authMocks function or in a separate utility file. This change can make your tests more modular and easier to maintain.** [libs/features/unlock/shopify/src/lib/OffKeyProfile/examples.tsx [29-31]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-a989bfef297ab964b9c8680402fa4386ede798d35806e0886f124aefe5ca466fR29-R31) ```diff -const mockWallet = createMock(walletApi, 'useWalletAuth'); -mockWallet.mockReturnValue(walletAuthMocks); +// In a separate utility file or outside the function +export const mockWalletAuth = createMock(walletApi, 'useWalletAuth'); +mockWalletAuth.mockReturnValue(walletAuthMocks); ``` | |
Implement or remove TODO comments to avoid technical debt.___ **Implement the actual logic forgetGateStateForAddress or remove the TODO comment if the function is not meant to be expanded. Leaving TODO comments in production code can lead to confusion and technical debt.** [libs/features/unlock/shopify/src/lib/actions/getGateStateForAddress.ts [13-21]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-2ae7ec5f54c9a1e6b79d3b98ed85adfdc3ea0376c7a05dab3885ec0de3c072f5R13-R21) ```diff -// TODO implement -// return __awaiter(this, void 0, void 0, function* () { -// return { -// status: 'locked', -// gateId, -// address, -// }; -// }); -return OffKeyState.Locked; +// Implemented version (example) +return fetchGateState(gateId, address); ``` | |
Enhancement |
Improve user feedback by handling the
___
**To enhance the user experience and provide feedback during the connection process, |
Pass state mappings as props for flexibility and maintainability.___ **To ensure that the component is more flexible and easier to maintain, consider passingstateToBorderColor , stateToKeyIcon , stateToStatusBackground , and other similar mappings as props. This change would make the component more reusable and easier to test.** [libs/features/unlock/shopify/src/lib/OffKeyInfo/OffKeyInfo.tsx [14-31]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-afda0c3e7456144fe461301c4114afbbcca1583d473b3be76f8fc49bf2fd9ecbR14-R31) ```diff -const stateToBorderColor = { - [OffKeyState.Unlocked]: 'border-success-border', - ... -}; +export function OffKeyInfo({ state, offKeyName, className, stateMappings }: OffKeyInfoProps & { stateMappings: StateMappings }) { ``` | |
Add a description to the
___
**Consider adding a description to the | |
Possible issue |
Ensure props are utilized or remove unnecessary props.___ **Theheader prop is being passed to OffKeyLayout but not utilized within it. Ensure that the header prop is correctly implemented inside OffKeyLayout or reconsider its necessity if it's not being used.** [apps/unlock/app/[locale]/shopify/[gateId]/(notConnected)/layout.tsx [24-26]](https://github.com/OfflineHQ/marketplace/pull/294/files#diff-300c9bf8ed78b5df256207749beeb349d0c908ad0c736d2ffa6a5f20e3c9090dR24-R26) ```diff - |
Type
enhancement, documentation
Description
OffKeyAuth
,OffKeyGate
,OffKeyHeader
, etc.) for better structure and functionality.OffKeyLayout
for consistent layout management across Shopify feature pages.OffKeyProfile
component for managing user profiles in connected state.OffKeyGate
component for managing gate states (unlocked, unlocking, used, locked).Changes walkthrough
12 files
page.tsx
Refactor Auth Page to Use OffKeyAuth Component
apps/unlock/app/[locale]/shopify/[gateId]/(notConnected)/@auth/page.tsx
OffKeyAuth
component with localization support.NextIntlClientProvider
for localized messages.page.tsx
Implement OffKeyHeader in Header Page
apps/unlock/app/[locale]/shopify/[gateId]/(notConnected)/@header/page.tsx - Implemented `OffKeyHeader` component for the header section.
layout.tsx
Use OffKeyLayout for Layout Management
apps/unlock/app/[locale]/shopify/[gateId]/(notConnected)/layout.tsx
ShopifyCard
withOffKeyLayout
for layout management.page.tsx
Integrate OffKeyGateSignIn Component
apps/unlock/app/[locale]/shopify/[gateId]/(notConnected)/page.tsx - Introduced `OffKeyGateSignIn` component for sign-in functionality.
page.tsx
Implement Connected User Header with OffKeyProfile
apps/unlock/app/[locale]/shopify/[gateId]/[address]/@header/page.tsx
OffKeyHeaderConnected
andOffKeyProfile
for connected userheader.
layout.tsx
Use OffKeyLayout in Address-Specific Layout
apps/unlock/app/[locale]/shopify/[gateId]/[address]/layout.tsx
OffKeyLayout
for layout management in address-specificpages.
page.tsx
Implement OffKeyGate Component for Gate State Management
apps/unlock/app/[locale]/shopify/[gateId]/[address]/page.tsx - Implemented `OffKeyGate` component to manage gate state.
index.ts
Export New Components for Shopify Feature
libs/features/unlock/shopify/src/index.ts
OffKeyAuth
,OffKeyGate
,OffKeyGateSignIn
,etc.) from the library.
OffKeyAuth.tsx
Add OffKeyAuth Component for Wallet Authentication
libs/features/unlock/shopify/src/lib/OffKeyAuth/OffKeyAuth.tsx - Added `OffKeyAuth` component for wallet authentication flow.
OffKeyGate.tsx
Introduce OffKeyGate Component
libs/features/unlock/shopify/src/lib/OffKeyGate/OffKeyGate.tsx - Introduced `OffKeyGate` component for gate state management.
OffKeyHeader.tsx
Implement OffKeyHeader Component
libs/features/unlock/shopify/src/lib/OffKeyHeader/OffKeyHeader.tsx - Implemented `OffKeyHeader` component for the header section.
OffKeyProfile.tsx
Add OffKeyProfile Component for User Profile Management
libs/features/unlock/shopify/src/lib/OffKeyProfile/OffKeyProfile.tsx - Added `OffKeyProfile` component for user profile management.
1 files
en.json
Add Translations for New Shopify Feature Components
libs/next/i18n/src/messages/en.json
OffKeyAuth
,OffKeyGate
,OffKeyProfile
, etc.).