diff --git a/lib/mm2/mm2_api/rpc/rpc_extras.dart b/lib/mm2/mm2_api/rpc/rpc_extras.dart new file mode 100644 index 0000000000..4b4d71eb7f --- /dev/null +++ b/lib/mm2/mm2_api/rpc/rpc_extras.dart @@ -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 withdrawForCoin(String coin) { + final normalizedCoin = coin.toUpperCase(); + + if (normalizedCoin == 'KMD') { + return { + 'kmd_rewards': { + 'amount': kDefaultKmdRewardsAmount, + 'claimed_by_me': true, + }, + }; + } + + return const {}; + } +} diff --git a/lib/mm2/mm2_api/rpc/withdraw/withdraw_request.dart b/lib/mm2/mm2_api/rpc/withdraw/withdraw_request.dart index 3871809456..60c8351382 100644 --- a/lib/mm2/mm2_api/rpc/withdraw/withdraw_request.dart +++ b/lib/mm2/mm2_api/rpc/withdraw/withdraw_request.dart @@ -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 { @@ -48,6 +49,7 @@ class WithdrawRequest @override Map toJson() { final FeeRequest? fee = params.fee; + final extras = RpcExtras.withdrawForCoin(params.coin); return { 'method': method, @@ -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), }; } }