Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/backend_task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,9 @@ impl AppContext {
seed_hash,
inputs,
outputs,
fee_payer_index,
} => {
self.transfer_platform_credits(seed_hash, inputs, outputs)
self.transfer_platform_credits(seed_hash, inputs, outputs, fee_payer_index)
.await
}
WalletTask::FundPlatformAddressFromAssetLock {
Expand All @@ -397,12 +398,14 @@ impl AppContext {
inputs,
output_script,
core_fee_per_byte,
fee_payer_index,
} => {
self.withdraw_from_platform_address(
seed_hash,
inputs,
output_script,
core_fee_per_byte,
fee_payer_index,
)
.await
}
Expand Down
5 changes: 5 additions & 0 deletions src/backend_task/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub enum WalletTask {
inputs: BTreeMap<PlatformAddress, Credits>,
/// Destination addresses with amounts
outputs: BTreeMap<PlatformAddress, Credits>,
/// Index of the input to deduct fees from (in BTreeMap order).
/// Should be the input with the highest balance to ensure sufficient funds for fees.
fee_payer_index: u16,
},
/// Fund Platform addresses from an asset lock
FundPlatformAddressFromAssetLock {
Expand All @@ -62,6 +65,8 @@ pub enum WalletTask {
output_script: CoreScript,
/// Core fee per byte
core_fee_per_byte: u32,
/// Index of the input to deduct fees from (in BTreeMap order).
fee_payer_index: u16,
},
/// Fund a platform address directly from wallet UTXOs
/// Creates asset lock, broadcasts, waits for proof, then funds platform address
Expand Down
17 changes: 15 additions & 2 deletions src/backend_task/wallet/transfer_platform_credits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ impl AppContext {
seed_hash: WalletSeedHash,
inputs: BTreeMap<PlatformAddress, Credits>,
outputs: BTreeMap<PlatformAddress, Credits>,
fee_payer_index: u16,
) -> Result<BackendTaskSuccessResult, String> {
use dash_sdk::dpp::address_funds::AddressFundsFeeStrategyStep;
use dash_sdk::platform::transition::transfer_address_funds::TransferAddressFunds;
Expand All @@ -31,8 +32,20 @@ impl AppContext {
(wallet, sdk)
};

// Deduct fee from the first input address (not output, which may be too small)
let fee_strategy = vec![AddressFundsFeeStrategyStep::DeductFromInput(0)];
// Deduct fee from the specified input address (should be the one with highest balance).
let fee_strategy = vec![AddressFundsFeeStrategyStep::DeductFromInput(
fee_payer_index,
)];

tracing::info!(
"transfer_platform_credits: fee_payer_index={}, inputs={}, outputs={}",
fee_payer_index,
inputs.len(),
outputs.len()
);
for (idx, (addr, amount)) in inputs.iter().enumerate() {
tracing::info!(" Input {}: {:?} -> {}", idx, addr, amount);
}

// Use the SDK to transfer - returns proof-verified updated address infos
let address_infos = sdk
Expand Down
7 changes: 5 additions & 2 deletions src/backend_task/wallet/withdraw_from_platform_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl AppContext {
inputs: BTreeMap<PlatformAddress, Credits>,
output_script: CoreScript,
core_fee_per_byte: u32,
fee_payer_index: u16,
) -> Result<BackendTaskSuccessResult, String> {
use dash_sdk::dpp::address_funds::AddressFundsFeeStrategyStep;
use dash_sdk::dpp::withdrawal::Pooling;
Expand All @@ -35,8 +36,10 @@ impl AppContext {
(wallet, sdk)
};

// Simple fee strategy: deduct from first input
let fee_strategy = vec![AddressFundsFeeStrategyStep::DeductFromInput(0)];
// Deduct fee from the specified input (should be the one with highest balance)
let fee_strategy = vec![AddressFundsFeeStrategyStep::DeductFromInput(
fee_payer_index,
)];

// Use the SDK to withdraw
let _result = sdk
Expand Down
31 changes: 26 additions & 5 deletions src/ui/components/amount_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ pub struct AmountInput {
show_validation_errors: bool,
// When true, we enforce that the input was changed, even if text edit didn't change.
changed: bool,
/// Optional hint explaining why the maximum is set (e.g., "fees reserved")
max_exceeded_hint: Option<String>,
}

impl AmountInput {
Expand Down Expand Up @@ -120,6 +122,7 @@ impl AmountInput {
desired_width: None,
show_validation_errors: true, // Default to showing validation errors
changed: true, // Start as changed to force initial validation
max_exceeded_hint: None,
}
}

Expand Down Expand Up @@ -216,6 +219,20 @@ impl AmountInput {
self
}

/// Sets a hint explaining why the maximum is limited (e.g., "fees reserved").
/// This hint is appended to the error message when the max is exceeded.
pub fn with_max_exceeded_hint(mut self, hint: impl Into<String>) -> Self {
self.max_exceeded_hint = Some(hint.into());
self
}

/// Sets a hint explaining why the maximum is limited (mutable reference version).
/// Use this for dynamic configuration when the hint changes at runtime.
pub fn set_max_exceeded_hint(&mut self, hint: Option<String>) -> &mut Self {
self.max_exceeded_hint = hint;
self
}

/// Sets the minimum amount allowed. Defaults to 1 (must be greater than zero).
/// Set to Some(0) to allow zero amounts, or None to disable minimum validation.
pub fn with_min_amount(mut self, min_amount: Option<Credits>) -> Self {
Expand Down Expand Up @@ -279,11 +296,15 @@ impl AmountInput {
if let Some(max_amount) = self.max_amount
&& amount.value() > max_amount
{
return Err(format!(
"Amount {} exceeds allowed maximum {}",
amount,
Amount::new(max_amount, self.decimal_places)
));
let max_formatted = Amount::new(max_amount, self.decimal_places);
return Err(if let Some(ref hint) = self.max_exceeded_hint {
format!(
"Amount {} exceeds maximum {}. {}",
amount, max_formatted, hint
)
} else {
format!("Amount {} exceeds maximum {}", amount, max_formatted)
});
}

// Check if amount is below minimum
Expand Down
Loading
Loading