feat: add on-chain reputation API and driver profile display#614
feat: add on-chain reputation API and driver profile display#614deepsikha-dash wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds end-to-end on-chain reputation score display to the driver profile. A new ChangesOn-Chain Reputation Integration
Sequence Diagram(s)sequenceDiagram
participant Driver as Driver App
participant Route as GET /:driverId/reputation
participant DB as Supabase driver_details
participant Service as getDriverReputation
participant Contract as reputationContract
Driver->>Route: HTTP GET with Supabase auth token
Route->>Route: Validate driverId ownership
Route->>DB: SELECT rating, polygon_wallet_address
DB-->>Route: { supabaseRating, walletAddress }
alt walletAddress present
Route->>Service: getDriverReputation(walletAddress)
Service->>Contract: getReputation(walletAddress)
Contract-->>Service: score or error
Service-->>Route: score string or null
else walletAddress null
Route-->>Route: onChainScore = null
end
Route-->>Driver: { driverId, walletAddress, onChainScore, supabaseRating }
alt success
Driver->>Driver: setState with scores
else non-200 or exception
Driver->>Driver: setState(_reputationUnavailable = true)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
🎉 Thank you for your contribution! Your pull request has been received and will be reviewed shortly. If you enjoy the project, please consider giving the repository a ⭐. You can also follow my GitHub profile to stay updated on future open-source projects. Thanks for being part of the community! 🚀 |
There was a problem hiding this comment.
Actionable comments posted: 6
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/driver/lib/screens/profile_screen.dart`:
- Around line 95-100: The code currently ignores the walletAddress field
returned by the backend when parsing user data and renders a generic `--` for
null scores regardless of whether the wallet is connected. To differentiate
between wallet-not-connected and other unavailable states, capture the
walletAddress value from the data object during the same data parsing where
_supabaseRating and _onChainScore are extracted, store it in an instance
variable, and then use this walletAddress value in the UI rendering logic
(referenced at lines 828-853) to display distinct messages or states based on
whether walletAddress is present or null versus whether the scores themselves
are null.
- Around line 103-106: The setState call in the non-200 response branch (where
_reputationUnavailable is set to true) is not guarded with a mounted check,
which can cause errors if setState is called after the widget is disposed. Wrap
the setState block with an if (mounted) condition to ensure the state is only
updated when the widget is still mounted and active.
- Around line 79-81: The Uri.parse() call for the reputation endpoint is using a
hardcoded localhost URL instead of the configured API base URL. Replace the
hardcoded 'http://localhost:5000' with the appropriate API base URL constant or
variable that should be used throughout the application for all API calls,
maintaining consistency with how other endpoints are configured in the codebase.
In `@backend/api/src/routes/driverRoutes.js`:
- Around line 324-340: The endpoint lacks an authorization check to prevent
drivers from accessing other drivers' data. After extracting driverId from
req.params at line 324, add a check that verifies driverId matches req.user.id.
If they do not match, return a 403 Forbidden response immediately, before
proceeding with the supabase query that fetches driver_details. This ensures
each driver can only retrieve their own reputation data and prevents
cross-driver data exposure.
In `@backend/api/src/services/reputation.js`:
- Around line 92-93: The call to reputationContract.getReputation(walletAddress)
lacks a timeout guard, which can cause the request to stall indefinitely if the
RPC hangs. Wrap the getReputation call with a timeout mechanism (such as
Promise.race with a setTimeout) to ensure that if the RPC operation takes longer
than a defined threshold (e.g., 5 seconds), the promise rejects or resolves with
null instead of hanging indefinitely. This allows the request path to degrade
gracefully rather than blocking.
- Around line 93-95: The Number(score) conversion on line 94 silently corrupts
large BigInt values that exceed Number.MAX_SAFE_INTEGER (2^53 - 1) since
ethers.js v6 returns BigInt for uint256 contract calls. Add a guard check before
converting the score returned from
reputationContract.getReputation(walletAddress) to ensure the BigInt value does
not exceed the safe integer limit, and throw an error or handle appropriately if
it does exceed the safe range. Only proceed with the Number conversion after
validating the value is within safe bounds.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 3f48c580-156e-46d1-8552-76366ca89e68
📒 Files selected for processing (3)
apps/driver/lib/screens/profile_screen.dartbackend/api/src/routes/driverRoutes.jsbackend/api/src/services/reputation.js
9d11029 to
1d33dae
Compare
|
@deepsikha-dash — Thanks for working on this! I reviewed the PR against issue #577 and checked the actual files in the repository. Unfortunately, the changes described in the summary do not appear to be present in the codebase. Findings
It looks like the force-push ( Please also verify the following issue requirements
Happy to re-review once the implementation is pushed. 🙂 |
Summary
Completes the driver reputation integration by exposing on-chain reputation data through an API endpoint and displaying both blockchain and platform ratings in the driver profile.
Changes
backend/api/src/services/reputation.js(updated)Added
getDriverReputation():nullwhen the reputation contract is unavailable.reputationContract.getReputation(walletAddress).backend/api/src/routes/driverRoutes.js(updated)Added:
Features:
ratingandpolygon_wallet_addressfrom Supabase.apps/driver/lib/screens/profile_screen.dart(updated)Added reputation UI and API integration:
Acceptance Criteria
GET /api/drivers/:driverId/reputationgetDriverReputation()onChainScore: nullprofile_screen.dartTest Results
Normal Case
Missing Wallet
onChainScoreremainsnull.Blockchain Failure
Flutter UI
Closes #577
Summary by CodeRabbit