Browse Source

Rates API implementation - Partial base code

master
Satinder Grewal 9 years ago
parent
commit
05e730b03c
  1. 15
      assets/scripts/coinwallets.js
  2. 53
      assets/scripts/dashboard.js
  3. 28
      index.html

15
assets/scripts/coinwallets.js

@ -5,6 +5,12 @@ $(document).ready(function() {
//console.log('EhLoe!');
//$('button[id="currency-send"]').on('click', function(){console.log($(this).data('currency'));});
//By default set USD as Fiat Currency if there's none selected already.
if ( localStorage.getItem('EasyDEX_FiatCurrency') == null ) {
var FiatCurrency = '';
FiatCurrency = 'USD';
localStorage.setItem('EasyDEX_FiatCurrency', FiatCurrency);
}
});
// Functions =============================================================
@ -130,6 +136,11 @@ function ExecuteSendCurrencyAPI() {
//Used this function to set desired Fiat Currency, selected from top menu bar of EasyDEX UI
function WalletFiatCurrency(fiat_currency_value) {
//console.log(fiat_currency_value);
var FiatCurrency = fiat_currency_value.fiatcurrency;
localStorage.setItem('EasyDEX_FiatCurrency', FiatCurrency);
//console.log(localStorage.getItem('EasyDEX_FiatCurrency'));
}

53
assets/scripts/dashboard.js

@ -201,6 +201,14 @@ var Dashboard = function() {
//console.log(testhistory.sent);
$('span[data-currency="' + AllcoinsDataOutput[value][index] + '"][id="currency-balance"]').text(CoinHistoryData.balance);
//Update Dashboard Header values as well
if ( AllcoinsDataOutput[value][index] == 'BTC' || AllcoinsDataOutput[value][index] == 'BTCD' ) {
$('span[data-currency="' + AllcoinsDataOutput[value][index] + '"][id="header_coinbalance"]').text(CoinHistoryData.balance);
}
//Calculate Total Fiat Value of BTC/BTCD in Fiat and disaply on Dashboard
TotalFiatValue();
var show_coin_history = CoinHistoryData; //Enable to get history from each coins's wallet address.
//var show_coin_history = testhistory; //Enable to get history from just test variable.
@ -340,4 +348,49 @@ function SwitchBasicliskFull(switch_data) {
}
}
});
}
function TotalFiatValue() {
var BTC_balance = $('div[data-currency="BTC"][id="header_coinbalance"]').text();
var BTCD_balance = $('div[data-currency="BTCD"][id="header_coinbalance"]').text();
var Fiat_Currency = localStorage.getItem('EasyDEX_FiatCurrency');
var BTC_Fiat_pair_value = '';
var Conversion_Fiat_Pair = '';
if ( Fiat_Currency == 'USD' ) {
BTC_Fiat_pair_value = 'BTC/'+Fiat_Currency;
Conversion_Fiat_Pair = 'EUR/USD';
} else {
BTC_Fiat_pair_value = 'BTC/USD';
Conversion_Fiat_Pair = Fiat_Currency+'/USD';
}
console.log(BTC_balance);
console.log(BTCD_balance);
var TotalFiatValueData = {"agent":"iguana","method":"rates","quotes":["BTCD/BTC", BTC_Fiat_pair_value, Conversion_Fiat_Pair]};
console.log(TotalFiatValueData);
//Get Rates
$.ajax({
type: 'POST',
data: JSON.stringify(TotalFiatValueData),
url: 'http://127.0.0.1:7778',
//dataType: 'text',
success: function(data, textStatus, jqXHR) {
var RatesData = JSON.parse(data);
var label_color = '';
var label_icon = '';
var wallettblContent = '';
console.log('== Rates Data OutPut ==');
console.log(RatesData.rates[1]);
},
error: function(xhr, textStatus, error) {
console.log('failed getting Coin History.');
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
}
});
}

28
index.html

@ -177,23 +177,27 @@
</a>
<ul class="dropdown-menu" role="menu">
<li role="presentation">
<a href="javascript:void(0)" role="menuitem">
<span class="icon fa-gbp"></span> USD</a>
<a href="javascript:void(0)" role="menuitem" data-fiatcurrency="USD" onclick="WalletFiatCurrency($(this).data())">
<span class="icon fa-usd"></span> USD</a>
</li>
<li role="presentation">
<a href="javascript:void(0)" role="menuitem">
<a href="javascript:void(0)" role="menuitem" data-fiatcurrency="GBP" onclick="WalletFiatCurrency($(this).data())">
<span class="icon fa-gbp"></span> GBP</a>
</li>
<li role="presentation">
<a href="javascript:void(0)" role="menuitem" data-fiatcurrency="EUR" onclick="WalletFiatCurrency($(this).data())">
<span class="icon fa-eur"></span> EURO</a>
</li>
<li role="presentation">
<a href="javascript:void(0)" role="menuitem">
<a href="javascript:void(0)" role="menuitem" data-fiatcurrency="CNY" onclick="WalletFiatCurrency($(this).data())">
<span class="icon fa-cny"></span> CNY</a>
</li>
<li role="presentation">
<a href="javascript:void(0)" role="menuitem">
<a href="javascript:void(0)" role="menuitem" data-fiatcurrency="JPY" onclick="WalletFiatCurrency($(this).data())">
<span class="icon fa-jpy"></span> JPY</a>
</li>
<li role="presentation">
<a href="javascript:void(0)" role="menuitem">
<a href="javascript:void(0)" role="menuitem" data-fiatcurrency="INR" onclick="WalletFiatCurrency($(this).data())">
<span class="icon fa-inr"></span> INR</a>
</li>
</ul>
@ -263,20 +267,20 @@
<div class="row no-space width-250 hidden-xs">
<div class="col-xs-4">
<div class="counter">
<span class="counter-number font-weight-medium">BTC</span>
<div class="counter-label">0.043235</div>
<span class="counter-number font-weight-medium" data-currency="BTC" id="header_coinname">BTC</span>
<div class="counter-label" data-currency="BTC" id="header_coinbalance">0.45</div>
</div>
</div>
<div class="col-xs-4">
<div class="counter">
<span class="counter-number font-weight-medium">BTCD</span>
<div class="counter-label">4.9888</div>
<span class="counter-number font-weight-medium" data-currency="BTCD" id="header_coinname">BTCD</span>
<div class="counter-label" data-currency="BTCD" id="header_coinbalance">398.546</div>
</div>
</div>
<div class="col-xs-4">
<div class="counter">
<span class="counter-number font-weight-medium">USD</span>
<div class="counter-label">$38,823</div>
<span class="counter-number font-weight-medium" data-currency="USD" id="header_fiatname">USD</span>
<div class="counter-label" data-currency="USD" id="header_fiattotalbalance">0</div>
</div>
</div>
</div>

Loading…
Cancel
Save