diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index 266050d..1b3529c 100644 --- a/react/src/actions/actionCreators.js +++ b/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'), diff --git a/react/src/components/dashboard/sendCoin.js b/react/src/components/dashboard/sendCoin.js index 2e2202c..86d42c0 100644 --- a/react/src/components/dashboard/sendCoin.js +++ b/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 { false ); } - } + } } 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 ( +
+
+ + +
+
+ +
+
+ ); + } 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 { + + {this.renderOASendUI()} +
- +
+
+ {this.renderOASendUI()} +
- +
diff --git a/react/src/config.js b/react/src/config.js index 700a203..0eb154b 100644 --- a/react/src/config.js +++ b/react/src/config.js @@ -4,4 +4,5 @@ module.exports = { agamaPort: 17777, enableCacheApi: true, useBasiliskInstance: true, + openAlias: true, };