aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/actions.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r--ui/app/actions.js134
1 files changed, 134 insertions, 0 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index 82a319907..bdf100040 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -113,6 +113,24 @@ var actions = {
// buy Eth with coinbase
BUY_ETH: 'BUY_ETH',
buyEth: buyEth,
+ buyEthSubview: buyEthSubview,
+ BUY_ETH_SUBVIEW: 'BUY_ETH_SUBVIEW',
+ UPDATE_COINBASE_AMOUNT: 'UPDATE_COIBASE_AMOUNT',
+ updateCoinBaseAmount: updateCoinBaseAmount,
+ UPDATE_BUY_ADDRESS: 'UPDATE_BUY_ADDRESS',
+ updateBuyAddress: updateBuyAddress,
+ COINBASE_SUBVIEW: 'COINBASE_SUBVIEW',
+ coinBaseSubview: coinBaseSubview,
+ SHAPESHIFT_SUBVIEW: 'SHAPESHIFT_SUBVIEW',
+ shapeShiftSubview: shapeShiftSubview,
+ PAIR_UPDATE: 'PAIR_UPDATE',
+ pairUpdate: pairUpdate,
+ COIN_SHIFT_REQUEST: 'COIN_SHIFT_REQUEST',
+ coinShiftRquest: coinShiftRquest,
+ SHOW_SUB_LOADING_INDICATION: 'SHOW_SUB_LOADING_INDICATION',
+ showSubLoadingIndication: showSubLoadingIndication,
+ HIDE_SUB_LOADING_INDICATION: 'HIDE_SUB_LOADING_INDICATION',
+ hideSubLoadingIndication: hideSubLoadingIndication,
}
module.exports = actions
@@ -496,6 +514,18 @@ function hideLoadingIndication () {
}
}
+function showSubLoadingIndication () {
+ return {
+ type: actions.SHOW_SUB_LOADING_INDICATION,
+ }
+}
+
+function hideSubLoadingIndication () {
+ return {
+ type: actions.HIDE_SUB_LOADING_INDICATION,
+ }
+}
+
function showWarning (text) {
return this.displayWarning(text)
}
@@ -594,3 +624,107 @@ function buyEth (address, amount) {
})
}
}
+<<<<<<< HEAD
+
+function buyEthSubview () {
+ return {
+ type: actions.BUY_ETH_SUBVIEW,
+ }
+}
+
+function updateCoinBaseAmount (value) {
+ return {
+ type: actions.UPDATE_COINBASE_AMOUNT,
+ value,
+ }
+}
+
+function updateBuyAddress (value) {
+ return {
+ type: actions.UPDATE_BUY_ADDRESS,
+ value,
+ }
+}
+
+function coinBaseSubview () {
+ return {
+ type: actions.COINBASE_SUBVIEW,
+ }
+}
+
+function pairUpdate (coin) {
+ return (dispatch) => {
+ dispatch(actions.showSubLoadingIndication())
+ dispatch(actions.hideWarning())
+ shapeShiftRequest('marketinfo', {pair: `${coin.toLowerCase()}_eth`}, (mktResponse) => {
+ dispatch(actions.hideSubLoadingIndication())
+ dispatch({
+ type: actions.PAIR_UPDATE,
+ value: {
+ marketinfo: mktResponse,
+ },
+ })
+ })
+ }
+}
+
+function shapeShiftSubview (network) {
+ var pair
+ network === 'classic' ? pair = 'btc_etc' : pair = 'btc_eth'
+
+ return (dispatch) => {
+ dispatch(actions.showSubLoadingIndication())
+ shapeShiftRequest('marketinfo', {pair}, (mktResponse) => {
+ shapeShiftRequest('getcoins', {}, (response) => {
+ dispatch(actions.hideSubLoadingIndication())
+ if (mktResponse.error) return dispatch(actions.showWarning(mktResponse.error))
+ dispatch({
+ type: actions.SHAPESHIFT_SUBVIEW,
+ value: {
+ marketinfo: mktResponse,
+ coinOptions: response,
+ },
+ })
+ })
+ })
+ }
+}
+
+function coinShiftRquest (data) {
+ return (dispatch) => {
+ dispatch(actions.showSubLoadingIndication())
+ shapeShiftRequest('shift', { method: 'POST', data}, (response) => {
+ dispatch(actions.hideSubLoadingIndication())
+ if (response.error) return dispatch(actions.showWarning(response.error))
+ dispatch({
+ type: actions.COIN_SHIFT_REQUEST,
+ value: {
+ response: response,
+ },
+ })
+ })
+ }
+}
+function shapeShiftRequest (query, options, cb) {
+ var queryResponse, method
+ !options ? options = {} : null
+ options.method ? method = options.method : method = 'GET'
+
+ var requestListner = function (request) {
+ queryResponse = JSON.parse(this.responseText)
+ cb ? cb(queryResponse) : null
+ return queryResponse
+ }
+
+ var shapShiftReq = new XMLHttpRequest()
+ shapShiftReq.addEventListener('load', requestListner)
+ shapShiftReq.open(method, `https://shapeshift.io/${query}/${options.pair ? options.pair : ''}`, true)
+
+ if (options.method === 'POST') {
+ var jsonObj = JSON.stringify(options.data)
+ shapShiftReq.setRequestHeader('Content-Type', 'application/json')
+ return shapShiftReq.send(jsonObj)
+ } else {
+ return shapShiftReq.send()
+ }
+}