From d6a222beca34f32399d60ef742ef639c9c7a61ab Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Thu, 12 Nov 2015 18:21:15 +0100 Subject: [PATCH] passing reserve details to the wallet via DOM event (#4047) --- website/fake_wire_transfer.php | 19 ++++++++++++++++--- website/index.html | 28 ++++++++++++++++++---------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/website/fake_wire_transfer.php b/website/fake_wire_transfer.php index a788a372e..97e36e9b7 100644 --- a/website/fake_wire_transfer.php +++ b/website/fake_wire_transfer.php @@ -43,13 +43,26 @@ $reserve_pk = $_POST['reserve_pk']; $kudos_amount = $_POST['kudos_amount']; $mint = $_SERVER['SERVER_NAME']; +// check if the webform has given a well formed amount +$ret = preg_match ('/[0-9]+(\.[0-9][0-9]?)? [A-Z]+/', $kudos_amount, $matches); +if ($matches[0] != $_POST['kudos_amount']) +{ + http_response_code(400); // BAD REQUEST + echo "Malformed amount given"; + return; +} +$amount_chunks = preg_split('/[ \.]/', $_POST['kudos_amount']); +$amount_fraction = 0; +if (count($amount_chunks) > 2) + $amount_fraction = (double) ("0." . $amount_chunks[1]); +$amount_fraction = $amount_fraction * 1000000; // pack the JSON $json = json_encode (array ('reserve_pub' => $reserve_pk, 'execution_date' => "/Date(" . time() . ")/", 'wire' => array ('type' => 'test'), - 'amount' => array ('value' => intval($kudos_amount), - 'fraction' => 0, - 'currency' => 'KUDOS'))); // TODO 'KUDOS' example needs 'KUDOS' denom keys .. + 'amount' => array ('value' => intval($amount_chunks[0]), + 'fraction' => $amount_fraction, + 'currency' => $amount_chunks[count($amount_chunks) - 1]))); // craft the HTTP request $req = new http\Client\Request ("POST", diff --git a/website/index.html b/website/index.html index 4dff2a7ad..7bb9bcc1e 100644 --- a/website/index.html +++ b/website/index.html @@ -48,19 +48,21 @@ -
+

Paste your reserve public key here (right-click, "paste"): - +
Amount to credit to your reserve: - + + + + + + +
@@ -74,6 +76,11 @@ - it gets installed - it gets a 'taler-wire-mfirst' event */ + function signal_reserve(){ + var reserve_submitted = new Event("reserve-submitted"); + document.body.dispatchEvent(reserve_submitted); + }; + document.body.addEventListener("taler-wallet-present", has_taler_wallet_cb, false); @@ -89,9 +96,10 @@ function wire_funds(){ - let wallet_param = { + var wallet_param = { 'currencies' : new Array("KUDOS"), - 'input_name' : 'reserve-pk-id', + 'input_amount' : 'reserve-amn-id', + 'input_pub' : 'reserve-pk-input', 'base_url' : window.location.host }; var trigger = new CustomEvent("taler-create-reserve", {detail: wallet_param});