Skip to content

feat: on-chain refunds, plan_changed event, webhook circuit breaker, … - #717

Merged
Dev-AdeTutu merged 3 commits into
Dev-AdeTutu:mainfrom
Olakunle567:feat/refunds-plan-events-webhook-circuit-breaker-tz-fix
Aug 26, 2026
Merged

feat: on-chain refunds, plan_changed event, webhook circuit breaker, …#717
Dev-AdeTutu merged 3 commits into
Dev-AdeTutu:mainfrom
Olakunle567:feat/refunds-plan-events-webhook-circuit-breaker-tz-fix

Conversation

@Olakunle567

@Olakunle567 Olakunle567 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

this pr closes #697
this pr closes #698
this pr closes #699
this pr closes #700

Implements four issues:

  • Contract: add admin-only refund_payment(meter_id, amount, recipient, reason). Caps the refund to what that address actually paid (net of prior refunds) via new PayerPaid/PayerRefunded tracking, decrements the meter balance and the admin's tracked provider revenue so refunded funds can't also be withdrawn, deactivates the meter if its balance hits zero, and emits a pmt_rfnd event carrying the reason for an audit trail. Adds set_refund_limit() to cap total refunds per rolling 24h window (0 = unlimited) to guard against balance-drainage bursts.

  • Contract: make_payment now emits a plan_chg event whenever a payment switches a meter's plan (e.g. Daily -> Weekly), so off-chain services can track plan migrations.

  • Backend: the webhook retry path already had the requested exponential backoff (1s/2s/4s/8s/16s, max 5 retries); added the circuit breaker from the issue's follow-up (open after 10 consecutive failures, pause 5 minutes) and enriched the failure log line with httpStatus/attemptedAt.

  • Frontend: UsageChart displayed raw UTC timestamps with no timezone indicator because dashboard/user/page.tsx pre-formatted them with toLocaleDateString() before they reached the chart, discarding time-of-day. Now the raw ISO timestamp is passed through and UsageChart formats ticks/tooltips in the viewer's local timezone with an explicit indicator (e.g. "9:00 AM" tick / "Aug 24, 9:00 AM GMT+3" tooltip).

Tests: added contract tests for refund_payment and plan_chg, a new backend integration suite for the circuit breaker, and new frontend unit tests for the timezone formatters. Verified against real suites (Rust toolchain unavailable in this sandbox, so the contract change is reviewed but not locally compiled); pre-existing unrelated failures on main were confirmed via baseline comparison and are unchanged by this branch.

Summary

Related Issue

Closes #

Type of Change

  • Bug fix
  • New feature
  • Refactor / code cleanup
  • Documentation update
  • Dependency update
  • Other:

Changes Made

How to Test

Checklist

  • Code builds without errors (cargo build / npm run build)
  • No TypeScript errors (tsc --noEmit)
  • Rust code is formatted (cargo fmt) and lint-clean (cargo clippy -- -D warnings)
  • No unintended breaking changes to existing functionality
  • PR targets the main branch and is rebased on the latest upstream

Screenshots (if applicable)

…chart tz fix

Implements four issues:

- Contract: add admin-only refund_payment(meter_id, amount, recipient, reason).
  Caps the refund to what that address actually paid (net of prior refunds)
  via new PayerPaid/PayerRefunded tracking, decrements the meter balance and
  the admin's tracked provider revenue so refunded funds can't also be
  withdrawn, deactivates the meter if its balance hits zero, and emits a
  pmt_rfnd event carrying the reason for an audit trail. Adds
  set_refund_limit() to cap total refunds per rolling 24h window (0 =
  unlimited) to guard against balance-drainage bursts.

- Contract: make_payment now emits a plan_chg event whenever a payment
  switches a meter's plan (e.g. Daily -> Weekly), so off-chain services can
  track plan migrations.

- Backend: the webhook retry path already had the requested exponential
  backoff (1s/2s/4s/8s/16s, max 5 retries); added the circuit breaker from
  the issue's follow-up (open after 10 consecutive failures, pause 5
  minutes) and enriched the failure log line with httpStatus/attemptedAt.

- Frontend: UsageChart displayed raw UTC timestamps with no timezone
  indicator because dashboard/user/page.tsx pre-formatted them with
  toLocaleDateString() before they reached the chart, discarding
  time-of-day. Now the raw ISO timestamp is passed through and UsageChart
  formats ticks/tooltips in the viewer's local timezone with an explicit
  indicator (e.g. "9:00 AM" tick / "Aug 24, 9:00 AM GMT+3" tooltip).

Tests: added contract tests for refund_payment and plan_chg, a new backend
integration suite for the circuit breaker, and new frontend unit tests for
the timezone formatters. Verified against real suites (Rust toolchain
unavailable in this sandbox, so the contract change is reviewed but not
locally compiled); pre-existing unrelated failures on main were confirmed
via baseline comparison and are unchanged by this branch.
Copilot AI lite review requested due to automatic review settings August 25, 2026 14:06
@drips-wave

drips-wave Bot commented Aug 25, 2026

Copy link
Copy Markdown

@Olakunle567 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

There are confirmed correctness/documentation/test-stability issues in the newly added frontend time formatting and contract refund event documentation that should be addressed before merge.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Implements four cross-cutting enhancements spanning the Soroban contract, backend webhook delivery, and frontend dashboard to support on-chain refunds, plan-change analytics events, resilient webhook delivery, and correct local-time usage chart rendering.

Changes:

  • Contracts: add admin-only refund_payment with per-payer paid/refunded tracking + rolling 24h refund limit; emit plan_chg on plan switch during make_payment.
  • Backend: add per-URL webhook circuit breaker (open after 10 consecutive failures; cooldown 5 minutes) and enrich failure logs.
  • Frontend: pass raw ISO timestamps through to UsageChart and format ticks/tooltips in the viewer’s local timezone with an explicit timezone indicator; add unit tests for the formatters.
File summaries
File Description
frontend/src/components/UsageChart.tsx Adds local-time tick/tooltip formatting helpers and wires them into Recharts X-axis + tooltip.
frontend/src/app/dashboard/user/page.tsx Stops pre-formatting timestamps so the chart can render accurate local times.
frontend/src/tests/UsageChart.test.tsx Adds unit tests for timestamp/date detection and local-time formatting behavior.
contracts/solar_grid/src/lib.rs Adds refund functionality + refund window limiting, tracks payer payments/refunds, and emits plan_chg on plan switches.
backend/src/lib/webhookRegistry.ts Implements an in-memory circuit breaker for webhook delivery and adds observability helpers for tests.
backend/tests/webhookRegistry.integration.test.ts Adds integration coverage for circuit breaker open/close/reset behavior.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread frontend/src/components/UsageChart.tsx
Comment thread frontend/src/__tests__/UsageChart.test.tsx
Comment thread backend/src/lib/webhookRegistry.ts
Comment thread contracts/solar_grid/src/lib.rs
@Dev-AdeTutu

Copy link
Copy Markdown
Owner

@Olakunle567 resolve conflicts

Olakunle567 and others added 2 commits August 25, 2026 23:45
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@Olakunle567 Olakunle567 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@Dev-AdeTutu
Dev-AdeTutu merged commit 04840fa into Dev-AdeTutu:main Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants