Skip to content

feat(alert): implement wallet balance alerts#2167

Merged
ygrishajev merged 1 commit intomainfrom
feature/billing
Nov 10, 2025
Merged

feat(alert): implement wallet balance alerts#2167
ygrishajev merged 1 commit intomainfrom
feature/billing

Conversation

@ygrishajev
Copy link
Contributor

@ygrishajev ygrishajev commented Nov 6, 2025

Which besides being another type of supported alerts would serve as auto credit reload.

refs #1779

Summary by CodeRabbit

  • New Features

    • Wallet balance alerts: create alerts that trigger when wallet balances meet configured conditions; evaluated on new blocks and send notifications.
  • API

    • Alert schemas and endpoints updated to accept, return, and list wallet-balance alert variants and params; paginated alert list output added.
  • Database

    • Alert type enum extended to include WALLET_BALANCE; migration snapshot updated.
  • Tests

    • New unit and functional tests plus test seeder covering wallet balance alert flows.
  • Reliability

    • Improved error handling and provider integration for balance fetching and alert processing.

@ygrishajev ygrishajev requested a review from a team as a code owner November 6, 2025 17:06
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 6, 2025

Walkthrough

Adds WALLET_BALANCE alert support: DB enum migration and snapshot; new WalletBalanceAlertsService with unit tests; schema, repository, module/provider, HTTP schema, handler, seeder, and test updates; small utility defensive error handling change.

Changes

