-
Notifications
You must be signed in to change notification settings - Fork 61
[DWE] Logic refactor to implement fee splitting through transfer endpoints #311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Claude finished @quetool's task in 3m 13s —— View job Code Review CompleteReviewing PR #311: DWE Logic Refactor with Transfer Endpoints Review SummaryThis PR introduces a significant feature enhancement for Deposit with Exchange (DwE) by adding transfer/swap/bridge capabilities through a new Critical Issues1. Timestamp Unit Mismatch Bug 🐛File: bool _tokenPriceIsOld(int timestampSeconds) {
final now = DateTime.now();
final timestamp = DateTime.fromMillisecondsSinceEpoch(
timestampSeconds * 1000, // ❌ Incorrectly multiplies by 1000
);
final difference = now.difference(timestamp);
return difference.inMinutes > 5;
}The method parameter is named _fetchedTokens.add((asset, DateTime.now().millisecondsSinceEpoch)); // Milliseconds!This causes the cache expiration logic to be completely broken. The timestamp gets multiplied by 1000 again, making it ~1000x too large, so cached tokens will never expire properly. Fix: Either:
2. Missing HTTP Status Code Validation 🔒File: Lines 152-168 and 181-189 don't validate HTTP status codes before parsing responses: final response = await http.post(
url.replace(queryParameters: _requiredParams),
headers: _requiredHeaders,
body: body,
);
final responseBody = response.body;
core.logger.d('[$runtimeType] -- quote response: $responseBody');
final responseData = jsonDecode(response.body) as Map<String, dynamic>; // ❌ No status checkThis could cause crashes when the API returns 4xx/5xx errors with non-JSON bodies. The code checks for Recommendation: Add status code validation: if (response.statusCode != 200) {
throw StateError('API error: ${response.statusCode} - ${response.body}');
}3. parseUnits Edge Case: Empty Integer Part
|
* test: Add comprehensive unit and integration tests for transfers service and DWE enhancements - Add unit tests for TransfersService covering: * Direct transfer quote generation (same chain/asset) * Cross-chain transfer quotes * Quote status retrieval * Exchange assets retrieval * Error handling for invalid chain IDs - Add unit tests for transfers utility functions: * parseUnits() - 11 test cases covering various scenarios * scaleAmountToBaseUnits() - 12 test cases including edge cases * DEAD_ADDRESSES_BY_NAMESPACE constant validation - Add unit tests for quote models: * QuoteStatus enum conversion and properties * QuoteFeeExtension formatting * QuoteExtension formatting * QuoteStepExtension type checking - Add unit tests for quote params and results: * GetQuoteParams serialization/deserialization * GetTransfersQuoteParams with optional fields * GetQuoteStatusParams * GetQuoteStatusResult and GetExchangeAssetsResult - Add integration tests for DWEService.loopOnTransferStatusCheck(): * Success status handling * Waiting/pending status polling behavior * Failure status handling * Timeout after max attempts * Stop checking functionality * Concurrent loop prevention * API error handling * Correct parameter passing All tests follow existing patterns using mockito and flutter_test. All linter errors have been resolved. * Tests improvements with AI
Description
This PR implements Deposit with Exchange (DwE) functionality with a new Transfer endpoint integration, enabling users to swap/bridge tokens when needed during deposits. The implementation includes fee splitting support and a refactored DWE service architecture.
Version:
1.8.0-beta01Key Changes
1. New Transfers Service
TransfersService(packages/reown_appkit/lib/modal/services/transfers/transfers_service.dart)/appkit/v1/transfers/quoteendpointITransfersServiceinterface with methods:getQuote()- Generates quotes for transfers/swaps/bridgesgetQuoteStatus()- Checks status of transfer quotesgetExchangeAssets()- Retrieves available assets from exchanges2. Quote Models
Quote- Main quote container with origin, destination, fees, steps, and timingQuoteFee- Fee breakdown with id, label, amount, and currencyQuoteAmount- Amount representation with value and currencyQuoteStep- Union type for deposit and transaction stepsQuoteStatus- Enum for tracking status (waiting, pending, success, submitted, failure, refund, timeout)QuoteType- Enum for quote types (direct-transfer)isError,isSuccess)3. Refactored DWE Service
DWEService(packages/reown_appkit/lib/modal/services/dwe_service/dwe_service.dart)TransfersServicevia dependency injectionselectedAsset→depositAssetfor claritydepositAmountInUSDanddepositAmountInAssetvalue notifiersloopOnTransferStatusCheckmethod for transfer status pollingloopOnDepositStatusCheckto useQuoteStatusenum instead of string statusfilterByNetworkanddepositAssetButtonoptionsconfiguredRecipientsmap per namespace4. New UI Pages
Exchange Assets Selector Page (
packages/reown_appkit/lib/modal/pages/public/dwe/exchange_assets_selector_page.dart)Payment Process Page (
packages/reown_appkit/lib/modal/pages/public/dwe/payment_process_page.dart)5. Updated Base Implementation
AppKit Base: Enhanced to support transfer quotes
AppKitBaseImplto integrate transfer serviceExchange Service: Updated to work with new transfer flow
Asset Models: Extended to support transfer operations
6. Version & Dependencies
1.8.0-beta01pubspec.yamlfilesTechnical Details
Transfer Flow
getExchangeAssetsgetQuote:loopOnTransferStatusCheckorloopOnDepositStatusCheckFee Splitting
id- Unique identifier for fee typelabel- Human-readable label (e.g., "Service Fee")amount- Fee amount in base unitscurrency- Currency/asset for the feeDirect Transfer Support
QuoteType.directTransferfor identificationStatus Management
QuoteStatusenum for both deposit and transfer statusFiles Changed
transfersservice directory:transfers_service.dart- Main service implementationi_transfers_service.dart- Service interfacequote_models.dart- Quote data modelsquote_params.dart- Request parameter modelsquote_results.dart- Response result modelstransfers_utils.dart- Utility functionsBreaking Changes
configDepositmethod signature updated:preselectedRecipientparameterfilterByNetworkanddepositAssetButtonparametersconfiguredRecipientsfrom single string to map per namespaceTesting Considerations
How Has This Been Tested?
Due Dilligence