diff --git a/react/src/actions/actionCreators.js b/react/src/actions/actionCreators.js index 4cd9df5..307b763 100644 --- a/react/src/actions/actionCreators.js +++ b/react/src/actions/actionCreators.js @@ -2,17 +2,48 @@ import 'whatwg-fetch'; import 'bluebird'; import _config from '../config'; -import { - startCurrencyAssetChain, - startAssetChain, - startCrypto, - checkCoinType, - checkAC -} from '../components/addcoin/payload'; -import { copyToClipboard } from '../util/copyToClipboard'; import { translate } from '../translate/translate'; - -let Config; +import * as storeType from './storeType'; +import { + logGuiHttp, + getAgamaLog, + guiLogState +} from './log'; + +export * from './nativeSyncInfo'; +export * from './basiliskCache'; +export * from './nativeSend'; +export * from './coinList'; +export * from './syncOnly'; +export * from './createWallet'; +export * from './nativeTxHistory'; +export * from './nativeBalance'; +export * from './nativeNewAddress'; +export * from './logout'; +export * from './syncOnly'; +export * from './basiliskProcessAddress'; +export * from './edexGetTx'; +export * from './sendFullBasilisk'; +export * from './settings'; +export * from './syncOnly'; +export * from './iguanaInstance'; +export * from './notary'; +export * from './edexBalance'; +export * from './addCoin'; +export * from './addressBalance'; +export * from './syncInfo'; +export * from './getAddrByAccount'; +export * from './atomic'; +export * from './walletAuth'; +export * from './openAlias'; +export * from './copyAddress'; +export * from './sysInfo'; +export * from './dexCoins'; +export * from './fullTxHistory'; +export * from './basiliskTxHistory'; +export * from './iguanaHelpers'; + +export let Config; try { Config = window.require('electron').remote.getCurrentWindow().appConfig; @@ -20,117 +51,76 @@ try { Config = _config; } -export const TOASTER_MESSAGE = 'TOASTER_MESSAGE'; -export const DISPLAY_ADDCOIN_MODAL = 'DISPLAY_ADDCOIN_MODAL'; -export const GET_ACTIVE_COINS = 'GET_ACTIVE_COINS'; -export const LOGIN = 'LOGIN'; -export const ACTIVE_HANDLE = 'ACTIVE_HANDLE'; -export const DASHBOARD_SECTION_CHANGE = 'DASHBOARD_SECTION_CHANGE'; -export const DASHBOARD_ACTIVE_COIN_CHANGE = 'DASHBOARD_ACTIVE_COIN_CHANGE'; -export const GET_MAIN_ADDRESS = 'GET_MAIN_ADDRESS'; -export const DASHBOARD_ACTIVE_COIN_BALANCE = 'DASHBOARD_ACTIVE_COIN_BALANCE'; -export const DASHBOARD_ACTIVE_COIN_SEND_FORM = 'DASHBOARD_ACTIVE_COIN_SEND_FORM'; -export const DASHBOARD_ACTIVE_COIN_RECEIVE_FORM = 'DASHBOARD_ACTIVE_COIN_RECEIVE_FORM'; -export const DASHBOARD_ACTIVE_COIN_RESET_FORMS = 'DASHBOARD_ACTIVE_COIN_RESET_FORMS'; -export const ATOMIC = 'ATOMIC'; -export const GET_WIF_KEY = 'GET_WIF_KEY'; -export const GET_PEERS_LIST = 'GET_PEERS_LIST'; -export const GET_DEBUG_LOG = 'GET_DEBUG_LOG'; -export const BASILISK_REFRESH = 'BASILISK_REFRESH'; -export const BASILISK_CONNECTION = 'BASILISK_CONNECTION'; -export const SYNCING_FULL_MODE = 'SYNCING_FULL_MODE'; -export const SYNCING_NATIVE_MODE = 'SYNCING_NATIVE_MODE'; -export const ACTIVE_COIN_GET_ADDRESSES = 'ACTIVE_COIN_GET_ADDRESSES'; -export const START_INTERVAL= 'START_INTERVAL'; -export const STOP_INTERVAL= 'STOP_INTERVAL'; -export const DASHBOARD_ACTIVE_SECTION = 'DASHBOARD_ACTIVE_SECTION'; -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 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 const DASHBOARD_GET_NOTARIES_LIST = 'DASHBOARD_GET_NOTARIES_LIST'; -export const DASHBOARD_DISPLAY_NOTARIES_MODAL = 'DASHBOARD_DISPLAY_NOTARIES_MODAL'; -export const DASHBOARD_CONNECT_NOTARIES = 'DASHBOARD_CONNECT_NOTARIES'; -export const VIEW_CACHE_DATA = 'VIEW_CACHE_DATA'; -export const SYNC_ONLY_MODAL_TOGGLE = 'SYNC_ONLY_MODAL_TOGGLE'; -export const SYNC_ONLY_DATA = 'SYNC_ONLY_DATA'; -export const LOAD_APP_CONFIG = 'LOAD_APP_CONFIG'; -export const SAVE_APP_CONFIG = 'SAVE_APP_CONFIG'; -export const SERVICE_ERROR = 'SERVICE_ERROR'; -export const DASHBOARD_ACTIVE_ADDRESS = 'DASHBOARD_ACTIVE_ADDRESS'; -export const LOAD_APP_INFO = 'LOAD_APP_INFO'; -export const LOG_GUI_HTTP = 'LOG_GUI_HTTP'; - -export function changeActiveAddress(address) { +export function triggerToaster(display, message, title, _type) { return { - type: DASHBOARD_ACTIVE_ADDRESS, - address, + type: storeType.TOASTER_MESSAGE, + display, + message, + title, + _type, } } -function updateErrosStack(method) { +export function changeActiveAddress(address) { return { - apiMethod: method, + type: storeType.DASHBOARD_ACTIVE_ADDRESS, + address, } } -export function toggleSyncOnlyModal(display) { +export function updateErrosStack(method) { return { - type: SYNC_ONLY_MODAL_TOGGLE, - display, + apiMethod: method, } } export function toggleViewCacheModal(display) { return { - type: VIEW_CACHE_DATA, + type: storeType.VIEW_CACHE_DATA, display, } } export function displayNotariesModal(display) { return { - type: DASHBOARD_DISPLAY_NOTARIES_MODAL, + type: storeType.DASHBOARD_DISPLAY_NOTARIES_MODAL, display, } } export function changeMainBasiliskAddress(address) { return { - type: DASHBOARD_ACTIVE_COIN_MAIN_BASILISK_ADDR, + type: storeType.DASHBOARD_ACTIVE_COIN_MAIN_BASILISK_ADDR, address, } } export function toggleDashboardActiveSection(name) { return { - type: DASHBOARD_ACTIVE_SECTION, + type: storeType.DASHBOARD_ACTIVE_SECTION, section: name, } } export function toggleDashboardTxInfoModal(display, txIndex) { return { - type: DASHBOARD_ACTIVE_TXINFO_MODAL, + type: storeType.DASHBOARD_ACTIVE_TXINFO_MODAL, showTransactionInfo: display, showTransactionInfoTxIndex: txIndex, } } -function basiliskConnectionState(display, json) { +export function basiliskConnectionState(display, json) { return { - type: BASILISK_CONNECTION, + type: storeType.BASILISK_CONNECTION, basiliskConnection: display, progress: json, } } -function basiliskRefreshState(display, json) { +export function basiliskRefreshState(display, json) { return { - type: BASILISK_REFRESH, + type: storeType.BASILISK_REFRESH, basiliskRefresh: display, progress: json, } @@ -150,7 +140,7 @@ export function basiliskConnection(display) { export function syncingNativeModeState(display, json) { return { - type: SYNCING_FULL_MODE, + type: storeType.SYNCING_FULL_MODE, syncingNativeMode: display, progress: json, } @@ -158,91 +148,53 @@ export function syncingNativeModeState(display, json) { export function syncingFullModeState(display, json) { return { - type: SYNCING_NATIVE_MODE, + type: storeType.SYNCING_NATIVE_MODE, syncingFullMode: display, progress: json, } } -function atomicState(json) { +export function toggleSendCoinFormState(display) { return { - type: ATOMIC, - response: json, - } -} - -function toggleSendCoinFormState(display) { - return { - type: DASHBOARD_ACTIVE_COIN_SEND_FORM, + type: storeType.DASHBOARD_ACTIVE_COIN_SEND_FORM, send: display, } } -function toggleReceiveCoinFormState(display) { +export function toggleReceiveCoinFormState(display) { return { - type: DASHBOARD_ACTIVE_COIN_RECEIVE_FORM, + type: storeType.DASHBOARD_ACTIVE_COIN_RECEIVE_FORM, receive: display, } } -function toggleSendReceiveCoinFormsState() { +export function toggleSendReceiveCoinFormsState() { return { - type: DASHBOARD_ACTIVE_COIN_RESET_FORMS, + type: storeType.DASHBOARD_ACTIVE_COIN_RESET_FORMS, send: false, receive: false, } } -export function triggerToaster(display, message, title, _type) { - return { - type: TOASTER_MESSAGE, - display, - message, - title, - _type, - } -} - -function toggleAddcoinModalState(display, isLogin) { +export function toggleAddcoinModalState(display, isLogin) { return { - type: DISPLAY_ADDCOIN_MODAL, + type: storeType.DISPLAY_ADDCOIN_MODAL, display: display, isLogin: isLogin, } } -function dashboardCoinsState(json) { +export function dashboardCoinsState(json) { return { - type: GET_ACTIVE_COINS, + type: storeType.GET_ACTIVE_COINS, coins: json, activeCoins: Object.keys(json.native).length || Object.keys(json.basilisk).length || Object.keys(json.full).length ? true : false } } -function iguanaWalletPassphraseState(json, dispatch) { - console.log('iguanaWalletPassphraseState', json); - sessionStorage.setItem('IguanaActiveAccount', JSON.stringify(json)); - dispatch(triggerToaster(true, translate('TOASTR.LOGIN_SUCCESSFULL'), translate('TOASTR.ACCOUNT_NOTIFICATION'), 'success')); - dispatch(getMainAddressState(json)); - dispatch(iguanaActiveHandleState(json)); - - return { - type: LOGIN, - isLoggedIn: json && json.pubkey ? true : false, - } -} - -function iguanaActiveHandleState(json) { - return { - type: ACTIVE_HANDLE, - isLoggedIn: sessionStorage.getItem('IguanaActiveAccount') && JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey === json.pubkey && json.status === 'unlocked' ? true : false, - handle: json, - } -} - -function getMainAddressState(json) { +export function getMainAddressState(json) { return { - type: GET_MAIN_ADDRESS, + type: storeType.GET_MAIN_ADDRESS, activeHandle: json, } } @@ -265,68 +217,9 @@ export function toggleSendReceiveCoinForms() { } } -function logoutState(json, dispatch) { - console.log('passp', json); - sessionStorage.removeItem('IguanaActiveAccount'); - - return { - type: LOGIN, - isLoggedIn: false, - } -} - -export function logout() { - return dispatch => { - dispatch(walletLock()); - } -} - -function walletLock() { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'bitcoinrpc', - 'method': 'walletlock', - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'walletLock', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'walletLock', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(logoutState(json)); - }) - } -} - -function dashboardChangeSectionState(sectionName) { +export function dashboardChangeSectionState(sectionName) { return { - type: DASHBOARD_SECTION_CHANGE, + type: storeType.DASHBOARD_SECTION_CHANGE, activeSection: sectionName, } } @@ -337,21 +230,14 @@ export function dashboardChangeSection(sectionName) { } } -function dashboardChangeActiveCoinState(coin, mode) { +export function dashboardChangeActiveCoinState(coin, mode) { return { - type: DASHBOARD_ACTIVE_COIN_CHANGE, + type: storeType.DASHBOARD_ACTIVE_COIN_CHANGE, coin: coin, mode: mode, } } -function iguanaEdexBalanceState(json) { - return { - type: DASHBOARD_ACTIVE_COIN_BALANCE, - balance: json && json.result ? json.result : 0, - } -} - export function dashboardChangeActiveCoin(coin, mode) { return dispatch => { dispatch(dashboardChangeActiveCoinState(coin, mode)); @@ -364,306 +250,14 @@ export function toggleAddcoinModal(display, isLogin) { } } -export function copyCoinAddress(address) { - const _result = copyToClipboard(address); - - if (_result) { - return dispatch => { - dispatch(triggerToaster(true, translate('DASHBOARD.ADDR_COPIED'), translate('TOASTR.COIN_NOTIFICATION'), 'success')); - } - } else { - return dispatch => { - dispatch(triggerToaster(true, 'Couldn\'t copy address to clipboard', translate('TOASTR.COIN_NOTIFICATION'), 'error')); - } - } -} - export function dismissToasterMessage() { return dispatch => { dispatch(triggerToaster(false)) } } -export function addCoin(coin, mode, syncOnly, port) { - console.log('coin, mode, syncOnly', coin + ' ' + mode + ' ' + syncOnly); - if (mode === '-1') { - return dispatch => { - dispatch(shepherdGetConfig(coin, mode)); - } - } else { - if (checkCoinType(coin) === 'currency_ac') { - const _acData = startCurrencyAssetChain('', coin, mode); - - return dispatch => { - dispatch(iguanaAddCoin(coin, mode, _acData)); - } - } - if (checkCoinType(coin) === 'ac') { - const _acData = startAssetChain('', coin, mode); - - return dispatch => { - dispatch(iguanaAddCoin(coin, mode, _acData)); - } - } - if (checkCoinType(coin) === 'crypto') { - const _acData = startCrypto('', coin, mode); - - if (syncOnly) { - const modeToValue = { - '1': 'full', - '0': 'basilisk', - '-1': 'native' - }; - - return dispatch => { - startIguanaInstance(modeToValue[mode] + '/sync', coin) - .then(function(json) { - setTimeout(function() { - console.log('started ' + coin + ' / ' + modeToValue[mode] + ' fork', json); - dispatch(iguanaAddCoin(coin, mode, _acData, json.result)); - }, 2000); - }); - } - } else { - if (port) { - return dispatch => { - dispatch(iguanaAddCoin(coin, mode, _acData, port)); - } - } else { - return dispatch => { - dispatch(iguanaAddCoin(coin, mode, _acData)); - } - } - } - } - } -} - -export function iguanaAddCoin(coin, mode, acData, port) { - function _iguanaAddCoin(dispatch) { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'iguanaAddCoin', - 'type': 'post', - 'url': 'http://127.0.0.1:' + (port ? port : Config.iguanaCorePort), - 'payload': acData, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + (port ? port : Config.iguanaCorePort), { - method: 'POST', - body: JSON.stringify(acData), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, translate('TOASTR.FAILED_TO_ADDCOIN'), translate('TOASTR.ACCOUNT_NOTIFICATION'), 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(addCoinResult(coin, mode, acData)) - }); - } - - if (mode === 0) { - return dispatch => { - return _iguanaAddCoin(dispatch); - } - } else { - return dispatch => { - return _iguanaAddCoin(dispatch); - } - } -} - -export function shepherdHerd(coin, mode, path) { - let acData; - let herdData = { - 'ac_name': coin, - 'ac_options': [ - '-daemon=0', - '-server', - '-ac_name=' + coin, - '-addnode=78.47.196.146' - ] - }; - - if (coin === 'ZEC') { - herdData = { - 'ac_name': 'zcashd', - 'ac_options': [ - '-daemon=0', - '-server=1' - ] - }; - } - - if (coin === 'KMD') { - herdData = { - 'ac_name': 'komodod', - 'ac_options': [ - '-daemon=0', - '-addnode=78.47.196.146' - ] - }; - } - - if (checkCoinType(coin) === 'crypto') { - acData = startCrypto(path.result, coin, mode); - } - if (checkCoinType(coin) === 'currency_ac') { - acData = startCurrencyAssetChain(path.result, coin, mode); - } - if (checkCoinType(coin) === 'ac') { - acData = startAssetChain(path.result, coin, mode); - var supply = startAssetChain(path.result, coin, mode, true); - herdData.ac_options.push('-ac_supply=' + supply); - } - - console.log('herdData', herdData); - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/herd', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - 'herd': coin !== 'ZEC' ? 'komodod' : 'zcashd', - 'options': herdData - }), - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, translate('FAILED_SHEPHERD_HERD'), translate('TOASTR.SERVICE_NOTIFICATION'), 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(iguanaAddCoin(coin, mode, acData))); - } -} - -export function addCoinResult(coin, mode) { - const modeToValue = { - '1': 'full', - '0': 'basilisk', - '-1': 'native' - }; - - return dispatch => { - dispatch(triggerToaster(true, coin + ' ' + translate('TOASTR.STARTED_IN') + ' ' + modeToValue[mode] + ' ' + translate('TOASTR.MODE'), translate('TOASTR.COIN_NOTIFICATION'), 'success')); - dispatch(toggleAddcoinModal(false, false)); - dispatch(getDexCoins()); - } -} - -export function _shepherdGetConfig(coin, mode) { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/getconf', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ 'chain': 'komodod' }) - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'Failed to get mode config', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(shepherdHerd(coin, mode, json))); - } -} - -export function shepherdGetConfig(coin, mode) { - if (coin === 'KMD' && - mode === '-1') { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/getconf', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ 'chain': 'komodod' }) - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'Failed to get KMD config', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(shepherdHerd(coin, mode, json))) - } - } else { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/getconf', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ 'chain': coin }) - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'Failed to get mode config', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(shepherdHerd(coin, mode, json))); - } - } -} - -export function getDexCoins() { - const _payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'InstantDEX', - 'method': 'allcoins', - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getDexCoins', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': _payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(_payload) - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'Error getDexCoins', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(dashboardCoinsState(json)); - }); - } -} - -function rpcErrorHandler(json, dispatch) { +// TODO +export function rpcErrorHandler(json, dispatch) { console.log('json', json); if (json && json.error) { @@ -673,485 +267,6 @@ function rpcErrorHandler(json, dispatch) { } } -export function iguanaWalletPassphrase(_passphrase) { - const _payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'handle': '', - 'password': _passphrase, - 'timeout': '2592000', - 'agent': 'bitcoinrpc', - 'method': 'walletpassphrase', - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'walletLock', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': _payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(_payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'Error iguanaWalletPassphrase', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(iguanaWalletPassphraseState(json, dispatch)); - }); - } -} - -export function iguanaActiveHandle(getMainAddress) { - const _payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'SuperNET', - 'method': 'activehandle', - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'iguanaActiveHandle', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': _payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(_payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(updateErrosStack('activeHandle')); - dispatch(triggerToaster(true, translate('TOASTR.IGUANA_ARE_YOU_SURE'), translate('TOASTR.SERVICE_NOTIFICATION'), 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(getMainAddress ? getMainAddressState(json) : iguanaActiveHandleState(json)); - }); - } -} - -export function iguanaEdexBalance(coin) { - const _payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'bitcoinrpc', - 'method': 'getbalance', - 'coin': coin, - }; - - return dispatch => { - if (coin) { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'iguanaEdexBalance', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': _payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(_payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'Error iguanaEdexBalance', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(iguanaEdexBalanceState(json))); - } - } -} - -export function atomic(payload) { - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'atomic', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, payload.method, 'Atomic explore error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(atomicState(json)); - }); - } -} - -export function settingsWifkeyState(json, coin) { - return { - type: GET_WIF_KEY, - wifkey: json[coin + 'wif'], - address: json[coin], - } -} - -export function encryptWallet(_passphrase, cb, coin) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'bitcoinrpc', - 'method': 'encryptwallet', - 'passphrase': _passphrase, - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'encryptWallet', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'encryptWallet', 'Error', 'error')); - }) - .then(dispatch(walletPassphrase(_passphrase))) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(cb.call(this, json, coin)); - }); - } -} - -export function walletPassphrase(_passphrase) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'bitcoinrpc', - 'method': 'walletpassphrase', - 'password': _passphrase, - 'timeout': '300000', - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'walletpassphrase', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'walletPassphrase', 'Error', 'error')); - }) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - }) - } -} - -export function getPeersListState(json) { - let peersList = {}; - - if (json && - json.rawpeers && - json.rawpeers.length) { - for (let i = 0; i < json.rawpeers.length; i++) { - peersList[json.rawpeers[i].coin] = json.rawpeers[i].peers; - } - } - return { - type: GET_PEERS_LIST, - supernetPeers: json && json.supernet[0] ? json.supernet : null, - rawPeers: peersList, - } -} - -export function getFullTransactionsList(coin) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'coin': coin, - 'method': 'listtransactions', - 'params': [ - 0, - 9999999, - [] - ], - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getFullTransactionsList', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getFullTransactionsList', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(getNativeTxHistoryState(json)); - }) - } -} - -export function getBasiliskTransactionsList(coin, address) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'dex', - 'method': 'listtransactions', - 'address': address, - 'count': 100, - 'skip': 0, - 'symbol': coin, - }; - - const pubkey = JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey; - - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'getBasiliskTransactionsList+cache', 'Error', 'error')); - }) - .then(response => response.json()) - .then(function(json) { - if (json.result && - !json.result.basilisk && - json.result.indexOf('no file with handle') > -1) { - console.log('new cache'); - } - - json = json.result.basilisk; - if (json[coin][address].listtransactions) { - dispatch(getNativeTxHistoryState({ 'result': json[coin][address].listtransactions.data })); - } - }) - } -} - -export function getPeersList(coin) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'SuperNET', - 'method': 'getpeers', - 'activecoin': coin, - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getPeersList', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getPeersList', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(getPeersListState(json, dispatch)); - }) - } -} - -function addPeerNodeState(json, dispatch) { - if (json.error === 'addnode needs active coin, do an addcoin first') { - return dispatch => { - dispatch(triggerToaster(true, 'Addnode needs active coin', translate('TOASTR.SETTINGS_NOTIFICATION'), 'error')); - } - } - if (json.result === 'peer was already connected') { - return dispatch => { - dispatch(triggerToaster(true, 'Peer was already connected', translate('TOASTR.SETTINGS_NOTIFICATION'), 'warning')); - } - } - if (json.result === 'addnode connection was already pending') { - return dispatch => { - dispatch(triggerToaster(true, 'Addnode connection was already pending', translate('TOASTR.SETTINGS_NOTIFICATION'), 'warning')); - } - } - if (json.result === 'addnode submitted') { - return dispatch => { - dispatch(triggerToaster(true, 'Peer is added', translate('TOASTR.SETTINGS_NOTIFICATION'), 'success')); - } - } -} - -export function addPeerNode(coin, ip) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'iguana', - 'method': 'addnode', - 'activecoin': coin, - 'ipaddr': ip, - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'addPeerNode', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'addPeerNode', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(addPeerNodeState(json, dispatch)); - }) - } -} - export function setBasiliskMainAddress(json, coin, mode) { if (mode === 'full') { let publicAddressArray = []; @@ -1171,81 +286,30 @@ export function setBasiliskMainAddress(json, coin, mode) { } return { - type: ACTIVE_COIN_GET_ADDRESSES, + type: storeType.ACTIVE_COIN_GET_ADDRESSES, addresses: { 'public': [] }, } } -export function getAddressesByAccountState(json, coin, mode) { - if (mode === 'full' || - mode === 'basilisk') { - let publicAddressArray = []; - - for (let i = 0; i < json.result.length; i++) { - publicAddressArray.push({ - 'address': json.result[i], - 'amount': 'N/A' - }); - } - - json.result = publicAddressArray; +export function getNativeTxHistoryState(json) { + if (json && + json.error) { + json = null; + } else if (json && json.result) { + json = json.result; + } else if (!json.length) { + json = 'no data'; } return { - type: ACTIVE_COIN_GET_ADDRESSES, - addresses: { 'public': json.result }, - } -} - -export function getAddressesByAccount(coin, mode) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'coin': coin, - 'agent': 'bitcoinrpc', - 'method': 'getaddressesbyaccount', - 'account': '*', - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getAddressesByAccount', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(updateErrosStack('activeHandle')); - dispatch(triggerToaster(true, 'getAddressesByAccount', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(getAddressesByAccountState(json, coin, mode)); - }) + type: storeType.DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY, + txhistory: json, } } export function startInterval(name, handle) { return { - type: START_INTERVAL, + type: storeType.START_INTERVAL, name, handle, } @@ -1255,2192 +319,7 @@ export function stopInterval(name, intervals) { clearInterval(intervals[name]); return { - type: STOP_INTERVAL, + type: storeType.STOP_INTERVAL, name, } -} - -// TODO: add custom json parser -function getSyncInfoState(json) { - try { - JSON.parse(json); - json = JSON.parse(json); - } catch(e) { - // - } - - return { - type: SYNCING_FULL_MODE, - progress: json, - } -} - -export function getSyncInfo(coin) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'coin': coin, - 'agent': 'bitcoinrpc', - 'method': 'getinfo', - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getSyncInfo', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getSyncInfo', 'Error', 'error')); - }) - .then(function(response) { - const _response = response.text().then(function(text) { return text; }); - - return _response; - }) - .then(function(json) { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - if (json.indexOf('coin is busy processing') === -1) { - dispatch(getSyncInfoState(json, dispatch)); - } - }) - } -} - -function getKMDAddressesNativeState(json) { - return { - type: ACTIVE_COIN_GET_ADDRESSES, - addresses: json, - } -} - -export function getKMDAddressesNative(coin, mode, currentAddress) { - const type = ['public', 'private']; - - if (mode !== 'native') { - type.pop(); - } - - return dispatch => { - Promise.all(type.map((_type, index) => { - return new Promise((resolve, reject) => { - let payload, - ajax_data_to_hex = '', - ajax_function_input = '', - tmplistaddr_hex_input = '', - passthru_agent = getPassthruAgent(coin), - tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); - - if (_type === 'public') { - ajax_function_input = 'getaddressesbyaccount'; - tmplistaddr_hex_input = '222200'; - } - if (_type === 'private') { - ajax_function_input = 'z_listaddresses'; - tmplistaddr_hex_input = ''; - } - - if (passthru_agent === 'iguana') { - payload = { - 'userpass': tmpIguanaRPCAuth, - 'agent': passthru_agent, - 'method': 'passthru', - 'asset': coin, - 'function': ajax_function_input, - 'hex': tmplistaddr_hex_input, - }; - } else { - payload = { - 'userpass': tmpIguanaRPCAuth, - 'agent': passthru_agent, - 'method': 'passthru', - 'function': ajax_function_input, - 'hex': tmplistaddr_hex_input, - }; - } - - if (mode === 'full' || mode === 'basilisk') { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'coin': coin, - 'agent': 'bitcoinrpc', - 'method': 'getaddressesbyaccount', - 'account': '*', - }; - } - - if (mode === 'basilisk') { - const pubkey = JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey; - - fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'getKMDAddressesNative+addresslist+cache', 'Error', 'error')); - }) - .then(response => response.json()) - .then(function(json) { - json = json.result.basilisk; - - if (json[coin].addresses) { - resolve({ 'result': json[coin].addresses }); - } - }) - } else { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getKMDAddressesNative', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getKMDAddressesNative', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - resolve(json); - }) - } - }); - })) - .then(result => { - // TODO: split into 2 functions - const passthru_agent = getPassthruAgent(coin), - tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); - let payload; - - if (passthru_agent === 'iguana') { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': passthru_agent, - 'method': 'passthru', - 'asset': coin, - 'function': 'listunspent', - 'hex': '', - }; - } else { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': passthru_agent, - 'method': 'passthru', - 'function': 'listunspent', - 'hex': '', - }; - } - - if (mode === 'full') { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'coin': coin, - 'method': 'listunspent', - 'params': [ - 1, - 9999999, - ], - }; - } - - // if api cache option is off - if (mode === 'basilisk') { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'dex', - 'method': 'listunspent', - 'address': currentAddress, - 'symbol': coin, - }; - } - - function calcBalance(result, json, dispatch, mode) { - if (mode === 'full' || - mode === 'basilisk') { - result[0] = result[0].result; - } - - if (mode !== 'basilisk' && - json && - json.length) { - 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]; - } - } - } - } - - let newAddressArray = []; - - for (let a = 0; a < result.length; a++) { - newAddressArray[a] = []; - - for (let b = 0; b < result[a].length; b++) { - 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++) { - sum += filteredArray[i]; - } - - newAddressArray[a][b] = { - address: result[a][b], - amount: currentAddress === result[a][b] || mode === 'native' ? sum : 'N/A', - }; - } - } - - dispatch(getKMDAddressesNativeState({ - 'public': newAddressArray[0], - 'private': newAddressArray[1] - })); - } - - if (mode === 'basilisk') { - const pubkey = JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey; - - fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'getKMDAddressesNative+addresslist+cache', 'Error', 'error')); - }) - .then(response => response.json()) - .then(function(json) { - let updatedCache = Object.assign({}, json.result); - json = json.result.basilisk; - // if listunspent is not in cache file retrieve new copy - // otherwise read from cache data - if (json[coin][currentAddress].refresh) { - calcBalance(result, json[coin][currentAddress].refresh.data, dispatch, mode); - } else { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getKMDAddressesNative+Balance', - 'type': 'post', - 'url': 'http://127.0.0.1:' + (Config.useBasiliskInstance && mode === 'basilisk' ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), - 'payload': payload, - 'status': 'pending', - })); - - fetch('http://127.0.0.1:' + (Config.useBasiliskInstance && mode === 'basilisk' ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getKMDAddressesNative+Balance', 'Error', 'error')); - }) - .then(response => response.json()) - .then(function(json) { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - updatedCache.basilisk[coin][currentAddress].refresh = { - 'data': json, - 'status': 'done', - 'timestamp': Date.now(), - }; - dispatch(shepherdGroomPost(pubkey, updatedCache)); - calcBalance(result, json, dispatch, mode); - }) - } - }) - } else { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getKMDAddressesNative+Balance', - 'type': 'post', - 'url': 'http://127.0.0.1:' + (Config.useBasiliskInstance && mode === 'basilisk' ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), - 'payload': payload, - 'status': 'pending', - })); - - fetch('http://127.0.0.1:' + (Config.useBasiliskInstance && mode === 'basilisk' ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getKMDAddressesNative+Balance', 'Error', 'error')); - }) - .then(response => response.json()) - .then(function(json) { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - calcBalance(result, json, dispatch, mode); - }) - } - }) - } -} - -export function shepherdGroomPost(_filename, _payload) { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/groom/', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - 'filename': _filename, - 'payload': JSON.stringify(_payload), - }), - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'shepherdGroomPost', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => console.log(json)) - } -} - -export function shepherdGroomPostPromise(_filename, _payload) { - return new Promise((resolve, reject) => { - fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/groom/', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - 'filename': _filename, - 'payload': JSON.stringify(_payload), - }), - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'shepherdGroomPostPromise', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => resolve(json)) - }) -} - -export function fetchUtxoCache(_payload) { - const _userpass = '?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - _pubkey = '&pubkey=' + _payload.pubkey, - _route = _payload.allcoins ? 'cache-all' : 'cache-one', - _coin = '&coin=' + _payload.coin, - _calls = '&calls=' + _payload.calls, - _address = _payload.address ? ('&address=' + _payload.address) : '', - _iguanaInstancePort = Config.useBasiliskInstance ? '&port=' + (Config.iguanaCorePort + 1) : ''; - - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/' + _route + _userpass + _pubkey + _coin + _calls + _address + _iguanaInstancePort, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'fetchNewCacheData', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(getShepherdCache(_pubkey))) - } -} - -function getShepherdCacheState(json, pubkey, coin) { - if (json.result && - json.error && - json.result.indexOf('no file with handle') > -1) { - return dispatch => { - dispatch(fetchNewCacheData({ - 'pubkey': pubkey, - 'allcoins': false, - 'coin': coin, - 'calls': 'listtransactions:getbalance', - })); - } - } else { - return { - type: DASHBOARD_ACTIVE_COIN_GET_CACHE, - cache: json && json.result && json.result.basilisk ? json.result.basilisk : null, - } - } -} - -export function getShepherdCache(pubkey, coin) { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'getShepherdCache', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(getShepherdCacheState(json, pubkey, coin))) - } -} - -function getDebugLogState(json) { - const _data = json.result.replace('\n', '\r\n'); - - return { - type: GET_DEBUG_LOG, - data: _data, - } -} - -export function getDebugLog(target, linesCount) { - const payload = { - 'herdname': target, - 'lastLines': linesCount - }; - - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/debuglog', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'getDebugLog', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(getDebugLogState(json))) - } -} - -function parseImportPrivKeyResponse(json, dispatch) { - if (json.error === 'illegal privkey') { - return dispatch => { - dispatch(triggerToaster(true, 'Illegal privkey', translate('TOASTR.SETTINGS_NOTIFICATION'), 'error')); - } - } - if (json.error === 'privkey already in wallet') { - return dispatch => { - dispatch(triggerToaster(true, 'Privkey already in wallet', translate('TOASTR.SETTINGS_NOTIFICATION'), 'warning')); - } - } - if (json && - json.result !== undefined && - json.result == 'success') { - return dispatch => { - dispatch(triggerToaster(true, translate('TOASTR.PRIV_KEY_IMPORTED'), translate('TOASTR.SETTINGS_NOTIFICATION'), 'success')); - } - } -} - -export function importPrivKey(wifKey) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'method': 'importprivkey', - 'params': [ - wifKey, - 'imported' - ], - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'importPrivKey', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'importPrivKey', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(parseImportPrivKeyResponse(json, dispatch)); - }) - .catch(function(ex) { - dispatch(parseImportPrivKeyResponse({ 'error': 'privkey already in wallet' }, dispatch)); - console.log('parsing failed', ex); - }) - } -} - -export function shepherdGetSysInfo() { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/sysinfo', { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - } - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'Failed to get sys info', 'Error', 'error')) - }) - .then(response => response.json()) - .then(json => dispatch(shepherdHerd(coin, mode, json))); - } -} - -export function getSyncInfoNativeKMD(skipDebug) { - const coin = 'KMD'; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getSyncInfoNativeKMD', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort + '/api/dex/getinfo?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth') + '&symbol=' + coin, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort + '/api/dex/getinfo?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth') + '&symbol=' + coin, { - method: 'GET', - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getSyncInfoNativeKMD', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(getSyncInfoNativeState({ 'remoteKMDNode': json })); - }) - .then(function() { - if (!skipDebug) { - dispatch(getDebugLog('komodo', 1)); - } - }) - } -} - -function getSyncInfoNativeState(json, coin, skipDebug) { - if (coin === 'KMD' && - json && - json.error) { - return getSyncInfoNativeKMD(skipDebug); - } else { - return { - type: SYNCING_NATIVE_MODE, - progress: json, - } - } -} - -function getPassthruAgent(coin) { - let passthru_agent; - - if ( coin === 'KMD') { passthru_agent = 'komodo'; }; - if ( coin === 'ZEC') { passthru_agent = 'zcash'; }; - - if (checkAC(coin)) { passthru_agent = 'iguana'; }; - - return passthru_agent; -} - -export function getSyncInfoNative(coin, skipDebug) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': getPassthruAgent(coin), - 'method': 'passthru', - 'asset': coin, - 'function': 'getinfo', - 'hex': '', - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getSyncInfo', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getSyncInfo', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(getSyncInfoNativeState(json, coin, skipDebug)); - }) - } -} - -export function getDexBalance(coin, mode, addr) { - Promise.all(addr.map((_addr, index) => { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'dex', - 'method': 'listunspent', - 'address': _addr, - 'symbol': coin, - }; - - return new Promise((resolve, reject) => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getDexBalance', - 'type': 'post', - 'url': 'http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), - 'payload': payload, - 'status': 'pending', - })); - - fetch('http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getDexBalance', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - console.log(json); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - }) - - resolve(index); - }); - })) - .then(result => { - console.log(result); - }); -} - -export function getKMDBalanceTotal(coin) { - let payload; - - if (coin !== 'KMD' && - coin !== 'ZEC') { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'iguana', - 'method': 'passthru', - 'asset': coin, - 'function': 'z_gettotalbalance', - 'hex': '3000', - }; - } else { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': getPassthruAgent(coin), - 'method': 'passthru', - 'function': 'z_gettotalbalance', - 'hex': '3000', - }; - } - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getKMDBalanceTotal', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getKMDBalanceTotal', 'Error', 'error')); - }) - .then(response => response.json()) - .then(function(json) { // TODO: figure out why komodod spits out "parse error" - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - if (json && - !json.error) { - dispatch(getNativeBalancesState(json)); - } - }) - } -} - -export function getNativeBalancesState(json) { - return { - type: DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE, - balance: json && !json.error ? json : 0, - } -} - -export function getNativeTxHistory(coin) { - let payload; - - if (getPassthruAgent(coin) === 'iguana') { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'iguana', - 'method': 'passthru', - 'asset': coin, - 'function': 'listtransactions', - 'hex': '', - }; - } else { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': getPassthruAgent(coin), - 'method': 'passthru', - 'function': 'listtransactions', - 'hex': '', - }; - } - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getNativeTxHistory', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getNativeTxHistory', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(getNativeTxHistoryState(json)); - }) - } -} - -export function getNativeTxHistoryState(json) { - if (json && - json.error) { - json = null; - } else if (json && json.result) { - json = json.result; - } else if (!json.length) { - json = 'no data'; - } - - return { - type: DASHBOARD_ACTIVE_COIN_NATIVE_TXHISTORY, - txhistory: json, - } -} - -function handleGetNewKMDAddresses(pubpriv, coin, dispatch) { - dispatch(triggerToaster(true, translate('KMD_NATIVE.NEW_ADDR_GENERATED'), translate('TOASTR.WALLET_NOTIFICATION'), 'success')); - dispatch(getKMDAddressesNative(coin)); - - return {}; -} - -export function getNewKMDAddresses(coin, pubpriv) { - let payload, - ajax_function_input = ''; - - if (pubpriv === 'public') { - ajax_function_input = 'getnewaddress'; - } - if (pubpriv === 'private') { - ajax_function_input = 'z_getnewaddress'; - } - - if (getPassthruAgent(coin) === 'iguana') { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': getPassthruAgent(coin), - 'method': 'passthru', - 'asset': coin, - 'function': ajax_function_input, - 'hex': '', - }; - } else { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': coin, - 'method': 'passthru', - 'function': ajax_function_input, - 'hex': '', - }; - } - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getNewKMDAddresses', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getNewKMDAddresses', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(handleGetNewKMDAddresses(pubpriv, coin, dispatch)); - }) - .catch(function(ex) { - dispatch(handleGetNewKMDAddresses(pubpriv, coin, dispatch)) - }) - } -} - -export function iguanaHashHex(data, dispatch) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'hash', - 'method': 'hex', - 'message': data, - }; - - return new Promise((resolve, reject) => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'iguanaHashHex', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'iguanaHashHex', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - resolve(json.hex); - }) - }) -} - -export function sendNativeTx(coin, _payload) { - let ajax_data_to_hex; - let payload; - let _apiMethod; - - if (_payload.addressType === 'public') { - _apiMethod = 'sendtoaddress'; - ajax_data_to_hex = '["' + _payload.sendTo + '", ' + (Number(_payload.amount) - Number(_payload.fee)) + ']'; - } else { - _apiMethod = 'z_sendmany'; - ajax_data_to_hex = '["' + _payload.sendFrom + '",[{"address":"' + _payload.sendTo + '","amount":' + (Number(_payload.amount) - Number(_payload.fee)) + '}]]'; - } - - return dispatch => { - return iguanaHashHex(ajax_data_to_hex, dispatch).then((hashHexJson) => { - if (getPassthruAgent(coin) === 'iguana') { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': getPassthruAgent(coin), - 'method': 'passthru', - 'asset': coin, - 'function': _apiMethod, - 'hex': hashHexJson, - }; - } else { - payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': getPassthruAgent(coin), - 'method': 'passthru', - 'function': _apiMethod, - 'hex': hashHexJson, - }; - } - - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'sendNativeTx', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'sendNativeTx', 'Error', 'error')); - }) - .then(response => response.json()) - .then(function(json) { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - - if (json.error && - json.error.toString().indexOf('code:') > -1) { - dispatch(triggerToaster(true, 'Send failed', translate('TOASTR.WALLET_NOTIFICATION'), 'error')); - } else { - dispatch(triggerToaster(true, translate('TOASTR.TX_SENT_ALT'), translate('TOASTR.WALLET_NOTIFICATION'), 'success')); - } - }) - .catch(function(ex) { - dispatch(triggerToaster(true, translate('TOASTR.TX_SENT_ALT'), translate('TOASTR.WALLET_NOTIFICATION'), 'success')); - console.log('parsing failed', ex); - }) - }); - } -} - -export function getKMDOPIDState(json) { - return { - type: DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS, - opids: json, - } -} - -export function getKMDOPID(opid, coin) { - let tmpopid_output = '', - ajax_data_to_hex; - - if (opid === undefined) { - ajax_data_to_hex = null; - } else { - ajax_data_to_hex = '["' + opid + '"]'; - } - - return dispatch => { - return iguanaHashHex(ajax_data_to_hex, dispatch).then((hashHexJson) => { - if (hashHexJson === '5b226e756c6c225d00') { - hashHexJson = ''; - } - - let payload, - passthru_agent = getPassthruAgent(coin), - tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); - - if (passthru_agent == 'iguana') { - payload = { - 'userpass': tmpIguanaRPCAuth, - 'agent': passthru_agent, - 'method': 'passthru', - 'asset': coin, - 'function': 'z_getoperationstatus', - 'hex': hashHexJson, - }; - } else { - payload = { - 'userpass': tmpIguanaRPCAuth, - 'agent': passthru_agent, - 'method': 'passthru', - 'function': 'z_getoperationstatus', - 'hex': hashHexJson, - }; - } - - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getKMDOPID', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getKMDOPID', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(getKMDOPIDState(json)); - }) - }) - } -} - -function sendToAddressState(json, dispatch) { - if (json && - json.error) { - dispatch(triggerToaster(true, json.error, 'Error', 'error')); - - return { - type: DASHBOARD_ACTIVE_COIN_SENDTO, - lastSendToResponse: json, - } - } 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 sendToAddressStateAlt(json) { - return { - type: DASHBOARD_ACTIVE_COIN_SENDTO, - lastSendToResponse: json, - } -} - -export function clearLastSendToResponseState() { - return { - type: DASHBOARD_ACTIVE_COIN_SENDTO, - lastSendToResponse: null, - } -} - -export function sendToAddress(coin, _payload) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'coin': coin, - 'method': 'sendtoaddress', - 'params': [ - _payload.sendTo, - _payload.amount, - 'EasyDEX', - 'EasyDEXTransaction' - ], - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'sendToAddress', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'sendToAddress', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(sendToAddressState(json, dispatch)); - }) - } -} - -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 => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'walletLock', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'sendFromAddress', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(sendToAddressState(json, dispatch)); - }) - } -} - -function checkAddressBasiliskHandle(json) { - if (json && - json.error) { - return dispatch => { - dispatch(triggerToaster(true, json.error, translate('TOASTR.WALLET_NOTIFICATION'), 'error')); - } - } - - if (json && - json.coin && - json.randipbits) { - return dispatch => { - dispatch(triggerToaster(true, 'Address already registered', translate('TOASTR.WALLET_NOTIFICATION'), 'warning')); - } - } -} - -export function checkAddressBasilisk(coin, address) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'dex', - 'method': 'checkaddress', - 'address': address, - 'symbol': coin, - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'checkAddressBasilisk', - 'type': 'post', - 'url': 'http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'checkAddressBasilisk', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(checkAddressBasiliskHandle(json)); - }) - } -} - -function validateAddressBasiliskHandle(json) { - return dispatch => { - if (json.iswatchonly === true) { - dispatch(triggerToaster(true, translate('TOASTR.VALIDATION_SUCCESS'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error')); - } - if (json.iswatchonly === false) { - dispatch(triggerToaster(true, translate('TOASTR.ADDR_ISNT_REG'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error')); - } - if (json.iswatchonly === undefined) { - dispatch(triggerToaster(true, translate('TOASTR.INVALID_QUERY_ALT'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error')); - } - if (json.error === 'less than required responses') { - dispatch(triggerToaster(true, translate('TOASTR.LESS_RESPONSES_REQ'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error')); - } - } -} - -export function validateAddressBasilisk(coin, address) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'dex', - 'method': 'validateaddress', - 'address': address, - 'symbol': coin, - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'validateAddressBasilisk', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'validateAddressBasilisk', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(validateAddressBasiliskHandle(json)); - }) - } -} - -function getDexNotariesState(json) { - if (json.error === 'less than required responses') { - return dispatch => { - dispatch(triggerToaster(true, translate('TOASTR.LESS_RESPONSES_REQ'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error')); - } - } else { - return { - type: DASHBOARD_GET_NOTARIES_LIST, - notaries: json, - } - } -} - -export function getDexNotaries(coin) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'dex', - 'method': 'getnotaries', - 'symbol': coin, - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'getDexNotaries', - 'type': 'post', - 'url': 'http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), - 'payload': payload, - 'status': 'pending', - })); - return fetch('http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getDexNotaries', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(getDexNotariesState(json)); - }) - } -} - -function createNewWalletState(json) { - if (json && - json.result && - json.result === 'success') { - return dispatch => { - dispatch(triggerToaster(true, translate('TOASTR.WALLET_CREATED_SUCCESFULLY'), translate('TOASTR.ACCOUNT_NOTIFICATION'), 'success')); - } - } else { - return dispatch => { - dispatch(triggerToaster(true, 'Couldn\'t create new wallet seed', translate('TOASTR.ACCOUNT_NOTIFICATION'), 'error')); - } - } -} - -export function createNewWallet(_passphrase) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'bitcoinrpc', - 'method': 'encryptwallet', - 'passphrase': _passphrase, - }; - - return dispatch => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'createNewWallet', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'createNewWallet', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(createNewWalletState(json)); - }) - } -} - -export function deleteCacheFile(_payload) { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/groom?', { - method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ 'filename': _payload.pubkey }), - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'deleteCacheFile', 'Error', 'error')) - }) - .then(response => response.json()) - .then(json => dispatch(fetchNewCacheData(_payload))); - } -} - -export function getCacheFile(pubkey) { - const _pubkey = pubkey || JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey; - - return new Promise((resolve, reject) => { - fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/groom?filename=' + _pubkey, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'getCacheFile', 'Error', 'error')) - }) - .then(response => response.json()) - .then(json => resolve(json)) - }) -} - -export function fetchNewCacheData(_payload) { - console.log('fetchNewCacheData', true); - const _userpass = '?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - _pubkey = '&pubkey=' + _payload.pubkey, - _route = _payload.allcoins ? 'cache-all' : 'cache-one', - _coin = '&coin=' + _payload.coin, - _calls = '&calls=' + _payload.calls, - _address = _payload.address ? ('&address=' + _payload.address) : '', - _iguanaInstancePort = Config.useBasiliskInstance ? '&port=' + (Config.iguanaCorePort + 1) : ''; - - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/' + _route + _userpass + _pubkey + _coin + _calls + _address + _iguanaInstancePort, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'fetchNewCacheData', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => console.log(json)) - } -} - -function initNotaryNodesConSequence(nodes) { - return dispatch => { - Promise.all(nodes.map((node, index) => { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'dex', - 'method': 'getinfo', - 'symbol': node, - 'timeout': 10000 - }; - - return new Promise((resolve, reject) => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'initNotaryNodesConSequence+' + node, - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - fetch('http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort) + '/api/dex/getinfo?userpass=' + ('tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth')) + '&symbol=' + node, { - method: 'GET', - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'getInfoDexNode+' + node, 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - dispatch(updateNotaryNodeConState(json, nodes.length, index, node)); - }) - }); - })); - } -} - -function updateNotaryNodeConState(json, totalNodes, currentNodeIndex, currentNodeName) { - if (currentNodeIndex === totalNodes - 1) { - return dispatch => { - dispatch(basiliskConnectionState(false)); - }; - } else { - if (json && - json.error === 'less than required responses') { - return { - type: DASHBOARD_CONNECT_NOTARIES, - total: totalNodes - 1, - current: currentNodeIndex, - name: currentNodeName, - failedNode: currentNodeName, - } - } else { - return { - type: DASHBOARD_CONNECT_NOTARIES, - total: totalNodes - 1, - current: currentNodeIndex, - name: currentNodeName, - } - } - } -} - -function connectAllNotaryNodes(json, dispatch) { - if (json && - json.length) { - dispatch(initNotaryNodesConSequence(json)); - - return { - type: DASHBOARD_CONNECT_NOTARIES, - total: json.length - 1, - current: 0, - name: json[0], - } - } -} - -export function startIguanaInstance(mode, coin) { - return new Promise((resolve, reject) => { - fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/forks', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - mode, - coin - }), - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'startIguanaInstance', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => resolve(json)) - }); -} - -export function getIguanaInstancesList() { - return new Promise((resolve, reject) => { - fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/forks', { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'getIguanaInstanceList', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => resolve(json)) - }); -} - -export function restartIguanaInstance(pmid) { - return new Promise((resolve, reject) => { - fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/forks/restart?pmid=' + pmid, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'restartIguanaInstance', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => resolve(json)) - }); -} - -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'), - 'agent': 'dpow', - 'method': 'notarychains', - }; - - 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, 'connectNotaries', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(connectAllNotaryNodes(json, dispatch))) - } -} - -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) => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'iguanaUTXORawTX', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'iguanaUTXORawTX', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - resolve(json); - }) - }); -} - -export function dexSendRawTX(data) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'agent': 'dex', - 'method': 'sendrawtransaction', - 'signedtx': data.signedtx, - 'symbol': data.coin - }; - - return new Promise((resolve, reject) => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'dexSendRawTX', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'dexSendRawTX', 'Error', 'error')); - }) - .then(function(response) { - const _response = response.text().then(function(text) { return text; }); - - return _response; - }) - .then(function(json) { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - resolve(json); - }) - }); -} - -export function edexGetTransaction(data) { - const payload = { - 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - 'symbol': data.coin, - 'agent': 'dex', - 'method': 'gettransaction', - 'vout': 1, - 'txid': data.txid - }; - - return new Promise((resolve, reject) => { - const _timestamp = Date.now(); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'function': 'edexGetTransaction', - 'type': 'post', - 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, - 'payload': payload, - 'status': 'pending', - })); - - fetch('http://127.0.0.1:' + Config.iguanaCorePort, { - method: 'POST', - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'error', - 'response': error, - })); - dispatch(triggerToaster(true, 'edexGetTransaction', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => { - dispatch(logGuiHttp({ - 'timestamp': _timestamp, - 'status': 'success', - 'response': json, - })); - resolve(json); - }) - }); -} - -export function saveAppConfig(_payload) { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/appconf', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ 'payload': _payload }), - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'saveAppConfig', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(getAppConfig())) - } -} - -function getAppConfigState(json) { - return { - type: LOAD_APP_CONFIG, - config: json, - } -} - -export function getAppConfig() { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/appconf', { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'getAppConfig', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(getAppConfigState(json))) - } -} - -function getSyncOnlyForksState(json) { - return { - type: SYNC_ONLY_DATA, - forks: JSON.parse(json.result), - } -} - -export function getSyncOnlyForks() { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/forks/info/show', { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'getSyncOnlyForks', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(getSyncOnlyForksState(json))) - } -} - -export function stopIguanaFork(pmid) { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/forks/stop?pmid=' + pmid, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'stopIguanaFork', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(triggerToaster(true, 'Iguana instance is stopped', translate('TOASTR.SERVICE_NOTIFICATION'), 'success'))) - } -} - -export function shepherdGetCoinList() { - return new Promise((resolve, reject) => { - fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/coinslist', { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'shepherdGetCoinList', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => resolve(json)) - }); -} - -export function shepherdPostCoinList(data) { - return new Promise((resolve, reject) => { - fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/coinslist', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ 'payload': data }), - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'shepherdPostCoinList', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => resolve(json)) - }); -} - -function getAppInfoState(json) { - return { - type: LOAD_APP_INFO, - info: json, - } -} - -export function getAppInfo() { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/appinfo', { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'getAppInfo', 'Error', 'error')); - }) - .then(response => response.json()) - .then(json => dispatch(getAppInfoState(json))) - } -} - -export function logGuiHttp(payload) { - return dispatch => { - dispatch(guiLogState(payload)); - - // disabled for now - /*return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/guilog', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(payload), - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'logGuiHttp', 'Error', 'error')); - }) - .then(response => response.json())*/ - } -} - -export function getAgamaLog(type) { - return dispatch => { - return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/getlog?type=' + type, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - .catch(function(error) { - console.log(error); - dispatch(triggerToaster(true, 'getAgamaLog', 'Error', 'error')); - }) - .then(response => response.json()) - .then() - } -} - -export function guiLogState(logData) { - return { - type: LOG_GUI_HTTP, - timestamp: logData.timestamp, - log: { - timestamp: logData.timestamp, - function: logData.function, - httpMethod: logData.type, - url: logData.url, - payload: logData.payload, - status: logData.status, - response: logData.response, - } - } } \ No newline at end of file diff --git a/react/src/actions/addCoin.js b/react/src/actions/addCoin.js new file mode 100644 index 0000000..dfa13a0 --- /dev/null +++ b/react/src/actions/addCoin.js @@ -0,0 +1,254 @@ +import * as storeType from './storeType'; +import { translate } from '../translate/translate'; +import { + triggerToaster, + Config, + toggleAddcoinModal, + getDexCoins +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; +import { + startCurrencyAssetChain, + startAssetChain, + startCrypto, + checkCoinType, + checkAC +} from '../components/addcoin/payload'; + +export function addCoin(coin, mode, syncOnly, port) { + if (mode === '-1') { + return dispatch => { + dispatch(shepherdGetConfig(coin, mode)); + } + } else { + if (checkCoinType(coin) === 'currency_ac') { + const _acData = startCurrencyAssetChain('', coin, mode); + + return dispatch => { + dispatch(iguanaAddCoin(coin, mode, _acData)); + } + } + if (checkCoinType(coin) === 'ac') { + const _acData = startAssetChain('', coin, mode); + + return dispatch => { + dispatch(iguanaAddCoin(coin, mode, _acData)); + } + } + if (checkCoinType(coin) === 'crypto') { + const _acData = startCrypto('', coin, mode); + + if (syncOnly) { + const modeToValue = { + '1': 'full', + '0': 'basilisk', + '-1': 'native' + }; + + return dispatch => { + startIguanaInstance(modeToValue[mode] + '/sync', coin) + .then(function(json) { + setTimeout(function() { + console.log('started ' + coin + ' / ' + modeToValue[mode] + ' fork', json); + dispatch(iguanaAddCoin(coin, mode, _acData, json.result)); + }, 2000); + }); + } + } else { + if (port) { + return dispatch => { + dispatch(iguanaAddCoin(coin, mode, _acData, port)); + } + } else { + return dispatch => { + dispatch(iguanaAddCoin(coin, mode, _acData)); + } + } + } + } + } +} + +export function iguanaAddCoin(coin, mode, acData, port) { + function _iguanaAddCoin(dispatch) { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'iguanaAddCoin', + 'type': 'post', + 'url': 'http://127.0.0.1:' + (port ? port : Config.iguanaCorePort), + 'payload': acData, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + (port ? port : Config.iguanaCorePort), { + method: 'POST', + body: JSON.stringify(acData), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, translate('TOASTR.FAILED_TO_ADDCOIN'), translate('TOASTR.ACCOUNT_NOTIFICATION'), 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(addCoinResult(coin, mode, acData)); + }); + } + + if (mode === 0) { + return dispatch => { + return _iguanaAddCoin(dispatch); + } + } else { + return dispatch => { + return _iguanaAddCoin(dispatch); + } + } +} + +export function shepherdHerd(coin, mode, path) { + let acData; + let herdData = { + 'ac_name': coin, + 'ac_options': [ + '-daemon=0', + '-server', + '-ac_name=' + coin, + '-addnode=78.47.196.146' + ] + }; + + if (coin === 'ZEC') { + herdData = { + 'ac_name': 'zcashd', + 'ac_options': [ + '-daemon=0', + '-server=1' + ] + }; + } + + if (coin === 'KMD') { + herdData = { + 'ac_name': 'komodod', + 'ac_options': [ + '-daemon=0', + '-addnode=78.47.196.146' + ] + }; + } + + if (checkCoinType(coin) === 'crypto') { + acData = startCrypto(path.result, coin, mode); + } + if (checkCoinType(coin) === 'currency_ac') { + acData = startCurrencyAssetChain(path.result, coin, mode); + } + if (checkCoinType(coin) === 'ac') { + acData = startAssetChain(path.result, coin, mode); + const supply = startAssetChain(path.result, coin, mode, true); + herdData.ac_options.push('-ac_supply=' + supply); + } + + console.log('herdData', herdData); + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/herd', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + 'herd': coin !== 'ZEC' ? 'komodod' : 'zcashd', + 'options': herdData + }), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, translate('FAILED_SHEPHERD_HERD'), translate('TOASTR.SERVICE_NOTIFICATION'), 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(iguanaAddCoin(coin, mode, acData))); + } +} + +export function addCoinResult(coin, mode) { + const modeToValue = { + '1': 'full', + '0': 'basilisk', + '-1': 'native' + }; + + return dispatch => { + dispatch(triggerToaster(true, coin + ' ' + translate('TOASTR.STARTED_IN') + ' ' + modeToValue[mode] + ' ' + translate('TOASTR.MODE'), translate('TOASTR.COIN_NOTIFICATION'), 'success')); + dispatch(toggleAddcoinModal(false, false)); + dispatch(getDexCoins()); + } +} + +export function _shepherdGetConfig(coin, mode) { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/getconf', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'chain': 'komodod' }) + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'Failed to get mode config', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(shepherdHerd(coin, mode, json))); + } +} + +export function shepherdGetConfig(coin, mode) { + if (coin === 'KMD' && + mode === '-1') { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/getconf', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'chain': 'komodod' }) + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'Failed to get KMD config', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(shepherdHerd(coin, mode, json))) + } + } else { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/getconf', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'chain': coin }) + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'Failed to get mode config', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(shepherdHerd(coin, mode, json))); + } + } +} \ No newline at end of file diff --git a/react/src/actions/addressBalance.js b/react/src/actions/addressBalance.js new file mode 100644 index 0000000..8bf3e5f --- /dev/null +++ b/react/src/actions/addressBalance.js @@ -0,0 +1,345 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config, + shepherdGroomPost, + getPassthruAgent +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +function getKMDAddressesNativeState(json) { + return { + type: storeType.ACTIVE_COIN_GET_ADDRESSES, + addresses: json, + } +} + +export function getKMDAddressesNative(coin, mode, currentAddress) { + const type = ['public', 'private']; + + if (mode !== 'native') { + type.pop(); + } + + return dispatch => { + Promise.all(type.map((_type, index) => { + return new Promise((resolve, reject) => { + let payload, + ajax_data_to_hex = '', + ajax_function_input = '', + tmplistaddr_hex_input = '', + passthru_agent = getPassthruAgent(coin), + tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); + + if (_type === 'public') { + ajax_function_input = 'getaddressesbyaccount'; + tmplistaddr_hex_input = '222200'; + } + if (_type === 'private') { + ajax_function_input = 'z_listaddresses'; + tmplistaddr_hex_input = ''; + } + + if (passthru_agent === 'iguana') { + payload = { + 'userpass': tmpIguanaRPCAuth, + 'agent': passthru_agent, + 'method': 'passthru', + 'asset': coin, + 'function': ajax_function_input, + 'hex': tmplistaddr_hex_input, + }; + } else { + payload = { + 'userpass': tmpIguanaRPCAuth, + 'agent': passthru_agent, + 'method': 'passthru', + 'function': ajax_function_input, + 'hex': tmplistaddr_hex_input, + }; + } + + if (mode === 'full' || mode === 'basilisk') { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'coin': coin, + 'agent': 'bitcoinrpc', + 'method': 'getaddressesbyaccount', + 'account': '*', + }; + } + + if (mode === 'basilisk') { + const pubkey = JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey; + + fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getKMDAddressesNative+addresslist+cache', 'Error', 'error')); + }) + .then(response => response.json()) + .then(function(json) { + json = json.result.basilisk; + + if (json[coin].addresses) { + resolve({ 'result': json[coin].addresses }); + } + }) + } else { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getKMDAddressesNative', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getKMDAddressesNative', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + resolve(json); + }) + } + }); + })) + .then(result => { + // TODO: split into 2 functions + const passthru_agent = getPassthruAgent(coin), + tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); + let payload; + + if (passthru_agent === 'iguana') { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': passthru_agent, + 'method': 'passthru', + 'asset': coin, + 'function': 'listunspent', + 'hex': '', + }; + } else { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': passthru_agent, + 'method': 'passthru', + 'function': 'listunspent', + 'hex': '', + }; + } + + if (mode === 'full') { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'coin': coin, + 'method': 'listunspent', + 'params': [ + 1, + 9999999, + ], + }; + } + + // if api cache option is off + if (mode === 'basilisk') { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'dex', + 'method': 'listunspent', + 'address': currentAddress, + 'symbol': coin, + }; + } + + function calcBalance(result, json, dispatch, mode) { + if (mode === 'full' || + mode === 'basilisk') { + result[0] = result[0].result; + } + + if (mode !== 'basilisk' && + json && + json.length) { + 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]; + } + } + } + } + + let newAddressArray = []; + + for (let a = 0; a < result.length; a++) { + newAddressArray[a] = []; + + for (let b = 0; b < result[a].length; b++) { + 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++) { + sum += filteredArray[i]; + } + + newAddressArray[a][b] = { + address: result[a][b], + amount: currentAddress === result[a][b] || mode === 'native' ? sum : 'N/A', + }; + } + } + + dispatch(getKMDAddressesNativeState({ + 'public': newAddressArray[0], + 'private': newAddressArray[1] + })); + } + + if (mode === 'basilisk') { + const pubkey = JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey; + + fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getKMDAddressesNative+addresslist+cache', 'Error', 'error')); + }) + .then(response => response.json()) + .then(function(json) { + let updatedCache = Object.assign({}, json.result); + json = json.result.basilisk; + // if listunspent is not in cache file retrieve new copy + // otherwise read from cache data + if (json[coin][currentAddress].refresh) { + calcBalance(result, json[coin][currentAddress].refresh.data, dispatch, mode); + } else { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getKMDAddressesNative+Balance', + 'type': 'post', + 'url': 'http://127.0.0.1:' + (Config.useBasiliskInstance && mode === 'basilisk' ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), + 'payload': payload, + 'status': 'pending', + })); + + fetch('http://127.0.0.1:' + (Config.useBasiliskInstance && mode === 'basilisk' ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getKMDAddressesNative+Balance', 'Error', 'error')); + }) + .then(response => response.json()) + .then(function(json) { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + updatedCache.basilisk[coin][currentAddress].refresh = { + 'data': json, + 'status': 'done', + 'timestamp': Date.now(), + }; + dispatch(shepherdGroomPost(pubkey, updatedCache)); + calcBalance(result, json, dispatch, mode); + }) + } + }) + } else { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getKMDAddressesNative+Balance', + 'type': 'post', + 'url': 'http://127.0.0.1:' + (Config.useBasiliskInstance && mode === 'basilisk' ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), + 'payload': payload, + 'status': 'pending', + })); + + fetch('http://127.0.0.1:' + (Config.useBasiliskInstance && mode === 'basilisk' ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getKMDAddressesNative+Balance', 'Error', 'error')); + }) + .then(response => response.json()) + .then(function(json) { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + calcBalance(result, json, dispatch, mode); + }) + } + }) + } +} \ No newline at end of file diff --git a/react/src/actions/atomic.js b/react/src/actions/atomic.js new file mode 100644 index 0000000..7f10461 --- /dev/null +++ b/react/src/actions/atomic.js @@ -0,0 +1,53 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function atomic(payload) { + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'atomic', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, payload.method, 'Atomic Explorer error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(atomicState(json)); + }); + } +} + +function atomicState(json) { + return { + type: storeType.ATOMIC, + response: json, + } +} \ No newline at end of file diff --git a/react/src/actions/basiliskCache.js b/react/src/actions/basiliskCache.js new file mode 100644 index 0000000..588df6c --- /dev/null +++ b/react/src/actions/basiliskCache.js @@ -0,0 +1,175 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function deleteCacheFile(_payload) { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/groom?', { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'filename': _payload.pubkey }), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'deleteCacheFile', 'Error', 'error')) + }) + .then(response => response.json()) + .then(json => dispatch(fetchNewCacheData(_payload))); + } +} + +export function getCacheFile(pubkey) { + const _pubkey = pubkey || JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey; + + return new Promise((resolve, reject) => { + fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/groom?filename=' + _pubkey, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getCacheFile', 'Error', 'error')) + }) + .then(response => response.json()) + .then(json => resolve(json)) + }) +} + +export function fetchNewCacheData(_payload) { + const _userpass = '?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + _pubkey = '&pubkey=' + _payload.pubkey, + _route = _payload.allcoins ? 'cache-all' : 'cache-one', + _coin = '&coin=' + _payload.coin, + _calls = '&calls=' + _payload.calls, + _address = _payload.address ? ('&address=' + _payload.address) : '', + _iguanaInstancePort = Config.useBasiliskInstance ? '&port=' + (Config.iguanaCorePort + 1) : ''; + + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/' + _route + _userpass + _pubkey + _coin + _calls + _address + _iguanaInstancePort, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'fetchNewCacheData', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => console.log(json)) + } +} + +export function getShepherdCache(pubkey, coin) { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getShepherdCache', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(getShepherdCacheState(json, pubkey, coin))) + } +} + +function getShepherdCacheState(json, pubkey, coin) { + if (json.result && + json.error && + json.result.indexOf('no file with handle') > -1) { + return dispatch => { + dispatch(fetchNewCacheData({ + 'pubkey': pubkey, + 'allcoins': false, + 'coin': coin, + 'calls': 'listtransactions:getbalance', + })); + } + } else { + return { + type: storeType.DASHBOARD_ACTIVE_COIN_GET_CACHE, + cache: json && json.result && json.result.basilisk ? json.result.basilisk : null, + } + } +} + +export function fetchUtxoCache(_payload) { + const _userpass = '?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + _pubkey = '&pubkey=' + _payload.pubkey, + _route = _payload.allcoins ? 'cache-all' : 'cache-one', + _coin = '&coin=' + _payload.coin, + _calls = '&calls=' + _payload.calls, + _address = _payload.address ? ('&address=' + _payload.address) : '', + _iguanaInstancePort = Config.useBasiliskInstance ? '&port=' + (Config.iguanaCorePort + 1) : ''; + + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/' + _route + _userpass + _pubkey + _coin + _calls + _address + _iguanaInstancePort, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'fetchNewCacheData', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(getShepherdCache(_pubkey))) + } +} + +export function shepherdGroomPost(_filename, _payload) { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/groom/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + 'filename': _filename, + 'payload': JSON.stringify(_payload), + }), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'shepherdGroomPost', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => console.log(json)) + } +} + +export function shepherdGroomPostPromise(_filename, _payload) { + return new Promise((resolve, reject) => { + fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/groom/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + 'filename': _filename, + 'payload': JSON.stringify(_payload), + }), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'shepherdGroomPostPromise', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => resolve(json)) + }) +} \ No newline at end of file diff --git a/react/src/actions/basiliskProcessAddress.js b/react/src/actions/basiliskProcessAddress.js new file mode 100644 index 0000000..fe1582f --- /dev/null +++ b/react/src/actions/basiliskProcessAddress.js @@ -0,0 +1,134 @@ +import * as storeType from './storeType'; +import { translate } from '../translate/translate'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function checkAddressBasilisk(coin, address) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'dex', + 'method': 'checkaddress', + 'address': address, + 'symbol': coin, + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'checkAddressBasilisk', + 'type': 'post', + 'url': 'http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'checkAddressBasilisk', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(checkAddressBasiliskHandle(json)); + }) + } +} + +function checkAddressBasiliskHandle(json) { + if (json && + json.error) { + return dispatch => { + dispatch(triggerToaster(true, json.error, translate('TOASTR.WALLET_NOTIFICATION'), 'error')); + } + } + + if (json && + json.coin && + json.randipbits) { + return dispatch => { + dispatch(triggerToaster(true, 'Address already registered', translate('TOASTR.WALLET_NOTIFICATION'), 'warning')); + } + } +} + +export function validateAddressBasilisk(coin, address) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'dex', + 'method': 'validateaddress', + 'address': address, + 'symbol': coin, + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'validateAddressBasilisk', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'validateAddressBasilisk', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(validateAddressBasiliskHandle(json)); + }) + } +} + +function validateAddressBasiliskHandle(json) { + return dispatch => { + if (json.iswatchonly === true) { + dispatch(triggerToaster(true, translate('TOASTR.VALIDATION_SUCCESS'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error')); + } + if (json.iswatchonly === false) { + dispatch(triggerToaster(true, translate('TOASTR.ADDR_ISNT_REG'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error')); + } + if (json.iswatchonly === undefined) { + dispatch(triggerToaster(true, translate('TOASTR.INVALID_QUERY_ALT'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error')); + } + if (json.error === 'less than required responses') { + dispatch(triggerToaster(true, translate('TOASTR.LESS_RESPONSES_REQ'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error')); + } + } +} \ No newline at end of file diff --git a/react/src/actions/basiliskTxHistory.js b/react/src/actions/basiliskTxHistory.js new file mode 100644 index 0000000..50d38f4 --- /dev/null +++ b/react/src/actions/basiliskTxHistory.js @@ -0,0 +1,40 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config, + getNativeTxHistoryState +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function getBasiliskTransactionsList(coin, address) { + const pubkey = JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey; + + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/cache?pubkey=' + pubkey, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getBasiliskTransactionsList+cache', 'Error', 'error')); + }) + .then(response => response.json()) + .then(function(json) { + if (json.result && + !json.result.basilisk && + json.result.indexOf('no file with handle') > -1) { + console.log('new cache'); + } + + json = json.result.basilisk; + if (json[coin][address].listtransactions) { + dispatch(getNativeTxHistoryState({ 'result': json[coin][address].listtransactions.data })); + } + }) + } +} \ No newline at end of file diff --git a/react/src/actions/coinList.js b/react/src/actions/coinList.js new file mode 100644 index 0000000..0e4f31b --- /dev/null +++ b/react/src/actions/coinList.js @@ -0,0 +1,44 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function shepherdGetCoinList() { + return new Promise((resolve, reject) => { + fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/coinslist', { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'shepherdGetCoinList', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => resolve(json)) + }); +} + +export function shepherdPostCoinList(data) { + return new Promise((resolve, reject) => { + fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/coinslist', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': data }), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'shepherdPostCoinList', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => resolve(json)) + }); +} \ No newline at end of file diff --git a/react/src/actions/copyAddress.js b/react/src/actions/copyAddress.js new file mode 100644 index 0000000..3b4dd3d --- /dev/null +++ b/react/src/actions/copyAddress.js @@ -0,0 +1,21 @@ +import { copyToClipboard } from '../util/copyToClipboard'; +import { translate } from '../translate/translate'; +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; + +export function copyCoinAddress(address) { + const _result = copyToClipboard(address); + + if (_result) { + return dispatch => { + dispatch(triggerToaster(true, translate('DASHBOARD.ADDR_COPIED'), translate('TOASTR.COIN_NOTIFICATION'), 'success')); + } + } else { + return dispatch => { + dispatch(triggerToaster(true, 'Couldn\'t copy address to clipboard', translate('TOASTR.COIN_NOTIFICATION'), 'error')); + } + } +} \ No newline at end of file diff --git a/react/src/actions/createWallet.js b/react/src/actions/createWallet.js new file mode 100644 index 0000000..425a2b6 --- /dev/null +++ b/react/src/actions/createWallet.js @@ -0,0 +1,68 @@ +import * as storeType from './storeType'; +import { translate } from '../translate/translate'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +function createNewWalletState(json) { + if (json && + json.result && + json.result === 'success') { + return dispatch => { + dispatch(triggerToaster(true, translate('TOASTR.WALLET_CREATED_SUCCESFULLY'), translate('TOASTR.ACCOUNT_NOTIFICATION'), 'success')); + } + } else { + return dispatch => { + dispatch(triggerToaster(true, 'Couldn\'t create new wallet seed', translate('TOASTR.ACCOUNT_NOTIFICATION'), 'error')); + } + } +} + +export function createNewWallet(_passphrase) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'bitcoinrpc', + 'method': 'encryptwallet', + 'passphrase': _passphrase, + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'createNewWallet', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'createNewWallet', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(createNewWalletState(json)); + }) + } +} \ No newline at end of file diff --git a/react/src/actions/dexCoins.js b/react/src/actions/dexCoins.js new file mode 100644 index 0000000..7f10dd2 --- /dev/null +++ b/react/src/actions/dexCoins.js @@ -0,0 +1,53 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config, + dashboardCoinsState +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function getDexCoins() { + const _payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'InstantDEX', + 'method': 'allcoins', + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getDexCoins', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': _payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(_payload) + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'Error getDexCoins', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(dashboardCoinsState(json)); + }); + } +} \ No newline at end of file diff --git a/react/src/actions/edexBalance.js b/react/src/actions/edexBalance.js new file mode 100644 index 0000000..b760791 --- /dev/null +++ b/react/src/actions/edexBalance.js @@ -0,0 +1,107 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function iguanaEdexBalance(coin) { + const _payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'bitcoinrpc', + 'method': 'getbalance', + 'coin': coin, + }; + + return dispatch => { + if (coin) { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'iguanaEdexBalance', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': _payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(_payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'Error iguanaEdexBalance', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(iguanaEdexBalanceState(json))); + } + } +} + +function iguanaEdexBalanceState(json) { + return { + type: storeType.DASHBOARD_ACTIVE_COIN_BALANCE, + balance: json && json.result ? json.result : 0, + } +} + +export function getDexBalance(coin, mode, addr) { + Promise.all(addr.map((_addr, index) => { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'dex', + 'method': 'listunspent', + 'address': _addr, + 'symbol': coin, + }; + + return new Promise((resolve, reject) => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getDexBalance', + 'type': 'post', + 'url': 'http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), + 'payload': payload, + 'status': 'pending', + })); + + fetch('http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getDexBalance', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + console.log(json); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + }) + + resolve(index); + }); + })) + .then(result => { + console.log(result); + }); +} \ No newline at end of file diff --git a/react/src/actions/edexGetTx.js b/react/src/actions/edexGetTx.js new file mode 100644 index 0000000..8cd1139 --- /dev/null +++ b/react/src/actions/edexGetTx.js @@ -0,0 +1,55 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function edexGetTransaction(data) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'symbol': data.coin, + 'agent': 'dex', + 'method': 'gettransaction', + 'vout': 1, + 'txid': data.txid + }; + + return new Promise((resolve, reject) => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'edexGetTransaction', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'edexGetTransaction', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + resolve(json); + }) + }); +} diff --git a/react/src/actions/fullTxHistory.js b/react/src/actions/fullTxHistory.js new file mode 100644 index 0000000..f73492e --- /dev/null +++ b/react/src/actions/fullTxHistory.js @@ -0,0 +1,58 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config, + getNativeTxHistoryState +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function getFullTransactionsList(coin) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'coin': coin, + 'method': 'listtransactions', + 'params': [ + 0, + 9999999, + [] + ], + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getFullTransactionsList', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getFullTransactionsList', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(getNativeTxHistoryState(json)); + }) + } +} \ No newline at end of file diff --git a/react/src/actions/getAddrByAccount.js b/react/src/actions/getAddrByAccount.js new file mode 100644 index 0000000..f1238d0 --- /dev/null +++ b/react/src/actions/getAddrByAccount.js @@ -0,0 +1,76 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function getAddressesByAccountState(json, coin, mode) { + if (mode === 'full' || + mode === 'basilisk') { + let publicAddressArray = []; + + for (let i = 0; i < json.result.length; i++) { + publicAddressArray.push({ + 'address': json.result[i], + 'amount': 'N/A' + }); + } + + json.result = publicAddressArray; + } + + return { + type: storeType.ACTIVE_COIN_GET_ADDRESSES, + addresses: { 'public': json.result }, + } +} + +export function getAddressesByAccount(coin, mode) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'coin': coin, + 'agent': 'bitcoinrpc', + 'method': 'getaddressesbyaccount', + 'account': '*', + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getAddressesByAccount', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(updateErrosStack('activeHandle')); + dispatch(triggerToaster(true, 'getAddressesByAccount', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(getAddressesByAccountState(json, coin, mode)); + }) + } +} \ No newline at end of file diff --git a/react/src/actions/iguanaHelpers.js b/react/src/actions/iguanaHelpers.js new file mode 100644 index 0000000..97b8371 --- /dev/null +++ b/react/src/actions/iguanaHelpers.js @@ -0,0 +1,66 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; +import { checkAC } from '../components/addcoin/payload'; + +export function getPassthruAgent(coin) { + let passthruAgent; + + if (coin === 'KMD') { passthruAgent = 'komodo'; }; + if (coin === 'ZEC') { passthruAgent = 'zcash'; }; + + if (checkAC(coin)) { passthruAgent = 'iguana'; }; + + return passthruAgent; +} + +export function iguanaHashHex(data, dispatch) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'hash', + 'method': 'hex', + 'message': data, + }; + + return new Promise((resolve, reject) => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'iguanaHashHex', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'iguanaHashHex', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + resolve(json.hex); + }) + }) +} + diff --git a/react/src/actions/iguanaInstance.js b/react/src/actions/iguanaInstance.js new file mode 100644 index 0000000..4a6adfd --- /dev/null +++ b/react/src/actions/iguanaInstance.js @@ -0,0 +1,80 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function restartIguanaInstance(pmid) { + return new Promise((resolve, reject) => { + fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/forks/restart?pmid=' + pmid, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'restartIguanaInstance', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => resolve(json)) + }); +} + +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 startIguanaInstance(mode, coin) { + return new Promise((resolve, reject) => { + fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/forks', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + mode, + coin + }), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'startIguanaInstance', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => resolve(json)) + }); +} + +export function getIguanaInstancesList() { + return new Promise((resolve, reject) => { + fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/forks', { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getIguanaInstanceList', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => resolve(json)) + }); +} \ No newline at end of file diff --git a/react/src/actions/log.js b/react/src/actions/log.js new file mode 100644 index 0000000..51e17ba --- /dev/null +++ b/react/src/actions/log.js @@ -0,0 +1,58 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; + +export function logGuiHttp(payload) { + return dispatch => { + dispatch(guiLogState(payload)); + + // disabled for now + /*return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/guilog', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'logGuiHttp', 'Error', 'error')); + }) + .then(response => response.json())*/ + } +} + +export function getAgamaLog(type) { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/getlog?type=' + type, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getAgamaLog', 'Error', 'error')); + }) + .then(response => response.json()) + .then() + } +} + +export function guiLogState(logData) { + return { + type: storeType.LOG_GUI_HTTP, + timestamp: logData.timestamp, + log: { + timestamp: logData.timestamp, + function: logData.function, + httpMethod: logData.type, + url: logData.url, + payload: logData.payload, + status: logData.status, + response: logData.response, + } + } +} \ No newline at end of file diff --git a/react/src/actions/logout.js b/react/src/actions/logout.js new file mode 100644 index 0000000..bfeb1e2 --- /dev/null +++ b/react/src/actions/logout.js @@ -0,0 +1,67 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +function logoutState(json, dispatch) { + sessionStorage.removeItem('IguanaActiveAccount'); + + return { + type: storeType.LOGIN, + isLoggedIn: false, + } +} + +export function logout() { + return dispatch => { + dispatch(walletLock()); + } +} + +function walletLock() { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'bitcoinrpc', + 'method': 'walletlock', + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'walletLock', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'walletLock', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(logoutState(json)); + }) + } +} \ No newline at end of file diff --git a/react/src/actions/nativeBalance.js b/react/src/actions/nativeBalance.js new file mode 100644 index 0000000..f8931b2 --- /dev/null +++ b/react/src/actions/nativeBalance.js @@ -0,0 +1,79 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config, + getPassthruAgent +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function getKMDBalanceTotal(coin) { + let payload; + + if (coin !== 'KMD' && + coin !== 'ZEC') { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'iguana', + 'method': 'passthru', + 'asset': coin, + 'function': 'z_gettotalbalance', + 'hex': '3000', + }; + } else { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': getPassthruAgent(coin), + 'method': 'passthru', + 'function': 'z_gettotalbalance', + 'hex': '3000', + }; + } + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getKMDBalanceTotal', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getKMDBalanceTotal', 'Error', 'error')); + }) + .then(response => response.json()) + .then(function(json) { // TODO: figure out why komodod spits out "parse error" + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + if (json && + !json.error) { + dispatch(getNativeBalancesState(json)); + } + }) + } +} + +export function getNativeBalancesState(json) { + return { + type: storeType.DASHBOARD_ACTIVE_COIN_NATIVE_BALANCE, + balance: json && !json.error ? json : 0, + } +} \ No newline at end of file diff --git a/react/src/actions/nativeNewAddress.js b/react/src/actions/nativeNewAddress.js new file mode 100644 index 0000000..93f3425 --- /dev/null +++ b/react/src/actions/nativeNewAddress.js @@ -0,0 +1,87 @@ +import * as storeType from './storeType'; +import { translate } from '../translate/translate'; +import { + triggerToaster, + Config, + getPassthruAgent +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +function handleGetNewKMDAddresses(pubpriv, coin, dispatch) { + dispatch(triggerToaster(true, translate('KMD_NATIVE.NEW_ADDR_GENERATED'), translate('TOASTR.WALLET_NOTIFICATION'), 'success')); + dispatch(getKMDAddressesNative(coin)); + + return {}; +} + +export function getNewKMDAddresses(coin, pubpriv) { + let payload, + ajax_function_input = ''; + + if (pubpriv === 'public') { + ajax_function_input = 'getnewaddress'; + } + if (pubpriv === 'private') { + ajax_function_input = 'z_getnewaddress'; + } + + if (getPassthruAgent(coin) === 'iguana') { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': getPassthruAgent(coin), + 'method': 'passthru', + 'asset': coin, + 'function': ajax_function_input, + 'hex': '', + }; + } else { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': coin, + 'method': 'passthru', + 'function': ajax_function_input, + 'hex': '', + }; + } + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getNewKMDAddresses', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getNewKMDAddresses', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(handleGetNewKMDAddresses(pubpriv, coin, dispatch)); + }) + .catch(function(ex) { + dispatch(handleGetNewKMDAddresses(pubpriv, coin, dispatch)) + }) + } +} \ No newline at end of file diff --git a/react/src/actions/nativeSend.js b/react/src/actions/nativeSend.js new file mode 100644 index 0000000..4d005d4 --- /dev/null +++ b/react/src/actions/nativeSend.js @@ -0,0 +1,174 @@ +import * as storeType from './storeType'; +import { translate } from '../translate/translate'; +import { + triggerToaster, + Config, + getPassthruAgent, + iguanaHashHex +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function sendNativeTx(coin, _payload) { + let ajax_data_to_hex; + let payload; + let _apiMethod; + + if (_payload.addressType === 'public') { + _apiMethod = 'sendtoaddress'; + ajax_data_to_hex = '["' + _payload.sendTo + '", ' + (Number(_payload.amount) - Number(_payload.fee)) + ']'; + } else { + _apiMethod = 'z_sendmany'; + ajax_data_to_hex = '["' + _payload.sendFrom + '",[{"address":"' + _payload.sendTo + '","amount":' + (Number(_payload.amount) - Number(_payload.fee)) + '}]]'; + } + + return dispatch => { + return iguanaHashHex(ajax_data_to_hex, dispatch).then((hashHexJson) => { + if (getPassthruAgent(coin) === 'iguana') { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': getPassthruAgent(coin), + 'method': 'passthru', + 'asset': coin, + 'function': _apiMethod, + 'hex': hashHexJson, + }; + } else { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': getPassthruAgent(coin), + 'method': 'passthru', + 'function': _apiMethod, + 'hex': hashHexJson, + }; + } + + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'sendNativeTx', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'sendNativeTx', 'Error', 'error')); + }) + .then(response => response.json()) + .then(function(json) { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + + if (json.error && + json.error.toString().indexOf('code:') > -1) { + dispatch(triggerToaster(true, 'Send failed', translate('TOASTR.WALLET_NOTIFICATION'), 'error')); + } else { + dispatch(triggerToaster(true, translate('TOASTR.TX_SENT_ALT'), translate('TOASTR.WALLET_NOTIFICATION'), 'success')); + } + }) + .catch(function(ex) { + dispatch(triggerToaster(true, translate('TOASTR.TX_SENT_ALT'), translate('TOASTR.WALLET_NOTIFICATION'), 'success')); + console.log('parsing failed', ex); + }) + }); + } +} + +export function getKMDOPIDState(json) { + return { + type: storeType.DASHBOARD_ACTIVE_COIN_NATIVE_OPIDS, + opids: json, + } +} + +export function getKMDOPID(opid, coin) { + let tmpopid_output = '', + ajax_data_to_hex; + + if (opid === undefined) { + ajax_data_to_hex = null; + } else { + ajax_data_to_hex = '["' + opid + '"]'; + } + + return dispatch => { + return iguanaHashHex(ajax_data_to_hex, dispatch).then((hashHexJson) => { + if (hashHexJson === '5b226e756c6c225d00') { + hashHexJson = ''; + } + + let payload, + passthru_agent = getPassthruAgent(coin), + tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); + + if (passthru_agent == 'iguana') { + payload = { + 'userpass': tmpIguanaRPCAuth, + 'agent': passthru_agent, + 'method': 'passthru', + 'asset': coin, + 'function': 'z_getoperationstatus', + 'hex': hashHexJson, + }; + } else { + payload = { + 'userpass': tmpIguanaRPCAuth, + 'agent': passthru_agent, + 'method': 'passthru', + 'function': 'z_getoperationstatus', + 'hex': hashHexJson, + }; + } + + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getKMDOPID', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getKMDOPID', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(getKMDOPIDState(json)); + }) + }) + } +} \ No newline at end of file diff --git a/react/src/actions/nativeSyncInfo.js b/react/src/actions/nativeSyncInfo.js new file mode 100644 index 0000000..18f6b26 --- /dev/null +++ b/react/src/actions/nativeSyncInfo.js @@ -0,0 +1,111 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function getSyncInfoNativeKMD(skipDebug) { + const coin = 'KMD'; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getSyncInfoNativeKMD', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort + '/api/dex/getinfo?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth') + '&symbol=' + coin, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort + '/api/dex/getinfo?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth') + '&symbol=' + coin, { + method: 'GET', + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getSyncInfoNativeKMD', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(getSyncInfoNativeState({ 'remoteKMDNode': json })); + }) + .then(function() { + if (!skipDebug) { + dispatch(getDebugLog('komodo', 1)); + } + }) + } +} + +function getSyncInfoNativeState(json, coin, skipDebug) { + if (coin === 'KMD' && + json && + json.error) { + return getSyncInfoNativeKMD(skipDebug); + } else { + return { + type: storeType.SYNCING_NATIVE_MODE, + progress: json, + } + } +} + +export function getSyncInfoNative(coin, skipDebug) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': getPassthruAgent(coin), + 'method': 'passthru', + 'asset': coin, + 'function': 'getinfo', + 'hex': '', + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getSyncInfo', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getSyncInfo', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(getSyncInfoNativeState(json, coin, skipDebug)); + }) + } +} \ No newline at end of file diff --git a/react/src/actions/nativeTxHistory.js b/react/src/actions/nativeTxHistory.js new file mode 100644 index 0000000..2b45e07 --- /dev/null +++ b/react/src/actions/nativeTxHistory.js @@ -0,0 +1,69 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config, + getPassthruAgent, + getNativeTxHistoryState +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function getNativeTxHistory(coin) { + let payload; + + if (getPassthruAgent(coin) === 'iguana') { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'iguana', + 'method': 'passthru', + 'asset': coin, + 'function': 'listtransactions', + 'hex': '', + }; + } else { + payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': getPassthruAgent(coin), + 'method': 'passthru', + 'function': 'listtransactions', + 'hex': '', + }; + } + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getNativeTxHistory', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getNativeTxHistory', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(getNativeTxHistoryState(json)); + }) + } +} \ No newline at end of file diff --git a/react/src/actions/notary.js b/react/src/actions/notary.js new file mode 100644 index 0000000..2582b70 --- /dev/null +++ b/react/src/actions/notary.js @@ -0,0 +1,175 @@ +import * as storeType from './storeType'; +import { translate } from '../translate/translate'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +function initNotaryNodesConSequence(nodes) { + return dispatch => { + Promise.all(nodes.map((node, index) => { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'dex', + 'method': 'getinfo', + 'symbol': node, + 'timeout': 10000 + }; + + return new Promise((resolve, reject) => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'initNotaryNodesConSequence+' + node, + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + fetch('http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort) + '/api/dex/getinfo?userpass=' + ('tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth')) + '&symbol=' + node, { + method: 'GET', + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getInfoDexNode+' + node, 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(updateNotaryNodeConState(json, nodes.length, index, node)); + }) + }); + })); + } +} + +function updateNotaryNodeConState(json, totalNodes, currentNodeIndex, currentNodeName) { + if (currentNodeIndex === totalNodes - 1) { + return dispatch => { + dispatch(basiliskConnectionState(false)); + }; + } else { + if (json && + json.error === 'less than required responses') { + return { + type: storeType.DASHBOARD_CONNECT_NOTARIES, + total: totalNodes - 1, + current: currentNodeIndex, + name: currentNodeName, + failedNode: currentNodeName, + } + } else { + return { + type: storeType.DASHBOARD_CONNECT_NOTARIES, + total: totalNodes - 1, + current: currentNodeIndex, + name: currentNodeName, + } + } + } +} + +function connectAllNotaryNodes(json, dispatch) { + if (json && + json.length) { + dispatch(initNotaryNodesConSequence(json)); + + return { + type: storeType.DASHBOARD_CONNECT_NOTARIES, + total: json.length - 1, + current: 0, + name: json[0], + } + } +} + +export function connectNotaries() { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'dpow', + 'method': 'notarychains', + }; + + 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, 'connectNotaries', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(connectAllNotaryNodes(json, dispatch))) + } +} + +function getDexNotariesState(json) { + if (json.error === 'less than required responses') { + return dispatch => { + dispatch(triggerToaster(true, translate('TOASTR.LESS_RESPONSES_REQ'), translate('TOASTR.BASILISK_NOTIFICATION'), 'error')); + } + } else { + return { + type: storeType.DASHBOARD_GET_NOTARIES_LIST, + notaries: json, + } + } +} + +export function getDexNotaries(coin) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'dex', + 'method': 'getnotaries', + 'symbol': coin, + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getDexNotaries', + 'type': 'post', + 'url': 'http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), + 'payload': payload, + 'status': 'pending', + })); + return fetch('http://127.0.0.1:' + (Config.useBasiliskInstance ? Config.iguanaCorePort + 1 : Config.iguanaCorePort), { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getDexNotaries', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(getDexNotariesState(json)); + }) + } +} \ No newline at end of file diff --git a/react/src/actions/openAlias.js b/react/src/actions/openAlias.js new file mode 100644 index 0000000..a9037f1 --- /dev/null +++ b/react/src/actions/openAlias.js @@ -0,0 +1,25 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +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)) + }); +} \ No newline at end of file diff --git a/react/src/actions/sendFullBasilisk.js b/react/src/actions/sendFullBasilisk.js new file mode 100644 index 0000000..2ce0ce5 --- /dev/null +++ b/react/src/actions/sendFullBasilisk.js @@ -0,0 +1,245 @@ +import * as storeType from './storeType'; +import { translate } from '../translate/translate'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function sendToAddress(coin, _payload) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'coin': coin, + 'method': 'sendtoaddress', + 'params': [ + _payload.sendTo, + _payload.amount, + 'EasyDEX', + 'EasyDEXTransaction' + ], + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'sendToAddress', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'sendToAddress', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(sendToAddressState(json, dispatch)); + }) + } +} + +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 => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'sendFromAddress', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'sendFromAddress', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(sendToAddressState(json, dispatch)); + }) + } +} + +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) => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'iguanaUTXORawTX', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'iguanaUTXORawTX', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + resolve(json); + }) + }); +} + +export function dexSendRawTX(data) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'dex', + 'method': 'sendrawtransaction', + 'signedtx': data.signedtx, + 'symbol': data.coin + }; + + return new Promise((resolve, reject) => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'dexSendRawTX', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'dexSendRawTX', 'Error', 'error')); + }) + .then(function(response) { + const _response = response.text().then(function(text) { return text; }); + + return _response; + }) + .then(function(json) { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + resolve(json); + }) + }); +} + +function sendToAddressState(json, dispatch) { + if (json && + json.error) { + dispatch(triggerToaster(true, json.error, 'Error', 'error')); + + return { + type: storeType.DASHBOARD_ACTIVE_COIN_SENDTO, + lastSendToResponse: json, + } + } else if (json && json.result && json.complete) { + dispatch(triggerToaster(true, translate('TOASTR.TX_SENT_ALT'), translate('TOASTR.WALLET_NOTIFICATION'), 'success')); + + return { + type: storeType.DASHBOARD_ACTIVE_COIN_SENDTO, + lastSendToResponse: json, + } + } +} + +export function sendToAddressStateAlt(json) { + return { + type: storeType.DASHBOARD_ACTIVE_COIN_SENDTO, + lastSendToResponse: json, + } +} + +export function clearLastSendToResponseState() { + return { + type: storeType.DASHBOARD_ACTIVE_COIN_SENDTO, + lastSendToResponse: null, + } +} \ No newline at end of file diff --git a/react/src/actions/settings.js b/react/src/actions/settings.js new file mode 100644 index 0000000..25d7832 --- /dev/null +++ b/react/src/actions/settings.js @@ -0,0 +1,318 @@ +import * as storeType from './storeType'; +import { translate } from '../translate/translate'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +function getAppInfoState(json) { + return { + type: storeType.LOAD_APP_INFO, + info: json, + } +} + +export function getAppInfo() { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/appinfo', { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getAppInfo', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(getAppInfoState(json))) + } +} + +export function settingsWifkeyState(json, coin) { + return { + type: storeType.GET_WIF_KEY, + wifkey: json[coin + 'wif'], + address: json[coin], + } +} + +function parseImportPrivKeyResponse(json, dispatch) { + if (json.error === 'illegal privkey') { + return dispatch => { + dispatch(triggerToaster(true, 'Illegal privkey', translate('TOASTR.SETTINGS_NOTIFICATION'), 'error')); + } + } + if (json.error === 'privkey already in wallet') { + return dispatch => { + dispatch(triggerToaster(true, 'Privkey already in wallet', translate('TOASTR.SETTINGS_NOTIFICATION'), 'warning')); + } + } + if (json && + json.result !== undefined && + json.result == 'success') { + return dispatch => { + dispatch(triggerToaster(true, translate('TOASTR.PRIV_KEY_IMPORTED'), translate('TOASTR.SETTINGS_NOTIFICATION'), 'success')); + } + } +} + +export function importPrivKey(wifKey) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'method': 'importprivkey', + 'params': [ + wifKey, + 'imported' + ], + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'importPrivKey', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'importPrivKey', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(parseImportPrivKeyResponse(json, dispatch)); + }) + .catch(function(ex) { + dispatch(parseImportPrivKeyResponse({ + 'error': 'privkey already in wallet' + }, dispatch)); + console.log('parsing failed', ex); + }) + } +} + +function getDebugLogState(json) { + const _data = json.result.replace('\n', '\r\n'); + + return { + type: storeType.GET_DEBUG_LOG, + data: _data, + } +} + +export function getDebugLog(target, linesCount) { + const payload = { + 'herdname': target, + 'lastLines': linesCount + }; + + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/debuglog', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getDebugLog', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(getDebugLogState(json))) + } +} + +export function getPeersList(coin) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'SuperNET', + 'method': 'getpeers', + 'activecoin': coin, + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getPeersList', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getPeersList', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(getPeersListState(json, dispatch)); + }) + } +} + +export function getPeersListState(json) { + let peersList = {}; + + if (json && + json.rawpeers && + json.rawpeers.length) { + for (let i = 0; i < json.rawpeers.length; i++) { + peersList[json.rawpeers[i].coin] = json.rawpeers[i].peers; + } + } + + return { + type: storeType.GET_PEERS_LIST, + supernetPeers: json && json.supernet[0] ? json.supernet : null, + rawPeers: peersList, + } +} + +function addPeerNodeState(json, dispatch) { + if (json.error === 'addnode needs active coin, do an addcoin first') { + return dispatch => { + dispatch(triggerToaster(true, 'Addnode needs active coin', translate('TOASTR.SETTINGS_NOTIFICATION'), 'error')); + } + } + if (json.result === 'peer was already connected') { + return dispatch => { + dispatch(triggerToaster(true, 'Peer was already connected', translate('TOASTR.SETTINGS_NOTIFICATION'), 'warning')); + } + } + if (json.result === 'addnode connection was already pending') { + return dispatch => { + dispatch(triggerToaster(true, 'Addnode connection was already pending', translate('TOASTR.SETTINGS_NOTIFICATION'), 'warning')); + } + } + if (json.result === 'addnode submitted') { + return dispatch => { + dispatch(triggerToaster(true, 'Peer is added', translate('TOASTR.SETTINGS_NOTIFICATION'), 'success')); + } + } +} + +export function addPeerNode(coin, ip) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'iguana', + 'method': 'addnode', + 'activecoin': coin, + 'ipaddr': ip, + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'addPeerNode', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'addPeerNode', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(addPeerNodeState(json, dispatch)); + }) + } +} + +export function saveAppConfig(_payload) { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/appconf', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': _payload }), + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'saveAppConfig', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(getAppConfig())) + } +} + +function getAppConfigState(json) { + return { + type: storeType.LOAD_APP_CONFIG, + config: json, + } +} + +export function getAppConfig() { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/appconf', { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getAppConfig', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(getAppConfigState(json))) + } +} \ No newline at end of file diff --git a/react/src/actions/storeType.js b/react/src/actions/storeType.js new file mode 100644 index 0000000..245db57 --- /dev/null +++ b/react/src/actions/storeType.js @@ -0,0 +1,43 @@ +export const TOASTER_MESSAGE = 'TOASTER_MESSAGE'; +export const DISPLAY_ADDCOIN_MODAL = 'DISPLAY_ADDCOIN_MODAL'; +export const GET_ACTIVE_COINS = 'GET_ACTIVE_COINS'; +export const LOGIN = 'LOGIN'; +export const ACTIVE_HANDLE = 'ACTIVE_HANDLE'; +export const DASHBOARD_SECTION_CHANGE = 'DASHBOARD_SECTION_CHANGE'; +export const DASHBOARD_ACTIVE_COIN_CHANGE = 'DASHBOARD_ACTIVE_COIN_CHANGE'; +export const GET_MAIN_ADDRESS = 'GET_MAIN_ADDRESS'; +export const DASHBOARD_ACTIVE_COIN_BALANCE = 'DASHBOARD_ACTIVE_COIN_BALANCE'; +export const DASHBOARD_ACTIVE_COIN_SEND_FORM = 'DASHBOARD_ACTIVE_COIN_SEND_FORM'; +export const DASHBOARD_ACTIVE_COIN_RECEIVE_FORM = 'DASHBOARD_ACTIVE_COIN_RECEIVE_FORM'; +export const DASHBOARD_ACTIVE_COIN_RESET_FORMS = 'DASHBOARD_ACTIVE_COIN_RESET_FORMS'; +export const ATOMIC = 'ATOMIC'; +export const GET_WIF_KEY = 'GET_WIF_KEY'; +export const GET_PEERS_LIST = 'GET_PEERS_LIST'; +export const GET_DEBUG_LOG = 'GET_DEBUG_LOG'; +export const BASILISK_REFRESH = 'BASILISK_REFRESH'; +export const BASILISK_CONNECTION = 'BASILISK_CONNECTION'; +export const SYNCING_FULL_MODE = 'SYNCING_FULL_MODE'; +export const SYNCING_NATIVE_MODE = 'SYNCING_NATIVE_MODE'; +export const ACTIVE_COIN_GET_ADDRESSES = 'ACTIVE_COIN_GET_ADDRESSES'; +export const START_INTERVAL= 'START_INTERVAL'; +export const STOP_INTERVAL= 'STOP_INTERVAL'; +export const DASHBOARD_ACTIVE_SECTION = 'DASHBOARD_ACTIVE_SECTION'; +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 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 const DASHBOARD_GET_NOTARIES_LIST = 'DASHBOARD_GET_NOTARIES_LIST'; +export const DASHBOARD_DISPLAY_NOTARIES_MODAL = 'DASHBOARD_DISPLAY_NOTARIES_MODAL'; +export const DASHBOARD_CONNECT_NOTARIES = 'DASHBOARD_CONNECT_NOTARIES'; +export const VIEW_CACHE_DATA = 'VIEW_CACHE_DATA'; +export const SYNC_ONLY_MODAL_TOGGLE = 'SYNC_ONLY_MODAL_TOGGLE'; +export const SYNC_ONLY_DATA = 'SYNC_ONLY_DATA'; +export const LOAD_APP_CONFIG = 'LOAD_APP_CONFIG'; +export const SAVE_APP_CONFIG = 'SAVE_APP_CONFIG'; +export const SERVICE_ERROR = 'SERVICE_ERROR'; +export const DASHBOARD_ACTIVE_ADDRESS = 'DASHBOARD_ACTIVE_ADDRESS'; +export const LOAD_APP_INFO = 'LOAD_APP_INFO'; +export const LOG_GUI_HTTP = 'LOG_GUI_HTTP'; \ No newline at end of file diff --git a/react/src/actions/syncInfo.js b/react/src/actions/syncInfo.js new file mode 100644 index 0000000..7a07627 --- /dev/null +++ b/react/src/actions/syncInfo.js @@ -0,0 +1,74 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +// TODO: add custom json parser +function getSyncInfoState(json) { + try { + JSON.parse(json); + json = JSON.parse(json); + } catch(e) { + // + } + + return { + type: storeType.SYNCING_FULL_MODE, + progress: json, + } +} + +export function getSyncInfo(coin) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'coin': coin, + 'agent': 'bitcoinrpc', + 'method': 'getinfo', + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'getSyncInfo', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'getSyncInfo', 'Error', 'error')); + }) + .then(function(response) { + const _response = response.text().then(function(text) { return text; }); + + return _response; + }) + .then(function(json) { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + if (json.indexOf('coin is busy processing') === -1) { + dispatch(getSyncInfoState(json, dispatch)); + } + }) + } +} \ No newline at end of file diff --git a/react/src/actions/syncOnly.js b/react/src/actions/syncOnly.js new file mode 100644 index 0000000..0415818 --- /dev/null +++ b/react/src/actions/syncOnly.js @@ -0,0 +1,58 @@ +import * as storeType from './storeType'; +import { translate } from '../translate/translate'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function toggleSyncOnlyModal(display) { + return { + type: storeType.SYNC_ONLY_MODAL_TOGGLE, + display, + } +} + +function getSyncOnlyForksState(json) { + return { + type: storeType.SYNC_ONLY_DATA, + forks: JSON.parse(json.result), + } +} + +export function getSyncOnlyForks() { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/forks/info/show', { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'getSyncOnlyForks', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(getSyncOnlyForksState(json))) + } +} + +export function stopIguanaFork(pmid) { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/forks/stop?pmid=' + pmid, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'stopIguanaFork', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => dispatch(triggerToaster(true, 'Iguana instance is stopped', translate('TOASTR.SERVICE_NOTIFICATION'), 'success'))) + } +} \ No newline at end of file diff --git a/react/src/actions/sysInfo.js b/react/src/actions/sysInfo.js new file mode 100644 index 0000000..b652a27 --- /dev/null +++ b/react/src/actions/sysInfo.js @@ -0,0 +1,26 @@ +import * as storeType from './storeType'; +import { + triggerToaster, + Config +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function shepherdGetSysInfo() { + return dispatch => { + return fetch('http://127.0.0.1:' + Config.agamaPort + '/shepherd/sysinfo', { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + } + }) + .catch(function(error) { + console.log(error); + dispatch(triggerToaster(true, 'Failed to get sys info', 'Error', 'error')) + }) + .then(response => response.json()) + .then(json => console.log(json)); + } +} \ No newline at end of file diff --git a/react/src/actions/walletAuth.js b/react/src/actions/walletAuth.js new file mode 100644 index 0000000..15ff1aa --- /dev/null +++ b/react/src/actions/walletAuth.js @@ -0,0 +1,209 @@ +import * as storeType from './storeType'; +import { translate } from '../translate/translate'; +import { + triggerToaster, + Config, + getMainAddressState +} from './actionCreators'; +import { + logGuiHttp, + guiLogState +} from './log'; + +export function encryptWallet(_passphrase, cb, coin) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'bitcoinrpc', + 'method': 'encryptwallet', + 'passphrase': _passphrase, + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'encryptWallet', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'encryptWallet', 'Error', 'error')); + }) + .then(dispatch(walletPassphrase(_passphrase))) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(cb.call(this, json, coin)); + }); + } +} + +export function walletPassphrase(_passphrase) { + const payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'bitcoinrpc', + 'method': 'walletpassphrase', + 'password': _passphrase, + 'timeout': '300000', + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'walletpassphrase', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'walletPassphrase', 'Error', 'error')); + }) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + }) + } +} + +export function iguanaWalletPassphrase(_passphrase) { + const _payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'handle': '', + 'password': _passphrase, + 'timeout': '2592000', + 'agent': 'bitcoinrpc', + 'method': 'walletpassphrase', + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'iguanaWalletPassphrase', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': _payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(_payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(triggerToaster(true, 'Error iguanaWalletPassphrase', 'Error', 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(iguanaWalletPassphraseState(json, dispatch)); + }); + } +} + +export function iguanaActiveHandle(getMainAddress) { + const _payload = { + 'userpass': 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + 'agent': 'SuperNET', + 'method': 'activehandle', + }; + + return dispatch => { + const _timestamp = Date.now(); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'function': 'iguanaActiveHandle', + 'type': 'post', + 'url': 'http://127.0.0.1:' + Config.iguanaCorePort, + 'payload': _payload, + 'status': 'pending', + })); + + return fetch('http://127.0.0.1:' + Config.iguanaCorePort, { + method: 'POST', + body: JSON.stringify(_payload), + }) + .catch(function(error) { + console.log(error); + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'error', + 'response': error, + })); + dispatch(updateErrosStack('activeHandle')); + dispatch(triggerToaster(true, translate('TOASTR.IGUANA_ARE_YOU_SURE'), translate('TOASTR.SERVICE_NOTIFICATION'), 'error')); + }) + .then(response => response.json()) + .then(json => { + dispatch(logGuiHttp({ + 'timestamp': _timestamp, + 'status': 'success', + 'response': json, + })); + dispatch(getMainAddress ? getMainAddressState(json) : iguanaActiveHandleState(json)); + }); + } +} + +function iguanaWalletPassphraseState(json, dispatch) { + sessionStorage.setItem('IguanaActiveAccount', JSON.stringify(json)); + dispatch(triggerToaster(true, translate('TOASTR.LOGIN_SUCCESSFULL'), translate('TOASTR.ACCOUNT_NOTIFICATION'), 'success')); + dispatch(getMainAddressState(json)); + dispatch(iguanaActiveHandleState(json)); + + return { + type: storeType.LOGIN, + isLoggedIn: json && json.pubkey ? true : false, + } +} + +function iguanaActiveHandleState(json) { + return { + type: storeType.ACTIVE_HANDLE, + isLoggedIn: sessionStorage.getItem('IguanaActiveAccount') && JSON.parse(sessionStorage.getItem('IguanaActiveAccount')).pubkey === json.pubkey && json.status === 'unlocked' ? true : false, + handle: json, + } +} \ No newline at end of file diff --git a/react/src/components/addcoin/addcoin.js b/react/src/components/addcoin/addcoin.js index d85b9a8..24999f7 100644 --- a/react/src/components/addcoin/addcoin.js +++ b/react/src/components/addcoin/addcoin.js @@ -3,9 +3,9 @@ import { translate } from '../../translate/translate'; import { addCoin, toggleAddcoinModal, + triggerToaster, shepherdGetCoinList, - shepherdPostCoinList, - triggerToaster + shepherdPostCoinList } from '../../actions/actionCreators'; import Store from '../../store'; import AddCoinOptionsCrypto from './addcoinOptionsCrypto'; diff --git a/react/src/components/dashboard/coinTileItem.js b/react/src/components/dashboard/coinTileItem.js index f28ea9d..c7cdd02 100644 --- a/react/src/components/dashboard/coinTileItem.js +++ b/react/src/components/dashboard/coinTileItem.js @@ -8,16 +8,15 @@ import { startInterval, stopInterval, iguanaEdexBalance, - getSyncInfoNative, - getKMDBalanceTotal, - getNativeTxHistory, getKMDAddressesNative, - getKMDOPID, getFullTransactionsList, getBasiliskTransactionsList, + changeActiveAddress, getShepherdCache, fetchNewCacheData, - changeActiveAddress + getKMDOPID, + getNativeTxHistory, + getKMDBalanceTotal } from '../../actions/actionCreators'; import Store from '../../store'; diff --git a/react/src/components/dashboard/jumblr.js b/react/src/components/dashboard/jumblr.js index fbe0577..f8b674d 100644 --- a/react/src/components/dashboard/jumblr.js +++ b/react/src/components/dashboard/jumblr.js @@ -22,7 +22,7 @@ class Jumblr extends React.Component { const _translationComponents = translate(_translationID).split('
'); return _translationComponents.map((_translation) => - + {_translation}
diff --git a/react/src/components/dashboard/navbar.js b/react/src/components/dashboard/navbar.js index 18f1779..2f3825d 100644 --- a/react/src/components/dashboard/navbar.js +++ b/react/src/components/dashboard/navbar.js @@ -3,11 +3,11 @@ import { translate } from '../../translate/translate'; import { dashboardChangeSection, toggleAddcoinModal, - logout, stopInterval, - toggleSyncOnlyModal, startInterval, - getSyncOnlyForks + toggleSyncOnlyModal, + getSyncOnlyForks, + logout } from '../../actions/actionCreators'; import Store from '../../store'; @@ -44,7 +44,7 @@ class Navbar extends React.Component { openSyncOnlyModal() { Store.dispatch(getSyncOnlyForks()); - var _iguanaActiveHandle = setInterval(function() { + const _iguanaActiveHandle = setInterval(function() { Store.dispatch(getSyncOnlyForks()); }.bind(this), 3000); Store.dispatch(startInterval('syncOnly', _iguanaActiveHandle)); @@ -63,7 +63,7 @@ class Navbar extends React.Component { -
+
diff --git a/react/src/components/dashboard/receiveCoin.js b/react/src/components/dashboard/receiveCoin.js index 78bd0b5..5dce12d 100644 --- a/react/src/components/dashboard/receiveCoin.js +++ b/react/src/components/dashboard/receiveCoin.js @@ -1,10 +1,9 @@ import React from 'react'; import { translate } from '../../translate/translate'; import { + copyCoinAddress, checkAddressBasilisk, - importAddressBasilisk, - validateAddressBasilisk, - copyCoinAddress + validateAddressBasilisk } from '../../actions/actionCreators'; import Store from '../../store'; diff --git a/react/src/components/dashboard/sendCoin.js b/react/src/components/dashboard/sendCoin.js index 42948d2..2e69531 100644 --- a/react/src/components/dashboard/sendCoin.js +++ b/react/src/components/dashboard/sendCoin.js @@ -7,23 +7,26 @@ import { secondsElapsedToString, secondsToString } from '../../util/time'; -import { edexGetTxIDList, edexRemoveTXID } from '../../util/cacheFormat'; import { - sendToAddress, + edexGetTxIDList, + edexRemoveTXID +} from '../../util/cacheFormat'; +import { sendFromAddress, sendNativeTx, getKMDOPID, resolveOpenAliasAddress, triggerToaster, - iguanaUTXORawTX, - clearLastSendToResponseState, - sendToAddressStateAlt, - dexSendRawTX, - fetchUtxoCache, basiliskRefresh, + shepherdGroomPostPromise, edexGetTransaction, getCacheFile, - shepherdGroomPostPromise + fetchUtxoCache, + sendToAddress, + iguanaUTXORawTX, + clearLastSendToResponseState, + sendToAddressStateAlt, + dexSendRawTX } from '../../actions/actionCreators'; import Store from '../../store'; diff --git a/react/src/components/dashboard/settings.js b/react/src/components/dashboard/settings.js index 0784eb3..c140ddd 100644 --- a/react/src/components/dashboard/settings.js +++ b/react/src/components/dashboard/settings.js @@ -299,7 +299,7 @@ class Settings extends React.Component { const _translationComponents = translate(_translationID).split('
'); return _translationComponents.map((_translation) => - + { _translation }
diff --git a/react/src/components/dashboard/syncOnly.js b/react/src/components/dashboard/syncOnly.js index b93b8ca..bcff8fe 100644 --- a/react/src/components/dashboard/syncOnly.js +++ b/react/src/components/dashboard/syncOnly.js @@ -1,11 +1,11 @@ import React from 'react'; import { translate } from '../../translate/translate'; import { - toggleSyncOnlyModal, stopInterval, + addCoin, + toggleSyncOnlyModal, stopIguanaFork, - restartIguanaInstance, - addCoin + restartIguanaInstance } from '../../actions/actionCreators'; import Store from '../../store'; @@ -231,7 +231,8 @@ class SyncOnly extends React.Component { const forkInfo = this.props.SyncOnly.forks[port]; if (forkInfo && - forkInfo.registry && forkInfo.getinfo) { + forkInfo.registry && + forkInfo.getinfo) { items.push(
diff --git a/react/src/components/dashboard/walletsData.js b/react/src/components/dashboard/walletsData.js index 9dcb4e0..592960c 100644 --- a/react/src/components/dashboard/walletsData.js +++ b/react/src/components/dashboard/walletsData.js @@ -6,18 +6,18 @@ import { sortByDate } from '../../util/sort'; import { basiliskRefresh, basiliskConnection, - getDexNotaries, toggleDashboardTxInfoModal, getBasiliskTransactionsList, changeMainBasiliskAddress, displayNotariesModal, - deleteCacheFile, - connectNotaries, toggleViewCacheModal, - fetchNewCacheData, - fetchUtxoCache, + changeActiveAddress, restartBasiliskInstance, - changeActiveAddress + connectNotaries, + getDexNotaries, + deleteCacheFile, + fetchNewCacheData, + fetchUtxoCache } from '../../actions/actionCreators'; import Store from '../../store'; @@ -82,14 +82,9 @@ class WalletsData extends React.Component { } } - componentDidMount() { - console.log('use cache = ', this.state.useCache); - } - toggleCacheApi() { const _useCache = !this.state.useCache; - console.log('useCache is set to', _useCache); sessionStorage.setItem('useCache', _useCache); this.setState(Object.assign({}, this.state, { useCache: _useCache, diff --git a/react/src/components/dashboard/walletsNativeReceive.js b/react/src/components/dashboard/walletsNativeReceive.js index bf1371d..4ae6efd 100644 --- a/react/src/components/dashboard/walletsNativeReceive.js +++ b/react/src/components/dashboard/walletsNativeReceive.js @@ -1,14 +1,11 @@ import React from 'react'; import { translate } from '../../translate/translate'; import { - getNewKMDAddresses, - copyCoinAddress + copyCoinAddress, + getNewKMDAddresses } from '../../actions/actionCreators'; import Store from '../../store'; -// TODO: implement sorting -// TODO: importaddress, importprivkey(?) - class WalletsNativeReceive extends React.Component { constructor(props) { super(props); diff --git a/react/src/components/dashboard/walletsNativeSend.js b/react/src/components/dashboard/walletsNativeSend.js index 2ac87f7..69884ef 100644 --- a/react/src/components/dashboard/walletsNativeSend.js +++ b/react/src/components/dashboard/walletsNativeSend.js @@ -3,10 +3,10 @@ import Config from '../../config'; import { translate } from '../../translate/translate'; import { secondsToString } from '../../util/time'; import { - sendNativeTx, - getKMDOPID, resolveOpenAliasAddress, - triggerToaster + triggerToaster, + sendNativeTx, + getKMDOPID } from '../../actions/actionCreators'; import Store from '../../store'; diff --git a/react/src/components/dashboard/walletsNav.js b/react/src/components/dashboard/walletsNav.js index dfb7080..b726c8b 100644 --- a/react/src/components/dashboard/walletsNav.js +++ b/react/src/components/dashboard/walletsNav.js @@ -72,7 +72,7 @@ class WalletsNav extends React.Component {
+ style={{ paddingBottom: '20px', marginBottom: this.props.ActiveCoin.mode === 'basilisk' ? '30px' : '0' }}>
    { translate('INDEX.MY') } { this.props && this.props.ActiveCoin ? this.props.ActiveCoin.coin : '-' } { translate('INDEX.ADDRESS') }: { this.props && this.props.Dashboard && this.props.Dashboard.activeHandle ? this.props.Dashboard.activeHandle[this.props.ActiveCoin.coin] : '-' }
diff --git a/react/src/components/login/login.js b/react/src/components/login/login.js index a0cf9d8..8187517 100644 --- a/react/src/components/login/login.js +++ b/react/src/components/login/login.js @@ -3,13 +3,13 @@ import { translate } from '../../translate/translate'; import { toggleAddcoinModal, iguanaWalletPassphrase, - createNewWallet, iguanaActiveHandle, - toggleSyncOnlyModal, startInterval, stopInterval, + getDexCoins, + toggleSyncOnlyModal, getSyncOnlyForks, - getDexCoins + createNewWallet } from '../../actions/actionCreators'; import Store from '../../store'; import { PassPhraseGenerator } from '../../util/crypto/passphrasegenerator'; @@ -41,7 +41,7 @@ class Login extends React.Component { openSyncOnlyModal() { Store.dispatch(getSyncOnlyForks()); - var _iguanaActiveHandle = setInterval(function() { + const _iguanaActiveHandle = setInterval(function() { Store.dispatch(getSyncOnlyForks()); }.bind(this), 3000); Store.dispatch(startInterval('syncOnly', _iguanaActiveHandle)); @@ -79,7 +79,7 @@ class Login extends React.Component { }); if (!this.props.Interval.interval.activeCoins) { - var _iguanaActiveCoins = setInterval(function() { + const _iguanaActiveCoins = setInterval(function() { Store.dispatch(getDexCoins()); }.bind(this), 10000); Store.dispatch(startInterval('activeCoins', _iguanaActiveCoins)); diff --git a/react/src/components/main/main.js b/react/src/components/main/main.js index 7285c93..9eebbd9 100644 --- a/react/src/components/main/main.js +++ b/react/src/components/main/main.js @@ -3,14 +3,14 @@ import Config from '../../config'; import WalletMain from './walletMain'; import { iguanaSetRPCAuth } from '../../util/auth'; import Store from '../../store'; -import { getDexCoins, iguanaActiveHandle } from '../../actions/actionCreators'; +import { + getDexCoins, + iguanaActiveHandle +} from '../../actions/actionCreators'; class Main extends React.Component { constructor(props) { super(props); - this.success = this.success.bind(this); - this.error = this.error.bind(this); - this.loading = this.loading.bind(this); this.isWalletUnlocked = this.isWalletUnlocked.bind(this); this.state = { isLoggedIn: false, @@ -22,7 +22,7 @@ class Main extends React.Component { componentDidMount() { Store.dispatch(iguanaActiveHandle()); - var _iguanaActiveHandle = setInterval(function() { + const _iguanaActiveHandle = setInterval(function() { Store.dispatch(iguanaActiveHandle()); }, 30000); @@ -32,36 +32,12 @@ class Main extends React.Component { } componentWillMount() { - console.log('mounting main component'); // set userpass param Store.dispatch(getDexCoins()); iguanaSetRPCAuth(); - if (sessionStorage.getItem('session')) { - this.setState({ - user: JSON.parse(sessionStorage.getItem('')), - }); - } - } - - error(response) { - console.error(response); - } - - loading() { - console.log('loading'); - } - - success(response) { - sessionStorage.setItem('session', JSON.stringify('')); - this.setState({ - user: JSON.parse(sessionStorage.getItem('session')), - }); } isWalletUnlocked() { - /*if (!this.state.seed) { - return (
add coin form
); - }*/ return ( ); @@ -70,7 +46,7 @@ class Main extends React.Component { render() { return (
- {this.isWalletUnlocked()} + { this.isWalletUnlocked() }
); } diff --git a/react/src/reducers/activeCoin.js b/react/src/reducers/activeCoin.js index 58200d9..ec0dee3 100644 --- a/react/src/reducers/activeCoin.js +++ b/react/src/reducers/activeCoin.js @@ -16,7 +16,7 @@ import { DASHBOARD_GET_NOTARIES_LIST, DASHBOARD_DISPLAY_NOTARIES_MODAL, DASHBOARD_ACTIVE_ADDRESS, -} from '../actions/actionCreators'; +} from '../actions/storeType'; // TODO: refactor diff --git a/react/src/reducers/addcoin.js b/react/src/reducers/addcoin.js index 4bd147c..47d96b6 100644 --- a/react/src/reducers/addcoin.js +++ b/react/src/reducers/addcoin.js @@ -1,4 +1,6 @@ -import { DISPLAY_ADDCOIN_MODAL } from '../actions/actionCreators' +import { + DISPLAY_ADDCOIN_MODAL +} from '../actions/storeType'; export function AddCoin(state = { display: false, diff --git a/react/src/reducers/atomic.js b/react/src/reducers/atomic.js index d518c51..073f7e6 100644 --- a/react/src/reducers/atomic.js +++ b/react/src/reducers/atomic.js @@ -1,4 +1,6 @@ -import { ATOMIC } from '../actions/actionCreators'; +import { + ATOMIC +} from '../actions/storeType'; export function Atomic(state = { response: null, diff --git a/react/src/reducers/dashboard.js b/react/src/reducers/dashboard.js index 5b5f69e..cf0923f 100644 --- a/react/src/reducers/dashboard.js +++ b/react/src/reducers/dashboard.js @@ -9,7 +9,7 @@ import { VIEW_CACHE_DATA, LOG_GUI_HTTP, TOGGLE_NOTIFICATIONS_MODAL -} from '../actions/actionCreators'; +} from '../actions/storeType'; export function Dashboard(state = { activeSection: 'wallets', diff --git a/react/src/reducers/errors.js b/react/src/reducers/errors.js index 812888b..bf77baf 100644 --- a/react/src/reducers/errors.js +++ b/react/src/reducers/errors.js @@ -1,4 +1,6 @@ -import { SERVICE_ERROR } from '../actions/actionCreators'; +import { + SERVICE_ERROR +} from '../actions/storeType'; export function Errors(state = { errors: {}, diff --git a/react/src/reducers/interval.js b/react/src/reducers/interval.js index 8a21c2b..10dca6f 100644 --- a/react/src/reducers/interval.js +++ b/react/src/reducers/interval.js @@ -1,4 +1,7 @@ -import { START_INTERVAL, STOP_INTERVAL } from '../actions/actionCreators' +import { + START_INTERVAL, + STOP_INTERVAL +} from '../actions/storeType' export function Interval(state = { interval: {}, diff --git a/react/src/reducers/main.js b/react/src/reducers/main.js index 63bc6fb..f000ae6 100644 --- a/react/src/reducers/main.js +++ b/react/src/reducers/main.js @@ -2,7 +2,7 @@ import { GET_ACTIVE_COINS, LOGIN, ACTIVE_HANDLE -} from '../actions/actionCreators'; +} from '../actions/storeType'; export function Main(state = { isLoggedIn: false, diff --git a/react/src/reducers/settings.js b/react/src/reducers/settings.js index ca26b76..2799e3d 100644 --- a/react/src/reducers/settings.js +++ b/react/src/reducers/settings.js @@ -4,7 +4,7 @@ import { GET_DEBUG_LOG, LOAD_APP_CONFIG, LOAD_APP_INFO -} from '../actions/actionCreators'; +} from '../actions/storeType'; export function Settings(state = { wifkey: null, diff --git a/react/src/reducers/syncOnly.js b/react/src/reducers/syncOnly.js index 55d201e..c1fecfb 100644 --- a/react/src/reducers/syncOnly.js +++ b/react/src/reducers/syncOnly.js @@ -1,7 +1,7 @@ import { SYNC_ONLY_MODAL_TOGGLE, SYNC_ONLY_DATA -} from '../actions/actionCreators'; +} from '../actions/storeType'; export function SyncOnly(state = { display: false, diff --git a/react/src/reducers/toaster.js b/react/src/reducers/toaster.js index 7ea1ed8..23057be 100644 --- a/react/src/reducers/toaster.js +++ b/react/src/reducers/toaster.js @@ -1,4 +1,6 @@ -import { TOASTER_MESSAGE } from '../actions/actionCreators'; +import { + TOASTER_MESSAGE +} from '../actions/storeType'; export function toaster(state = { display: false, diff --git a/react/src/util/auth.js b/react/src/util/auth.js index 00d12f6..46d20f1 100644 --- a/react/src/util/auth.js +++ b/react/src/util/auth.js @@ -11,5 +11,4 @@ try { export function iguanaSetRPCAuth() { sessionStorage.setItem('IguanaRPCAuth', appSessionHash); - console.log('passphraseGen', appSessionHash); } \ No newline at end of file