Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use color_eyre::owo_colors::OwoColorize;
use inquire::{CustomType, Select};

use crate::commands::account::MIN_ALLOWED_TOP_LEVEL_ACCOUNT_LENGTH;
Expand Down Expand Up @@ -63,19 +64,28 @@ impl NewAccount {
No,
}
let select_choose_input =
Select::new("\nDo you want to check the existence of the specified account so that you dont waste tokens with sending a transaction that won't succeed?",
Select::new("Do you want to check the existence of the specified account so that you don't waste tokens with sending a transaction that won't succeed?",
vec![ConfirmOptions::Yes{account_id: new_account_id.clone()}, ConfirmOptions::No],
)
.prompt()?;
if let ConfirmOptions::Yes { account_id } = select_choose_input {
let network = crate::common::find_network_where_account_exist(
context,
account_id.clone().into(),
)?;
if let Some(network_config) = network {
eprintln!(
"\nHeads up! You will only waste tokens if you proceed creating <{}> account on <{}> as the account already exists.",
);

if let Err(crate::common::AccountStateError::Skip) = network {
tracing::warn!(
"It was not checked whether <{account_id}> was available on the network."
);
return Ok(Some(new_account_id));
};

if let Some(network_config) = network.map_err(color_eyre::Report::msg)? {
tracing::warn!("{}", format!(
"Heads up! You will only waste tokens if you proceed creating <{}> account on <{}> as the account already exists.",
&account_id, network_config.network_name
).red()
);
if !crate::common::ask_if_different_account_id_wanted()? {
return Ok(Some(account_id));
Expand All @@ -84,8 +94,8 @@ impl NewAccount {
< MIN_ALLOWED_TOP_LEVEL_ACCOUNT_LENGTH
&& account_id.0.is_top_level()
{
eprintln!(
"\nAccount <{}> has <{}> character count. Only the registrar account can create new top level accounts that are shorter than {} characters. Read more about it in nomicon: https://nomicon.io/DataStructures/Account#top-level-accounts",
tracing::warn!(
"Account <{}> has <{}> character count. Only the registrar account can create new top level accounts that are shorter than {} characters. Read more about it in nomicon: https://nomicon.io/DataStructures/Account#top-level-accounts",
&account_id,
&account_id.0.as_str().chars().count(),
MIN_ALLOWED_TOP_LEVEL_ACCOUNT_LENGTH,
Expand All @@ -94,22 +104,36 @@ impl NewAccount {
return Ok(Some(account_id));
};
} else {
tracing::info!("{}", format!("The account <{}> does not exist on [{}] networks. So, you can create this account.",
account_id,
context.config.network_names().join(", ")).green()
);
let parent_account_id =
account_id.clone().get_parent_account_id_from_sub_account();
if !near_primitives::types::AccountId::from(parent_account_id.clone())
.is_top_level()
{
if crate::common::find_network_where_account_exist(
context,
parent_account_id.clone().into(),
)?
.is_none()
{
eprintln!(
"\nThe parent account <{}> does not exist on [{}] networks. Therefore, you cannot create an account <{}>.",
let network_where_account_exist =
match crate::common::find_network_where_account_exist(
context,
parent_account_id.clone().into(),
) {
Ok(network_config) => network_config,
Err(crate::common::AccountStateError::Skip) => {
return Ok(Some(account_id));
}
Err(err) => {
return color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!(
err
));
}
};
if network_where_account_exist.is_none() {
tracing::warn!("{}",
format!("The parent account <{}> does not exist on [{}] networks. Therefore, you cannot create an account <{}>.",
parent_account_id,
context.config.network_names().join(", "),
account_id
account_id).red()
);
if !crate::common::ask_if_different_account_id_wanted()? {
return Ok(Some(account_id));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use color_eyre::owo_colors::OwoColorize;
use serde_json::json;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
Expand Down Expand Up @@ -198,9 +199,15 @@ fn validate_new_account_id(
account_id,
network_config.network_name
)),
Err(crate::common::AccountStateError::Cancel) => color_eyre::eyre::Result::Err(
color_eyre::eyre::eyre!("Operation was canceled by the user"),
),
Err(crate::common::AccountStateError::Skip) => {
tracing::warn!(
"{}",
format!(
"Account <{account_id}> is not verified. You can sign and send the created transaction later."
)
);
Ok(())
}
Err(crate::common::AccountStateError::JsonRpcError(
near_jsonrpc_client::errors::JsonRpcError::ServerError(
near_jsonrpc_client::errors::JsonRpcServerError::HandlerError(
Expand All @@ -213,13 +220,14 @@ fn validate_new_account_id(
)) => {
tracing::warn!(
parent: &tracing::Span::none(),
"Transport error.{}",
"{}{}",
"Transport error.".red(),
crate::common::indent_payload(
"\nIt is currently possible to continue creating an account offline.\nYou can sign and send the created transaction later.\n"
)
"\nIt is currently possible to continue creating an account offline.\nYou can sign and send the created transaction later.\n "
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indent_payload message ends with a trailing space ("\n "). This can result in awkward whitespace in the warning output. Consider trimming the trailing space from the string literal.

Suggested change
"\nIt is currently possible to continue creating an account offline.\nYou can sign and send the created transaction later.\n "
"\nIt is currently possible to continue creating an account offline.\nYou can sign and send the created transaction later.\n"

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This correctly changes the displayed result.

).yellow()
);
Ok(())
}
Err(err) => color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!("{:?}", err)),
Err(err) => color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!(err)),
}
}
33 changes: 22 additions & 11 deletions src/commands/account/delete_account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl BeneficiaryAccount {
};

if beneficiary_account_id.0 == context.account_id {
eprintln!("{}", "You have selected a beneficiary account ID that will now be deleted. This will result in the loss of your funds. So make your choice again.".red());
tracing::warn!("{}", "You have selected a beneficiary account ID that will now be deleted. This will result in the loss of your funds. So make your choice again.".red());
continue;
}

Expand All @@ -152,16 +152,27 @@ impl BeneficiaryAccount {
)
.prompt()?;
if let ConfirmOptions::Yes { account_id } = select_choose_input {
if crate::common::find_network_where_account_exist(
&context.global_context,
account_id.clone().into(),
)?
.is_none()
{
eprintln!(
"\nHeads up! You will lose remaining NEAR tokens on the account you delete if you specify the account <{}> as the beneficiary as it does not exist on [{}] networks.",
account_id,
context.global_context.config.network_names().join(", ")
let network_where_account_exist =
match crate::common::find_network_where_account_exist(
&context.global_context,
account_id.clone().into(),
) {
Ok(network_config) => network_config,
Err(crate::common::AccountStateError::Skip) => {
tracing::warn!("{}", "Cannot verify beneficiary. Proceeding may result in total loss of NEAR tokens of the deleting account.".red());
return Ok(Some(account_id));
}
Err(err) => {
return color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!(err));
}
};
if network_where_account_exist.is_none() {
tracing::warn!("{}",
format!(
"Heads up! You will lose remaining NEAR tokens on the account you delete if you specify the account <{}> as the beneficiary as it does not exist on [{}] networks.",
account_id,
context.global_context.config.network_names().join(", ")
).red()
);
if !crate::common::ask_if_different_account_id_wanted()? {
return Ok(Some(account_id));
Expand Down
6 changes: 2 additions & 4 deletions src/commands/account/import_account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ pub fn login(
public_key.clone(),
network_config.clone(),
);
if let Err(crate::common::AccountStateError::Cancel) = access_key_view {
return color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!(
"Operation was canceled by the user"
));
if let Err(err @ crate::common::AccountStateError::Cancel) = access_key_view {
return color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!(err));
}
if access_key_view.is_err() {
tracing::warn!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl LoginFromPrivateKeyContext {
&key_pair_properties_buf,
&public_key.to_string(),
&format!(
"\nIt is currently not possible to verify the account access key on network <{}>.\nYou may have entered an incorrect account_id.\nYou have the option to reconfirm your account or save your access key information.\n",
"\nIt is currently not possible to verify the account access key on network <{}>.\nYou may have entered an incorrect account_id.\nYou have the option to reconfirm your account or save your access key information.\n ",
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formatted string ends with an extra trailing space ("\n "), which alters the displayed message. Consider removing the trailing space.

Suggested change
"\nIt is currently not possible to verify the account access key on network <{}>.\nYou may have entered an incorrect account_id.\nYou have the option to reconfirm your account or save your access key information.\n ",
"\nIt is currently not possible to verify the account access key on network <{}>.\nYou may have entered an incorrect account_id.\nYou have the option to reconfirm your account or save your access key information.\n",

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This correctly changes the displayed result.

network_config.network_name
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl LoginFromSeedPhraseContext {
&key_pair_properties_buf,
&key_pair_properties.public_key_str,
&format!(
"\nIt is currently not possible to verify the account access key on network <{}>.\nYou may have entered an incorrect account_id.\nYou have the option to reconfirm your account or save your access key information.\n",
"\nIt is currently not possible to verify the account access key on network <{}>.\nYou may have entered an incorrect account_id.\nYou have the option to reconfirm your account or save your access key information.\n ",
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prompt string now has a trailing space at the end ("\n "), which will show up in the UI output. Consider removing the trailing space.

Suggested change
"\nIt is currently not possible to verify the account access key on network <{}>.\nYou may have entered an incorrect account_id.\nYou have the option to reconfirm your account or save your access key information.\n ",
"\nIt is currently not possible to verify the account access key on network <{}>.\nYou may have entered an incorrect account_id.\nYou have the option to reconfirm your account or save your access key information.\n",

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This correctly changes the displayed result.

network_config.network_name
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl LoginFromWebWalletContext {

let key_pair_properties_buf = serde_json::to_string(&key_pair_properties)?;
let error_message = format!(
"\nIt is currently not possible to verify the account access key.\nYou may not be logged in to {} or you may have entered an incorrect account_id.\nYou have the option to reconfirm your account or save your access key information.\n",
"\nIt is currently not possible to verify the account access key.\nYou may not be logged in to {} or you may have entered an incorrect account_id.\nYou have the option to reconfirm your account or save your access key information.\n ",
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatted error_message literal now ends with an extra space ("\n "). This changes the rendered output (and can produce awkward trailing whitespace). Consider removing the trailing space from the string.

Suggested change
"\nIt is currently not possible to verify the account access key.\nYou may not be logged in to {} or you may have entered an incorrect account_id.\nYou have the option to reconfirm your account or save your access key information.\n ",
"\nIt is currently not possible to verify the account access key.\nYou may not be logged in to {} or you may have entered an incorrect account_id.\nYou have the option to reconfirm your account or save your access key information.\n",

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

@FroVolod FroVolod Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This correctly changes the displayed result.
Screenshot 2026-02-14 at 09 15 37

After removing the space at the end of the line:
Screenshot 2026-02-14 at 08 47 24

&url.as_str()
);
super::login(
Expand Down
9 changes: 6 additions & 3 deletions src/commands/account/storage_management/storage_deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ impl DepositArgs {
&context.global_context.config.network_connection,
receiver_account_id.clone().into(),
)? {
eprintln!(
"\nThe account <{receiver_account_id}> does not exist on [{}] networks.",
context.global_context.config.network_names().join(", ")
tracing::warn!(
"{}",
format!(
"The account <{receiver_account_id}> does not exist on [{}] networks.",
context.global_context.config.network_names().join(", ")
)
);
#[derive(strum_macros::Display)]
enum ConfirmOptions {
Expand Down
9 changes: 6 additions & 3 deletions src/commands/account/update_social_profile/sign_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ impl Signer {
&context.global_context.config.network_connection,
signer_account_id.clone().into(),
)? {
eprintln!(
"\nThe account <{signer_account_id}> does not exist on [{}] networks.",
context.global_context.config.network_names().join(", ")
tracing::warn!(
"{}",
format!(
"The account <{signer_account_id}> does not exist on [{}] networks.",
context.global_context.config.network_names().join(", ")
)
);
#[derive(strum_macros::Display)]
enum ConfirmOptions {
Expand Down
39 changes: 21 additions & 18 deletions src/commands/contract/call_function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,34 @@ fn input_function_name(
let network_config = crate::common::find_network_where_account_exist(
global_context,
contract_account_id.clone(),
)?;
);

if let Some(network_config) = network_config {
let json_rpc_client = network_config.json_rpc_client();
if let Ok(contract_abi) =
if let Err(err @ crate::common::AccountStateError::Cancel) = network_config {
return color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!(err));
}

if let Ok(network) = network_config
&& let Some(network_config) = network
&& let Ok(contract_abi) =
tokio::runtime::Runtime::new()
.unwrap()
.block_on(super::get_contract_abi(
&json_rpc_client,
&network_config.json_rpc_client(),
&near_primitives::types::Finality::Final.into(),
contract_account_id,
))
{
let function_names = contract_abi
.body
.functions
.into_iter()
.filter(|function| function_kind == function.kind)
.map(|function| function.name)
.collect::<Vec<String>>();
if !function_names.is_empty() {
return Ok(Some(
Select::new(message, function_names).prompt()?.to_string(),
));
}
{
let function_names = contract_abi
.body
.functions
.into_iter()
.filter(|function| function_kind == function.kind)
.map(|function| function.name)
.collect::<Vec<String>>();
if !function_names.is_empty() {
return Ok(Some(
Select::new(message, function_names).prompt()?.to_string(),
));
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/commands/tokens/send_ft/amount_ft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ impl AmountFtContext {
let network_config = crate::common::find_network_where_account_exist(
&previous_context.global_context,
previous_context.ft_contract_account_id.clone(),
)?
)
.map_err(color_eyre::Report::msg)?
.wrap_err_with(|| {
format!(
"Contract <{}> does not exist in networks",
Expand Down Expand Up @@ -69,7 +70,8 @@ impl AmountFt {
let network_config = crate::common::find_network_where_account_exist(
&context.global_context,
context.ft_contract_account_id.clone(),
)?
)
.map_err(color_eyre::Report::msg)?
.wrap_err_with(|| {
format!(
"Contract <{}> does not exist in networks",
Expand Down
Loading
Loading