Skip to content

Commit

Permalink
feat: Added loading indicators to wait for the create-account (sponso…
Browse files Browse the repository at this point in the history
…r-by-faucet-service) command (#339)
  • Loading branch information
FroVolod authored May 31, 2024
1 parent c47b0bb commit ad3447b
Show file tree
Hide file tree
Showing 47 changed files with 323 additions and 307 deletions.
4 changes: 2 additions & 2 deletions src/commands/account/add_key/autogenerate_new_keypair/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ impl GenerateKeypairContext {
/// Save an access key for this account:
pub enum SaveMode {
#[strum_discriminants(strum(
message = "save-to-keychain - Save automatically generated key pair to keychain"
message = "save-to-keychain - Save automatically generated key pair to keychain"
))]
/// Save automatically generated key pair to keychain
SaveToKeychain(self::save_keypair_to_keychain::SaveKeypairToKeychain),
#[strum_discriminants(strum(
message = "save-to-legacy-keychain - Save automatically generated key pair to the legacy keychain (compatible with JS CLI)"
message = "save-to-legacy-keychain - Save automatically generated key pair to the legacy keychain (compatible with JS CLI)"
))]
/// Save automatically generated key pair to the legacy keychain (compatible with JS CLI)
SaveToLegacyKeychain(self::save_keypair_to_legacy_keychain::SaveKeypairToLegacyKeychain),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl PrintKeypairToTerminalContext {

impl From<PrintKeypairToTerminalContext> for crate::commands::ActionContext {
fn from(item: PrintKeypairToTerminalContext) -> Self {
let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback =
let get_prepopulated_transaction_after_getting_network_callback: crate::commands::GetPrepopulatedTransactionAfterGettingNetworkCallback =
std::sync::Arc::new({
let signer_account_id = item.signer_account_id.clone();

Expand All @@ -57,28 +57,27 @@ impl From<PrintKeypairToTerminalContext> for crate::commands::ActionContext {
Self {
global_context: item.global_context,
interacting_with_account_ids: vec![item.signer_account_id],
on_after_getting_network_callback,
get_prepopulated_transaction_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
),
on_before_sending_transaction_callback: std::sync::Arc::new(
|_signed_transaction, _network_config, _message| Ok(()),
),
on_after_sending_transaction_callback: std::sync::Arc::new(
move |_outcome_view, _network_config| {
eprintln!("\n-------------------- Access key info ------------------\n");
eprintln!(
"Master Seed Phrase: {}\nSeed Phrase HD Path: {}\nImplicit Account ID: {}\nPublic Key: {}\nSECRET KEYPAIR: {}",
move |_transaction, _network_config| {
Ok(format!(
"\n-------------------- Access key info ------------------
\nMaster Seed Phrase: {}\nSeed Phrase HD Path: {}\nImplicit Account ID: {}\nPublic Key: {}\nSECRET KEYPAIR: {}
\n--------------------------------------------------------",
item.key_pair_properties.master_seed_phrase,
item.key_pair_properties.seed_phrase_hd_path,
item.key_pair_properties.implicit_account_id,
item.key_pair_properties.public_key_str,
item.key_pair_properties.secret_keypair_str,
);
eprintln!("\n--------------------------------------------------------");
Ok(())
))
},
),
on_after_sending_transaction_callback: std::sync::Arc::new(
move |_outcome_view, _network_config| Ok(()),
),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl SaveKeypairToKeychainContext {

impl From<SaveKeypairToKeychainContext> for crate::commands::ActionContext {
fn from(item: SaveKeypairToKeychainContext) -> Self {
let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback =
let get_prepopulated_transaction_after_getting_network_callback: crate::commands::GetPrepopulatedTransactionAfterGettingNetworkCallback =
std::sync::Arc::new({
let signer_account_id = item.0.signer_account_id.clone();

Expand All @@ -43,21 +43,28 @@ impl From<SaveKeypairToKeychainContext> for crate::commands::ActionContext {
});
let on_before_sending_transaction_callback: crate::transaction_signature_options::OnBeforeSendingTransactionCallback =
std::sync::Arc::new(
move |signed_transaction, network_config, storage_message| {
*storage_message = crate::common::save_access_key_to_keychain(
move |transaction, network_config| {
let account_id = match transaction {
crate::transaction_signature_options::SignedTransactionOrSignedDelegateAction::SignedTransaction(
signed_transaction,
) => signed_transaction.transaction.signer_id.clone(),
crate::transaction_signature_options::SignedTransactionOrSignedDelegateAction::SignedDelegateAction(
signed_delegate_action,
) => signed_delegate_action.delegate_action.sender_id.clone()
};
crate::common::save_access_key_to_keychain(
network_config.clone(),
&serde_json::to_string(&item.0.key_pair_properties)?,
&item.0.key_pair_properties.public_key_str,
signed_transaction.transaction.signer_id.as_ref(),
)?;
Ok(())
account_id.as_ref(),
)
},
);

Self {
global_context: item.0.global_context,
interacting_with_account_ids: vec![item.0.signer_account_id],
on_after_getting_network_callback,
get_prepopulated_transaction_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl SaveKeypairToLegacyKeychainContext {

impl From<SaveKeypairToLegacyKeychainContext> for crate::commands::ActionContext {
fn from(item: SaveKeypairToLegacyKeychainContext) -> Self {
let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback =
let get_prepopulated_transaction_after_getting_network_callback: crate::commands::GetPrepopulatedTransactionAfterGettingNetworkCallback =
std::sync::Arc::new({
let signer_account_id = item.signer_account_id.clone();

Expand All @@ -60,29 +60,36 @@ impl From<SaveKeypairToLegacyKeychainContext> for crate::commands::ActionContext
std::sync::Arc::new({
let credentials_home_dir = item.global_context.config.credentials_home_dir.clone();

move |signed_transaction, network_config, storage_message| {
move |transaction, network_config| {
let account_id = match transaction {
crate::transaction_signature_options::SignedTransactionOrSignedDelegateAction::SignedTransaction(
signed_transaction,
) => signed_transaction.transaction.signer_id.clone(),
crate::transaction_signature_options::SignedTransactionOrSignedDelegateAction::SignedDelegateAction(
signed_delegate_action,
) => signed_delegate_action.delegate_action.sender_id.clone()
};
let key_pair_properties_buf = serde_json::to_string(&item.key_pair_properties)?;
*storage_message = crate::common::save_access_key_to_legacy_keychain(
crate::common::save_access_key_to_legacy_keychain(
network_config.clone(),
credentials_home_dir.clone(),
&key_pair_properties_buf,
&item.key_pair_properties.public_key_str,
signed_transaction.transaction.signer_id.as_ref(),
account_id.as_ref(),
)
.wrap_err_with(|| {
format!(
"Failed to save a file with access key: {}",
&item.key_pair_properties.public_key_str
)
})?;
Ok(())
})
}
});

Self {
global_context: item.global_context,
interacting_with_account_ids: vec![item.signer_account_id],
on_after_getting_network_callback,
get_prepopulated_transaction_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
),
Expand Down
6 changes: 3 additions & 3 deletions src/commands/account/add_key/use_ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl AddLedgerKeyActionContext {

impl From<AddLedgerKeyActionContext> for crate::commands::ActionContext {
fn from(item: AddLedgerKeyActionContext) -> Self {
let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback =
let get_prepopulated_transaction_after_getting_network_callback: crate::commands::GetPrepopulatedTransactionAfterGettingNetworkCallback =
std::sync::Arc::new({
let signer_account_id = item.signer_account_id.clone();

Expand All @@ -72,12 +72,12 @@ impl From<AddLedgerKeyActionContext> for crate::commands::ActionContext {
Self {
global_context: item.global_context,
interacting_with_account_ids: vec![item.signer_account_id],
on_after_getting_network_callback,
get_prepopulated_transaction_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
),
on_before_sending_transaction_callback: std::sync::Arc::new(
|_signed_transaction, _network_config, _message| Ok(()),
|_signed_transaction, _network_config| Ok(String::new()),
),
on_after_sending_transaction_callback: std::sync::Arc::new(
|_outcome_view, _network_config| Ok(()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl AddAccessWithSeedPhraseActionContext {

impl From<AddAccessWithSeedPhraseActionContext> for crate::commands::ActionContext {
fn from(item: AddAccessWithSeedPhraseActionContext) -> Self {
let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback =
let get_prepopulated_transaction_after_getting_network_callback: crate::commands::GetPrepopulatedTransactionAfterGettingNetworkCallback =
std::sync::Arc::new({
let signer_account_id = item.signer_account_id.clone();

Expand All @@ -64,12 +64,12 @@ impl From<AddAccessWithSeedPhraseActionContext> for crate::commands::ActionConte
Self {
global_context: item.global_context,
interacting_with_account_ids: vec![item.signer_account_id],
on_after_getting_network_callback,
get_prepopulated_transaction_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
),
on_before_sending_transaction_callback: std::sync::Arc::new(
|_signed_transaction, _network_config, _message| Ok(()),
|_signed_transaction, _network_config| Ok(String::new()),
),
on_after_sending_transaction_callback: std::sync::Arc::new(
|_outcome_view, _network_config| Ok(()),
Expand Down
6 changes: 3 additions & 3 deletions src/commands/account/add_key/use_public_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl AddAccessKeyActionContext {

impl From<AddAccessKeyActionContext> for crate::commands::ActionContext {
fn from(item: AddAccessKeyActionContext) -> Self {
let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback =
let get_prepopulated_transaction_after_getting_network_callback: crate::commands::GetPrepopulatedTransactionAfterGettingNetworkCallback =
std::sync::Arc::new({
let signer_account_id = item.signer_account_id.clone();

Expand All @@ -57,12 +57,12 @@ impl From<AddAccessKeyActionContext> for crate::commands::ActionContext {
Self {
global_context: item.global_context,
interacting_with_account_ids: vec![item.signer_account_id],
on_after_getting_network_callback,
get_prepopulated_transaction_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
),
on_before_sending_transaction_callback: std::sync::Arc::new(
|_signed_transaction, _network_config, _message| Ok(()),
|_signed_transaction, _network_config| Ok(String::new()),
),
on_after_sending_transaction_callback: std::sync::Arc::new(
|_outcome_view, _network_config| Ok(()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl From<GenerateKeypairContext> for super::super::AccountPropertiesContext {
global_context: item.global_context,
account_properties: item.account_properties,
on_before_sending_transaction_callback: std::sync::Arc::new(
|_signed_transaction, _network_config, _message| Ok(()),
|_signed_transaction, _network_config| Ok(String::new()),
),
}
}
Expand Down Expand Up @@ -90,43 +90,42 @@ impl SaveModeContext {
let key_pair_properties = previous_context.key_pair_properties.clone();
let credentials_home_dir = previous_context.global_context.config.credentials_home_dir.clone();

move |_signed_transaction, network_config, storage_message| {
move |_transaction, network_config| {
match scope {
SaveModeDiscriminants::SaveToKeychain => {
let key_pair_properties_buf =
serde_json::to_string(&key_pair_properties)?;
*storage_message = crate::common::save_access_key_to_keychain(
crate::common::save_access_key_to_keychain(
network_config.clone(),
&key_pair_properties_buf,
&key_pair_properties.public_key_str,
new_account_id.as_ref(),
)?;
)
}
SaveModeDiscriminants::SaveToLegacyKeychain => {
let key_pair_properties_buf =
serde_json::to_string(&key_pair_properties)?;
*storage_message = crate::common::save_access_key_to_legacy_keychain(
crate::common::save_access_key_to_legacy_keychain(
network_config.clone(),
credentials_home_dir.clone(),
&key_pair_properties_buf,
&key_pair_properties.public_key_str,
new_account_id.as_ref(),
)?;
)
}
SaveModeDiscriminants::PrintToTerminal => {
eprintln!("\n-------------------- Access key info for account <{}> ------------------\n", &new_account_id);
eprintln!(
"Master Seed Phrase: {}\nSeed Phrase HD Path: {}\nImplicit Account ID: {}\nPublic Key: {}\nSECRET KEYPAIR: {}",
Ok(format!(
"\n-------------------- Access key info ------------------
\nMaster Seed Phrase: {}\nSeed Phrase HD Path: {}\nImplicit Account ID: {}\nPublic Key: {}\nSECRET KEYPAIR: {}
\n--------------------------------------------------------",
key_pair_properties.master_seed_phrase,
key_pair_properties.seed_phrase_hd_path,
key_pair_properties.implicit_account_id,
key_pair_properties.public_key_str,
key_pair_properties.secret_keypair_str,
);
eprintln!("\n------------------------------------------------------------------------------------");
))
}
}
Ok(())
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl AddAccessWithLedgerContext {
global_context: previous_context.global_context,
account_properties,
on_before_sending_transaction_callback: std::sync::Arc::new(
|_signed_transaction, _network_config, _message| Ok(()),
|_signed_transaction, _network_config| Ok(String::new()),
),
}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl AddAccessWithSeedPhraseActionContext {
global_context: previous_context.global_context,
account_properties,
on_before_sending_transaction_callback: std::sync::Arc::new(
|_signed_transaction, _network_config, _message| Ok(()),
|_signed_transaction, _network_config| Ok(String::new()),
),
}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl AddPublicKeyActionContext {
global_context: previous_context.global_context,
account_properties,
on_before_sending_transaction_callback: std::sync::Arc::new(
|_signed_transaction, _network_config, _message| Ok(()),
|_signed_transaction, _network_config| Ok(String::new()),
),
}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl From<SignerAccountIdContext> for crate::commands::ActionContext {
fn from(item: SignerAccountIdContext) -> Self {
let global_context = item.global_context.clone();

let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback =
let get_prepopulated_transaction_after_getting_network_callback: crate::commands::GetPrepopulatedTransactionAfterGettingNetworkCallback =
std::sync::Arc::new({
let new_account_id = item.account_properties.new_account_id.clone();
let signer_id = item.signer_account_id.clone();
Expand Down Expand Up @@ -149,7 +149,7 @@ impl From<SignerAccountIdContext> for crate::commands::ActionContext {
item.signer_account_id,
item.account_properties.new_account_id,
],
on_after_getting_network_callback,
get_prepopulated_transaction_after_getting_network_callback,
on_before_signing_callback: std::sync::Arc::new(
|_prepolulated_unsinged_transaction, _network_config| Ok(()),
),
Expand Down
Loading

0 comments on commit ad3447b

Please sign in to comment.