Cohort / File(s) Change Summary
DB migration & snapshot
apps/notifications/drizzle/0005_left_magus.sql, apps/notifications/drizzle/meta/0005_snapshot.json, apps/notifications/drizzle/meta/_journal.json
Adds WALLET_BALANCE to alert_type enum; updates snapshot with alerts/block_cursor/notification_channels and appends journal entry.
Handler & tests
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts, apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
Injects WalletBalanceAlertsService; runs deployment and wallet checks concurrently and updates tests to provide and assert wallet service usage.
Alert model & JSON schemas
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts, apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
Adds WALLET_BALANCE to AlertType; renames deploymentBalanceConditionsSchemabalanceConditionsSchema; introduces wallet balance JSON schemas and params.
Repository
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts
Adds WalletBalanceJsonFields and WalletBalance alert input/output types; extends AlertInput/AlertOutput unions and type maps; handles WALLET_BALANCE in toOutput.
WalletBalance service & tests
apps/notifications/src/modules/alert/services/wallet-balance-alerts/*
New WalletBalanceAlertsService with pagination, balance fetching via BalanceHttpService, condition matching, throttled minBlockHeight updates, status toggles, message emission; comprehensive unit tests added.
Module & providers
apps/notifications/src/modules/alert/alert.module.ts, apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
Registers and exports WalletBalanceAlertsService; adds BalanceHttpService provider configured from alert.API_NODE_ENDPOINT.
HTTP schemas / REST
apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts
Adds walletBalanceCreateInputSchema and walletBalanceOutputSchema; includes wallet balance in discriminated unions; uses balanceConditionsSchema; adds AlertListOutputResponse.
Utilities
apps/notifications/src/lib/value-backoff/value-backoff.ts
Defensive error handling: if createError provided, call it in try/catch, attach original error as cause, and fall back if createError throws.
Tests & seeders
apps/notifications/test/functional/balance-alert.spec.ts, apps/notifications/test/seeders/wallet-balance-alert.seeder.ts
Removes duplicate process call in functional test; adds generateWalletBalanceAlert test seeder producing WalletBalanceAlertOutput defaults.

Sequence Diagram(s)

sequenceDiagram
    participant BC as BlockCreated
    participant CEH as ChainEventsHandler
    participant DBAS as DeploymentBalanceAlertsService
    participant WBAS as WalletBalanceAlertsService
    participant BR as AlertRepository
    participant BHS as BalanceHttpService
    participant AMS as AlertMessageService
    participant MC as MessageCallback

    BC->>CEH: blockCreated(block)
    par Concurrent checks
        CEH->>DBAS: evaluateDeploymentBalanceAlertsOnBlock(block)
        CEH->>WBAS: evaluateWalletBalanceAlertsOnBlock(block)
    end

    opt Wallet flow details
        WBAS->>BR: paginate WALLET_BALANCE alerts
        loop per alert
            WBAS->>BHS: fetchBalance(owner, denom)
            alt fetch success & condition matches
                WBAS->>BR: update status -> TRIGGERED and minBlockHeight
                WBAS->>AMS: build message
                WBAS->>MC: emit onMessage
            else fetch success & no match
                WBAS->>BR: update status -> OK and minBlockHeight
            else fetch error
                WBAS->>WBAS: log ALERT_FAILURE (block, alert, error)
            end
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25–30 minutes

  • Review focus:
    • WalletBalanceAlertsService: pagination, throttle (minBlockHeight), per-alert error handling and logs.
    • Repository JSON parsing / toOutput adjustments for new type.
    • ChainEventsHandler concurrency and updated tests.
    • Provider wiring for BalanceHttpService and module exports.

Possibly related PRs

Suggested reviewers

  • stalniy
  • baktun14

Poem

🐇 In burrows of code I softly tread,
I watch wallets bloom where numbers spread,
Enums hop in morning light,
Alerts sing out from day to night,
Carrots for bugs — all patched and fed! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(alert): implement wallet balance alerts' directly and clearly summarizes the main change: implementing a new wallet balance alerts feature within the alert module.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/billing

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (3)
apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (1)

2-2: LGTM! BalanceHttpService provider correctly configured.

The BalanceHttpService provider is properly set up with the required configuration from ConfigService.

Note: Unlike DeploymentHttpService and LeaseHttpService which share a common HttpClient instance, BalanceHttpService creates its own HTTP client. This is due to the different constructor signature in the @akashnetwork/http-sdk package and results in separate connection pools.

Also applies to: 26-30

apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (2)

6-6: Remove unused import.

DeploymentBalanceAlertOutput is imported but the only reference to it on line 64 is incorrect—it should be WalletBalanceAlertOutput instead. Remove this unused import.

-import { AlertRepository, DeploymentBalanceAlertOutput, WalletBalanceAlertOutput } from "@src/modules/alert/repositories/alert/alert.repository";
+import { AlertRepository, WalletBalanceAlertOutput } from "@src/modules/alert/repositories/alert/alert.repository";

54-61: Add block context to error logging.

The error log is missing the block height, which would be helpful for correlating failures with specific chain events and debugging.

       if (!balance) {
         this.loggerService.error({
           event: "ALERT_FAILURE",
+          block: block.height,
           alert,
           error: new Error("Failed to fetch balance")
         });
         return;
       }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c34f76b and 4ce51b5.

📒 Files selected for processing (16)
  • apps/notifications/drizzle/0005_left_magus.sql (1 hunks)
  • apps/notifications/drizzle/meta/0005_snapshot.json (1 hunks)
  • apps/notifications/drizzle/meta/_journal.json (1 hunks)
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts (2 hunks)
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1 hunks)
  • apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (3 hunks)
  • apps/notifications/src/lib/value-backoff/value-backoff.ts (1 hunks)
  • apps/notifications/src/modules/alert/alert.module.ts (3 hunks)
  • apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1 hunks)
  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (2 hunks)
  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (4 hunks)
  • apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (3 hunks)
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (1 hunks)
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1 hunks)
  • apps/notifications/test/functional/balance-alert.spec.ts (1 hunks)
  • apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.spec.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block in test files
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

Files:

  • apps/notifications/test/functional/balance-alert.spec.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/notifications/test/functional/balance-alert.spec.ts
  • apps/notifications/src/modules/alert/model-schemas/alert.schema.ts
  • apps/notifications/test/seeders/wallet-balance-alert.seeder.ts
  • apps/notifications/src/modules/alert/alert.module.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/lib/value-backoff/value-backoff.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts
  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
  • apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/notifications/test/functional/balance-alert.spec.ts
  • apps/notifications/src/modules/alert/model-schemas/alert.schema.ts
  • apps/notifications/test/seeders/wallet-balance-alert.seeder.ts
  • apps/notifications/src/modules/alert/alert.module.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/lib/value-backoff/value-backoff.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts
  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
  • apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
🧠 Learnings (5)
📚 Learning: 2025-10-15T16:39:55.348Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.

Applied to files:

  • apps/notifications/test/seeders/wallet-balance-alert.seeder.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-03T14:40:49.886Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 1498
File: apps/api/src/services/external/templates/template-fetcher.service.ts:0-0
Timestamp: 2025-07-03T14:40:49.886Z
Learning: In the TemplateFetcherService class in apps/api/src/services/external/templates/template-fetcher.service.ts, the error handling strategy should maintain process resilience by catching all errors and returning null rather than re-throwing critical errors, to avoid breaking the whole template fetching process.

Applied to files:

  • apps/notifications/src/lib/value-backoff/value-backoff.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it

Applied to files:

  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-09-04T04:27:50.638Z
Learnt from: stalniy
Repo: akash-network/console PR: 1868
File: apps/api/src/billing/services/managed-signer/managed-signer.service.ts:1-1
Timestamp: 2025-09-04T04:27:50.638Z
Learning: In the akash-network/console project, importing MsgCreateLease from "akashnetwork/akash-api/v1beta3" instead of v1beta4 is considered non-critical by the maintainers, likely due to backward compatibility or project-specific requirements.

Applied to files:

  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
📚 Learning: 2025-09-25T14:31:44.914Z
Learnt from: baktun14
Repo: akash-network/console PR: 1969
File: apps/deploy-web/src/pages/payment.tsx:179-191
Timestamp: 2025-09-25T14:31:44.914Z
Learning: The payment confirmation endpoint in apps/api/src/billing/http-schemas/stripe.schema.ts uses zod schema validation with `amount: z.number().gte(20, "Amount must be greater or equal to $20")` to ensure all payment requests meet the minimum amount requirement, preventing zero-amount or invalid payments from reaching Stripe.

Applied to files:

  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
🧬 Code graph analysis (9)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
  • AlertType (34-34)
apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (2)
apps/notifications/test/seeders/akash-address.seeder.ts (1)
  • mockAkashAddress (3-3)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
  • WalletBalanceAlertOutput (29-29)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (3)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1)
  • Injectable (13-100)
apps/notifications/src/infrastructure/broker/services/broker/broker.service.ts (1)
  • Injectable (17-72)
apps/notifications/src/common/config/event-key-registry.config.ts (1)
  • eventKeyRegistry (1-5)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
  • AlertType (8-8)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (8)
apps/notifications/test/seeders/akash-address.seeder.ts (1)
  • mockAkashAddress (3-3)
apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1)
  • generateWalletBalanceAlert (7-45)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
  • WalletBalanceAlertOutput (29-29)
  • AlertOutput (32-32)
packages/http-sdk/src/types/denom.type.ts (1)
  • Denom (1-4)
apps/notifications/test/seeders/alert-message.seeder.ts (1)
  • generateAlertMessage (5-17)
packages/logging/src/services/logger/logger.service.ts (1)
  • error (142-144)
packages/http-sdk/src/balance/balance-http.service.ts (1)
  • BalanceHttpService (20-29)
apps/notifications/test/mocks/provider.mock.ts (1)
  • MockProvider (4-6)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts (2)
apps/notifications/src/common/config/event-key-registry.config.ts (1)
  • eventKeyRegistry (1-5)
apps/notifications/test/mocks/provider.mock.ts (1)
  • MockProvider (4-6)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (6)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (3)
  • WalletBalanceAlertOutput (29-29)
  • Injectable (84-320)
  • DeploymentBalanceAlertOutput (26-26)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)
  • Injectable (11-45)
packages/http-sdk/src/balance/balance-http.service.ts (1)
  • BalanceHttpService (20-29)
apps/notifications/src/modules/alert/types/message-callback.type.ts (1)
  • MessageCallback (8-8)
packages/logging/src/services/logger/logger.service.ts (1)
  • error (142-144)
apps/notifications/src/modules/alert/services/conditions-matcher/conditions-matcher.service.ts (1)
  • isMatching (22-25)
apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (2)
packages/http-sdk/src/balance/balance-http.service.ts (1)
  • BalanceHttpService (20-29)
apps/notifications/src/modules/alert/config/index.ts (1)
  • AlertConfig (9-9)
apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (2)
apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (5)
  • balanceConditionsSchema (31-31)
  • deploymentBalanceParamsSchema (37-41)
  • walletBalanceTypeSchema (58-58)
  • walletBalanceParamsSchema (43-47)
  • generalAlertConditionsSchema (23-23)
packages/http-sdk/src/generated/NotificationSDK.ts (1)
  • AlertCreateInput (13-93)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
🔇 Additional comments (12)
apps/notifications/drizzle/0005_left_magus.sql (1)

1-1: LGTM! SQL migration is correct.

The migration correctly extends the alert_type enum with the new WALLET_BALANCE value using proper PostgreSQL syntax.

apps/notifications/drizzle/meta/_journal.json (1)

40-46: LGTM! Migration journal entry is correct.

The new journal entry properly tracks the 0005_left_magus migration with appropriate metadata.

apps/notifications/drizzle/meta/0005_snapshot.json (1)

1-444: LGTM! Snapshot reflects the schema after migration.

This auto-generated snapshot correctly captures the database schema state including the new WALLET_BALANCE enum value in the alert_type enum.

apps/notifications/src/modules/alert/alert.module.ts (2)

14-14: LGTM! Service properly registered.

The WalletBalanceAlertsService is correctly imported and added to the module's providers array, making it available for dependency injection.

Also applies to: 30-30


39-39: LGTM! Service properly exported.

Exporting WalletBalanceAlertsService makes it available for injection in other modules, which is necessary for the ChainEventsHandler to use it.

apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)

8-8: LGTM! Enum extension is correct.

The WALLET_BALANCE value has been properly added to the AlertType enum, maintaining consistency with the SQL migration and providing type safety for TypeScript code.

apps/notifications/test/functional/balance-alert.spec.ts (1)

127-128: LGTM! Method rename improves clarity.

The renamed method evaluateDeploymentBalanceAlertsOnBlock is more descriptive and explicitly indicates that it processes deployment balance alerts, distinguishing it from the new wallet balance alert evaluation pathway.

apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1)

7-45: LGTM! Test seeder is well-implemented.

The generateWalletBalanceAlert function follows established patterns in the codebase, provides sensible defaults for all fields, and maintains type safety with WalletBalanceAlertOutput. The default conditions and params are appropriate for wallet balance alert testing scenarios.

apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1)

31-48: Reconsider re-throwing errors in batch processing.

The error is re-thrown on line 46, which could cause the entire block processing to fail. Since processSingleAlert already has isolated error handling (lines 92-98) that doesn't re-throw, this inconsistency means a pagination-level error (e.g., database timeout) will propagate up and potentially stop all alert processing for the block, while per-alert errors are contained.

Consider whether pagination errors should also be isolated to allow other alerts to continue processing, or if failing fast is the intended behavior.

     } catch (error) {
       this.loggerService.error({
         event: "ALERT_FAILURE",
         block,
         error
       });
-      throw error;
     }
apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (3)

31-31: Good refactoring to share the schema.

Renaming deploymentBalanceConditionsSchema to balanceConditionsSchema appropriately reflects that the schema is now shared between deployment and wallet balance alerts, eliminating duplication.


43-47: Consider adding validation for address and denomination formats.

The owner and denom fields accept any string without format validation. Invalid addresses or denominations will only fail at runtime when BalanceHttpService.getBalance() is called, potentially after the alert is already saved.

Verify whether validation should be added here (e.g., Bech32 format for owner, known denom values for denom) or if flexibility is preferred for supporting various chain configurations.


72-76: LGTM!

The walletBalanceJsonFieldsSchema and WalletBalanceJsonFields type follow the same pattern as the existing deployment balance schema, maintaining consistency across alert types.

Also applies to: 80-80

@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

❌ Patch coverage is 85.07463% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.43%. Comparing base (cd46e86) to head (7c56445).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...tifications/src/lib/value-backoff/value-backoff.ts 28.57% 5 Missing ⚠️
...ents/handlers/chain-events/chain-events.handler.ts 66.66% 3 Missing ⚠️
...dules/alert/repositories/alert/alert.repository.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2167      +/-   ##
==========================================
- Coverage   46.70%   46.43%   -0.28%     
==========================================
  Files        1019     1010       -9     
  Lines       28929    28641     -288     
  Branches     7515     7480      -35     
==========================================
- Hits        13512    13300     -212     
+ Misses      15103    15047      -56     
+ Partials      314      294      -20     
Flag Coverage Δ *Carryforward flag
api 81.83% <ø> (ø) Carriedforward from cd46e86
deploy-web 25.26% <ø> (ø) Carriedforward from cd46e86
log-collector ?
notifications 87.94% <85.07%> (-0.18%) ⬇️
provider-console 81.48% <ø> (ø) Carriedforward from cd46e86
provider-proxy 85.28% <ø> (ø) Carriedforward from cd46e86

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
.../interfaces/rest/http-schemas/alert.http-schema.ts 100.00% <100.00%> (ø)
...ns/src/modules/alert/model-schemas/alert.schema.ts 88.88% <100.00%> (ø)
...s/src/modules/alert/providers/http-sdk.provider.ts 100.00% <100.00%> (ø)
...ert/repositories/alert/alert-json-fields.schema.ts 100.00% <100.00%> (ø)
...et-balance-alerts/wallet-balance-alerts.service.ts 100.00% <100.00%> (ø)
...dules/alert/repositories/alert/alert.repository.ts 79.79% <0.00%> (-1.65%) ⬇️
...ents/handlers/chain-events/chain-events.handler.ts 87.50% <66.66%> (-12.50%) ⬇️
...tifications/src/lib/value-backoff/value-backoff.ts 78.26% <28.57%> (-21.74%) ⬇️

... and 12 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ygrishajev ygrishajev marked this pull request as draft November 6, 2025 17:34
@ygrishajev ygrishajev force-pushed the feature/billing branch 2 times, most recently from ab00336 to 24eeebf Compare November 7, 2025 11:52
@ygrishajev ygrishajev marked this pull request as ready for review November 7, 2025 12:15
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: 1

♻️ Duplicate comments (1)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (1)

235-266: Match setup signature with mandated pattern.

The setup function must accept exactly one parameter with an inline type definition and should not declare an explicit return type, per the coding guidelines.

Apply this diff:

-  async function setup(): Promise<{
-    service: WalletBalanceAlertsService;
-    loggerService: MockProxy<LoggerService>;
-    alertRepository: MockProxy<AlertRepository>;
-    conditionsMatcherService: ConditionsMatcherService;
-    alertMessageService: MockProxy<AlertMessageService>;
-    balanceHttpService: MockProxy<BalanceHttpService>;
-    onMessage: jest.Mock;
-  }> {
+  async function setup(opts: Record<string, never> = {}) {

As per coding guidelines.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ce51b5 and 24eeebf.

📒 Files selected for processing (16)
  • apps/notifications/drizzle/0005_left_magus.sql (1 hunks)
  • apps/notifications/drizzle/meta/0005_snapshot.json (1 hunks)
  • apps/notifications/drizzle/meta/_journal.json (1 hunks)
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts (2 hunks)
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1 hunks)
  • apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (3 hunks)
  • apps/notifications/src/lib/value-backoff/value-backoff.ts (1 hunks)
  • apps/notifications/src/modules/alert/alert.module.ts (3 hunks)
  • apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1 hunks)
  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (2 hunks)
  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (4 hunks)
  • apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (3 hunks)
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (1 hunks)
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1 hunks)
  • apps/notifications/test/functional/balance-alert.spec.ts (1 hunks)
  • apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • apps/notifications/src/modules/alert/alert.module.ts
  • apps/notifications/src/modules/alert/model-schemas/alert.schema.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
  • apps/notifications/test/functional/balance-alert.spec.ts
  • apps/notifications/src/lib/value-backoff/value-backoff.ts
  • apps/notifications/test/seeders/wallet-balance-alert.seeder.ts
  • apps/notifications/drizzle/0005_left_magus.sql
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
  • apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
  • apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts
**/*.spec.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block in test files
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

