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: Added loading indicators for waiting for responses from RPC #315

Merged
merged 18 commits into from
Apr 25, 2024
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
56 changes: 56 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ url = { version = "2", features = ["serde"] }
open = "4"
shell-words = "1"
cargo-util = "0.1.1"
indicatif = "0.17.8"
tracing = "0.1.40"
tracing-indicatif = "0.3.6"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

wasmparser = "0.200.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,14 @@ fn validate_new_account_id(
account_id: &near_primitives::types::AccountId,
) -> crate::CliResult {
for _ in 0..3 {
let account_state = crate::common::get_account_state(
network_config.clone(),
account_id.clone(),
near_primitives::types::BlockReference::latest(),
);
let account_state =
tokio::runtime::Runtime::new()
.unwrap()
.block_on(crate::common::get_account_state(
network_config,
account_id,
near_primitives::types::BlockReference::latest(),
));
if let Err(near_jsonrpc_client::errors::JsonRpcError::TransportError(
near_jsonrpc_client::errors::RpcTransportError::SendError(_),
)) = account_state
Expand All @@ -198,10 +201,10 @@ fn validate_new_account_id(
match account_state {
Ok(_) => {
return color_eyre::eyre::Result::Err(color_eyre::eyre::eyre!(
"\nAccount <{}> already exists in network <{}>. Therefore, it is not possible to create an account with this name.",
account_id,
network_config.network_name
));
"\nAccount <{}> already exists in network <{}>. Therefore, it is not possible to create an account with this name.",
account_id,
network_config.network_name
));
}
Err(near_jsonrpc_client::errors::JsonRpcError::ServerError(
near_jsonrpc_client::errors::JsonRpcServerError::HandlerError(
Expand Down
9 changes: 6 additions & 3 deletions src/commands/tokens/view_near_balance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct ViewNearBalance {
pub struct ViewNearBalanceContext(crate::network_view_at_block::ArgsForViewContext);

impl ViewNearBalanceContext {
#[tracing::instrument(name = "Getting a NEAR balance for your account ...", skip_all)]
pub fn from_previous_context(
previous_context: super::TokensCommandsContext,
_scope: &<ViewNearBalance as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
Expand All @@ -19,11 +20,13 @@ impl ViewNearBalanceContext {
let owner_account_id = previous_context.owner_account_id.clone();

move |network_config, block_reference| {
let account_transfer_allowance = crate::common::get_account_transfer_allowance(
network_config.clone(),
let account_transfer_allowance = tokio::runtime::Runtime::new()
.unwrap()
.block_on(crate::common::get_account_transfer_allowance(
network_config,
owner_account_id.clone(),
block_reference.clone(),
)?;
))?;
eprintln!("{account_transfer_allowance}");
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl SubmitContext {
Ok(response) => {
break response;
}
Err(err) => match crate::common::rpc_transaction_error(err) {
Err(err) => match crate::common::rpc_transaction_error(&err) {
Ok(_) => std::thread::sleep(std::time::Duration::from_millis(100)),
Err(report) => return Err(color_eyre::Report::msg(report)),
},
Expand Down
Loading
Loading