From b7364c73c4cdc2e0e0db4bd6cd5823bd69d5b1ea Mon Sep 17 00:00:00 2001 From: Satinder Grewal Date: Tue, 28 Feb 2017 00:54:36 +1300 Subject: [PATCH 1/3] updated functions in iguana api --- assets/scripts/iguana_api.js | 90 +++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/assets/scripts/iguana_api.js b/assets/scripts/iguana_api.js index 096cf0d..acd5849 100644 --- a/assets/scripts/iguana_api.js +++ b/assets/scripts/iguana_api.js @@ -1943,7 +1943,7 @@ function Shepherd_herdlist(data) { }); } -function Shepherd_FetchBasiliskData() { +function Shepherd_FetchBasiliskData(req_data) { return new Promise((resolve) => { var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), parse_session_data = sessionStorage.getItem('IguanaActiveAccount'); @@ -1956,10 +1956,20 @@ function Shepherd_FetchBasiliskData() { 'pubkey': session_pubkey }; + if (req_data.allcoins !== false ) { + var req_url = 'http://127.0.0.1:17777/shepherd/allcoins' + } else { + var req_url = 'http://127.0.0.1:17777/shepherd/cache-one' + ajax_data.coin = req_data.coin + ajax_data.calls = req_data.calls + } + + console.log(ajax_data) + $.ajax({ type: 'GET', data: ajax_data, - url: 'http://127.0.0.1:17777/shepherd/allcoins', + url: req_url, contentType: 'application/json', // send as JSON }).done(function(data) { resolve(data); @@ -1984,4 +1994,80 @@ function Shepherd_GetBasiliskCache() { resolve(data); }); }); +} + + +function Shepherd_CheckBasiliskCacheData(coin) { + return new Promise((resolve) => { + Shepherd_GetBasiliskCache().then(function(result){ + var _data = JSON.parse(result) + var query = _data.result.basilisk + coin_exists = true + addresses_exists = true + getbalance_exists = true + listtransactions_exists = true + listunspent_exists = true + refresh_exists = true + //console.log(query) + + if (!query) { + console.log('data not found.') + res_data = {"coin":false, "addresses":false, "getbalance": false,"listtransactions": false,"listunspent": false,"refresh": false} + //console.log(res_data) + resolve(res_data) + } else if (!query[coin]) { + console.log(coin + ' not found.') + coin_exists = false + res_data = {"coin":coin_exists, "addresses":false, "getbalance": false,"listtransactions": false,"listunspent": false,"refresh": false} + //console.log(res_data) + resolve(res_data) + } else if (!('addresses' in query[coin])) { + console.log(coin + ' addresses not found.') + addresses_exists = false + res_data = {"coin":coin_exists, "addresses":false, "getbalance": false,"listtransactions": false,"listunspent": false,"refresh": false} + //console.log(res_data) + resolve(res_data) + } else { + Promise.all(query[coin].addresses.map((coinaddr_value,coinaddr_index) => { + return new Promise((resolve, reject) => { + //console.log(coinaddr_index) + //console.log(coinaddr_value) + var data = query[coin][coinaddr_value].getbalance + + if (!('getbalance' in query[coin][coinaddr_value])) { + //console.log(coin + '>>>' + coinaddr_value + ' => getbalance not found.') + getbalance_exists = false + } + + if (!('listtransactions' in query[coin][coinaddr_value])) { + //console.log(coin + '>>>' + coinaddr_value + ' => listtransactions not found.') + listtransactions_exists = false + } + + if (!('listunspent' in query[coin][coinaddr_value])) { + //console.log(coin + '>>>' + coinaddr_value + ' => listunspent not found.') + listunspent_exists = false + } + + if (!('refresh' in query[coin][coinaddr_value])) { + //console.log(coin + '>>>' + coinaddr_value + ' => refresh not found.') + refresh_exists = false + } + + pass_data = {"getbalance": getbalance_exists,"listtransactions": listtransactions_exists,"listunspent": listunspent_exists,"refresh": refresh_exists} + resolve(pass_data) + }) + })).then(result => { + //console.log(result) + //console.log(result[result.length-1]) + var res_data = result[result.length-1] + res_data.coin = coin_exists + res_data.addresses = addresses_exists + //console.log(res_data) + resolve(res_data) + }) + } + + }) + }) } \ No newline at end of file From 1aad8bec2dea9b58111232c26c0f2c57aa3bfe39 Mon Sep 17 00:00:00 2001 From: Satinder Grewal Date: Tue, 28 Feb 2017 02:32:10 +1300 Subject: [PATCH 2/3] trigger data fetch if data is not available for basilisk coin --- assets/scripts/dashboard.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/assets/scripts/dashboard.js b/assets/scripts/dashboard.js index a164e76..0c1bf69 100644 --- a/assets/scripts/dashboard.js +++ b/assets/scripts/dashboard.js @@ -1116,6 +1116,22 @@ function getDEXGetBalance_cache(coin) { NProgress.start(); return new Promise((resolve) => { + Shepherd_CheckBasiliskCacheData(coin).then(function(result){ + console.log(result) + console.log(result.coin) + if (result.coin == false || result.addresses == false) { + var call_data = {"allcoins": false,"coin":coin,"calls":"listunspent:listtransactions:getbalance:refresh"} + console.log(call_data) + } else if (result.getbalance == false) { + var call_data = {"allcoins": false,"coin":coin,"calls":"getbalance"} + console.log(call_data) + } + + Shepherd_FetchBasiliskData(call_data).then(function(result){ + console.log(result) + }) + }) + Shepherd_GetBasiliskCache().then(function(result) { var _data = JSON.parse(result), query = _data.result.basilisk, @@ -1124,8 +1140,8 @@ function getDEXGetBalance_cache(coin) { Promise.all(query[coin].addresses.map((coinaddr_value,coinaddr_index) => { return new Promise((resolve, reject) => { - if ( query[coin][coinaddr_value].getbalance !== undefined ) { - var data = query[coin][coinaddr_value].getbalance; + if ( query[coin][coinaddr_value].getbalance.data !== undefined ) { + var data = query[coin][coinaddr_value].getbalance.data; total_balance = parseFloat(total_balance) + parseFloat(data.balance); if (data.interest !== undefined) { @@ -1973,7 +1989,7 @@ function EdexGetTxList_cache(coin) { Promise.all(query[coin].addresses.map((coinaddr_value, coinaddr_index) => { return new Promise((resolve, reject) => { - var data = query[coin][coinaddr_value].listtransactions; + var data = query[coin][coinaddr_value].listtransactions.data; total_utxos = $.merge(total_utxos, data); resolve(total_utxos); From ca997a36751fdbecb4118fddf49cab9fecedfa66 Mon Sep 17 00:00:00 2001 From: Satinder Grewal Date: Tue, 28 Feb 2017 06:12:01 +1300 Subject: [PATCH 3/3] fix displaying balance boxes in different wallets --- assets/scripts/dashboard.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/assets/scripts/dashboard.js b/assets/scripts/dashboard.js index 0c1bf69..43e206e 100644 --- a/assets/scripts/dashboard.js +++ b/assets/scripts/dashboard.js @@ -36,7 +36,17 @@ var Dashboard = function() { $('#btn_edexcoin_dashboard').hide(); $('#btn_edexcoin_send').show(); $('#btn_edexcoin_recieve').show(); + var active_edexcoin = $('[data-edexcoin]').attr('data-edexcoin'); + + $('#edexcoin_getbalance_interest').hide(); + $('#edexcoin_getbalance_total_interest').hide(); + $('#edexcoin_getbalance_t').removeClass( 'col-lg-4' ).addClass( 'col-lg-12' ); + $('#edex_interest_balance').text('-'); + $('#edex_total_balance_interest').text('-'); + $('#edex_total_balance').text('-'); + $('#edex_total_balance_coincode').text(active_edexcoin); + if ( sessionStorage.getItem('edexTmpMode') === 'Full') { sessionStorage.setItem('edexTmpRefresh', 'start'); } @@ -54,7 +64,7 @@ var Dashboard = function() { if ( selected_coinmode == 'Basilisk' ) { getDEXGetBalance_cache(active_edexcoin).then(function(result) { console.log(result) - if ( result.interest !== undefined ) { + if ( result.interest !== undefined && active_edexcoin == 'KMD') { $('#edexcoin_getbalance_interest').show(); $('#edexcoin_getbalance_total_interest').show(); $('#edexcoin_getbalance_t').removeClass( 'col-lg-12' ).addClass( 'col-lg-4' ); @@ -773,6 +783,14 @@ function edexCoinBtnAction() { selected_coinmode = $(this).data('edexcoinmodecode'), selected_coinname = $(this).data('edexcoinname'); + $('#edexcoin_getbalance_interest').hide(); + $('#edexcoin_getbalance_total_interest').hide(); + $('#edexcoin_getbalance_t').removeClass( 'col-lg-4' ).addClass( 'col-lg-12' ); + $('#edex_interest_balance').text('-'); + $('#edex_total_balance_interest').text('-'); + $('#edex_total_balance').text('-'); + $('#edex_total_balance_coincode').text(selected_coin); + sessionStorage.setItem('edexTmpMode', selected_coinmode); resizeDashboardWindow(); @@ -859,7 +877,7 @@ function edexCoinBtnAction() { selected_coin !== 'ANC' && selected_coin !== 'FRK') { getDEXGetBalance_cache(selected_coin).then(function(result) { - if ( result.interest !== undefined ) { + if ( result.interest !== undefined && selected_coin == 'KMD') { $('#edexcoin_getbalance_interest').show(); $('#edexcoin_getbalance_total_interest').show(); $('#edexcoin_getbalance_t').removeClass( 'col-lg-12' ).addClass( 'col-lg-4' ); @@ -1120,10 +1138,10 @@ function getDEXGetBalance_cache(coin) { console.log(result) console.log(result.coin) if (result.coin == false || result.addresses == false) { - var call_data = {"allcoins": false,"coin":coin,"calls":"listunspent:listtransactions:getbalance:refresh"} + var call_data = {"allcoins": false,"coin":coin,"calls":"listunspent:listtransactions:getbalance"} console.log(call_data) - } else if (result.getbalance == false) { - var call_data = {"allcoins": false,"coin":coin,"calls":"getbalance"} + } else if (result.getbalance == false || result.listtransactions == false) { + var call_data = {"allcoins": false,"coin":coin,"calls":"getbalance:listtransactions"} console.log(call_data) }