@ -1,7 +1,9 @@
import 'whatwg-fetch' ;
import { startCurrencyAssetChain } from '../components/addcoin/payload' ;
import { translate } from '../translate/translate' ;
export const TOASTER_MESSAGE = 'TOASTER_MESSAGE' ;
export const DISPLAY_ADDCOIN_MODAL = 'DISPLAY_ADDCOIN_MODAL' ;
function triggerToaster ( display , message , title , _ type ) {
return {
@ -13,21 +15,86 @@ function triggerToaster(display, message, title, _type) {
}
}
function toggleAddcoinModalState ( display , isLogin ) {
return {
type : DISPLAY_ADDCOIN_MODAL ,
display : display ,
isLogin : isLogin ,
}
}
export function toggleAddcoinModal ( display , isLogin ) {
return dispatch => {
dispatch ( toggleAddcoinModalState ( display , isLogin ) ) ;
}
}
export function addCoin ( coin , mode ) {
console . log ( 'coin, mode' , coin + ' ' + mode ) ;
return dispatch => {
dispatch ( shepherdGetConfig ( coin , mode ) ) ;
//dispatch(triggerToaster(true, 'Coin ' + coin + ' added in ' + mode, 'Coin message', 'warning'))
}
}
export function addCoinResult ( coin , mode , acData ) {
console . log ( 'coin' , coin ) ;
export function iguanaAddCoin ( coin , mode , acData ) {
console . log ( 'acData' , acData ) ;
//console.log('coin, mode', coin + ' ' + mode);
return dispatch => {
return fetch ( 'http://127.0.0.1:7778' , {
method : 'POST' ,
body : JSON . stringify ( acData ) ,
} )
. catch ( function ( error ) {
console . log ( error ) ;
dispatch ( triggerToaster ( true , translate ( 'TOASTR.FAILED_TO_ADDCOIN' ) , translate ( 'TOASTR.ACCOUNT_NOTIFICATION' ) , 'error' ) )
} )
. then ( response => response . json ( ) )
. then ( json => dispatch ( addCoinResult ( coin , mode , acData ) ) ) ;
}
}
export function shepherdHerd ( coin , mode , path ) {
const herdData = {
'ac_name' : coin ,
'ac_options' : [
'-daemon=0' ,
'-server' ,
'-ac_name=' + coin ,
'-addnode=78.47.196.146'
]
} ;
const acData = startCurrencyAssetChain ( path . result , coin , mode ) ;
console . log ( 'herdData' , herdData ) ;
return dispatch => {
return fetch ( 'http://127.0.0.1:17777/shepherd/herd' , {
method : 'POST' ,
headers : {
'Content-Type' : 'application/json' ,
} ,
body : JSON . stringify ( {
'herd' : coin !== 'zcashd' ? '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 = {
'full' : 1 ,
'basilisk' : 0 ,
'native' : - 1 ,
} ;
return dispatch => {
//dispatch(shepherdGetConfig(coin, mode));
dispatch ( triggerToaster ( true , 'Coin ' + coin + ' added in ' + mode + ' mode' , 'Coin message' , 'success' ) )
dispatch ( triggerToaster ( true , coin + ' ' + translate ( 'TOASTR.COIN_STARTED' ) + modeToValue [ defaultMode ] + ' ' + translate ( 'TOASTR.MODE' ) , translate ( 'TOASTR.COIN_NOTIFICATION' ) , 'success' ) ) ;
}
}
@ -45,29 +112,6 @@ export function shepherdGetConfig(coin, mode) {
dispatch ( triggerToaster ( true , 'Failed to get mode config' , 'Error' , 'error' ) )
} )
. then ( response => response . json ( ) )
. then ( json => dispatch ( addCoinResult ( coin , mode , startCurrencyAssetChain ( json . result , coin , mode ) ) ) )
. then ( json => dispatch ( shepherdHerd ( coin , mode , json ) ) ) ;
}
/ * f u n c t i o n S h e p h e r d _ g e t C o n f ( c o i n ) {
var result = [ ] ,
ajax_data = { 'chain' : coin } ;
console . log ( ajax_data ) ;
$ . ajax ( {
async : false ,
type : 'POST' ,
data : JSON . stringify ( ajax_data ) ,
url : 'http://127.0.0.1:17777/shepherd/getconf' ,
contentType : 'application/json' , // send as JSON
success : function ( data , textStatus , jqXHR ) {
var AjaxOutputData = JSON . parse ( data ) ;
console . log ( AjaxOutputData . result ) ;
result . push ( { 'path' : AjaxOutputData . result } ) ;
} ,
error : function ( xhr , textStatus , error ) {
}
} ) ;
return result ;
} * /
}