Buy Bitcoin (#398)

* Add fiat on-ramp service

* Use sdk-common MoonpayProvider

* Bump flutter qr dependency

* Bump sdk-common dependency
This commit is contained in:
Ross Savage
2024-07-19 14:57:51 +02:00
committed by GitHub
parent 970489ccfa
commit bfeb785221
25 changed files with 1663 additions and 21 deletions

View File

@@ -54,6 +54,13 @@ pub(crate) enum Command {
/// Amount the payer will send, in satoshi
payer_amount_sat: u64,
},
/// Generates an URL to buy bitcoin from a 3rd party provider
BuyBitcoin {
provider: BuyBitcoinProvider,
/// Amount to buy, in satoshi
amount_sat: u64,
},
/// List incoming and outgoing payments
ListPayments {
/// The optional from unix timestamp
@@ -293,6 +300,37 @@ pub(crate) async fn handle_command(
result.push_str(&build_qr_text(&bip21));
result
}
Command::BuyBitcoin {
provider,
amount_sat,
} => {
let prepare_res = sdk
.prepare_buy_bitcoin(&PrepareBuyBitcoinRequest {
provider,
amount_sat,
})
.await?;
wait_confirmation!(
format!(
"Fees: {} sat. Are the fees acceptable? (y/N) ",
prepare_res.fees_sat
),
"Buy Bitcoin halted"
);
let url = sdk
.buy_bitcoin(&BuyBitcoinRequest {
prepare_res,
redirect_url: None,
})
.await?;
let mut result = command_result!(url.clone());
result.push('\n');
result.push_str(&build_qr_text(&url));
result
}
Command::GetInfo => {
command_result!(sdk.get_info().await?)
}