feat(credit): implement subscription credit system and account balance (#719)#797
Open
Yinklekay wants to merge 2 commits into
Open
feat(credit): implement subscription credit system and account balance (#719)#797Yinklekay wants to merge 2 commits into
Yinklekay wants to merge 2 commits into
Conversation
Smartdevs17#719) Adds an end-to-end subscription credit system mirroring the subtrackr-credit Soroban contract and the mobile AccountCredit ledger store, with: - per-user credit balances (never-negative, oldest-first consumption) - applyCreditToCharge integration at invoice close - paginated audit trail (filterable by time and entry kind) - Credit analytics: getAccountSummary, getGlobalBreakdown, getUsageTrend, getExpiryForecast, topAccountsByBalance - expiration management: setExpirationPolicy + expireAccount / expireAll mutations on a clone-first projection - bidirectional credit transfer - prepayment wallets (createWallet / deposit / withdraw / drawdown) - CSV/JSON credit reporting via printReport / exportReport Fixes a pre-existing compile error in app/stores/creditStore.ts. Wires a 4-tab credit balance dashboard into the mobile analytics store. Surfaces projected-vs-committed outstanding liability so finance dashboards can show the on-chain lag. Closes Smartdevs17#719 Backend jest: 36/36 passing. Root tsc clean. Lint clean (4 style warnings on existing Array<T> usage; safe to leave).
|
@Yinklekay 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! 🚀 |
Owner
|
merge conflicts |
Author
|
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request: Implement subscription credit system and account balance (Closes #719)
Summary
Adds a complete, end-to-end subscription credit system that mirrors the existing
subtrackr-creditSoroban contract shape and the mobileAccountCreditledger store, exposing:after_secspolicy and explicitexpireAccount/expireAllmutations that produce auditable ledger entries.Closes #719
Acceptance Criteria
creditService.getBalance,getAccount; mobile + web stores unchanged.applyCreditToCharge(integrates at invoice close).getAuditTrailwith time/kind filters +printReporthistory section.getGlobalBreakdown,getUsageTrend,getExpiryForecast,getAccountSummary,topAccountsByBalance; mobile 4-tabCreditBalanceScreen.tsx+app/stores/analyticsStore.tssnapshot.setExpirationPolicy,expireAccount,expireAll,getExpiryForecast(filters past-due lots).transferCreditwith sender/recipient ledger entries.printReport+exportReport(..., 'csv' | 'json').Technical Scope
A backend/services/billing/creditTypes.ts (new)
A backend/services/billing/creditService.ts (new)
A backend/services/billing/tests/creditService.test.ts (new — 36 tests)
M backend/services/billing/interfaces.ts (added ICreditService)
M backend/services/billing/errors.ts (added credit error codes + factories)
M backend/services/billing/index.ts (exported CreditService / types / helpers)
M app/stores/creditStore.ts (fixed pre-existing compile error; behaviour-preserving rewrite)
M app/screens/CreditBalanceScreen.tsx (rebuilt: 4-tab analytics dashboard UI)
M app/stores/analyticsStore.ts (added CreditMetricSnapshot + aggregation)
Architecture
projectExpiry(). Mutating expiry surface is explicit (expireAccount/expireAll).applyCreditToCharge.Test Plan
npx jest -c jest.backend.config.js backend/services/billing/__tests__/creditService.test.ts).tsc --noEmit: clean.tsc --noEmit -p tsconfig.json: clean for the credit files.eslint --no-ignoreon modified files: 0 errors (4 Array style warnings).Risks / Notes
ICreditServiceinterface makes a DB-backed repository a drop-in replacement.getUsageTrend(a "now" signal). A future per-day historical expiry trend would be a separateprojectExpiryTrendhelper.contracts/credit/src/lib.rs) already implements the same operation set and is not modified by this PR.Reviewer Checklist
app/stores/creditStore.tsrewrite preserves the 8 existing tests.creditServiceis class+instance withICreditServicere-exported.BillingErrorwith appropriate codes.CreditBucketBreakdownreturns both projected and committed outstanding liability.