Skip to content

Commit

Permalink
Fix balance
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Nov 16, 2023
1 parent 0b24cec commit c1e988c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
42 changes: 17 additions & 25 deletions sdk/src/wallet/operations/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ where
if !wallet_data.locked_outputs.contains(output_id) {
total_storage_cost += storage_cost;
}
// Add native tokens
total_native_tokens.add_native_tokens(output.native_tokens().clone())?;

let account_id = output.account_id_non_null(output_id);
balance.accounts.push(account_id);
Expand All @@ -87,8 +85,11 @@ where
if !wallet_data.locked_outputs.contains(output_id) {
total_storage_cost += storage_cost;
}
// Add native tokens
total_native_tokens.add_native_tokens(output.native_tokens().clone())?;

// Add native token
if let Some(native_token) = output.native_token() {
total_native_tokens.add_native_token(native_token.clone())?;
}

balance.foundries.push(output.id());
}
Expand All @@ -112,12 +113,7 @@ where
// Add storage deposit
if output.is_basic() {
balance.required_storage_deposit.basic += storage_cost;
if output
.native_tokens()
.map(|native_tokens| !native_tokens.is_empty())
.unwrap_or(false)
&& !wallet_data.locked_outputs.contains(output_id)
{
if output.native_token().is_some() && !wallet_data.locked_outputs.contains(output_id) {
total_storage_cost += storage_cost;
}
} else if output.is_nft() {
Expand All @@ -127,9 +123,9 @@ where
}
}

// Add native tokens
if let Some(native_tokens) = output.native_tokens() {
total_native_tokens.add_native_tokens(native_tokens.clone())?;
// Add native token
if let Some(native_token) = output.native_token() {
total_native_tokens.add_native_token(native_token.clone())?;
}
} else {
// if we have multiple unlock conditions for basic or nft outputs, then we can't
Expand Down Expand Up @@ -187,13 +183,9 @@ where
// Add storage deposit
if output.is_basic() {
balance.required_storage_deposit.basic += storage_cost;
// Amount for basic outputs isn't added to total storage cost if there aren't
// native tokens, since we can
// spend it without burning.
if output
.native_tokens()
.map(|native_tokens| !native_tokens.is_empty())
.unwrap_or(false)
// Amount for basic outputs isn't added to total storage cost if there aren't native
// tokens, since we can spend it without burning.
if output.native_token().is_some()
&& !wallet_data.locked_outputs.contains(output_id)
{
total_storage_cost += storage_cost;
Expand All @@ -205,9 +197,9 @@ where
}
}

// Add native tokens
if let Some(native_tokens) = output.native_tokens() {
total_native_tokens.add_native_tokens(native_tokens.clone())?;
// Add native token
if let Some(native_token) = output.native_token() {
total_native_tokens.add_native_token(native_token.clone())?;
}
} else {
// only add outputs that can't be locked now and at any point in the future
Expand Down Expand Up @@ -267,8 +259,8 @@ where
// Only check outputs that are in this network
if output_data.network_id == network_id {
locked_amount += output_data.output.amount();
if let Some(native_tokens) = output_data.output.native_tokens() {
locked_native_tokens.add_native_tokens(native_tokens.clone())?;
if let Some(native_token) = output_data.output.native_token() {
locked_native_tokens.add_native_token(native_token.clone())?;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use instant::Instant;
use packable::bounded::TryIntoBoundedU16Error;

#[cfg(feature = "events")]
// TODO why is this not used anymore? Are we not triggering an event anymore?
use crate::wallet::events::types::{AddressData, TransactionProgressEvent, WalletEvent};
use crate::{
client::{api::PreparedTransactionData, secret::SecretManage},
Expand Down

0 comments on commit c1e988c

Please sign in to comment.