Skip to content

Commit 0ca65dd

Browse files
authored
fix: Fixed UI for interactive mode (#531)
1 parent f8b73ea commit 0ca65dd

File tree

61 files changed

+418
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+418
-413
lines changed

src/commands/account/create_account/create_implicit_account/use_auto_generation.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ impl SaveWithUseAutoGenerationContext {
4343
.write(buf.as_bytes())
4444
.wrap_err_with(|| format!("Failed to write to file: {folder_path:?}"))?;
4545

46-
tracing::info!(
47-
parent: &tracing::Span::none(),
48-
"The file {:?} was saved successfully",
49-
&file_path
50-
);
46+
if let crate::Verbosity::Interactive | crate::Verbosity::TeachMe =
47+
previous_context.verbosity
48+
{
49+
eprintln!("\nThe file {file_path:?} was saved successfully");
50+
}
5151

5252
Ok(())
5353
}

src/commands/account/create_account/create_implicit_account/use_ledger.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ impl SaveWithLedgerContext {
6565
.write(buf.as_bytes())
6666
.wrap_err_with(|| format!("Failed to write to file: {file_path:?}"))?;
6767

68-
tracing::info!(
69-
parent: &tracing::Span::none(),
70-
"The file {:?} was saved successfully",
71-
&file_path
72-
);
68+
if let crate::Verbosity::Interactive | crate::Verbosity::TeachMe =
69+
previous_context.verbosity
70+
{
71+
eprintln!("\nThe file {file_path:?} was saved successfully");
72+
}
7373

7474
Ok(())
7575
}

src/commands/account/create_account/create_implicit_account/use_seed_phrase.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ impl SaveWithSeedPhraseContext {
5252
.write(buf.as_bytes())
5353
.wrap_err_with(|| format!("Failed to write to file: {file_path:?}"))?;
5454

55-
tracing::info!(
56-
parent: &tracing::Span::none(),
57-
"The file {:?} was saved successfully",
58-
&file_path
59-
);
55+
if let crate::Verbosity::Interactive | crate::Verbosity::TeachMe =
56+
previous_context.verbosity
57+
{
58+
eprintln!("\nThe file {file_path:?} was saved successfully");
59+
}
6060

6161
Ok(())
6262
}

src/commands/account/create_account/fund_myself_create_account/sign_as/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ fn validate_new_account_id(
182182
network_config: &crate::config::NetworkConfig,
183183
account_id: &near_primitives::types::AccountId,
184184
) -> crate::CliResult {
185+
tracing::info!(target: "near_teach_me", "Validation new account_id ...");
185186
let account_state =
186187
tokio::runtime::Runtime::new()
187188
.unwrap()

src/commands/account/create_account/sponsor_by_faucet_service/mod.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl NewAccountContext {
4545
public_key,
4646
&credentials_home_dir,
4747
storage_message,
48+
previous_context.verbosity,
4849
)
4950
}
5051
});
@@ -72,6 +73,7 @@ pub fn before_creating_account(
7273
public_key: &near_crypto::PublicKey,
7374
credentials_home_dir: &std::path::Path,
7475
storage_message: String,
76+
verbosity: crate::Verbosity,
7577
) -> crate::CliResult {
7678
let faucet_service_url = match &network_config.faucet_url {
7779
Some(url) => url,
@@ -81,7 +83,7 @@ pub fn before_creating_account(
8183
)))
8284
};
8385
tracing::Span::current().pb_set_message(faucet_service_url.as_str());
84-
tracing::info!(target: "near_teach_me", "{}", faucet_service_url.as_str());
86+
tracing::info!(target: "near_teach_me", "Receiving request via faucet service {}", faucet_service_url.as_str());
8587
let mut data = std::collections::HashMap::new();
8688
data.insert("newAccountId", new_account_id.to_string());
8789
data.insert("newAccountPublicKey", public_key.to_string());
@@ -113,6 +115,7 @@ pub fn before_creating_account(
113115
new_account_id,
114116
credentials_home_dir,
115117
storage_message,
118+
verbosity,
116119
)
117120
}
118121