Files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
🧠 Learnings (11)
📚 Learning: 2025-09-04T04:27:50.638Z
Learnt from: stalniy
Repo: akash-network/console PR: 1868
File: apps/api/src/billing/services/managed-signer/managed-signer.service.ts:1-1
Timestamp: 2025-09-04T04:27:50.638Z
Learning: In the akash-network/console project, importing MsgCreateLease from "akashnetwork/akash-api/v1beta3" instead of v1beta4 is considered non-critical by the maintainers, likely due to backward compatibility or project-specific requirements.

Applied to files:

  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
📚 Learning: 2025-10-15T16:39:55.348Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function should accept a single parameter with inline type definition

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't specify return type of `setup` function

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Use `setup` function instead of `beforeEach` in test files

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use shared state in `setup` function

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function must be at the bottom of the root `describe` block in test files

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:24:24.269Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/no-jest-mock.mdc:0-0
Timestamp: 2025-07-21T08:24:24.269Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use `jest.mock()` to mock dependencies in test files. Instead, use `jest-mock-extended` to create mocks and pass mocks as dependencies to the service under test.

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-03T14:42:10.968Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 1498
File: apps/api/test/functional/templates.spec.ts:39-110
Timestamp: 2025-07-03T14:42:10.968Z
Learning: Setup function guidelines in test files apply when creating objects under test. For simple environment preparation functions (like file copying), the typical setup function pattern of accepting parameters and returning objects may not be necessary.

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-09-25T14:31:44.914Z
Learnt from: baktun14
Repo: akash-network/console PR: 1969
File: apps/deploy-web/src/pages/payment.tsx:179-191
Timestamp: 2025-09-25T14:31:44.914Z
Learning: The payment confirmation endpoint in apps/api/src/billing/http-schemas/stripe.schema.ts uses zod schema validation with `amount: z.number().gte(20, "Amount must be greater or equal to $20")` to ensure all payment requests meet the minimum amount requirement, preventing zero-amount or invalid payments from reaching Stripe.

