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

[OTE-420]: Deprecate ONBOARD from Indexer #1728

Merged
merged 3 commits into from
Jun 19, 2024
Merged

Conversation

Christopher-Li
Copy link
Contributor

@Christopher-Li Christopher-Li commented Jun 19, 2024

Changelist

Deprecate ONBOARD from Indexer

Test Plan

Unit tests

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • New Features

    • Enhanced compliance handling based on country restrictions and wallet status.
  • Refactor

    • Updated compliance actions and status management for improved clarity and efficiency.
  • Tests

    • Revised and added new test cases for compliance actions and status updates.

Copy link

linear bot commented Jun 19, 2024

Copy link
Contributor

coderabbitai bot commented Jun 19, 2024

Walkthrough

Recent updates to the ComplianceV2Controller revolve around replacing the ONBOARD action with CONNECT and enhancing compliance status logic. This includes introducing a new function, upsertComplianceStatus, which better handles compliance status updates based on conditions like country restrictions and wallet presence, along with new test cases tailored to these updates.

Changes

Files Change Summary
.../api/v4/compliance-v2-controller.test.ts Updated test cases replacing ONBOARD with CONNECT, added compliance checks, and refined test case descriptions.
.../api/v4/compliance-v2-controller.ts Added imports, created upsertComplianceStatus function, adjusted function signatures, and enhanced compliance logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ComplianceController
    participant WalletTable
    participant ComplianceStatusDB

    User ->> ComplianceController: Initiates CONNECT action
    ComplianceController ->> WalletTable: Check wallet existence
    WalletTable -->> ComplianceController: Responds with wallet info
    ComplianceController ->> ComplianceStatusDB: upsertComplianceStatus
    ComplianceStatusDB -->> ComplianceController: Compliance status updated
    ComplianceController -->> User: Responds with updated status
Loading

Poem

In the land where code doth bloom,
Compliance shifts to make more room.
From ONBOARD to CONNECT, we steer,
To ensure compliance, crystal clear.
With logic keen and tests anew,
Our system grows, resilient and true.
🌸✨

Warning

Review ran into problems

Problems (1)
  • Git: Failed to clone repository. Please contact CodeRabbit support.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

Outside diff range and nitpick comments (1)
indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts (1)

Line range hint 64-64: Decorators are incorrectly placed here. Decorators should only be used on class declarations, class expressions, and class methods. Please adjust the placement or configuration accordingly.

- @Get('/screen/:address')
+ // Decorator needs to be moved or configured correctly.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e09241b and ca65150.

Files selected for processing (2)
  • indexer/services/comlink/tests/controllers/api/v4/compliance-v2-controller.test.ts (4 hunks)
  • indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts (4 hunks)
Additional context used
Biome
indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts

[error] 64-64: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 78-82: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 83-117: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 112-116: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 383-389: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.

Additional comments not posted (5)
indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts (2)

12-13: The imports for WalletFromDatabase and WalletTable are correctly added to handle wallet-related operations in compliance checks.


17-17: Import of lodash (_) is added to facilitate object and array manipulations which are common in the compliance logic.
[APROVED]

indexer/services/comlink/__tests__/controllers/api/v4/compliance-v2-controller.test.ts (3)

253-253: The test correctly modifies the action to ComplianceAction.CONNECT as part of the deprecation of the ONBOARD action. This aligns with changes in the main controller.


347-347: The addition of await dbHelpers.clearData() is a good practice to ensure a clean state before executing tests, particularly useful in compliance-related tests where state must be controlled.


369-369: This test case effectively checks the behavior when a CONNECT action is received from a restricted country with no existing compliance status and a wallet. It ensures that the system correctly sets the status to FIRST_STRIKE_CLOSE_ONLY.

