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_OPIDS = 'DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS';
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) {
return {
@ -1078,33 +1088,29 @@ export function getKMDAddressesNative(coin, mode, currentAddress) {
}
}
/*function Shepherd_GetBasiliskCache() {
return new Promise((resolve) => {
var parse_session_data = sessionStorage.getItem('IguanaActiveAccount');
parse_session_data = JSON.parse(JSON.parse(parse_session_data));
var session_pubkey = parse_session_data.pubkey,
ajax_data = { 'pubkey': session_pubkey };
function getShepherdCacheState(json) {
return {
type: DASHBOARD_ACTIVE_COIN_GET_CACHE,
cache: json && json.result && json.result.basilisk ? json.result.basilisk : null,
}
}
$.ajax({
type: 'GET',
data: ajax_data,
url: 'http://127.0.0.1:17777/shepherd/cache',
contentType: 'application/json' // send as JSON
export function getShepherdCache(pubkey) {
return dispatch => {
return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
.done(function(data) {
resolve(data);
data = JSON.parse(data);
if (data.result === 'JSON parse error') {
Shepherd_GroomData_Delete()
.then(function(result) {
console.log('error reading cache, flushing...');
});
}
});
});
}*/
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'getShepherdCache', 'Error', 'error'));
})
.then(response => response.json())
.then(json => dispatch(getShepherdCacheState(json)))
}
}
function getDebugLogState(json) {
const _data = json.result.replace('\n', '\r\n');
@ -1385,7 +1391,9 @@ export function getNativeTxHistoryState(json) {
json = null;
} else if (json && json.result) {
json = json.result;
}
} else if (!json.length) {
json = 'no data';
}
return {
type: DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY,
@ -1615,7 +1623,7 @@ export function sendToAddress(coin, _payload) {
dispatch(triggerToaster(true, 'sendToAddress', 'Error', 'error'));
})
.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,
getKMDOPID,
getFullTransactionsList,
getBasiliskTransactionsList
getBasiliskTransactionsList,
getShepherdCache
} from '../../actions/actionCreators';
import Store from '../../store';
@ -57,11 +58,14 @@ class CoinTileItem extends React.Component {
}
if (mode === 'basilisk') {
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]) {
Store.dispatch(getBasiliskTransactionsList(coin, this.props.Dashboard.activeHandle[coin]));
Store.dispatch(getKMDAddressesNative(coin, mode, this.props.Dashboard.activeHandle[coin]));
Store.dispatch(getBasiliskTransactionsList(coin, useAddress));
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);
Store.dispatch(startInterval('sync', _iguanaActiveHandle));
// basilisk

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

@ -5,7 +5,9 @@ import {
basiliskRefresh,
basiliskConnection,
getDexNotaries,
toggleDashboardTxInfoModal
toggleDashboardTxInfoModal,
getBasiliskTransactionsList,
changeMainBasiliskAddress
} from '../../actions/actionCreators';
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) {
@ -109,8 +118,8 @@ class WalletsData extends React.Component {
<label>
Show&nbsp;
<select name="itemsPerPage" aria-controls="kmd-tx-history-tbl" className="form-control input-sm" onChange={this.updateInput}>
<option value="1">10</option>
<option value="2">25</option>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>&nbsp;
@ -189,7 +198,7 @@ class WalletsData extends React.Component {
}
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) =>
<tr key={tx.txid + tx.amount}>
<td>{this.renderTxType(tx.category || tx.type)}</td>
@ -202,11 +211,31 @@ class WalletsData extends React.Component {
</td>
</tr>
);
} else {
}
if (this.state.itemsList === 'no data') {
return (
<span>No data</span>
);
}
if (!this.state.itemsList) {
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() {
this.setState(Object.assign({}, this.state, {
addressSelectorOpen: !this.state.addressSelectorOpen,
@ -215,7 +244,6 @@ class WalletsData extends React.Component {
renderAddressByType(type) {
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) =>
<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>
@ -227,10 +255,10 @@ class WalletsData extends React.Component {
}
renderSelectorCurrentLabel() {
if (this.state.sendFrom) {
if (this.state.currentAddress) {
return (
<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>
);
} else {
@ -241,7 +269,7 @@ class WalletsData extends React.Component {
}
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 (
<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}>

14
react/src/reducers/activeCoin.js

@ -10,7 +10,9 @@ import {
DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE,
DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY,
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';
// TODO: keep all coin data in array of objects instead of single object
@ -27,6 +29,8 @@ export function ActiveCoin(state = {
txhistory: [],
opids: null,
lastSendToResponse: null,
cache: null,
mainBasiliskAddress: null,
}, action) {
switch (action.type) {
case DASHBOARD_ACTIVE_COIN_CHANGE:
@ -89,6 +93,14 @@ export function ActiveCoin(state = {
return Object.assign({}, state, {
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:
return state;
}

Loading…
Cancel
Save