adding custom qr code generation

master
lalanza808 4 years ago
parent 34c4f8e445
commit 1bc234bd61

@ -7,6 +7,7 @@ extern crate qrcode_generator;
mod data_types;
use rocket::http::RawStr;
use rocket::request::Form;
use rocket::response::Redirect;
use rocket_contrib::json::{Json,JsonValue};
use rocket_contrib::templates::Template;
@ -104,9 +105,22 @@ fn get_transaction_by_hash(tx_hash: String) -> Template {
Template::render("transaction", context)
}
#[get("/address/<wallet_address>")]
fn show_wallet_address(wallet_address: String) -> Template {
let address_uri = format!("monero:{}", wallet_address);
#[get("/address/<wallet_address>?<tx_amount>&<tx_description>&<recipient_name>&<tx_payment_id>")]
fn show_wallet_address(
wallet_address: String,
tx_amount: Option<String>,
tx_description: Option<String>,
recipient_name: Option<String>,
tx_payment_id: Option<String>
) -> Template {
let address_uri = format!(
"monero:{}&tx_amount={}&tx_description={}&recipient_name={}&tx_payment_id={}",
wallet_address,
tx_amount.unwrap_or("".to_string()),
tx_description.unwrap_or("".to_string()),
recipient_name.unwrap_or("".to_string()),
tx_payment_id.unwrap_or("".to_string())
);
let qr_code: String = qrcode_generator::to_svg_to_string(address_uri, QrCodeEcc::Low, 256, None)
.unwrap();
let qr_code: String = base64::encode(qr_code);
@ -164,11 +178,11 @@ fn search(value: &RawStr) -> Redirect {
} else if sl == 95 {
// Equal to 95 characters is probably a wallet address.
// For this let's just redirect to the `show_wallet_address` route.
return Redirect::found(uri!(show_wallet_address: value.as_str()))
return Redirect::found(uri!(show_wallet_address: value.as_str(), "", "", "", ""))
} else if sl == 105 {
// Equal to 105 characters is probably an integrated address.
// For this let's just redirect to the `show_wallet_address` route.
return Redirect::found(uri!(show_wallet_address: value.as_str()))
return Redirect::found(uri!(show_wallet_address: value.as_str(), "", "", "", ""))
} else {
// Anything else hasn't been implemented yet
// so redirect to error response.

@ -297,3 +297,13 @@ p.subheader {
margin: 0 auto;
display: block;
}
.qr_form form {
text-align: center;
}
.qr_form form input {
width: 75%;
margin: .5em auto;
padding-bottom: 1em;
}

@ -13,23 +13,19 @@
<div class="center">
<img src="data:image/svg+xml;base64,{{ qr_code }}" width=200 class="center">
</div>
<!-- Want to generate a QR code for incoming payment?
<form action="." method="get">
<input type="text" name="amount" placeholder="Enter amount for transaction.">
<input type="submit" value="Search">
</form> -->
<div class="qr_form">
<p>Want to generate a QR code for incoming payment?</p>
<form action="" method="get">
<input type="text" name="tx_amount" placeholder="Enter amount for transaction.">
<input type="text" name="tx_payment_id" placeholder="Enter a payment ID for transaction.">
<input type="text" name="recipient_name" placeholder="Enter the name of the recipient.">
<input type="text" name="tx_description" placeholder="Enter a description for the transaction.">
<button type="submit" value="">Regenerate QR Code</button>
</form>
</div>
</section>
</div>
</div>
</section>
<!--
https://monero.fandom.com/wiki/URI_formatting
address String hierarch. The raw address (or the openalias?).
tx_payment_id String ? The proposed payment ID of the transaction.
recipient_name String ? The proposed contact name of the recipient.
tx_amount UInt64 query The proposed amount of the transaction in floating point units (eg. 5.3 XMR instead of 5300000000000)
tx_description String fragment Describes the transaction which should be initiated.
-->
{% endblock content %}

Loading…
Cancel
Save