Comment on lines 300 to 393
/**
* If the address doesn't exist in the compliance table:
* - if the request is from a restricted country:
* - if the action is CONNECT and no wallet, set the status to BLOCKED
* - if the action is CONNECT and wallet exists, set the status to FIRST_STRIKE_CLOSE_ONLY
* - else if the request is from a non-restricted country:
* - set the status to COMPLIANT
*
* if the address is COMPLIANT:
* - the ONLY action should be CONNECT. VALID_SURVEY/INVALID_SURVEY are no-ops.
* - if the request is from a restricted country:
* - set the status to FIRST_STRIKE_CLOSE_ONLY
*
* if the address is FIRST_STRIKE_CLOSE_ONLY:
* - the ONLY actions should be VALID_SURVEY/INVALID_SURVEY/CONNECT. CONNECT
* are no-ops.
* - if the action is VALID_SURVEY:
* - set the status to FIRST_STRIKE
* - if the action is INVALID_SURVEY:
* - set the status to CLOSE_ONLY
*
* if the address is FIRST_STRIKE:
* - the ONLY action should be CONNECT. VALID_SURVEY/INVALID_SURVEY are no-ops.
* - if the request is from a restricted country:
* - set the status to CLOSE_ONLY
*/
async function upsertComplicanceStatus(
req: express.Request,
action: ComplianceAction,
address: string,
wallet: WalletFromDatabase | undefined,
complianceStatus: ComplianceStatusFromDatabase[],
updatedAt: string,
): Promise<ComplianceStatusFromDatabase | undefined> {
if (complianceStatus.length === 0) {
if (!isRestrictedCountryHeaders(req.headers as CountryHeaders)) {
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.COMPLIANT,
updatedAt,
});
}

// If address is restricted and is not onboarded then block
if (_.isUndefined(wallet)) {
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.BLOCKED,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}

return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}

if (
complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE ||
complianceStatus[0].status === ComplianceStatus.COMPLIANT
) {
if (
isRestrictedCountryHeaders(req.headers as CountryHeaders) &&
action === ComplianceAction.CONNECT
) {
return ComplianceStatusTable.update({
address,
status: COMPLIANCE_PROGRESSION[complianceStatus[0].status],
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
} else if (complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY) {
if (action === ComplianceAction.VALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.FIRST_STRIKE,
updatedAt,
});
} else if (action === ComplianceAction.INVALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.CLOSE_ONLY,
updatedAt,
});
}
}

return complianceStatus[0];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The function upsertComplianceStatus is well-structured to handle various compliance scenarios based on the country and wallet existence. However, the function name contains a typo. It should be upsertComplianceStatus.

- async function upsertComplicanceStatus(
+ async function upsertComplianceStatus(
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 the address doesn't exist in the compliance table:
* - if the request is from a restricted country:
* - if the action is CONNECT and no wallet, set the status to BLOCKED
* - if the action is CONNECT and wallet exists, set the status to FIRST_STRIKE_CLOSE_ONLY
* - else if the request is from a non-restricted country:
* - set the status to COMPLIANT
*
* if the address is COMPLIANT:
* - the ONLY action should be CONNECT. VALID_SURVEY/INVALID_SURVEY are no-ops.
* - if the request is from a restricted country:
* - set the status to FIRST_STRIKE_CLOSE_ONLY
*
* if the address is FIRST_STRIKE_CLOSE_ONLY:
* - the ONLY actions should be VALID_SURVEY/INVALID_SURVEY/CONNECT. CONNECT
* are no-ops.
* - if the action is VALID_SURVEY:
* - set the status to FIRST_STRIKE
* - if the action is INVALID_SURVEY:
* - set the status to CLOSE_ONLY
*
* if the address is FIRST_STRIKE:
* - the ONLY action should be CONNECT. VALID_SURVEY/INVALID_SURVEY are no-ops.
* - if the request is from a restricted country:
* - set the status to CLOSE_ONLY
*/
async function upsertComplicanceStatus(
req: express.Request,
action: ComplianceAction,
address: string,
wallet: WalletFromDatabase | undefined,
complianceStatus: ComplianceStatusFromDatabase[],
updatedAt: string,
): Promise<ComplianceStatusFromDatabase | undefined> {
if (complianceStatus.length === 0) {
if (!isRestrictedCountryHeaders(req.headers as CountryHeaders)) {
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.COMPLIANT,
updatedAt,
});
}
// If address is restricted and is not onboarded then block
if (_.isUndefined(wallet)) {
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.BLOCKED,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
if (
complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE ||
complianceStatus[0].status === ComplianceStatus.COMPLIANT
) {
if (
isRestrictedCountryHeaders(req.headers as CountryHeaders) &&
action === ComplianceAction.CONNECT
) {
return ComplianceStatusTable.update({
address,
status: COMPLIANCE_PROGRESSION[complianceStatus[0].status],
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
} else if (complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY) {
if (action === ComplianceAction.VALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.FIRST_STRIKE,
updatedAt,
});
} else if (action === ComplianceAction.INVALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.CLOSE_ONLY,
updatedAt,
});
}
}
return complianceStatus[0];
}
async function upsertComplianceStatus(
req: express.Request,
action: ComplianceAction,
address: string,
wallet: WalletFromDatabase | undefined,
complianceStatus: ComplianceStatusFromDatabase[],
updatedAt: string,
): Promise<ComplianceStatusFromDatabase | undefined> {
if (complianceStatus.length === 0) {
if (!isRestrictedCountryHeaders(req.headers as CountryHeaders)) {
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.COMPLIANT,
updatedAt,
});
}
// If address is restricted and is not onboarded then block
if (_.isUndefined(wallet)) {
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.BLOCKED,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
if (
complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE ||
complianceStatus[0].status === ComplianceStatus.COMPLIANT
) {
if (
isRestrictedCountryHeaders(req.headers as CountryHeaders) &&
action === ComplianceAction.CONNECT
) {
return ComplianceStatusTable.update({
address,
status: COMPLIANCE_PROGRESSION[complianceStatus[0].status],
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
} else if (complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY) {
if (action === ComplianceAction.VALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.FIRST_STRIKE,
updatedAt,
});
} else if (action === ComplianceAction.INVALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.CLOSE_ONLY,
updatedAt,
});
}
}
return complianceStatus[0];
}
Tools
Biome

