summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <marcello.stanisci@inria.fr>2015-11-12 18:21:15 +0100
committerMarcello Stanisci <marcello.stanisci@inria.fr>2015-11-12 18:21:15 +0100
commitd6a222beca34f32399d60ef742ef639c9c7a61ab (patch)
tree099ae9baf614228cbe84215eca0f7c886a38fb2f
parent5a12cbac296493999bbbcee46ca471d3f98685c4 (diff)
downloadexchange-d6a222beca34f32399d60ef742ef639c9c7a61ab.tar.gz
exchange-d6a222beca34f32399d60ef742ef639c9c7a61ab.tar.bz2
exchange-d6a222beca34f32399d60ef742ef639c9c7a61ab.zip
passing reserve details to the wallet via DOM event (#4047)
-rw-r--r--website/fake_wire_transfer.php19
-rw-r--r--website/index.html28
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 @@
<input id="wire-funds-button" type="button" value="Wire funds" disabled=true
onclick='wire_funds();'></input>
</div>
- <form id="reserve-form" name="tform" action="/fake_wire_transfer.php" method="POST">
+ <form id="reserve-form" name="tform" action="/fake_wire_transfer.php" method="POST" onsubmit="signal_reserve()">
<div class="participation" id="fake-wire">
<br>
Paste your reserve public key here (right-click, "paste"):
- <input type="text" name="reserve_pk"></input>
+ <input type="text" id="reserve-pk-input" name="reserve_pk"></input>
<br>
Amount to credit to your reserve:
- <select id="amount" name="kudos_amount">
- <option value="1">1 KUDOS</option>
- <option value="2">2 KUDOS</option>
- <option value="5">5 KUDOS</option>
- <option value="10">10 KUDOS</option>
- <option value="1000">1000 KUDOS</option>
+ <select id="reserve-amn-id" name="kudos_amount">
+ <option value="1 KUDOS">1 KUDOS</option>
+ <option value="2 KUDOS">2 KUDOS</option>
+ <option value="3.01 KUDOS">3.01 KUDOS</option>
+ <option value="5 KUDOS">5 KUDOS</option>
+ <option value="10 KUDOS">10 KUDOS</option>
+ <option value="10.50 KUDOS">10.50 KUDOS</option>
+ <option value="1000 KUDOS">1000 KUDOS</option>
</select>
<br>
<input type="submit" value="Submit"></input>
@@ -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});