Skip to content

Commit

Permalink
feat(wallet): auto-open browser
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwht committed Dec 17, 2024
1 parent 0e19b8a commit b2a6dcb
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 104 deletions.
37 changes: 37 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ strum_macros = "0.26"

# wallet-integration
axum = "0.7.9"
open = "5.3.1"
tower-http = "0.6.2"
1 change: 1 addition & 0 deletions crates/pop-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pop-common = { path = "../pop-common", version = "0.5.0" }

# wallet-integration
axum.workspace = true
open.workspace = true
tower-http = { workspace = true, features = ["fs", "cors"] }

[dev-dependencies]
Expand Down
202 changes: 101 additions & 101 deletions crates/pop-cli/src/assets/index.html

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions crates/pop-cli/src/common/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,22 @@ pub const USE_WALLET_PROMPT: &str = "Do you want to use your browser wallet to s
/// * `url` - Chain rpc.
/// # Returns
/// * The signed payload, if it exists.
pub async fn request_signature(call_data: Vec<u8>, url: String) -> anyhow::Result<Option<String>> {
pub async fn request_signature(call_data: Vec<u8>, rpc: String) -> anyhow::Result<Option<String>> {
let ui = FrontendFromString::new(include_str!("../assets/index.html").to_string());

let transaction_data = TransactionData::new(url, call_data);
let transaction_data = TransactionData::new(rpc, call_data);
// Starts server with random port.
let mut wallet = WalletIntegrationManager::new(ui, transaction_data, None);
log::step(format!("Wallet signing portal started at http://{}", wallet.server_url))?;
let url = wallet.server_url.clone();
log::step(format!("Wallet signing portal started at http://{url}."))?;

let spinner = spinner();
spinner.start(format!("Opening browser to http://{url}"));
let res = open::that(format!("http://{url}"));
if let Err(e) = res {
spinner.error(format!("Failed to launch browser. Please open link manually. {e}"));
}

spinner.start("Waiting for signature... Press Ctrl+C to terminate early.");
loop {
// Display error, if any.
Expand Down

0 comments on commit b2a6dcb

Please sign in to comment.