Browse Source

send to openalias handle

all-modes
pbca26 8 years ago
parent
commit
fe424cb371
  1. 34
      react/src/actions/actionCreators.js
  2. 67
      react/src/components/dashboard/sendCoin.js
  3. 19
      react/src/components/dashboard/walletsData.js
  4. 66
      react/src/components/dashboard/walletsNativeSend.js
  5. 1
      react/src/config.js

34
react/src/actions/actionCreators.js

@ -157,7 +157,7 @@ function toggleSendReceiveCoinFormsState() {
}
}
function triggerToaster(display, message, title, _type) {
export function triggerToaster(display, message, title, _type) {
return {
type: TOASTER_MESSAGE,
display,
@ -2063,6 +2063,38 @@ export function restartIguanaInstance(pmid) {
});
}
export function restartBasiliskInstance() {
return dispatch => {
getIguanaInstancesList()
.then(function(json) {
for (let port in json.result) {
if (json.result[port].mode === 'basilisk') {
restartIguanaInstance(json.result[port].pmid)
.then(function(json) {
console.log('restartBasiliskInstance', json);
});
}
}
});
}
}
export function resolveOpenAliasAddress(email) {
const url = email.replace('@', '.');
return new Promise((resolve, reject) => {
fetch('https://dns.google.com/resolve?name=' + url + '&type=txt', {
method: 'GET',
})
.catch(function(error) {
console.log(error);
dispatch(triggerToaster(true, 'resolveOpenAliasAddress', 'Error', 'error'));
})
.then(response => response.json())
.then(json => resolve(json))
});
}
export function connectNotaries() {
const payload = {
'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'),

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

@ -1,6 +1,13 @@
import React from 'react';
import Config from '../../config';
import { translate } from '../../translate/translate';
import { sendToAddress } from '../../actions/actionCreators';
import {
sendToAddress,
sendNativeTx,
getKMDOPID,
resolveOpenAliasAddress,
triggerToaster
} from '../../actions/actionCreators';
import Store from '../../store';
// TODO: implement logic
@ -12,7 +19,8 @@ class SendCoin extends React.Component {
currentStep: 0,
sendFrom: this.props.Dashboard && this.props.Dashboard.activeHandle ? this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin] : null,
sendFromAmount: 0,
sendTo: null,
sendTo: '',
sendToOA: null,
amount: 0,
fee: 0.0001,
sendSig: false,
@ -20,6 +28,7 @@ class SendCoin extends React.Component {
this.updateInput = this.updateInput.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.toggleSendSig = this.toggleSendSig.bind(this);
this.getOAdress = this.getOAdress.bind(this);
}
changeSendCoinStep(step) {
@ -97,7 +106,7 @@ class SendCoin extends React.Component {
<span className="label label-danger">false</span>
);
}
}
}
}
renderSendCoinResponse() {
@ -113,6 +122,53 @@ class SendCoin extends React.Component {
}
}
getOAdress() {
resolveOpenAliasAddress(this.state.sendToOA)
.then(function(json) {
const reply = json.Answer;
if (reply && reply.length) {
for (let i = 0; i < reply.length; i++) {
const _address = reply[i].data.split(' ');
const coin = _address[0].replace('"oa1:', '');
const coinAddress = _address[1].replace('recipient_address=', '').replace(';', '');
if (coin.toUpperCase() === this.props.ActiveCoin.coin) {
this.setState(Object.assign({}, this.state, {
sendTo: coinAddress,
}));
}
}
if (this.state.sendTo === '') {
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'));
}
}.bind(this));
}
renderOASendUI() {
if (Config.openAlias) {
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>
<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">
<button type="button" className="btn btn-primary waves-effect waves-light" data-toggle="modal" id="kmd_wallet_send_coins_btn" onClick={this.getOAdress}>
Get address
</button>
</div>
</div>
);
} else {
return null;
}
}
render() {
if (this.props.ActiveCoin && this.props.ActiveCoin.send && this.props.ActiveCoin.mode !== 'native') {
return (
@ -155,9 +211,12 @@ class SendCoin extends React.Component {
<label className="control-label" data-edexcoin="COIN" htmlFor="edexcoin_send_from">{translate('INDEX.SEND_FROM')}</label>
<select className="form-control form-material showedexcoinaddrs show-tick" data-edexcoin="COIN" id="edexcoin_send_from" onChange={this.updateInput} title="Select Transparent or Private Address" data-size="5"></select>
</div>
</div>
{this.renderOASendUI()}
<div className="row">
<div className="col-xlg-12 form-group form-material">
<label className="control-label" data-edexcoin="COIN" htmlFor="edexcoin_sendto">{translate('INDEX.SEND_TO')}</label>
<input type="text" className="form-control" data-edexcoin="COIN" id="edexcoin_sendto" name="sendTo" placeholder="Enter address" autoComplete="off" onChange={this.updateInput} required />
<input type="text" className="form-control" data-edexcoin="COIN" id="edexcoin_sendto" name="sendTo" placeholder="Enter address" autoComplete="off" value={this.state.sendTo} onChange={this.updateInput} required />
</div>
<div className="col-lg-6 form-group form-material">
<label className="control-label" htmlFor="edexcoin_amount" data-edexcoin="COIN" id="edexcoin_amount_label">

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

@ -15,8 +15,7 @@ import {
toggleViewCacheModal,
fetchNewCacheData,
fetchUtxoCache,
getIguanaInstancesList,
restartIguanaInstance
restartBasiliskInstance
} from '../../actions/actionCreators';
import Store from '../../store';
@ -72,6 +71,10 @@ class WalletsData extends React.Component {
}));
}
restartBasiliskInstance() {
Store.dispatch(restartBasiliskInstance());
}
_toggleViewCacheModal() {
Store.dispatch(toggleViewCacheModal(!this.props.Dashboard.displayViewCacheModal));
}
@ -96,18 +99,6 @@ class WalletsData extends React.Component {
}
}
restartBasiliskInstance() {
getIguanaInstancesList().then(function(json) {
for (let port in json.result) {
if (json.result[port].mode === 'basilisk') {
restartIguanaInstance(json.result[port].pmid).then(function(json) {
console.log('restartBasiliskInstance', json);
});
}
}
});
}
removeAndFetchNewCache() {
Store.dispatch(deleteCacheFile({
'pubkey': this.props.Dashboard.activeHandle.pubkey,

66
react/src/components/dashboard/walletsNativeSend.js

@ -1,7 +1,13 @@
import React from 'react';
import Config from '../../config';
import { translate } from '../../translate/translate';
import { secondsToString } from '../../util/time';
import { sendNativeTx, getKMDOPID } from '../../actions/actionCreators';
import {
sendNativeTx,
getKMDOPID,
resolveOpenAliasAddress,
triggerToaster
} from '../../actions/actionCreators';
import Store from '../../store';
class WalletsNativeSend extends React.Component {
@ -11,7 +17,8 @@ class WalletsNativeSend extends React.Component {
addressType: null,
sendFrom: null,
sendFromAmount: 0,
sendTo: null,
sendTo: '',
sendToOA: null,
amount: 0,
fee: 0.0001,
addressSelectorOpen: false,
@ -19,6 +26,7 @@ class WalletsNativeSend extends React.Component {
this.updateInput = this.updateInput.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.openDropMenu = this.openDropMenu.bind(this);
this.getOAdress = this.getOAdress.bind(this);
}
renderAddressByType(type) {
@ -182,6 +190,53 @@ class WalletsNativeSend extends React.Component {
}, 1000);
}
getOAdress() {
resolveOpenAliasAddress(this.state.sendToOA)
.then(function(json) {
const reply = json.Answer;
if (reply && reply.length) {
for (let i = 0; i < reply.length; i++) {
const _address = reply[i].data.split(' ');
const coin = _address[0].replace('"oa1:', '');
const coinAddress = _address[1].replace('recipient_address=', '').replace(';', '');
if (coin.toUpperCase() === this.props.ActiveCoin.coin) {
this.setState(Object.assign({}, this.state, {
sendTo: coinAddress,
}));
}
}
if (this.state.sendTo === '') {
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'));
}
}.bind(this));
}
renderOASendUI() {
if (Config.openAlias) {
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>
<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">
<button type="button" className="btn btn-primary waves-effect waves-light" data-toggle="modal" id="kmd_wallet_send_coins_btn" onClick={this.getOAdress}>
Get address
</button>
</div>
</div>
);
} else {
return null;
}
}
render() {
if (this.props && this.props.ActiveCoin && this.props.ActiveCoin.nativeActiveSection === 'send') {
return (
@ -200,13 +255,16 @@ class WalletsNativeSend extends React.Component {
<label className="control-label" data-extcoin="COIN" htmlFor="kmd_wallet_send_from">{translate('INDEX.SEND_FROM')}</label>
{this.renderAddressList()}
</div>
</div>
{this.renderOASendUI()}
<div className="row">
<div className="col-xlg-12 form-group form-material">
<label className="control-label" data-extcoin="COIN" htmlFor="kmd_wallet_sendto">{translate('INDEX.SEND_TO')}</label>
<input type="text" className="form-control" data-extcoin="COIN" name="sendTo" onChange={this.updateInput} id="kmd_wallet_sendto" placeholder="Enter Transparent or Private address" autoComplete="off" required />
<input type="text" className="form-control" data-extcoin="COIN" name="sendTo" onChange={this.updateInput} value={this.state.sendTo} id="kmd_wallet_sendto" placeholder="Enter Transparent or Private address" autoComplete="off" required />
</div>
<div className="col-lg-6 form-group form-material">
<label className="control-label" htmlFor="kmd_wallet_amount" data-extcoin="COIN" id="kmd_wallet_amount_label">
<span data-extcoinname="COIN"></span>
{this.props.ActiveCoin.coin}
</label>
<input type="text" className="form-control" name="amount" onChange={this.updateInput} data-extcoin="COIN" id="kmd_wallet_amount" placeholder="0.000" autoComplete="off" />
</div>

1
react/src/config.js

@ -4,4 +4,5 @@ module.exports = {
agamaPort: 17777,
enableCacheApi: true,
useBasiliskInstance: true,
openAlias: true,
};

Loading…
Cancel
Save