@@ -122,6 +125,7 @@ fn print_account_creation_status(
122125
new_account_id: &crate::types::account_id::AccountId,
123126
credentials_home_dir: &std::path::Path,
124127
storage_message: String,
128+
verbosity: crate::Verbosity,
125129
) -> crate::CliResult {
126130
match result {
127131
Ok(response) => {
@@ -134,9 +138,9 @@ fn print_account_creation_status(
134138
if response.status() >= reqwest::StatusCode::BAD_REQUEST {
135139
tracing::warn!(
136140
parent: &tracing::Span::none(),
137-
"WARNING!{}",
141+
"{}",
138142
crate::common::indent_payload(&format!(
139-
"\nThe new account <{new_account_id}> could not be created successfully.\n{storage_message}\n"
143+
"\nThe new account <{new_account_id}> could not be created successfully.\n{storage_message}\n "
140144
))
141145
);
142146
return Err(color_eyre::Report::msg(format!(
@@ -156,45 +160,46 @@ fn print_account_creation_status(
156160
})?;
157161
match account_creation_transaction.status {
158162
near_primitives::views::FinalExecutionStatus::SuccessValue(ref value) => {
163+
tracing::info!(
164+
parent: &tracing::Span::none(),
165+
"Transaction Execution Info:\n{}",
166+
crate::common::indent_payload(&format!(
167+
"Transaction ID: {id}\nTo see the transaction in the transaction explorer, please open this url in your browser:\n{path}{id}\n",
168+
id=account_creation_transaction.transaction_outcome.id,
169+
path=network_config.explorer_transaction_url
170+
))
171+
);
159172
if value == b"false" {
160173
tracing::warn!(
161174
parent: &tracing::Span::none(),
162-
"WARNING!{}",
175+
"{}",
163176
crate::common::indent_payload(&format!(
164-
"\nThe new account <{new_account_id}> could not be created successfully.\n{storage_message}\n"
177+
"\nThe new account <{new_account_id}> could not be created successfully.\n{storage_message}\n "
165178
))
166179
);
167180
} else {
168181
crate::common::update_used_account_list_as_signer(
169182
credentials_home_dir,
170183
new_account_id.as_ref(),
171184
);
172-
tracing::info!(
173-
parent: &tracing::Span::none(),
174-
"{}",
175-
crate::common::indent_payload(&format!(
176-
"\nNew account <{new_account_id}> created successfully.\n{storage_message}\n"
177-
))
178-
);
185+
if let crate::Verbosity::Interactive | crate::Verbosity::TeachMe = verbosity
186+
{
187+
tracing_indicatif::suspend_tracing_indicatif(|| {
188+
eprintln!(
189+
"New account <{new_account_id}> created successfully.\n{storage_message}"
190+
)
191+
});
192+
}
179193
}
180-
tracing::info!(
181-
parent: &tracing::Span::none(),
182-
"\n{}",
183-
crate::common::indent_payload(&format!(
184-
"Transaction ID: {id}\nTo see the transaction in the transaction explorer, please open this url in your browser:\n{path}{id}\n",
185-
id=account_creation_transaction.transaction_outcome.id,
186-
path=network_config.explorer_transaction_url
187-
))
188-
);
189194
}
190195
near_primitives::views::FinalExecutionStatus::NotStarted
191196
| near_primitives::views::FinalExecutionStatus::Started => unreachable!(),
192197
near_primitives::views::FinalExecutionStatus::Failure(tx_execution_error) => {
193198
tracing::warn!(
194199
parent: &tracing::Span::none(),
195-
"WARNING!{}",
200+
"{}",
196201
crate::common::indent_payload(&format!(
197-
"\nThe new account <{new_account_id}> could not be created successfully.\n{storage_message}\n"
202+
"\nThe new account <{new_account_id}> could not be created successfully.\n{storage_message}\n "
198203
))
199204
);
200205
match tx_execution_error {
@@ -224,9 +229,9 @@ fn print_account_creation_status(
224229
);
225230
tracing::warn!(
226231
parent: &tracing::Span::none(),
227-
"WARNING!{}",
232+
"{}",
228233
crate::common::indent_payload(&format!(
229-
"\nThe new account <{new_account_id}> could not be created successfully.\n{storage_message}\n"
234+
"\nThe new account <{new_account_id}> could not be created successfully.\n{storage_message}\n "
230235
))
231236
);
232237
Err(color_eyre::Report::msg(err.to_string()))

src/commands/account/create_account/sponsor_by_faucet_service/network/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl NetworkContext {
4848
"", "public key:", &previous_context.public_key
4949
));
5050
info_str.push_str(&format!("\n{:>18} {:<13} FullAccess", "", "permission:"));
51-
info_str.push('\n');
51+
info_str.push_str("\n ");
5252

5353
tracing::info!(
5454
"Your transaction:{}",
@@ -93,6 +93,7 @@ impl SubmitContext {
9393
previous_context: NetworkContext,
9494
_scope: &<Submit as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
9595
) -> color_eyre::eyre::Result<Self> {
96+
tracing::info!(target: "near_teach_me", "Creating a new account ...");
9697
let storage_message =
9798
(previous_context.on_after_getting_network_callback)(&previous_context.network_config)?;
9899
(previous_context.on_before_creating_account_callback)(

src/commands/account/export_account/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub fn get_password_from_keychain(
8787
network_config: &crate::config::NetworkConfig,
8888
account_id: &near_primitives::types::AccountId,
8989
) -> color_eyre::eyre::Result<String> {
90+
tracing::info!(target: "near_teach_me", "Receiving the account key pair from the keychain ...");
9091
let service_name: std::borrow::Cow<'_, str> = std::borrow::Cow::Owned(format!(
9192
"near-{}-{}",
9293
network_config.network_name,
@@ -161,6 +162,7 @@ pub fn get_account_properties_data_path(
161162
credentials_home_dir: &std::path::Path,
162163
check_if_seed_phrase_exists: bool,
163164
) -> color_eyre::eyre::Result<std::path::PathBuf> {
165+
tracing::info!(target: "near_teach_me", "Receiving the account key pair from a legacy keychain ...");
164166
let file_name = format!("{account_id}.json");
165167
let mut path = std::path::PathBuf::from(credentials_home_dir);
166168

src/commands/account/get_public_key/from_keychain/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ impl PublicKeyFromKeychainContext {
8383
let account_key_pair: crate::transaction_signature_options::AccountKeyPair =
8484
serde_json::from_str(&password).wrap_err("Error reading data")?;
8585

86-
if let crate::Verbosity::Quiet = previous_context.verbosity {
87-
println!("{}", account_key_pair.public_key);
88-
} else {
89-
eprintln!("\nPublic key (printed to stdout): ");
90-
println!("{}", account_key_pair.public_key);
86+
if let crate::Verbosity::Interactive | crate::Verbosity::TeachMe =
87+
previous_context.verbosity
88+
{
89+
eprint!("Public key (printed to stdout): ");
9190
}
91+
println!("{}", account_key_pair.public_key);
9292

9393
Ok(())
9494
}

src/commands/account/get_public_key/from_ledger/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ impl PublicKeyFromLedgerContext {
3737
verifying_key.to_bytes(),
3838
));
3939

40-
if let crate::Verbosity::Quiet = previous_context.verbosity {
41-
println!("{public_key}");
42-
} else {
43-
eprintln!("\nPublic key (printed to stdout): ");
44-
println!("{public_key}");
40+
if let crate::Verbosity::Interactive | crate::Verbosity::TeachMe =
41+
previous_context.verbosity
42+
{
43+
eprint!("Public key (printed to stdout): ");
4544
}
45+
println!("{public_key}");
4646

4747
Ok(Self {})
4848
}

src/commands/account/get_public_key/from_legacy_keychain/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ impl PublicKeyFromLegacyKeychainContext {
101101
)
102102
})?;
103103

104-
if let crate::Verbosity::Quiet = previous_context.verbosity {
105-
println!("{}", account_key_pair.public_key);
106-
} else {
107-
eprintln!("\nPublic key (printed to stdout): ");
108-
println!("{}", account_key_pair.public_key);
104+
if let crate::Verbosity::Interactive | crate::Verbosity::TeachMe =
105+
previous_context.verbosity
106+
{
107+
eprint!("Public key (printed to stdout): ");
109108
}
109+
println!("{}", account_key_pair.public_key);
110110

111111
Ok(())
112112
}

0 commit comments

Comments
 (0)