Skip to content
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

fix: better error #17

Merged
merged 1 commit into from
Mar 21, 2023
Merged
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
14 changes: 10 additions & 4 deletions contracts/credits/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use ::cw20_base::ContractError as Cw20ContractError;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, BankMsg, Binary, Coin, Deps, DepsMut, Env, MessageInfo, Response, StdResult, Uint128,
to_binary, BankMsg, Binary, Coin, Deps, DepsMut, Env, MessageInfo, Response, StdError,
StdResult, Uint128,
};
use cw2::set_contract_version;
use cw20::BalanceResponse;
Expand Down Expand Up @@ -504,9 +505,14 @@ fn query_withdrawable_amount(
&allocation.schedule,
env.block.time.seconds(),
)?;
// because we have lockdrop rewards that skip vesting, we can get withdrawable amount greater than the current balance
// so we need to withdraw not more than the current balance
let actual_balance = BALANCES.load(deps.storage, &owner)?;
// // because we have lockdrop rewards that skip vesting, we can get withdrawable amount greater than the current balance
// // so we need to withdraw not more than the current balance
let actual_balance =
BALANCES
.may_load(deps.storage, &owner)?
.ok_or_else(|| StdError::GenericErr {
msg: "No balance".to_string(),
})?;
let amount = max_withdrawable_amount.min(actual_balance);

Ok(WithdrawableAmountResponse { amount })
Expand Down