Skip to content

Commit

Permalink
create helper closure for balance error
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Jan 23, 2025
1 parent 0f08e05 commit 8d44f10
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,6 @@ impl TendermintCoin {
.map_to_mm(|e| TendermintCoinRpcError::InvalidResponse(format!("balance is not u64, err {}", e)))
}

#[allow(clippy::result_large_err)]
pub(super) fn extract_account_id_and_private_key(
&self,
withdraw_from: Option<WithdrawFrom>,
Expand Down Expand Up @@ -2159,13 +2158,15 @@ impl TendermintCoin {
request_amount: BigDecimal,
is_max: bool,
) -> Result<(u64, BigDecimal), DelegationError> {
let not_sufficient = |required| DelegationError::NotSufficientBalance {
coin: coin.ticker.clone(),
available: balance_decimal.clone(),
required,
};

if is_max {
if balance_u64 < fee_u64 {
return Err(DelegationError::NotSufficientBalance {
coin: coin.ticker.clone(),
available: balance_decimal,
required: fee_decimal,
});
return Err(not_sufficient(fee_decimal));
}

let amount_u64 = balance_u64 - fee_u64;
Expand All @@ -2174,11 +2175,7 @@ impl TendermintCoin {

let total = &request_amount + &fee_decimal;
if balance_decimal < total {
return Err(DelegationError::NotSufficientBalance {
coin: coin.ticker.clone(),
available: balance_decimal,
required: total,
});
return Err(not_sufficient(total));
}

let amount_u64 = sat_from_big_decimal(&request_amount, coin.decimals)
Expand Down

0 comments on commit 8d44f10

Please sign in to comment.