Applied to files:

  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
🧬 Code graph analysis (6)
apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (3)
packages/http-sdk/src/balance/balance-http.service.ts (1)
  • BalanceHttpService (20-29)
apps/api/src/core/services/config/config.service.ts (1)
  • ConfigService (9-22)
apps/notifications/src/modules/alert/config/index.ts (1)
  • AlertConfig (9-9)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
  • AlertType (8-8)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (7)
apps/notifications/test/seeders/akash-address.seeder.ts (1)
  • mockAkashAddress (3-3)
apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1)
  • generateWalletBalanceAlert (7-45)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
  • WalletBalanceAlertOutput (29-29)
  • AlertOutput (32-32)
packages/http-sdk/src/types/denom.type.ts (1)
  • Denom (1-4)
apps/notifications/test/seeders/alert-message.seeder.ts (1)
  • generateAlertMessage (5-17)
packages/http-sdk/src/balance/balance-http.service.ts (1)
  • BalanceHttpService (20-29)
apps/notifications/test/mocks/provider.mock.ts (1)
  • MockProvider (4-6)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (3)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
  • Injectable (84-320)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1)
  • Injectable (13-100)
apps/notifications/src/infrastructure/broker/services/broker/broker.service.ts (1)
  • Injectable (17-72)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (6)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
  • WalletBalanceAlertOutput (29-29)
  • Injectable (84-320)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)
  • Injectable (11-45)
