Browse Source

partial cache file basilisk support

all-modes
pbca26 8 years ago
parent
commit
5329bb7801
  1. 153
      react/src/actions/actionCreators.js
  2. 16
      react/src/components/dashboard/coinTileItem.js
  3. 22
      react/src/components/dashboard/walletsData.js
  4. 2
      react/src/config.js
  5. 4
      react/src/translate/en.js

153
react/src/actions/actionCreators.js

@ -700,17 +700,41 @@ export function getBasiliskTransactionsList(coin, address) {
'symbol': coin
};
return dispatch => {
return fetch('http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.basiliskPort : Config.iguanaCorePort), {
method: 'POST',
body: JSON.stringify(payload),
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'getBasiliskTransactionsList', 'Error', 'error'));
})
.then(response => response.json())
.then(json => dispatch(getNativeTxHistoryState(json)))
if (sessionStorage.getItem('useCache')) {
const pubkey = JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey;
return dispatch => {
return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'getBasiliskTransactionsList+cache', 'Error', 'error'));
})
.then(response => response.json())
.then(function(json) {
json = json.result.basilisk;
if (json[coin][address].listtransactions) {
dispatch(getNativeTxHistoryState({ 'result': json[coin][address].listtransactions.data }));
}
})
}
} else {
return dispatch => {
return fetch('http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.basiliskPort : Config.iguanaCorePort), {
method: 'POST',
body: JSON.stringify(payload),
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'getBasiliskTransactionsList', 'Error', 'error'));
})
.then(response => response.json())
.then(json => dispatch(getNativeTxHistoryState(json)))
}
}
}
@ -942,16 +966,38 @@ export function getKMDAddressesNative(coin, mode, currentAddress) {
};
}
fetch('http://127.0.0.1:' + Config.iguanaCorePort, {
method: 'POST',
body: JSON.stringify(payload),
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'getKMDAddressesNative', 'Error', 'error'));
})
.then(response => response.json())
.then(json => resolve(json))
if (sessionStorage.getItem('useCache') && mode === 'basilisk') {
const pubkey = JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey;
fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'getKMDAddressesNative+addresslist+cache', 'Error', 'error'));
})
.then(response => response.json())
.then(function(json) {
json = json.result.basilisk;
if (json[coin].addresses) {
resolve({ 'result': json[coin].addresses });
}
})
} else {
fetch('http://127.0.0.1:' + Config.iguanaCorePort, {
method: 'POST',
body: JSON.stringify(payload),
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'getKMDAddressesNative', 'Error', 'error'));
})
.then(response => response.json())
.then(json => resolve(json))
}
});
}))
.then(result => {
@ -1002,16 +1048,7 @@ export function getKMDAddressesNative(coin, mode, currentAddress) {
};
}
fetch('http://127.0.0.1:' + (Config.useBasiliskInstance && mode === 'basilisk' ? Config.basiliskPort : Config.iguanaCorePort), {
method: 'POST',
body: JSON.stringify(payload),
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'getKMDAddressesNative+Balance', 'Error', 'error'));
})
.then(response => response.json())
.then(function(json) {
function calcBalance(result, json, dispatch, mode) {
if (mode === 'full' || mode === 'basilisk') {
result[0] = result[0].result;
}
@ -1072,7 +1109,58 @@ export function getKMDAddressesNative(coin, mode, currentAddress) {
'public': newAddressArray[0],
'private': newAddressArray[1]
}));
})
}
if (sessionStorage.getItem('useCache') && mode === 'basilisk') {
const pubkey = JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey;
fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'getKMDAddressesNative+addresslist+cache', 'Error', 'error'));
})
.then(response => response.json())
.then(function(json) {
json = json.result.basilisk;
// if listunspent is not in cache file retrieve new copy
// otherwise read from cache data
// TODO: save listunspent to cache file(?)
if (json[coin][currentAddress].listunspent) {
calcBalance(result, json[coin][currentAddress].listunspent, dispatch, mode);
} else {
fetch('http://127.0.0.1:' + (Config.useBasiliskInstance && mode === 'basilisk' ? Config.basiliskPort : Config.iguanaCorePort), {
method: 'POST',
body: JSON.stringify(payload),
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'getKMDAddressesNative+Balance', 'Error', 'error'));
})
.then(response => response.json())
.then(function(json) {
calcBalance(result, json, dispatch, mode);
})
}
})
} else {
fetch('http://127.0.0.1:' + (Config.useBasiliskInstance && mode === 'basilisk' ? Config.basiliskPort : Config.iguanaCorePort), {
method: 'POST',
body: JSON.stringify(payload),
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'getKMDAddressesNative+Balance', 'Error', 'error'));
})
.then(response => response.json())
.then(function(json) {
calcBalance(result, json, dispatch, mode);
})
}
})
}
}
@ -1788,7 +1876,6 @@ export function fetchNewCacheData(_payload) {
_calls = '&calls=' + _payload.calls,
_iguanaInstancePort = Config.useBasiliskInstance ? '&port=' + Config.basiliskPort : '';
console.log('fetchNewCacheData', 'http://127.0.0.1:' + Config.agamaPort + '/shepherd/' + _route + _userpass + _pubkey + _coin + _calls + _iguanaInstancePort);
return dispatch => {
return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/' + _route + _userpass + _pubkey + _coin + _calls + _iguanaInstancePort, {
method: 'GET',

16
react/src/components/dashboard/coinTileItem.js

@ -15,7 +15,8 @@ import {
getKMDOPID,
getFullTransactionsList,
getBasiliskTransactionsList,
getShepherdCache
getShepherdCache,
fetchNewCacheData
} from '../../actions/actionCreators';
import Store from '../../store';
@ -34,6 +35,7 @@ class CoinTileItem extends React.Component {
dashboardChangeActiveCoin(coin, mode) {
if (coin !== this.props.ActiveCoin.coin) {
Store.dispatch(stopInterval('sync', this.props.Interval.interval));
Store.dispatch(stopInterval('basilisk', this.props.Interval.interval));
Store.dispatch(dashboardChangeActiveCoin(coin, mode));
if (mode === 'full') {
@ -67,7 +69,19 @@ class CoinTileItem extends React.Component {
Store.dispatch(iguanaEdexBalance(coin, mode));
}
}.bind(this), 3000);
var _basiliskCache = setInterval(function() {
if (sessionStorage.getItem('useCache')) {
Store.dispatch(fetchNewCacheData({
'pubkey': this.props.Dashboard.activeHandle.pubkey,
'allcoins': false,
'coin': this.props.ActiveCoin.coin,
'calls': 'listtransactions:getbalance',
}));
}
}.bind(this), 60000);
Store.dispatch(startInterval('sync', _iguanaActiveHandle));
Store.dispatch(startInterval('basilisk', _basiliskCache));
// basilisk
}
}

22
react/src/components/dashboard/walletsData.js

@ -39,6 +39,7 @@ class WalletsData extends React.Component {
addressSelectorOpen: false,
currentStackLength: 0,
totalStackLength: 0,
useCache: sessionStorage.getItem('useCache'),
};
this.updateInput = this.updateInput.bind(this);
this.toggleBasiliskActionsMenu = this.toggleBasiliskActionsMenu.bind(this);
@ -49,9 +50,18 @@ class WalletsData extends React.Component {
this.refreshTxList = this.refreshTxList.bind(this);
this.removeAndFetchNewCache = this.removeAndFetchNewCache.bind(this);
this._toggleViewCacheModal = this._toggleViewCacheModal.bind(this);
this.toggleCacheApi = this.toggleCacheApi.bind(this);
socket.on('messages', msg => this.updateSocketsData(msg));
}
toggleCacheApi() {
console.log('useCache is set to', !this.state.useCache);
sessionStorage.setItem('useCache', !this.state.useCache);
this.setState(Object.assign({}, this.state, {
useCache: !this.state.useCache,
}));
}
_toggleViewCacheModal() {
Store.dispatch(toggleViewCacheModal(!this.props.Dashboard.displayViewCacheModal));
}
@ -397,17 +407,17 @@ class WalletsData extends React.Component {
<i className="icon wb-refresh" aria-hidden="true"></i> {translate('INDEX.REFRESH_BASILISK_CONNECTIONS')}
</a>
</li>
<li data-edexcoin="COIN" role="presentation">
<li data-edexcoin="COIN" role="presentation" className={!this.state.useCache ? 'hide' : ''}>
<a className="btn_edexcoin_dashboard_fetchdata" data-edexcoin="COIN" id="btn_edexcoin_dashboard_fetchdata" role="menuitem" onClick={this.basiliskRefreshAction}>
<i className="icon fa-cloud-download" aria-hidden="true"></i> {translate('INDEX.FETCH_WALLET_DATA')}
</a>
</li>
<li data-edexcoin="COIN" role="presentation">
<li data-edexcoin="COIN" role="presentation" className={!this.state.useCache ? 'hide' : ''}>
<a className="btn_edexcoin_dashboard_refetchdata" data-edexcoin="COIN" id="btn_edexcoin_dashboard_refetchdata" role="menuitem" onClick={this.removeAndFetchNewCache}>
<i className="icon fa-history" aria-hidden="true"></i> {translate('INDEX.REFETCH_WALLET_DATA')}
</a>
</li>
<li data-edexcoin="COIN" role="presentation">
<li data-edexcoin="COIN" role="presentation" className={!this.state.useCache ? 'hide' : ''}>
<a className="btn_edexcoin_dashboard_fetchdata" role="menuitem" onClick={this._toggleViewCacheModal}>
<i className="icon fa-list-alt" aria-hidden="true"></i> {translate('INDEX.VIEW_CACHE_DATA')}
</a>
@ -422,6 +432,12 @@ class WalletsData extends React.Component {
<div className="col-sm-6">
{this.renderAddressList()}
</div>
<div className="col-sm-2">
<div className="pull-left margin-right-10">
<input type="checkbox" id="edexcoin_cache_api" checked={this.state.useCache} data-plugin="switchery" data-size="small" />
</div>
<label className="padding-top-3" htmlFor="edexcoin_cache_api" onClick={this.toggleCacheApi}>Use cache</label>
</div>
</div>
<div className="row">
<div className="col-sm-6">

2
react/src/config.js

@ -2,6 +2,6 @@ module.exports = {
iguanaCorePort: 7778,
basiliskPort: 7779,
agamaPort: 17777,
enableCacheApi: false,
enableCacheApi: true,
useBasiliskInstance: true,
};

4
react/src/translate/en.js

@ -81,8 +81,8 @@ export const _lang = {
'GET_NOTARY_NODES_LIST': 'Get Notary Nodes List',
'REFRESH_BASILISK_CONNECTIONS': 'Refresh Basilisk Connections',
'FETCH_WALLET_DATA': 'Fetch Wallet Data',
'REFETCH_WALLET_DATA': 'Reset cache data',
'VIEW_CACHE_DATA': 'View cache data',
'REFETCH_WALLET_DATA': 'Reset Cache Data',
'VIEW_CACHE_DATA': 'View Cache Data',
'TRANSACTION_HISTORY': 'Transactions History',
'DIRECTION': 'Direction',
'CONFIRMATIONS': 'Confirmations',

Loading…
Cancel
Save