From 9c6dd9ef4953f6e421feb6e6684ef43da26f6b75 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 10 Aug 2016 13:43:01 -0700 Subject: Create "buy form" add shape shift --- ui/app/actions.js | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) (limited to 'ui/app/actions.js') 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() + } +} -- cgit From 4ace425a9c4a5112692d1e9269d3074a0987e5e9 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 10 Aug 2016 13:51:14 -0700 Subject: Fix merge mess --- ui/app/actions.js | 1 - 1 file changed, 1 deletion(-) (limited to 'ui/app/actions.js') diff --git a/ui/app/actions.js b/ui/app/actions.js index bdf100040..52c03f16f 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -624,7 +624,6 @@ function buyEth (address, amount) { }) } } -<<<<<<< HEAD function buyEthSubview () { return { -- cgit From b4c9a5225947f9aadac5fd1bb23fde64740d774a Mon Sep 17 00:00:00 2001 From: Frankie Date: Fri, 12 Aug 2016 15:41:59 -0700 Subject: Change buy forms so that they are their own view and add Qr-code --- ui/app/actions.js | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'ui/app/actions.js') diff --git a/ui/app/actions.js b/ui/app/actions.js index 52c03f16f..b6b5e684b 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -113,8 +113,8 @@ var actions = { // buy Eth with coinbase BUY_ETH: 'BUY_ETH', buyEth: buyEth, - buyEthSubview: buyEthSubview, - BUY_ETH_SUBVIEW: 'BUY_ETH_SUBVIEW', + buyEthView: buyEthView, + BUY_ETH_VIEW: 'BUY_ETH_VIEW', UPDATE_COINBASE_AMOUNT: 'UPDATE_COIBASE_AMOUNT', updateCoinBaseAmount: updateCoinBaseAmount, UPDATE_BUY_ADDRESS: 'UPDATE_BUY_ADDRESS', @@ -125,12 +125,14 @@ var actions = { 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, +// QR STUFF: + SHOW_QR: 'SHOW_QR', + getQr: getQr, } module.exports = actions @@ -625,9 +627,10 @@ function buyEth (address, amount) { } } -function buyEthSubview () { +function buyEthView (address) { return { - type: actions.BUY_ETH_SUBVIEW, + type: actions.BUY_ETH_VIEW, + value: address, } } @@ -691,19 +694,32 @@ function shapeShiftSubview (network) { function coinShiftRquest (data) { return (dispatch) => { - dispatch(actions.showSubLoadingIndication()) + dispatch(actions.showLoadingIndication()) shapeShiftRequest('shift', { method: 'POST', data}, (response) => { - dispatch(actions.hideSubLoadingIndication()) + if (response.error) return dispatch(actions.showWarning(response.error)) + var message = `Deposit your ${response.depositType} to the address bellow:` + dispatch(actions.getQr(response.deposit, '125x125', message)) + }) + } +} + +function getQr (data, size, message) { + return (dispatch) => { + qrRequest(data, size, (response) => { + dispatch(actions.hideLoadingIndication()) if (response.error) return dispatch(actions.showWarning(response.error)) dispatch({ - type: actions.COIN_SHIFT_REQUEST, + type: actions.SHOW_QR, value: { - response: response, + qr: response, + message: message, + data: data, }, }) }) } } + function shapeShiftRequest (query, options, cb) { var queryResponse, method !options ? options = {} : null @@ -727,3 +743,15 @@ function shapeShiftRequest (query, options, cb) { return shapShiftReq.send() } } + +function qrRequest (data, size, cb) { + var requestListner = function (request) { + cb ? cb(this.responseText) : null + return this.responseText + } + + var qrReq = new XMLHttpRequest() + qrReq.addEventListener('load', requestListner) + qrReq.open('GET', `https://api.qrserver.com/v1/create-qr-code/?size=${size}&format=svg&data=${data}`, true) + qrReq.send() +} -- cgit From 99a788a6f02ffcd53e88222ab0ba4b89d8040f4f Mon Sep 17 00:00:00 2001 From: Frankie Date: Fri, 12 Aug 2016 17:43:24 -0700 Subject: Add multi message capability to Qr view for market info --- ui/app/actions.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'ui/app/actions.js') diff --git a/ui/app/actions.js b/ui/app/actions.js index b6b5e684b..61f900df9 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -692,13 +692,14 @@ function shapeShiftSubview (network) { } } -function coinShiftRquest (data) { +function coinShiftRquest (data, marketData) { return (dispatch) => { dispatch(actions.showLoadingIndication()) shapeShiftRequest('shift', { method: 'POST', data}, (response) => { if (response.error) return dispatch(actions.showWarning(response.error)) - var message = `Deposit your ${response.depositType} to the address bellow:` - dispatch(actions.getQr(response.deposit, '125x125', message)) + var message = ` + Deposit your ${response.depositType} to the address bellow:` + dispatch(actions.getQr(response.deposit, '125x125', [message].concat(marketData))) }) } } -- cgit