packages/http-sdk/src/balance/balance-http.service.ts (1)
  • BalanceHttpService (20-29)
apps/notifications/src/modules/alert/types/message-callback.type.ts (1)
  • MessageCallback (8-8)
packages/logging/src/services/logger/logger.service.ts (1)
  • error (142-144)
apps/notifications/src/modules/alert/services/conditions-matcher/conditions-matcher.service.ts (1)
  • isMatching (22-25)
apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (2)
apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (5)
  • balanceConditionsSchema (31-31)
  • deploymentBalanceParamsSchema (37-41)
  • walletBalanceTypeSchema (58-58)
  • walletBalanceParamsSchema (43-47)
  • generalAlertConditionsSchema (23-23)
packages/http-sdk/src/generated/NotificationSDK.ts (1)
  • AlertCreateInput (13-93)
🔇 Additional comments (2)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1)

1-100: LGTM!

The service implementation correctly orchestrates wallet balance alert processing with proper error handling, status transitions, and message emission logic.

apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (1)

52-58: LGTM!

The wallet balance alert schemas are properly integrated into the discriminated unions for both input and output, with appropriate reuse of balanceConditionsSchema.

Also applies to: 60-65, 106-117

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

♻️ Duplicate comments (3)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)

40-46: Keep a single blockCreated handler

Registering a second @Handler for eventKeyRegistry.blockCreated spins up another worker on the same queue, so one handler steals jobs from the other and wallet/deployment alerts get skipped. We already fan out inside processBlock; drop the duplicate handler.

-  @Handler({
-    key: eventKeyRegistry.blockCreated,
-    dto: ChainBlockCreatedDto
-  })
-  async evaluateWalletBalanceAlertsOnBlock(block: ChainBlockCreatedDto) {
-    await this.walletBalanceAlertsService.alertFor(block, async message => this.brokerService.publish(eventKeyRegistry.createNotification, message));
-  }
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts (1)

50-58: Align setup signature with spec guidelines

Per the spec conventions, setup must accept a single inline-typed parameter. Please update the helper signature accordingly. As per coding guidelines.

