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

feat: don't permit trying to send interactive transfers from hardware devices #6458

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
13 changes: 11 additions & 2 deletions applications/minotari_console_wallet/src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use minotari_wallet::{error::WalletError, util::wallet_identity::WalletIdentity, WalletConfig, WalletSqlite};
use tari_common::exit_codes::ExitError;
use tari_common::exit_codes::{ExitCode, ExitError};
use tari_comms::peer_manager::Peer;
use tokio::runtime::Handle;
use tui::{
Expand Down Expand Up @@ -102,7 +102,16 @@ impl<B: Backend> App<B> {

let tabs = TabsContainer::<B>::new(title.clone())
.add("Transactions".into(), Box::new(TransactionsTab::new()))
.add("Send".into(), Box::new(SendTab::new(&app_state)))
.add(
"Send".into(),
Box::new(SendTab::new(
&app_state,
app_state
.get_wallet_type()
.await
.map_err(|e| ExitError::new(ExitCode::WalletError, e))?,
)),
)
.add("Receive".into(), Box::new(ReceiveTab::new()))
.add("Burn".into(), Box::new(BurnTab::new(&app_state)))
.add("Templates".into(), Box::new(RegisterTemplateTab::new(&app_state)))
Expand Down
72 changes: 44 additions & 28 deletions applications/minotari_console_wallet/src/ui/components/send_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use log::*;
use minotari_wallet::output_manager_service::UtxoSelectionCriteria;
use tari_common_types::wallet_types::WalletType;
use tari_core::transactions::tari_amount::MicroMinotari;
use tari_utilities::hex::Hex;
use tokio::{runtime::Handle, sync::watch};
Expand Down Expand Up @@ -41,10 +42,11 @@ pub struct SendTab {
confirmation_dialog: Option<ConfirmationDialogType>,
selected_unique_id: Option<Vec<u8>>,
table_state: TableState,
wallet_type: WalletType,
}

impl SendTab {
pub fn new(app_state: &AppState) -> Self {
pub fn new(app_state: &AppState, wallet_type: WalletType) -> Self {
Self {
balance: Balance::new(),
send_input_mode: SendInputMode::None,
Expand All @@ -62,6 +64,7 @@ impl SendTab {
confirmation_dialog: None,
selected_unique_id: None,
table_state: TableState::default(),
wallet_type,
}
}

Expand Down Expand Up @@ -89,36 +92,43 @@ impl SendTab {
)
.margin(1)
.split(area);
let instructions = Paragraph::new(vec![
Spans::from(vec![
Span::raw("Press "),
Span::styled("T", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Span::styled("To", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" field, "),
Span::styled("A", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Span::styled("Amount/Token, ", Style::default().add_modifier(Modifier::BOLD)),
Span::styled("F", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Span::styled("Fee-Per-Gram", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" field, "),
Span::styled("C", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to select a contact, "),
Span::styled("P", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Span::styled("Payment-id", Style::default().add_modifier(Modifier::BOLD)),
]),
Spans::from(vec![
let mut instructions = vec![Spans::from(vec![
Span::raw("Press "),
Span::styled("T", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Span::styled("To", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" field, "),
Span::styled("A", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Span::styled("Amount/Token, ", Style::default().add_modifier(Modifier::BOLD)),
Span::styled("F", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Span::styled("Fee-Per-Gram", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" field, "),
Span::styled("C", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to select a contact, "),
Span::styled("P", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Span::styled("Payment-id", Style::default().add_modifier(Modifier::BOLD)),
])];

let mut send_instructions = vec![];
if let WalletType::DerivedKeys | WalletType::ProvidedKeys(_) = self.wallet_type {
send_instructions.append(&mut vec![
Span::raw("Press "),
Span::styled("S", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to send a normal transaction, "),
Span::styled("O", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to send a one-sided transaction"),
]),
])
.wrap(Wrap { trim: false })
.block(Block::default());
]);
}
send_instructions.append(&mut vec![
Span::styled("O", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to send a one-sided transaction"),
]);
instructions.push(Spans::from(send_instructions));

let instructions = Paragraph::new(instructions)
.wrap(Wrap { trim: false })
.block(Block::default());
f.render_widget(instructions, vert_chunks[0]);

let to_input = Paragraph::new(self.to_field.as_ref())
Expand Down Expand Up @@ -574,6 +584,12 @@ impl<B: Backend> Component<B> for SendTab {
'm' => self.send_input_mode = SendInputMode::Message,
'p' => self.send_input_mode = SendInputMode::PaymentId,
's' | 'o' => {
if let WalletType::Ledger(_) = self.wallet_type {
// If we're a ledger wallet, then ignore interactive send requests
if c == 's' {
return;
}
}
if self.to_field.is_empty() {
self.error_message =
Some("Destination Tari Address/Emoji ID\nPress Enter to continue.".to_string());
Expand Down
14 changes: 14 additions & 0 deletions applications/minotari_console_wallet/src/ui/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use tari_common_types::{
tari_address::TariAddress,
transaction::{TransactionDirection, TransactionStatus, TxId},
types::PublicKey,
wallet_types::WalletType,
};
use tari_comms::{
connectivity::ConnectivityEventRx,
Expand Down Expand Up @@ -650,6 +651,11 @@ impl AppState {
pub async fn get_network(&self) -> Network {
self.inner.read().await.get_network()
}

pub async fn get_wallet_type(&self) -> Result<WalletType, UiError> {
let inner = self.inner.write().await;
inner.get_wallet_type()
}
}
pub struct AppStateInner {
updated: bool,
Expand All @@ -673,6 +679,14 @@ impl AppStateInner {
}
}

pub fn get_wallet_type(&self) -> Result<WalletType, UiError> {
self.wallet
.db
.get_wallet_type()
.map_err(UiError::WalletStorageError)
.and_then(|opt| opt.ok_or(UiError::WalletTypeError))
}

pub fn get_network(&self) -> Network {
self.wallet.network.as_network()
}
Expand Down
2 changes: 2 additions & 0 deletions applications/minotari_console_wallet/src/ui/ui_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub enum UiError {
SendError(String),
#[error("Transaction error: `{0}`")]
TransactionError(String),
#[error("Couldn't read wallet type")]
WalletTypeError,
}

impl From<HexError> for UiError {
Expand Down
Loading