Browse Source

send to address js code added

master
Satinder Grewal 8 years ago
parent
commit
b17b88b960
  1. 142
      assets/scripts/dashboard.js
  2. 169
      assets/scripts/iguana_api.js
  3. 20
      index.html

142
assets/scripts/dashboard.js

@ -30,7 +30,131 @@ var Dashboard = function() {
var handle_edex_send = function() {
$('#btn_edexcoin_wallet_send').click(function() {
var active_edexcoin = $('[data-edexcoin]').attr("data-edexcoin");
//console.log(active_edexcoin);
$('#edexcoin_dashboardinfo').hide();
$('#edexcoin_send').show();
$('#edexcoin_recieve_section').hide();
$('#edexcoin_settings').hide();
//Disabled dropdown list address in EasyDEX's main send option, as it's using sendtoaddress at the moment.
//This option can be enabled later for other section where user can select particular address to send funds from.
/*var edexcoin_addr_list_with_balance = EDEXlistunspent(active_edexcoin);
console.log(edexcoin_addr_list_with_balance);
var tmpoptions = '';
tmpoptions += '<option> - Select Address - </option>';
$.each(edexcoin_addr_list_with_balance, function(index) {
tmpoptions += '<option value="' + edexcoin_addr_list_with_balance[index].addr + '" data-total="' + edexcoin_addr_list_with_balance[index].total.toFixed(8) + '">[ ' + edexcoin_addr_list_with_balance[index].total.toFixed(8) + ' KMD ] &emsp;' + edexcoin_addr_list_with_balance[index].addr + '</option>';
$('#edexcoin_send_from').html(tmpoptions);
});
$('.showedexcoinaddrs').selectpicker({ style: 'btn-info' });
$('.showedexcoinaddrs').selectpicker('refresh');*/
clearEdexSendFieldData();
});
$('.showedexcoinaddrs').on('change', function(){
var selected = $(this).find("option:selected").val();
//console.log(selected);
//console.log($(this).find("option:selected").data('total'));
});
$('#edexcoin_amount').keyup(function() {
var sum_val1 = parseFloat($('#edexcoin_amount').val())
var sum_val2 = parseFloat($('#edexcoin_fee').val())
var total_minus_currency_fee = sum_val1 - sum_val2;
var mdl_send_btn = $('#edexcoin_send_coins_btn');
//console.log($('#edexcoin_amount').val());
$('#edexcoin_total_value').text(total_minus_currency_fee.toFixed(8));
if ($('#edexcoin_send_from').val() != '- Select Transparent or Private KMD Address -' && $('#edexcoin_amount').val() != '' && $('#edexcoin_sendto') != '' && $('#edexcoin_fee') != '' ) {
mdl_send_btn.removeClass('disabled');
//mdl_send_btn.attr('data-dismiss','modal');
//mdl_send_btn.attr('data-target','#SendCoinModelStep2');
} else {
mdl_send_btn.addClass('disabled');
mdl_send_btn.removeAttr('data-dismiss');
mdl_send_btn.removeAttr('data-target');
}
});
$('#edexcoin_fee').keyup(function() {
var sum_val1 = parseFloat($('#edexcoin_amount').val())
var sum_val2 = parseFloat($('#edexcoin_fee').val())
var total_minus_currency_fee = sum_val1 - sum_val2;
var mdl_send_btn = $('#edexcoin_send_coins_btn');
//console.log($('#edexcoin_amount').val());
$('#edexcoin_total_value').text(total_minus_currency_fee.toFixed(8));
if ($('#edexcoin_send_from').val() != '- Select Transparent or Private KMD Address -' && $('#edexcoin_amount').val() != '' && $('#edexcoin_sendto') != '' && $('#edexcoin_fee') != '' ) {
mdl_send_btn.removeClass('disabled');
//mdl_send_btn.attr('data-dismiss','modal');
//mdl_send_btn.attr('data-target','#SendCoinModelStep2');
} else {
mdl_send_btn.addClass('disabled');
mdl_send_btn.removeAttr('data-dismiss');
mdl_send_btn.removeAttr('data-target');
}
});
$('.edexcoin-send-form').validate({
//errorElement: 'span', //default input error message container
//errorClass: 'help-block', // default input error message class
//focusInvalid: false, // do not focus the last invalid input
rules: {
edexcoin_send_from: {
required: true
},
edexcoin_sendto: {
required: true
},
edexcoin_amount: {
required: true
},
edexcoin_fee: {
required: true
},
edexcoin_total_value: {
required: true
}
},
messages: {
edexcoin_send_from: {
required: "From Address is required."
},
edexcoin_sendto: {
required: "To Address is required."
},
edexcoin_amount: {
required: "Please enter amount to send."
},
edexcoin_fee: {
required: "Make sure you have fee entered. Default value is 0.0001."
},
edexcoin_total_value: {
required: "Make sure you have both amount and fee entered to calculate final total."
}
},
submitHandler: function(form) {
console.log('Sent control here after clicked in form...');
var active_edexcoin = $('[data-edexcoin]').attr("data-edexcoin");
var tmp_send_from_addr = $('#edexcoin_send_from').val();
var tmp_send_to_addr = $('#edexcoin_sendto').val();
var tmp_send_total_amount = $('#edexcoin_total_value').text();
var tmp_json_data = {'coin':active_edexcoin,'sendtoaddr':tmp_send_to_addr,'amount':tmp_send_total_amount};
//console.log(tmp_json_data);
var tmp_sendtoaddr_output = EDEXSendToAddr(tmp_json_data);
console.log(tmp_sendtoaddr_output);
//clearSendManyFieldData();
}
});
}
@ -290,7 +414,7 @@ var Dashboard = function() {
var active_edexcoin = $('[data-edexcoin]').attr("data-edexcoin");
ShowCoinProgressBar(active_edexcoin);
if ( sessionStorage.getItem('Activate'+active_edexcoin+'History') === 'Yes' ) {
console.log('Show coin history');
//console.log('Show coin history');
var historyvalues = {"timeout":20000,"immediate":100,"agent":"basilisk","method":"history","vals":{"coin":"" + active_edexcoin + ""}};
//ShowCoinHistory(historyvalues);
//}
@ -328,8 +452,8 @@ var Dashboard = function() {
RunTotalFiatValue = setInterval(function() {
if ( sessionStorage.getItem('IguanaActiveAccount') === null ) {
console.log('=> No wallet logged in. No need to get Rates.');
StopTotalFiatValue();
//console.log('=> No wallet logged in. No need to get Rates.');
//StopTotalFiatValue();
} else {
//TotalFiatValue();
//console.log('Get Rates (every 60 seconds)');
@ -359,10 +483,21 @@ function resizeDashboardWindow() {
function edexCoinBtnAction() {
$('.edexcoin-logo').click(function() {
console.log($(this).data('edexcoincode'));
//get selected coin's code and populate in easydex wallet widget's html elements
var coincode = $(this).data('edexcoincode');
$.each($('[data-edexcoin]'), function(index, value) {$('[data-edexcoin]').attr("data-edexcoin",coincode); $('[data-edexcoin="'+coincode+'"]')});
$.each($('[data-edexcoinmenu]'), function(index, value) {$('[data-edexcoinmenu]').attr("data-edexcoinmenu",coincode); $('[data-edexcoinmenu="'+coincode+'"]')});
$('#edexcoin-active').text(coincode);
//populate selected coin's address
var coinmainaddr = EDEXMainAddr(coincode);
$('#edexcoin_active_addr').text(coinmainaddr[0]);
//populate selected coin's balance
var coinwalletbalance = EDEXgetBalance(coincode);
$('#edex_total_balance').text(coinwalletbalance[0]);
});
}
@ -526,6 +661,7 @@ function getCoinBalance(coin) {
var ajax_data = {"agent":"bitcoinrpc","method":"getbalance","coin": coin};
//console.log(ajax_data);
$.ajax({
async: false,
type: 'POST',
data: JSON.stringify(ajax_data),
url: 'http://127.0.0.1:7778',

169
assets/scripts/iguana_api.js

@ -412,4 +412,173 @@ function Iguana_HashHex(data) {
}
});
return result;
}
function EDEXlistunspent(coin) {
NProgress.done(true);
NProgress.configure({
template: '<div class="bar nprogress-bar-header nprogress-bar-info" role="bar"></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>'
});
NProgress.start();
var result = [];
var ajax_data = {"coin":coin,"method":"listunspent","params":[]}
//console.log(ajax_data);
$.ajax({
async: false,
type: 'POST',
data: JSON.stringify(ajax_data),
url: 'http://127.0.0.1:7778',
//dataType: 'text',
success: function(data, textStatus, jqXHR) {
var AjaxOutputData = JSON.parse(data); //Ajax output gets the whole list of unspent coin with addresses
//console.log('== Data OutPut ==');
//console.log(AjaxOutputData);
var unique_addresses = _.keys(_.countBy(AjaxOutputData, function(data) { return data.address; })); //This code using undscore.js takes only the address into an array which are unique in that list
// This function calls each unique address and calculates the total amount of coins in it.
$.each(unique_addresses, function(index) {
console.log(unique_addresses[index]);
var unique_addr_tmp_array = _.where(AjaxOutputData, {address: unique_addresses[index]});
//console.log(unique_addr_tmp_array);
var tmpcalcnum = 0;
$.each(unique_addr_tmp_array, function(index, value) {
//console.log(value.amount);
tmpcalcnum = tmpcalcnum + value.amount;
});
//console.log(tmpcalcnum);
var tmp_addr_total_balance_output = {"addr": unique_addr_tmp_array[0].address, "total": tmpcalcnum};
//console.log(tmp_addr_total_balance_output);
result.push(tmp_addr_total_balance_output);
});
},
error: function(xhr, textStatus, error) {
console.log('failed getting Coin History.');
console.log(xhr.statusText);
if ( xhr.readyState == 0 ) {
Iguana_ServiceUnavailable();
}
console.log(textStatus);
console.log(error);
}
});
//console.log(result);
NProgress.done();
return result;
}
function clearEdexSendFieldData() {
$('.showedexcoinaddrs').selectpicker('refresh');
$('#edexcoin_sendto').val('');
$('#edexcoin_total_value').text('');
$('#edexcoin_amount').val('');
}
function EDEXMainAddr(coin) {
NProgress.done(true);
NProgress.configure({
template: '<div class="bar nprogress-bar-header nprogress-bar-info" role="bar"></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>'
});
NProgress.start();
var result = [];
var ajax_data = {"agent":"SuperNET","method":"activehandle"}
//console.log(ajax_data);
$.ajax({
async: false,
type: 'POST',
data: JSON.stringify(ajax_data),
url: 'http://127.0.0.1:7778',
//dataType: 'text',
success: function(data, textStatus, jqXHR) {
var AjaxOutputData = JSON.parse(data); //Ajax output gets the whole list of unspent coin with addresses
//console.log('== Data OutPut ==');
//console.log(AjaxOutputData[coin]);
result.push(AjaxOutputData[coin]);
},
error: function(xhr, textStatus, error) {
console.log('failed getting Coin History.');
console.log(xhr.statusText);
if ( xhr.readyState == 0 ) {
Iguana_ServiceUnavailable();
}
console.log(textStatus);
console.log(error);
}
});
//console.log(result);
NProgress.done();
return result;
}
function EDEXgetBalance(coin) {
var result = [];
//console.log(rmd160conv_data);
//return rmd160conv_data;
//comment
var ajax_data = {"agent":"bitcoinrpc","method":"getbalance","coin": coin};
//console.log(ajax_data);
$.ajax({
async: false,
type: 'POST',
data: JSON.stringify(ajax_data),
url: 'http://127.0.0.1:7778',
//dataType: 'text',
success: function(data, textStatus, jqXHR) {
var AjaxOutputData = JSON.parse(data);
//console.log('== Data OutPut getbalance ==');
//console.log(AjaxOutputData.result);
result.push(AjaxOutputData['result']);
},
error: function(xhr, textStatus, error) {
console.log('failed getting Coin History.');
console.log(xhr.statusText);
if ( xhr.readyState == 0 ) {
Iguana_ServiceUnavailable();
}
console.log(textStatus);
console.log(error);
}
});
return result;
}
function EDEXSendToAddr(data) {
var result = [];
var confirm_coinname_to_send = data.coin;
var confirm_send_amount = data.amount;
var confirm_sendto_address = data.sendtoaddr;
//Get parameters values from confirm dialog and send currency
var sendtoaddrvalues = {"coin": confirm_coinname_to_send,"method":"sendtoaddress","params":[confirm_sendto_address,confirm_send_amount,"EasyDEX","EasyDEXTransaction"]};
console.log(sendtoaddrvalues);
$.ajax({
async: false,
type: 'POST',
data: JSON.stringify(sendtoaddrvalues),
url: 'http://127.0.0.1:7778',
//dataType: 'text',
success: function(data, textStatus, jqXHR) {
var SendToAddrData = JSON.parse(data);
console.log('== Data OutPut ==');
//console.log(SendToAddrData);
result.push(SendToAddrData);
},
error: function(xhr, textStatus, error) {
console.log('failed getting Coin History.');
console.log(xhr.statusText);
if ( xhr.readyState == 0 ) {
Iguana_ServiceUnavailable();
}
console.log(textStatus);
console.log(error);
}
});
return result;
}

20
index.html

@ -465,9 +465,7 @@
<!-- Begin page header -->
<div class="page-header page-header-bordered header-easydex" id="header-dashboard" data-edexcoin="COIN">
<ol class="breadcrumb" data-edexcoin="COIN">
<li>Dashboard</li>
<li>Wallet</li>
<li class="active" data-edexcoin="COIN" id="edexcoin-active">COIN</li>
<b>My <span data-edexcoin="COIN" id="edexcoin-active">-</span> Address: </b> <span data-edexcoin="COIN" id="edexcoin_active_addr">-</span>
</ol>
<div class="page-header-actions" data-edexcoin="COIN" id="edexcoin-actions">
<!-- EasyDEX Coin Wallet Header button -->
@ -535,7 +533,7 @@
<!-- EasyDEX Panel send -->
<div class="panel" id="projects">
<div class="panel-heading">
<h3 data-edexcoin="COIN" class="panel-title">Send <span data-edexcoinname="COIN"></span></h3>
<h3 data-edexcoin="COIN" class="panel-title">Send <span data-edexcoin="COIN"></span></h3>
<!--<div class="panel-actions">
<a class="panel-action icon md-refresh-alt" data-toggle="panel-refresh" data-load-type="blue-only"
data-load-callback="KMDSendScreenRefreshCallback" aria-hidden="true"></a>
@ -544,17 +542,17 @@
<div class="panel-body container-fluid">
<form class="edexcoin-send-form" data-edexcoin="COIN" method="post" role="form" autocomplete="off" onsubmit="return false;">
<div class="row">
<div class="col-xlg-12 form-group form-material">
<!--<div class="col-xlg-12 form-group form-material">
<label class="control-label" data-edexcoin="COIN" for="edexcoin_send_from">Send From</label>
<select class="form-control form-material showkmdwalletaddrs show-tick" data-edexcoin="COIN" id="edexcoin_send_from" title="Select Transparent or Private Address" data-size="5">
<select class="form-control form-material showedexcoinaddrs show-tick" data-edexcoin="COIN" id="edexcoin_send_from" title="Select Transparent or Private Address" data-size="5">
</select>
</div>
</div>-->
<div class="col-xlg-12 form-group form-material">
<label class="control-label" data-edexcoin="COIN" for="edexcoin_sendto">Send To</label>
<input type="text" class="form-control" data-edexcoin="COIN" id="edexcoin_sendto" name="edexcoin_sendto" placeholder="Enter Transparent or Private address" autocomplete="off" required/>
<input type="text" class="form-control" data-edexcoin="COIN" id="edexcoin_sendto" name="edexcoin_sendto" placeholder="Enter address" autocomplete="off" required/>
</div>
<div class="col-lg-6 form-group form-material">
<label class="control-label" for="edexcoin_amount" data-edexcoin="COIN" id="edexcoin_amount_label"><span data-edexcoinname="COIN"></span></label>
<label class="control-label" for="edexcoin_amount" data-edexcoin="COIN" id="edexcoin_amount_label"><span data-edexcoin="COIN"></span></label>
<input type="text" class="form-control" data-edexcoin="COIN" id="edexcoin_amount" name="edexcoin_amount" placeholder="0.000" autocomplete="off"/>
</div>
<div class="col-lg-6 form-group form-material">
@ -562,10 +560,10 @@
<input type="text" class="form-control" data-edexcoin="COIN" id="edexcoin_fee" name="edexcoin_fee" placeholder="0.000" value="0.0001" autocomplete="off"/>
</div>
<div class="col-lg-12">
<span data-edexcoin="KMD"><b>Total (<span data-edexcoinname="COIN"></span> - txfee):</b> <span data-edexcoin="COIN" id="edexcoin_total_value">0.000</span> <span data-edexcoin="COIN" id="edexcoin_total_coinname" data-edexcoinname="COIN"></span></span>
<span data-edexcoin="KMD"><b>Total (<span data-edexcoin="COIN">amount</span> - txfee):</b> <span data-edexcoin="COIN" id="edexcoin_total_value">0.000</span> <span data-edexcoin="COIN" id="edexcoin_total_coinname" data-edexcoin="COIN"></span></span>
</div>
<div class="col-lg-12">
<button type="submit" class="btn btn-primary waves-effect waves-light pull-right" data-toggle="modal" id="edexcoin_send_coins_btn">Send <span data-edexcoinname="COIN"></span></button>
<button type="submit" class="btn btn-primary waves-effect waves-light pull-right" data-toggle="modal" id="edexcoin_send_coins_btn">Send <span data-edexcoin="COIN"></span></button>
</div>
</div>
</div>

Loading…
Cancel
Save