-  async function setup() {
+  async function setup({}: Record<string, never> = {}) {
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (1)

235-266: Adjust setup function signature to match coding guidelines.

The setup function currently has no parameter and an explicit return type, which violates the coding guidelines. Per the guidelines and similar to the previous review comment, the function should accept a single parameter with an inline type definition and should not have an explicit return type annotation.

As per coding guidelines. Based on learnings.

Apply this diff:

-  async function setup(): Promise<{
-    service: WalletBalanceAlertsService;
-    loggerService: MockProxy<LoggerService>;
-    alertRepository: MockProxy<AlertRepository>;
-    conditionsMatcherService: ConditionsMatcherService;
-    alertMessageService: MockProxy<AlertMessageService>;
-    balanceHttpService: MockProxy<BalanceHttpService>;
-    onMessage: jest.Mock;
-  }> {
+  async function setup({}: {} = {}) {
     const module: TestingModule = await Test.createTestingModule({
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24eeebf and ba550e4.

📒 Files selected for processing (16)
  • apps/notifications/drizzle/0005_left_magus.sql (1 hunks)
  • apps/notifications/drizzle/meta/0005_snapshot.json (1 hunks)
  • apps/notifications/drizzle/meta/_journal.json (1 hunks)
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts (3 hunks)
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (2 hunks)
  • apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (3 hunks)
  • apps/notifications/src/lib/value-backoff/value-backoff.ts (1 hunks)
  • apps/notifications/src/modules/alert/alert.module.ts (3 hunks)
  • apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1 hunks)
  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (2 hunks)
  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (4 hunks)
  • apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (3 hunks)
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (1 hunks)
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1 hunks)
  • apps/notifications/test/functional/balance-alert.spec.ts (1 hunks)
  • apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • apps/notifications/src/modules/alert/alert.module.ts
  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
  • apps/notifications/src/lib/value-backoff/value-backoff.ts
  • apps/notifications/drizzle/meta/_journal.json
  • apps/notifications/drizzle/0005_left_magus.sql
🧰 Additional context used
📓 Path-based instructions (3)
**/*.spec.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block in test files
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

Files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
  • apps/notifications/test/functional/balance-alert.spec.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/modules/alert/model-schemas/alert.schema.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts
  • apps/notifications/test/seeders/wallet-balance-alert.seeder.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
  • apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts
  • apps/notifications/test/functional/balance-alert.spec.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/modules/alert/model-schemas/alert.schema.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts
  • apps/notifications/test/seeders/wallet-balance-alert.seeder.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
  • apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts
  • apps/notifications/test/functional/balance-alert.spec.ts
🧠 Learnings (11)
📚 Learning: 2025-10-15T16:39:55.348Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/test/seeders/wallet-balance-alert.seeder.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function should accept a single parameter with inline type definition

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't specify return type of `setup` function

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Use `setup` function instead of `beforeEach` in test files

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use shared state in `setup` function

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function must be at the bottom of the root `describe` block in test files

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-21T08:24:24.269Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/no-jest-mock.mdc:0-0
Timestamp: 2025-07-21T08:24:24.269Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use `jest.mock()` to mock dependencies in test files. Instead, use `jest-mock-extended` to create mocks and pass mocks as dependencies to the service under test.

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-07-03T14:42:10.968Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 1498
File: apps/api/test/functional/templates.spec.ts:39-110
Timestamp: 2025-07-03T14:42:10.968Z
Learning: Setup function guidelines in test files apply when creating objects under test. For simple environment preparation functions (like file copying), the typical setup function pattern of accepting parameters and returning objects may not be necessary.

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
📚 Learning: 2025-09-25T14:31:44.914Z
Learnt from: baktun14
Repo: akash-network/console PR: 1969
File: apps/deploy-web/src/pages/payment.tsx:179-191
Timestamp: 2025-09-25T14:31:44.914Z
Learning: The payment confirmation endpoint in apps/api/src/billing/http-schemas/stripe.schema.ts uses zod schema validation with `amount: z.number().gte(20, "Amount must be greater or equal to $20")` to ensure all payment requests meet the minimum amount requirement, preventing zero-amount or invalid payments from reaching Stripe.

Applied to files:

  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
📚 Learning: 2025-07-21T08:24:27.953Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-07-21T08:24:27.953Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files

Applied to files:

  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
🧬 Code graph analysis (8)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (8)
apps/notifications/test/seeders/akash-address.seeder.ts (1)
  • mockAkashAddress (3-3)
apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1)
  • generateWalletBalanceAlert (7-45)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
  • WalletBalanceAlertOutput (29-29)
  • AlertOutput (32-32)
packages/http-sdk/src/types/denom.type.ts (1)
  • Denom (1-4)
apps/notifications/test/seeders/alert-message.seeder.ts (1)
  • generateAlertMessage (5-17)
packages/logging/src/services/logger/logger.service.ts (1)
  • error (142-144)
packages/http-sdk/src/balance/balance-http.service.ts (1)
  • BalanceHttpService (20-29)
apps/notifications/test/mocks/provider.mock.ts (1)
  • MockProvider (4-6)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
  • AlertType (34-34)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (6)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1)
  • Injectable (13-100)
apps/notifications/src/infrastructure/broker/services/broker/broker.service.ts (1)
  • Injectable (17-72)
apps/notifications/src/modules/alert/services/deployment-balance-alerts/deployment-balance-alerts.service.ts (1)
  • Injectable (16-133)
apps/notifications/src/common/config/event-key-registry.config.ts (1)
  • eventKeyRegistry (1-5)
apps/notifications/src/infrastructure/broker/decorators/handler.decorator.ts (1)
  • Handler (7-7)
apps/notifications/src/modules/alert/dto/chain-block-created.dto.ts (1)
  • ChainBlockCreatedDto (8-8)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (1)
  • WalletBalanceJsonFields (80-80)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
  • AlertType (8-8)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (7)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
  • WalletBalanceAlertOutput (29-29)
  • Injectable (84-320)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)
  • Injectable (11-57)
packages/http-sdk/src/balance/balance-http.service.ts (1)
  • BalanceHttpService (20-29)
apps/notifications/src/modules/alert/dto/chain-block-created.dto.ts (1)
  • ChainBlockCreatedDto (8-8)
apps/notifications/src/modules/alert/types/message-callback.type.ts (1)
  • MessageCallback (8-8)
packages/logging/src/services/logger/logger.service.ts (1)
  • error (142-144)
apps/notifications/src/modules/alert/services/conditions-matcher/conditions-matcher.service.ts (1)
  • isMatching (22-25)
apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (2)
apps/notifications/test/seeders/akash-address.seeder.ts (1)
  • mockAkashAddress (3-3)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
  • WalletBalanceAlertOutput (29-29)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts (2)
apps/notifications/src/common/config/event-key-registry.config.ts (1)
  • eventKeyRegistry (1-5)
apps/notifications/test/mocks/provider.mock.ts (1)
  • MockProvider (4-6)
apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (1)
apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (5)
  • balanceConditionsSchema (31-31)
  • deploymentBalanceParamsSchema (37-41)
  • walletBalanceTypeSchema (58-58)
  • walletBalanceParamsSchema (43-47)
  • generalAlertConditionsSchema (23-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
🔇 Additional comments (20)
apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1)

7-45: LGTM!

The seeder function is well-structured with appropriate defaults and type safety. The function signature correctly uses Partial<WalletBalanceAlertOutput> for flexible test data generation, and all fields are properly initialized with sensible faker-generated values or explicit defaults.

apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (4)

14-14: LGTM!

The import of WalletBalanceJsonFields is correctly added alongside existing alert type imports.


28-32: LGTM!

The type definitions follow the established pattern for alert types. WalletBalanceAlertInput and WalletBalanceAlertOutput are properly defined using the same Omit pattern as DeploymentBalanceAlertInput/Output, and they're correctly integrated into the union types.


38-48: LGTM!

The type maps are correctly extended to include WALLET_BALANCE entries, maintaining consistency with the existing alert type registration pattern.


311-316: LGTM!

The WALLET_BALANCE handling in toOutput correctly follows the same pattern as DEPLOYMENT_BALANCE, parsing the schema and returning the typed output.

apps/notifications/drizzle/meta/0005_snapshot.json (1)

416-425: LGTM!

The database snapshot correctly includes WALLET_BALANCE in the alert_type enum alongside existing alert types. This generated file properly reflects the schema changes for wallet balance alerts.

apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (6)

20-69: LGTM!

The test comprehensively validates the alert triggering flow, including balance fetching, condition matching, message generation, and repository updates with correct status and minBlockHeight values.


71-122: LGTM!

The recovery test correctly validates that a triggered alert transitions back to OK status when the balance condition is no longer met.


124-161: LGTM!

This test correctly validates the duplicate trigger guard behavior: when an alert is already triggered and conditions still match, the service skips message generation and emission while still updating the minBlockHeight.


163-191: LGTM!

The test properly validates error handling when balance fetch returns null, ensuring the error is logged with the correct event type and alert context without attempting updates.


193-210: LGTM!

The test correctly validates that repository failures are logged with event, block, and error details, and the error is propagated to the caller.


212-232: LGTM!

The test validates that individual alert processing errors are caught, logged with alert and error context, and don't prevent other alerts from being processed.

apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (4)

14-25: LGTM!

The service is properly structured with correct dependency injection and the logger context is set appropriately. The throttle constant is well-named and scoped.


27-29: LGTM!

Clean delegation pattern that separates concerns between block processing orchestration and per-alert processing logic.


31-48: LGTM!

The pagination logic correctly queries WALLET_BALANCE alerts for the given block, processes them concurrently with Promise.all, and properly handles errors by logging and re-throwing to notify the caller.


50-99: LGTM!

The alert processing logic is well-structured:

  • Fetches balance and handles missing data gracefully
  • Uses conditions matcher to determine if alert should trigger
  • Correctly manages status transitions (OK ↔ TRIGGERED) with appropriate throttling
  • Sends notifications only when status changes
  • Catches and logs individual alert errors without failing the entire batch
apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (4)

6-15: LGTM!

The imports correctly include the new wallet balance schemas and the shared balanceConditionsSchema, which promotes reuse between deployment and wallet balance alert types.


52-58: LGTM!

The walletBalanceCreateInputSchema correctly follows the same pattern as deploymentBalanceCreateInputSchema, using the shared balanceConditionsSchema and wallet-specific params schema.


60-65: LGTM!

The discriminated union correctly includes walletBalanceCreateInputSchema, enabling type-safe alert creation for wallet balance alerts.


106-117: LGTM!

The output schemas correctly mirror the input schema structure, with walletBalanceOutputSchema properly included in the discriminated union for type-safe alert responses.

await this.deploymentBalanceAlertsService.alertFor(block, message => this.brokerService.publish(eventKeyRegistry.createNotification, message));
const results = await Promise.allSettled([
this.deploymentBalanceAlertsService.alertFor(block, message => this.brokerService.publish(eventKeyRegistry.createNotification, message)),
this.walletBalanceAlertsService.alertFor(block, async message => this.brokerService.publish(eventKeyRegistry.createNotification, message))
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Does that mean we fetch the balance from the api every block for every alerts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is a throttle value similarly to deployment balance alerts.
https://github.com/akash-network/console/pull/2167/files/ba550e4f0ead428a2566ef26d1018ce6483f71ec#diff-84fb62ed999011521b82c17f15f2a14d301ffb7be42f3dd6ff10128965d1dfe4R65
https://github.com/akash-network/console/pull/2167/files/ba550e4f0ead428a2566ef26d1018ce6483f71ec#diff-84fb62ed999011521b82c17f15f2a14d301ffb7be42f3dd6ff10128965d1dfe4R34

However this a dumb initial implementation which is fine for quite a while. By the end of the milestone I have an idea on how to optimise this much nicer: listen to deployment-closed/created events and recalculate that value for owners.

baktun14
baktun14 previously approved these changes Nov 7, 2025
Which besides being another type of supported alerts would serve as auto credit reload.

refs #1779
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

♻️ Duplicate comments (1)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (1)

235-243: Adjust setup signature to match coding guidelines.

The setup function violates coding guidelines by having no parameter and an explicit return type. As per coding guidelines.

Apply this diff:

-  async function setup(): Promise<{
-    service: WalletBalanceAlertsService;
-    loggerService: MockProxy<LoggerService>;
-    alertRepository: MockProxy<AlertRepository>;
-    conditionsMatcherService: ConditionsMatcherService;
-    alertMessageService: MockProxy<AlertMessageService>;
-    balanceHttpService: MockProxy<BalanceHttpService>;
-    onMessage: jest.Mock;
-  }> {
+  async function setup(opts: {} = {}) {
🧹 Nitpick comments (1)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)

25-28: Remove unnecessary async keyword for consistency.

Line 27 uses async message => while line 26 uses message =>. Since brokerService.publish already returns a Promise, the async keyword is redundant and creates an inconsistency.

Apply this diff:

-      this.walletBalanceAlertsService.alertFor(block, async message => this.brokerService.publish(eventKeyRegistry.createNotification, message))
+      this.walletBalanceAlertsService.alertFor(block, message => this.brokerService.publish(eventKeyRegistry.createNotification, message))
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba550e4 and 7c56445.

📒 Files selected for processing (16)
  • apps/notifications/drizzle/0005_left_magus.sql (1 hunks)
  • apps/notifications/drizzle/meta/0005_snapshot.json (1 hunks)
  • apps/notifications/drizzle/meta/_journal.json (1 hunks)
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts (3 hunks)
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (2 hunks)
  • apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts (3 hunks)
  • apps/notifications/src/lib/value-backoff/value-backoff.ts (1 hunks)
  • apps/notifications/src/modules/alert/alert.module.ts (3 hunks)
  • apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1 hunks)
  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (2 hunks)
  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts (4 hunks)
  • apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (3 hunks)
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (1 hunks)
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1 hunks)
  • apps/notifications/test/functional/balance-alert.spec.ts (0 hunks)
  • apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/notifications/test/functional/balance-alert.spec.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/notifications/drizzle/0005_left_magus.sql
🚧 Files skipped from review as they are similar to previous changes (9)
  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.spec.ts
  • apps/notifications/src/lib/value-backoff/value-backoff.ts
  • apps/notifications/src/interfaces/rest/http-schemas/alert.http-schema.ts
  • apps/notifications/test/seeders/wallet-balance-alert.seeder.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert-json-fields.schema.ts
  • apps/notifications/src/modules/alert/alert.module.ts
  • apps/notifications/drizzle/meta/0005_snapshot.json
  • apps/notifications/drizzle/meta/_journal.json
  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/modules/alert/model-schemas/alert.schema.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
  • apps/notifications/src/modules/alert/model-schemas/alert.schema.ts
  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts
  • apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts
**/*.spec.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block in test files
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

Files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
🧠 Learnings (9)
📚 Learning: 2025-10-15T16:39:55.348Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function should accept a single parameter with inline type definition

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't specify return type of `setup` function

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Use `setup` function instead of `beforeEach` in test files

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function creates an object under test and returns it

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use shared state in `setup` function

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:25:07.474Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : `setup` function must be at the bottom of the root `describe` block in test files

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-21T08:24:24.269Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/no-jest-mock.mdc:0-0
Timestamp: 2025-07-21T08:24:24.269Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use `jest.mock()` to mock dependencies in test files. Instead, use `jest-mock-extended` to create mocks and pass mocks as dependencies to the service under test.

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
📚 Learning: 2025-07-03T14:42:10.968Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 1498
File: apps/api/test/functional/templates.spec.ts:39-110
Timestamp: 2025-07-03T14:42:10.968Z
Learning: Setup function guidelines in test files apply when creating objects under test. For simple environment preparation functions (like file copying), the typical setup function pattern of accepting parameters and returning objects may not be necessary.

Applied to files:

  • apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts
🧬 Code graph analysis (5)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (4)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (1)
  • Injectable (13-100)
apps/notifications/src/infrastructure/broker/services/broker/broker.service.ts (1)
  • Injectable (17-72)
apps/notifications/src/modules/alert/services/deployment-balance-alerts/deployment-balance-alerts.service.ts (1)
  • Injectable (16-133)
apps/notifications/src/common/config/event-key-registry.config.ts (1)
  • eventKeyRegistry (1-5)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (7)
apps/notifications/test/seeders/akash-address.seeder.ts (1)
  • mockAkashAddress (3-3)
apps/notifications/test/seeders/wallet-balance-alert.seeder.ts (1)
  • generateWalletBalanceAlert (7-45)
packages/http-sdk/src/types/denom.type.ts (1)
  • Denom (1-4)
apps/notifications/test/seeders/alert-message.seeder.ts (1)
  • generateAlertMessage (5-17)
packages/logging/src/services/logger/logger.service.ts (1)
  • error (142-144)
packages/http-sdk/src/balance/balance-http.service.ts (1)
  • BalanceHttpService (20-29)
apps/notifications/test/mocks/provider.mock.ts (1)
  • MockProvider (4-6)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
  • AlertType (34-34)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (6)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)
  • WalletBalanceAlertOutput (29-29)
  • Injectable (84-320)
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)
  • Injectable (11-49)
packages/http-sdk/src/balance/balance-http.service.ts (1)
  • BalanceHttpService (20-29)
apps/notifications/src/modules/alert/types/message-callback.type.ts (1)
  • MessageCallback (8-8)
packages/logging/src/services/logger/logger.service.ts (1)
  • error (142-144)
apps/notifications/src/modules/alert/services/conditions-matcher/conditions-matcher.service.ts (1)
  • isMatching (22-25)
apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (1)
apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)
  • AlertType (8-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: validate / validate-app
🔇 Additional comments (8)
apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.ts (3)

27-29: LGTM!

The public API cleanly delegates to the internal pagination logic.


31-48: LGTM!

Pagination logic with concurrent batch processing and appropriate error handling matches the established pattern.


50-99: LGTM!

The per-alert processing logic is well-structured:

  • Defensive balance check with early return
  • Correct status transitions (OK ↔ TRIGGERED)
  • Message sent only on status change
  • Per-alert error handling ensures batch resilience
apps/notifications/src/interfaces/alert-events/handlers/chain-events/chain-events.handler.ts (1)

25-37: Good use of Promise.allSettled for concurrent execution.

The refactor to Promise.allSettled with AggregateError ensures both deployment and wallet balance alerts run concurrently while properly collecting and surfacing all failures.

apps/notifications/src/modules/alert/model-schemas/alert.schema.ts (1)

8-8: LGTM!

The enum extension correctly adds WALLET_BALANCE as a new alert type, aligning with the PR objectives.

apps/notifications/src/modules/alert/repositories/alert/alert.repository.ts (2)

14-14: LGTM!

The type system extensions for wallet balance alerts follow the established pattern used by deployment balance alerts, maintaining type safety across the repository layer.

Also applies to: 28-29, 31-32, 38-38, 45-45


311-316: LGTM!

The WALLET_BALANCE case in toOutput correctly parses wallet balance JSON fields using the appropriate schema, consistent with existing alert types.

apps/notifications/src/modules/alert/services/wallet-balance-alerts/wallet-balance-alerts.service.spec.ts (1)

20-232: Comprehensive test coverage.

The test suite thoroughly covers the wallet balance alerting scenarios:

  • Alert triggering when condition matches
  • Alert recovery when condition no longer matches
  • Duplicate trigger prevention
  • Missing balance error handling
  • Repository failure handling
  • Per-alert error isolation

@ygrishajev ygrishajev merged commit 95fc847 into main Nov 10, 2025
62 checks passed
@ygrishajev ygrishajev deleted the feature/billing branch November 10, 2025 10:47
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

Comments