@@ -100,7 +100,6 @@ import { LOVELACES_PER_ADA } from '../config/numbersConfig';
100100import {
101101 SMASH_SERVER_STATUSES ,
102102 SMASH_SERVERS_LIST ,
103- DELEGATION_DEPOSIT ,
104103 MIN_REWARDS_REDEMPTION_RECEIVER_BALANCE ,
105104 REWARDS_REDEMPTION_FEE_CALCULATION_AMOUNT ,
106105} from '../config/stakingConfig' ;
@@ -891,7 +890,6 @@ export default class AdaApi {
891890 parameters : filterLogData ( request ) ,
892891 } ) ;
893892 const { walletId, payments, delegation } = request ;
894-
895893 try {
896894 let data ;
897895 if ( delegation ) {
@@ -925,13 +923,15 @@ export default class AdaApi {
925923 const outputs = concat ( response . outputs , response . change ) ;
926924
927925 // Calculate fee from inputs and outputs
928- let totalInputs = 0 ;
929- let totalOutputs = 0 ;
930926 const inputsData = [ ] ;
931927 const outputsData = [ ] ;
932928 const certificatesData = [ ] ;
929+ let totalInputs = new BigNumber ( 0 ) ;
930+ let totalOutputs = new BigNumber ( 0 ) ;
931+
933932 map ( response . inputs , ( input ) => {
934- totalInputs += input . amount . quantity ;
933+ const inputAmount = new BigNumber ( input . amount . quantity ) ;
934+ totalInputs = totalInputs . plus ( inputAmount ) ;
935935 const inputData = {
936936 address : input . address ,
937937 amount : input . amount ,
@@ -941,15 +941,18 @@ export default class AdaApi {
941941 } ;
942942 inputsData . push ( inputData ) ;
943943 } ) ;
944+
944945 map ( outputs , ( output ) => {
945- totalOutputs += output . amount . quantity ;
946+ const outputAmount = new BigNumber ( output . amount . quantity ) ;
947+ totalOutputs = totalOutputs . plus ( outputAmount ) ;
946948 const outputData = {
947949 address : output . address ,
948950 amount : output . amount ,
949951 derivationPath : output . derivation_path || null ,
950952 } ;
951953 outputsData . push ( outputData ) ;
952954 } ) ;
955+
953956 if ( response . certificates ) {
954957 map ( response . certificates , ( certificate ) => {
955958 const certificateData = {
@@ -960,28 +963,21 @@ export default class AdaApi {
960963 certificatesData . push ( certificateData ) ;
961964 } ) ;
962965 }
963- const fee = new BigNumber ( totalInputs - totalOutputs ) . dividedBy (
964- LOVELACES_PER_ADA
965- ) ;
966966
967- let transactionFee ;
968- if ( delegation && delegation . delegationAction ) {
969- const delegationDeposit = new BigNumber ( DELEGATION_DEPOSIT ) ;
970- const isDepositIncluded = fee . gt ( delegationDeposit ) ;
971- transactionFee = isDepositIncluded ? fee . minus ( delegationDeposit ) : fee ;
972- } else {
973- transactionFee = fee ;
974- }
967+ const deposits = map ( response . deposits , ( deposit ) => deposit . quantity ) ;
968+ const totalDeposits = deposits . length
969+ ? BigNumber . sum . apply ( null , deposits )
970+ : new BigNumber ( 0 ) ;
971+ const feeWithDeposits = totalInputs . minus ( totalOutputs ) ;
972+ const fee = feeWithDeposits . minus ( totalDeposits ) ;
975973
976- // On first wallet delegation deposit is included in fee
977974 const extendedResponse = {
978975 inputs : inputsData ,
979976 outputs : outputsData ,
980977 certificates : certificatesData ,
981- feeWithDelegationDeposit : fee ,
982- fee : transactionFee ,
978+ feeWithDeposits : feeWithDeposits . dividedBy ( LOVELACES_PER_ADA ) ,
979+ fee : fee . dividedBy ( LOVELACES_PER_ADA ) ,
983980 } ;
984-
985981 logger . debug ( 'AdaApi::selectCoins success' , { extendedResponse } ) ;
986982 return extendedResponse ;
987983 } catch ( error ) {
0 commit comments