Browse Source

addr amount render fix; toggle send api type

all-modes
pbca26 8 years ago
parent
commit
04c4fcd564
  1. 72
      react/src/actions/actionCreators.js
  2. 101
      react/src/components/dashboard/sendCoin.js
  3. 15
      react/src/components/dashboard/walletsData.js

72
react/src/actions/actionCreators.js

@ -978,7 +978,7 @@ export function getKMDAddressesNative(coin, mode, currentAddress) {
'account': '*'
};
}
console.log('pl', payload);
//console.log('pl', payload);
if (sessionStorage.getItem('useCache') && mode === 'basilisk') {
const pubkey = JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey;
@ -1063,7 +1063,7 @@ export function getKMDAddressesNative(coin, mode, currentAddress) {
}
function calcBalance(result, json, dispatch, mode) {
console.log('result', result);
//console.log('result', result);
if (mode === 'full' || mode === 'basilisk') {
result[0] = result[0].result;
} else {
@ -1071,8 +1071,8 @@ export function getKMDAddressesNative(coin, mode, currentAddress) {
result[1] = result[1].result;
}
console.log('calc result', result);
console.log('calc json', json);
//console.log('calc result', result);
//console.log('calc json', json);
if (mode !== 'basilisk') {
const allAddrArray = json.map(res => res.address).filter((x, i, a) => a.indexOf(x) == i);
@ -1112,8 +1112,8 @@ export function getKMDAddressesNative(coin, mode, currentAddress) {
} else {
filteredArray = json.filter(res => res.address === result[a][b]).map(res => res.amount);
}
console.log('filteredArray', filteredArray);
console.log('addr', result[a][b]);
//console.log('filteredArray', filteredArray);
//console.log('addr', result[a][b]);
let sum = 0;
@ -1752,6 +1752,34 @@ export function sendToAddress(coin, _payload) {
}
}
export function sendFromAddress(coin, _payload) {
const payload = {
'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'),
'coin': coin,
'method': 'sendfrom',
'params': [
_payload.sendFrom,
_payload.sendTo,
_payload.amount,
'EasyDEX',
'EasyDEXTransaction'
]
};
return dispatch => {
return fetch('http://127.0.0.1:' + Config.iguanaCorePort, {
method: 'POST',
body: JSON.stringify(payload),
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'sendFromAddress', 'Error', 'error'));
})
.then(response => response.json())
.then(json => dispatch(sendToAddressState(json, dispatch)))
}
}
function checkAddressBasiliskHandle(json) {
if (json && json.error) {
return dispatch => {
@ -2116,6 +2144,38 @@ export function connectNotaries() {
}
}
export function iguanaUTXORawTX(data) {
const payload = {
'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'),
'symbol': data.coin,
'agent': 'basilisk',
'method': 'utxorawtx',
'vals': {
'timelock': 0,
'changeaddr': data.sendfrom,
'destaddr': data.sendtoaddr,
'txfee': data.txfee,
'amount': data.amount,
'sendflag': data.sendsig
},
'utxos': data.utxos
};
console.log('iguanaUTXORawTXExport', payload);
return new Promise((resolve, reject) => {
fetch('http://127.0.0.1:' + Config.iguanaCorePort, {
method: 'POST',
body: JSON.stringify(payload),
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'iguanaUTXORawTX', 'Error', 'error'));
})
.then(response => response.json())
.then(json => resolve(json))
});
}
/*function Shepherd_SendPendValue() {
Shepherd_SysInfo().then(function(result){
var ram_data = formatBytes(result.totalmem_bytes)

101
react/src/components/dashboard/sendCoin.js

@ -3,6 +3,7 @@ import Config from '../../config';
import { translate } from '../../translate/translate';
import {
sendToAddress,
sendFromAddress,
sendNativeTx,
getKMDOPID,
resolveOpenAliasAddress,
@ -26,22 +27,47 @@ class SendCoin extends React.Component {
amount: 0,
fee: 0.0001,
sendSig: false,
sendApiType: false,
addressSelectorOpen: false,
};
this.updateInput = this.updateInput.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.handleBasiliskSend = this.handleBasiliskSend.bind(this);
this.openDropMenu = this.openDropMenu.bind(this);
this.toggleSendSig = this.toggleSendSig.bind(this);
this.getOAdress = this.getOAdress.bind(this);
this.toggleSendAPIType = this.toggleSendAPIType.bind(this);
}
renderAddressAmount(address) {
if (this.props.ActiveCoin.addresses && this.props.ActiveCoin.addresses['public'] && this.props.ActiveCoin.addresses['public'].length) {
for (let i = 0; i < this.props.ActiveCoin.addresses['public'].length; i++) {
if (this.props.ActiveCoin.addresses['public'][i].address === address) {
return this.props.ActiveCoin.addresses['public'][i].amount;
}
}
} else {
return 0;
}
}
renderAddressByType(type) {
if (this.props.ActiveCoin.addresses && this.props.ActiveCoin.addresses[type] && this.props.ActiveCoin.addresses[type].length) {
return this.props.ActiveCoin.addresses[type].map((address) =>
<li data-original-index="2" key={address.address} className={address.amount <= 0 ? 'hide' : ''}>
<a tabIndex="0" data-tokens="null" 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>
</li>
);
if (this.state.sendApiType) {
const mainAddress = this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin];
const mainAddressAmount = this.renderAddressAmount(mainAddress);
return(
<li data-original-index="2" key={mainAddress} className={mainAddressAmount <= 0 ? 'hide' : ''}>
<a tabIndex="0" data-tokens="null" onClick={() => this.updateAddressSelection(mainAddress, type, mainAddressAmount)}><i className={type === 'public' ? 'icon fa-eye' : 'icon fa-eye-slash'}></i> <span className="text">[ {mainAddressAmount} {this.props.ActiveCoin.coin} ] {mainAddress}</span><span className="glyphicon glyphicon-ok check-mark"></span></a>
</li>
);
} else {
return this.props.ActiveCoin.addresses[type].map((address) =>
<li data-original-index="2" key={address.address} className={address.amount <= 0 ? 'hide' : ''}>
<a tabIndex="0" data-tokens="null" 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>
</li>
);
}
} else {
return null;
}
@ -54,6 +80,16 @@ class SendCoin extends React.Component {
<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>
</span>
);
} else if (this.state.sendApiType) {
const mainAddress = this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin];
const mainAddressAmount = this.renderAddressAmount(mainAddress);
console.log('sendApiType', this.state.sendApiType);
return (
<span>
<i className={this.state.addressType === 'public' ? 'icon fa-eye' : 'icon fa-eye-slash'}></i> <span className="text">[ {mainAddressAmount} {this.props.ActiveCoin.coin} ] {mainAddress}</span>
</span>
);
} else {
return (
<span>- Select Transparent or Private Address -</span>
@ -89,7 +125,7 @@ class SendCoin extends React.Component {
this.setState(Object.assign({}, this.state, {
sendFrom: address,
addressType: type,
sendFromAmount: amount,
sendFromAmount: amount ? amount : this.props.ActiveCoin.addresses[type][address].amount,
addressSelectorOpen: !this.state.addressSelectorOpen,
}));
}
@ -100,7 +136,12 @@ class SendCoin extends React.Component {
}));
if (step === 2) {
Store.dispatch(sendToAddress(this.props.ActiveCoin.coin, this.state));
if (!this.state.sendApiType) {
handleBasiliskSend();
} else {
Store.dispatch(sendToAddress(this.props.ActiveCoin.coin, this.state));
}
//Store.dispatch(sendFromAddress(this.props.ActiveCoin.coin, this.state));
}
}
@ -110,14 +151,19 @@ class SendCoin extends React.Component {
}));
}
toggleSendAPIType() {
this.setState(Object.assign({}, this.state, {
sendApiType: !this.state.sendApiType,
}));
}
updateInput(e) {
this.setState({
[e.target.name]: e.target.value,
});
console.log(this.state);
}
handleSubmit() {
handleBasiliskSend() {
const utxoSet = this.props.ActiveCoin.cache[this.props.ActiveCoin.coin][this.state.sendFrom].refresh;
const sendData = {
'coin': this.props.ActiveCoin.coin,
@ -130,6 +176,19 @@ class SendCoin extends React.Component {
};
iguanaUTXORawTX(sendData)
.then(function(json) {
console.log('sendData', sendData);
console.log('iguanaUTXORawTXJSON', json);
if (json.result === 'success' && json.completed === true) {
Store.dispatch(triggerToaster(true, translate('TOASTR.SIGNED_TX_GENERATED') + '.', translate('TOASTR.WALLET_NOTIFICATION')));
if (sendData.sendsig === 1) {
Store.dispatch(triggerToaster(true, translate('TOASTR.SENDING_TX') + '.', translate('TOASTR.WALLET_NOTIFICATION')));
ajax_data_dexrawtx = {
'signedtx': json.signedtx,
'coin': sendData.coin
};
}
}
console.log(json);
});
//Store.dispatch(sendNativeTx(this.props.ActiveCoin.coin, this.state));
@ -218,7 +277,7 @@ class SendCoin extends React.Component {
}
if (this.state.sendTo === '') {
Store.dispatch(triggerToaster(true, 'Couldn\'t find any ' + this.props.ActiveCoin.coin +' addresses', 'OpenAlias', 'error'));
Store.dispatch(triggerToaster(true, 'Couldn\'t find any ' + this.props.ActiveCoin.coin + ' addresses', 'OpenAlias', 'error'));
}
} else {
Store.dispatch(triggerToaster(true, 'Couldn\'t find any addresses', 'OpenAlias', 'error'));
@ -231,7 +290,7 @@ class SendCoin extends React.Component {
return (
<div className="row">
<div className="col-lg-6 form-group form-material">
<label className="control-label" data-extcoin="COIN" htmlFor="kmd_wallet_sendto">{translate('INDEX.SEND_TO')} via Openalias address</label>
<label className="control-label" data-extcoin="COIN" htmlFor="kmd_wallet_sendto">Fetch OpenAlias recipient address</label>
<input type="text" className="form-control" data-extcoin="COIN" name="sendToOA" onChange={this.updateInput} id="kmd_wallet_sendto" placeholder="Enter an alias as address@site.com" autoComplete="off" required />
</div>
<div className="col-lg-6 form-group form-material">
@ -246,6 +305,23 @@ class SendCoin extends React.Component {
}
}
renderSendApiTypeSelector() {
if (this.props.ActiveCoin.mode === 'basilisk') {
return (
<div className="row">
<div className="col-lg-10 margin-bottom-10">
<div className="pull-left margin-right-10">
<input type="checkbox" id="edexcoin_send_api_type" data-plugin="switchery" data-size="small" />
</div>
<label className="padding-top-3" htmlFor="edexcoin_send_api_type" onClick={this.toggleSendAPIType}>Send via sendtoaddress API</label>
</div>
</div>
);
} else {
return null;
}
}
render() {
if (this.props.ActiveCoin && this.props.ActiveCoin.send && this.props.ActiveCoin.mode !== 'native') {
return (
@ -283,6 +359,7 @@ class SendCoin extends React.Component {
</div>
<div className="panel-body container-fluid">
<form className="edexcoin-send-form" data-edexcoin="COIN" method="post" role="form" autoComplete="off">
{this.renderSendApiTypeSelector()}
<div className="row">
<div className={this.props.ActiveCoin.mode === 'basilisk' ? 'col-xlg-12 form-group form-material' : 'hide'}>
<label className="control-label" data-edexcoin="COIN" htmlFor="edexcoin_send_from">{translate('INDEX.SEND_FROM')}</label>

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

@ -64,6 +64,7 @@ class WalletsData extends React.Component {
toggleCacheApi() {
const _useCache = !this.state.useCache;
console.log('useCache is set to', _useCache);
sessionStorage.setItem('useCache', _useCache);
this.setState(Object.assign({}, this.state, {
@ -353,11 +354,23 @@ class WalletsData extends React.Component {
}
}
renderAddressAmount() {
if (this.props.ActiveCoin.addresses['public'] && this.props.ActiveCoin.addresses['public'].length) {
for (let i = 0; i < this.props.ActiveCoin.addresses['public'].length; i++) {
if (this.props.ActiveCoin.addresses['public'][i].address === this.state.currentAddress) {
return this.props.ActiveCoin.addresses['public'][i].amount;
}
}
} else {
return 0;
}
}
renderSelectorCurrentLabel() {
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.currentAddress}</span>
<i className={this.state.addressType === 'public' ? 'icon fa-eye' : 'icon fa-eye-slash'}></i> <span className="text">[ {this.renderAddressAmount()} {this.props.ActiveCoin.coin} ] {this.state.currentAddress}</span>
</span>
);
} else {

Loading…
Cancel
Save