Browse Source

linked basilisk addr dropdown to tx history req

all-modes
Petr Balashov 8 years ago
parent
commit
be3af6477d
  1. 62
      react/src/actions/actionCreators.js
  2. 12
      react/src/components/dashboard/coinTileItem.js
  3. 46
      react/src/components/dashboard/walletsData.js
  4. 14
      react/src/reducers/activeCoin.js

62
react/src/actions/actionCreators.js

@ -41,6 +41,16 @@ export const DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE = 'DASHBOARD_ACTIVE_COIN_NATIV
export const DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY = 'DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY'; export const DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY = 'DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY';
export const DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS = 'DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS'; export const DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS = 'DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS';
export const DASHBOARD_ACTIVE_COIN_SENDTO = 'DASHBOARD_ACTIVE_COIN_SENDTO'; export const DASHBOARD_ACTIVE_COIN_SENDTO = 'DASHBOARD_ACTIVE_COIN_SENDTO';
export const DASHBOARD_ACTIVE_COIN_GET_CACHE = 'DASHBOARD_ACTIVE_COIN_GET_CACHE';
export const DASHBOARD_ACTIVE_COIN_MAIN_BASILISK_ADDR = 'DASHBOARD_ACTIVE_COIN_MAIN_BASILISK_ADDR';
export function changeMainBasiliskAddress(address) {
console.log('changeMainBasiliskAddress', address);
return {
type: DASHBOARD_ACTIVE_COIN_MAIN_BASILISK_ADDR,
address,
}
}
export function toggleDashboardActiveSection(name) { export function toggleDashboardActiveSection(name) {
return { return {
@ -1078,33 +1088,29 @@ export function getKMDAddressesNative(coin, mode, currentAddress) {
} }
} }
/*function Shepherd_GetBasiliskCache() { function getShepherdCacheState(json) {
return new Promise((resolve) => { return {
var parse_session_data = sessionStorage.getItem('IguanaActiveAccount'); type: DASHBOARD_ACTIVE_COIN_GET_CACHE,
parse_session_data = JSON.parse(JSON.parse(parse_session_data)); cache: json && json.result && json.result.basilisk ? json.result.basilisk : null,
}
var session_pubkey = parse_session_data.pubkey, }
ajax_data = { 'pubkey': session_pubkey };
$.ajax({ export function getShepherdCache(pubkey) {
type: 'GET', return dispatch => {
data: ajax_data, return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, {
url: 'http://127.0.0.1:17777/shepherd/cache', method: 'GET',
contentType: 'application/json' // send as JSON headers: {
'Content-Type': 'application/json',
},
}) })
.done(function(data) { .catch(function(error) {
resolve(data); console.log(error);
data = JSON.parse(data); dispatch(triggerToaster(true, 'getShepherdCache', 'Error', 'error'));
})
if (data.result === 'JSON parse error') { .then(response => response.json())
Shepherd_GroomData_Delete() .then(json => dispatch(getShepherdCacheState(json)))
.then(function(result) { }
console.log('error reading cache, flushing...'); }
});
}
});
});
}*/
function getDebugLogState(json) { function getDebugLogState(json) {
const _data = json.result.replace('\n', '\r\n'); const _data = json.result.replace('\n', '\r\n');
@ -1385,7 +1391,9 @@ export function getNativeTxHistoryState(json) {
json = null; json = null;
} else if (json && json.result) { } else if (json && json.result) {
json = json.result; json = json.result;
} } else if (!json.length) {
json = 'no data';
}
return { return {
type: DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY, type: DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY,
@ -1615,7 +1623,7 @@ export function sendToAddress(coin, _payload) {
dispatch(triggerToaster(true, 'sendToAddress', 'Error', 'error')); dispatch(triggerToaster(true, 'sendToAddress', 'Error', 'error'));
}) })
.then(response => response.json()) .then(response => response.json())
.then(json => dispatch(sendToAddressHandler(json))) .then(json => dispatch(sendToAddressState(json, dispatch)))
} }
} }

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