[error] 383-389: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.

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

Commits

Files that changed from the base of the PR and between ca65150 and 1e68e8c.

Files selected for processing (1)
  • indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts (4 hunks)
Additional context used
Biome
indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts

[error] 64-64: Decorators are not valid here. (parse)

Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting the unsafeParameterDecoratorsEnabled option to true in your configuration file.


[error] 78-82: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 83-117: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 112-116: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 384-390: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.

Additional comments not posted (2)
indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts (2)

12-13: Imports for WalletFromDatabase and WalletTable added successfully.


17-17: Import of lodash using _ is correctly added.

Comment on lines 242 to 266
const [
complianceStatus,
wallet,
]: [
ComplianceStatusFromDatabase[],
WalletFromDatabase | undefined,
] = await Promise.all([
ComplianceStatusTable.findAll(
{ address: [address] },
[],
),
WalletTable.findById(address),
]);

const updatedAt: string = DateTime.utc().toISO();
if (complianceStatus.length === 0) {
if (isRestrictedCountryHeaders(req.headers as CountryHeaders)) {
if (action === ComplianceAction.ONBOARD) {
complianceStatusFromDatabase = await ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.BLOCKED,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
} else if (action === ComplianceAction.CONNECT) {
complianceStatusFromDatabase = await ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
} else {
complianceStatusFromDatabase = await ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.COMPLIANT,
updatedAt,
});
}
} else {
complianceStatusFromDatabase = complianceStatus[0];
if (
complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE ||
complianceStatus[0].status === ComplianceStatus.COMPLIANT
) {
if (
isRestrictedCountryHeaders(req.headers as CountryHeaders) &&
action === ComplianceAction.CONNECT
) {
complianceStatusFromDatabase = await ComplianceStatusTable.update({
address,
status: COMPLIANCE_PROGRESSION[complianceStatus[0].status],
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
} else if (
complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY
) {
if (action === ComplianceAction.VALID_SURVEY) {
complianceStatusFromDatabase = await ComplianceStatusTable.update({
address,
status: ComplianceStatus.FIRST_STRIKE,
updatedAt,
});
} else if (action === ComplianceAction.INVALID_SURVEY) {
complianceStatusFromDatabase = await ComplianceStatusTable.update({
address,
status: ComplianceStatus.CLOSE_ONLY,
updatedAt,
});
}
}
}
const complianceStatusFromDatabase:
ComplianceStatusFromDatabase | undefined = await upsertComplicanceStatus(
req,
action,
address,
wallet,
complianceStatus,
updatedAt,
);

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a typo in the function name upsertComplicanceStatus which should be corrected to upsertComplianceStatus.

- const complianceStatusFromDatabase: ComplianceStatusFromDatabase | undefined = await upsertComplicanceStatus(
+ const complianceStatusFromDatabase: ComplianceStatusFromDatabase | undefined = await upsertComplianceStatus(
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
const [
complianceStatus,
wallet,
]: [
ComplianceStatusFromDatabase[],
WalletFromDatabase | undefined,
] = await Promise.all([
ComplianceStatusTable.findAll(
{ address: [address] },
[],
),
WalletTable.findById(address),
]);
const updatedAt: string = DateTime.utc().toISO();
if (complianceStatus.length === 0) {
if (isRestrictedCountryHeaders(req.headers as CountryHeaders)) {
if (action === ComplianceAction.ONBOARD) {
complianceStatusFromDatabase = await ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.BLOCKED,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
} else if (action === ComplianceAction.CONNECT) {
complianceStatusFromDatabase = await ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
} else {
complianceStatusFromDatabase = await ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.COMPLIANT,
updatedAt,
});
}
} else {
complianceStatusFromDatabase = complianceStatus[0];
if (
complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE ||
complianceStatus[0].status === ComplianceStatus.COMPLIANT
) {
if (
isRestrictedCountryHeaders(req.headers as CountryHeaders) &&
action === ComplianceAction.CONNECT
) {
complianceStatusFromDatabase = await ComplianceStatusTable.update({
address,
status: COMPLIANCE_PROGRESSION[complianceStatus[0].status],
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
} else if (
complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY
) {
if (action === ComplianceAction.VALID_SURVEY) {
complianceStatusFromDatabase = await ComplianceStatusTable.update({
address,
status: ComplianceStatus.FIRST_STRIKE,
updatedAt,
});
} else if (action === ComplianceAction.INVALID_SURVEY) {
complianceStatusFromDatabase = await ComplianceStatusTable.update({
address,
status: ComplianceStatus.CLOSE_ONLY,
updatedAt,
});
}
}
}
const complianceStatusFromDatabase:
ComplianceStatusFromDatabase | undefined = await upsertComplicanceStatus(
req,
action,
address,
wallet,
complianceStatus,
updatedAt,
);
const [
complianceStatus,
wallet,
]: [
ComplianceStatusFromDatabase[],
WalletFromDatabase | undefined,
] = await Promise.all([
ComplianceStatusTable.findAll(
{ address: [address] },
[],
),
WalletTable.findById(address),
]);
const updatedAt: string = DateTime.utc().toISO();
const complianceStatusFromDatabase:
ComplianceStatusFromDatabase | undefined = await upsertComplianceStatus(
req,
action,
address,
wallet,
complianceStatus,
updatedAt,
);

Comment on lines +384 to +390
} else if (action === ComplianceAction.INVALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.CLOSE_ONLY,
updatedAt,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This else clause can be omitted as previous branches break early, simplifying the control flow.

- } else if (action === ComplianceAction.INVALID_SURVEY) {
-   return ComplianceStatusTable.update({
-     address,
-     status: ComplianceStatus.CLOSE_ONLY,
-     updatedAt,
-   });
- }
+ // Removed unnecessary else clause

Committable suggestion was skipped due to low confidence.

Tools
Biome

[error] 384-390: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.

Comment on lines 327 to 394
async function upsertComplicanceStatus(
req: express.Request,
action: ComplianceAction,
address: string,
wallet: WalletFromDatabase | undefined,
complianceStatus: ComplianceStatusFromDatabase[],
updatedAt: string,
): Promise<ComplianceStatusFromDatabase | undefined> {
if (complianceStatus.length === 0) {
if (!isRestrictedCountryHeaders(req.headers as CountryHeaders)) {
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.COMPLIANT,
updatedAt,
});
}

// If address is restricted and is not onboarded then block
if (_.isUndefined(wallet)) {
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.BLOCKED,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}

return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}

if (
complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE ||
complianceStatus[0].status === ComplianceStatus.COMPLIANT
) {
if (
isRestrictedCountryHeaders(req.headers as CountryHeaders) &&
action === ComplianceAction.CONNECT
) {
return ComplianceStatusTable.update({
address,
status: COMPLIANCE_PROGRESSION[complianceStatus[0].status],
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
} else if (complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY) {
if (action === ComplianceAction.VALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.FIRST_STRIKE,
updatedAt,
});
} else if (action === ComplianceAction.INVALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.CLOSE_ONLY,
updatedAt,
});
}
}

return complianceStatus[0];
}
Copy link
Contributor

@coderabbitai coderabbitai bot Jun 19, 2024

Choose a reason for hiding this comment

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

The function upsertComplicanceStatus should be renamed to upsertComplianceStatus to correct the typo.

- async function upsertComplicanceStatus(
+ async function upsertComplianceStatus(
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
async function upsertComplicanceStatus(
req: express.Request,
action: ComplianceAction,
address: string,
wallet: WalletFromDatabase | undefined,
complianceStatus: ComplianceStatusFromDatabase[],
updatedAt: string,
): Promise<ComplianceStatusFromDatabase | undefined> {
if (complianceStatus.length === 0) {
if (!isRestrictedCountryHeaders(req.headers as CountryHeaders)) {
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.COMPLIANT,
updatedAt,
});
}
// If address is restricted and is not onboarded then block
if (_.isUndefined(wallet)) {
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.BLOCKED,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
if (
complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE ||
complianceStatus[0].status === ComplianceStatus.COMPLIANT
) {
if (
isRestrictedCountryHeaders(req.headers as CountryHeaders) &&
action === ComplianceAction.CONNECT
) {
return ComplianceStatusTable.update({
address,
status: COMPLIANCE_PROGRESSION[complianceStatus[0].status],
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
} else if (complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY) {
if (action === ComplianceAction.VALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.FIRST_STRIKE,
updatedAt,
});
} else if (action === ComplianceAction.INVALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.CLOSE_ONLY,
updatedAt,
});
}
}
return complianceStatus[0];
}
async function upsertComplianceStatus(
req: express.Request,
action: ComplianceAction,
address: string,
wallet: WalletFromDatabase | undefined,
complianceStatus: ComplianceStatusFromDatabase[],
updatedAt: string,
): Promise<ComplianceStatusFromDatabase | undefined> {
if (complianceStatus.length === 0) {
if (!isRestrictedCountryHeaders(req.headers as CountryHeaders)) {
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.COMPLIANT,
updatedAt,
});
}
// If address is restricted and is not onboarded then block
if (_.isUndefined(wallet)) {
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.BLOCKED,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
return ComplianceStatusTable.upsert({
address,
status: ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY,
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
if (
complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE ||
complianceStatus[0].status === ComplianceStatus.COMPLIANT
) {
if (
isRestrictedCountryHeaders(req.headers as CountryHeaders) &&
action === ComplianceAction.CONNECT
) {
return ComplianceStatusTable.update({
address,
status: COMPLIANCE_PROGRESSION[complianceStatus[0].status],
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt,
});
}
} else if (complianceStatus[0].status === ComplianceStatus.FIRST_STRIKE_CLOSE_ONLY) {
if (action === ComplianceAction.VALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.FIRST_STRIKE,
updatedAt,
});
} else if (action === ComplianceAction.INVALID_SURVEY) {
return ComplianceStatusTable.update({
address,
status: ComplianceStatus.CLOSE_ONLY,
updatedAt,
});
}
}
return complianceStatus[0];
}
Tools
Biome

[error] 384-390: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

@vincentwschau, thanks for the thumbs-up! If you need any more help or have further questions, feel free to ask. Happy coding! 🐰


Learnings added
User: vincentwschau
PR: dydxprotocol/v4-chain#1728
File: indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts:327-394
Timestamp: 2024-06-19T15:01:42.992Z
Learning: User vincentwschau acknowledged the correction suggestion about renaming the function `upsertComplicanceStatus` to `upsertComplianceStatus` with a thumbs-up emoji, indicating agreement or approval.

Note: Learnings are effective only in the context of specific code segments. To apply general coding guidelines, please configure review instructions.

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1e68e8c and 19bcfa3.

Files selected for processing (1)
  • indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts

@Christopher-Li Christopher-Li merged commit 2039998 into main Jun 19, 2024
11 checks passed
@Christopher-Li Christopher-Li deleted the cl_deprecate_onboard branch June 19, 2024 15:24
@Christopher-Li
Copy link
Contributor Author

@Mergifyio backport release/indexer/v5.x

Copy link
Contributor

mergify bot commented Jun 19, 2024

backport release/indexer/v5.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jun 19, 2024
Christopher-Li added a commit that referenced this pull request Jun 19, 2024
dydxwill added a commit that referenced this pull request Jun 28, 2024
dydxwill added a commit that referenced this pull request Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants