Skip to content

Commit

Permalink
Only show faucet URL for non-mainnet targets
Browse files Browse the repository at this point in the history
  • Loading branch information
alfiedotwtf committed Oct 8, 2024
1 parent c77c37a commit a75450a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
1 change: 0 additions & 1 deletion forc-plugins/forc-client/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub const BETA_4_FAUCET_URL: &str = "https://faucet-beta-4.fuel.network";
pub const BETA_5_FAUCET_URL: &str = "https://faucet-beta-5.fuel.network";
pub const DEVNET_FAUCET_URL: &str = "https://faucet-devnet.fuel.network";
pub const TESTNET_FAUCET_URL: &str = "https://faucet-testnet.fuel.network";
pub const MAINNET_FAUCET_URL: &str = "https://faucet-mainnet.fuel.network";

pub const TESTNET_EXPLORER_URL: &str = "https://app.fuel.network";
pub const MAINNET_EXPLORER_URL: &str = "https://app.fuel.network";
Expand Down
18 changes: 9 additions & 9 deletions forc-plugins/forc-client/src/util/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ impl Target {
Target::Mainnet
}

pub fn faucet_url(&self) -> String {
pub fn faucet_url(&self) -> Option<String> {
match self {
Target::Beta2 => BETA_2_FAUCET_URL.to_string(),
Target::Beta3 => BETA_3_FAUCET_URL.to_string(),
Target::Beta4 => BETA_4_FAUCET_URL.to_string(),
Target::Beta5 => BETA_5_FAUCET_URL.to_string(),
Target::Devnet => DEVNET_FAUCET_URL.to_string(),
Target::Testnet => TESTNET_FAUCET_URL.to_string(),
Target::Mainnet => TESTNET_FAUCET_URL.to_string(),
Target::Local => "http://localhost:3000".to_string(),
Target::Beta2 => Some(BETA_2_FAUCET_URL.to_string()),
Target::Beta3 => Some(BETA_3_FAUCET_URL.to_string()),
Target::Beta4 => Some(BETA_4_FAUCET_URL.to_string()),
Target::Beta5 => Some(BETA_5_FAUCET_URL.to_string()),
Target::Devnet => Some(DEVNET_FAUCET_URL.to_string()),
Target::Testnet => Some(TESTNET_FAUCET_URL.to_string()),
Target::Mainnet => None,
Target::Local => Some("http://localhost:3000".to_string()),
}
}

Expand Down
17 changes: 12 additions & 5 deletions forc-plugins/forc-client/src/util/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,18 @@ pub(crate) async fn select_account(
.get(&0)
.ok_or_else(|| anyhow::anyhow!("No account derived for this wallet"))?;
let target = Target::from_str(&chain_info.name).unwrap_or_default();
let faucet_link = format!("{}/?address={first_account}", target.faucet_url());
anyhow::bail!("Your wallet does not have any funds to pay for the transaction.\
\n\nIf you are interacting with a testnet consider using the faucet.\
\n-> {target} network faucet: {faucet_link}\
\nIf you are interacting with a local node, consider providing a chainConfig which funds your account.")
let message = if let Some(faucet_url) = target.faucet_url() {
format!(
"Your wallet does not have any funds to pay for the transaction.\
\n\nIf you are interacting with a testnet, consider using the faucet.\
\n-> {target} network faucet: {}/?address={first_account}\
\nIf you are interacting with a local node, consider providing a chainConfig which funds your account.",
faucet_url
)
} else {
"Your wallet does not have any funds to pay for the transaction.".to_string()
};
anyhow::bail!(message)
}
let selections =
format_base_asset_account_balances(&accounts, &account_balances, base_asset_id);
Expand Down

0 comments on commit a75450a

Please sign in to comment.