Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/mm2/mm2_api/rpc/rpc_extras.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// Provides coin-specific RPC parameter extensions for MM2 API calls.
///
/// This adapter centralizes coin-specific requirements that need to be added
/// to RPC requests, preventing duplication and keeping coin logic isolated.
class RpcExtras {
/// Default amount value for KMD rewards when claiming.
static const String kDefaultKmdRewardsAmount = '0';

/// Returns coin-specific extra parameters for withdrawal requests.
///
/// These parameters are merged into the 'params' section of the RPC request.
/// Currently handles:
/// - KMD: Adds kmd_rewards object with claimed_by_me flag
///
/// Returns an empty map if no coin-specific parameters are needed.
static Map<String, dynamic> withdrawForCoin(String coin) {
final normalizedCoin = coin.toUpperCase();

if (normalizedCoin == 'KMD') {
return {
'kmd_rewards': {
'amount': kDefaultKmdRewardsAmount,
'claimed_by_me': true,
},
};
}

return const {};
}
}
4 changes: 3 additions & 1 deletion lib/mm2/mm2_api/rpc/withdraw/withdraw_request.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:web_dex/app_config/app_config.dart';
import 'package:web_dex/mm2/mm2_api/rpc/base.dart';
import 'package:web_dex/mm2/mm2_api/rpc/rpc_extras.dart';
import 'package:web_dex/mm2/mm2_api/rpc/withdraw/fee/fee_request.dart';

class WithdrawRequestParams {
Expand Down Expand Up @@ -48,6 +49,7 @@ class WithdrawRequest
@override
Map<String, dynamic> toJson() {
final FeeRequest? fee = params.fee;
final extras = RpcExtras.withdrawForCoin(params.coin);

return <String, dynamic>{
'method': method,
Expand All @@ -60,7 +62,7 @@ class WithdrawRequest
if (params.memo != null) 'memo': params.memo,
if (params.amount != null) 'amount': params.amount,
if (fee != null) 'fee': fee.toJson(),
},
}..addAll(extras),
};
}
}
Loading