passing reserve details to the wallet via DOM event (#4047)
This commit is contained in:
parent
5a12cbac29
commit
d6a222beca
@ -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",
|
||||
|
@ -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});
|
||||
|
Loading…
Reference in New Issue
Block a user