diff options
author | Frankie <frankie.pangilinan@consensys.net> | 2016-08-11 04:43:01 +0800 |
---|---|---|
committer | Frankie <frankie.pangilinan@consensys.net> | 2016-08-11 04:43:01 +0800 |
commit | 9c6dd9ef4953f6e421feb6e6684ef43da26f6b75 (patch) | |
tree | 309366cc31236440709705e0a9a9e7eb183801a3 /ui/app/actions.js | |
parent | 667483ac2037bef5b412ce33f0d9bb0605d6c13b (diff) | |
download | tangerine-wallet-browser-9c6dd9ef4953f6e421feb6e6684ef43da26f6b75.tar tangerine-wallet-browser-9c6dd9ef4953f6e421feb6e6684ef43da26f6b75.tar.gz tangerine-wallet-browser-9c6dd9ef4953f6e421feb6e6684ef43da26f6b75.tar.bz2 tangerine-wallet-browser-9c6dd9ef4953f6e421feb6e6684ef43da26f6b75.tar.lz tangerine-wallet-browser-9c6dd9ef4953f6e421feb6e6684ef43da26f6b75.tar.xz tangerine-wallet-browser-9c6dd9ef4953f6e421feb6e6684ef43da26f6b75.tar.zst tangerine-wallet-browser-9c6dd9ef4953f6e421feb6e6684ef43da26f6b75.zip |
Create "buy form" add shape shift
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r-- | ui/app/actions.js | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js index 3e0fe55c0..754ffced8 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -66,6 +66,10 @@ var actions = { showPrivateKey: showPrivateKey, SAVE_ACCOUNT_LABEL: 'SAVE_ACCOUNT_LABEL', saveAccountLabel: saveAccountLabel, + AGREE_TO_ETH_WARNING: 'AGREE_TO_ETH_WARNING', + agreeToEthWarning: agreeToEthWarning, + SHOW_ETH_WARNING: 'SHOW_ETH_WARNING', + showEthWarning: showEthWarning, // tx conf screen COMPLETED_TX: 'COMPLETED_TX', TRANSACTION_ERROR: 'TRANSACTION_ERROR', @@ -106,6 +110,28 @@ var actions = { HIDE_LOADING: 'HIDE_LOADING_INDICATION', showLoadingIndication: showLoadingIndication, hideLoadingIndication: hideLoadingIndication, + // 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 @@ -489,6 +515,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) } @@ -559,3 +597,134 @@ function showSendPage () { type: actions.SHOW_SEND_PAGE, } } + +function agreeToEthWarning () { + return (dispatch) => { + _accountManager.agreeToEthWarning((err) => { + if (err) { + return dispatch(actions.showEthWarning(err.message)) + } + dispatch({ + type: actions.AGREE_TO_ETH_WARNING, + }) + }) + } +} + +function showEthWarning () { + return { + type: actions.SHOW_ETH_WARNING, + } +} + +function buyEth (address, amount) { + return (dispatch) => { + _accountManager.buyEth(address, amount) + dispatch({ + type: actions.BUY_ETH, + }) + } +} + +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() + } +} |