@ -14,7 +14,8 @@ import {
getKMDAddressesNative, getKMDAddressesNative,
getKMDOPID, getKMDOPID,
getFullTransactionsList, getFullTransactionsList,
getBasiliskTransactionsList getBasiliskTransactionsList,
getShepherdCache
} from '../../actions/actionCreators'; } from '../../actions/actionCreators';
import Store from '../../store'; import Store from '../../store';
@ -57,11 +58,14 @@ class CoinTileItem extends React.Component {
} }
if (mode === 'basilisk') { if (mode === 'basilisk') {
var _iguanaActiveHandle = setInterval(function() { var _iguanaActiveHandle = setInterval(function() {
const useAddress = this.props.ActiveCoin.mainBasiliskAddress ? this.props.ActiveCoin.mainBasiliskAddress : this.props.Dashboard.activeHandle[coin];
if (this.props && this.props.Dashboard && this.props.Dashboard.activeHandle && this.props.Dashboard.activeHandle[coin]) { if (this.props && this.props.Dashboard && this.props.Dashboard.activeHandle && this.props.Dashboard.activeHandle[coin]) {
Store.dispatch(getBasiliskTransactionsList(coin, this.props.Dashboard.activeHandle[coin])); Store.dispatch(getBasiliskTransactionsList(coin, useAddress));
Store.dispatch(getKMDAddressesNative(coin, mode, this.props.Dashboard.activeHandle[coin])); Store.dispatch(getKMDAddressesNative(coin, mode, useAddress));
Store.dispatch(getShepherdCache(this.props.Dashboard.activeHandle.pubkey));
Store.dispatch(iguanaEdexBalance(coin, mode));
} }
Store.dispatch(iguanaEdexBalance(coin, mode));
}.bind(this), 3000); }.bind(this), 3000);
Store.dispatch(startInterval('sync', _iguanaActiveHandle)); Store.dispatch(startInterval('sync', _iguanaActiveHandle));
// basilisk // basilisk

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

@ -5,7 +5,9 @@ import {
basiliskRefresh, basiliskRefresh,
basiliskConnection, basiliskConnection,
getDexNotaries, getDexNotaries,
toggleDashboardTxInfoModal toggleDashboardTxInfoModal,
getBasiliskTransactionsList,
changeMainBasiliskAddress
} from '../../actions/actionCreators'; } from '../../actions/actionCreators';
import Store from '../../store'; import Store from '../../store';
@ -76,6 +78,13 @@ class WalletsData extends React.Component {
})); }));
} }
} }
if (this.props.ActiveCoin.txhistory && this.props.ActiveCoin.txhistory === 'no data') {
console.log('no data', true);
this.setState(Object.assign({}, this.state, {
itemsList: 'no data',
}));
}
} }
updateCurrentPage(page) { updateCurrentPage(page) {
@ -109,8 +118,8 @@ class WalletsData extends React.Component {
<label> <label>
Show&nbsp; Show&nbsp;
<select name="itemsPerPage" aria-controls="kmd-tx-history-tbl" className="form-control input-sm" onChange={this.updateInput}> <select name="itemsPerPage" aria-controls="kmd-tx-history-tbl" className="form-control input-sm" onChange={this.updateInput}>
<option value="1">10</option> <option value="10">10</option>
<option value="2">25</option> <option value="25">25</option>
<option value="50">50</option> <option value="50">50</option>
<option value="100">100</option> <option value="100">100</option>
</select>&nbsp; </select>&nbsp;
@ -189,7 +198,7 @@ class WalletsData extends React.Component {
} }
renderTxHistoryList() { renderTxHistoryList() {
if (this.state.itemsList && this.state.itemsList.length) { if (this.state.itemsList && this.state.itemsList.length && this.state.itemsList !== 'no data') {
return this.state.itemsList.map((tx, index) => return this.state.itemsList.map((tx, index) =>
<tr key={tx.txid + tx.amount}> <tr key={tx.txid + tx.amount}>
<td>{this.renderTxType(tx.category || tx.type)}</td> <td>{this.renderTxType(tx.category || tx.type)}</td>
@ -202,11 +211,31 @@ class WalletsData extends React.Component {
</td> </td>
</tr> </tr>
); );
} else { }
if (this.state.itemsList === 'no data') {
return (
<span>No data</span>
);
}
if (!this.state.itemsList) {
return null; return null;
} }
} }
updateAddressSelection(address, type, amount) {
this.setState(Object.assign({}, this.state, {
currentAddress: address,
addressSelectorOpen: false,
}));
setTimeout(function() {
Store.dispatch(changeMainBasiliskAddress(address));
Store.dispatch(getBasiliskTransactionsList(this.props.ActiveCoin.coin, address));
}.bind(this), 100);
}
openDropMenu() { openDropMenu() {
this.setState(Object.assign({}, this.state, { this.setState(Object.assign({}, this.state, {
addressSelectorOpen: !this.state.addressSelectorOpen, addressSelectorOpen: !this.state.addressSelectorOpen,
@ -215,7 +244,6 @@ class WalletsData extends React.Component {
renderAddressByType(type) { renderAddressByType(type) {
if (this.props.ActiveCoin.addresses && this.props.ActiveCoin.addresses[type] && this.props.ActiveCoin.addresses[type].length) { if (this.props.ActiveCoin.addresses && this.props.ActiveCoin.addresses[type] && this.props.ActiveCoin.addresses[type].length) {
console.log(type);
return this.props.ActiveCoin.addresses[type].map((address) => return this.props.ActiveCoin.addresses[type].map((address) =>
<li key={address.address}> <li key={address.address}>
<a tabIndex="0" onClick={() => this.updateAddressSelection(address.address, type, address.amount)}><i className={type === 'public' ? 'icon fa-eye' : 'icon fa-eye-slash'}></i> <span className="text">[ {address.amount} {this.props.ActiveCoin.coin} ] {address.address}</span><span className="glyphicon glyphicon-ok check-mark"></span></a> <a tabIndex="0" onClick={() => this.updateAddressSelection(address.address, type, address.amount)}><i className={type === 'public' ? 'icon fa-eye' : 'icon fa-eye-slash'}></i> <span className="text">[ {address.amount} {this.props.ActiveCoin.coin} ] {address.address}</span><span className="glyphicon glyphicon-ok check-mark"></span></a>
@ -227,10 +255,10 @@ class WalletsData extends React.Component {
} }
renderSelectorCurrentLabel() { renderSelectorCurrentLabel() {
if (this.state.sendFrom) { if (this.state.currentAddress) {
return ( return (
<span> <span>
<i className={this.state.addressType === 'public' ? 'icon fa-eye' : 'icon fa-eye-slash'}></i> <span className="text">[ {this.state.sendFromAmount} {this.props.ActiveCoin.coin} ] {this.state.sendFrom}</span> <i className={this.state.addressType === 'public' ? 'icon fa-eye' : 'icon fa-eye-slash'}></i> <span className="text">[ {this.state.sendFromAmount} {this.props.ActiveCoin.coin} ] {this.state.currentAddress}</span>
</span> </span>
); );
} else { } else {
@ -241,7 +269,7 @@ class WalletsData extends React.Component {
} }
renderAddressList() { renderAddressList() {
if (this.props.Dashboard && this.props.Dashboard.activeHandle && this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin]) { if (this.props.Dashboard && this.props.Dashboard.activeHandle && this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin] && this.props.ActiveCoin.mode === 'basilisk') {
return ( return (
<div className={'btn-group bootstrap-select form-control form-material showkmdwalletaddrs show-tick ' + (this.state.addressSelectorOpen ? 'open' : '')}> <div className={'btn-group bootstrap-select form-control form-material showkmdwalletaddrs show-tick ' + (this.state.addressSelectorOpen ? 'open' : '')}>
<button type="button" className="btn dropdown-toggle btn-info" data-toggle="dropdown" data-id="kmd_wallet_send_from" title="- Select Transparent or Private Address -" aria-expanded="true" onClick={this.openDropMenu}> <button type="button" className="btn dropdown-toggle btn-info" data-toggle="dropdown" data-id="kmd_wallet_send_from" title="- Select Transparent or Private Address -" aria-expanded="true" onClick={this.openDropMenu}>

14
react/src/reducers/activeCoin.js

@ -10,7 +10,9 @@ import {
DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE, DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE,
DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY, DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY,
DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS, DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS,
DASHBOARD_ACTIVE_COIN_SENDTO DASHBOARD_ACTIVE_COIN_SENDTO,
DASHBOARD_ACTIVE_COIN_GET_CACHE,
DASHBOARD_ACTIVE_COIN_MAIN_BASILISK_ADDR
} from '../actions/actionCreators'; } from '../actions/actionCreators';
// TODO: keep all coin data in array of objects instead of single object // TODO: keep all coin data in array of objects instead of single object
@ -27,6 +29,8 @@ export function ActiveCoin(state = {
txhistory: [], txhistory: [],
opids: null, opids: null,
lastSendToResponse: null, lastSendToResponse: null,
cache: null,
mainBasiliskAddress: null,
}, action) { }, action) {
switch (action.type) { switch (action.type) {
case DASHBOARD_ACTIVE_COIN_CHANGE: case DASHBOARD_ACTIVE_COIN_CHANGE:
@ -89,6 +93,14 @@ export function ActiveCoin(state = {
return Object.assign({}, state, { return Object.assign({}, state, {
lastSendToResponse: action.lastSendToResponse, lastSendToResponse: action.lastSendToResponse,
}); });
case DASHBOARD_ACTIVE_COIN_GET_CACHE:
return Object.assign({}, state, {
cache: action.cache,
});
case DASHBOARD_ACTIVE_COIN_MAIN_BASILISK_ADDR:
return Object.assign({}, state, {
mainBasiliskAddress: action.address,
});
default: default:
return state; return state;
} }

Loading…
Cancel
Save