From a23114ffd9bb3bf02daa9198afa80880466b5ce0 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Wed, 19 Apr 2017 09:07:33 +0300 Subject: [PATCH] wallet components #6 --- react/src/actions/actionCreators.js | 134 +++++++++++++++--- .../src/components/dashboard/coinTileItem.js | 10 +- react/src/components/dashboard/dashboard.js | 2 +- react/src/components/dashboard/receiveCoin.js | 2 + react/src/components/dashboard/sendCoin.js | 92 ++++++++---- react/src/components/dashboard/walletsData.js | 17 ++- .../src/components/dashboard/walletsNative.js | 2 +- .../dashboard/walletsNativeReceive.js | 1 + .../components/dashboard/walletsNativeSend.js | 10 +- .../src/components/dashboard/walletsTxInfo.js | 18 +-- react/src/config.js | 3 +- react/src/reducers/activeCoin.js | 8 +- 12 files changed, 224 insertions(+), 75 deletions(-) diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index 325fd3a..5aeab29 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -40,6 +40,7 @@ export const DASHBOARD_ACTIVE_TXINFO_MODAL = 'DASHBOARD_ACTIVE_TXINFO_MODAL'; export const DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE = 'DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE'; 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 function toggleDashboardActiveSection(name) { return { @@ -661,6 +662,31 @@ export function getFullTransactionsList(coin) { } } +export function getBasiliskTransactionsList(coin, address) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'dex', + 'method': 'listtransactions', + 'address': address, + 'count': 100, + 'skip': 0, + 'symbol': coin + }; + + 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, 'getBasiliskTransactionsList', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(getNativeTxHistoryState(json))) + } +} + export function getPeersList(coin) { const payload = { 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), @@ -907,7 +933,7 @@ export function getKMDAddressesNative(coin, mode) { }; } - if (mode !== 'native') { + if (mode !== 'native' || mode !== 'basilisk') { payload = { 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), 'coin': coin, @@ -962,11 +988,20 @@ export function getKMDAddressesNative(coin, mode) { 'params': [ 1, 9999999, - //[ atomic_explorer_input_data_val ] ] }; } + if (mode === 'basilisk') { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'dex', + 'method': 'listunspent', + 'address': 'RDbGxL8QYdEp8sMULaVZS2E6XThcTKT9Jd', + 'symbol': coin + }; + } + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { method: 'POST', body: JSON.stringify(payload), @@ -977,30 +1012,33 @@ export function getKMDAddressesNative(coin, mode) { }) .then(response => response.json()) .then(function(json) { - if (mode === 'full') { + console.log('getaddrjson', result[0]); + if (mode === 'full' || mode === 'basilisk') { result[0] = result[0].result; } - const allAddrArray = json.map(res => res.address).filter((x, i, a) => a.indexOf(x) == i); - for (let a=0; a < allAddrArray.length; a++) { - const filteredArray = json.filter(res => res.address === allAddrArray[a]).map(res => res.amount); - - let isNewAddr = true; - for (let x=0; x < result.length && isNewAddr; x++) { - for (let y=0; y < result[x].length && isNewAddr; y++) { - if (allAddrArray[a] === result[x][y]) { - isNewAddr = false; + if (mode !== 'basilisk') { + const allAddrArray = json.map(res => res.address).filter((x, i, a) => a.indexOf(x) == i); + for (let a=0; a < allAddrArray.length; a++) { + const filteredArray = json.filter(res => res.address === allAddrArray[a]).map(res => res.amount); + + let isNewAddr = true; + for (let x=0; x < result.length && isNewAddr; x++) { + for (let y=0; y < result[x].length && isNewAddr; y++) { + if (allAddrArray[a] === result[x][y]) { + isNewAddr = false; + } } } - } - if (isNewAddr) { - if (allAddrArray[a].substring(0, 2) === 'zc' || allAddrArray[a].substring(0, 2) === 'zt') { - result[1][result[1].length] = allAddrArray[a]; - } else { - result[0][result[0].length] = allAddrArray[a]; + if (isNewAddr) { + if (allAddrArray[a].substring(0, 2) === 'zc' || allAddrArray[a].substring(0, 2) === 'zt') { + result[1][result[1].length] = allAddrArray[a]; + } else { + result[0][result[0].length] = allAddrArray[a]; + } + console.log('new addr ' + allAddrArray[a] + ' | ' + allAddrArray[a].substring(0, 2)); } - console.log('new addr ' + allAddrArray[a] + ' | ' + allAddrArray[a].substring(0, 2)); } } @@ -1010,7 +1048,14 @@ export function getKMDAddressesNative(coin, mode) { newAddressArray[a] = []; for (let b=0; b < result[a].length; b++) { - const filteredArray = json.filter(res => res.address === result[a][b]).map(res => res.amount); + var filteredArray; + + if (mode === 'basilisk') { + filteredArray = json.map(res => res.amount); + } else { + filteredArray = json.filter(res => res.address === result[a][b]).map(res => res.amount); + } + let sum = 0; for (let i=0; i < filteredArray.length; i++) { @@ -1500,6 +1545,55 @@ export function getKMDOPID(opid, coin) { } } +function sendToAddressState(json, dispatch) { + if (json && json.error) { + dispatch(triggerToaster(true, json.error, 'Error', 'error')); + + return { + type: DASHBOARD_ACTIVE_COIN_SENDTO, + lastSendToResponse: json.error, + } + } else if (json && json.result && json.complete) { + dispatch(triggerToaster(true, translate('TOASTR.TX_SENT_ALT'), translate('TOASTR.WALLET_NOTIFICATION'), 'success')); + + return { + type: DASHBOARD_ACTIVE_COIN_SENDTO, + lastSendToResponse: json, + } + } +} + +export function sendToAddress(coin, _payload) { + var payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'coin': coin, + 'method': 'sendtoaddress', + 'params': [ + _payload.sendTo, + _payload.amount, + 'EasyDEX', + 'EasyDEXTransaction' + ] + }; + + return dispatch => { + const json = {"result":"1c629f37ed45a4734e27e5cf699907dc29d278a09a48d8564e2bf9571687a1d9","signedtx":"0100000001ff3de00c3ef4f2eefbda19debe2d454031f80481fd7a6db07a8faa3e8094f5be010000006b48304502210093ab5029e24645acaa014fc806a43caa8ba55ebc5767647d235f568ce045cf0c022055925b481e9cb9210a17dd5df01360420aea4b3bfd8b632e9b5e506309cfac14012102743d2afdb88ede68fb5938e961b1f41c2b6267b3286516543eb4e4ab87ad0d0affffffff02a0860100000000001976a9142f4c0f91fc06ac228c120aee41741d0d3909683288aca070da14000000001976a9142f4c0f91fc06ac228c120aee41741d0d3909683288ac00000000","complete":true,"sendrawtransaction":"success","tag":"9015189477602923119"}; + dispatch(sendToAddressState(json, dispatch)); + } + /*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, 'sendToAddress', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(sendToAddressHandler(json))) + }*/ +} + /*function Shepherd_SendPendValue() { Shepherd_SysInfo().then(function(result){ var ram_data = formatBytes(result.totalmem_bytes) diff --git a/react/src/components/dashboard/coinTileItem.js b/react/src/components/dashboard/coinTileItem.js index 724566e..3a5f957 100644 --- a/react/src/components/dashboard/coinTileItem.js +++ b/react/src/components/dashboard/coinTileItem.js @@ -13,7 +13,8 @@ import { getNativeTxHistory, getKMDAddressesNative, getKMDOPID, - getFullTransactionsList + getFullTransactionsList, + getBasiliskTransactionsList } from '../../actions/actionCreators'; import Store from '../../store'; @@ -50,7 +51,12 @@ class CoinTileItem extends React.Component { Store.dispatch(startInterval('sync', _iguanaActiveHandle)); } if (mode === 'basilisk') { - Store.dispatch(getAddressesByAccount(coin)); + var _iguanaActiveHandle = setInterval(function() { + Store.dispatch(getBasiliskTransactionsList(coin, 'RDbGxL8QYdEp8sMULaVZS2E6XThcTKT9Jd')); + Store.dispatch(iguanaEdexBalance(coin, mode)); + Store.dispatch(getKMDAddressesNative(coin, mode)); + }, 3000); + Store.dispatch(startInterval('sync', _iguanaActiveHandle)); // basilisk } } diff --git a/react/src/components/dashboard/dashboard.js b/react/src/components/dashboard/dashboard.js index 63d780f..2564891 100644 --- a/react/src/components/dashboard/dashboard.js +++ b/react/src/components/dashboard/dashboard.js @@ -38,7 +38,7 @@ class Dashboard extends React.Component { - + diff --git a/react/src/components/dashboard/receiveCoin.js b/react/src/components/dashboard/receiveCoin.js index 01d43ff..830f406 100644 --- a/react/src/components/dashboard/receiveCoin.js +++ b/react/src/components/dashboard/receiveCoin.js @@ -1,6 +1,8 @@ import React from 'react'; import { translate } from '../../translate/translate'; +// TODO: implement sorting + class ReceiveCoin extends React.Component { renderAddressList() { if (this.props.addresses && this.props.addresses['public'] && this.props.addresses['public'].length) { diff --git a/react/src/components/dashboard/sendCoin.js b/react/src/components/dashboard/sendCoin.js index 06e69ac..9701b0e 100644 --- a/react/src/components/dashboard/sendCoin.js +++ b/react/src/components/dashboard/sendCoin.js @@ -1,7 +1,7 @@ import React from 'react'; import { translate } from '../../translate/translate'; -//import { } from '../../actions/actionCreators'; -//import Store from '../../store'; +import { sendToAddress } from '../../actions/actionCreators'; +import Store from '../../store'; // TODO: implement logic @@ -10,17 +10,65 @@ class SendCoin extends React.Component { super(props); this.state = { currentStep: 0, + sendFrom: this.props.Dashboard && this.props.Dashboard.activeHandle ? this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin] : null, + sendFromAmount: 0, + sendTo: null, + amount: 0, + fee: 0.0001, + sendSig: false, }; + this.updateInput = this.updateInput.bind(this); + this.handleSubmit = this.handleSubmit.bind(this); + this.toggleSendSig = this.toggleSendSig.bind(this); } changeSendCoinStep(step) { this.setState(Object.assign({}, this.state, { currentStep: step, })); + + if (step === 2) { + Store.dispatch(sendToAddress(this.props.ActiveCoin.coin, this.state)); + } + } + + toggleSendSig() { + this.setState(Object.assign({}, this.state, { + sendSig: !this.state.sendSig, + })); + } + + updateInput(e) { + this.setState({ + [e.target.name]: e.target.value, + }); + console.log(this.state); + } + + handleSubmit() { + Store.dispatch(sendNativeTx(this.props.ActiveCoin.coin, this.state)); + setTimeout(function() { + Store.dispatch(getKMDOPID(null, this.props.ActiveCoin.coin)); + }, 1000); + } + + renderSendCoinResponse() { + if (this.props.ActiveCoin.lastSendToResponse) { + return Object.keys(this.props.ActiveCoin.lastSendToResponse).map((key, index) => + + {key} + {key === 'signedtx' ? ( + this.props.ActiveCoin.lastSendToResponse[key].substring(0, this.props.ActiveCoin.lastSendToResponse[key].length / 3) + ' ' + + this.props.ActiveCoin.lastSendToResponse[key].substring(this.props.ActiveCoin.lastSendToResponse[key].length / 3, this.props.ActiveCoin.lastSendToResponse[key].length * 2 / 3)) : this.props.ActiveCoin.lastSendToResponse[key]} + + ); + } else { + return null; + } } render() { - if (this.props && this.props.send && this.props.mode !== 'native') { + if (this.props.ActiveCoin && this.props.ActiveCoin.send && this.props.ActiveCoin.mode !== 'native') { return (
@@ -51,49 +99,44 @@ class SendCoin extends React.Component {

- {translate('INDEX.SEND')} + {translate('INDEX.SEND')} {this.props.ActiveCoin.coin}

-
-
+
- +
- +
- +
- +
- {translate('INDEX.TOTAL')} ({translate('INDEX.AMOUNT_SM')} - txfee): 0.000 + {translate('INDEX.TOTAL')} ({translate('INDEX.AMOUNT_SM')} - txfee): {Number(this.state.amount) - Number(this.state.fee)} {this.props.ActiveCoin.coin}
- +
- +
@@ -109,13 +152,13 @@ class SendCoin extends React.Component {
{translate('INDEX.TO')}
-
[coin-address-goes-here]
+
{this.state.sendTo}
- 0.00000000 [COIN] + {this.state.amount} {this.props.ActiveCoin.coin}
{translate('INDEX.TX_FEE_REQ')}
- 0.00000000 [COIN] + {this.state.fee} {this.props.ActiveCoin.coin}

@@ -124,9 +167,9 @@ class SendCoin extends React.Component {
{translate('INDEX.FROM')}
-
[coin-address-goes-here]
+
{this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin]}
- -0.00000000 [COIN] + {Number(this.state.amount) - Number(this.state.fee)} {this.props.ActiveCoin.coin}
@@ -151,6 +194,7 @@ class SendCoin extends React.Component { + {this.renderSendCoinResponse()}
diff --git a/react/src/components/dashboard/walletsData.js b/react/src/components/dashboard/walletsData.js index 4a0c3bb..c97ebf5 100644 --- a/react/src/components/dashboard/walletsData.js +++ b/react/src/components/dashboard/walletsData.js @@ -148,14 +148,14 @@ class WalletsData extends React.Component { } renderTxType(category) { - if ( category === 'send' ) { + if ( category === 'send' || category === 'sent' ) { return ( {translate('DASHBOARD.OUT')} ); } - if ( category === 'receive' ) { + if ( category === 'receive' || category === 'received' ) { return ( {translate('DASHBOARD.IN')} @@ -176,16 +176,23 @@ class WalletsData extends React.Component { ); } + if ( category === 'unknown' ) { + return ( + + {translate('DASHBOARD.UNKNOWN')} + + ); + } } renderTxHistoryList() { if (this.state.itemsList && this.state.itemsList.length) { return this.state.itemsList.map((tx, index) => - {this.renderTxType(tx.category)} + {this.renderTxType(tx.category || tx.type)} {tx.confirmations} - {tx.amount} - {secondsToString(tx.blocktime)} + {tx.amount || translate('DASHBOARD.UNKNOWN')} + {secondsToString(tx.blocktime || tx.timestamp)} {tx.address} diff --git a/react/src/components/dashboard/walletsNative.js b/react/src/components/dashboard/walletsNative.js index 9f1640f..361a4c5 100644 --- a/react/src/components/dashboard/walletsNative.js +++ b/react/src/components/dashboard/walletsNative.js @@ -13,6 +13,7 @@ class WalletsNative extends React.Component { super(props); } + // render() { if (this.props && this.props.ActiveCoin && this.props.ActiveCoin.mode === 'native') { return ( @@ -26,7 +27,6 @@ class WalletsNative extends React.Component {
-
diff --git a/react/src/components/dashboard/walletsNativeReceive.js b/react/src/components/dashboard/walletsNativeReceive.js index dea9b93..dba6835 100644 --- a/react/src/components/dashboard/walletsNativeReceive.js +++ b/react/src/components/dashboard/walletsNativeReceive.js @@ -3,6 +3,7 @@ import { translate } from '../../translate/translate'; import { getNewKMDAddresses, copyCoinAddress } from '../../actions/actionCreators'; import Store from '../../store'; +// TODO: implement sorting // TODO: importaddress, importprivkey(?) class WalletsNativeReceive extends React.Component { diff --git a/react/src/components/dashboard/walletsNativeSend.js b/react/src/components/dashboard/walletsNativeSend.js index 42b522a..d1cc817 100644 --- a/react/src/components/dashboard/walletsNativeSend.js +++ b/react/src/components/dashboard/walletsNativeSend.js @@ -103,13 +103,13 @@ class WalletsNativeSend extends React.Component { if (opid.status === 'queued') { isWaitingStatus = false; return ( - {translate('KMD_NATIVE.PLEASE_REFRESH')}... + Awaiting in queue... ); } if (opid.status === 'executing') { isWaitingStatus = false; return ( - {translate('KMD_NATIVE.PLEASE_REFRESH')}... + Processing... ); } if (opid.status === 'failed') { @@ -176,7 +176,6 @@ class WalletsNativeSend extends React.Component { } handleSubmit() { - console.log(this.state); Store.dispatch(sendNativeTx(this.props.ActiveCoin.coin, this.state)); setTimeout(function() { Store.dispatch(getKMDOPID(null, this.props.ActiveCoin.coin)); @@ -238,11 +237,6 @@ class WalletsNativeSend extends React.Component {
-
- -

{translate('INDEX.OPERATIONS_STATUSES')}

diff --git a/react/src/components/dashboard/walletsTxInfo.js b/react/src/components/dashboard/walletsTxInfo.js index c5fed44..5ee6e53 100644 --- a/react/src/components/dashboard/walletsTxInfo.js +++ b/react/src/components/dashboard/walletsTxInfo.js @@ -51,6 +51,12 @@ class WalletsTxInfo extends React.Component {
+ + + + - - - - - - - -
address + {txInfo.address} +
amount @@ -87,18 +93,6 @@ class WalletsTxInfo extends React.Component { {txInfo.txid}
time - {secondsToString(txInfo.time)} -
timereceived - {secondsToString(txInfo.timereceived)} -
diff --git a/react/src/config.js b/react/src/config.js index bb2d029..e2553a8 100644 --- a/react/src/config.js +++ b/react/src/config.js @@ -1,4 +1,5 @@ module.exports = { iguanaCorePort: 7778, - agamaPort: 17777 + agamaPort: 17777, + enableCacheApi: false, }; diff --git a/react/src/reducers/activeCoin.js b/react/src/reducers/activeCoin.js index bf1d5b3..8e34018 100644 --- a/react/src/reducers/activeCoin.js +++ b/react/src/reducers/activeCoin.js @@ -9,7 +9,8 @@ import { ACTIVE_COIN_GET_ADDRESSES, DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE, DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY, - DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS + DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS, + DASHBOARD_ACTIVE_COIN_SENDTO } from '../actions/actionCreators'; // TODO: keep all coin data in array of objects instead of single object @@ -25,6 +26,7 @@ export function ActiveCoin(state = { showTransactionInfoTxIndex: null, txhistory: [], opids: null, + lastSendToResponse: null, }, action) { switch (action.type) { case DASHBOARD_ACTIVE_COIN_CHANGE: @@ -83,6 +85,10 @@ export function ActiveCoin(state = { return Object.assign({}, state, { opids: action.opids, }); + case DASHBOARD_ACTIVE_COIN_SENDTO: + return Object.assign({}, state, { + lastSendToResponse: action.lastSendToResponse, + }); default: return state; }