Skip to content

[TASK-7550] fix(kyc): store kyc status in db#569

Merged
jjramirezn merged 1 commit intodevelopfrom
fix/get-kyc-statu
Dec 14, 2024
Merged

[TASK-7550] fix(kyc): store kyc status in db#569
jjramirezn merged 1 commit intodevelopfrom
fix/get-kyc-statu

Conversation

@jjramirezn
Copy link
Contributor

@jjramirezn jjramirezn commented Dec 13, 2024

Correctly update kyc status

Summary by CodeRabbit

  • New Features

    • Enhanced documentation for the Next.js application structure, including detailed sections on routing, assets, configuration, contexts, hooks, and middleware.
    • Updated response structure for user status checks, now including KYC status alongside customer ID.
  • Bug Fixes

    • Adjusted KYC status checks from 'verified' to 'approved' across multiple components to improve user verification processes.
  • Documentation

    • Expanded and clarified project documentation for better understanding of components and functionality.
  • Chores

    • Renamed functions and updated method signatures to improve clarity and consistency in the codebase.

@notion-workspace
Copy link

@vercel
Copy link

vercel bot commented Dec 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
peanut-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 13, 2024 7:57pm

@jjramirezn jjramirezn requested a review from Hugo0 December 13, 2024 19:57
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Walkthrough

The pull request introduces significant enhancements to the documentation of a Next.js application, particularly in docs/high_level_overview.md, by clarifying the application structure and functionality. Key changes include renaming a function in the Auth Context for better clarity and expanding documentation on various components like App Router, Assets, and Hooks. Additionally, modifications to several API routes and components reflect updates in handling user KYC status, error messages, and request structures, ensuring a more coherent user experience and improved code maintainability.

Changes

File Path Change Summary
docs/high_level_overview.md Enhanced documentation of application structure; renamed updateBridgeCustomerId to updateBridgeCustomerData.
src/app/api/bridge/user/new/get-status/route.ts Updated response structure to include kyc_status; maintained existing error handling.
src/app/api/peanut/user/update-user/route.ts Added kycStatus parameter to request body; retains existing error handling and response structure.
src/components/Cashout/Components/Initial.view.tsx Changed KYC status check from 'verified' to 'approved'; refined error messages for bank account validation.
src/components/Claim/Link/Initial.view.tsx Updated KYC status check from 'verified' to 'approved'; enhanced error handling logic in claim functions.
src/components/Global/KYCComponent/index.tsx Renamed function updateBridgeCustomerId to updateBridgeCustomerData; removed kycStatus state variable.
src/components/Global/LinkAccountComponent/index.tsx Updated KYC status check from 'verified' to 'approved'; modified rendering logic based on KYC status.
src/components/Kyc/index.tsx Changed KYC status check from 'verified' to 'approved'; preserved component structure and error handling.
src/components/LinkAccount/index.tsx Updated KYC status check from 'verified' to 'approved'; maintained error handling during logout.
src/components/Profile/index.tsx Altered KYC status display logic from 'verified' to 'approved'; preserved overall component functionality.
src/context/authContext.tsx Renamed updateBridgeCustomerId to updateBridgeCustomerData; updated parameter type to GetUserLinksResponse.
src/utils/cashout.utils.ts Introduced GetUserLinksResponse type; updated getUserLinks function signature for type safety and error handling.

Possibly related PRs

Suggested reviewers

  • panosfilianos

🐰 In the garden of code, we hop and play,
With KYC and routes, we brighten the day.
From 'verified' to 'approved', we make it clear,
Documentation blooms, bringing developers near.
So let’s celebrate changes, both big and small,
In the world of Next.js, we’re having a ball! 🎉


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dff936b and 8716d7b.

📒 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.tsx
    • src/components/Global/KYCComponent/index.tsx
    • docs/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()
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

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)
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

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 })
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 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.id is validated before updating customerObject.
  • Add error handling for scenarios where customer.id is 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

Copy link
Contributor

@Hugo0 Hugo0 left a comment

Choose a reason for hiding this comment

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

lgtm

})
} 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 }), {
Copy link
Contributor

Choose a reason for hiding this comment

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

better :)

password: '',
})
if (user?.user.kycStatus == 'verified') {
if (user?.user.kycStatus === 'approved') {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@jjramirezn jjramirezn merged commit a1709ea into develop Dec 14, 2024
3 checks passed
@jjramirezn jjramirezn deleted the fix/get-kyc-statu branch December 14, 2024 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants