[TASK-7550] fix(kyc): store kyc status in db#569
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe pull request introduces significant enhancements to the documentation of a Next.js application, particularly in 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.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (12)
docs/high_level_overview.md(1 hunks)src/app/api/bridge/user/new/get-status/route.ts(1 hunks)src/app/api/peanut/user/update-user/route.ts(2 hunks)src/components/Cashout/Components/Initial.view.tsx(1 hunks)src/components/Claim/Link/Initial.view.tsx(1 hunks)src/components/Global/KYCComponent/index.tsx(5 hunks)src/components/Global/LinkAccountComponent/index.tsx(3 hunks)src/components/Kyc/index.tsx(1 hunks)src/components/LinkAccount/index.tsx(1 hunks)src/components/Profile/index.tsx(1 hunks)src/context/authContext.tsx(4 hunks)src/utils/cashout.utils.ts(1 hunks)
🧰 Additional context used
📓 Learnings (1)
src/components/Cashout/Components/Initial.view.tsx (1)
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#484
File: src/components/Cashout/Components/Initial.view.tsx:273-274
Timestamp: 2024-11-12T09:39:20.720Z
Learning: In the `InitialCashoutView` component (`src/components/Cashout/Components/Initial.view.tsx`), linked bank accounts should not generate error states, and the `ValidatedInput` component will clear any error messages if needed. Therefore, it's unnecessary to manually clear the error state when selecting or clearing linked bank accounts.
🔇 Additional comments (12)
src/app/api/peanut/user/update-user/route.ts (1)
27-27: Proper inclusion of kycStatus in the API request body.
The inclusion of kycStatus in the JSON body of the fetch request is correctly implemented. This ensures that the backend API can receive and process the new kycStatus parameter as intended.
src/app/api/bridge/user/new/get-status/route.ts (1)
61-61: Updated response structure is appropriate and functional.
The updated response structure, which includes both id and kyc_status, is correctly implemented. This change enhances the API's functionality by providing more comprehensive data, aligning with the updated requirements for KYC status handling.
src/components/LinkAccount/index.tsx (1)
41-41: Updated KYC status check is correctly implemented.
The change in the conditional rendering logic to check if kycStatus is not 'approved' is correctly implemented. This ensures that users are appropriately prompted to complete their KYC process, aligning with the updated KYC verification requirements across the application.
src/components/Kyc/index.tsx (1)
42-42: Approve the KYC status check update.
The update from 'verified' to 'approved' in the KYC status check is correctly implemented. Ensure that this change is consistently applied across all components that utilize the KYC status for conditional rendering to maintain functional integrity throughout the application.
Run the following script to verify the consistency of KYC status checks across the application:
✅ Verification successful
KYC status checks are consistent across the application.
The change from 'verified' to 'approved' is correctly implemented in all relevant components. No remaining instances of 'verified' KYC status checks were found, ensuring functional integrity throughout the application.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify all KYC status checks in the application.
# Test: Search for KYC status checks. Expect: Only occurrences of 'approved'.
rg "kycStatus === 'approved'" --files-with-matches
Length of output: 313
Script:
#!/bin/bash
# Description: Check for any remaining 'verified' KYC status checks.
# Test: Search for KYC status checks. Expect: No occurrences of 'verified'.
rg "kycStatus === 'verified'" --files-with-matches
Length of output: 58
docs/high_level_overview.md (1)
89-89: Approve the documentation enhancements.
The renaming of updateBridgeCustomerId to updateBridgeCustomerData and the expanded sections on the App Router, Assets, and other components significantly enhance the clarity and comprehensiveness of the documentation. These changes are crucial for maintaining an accurate and helpful developer guide.
src/context/authContext.tsx (1)
Line range hint 129-141: Approve the method signature change and implementation.
The update from updateBridgeCustomerId to updateBridgeCustomerData with the new parameter type GetUserLinksResponse is correctly implemented. This change enhances type safety and aligns with the new requirements for handling user data. Ensure that this method is correctly integrated and used consistently across the application.
Run the following script to verify the integration of the updateBridgeCustomerData method across the application:
✅ Verification successful
✅ updateBridgeCustomerData is correctly integrated and consistently used across the application. No issues found.
- Files Verified:
src/context/authContext.tsxsrc/components/Global/KYCComponent/index.tsxdocs/high_level_overview.md
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the usage of `updateBridgeCustomerData` in the application.
# Test: Search for the method usage. Expect: Correct integration and consistent usage.
rg "updateBridgeCustomerData" --files-with-matches
Length of output: 151
Script:
#!/bin/bash
# Description: Extract the usage details of `updateBridgeCustomerData` in the identified files.
rg "updateBridgeCustomerData" src/context/authContext.tsx src/components/Global/KYCComponent/index.tsx docs/high_level_overview.md -C 2
Length of output: 3598
Script:
#!/bin/bash
# Description: Extract the usage details of `updateBridgeCustomerData` to verify correct parameter types.
rg "updateBridgeCustomerData" src/components/Global/KYCComponent/index.tsx -C 3
Length of output: 1624
src/components/Global/KYCComponent/index.tsx (1)
50-50: Function Renaming: Verify across the codebase
The renaming of updateBridgeCustomerId to updateBridgeCustomerData is a significant change. Ensure that all references to this function across the entire codebase have been updated to reflect this change.
src/components/Cashout/Components/Initial.view.tsx (1)
166-166: KYC Status Check: Ensure consistency across components
The update from verified to approved for KYC status checks is crucial. Verify that this change is consistently applied across all components that handle KYC status to prevent any discrepancies.
✅ Verification successful
KYC Status Check: Consistent Usage Confirmed
The KYC status checks across all components are consistently using 'approved'. No discrepancies found.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the consistency of KYC status checks across components.
# Test: Search for KYC status checks in the codebase. Expect: Only 'approved' should be used.
rg -A 5 $'kycStatus'
Length of output: 13331
src/utils/cashout.utils.ts (1)
132-132: Type Safety: Validate new type definition usage
The introduction of GetUserLinksResponse type is a significant improvement for type safety. Ensure that this type is correctly used in all relevant functions to prevent type mismatches and enhance code reliability.
✅ Verification successful
Continue Verification: Further Validate GetUserLinksResponse Usage
Continue Verification: Ensure Consistent Usage of GetUserLinksResponse Across All Functions
Verified: GetUserLinksResponse is Consistently Used Across the Codebase
- No inconsistencies or type mismatches found in the usage of
GetUserLinksResponse.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the usage of `GetUserLinksResponse` type across the codebase.
# Test: Search for the type usage in the codebase. Expect: Consistent use of `GetUserLinksResponse`.
rg -A 5 $'GetUserLinksResponse'
Length of output: 1913
Script:
#!/bin/bash
# Description: Check for consistent and correct usage of `GetUserLinksResponse` type in function signatures.
# Search for all function declarations or exports that use `GetUserLinksResponse` and verify their return types.
rg --type ts 'function\s+\w+\s*\([^)]*\):\s*Promise<GetUserLinksResponse>' | rg -v 'any|unknown|Object'
Length of output: 231
Script:
#!/bin/bash
# Description: Verify that `GetUserLinksResponse` is used consistently in all relevant function signatures and type annotations.
# Search for all occurrences of `GetUserLinksResponse` in type annotations and verify their contexts.
ast-grep --pattern '
type_definition {
name: "GetUserLinksResponse",
...
}
'
rg --type ts 'GetUserLinksResponse' -A 5
Length of output: 2014
src/components/Profile/index.tsx (1)
399-401: KYC Status Update Implemented Correctly
The update from 'verified' to 'approved' for the KYC status check is implemented correctly. This change is consistent with the PR's objective and is localized without introducing side effects. The use of conditional rendering based on the KYC status is appropriate and well-implemented.
src/components/Global/LinkAccountComponent/index.tsx (1)
172-172: KYC Status Update Implemented Correctly
The update from 'verified' to 'approved' for the KYC status check is implemented correctly. This change is consistent with the PR's objective and is localized without introducing side effects. The use of conditional checks and form submissions based on the KYC status is appropriate and well-implemented.
Also applies to: 427-427
src/components/Claim/Link/Initial.view.tsx (1)
235-235: KYC Status Update Implemented Correctly
The update from 'verified' to 'approved' for the KYC status check is implemented correctly. This change is consistent with the PR's objective and is localized without introducing side effects. The use of conditional rendering and form submissions based on the KYC status is appropriate and well-implemented.
|
|
||
| export async function POST(request: NextRequest) { | ||
| const { userId, username, bridge_customer_id } = await request.json() | ||
| const { userId, username, bridge_customer_id, kycStatus } = await request.json() |
There was a problem hiding this comment.
Add validation for kycStatus.
The addition of kycStatus to the destructured parameters is crucial for the functionality of this endpoint. However, it's important to ensure that kycStatus is also validated similarly to userId, apiKey, and token. This will prevent potential issues from missing or incorrect kycStatus values in the request.
Consider adding a check like:
if not kycStatus:
return new NextResponse('Bad Request: missing kycStatus', { status: 400 })| } else { | ||
| let data = await utils.getUserLinks(inputFormData) | ||
| await updateBridgeCustomerId(data.id) | ||
| await updateBridgeCustomerData(data) |
There was a problem hiding this comment.
Critical: Ensure proper error handling in async function calls
Multiple instances of updateBridgeCustomerData are used without proper error handling. Consider wrapping these calls in try-catch blocks to handle potential exceptions and maintain robust error handling throughout the KYC process.
- await updateBridgeCustomerData(data)
+ try {
+ await updateBridgeCustomerData(data)
+ } catch (error) {
+ console.error('Failed to update bridge customer data:', error);
+ setErrorState({ showError: true, errorMessage: 'Failed to update data. Please try again.' });
+ }
- await updateBridgeCustomerData(_customerObject)
+ try {
+ await updateBridgeCustomerData(_customerObject)
+ } catch (error) {
+ console.error('Failed to update bridge customer data:', error);
+ setErrorState({ showError: true, errorMessage: 'Failed to update data. Please try again.' });
+ }
- await updateBridgeCustomerData(_customerObject)
+ try {
+ await updateBridgeCustomerData(_customerObject)
+ } catch (error) {
+ console.error('Failed to update bridge customer data:', error);
+ setErrorState({ showError: true, errorMessage: 'Failed to update data. Please try again.' });
+ }
- await updateBridgeCustomerData(customer)
+ try {
+ await updateBridgeCustomerData(customer)
+ } catch (error) {
+ console.error('Failed to update bridge customer data:', error);
+ setErrorState({ showError: true, errorMessage: 'Failed to update data. Please try again.' });
+ }Also applies to: 132-132, 187-187, 265-265
| // Get customer ID | ||
| const customer = await utils.getStatus(_customerObject.id, 'customer_id') | ||
| setCustomerObject({ ..._customerObject, customer_id: customer.customer_id }) | ||
| setCustomerObject({ ..._customerObject, customer_id: customer.id }) |
There was a problem hiding this comment.
💡 Codebase verification
Data Integrity Issue: Customer ID update lacks validation
The current implementation of updating customer_id does not appear to handle cases where customer.id is missing or invalid. This could compromise data integrity in the KYC process.
- Ensure that
customer.idis validated before updatingcustomerObject. - Add error handling for scenarios where
customer.idis absent or incorrect.
🔗 Analysis chain
Data Integrity: Verify customer ID update logic
The logic for updating the customer ID (customer_id) should be verified to ensure it correctly handles scenarios where the ID might not be present or is incorrect. This is crucial for maintaining data integrity in the KYC process.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the logic for updating customer ID in the KYC process.
# Test: Search for the function usage and check for proper handling of missing or incorrect IDs.
rg -A 5 $'setCustomerObject'
Length of output: 2648
Script:
#!/bin/bash
# Description: Verify how customer.id is obtained and validated before updating customerObject.
# Search for the origin of 'customer' and check for validation of 'customer.id'
rg 'customer\.' --context 5
Length of output: 1758
| }) | ||
| } else if (type === 'customer_id') { | ||
| return new NextResponse(JSON.stringify({ customer_id: data.customer_id }), { | ||
| return new NextResponse(JSON.stringify({ id: data.customer_id, kyc_status: data.kyc_status }), { |
| password: '', | ||
| }) | ||
| if (user?.user.kycStatus == 'verified') { | ||
| if (user?.user.kycStatus === 'approved') { |
Correctly update kyc status
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores