From 752d16f6c072b0dd54eb245209881a25ff06cb8e Mon Sep 17 00:00:00 2001 From: Frankie Date: Thu, 18 Aug 2016 10:40:35 -0700 Subject: WIP: ShapeShift tx --- app/scripts/lib/config-manager.js | 33 +++++++++++++++++++++++++++++++++ app/scripts/lib/idStore.js | 1 + app/scripts/metamask-controller.js | 6 ++++++ 3 files changed, 40 insertions(+) (limited to 'app/scripts') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index d14d3afc3..8e59d02f3 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -284,3 +284,36 @@ ConfigManager.prototype.getShouldntShowWarning = function () { var data = this.getData() return ('isEthConfirmed' in data) && data.isEthConfirmed } + +ConfigManager.prototype.getShapeShiftTxList = function () { + var data = this.getData() + var shapeShiftTxList = data.shapeShiftTxList ? data.shapeShiftTxList : [] + shapeShiftTxList.forEach((tx) => { + if (tx.response.status !== 'complete'){ + var requestListner = function (request) { + tx.response = JSON.parse(this.responseText) + if (tx.status === 'complete') { + tx.completeTime = new Date().getTime() + } + } + + var shapShiftReq = new XMLHttpRequest() + shapShiftReq.addEventListener('load', requestListner) + shapShiftReq.open('GET', `https://shapeshift.io/txStat/${tx.depositAddress}`, true) + shapShiftReq.send() + } + }) + return shapeShiftTxList +} + +ConfigManager.prototype.createShapeShiftTx = function (depositAddress, depositType) { + var data = this.getData() + + var shapeShiftTx = {depositAddress, depositType, key: 'shapeshift', time: new Date().getTime(), response: {}} + if(!data.shapeShiftTxList) { + data.shapeShiftTxList = [shapeShiftTx] + } else { + data.shapeShiftTxList.push(shapeShiftTx) + } + this.setData(data) +} diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index f63e03ec6..55d5e5e61 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -100,6 +100,7 @@ IdentityStore.prototype.getState = function () { unconfMsgs: messageManager.unconfirmedMsgs(), messages: messageManager.getMsgList(), selectedAddress: configManager.getSelectedAccount(), + shapeShiftTxList: configManager.getShapeShiftTxList(), })) } diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 2c141a402..d34f594d7 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -59,6 +59,8 @@ module.exports = class MetamaskController { recoverSeed: idStore.recoverSeed.bind(idStore), // coinbase buyEth: this.buyEth.bind(this), + // shapeshift + createShapeShiftTx : this.createShapeShiftTx.bind(this), } } @@ -287,6 +289,10 @@ module.exports = class MetamaskController { }) } + createShapeShiftTx (depositAddress, depositType) { + this.configManager.createShapeShiftTx(depositAddress, depositType) + } + } function noop () {} -- cgit v1.2.3 From 3525dc080110e7af1f9544e18b5646c87fb9ae95 Mon Sep 17 00:00:00 2001 From: Frankie Date: Thu, 18 Aug 2016 15:20:26 -0700 Subject: Create a ShapeShift tx in tx History --- app/scripts/lib/config-manager.js | 10 ++++++---- app/scripts/metamask-controller.js | 5 ++--- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index d6d10c8f2..6f5cb3a4a 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -337,11 +337,11 @@ ConfigManager.prototype.getShapeShiftTxList = function () { var data = this.getData() var shapeShiftTxList = data.shapeShiftTxList ? data.shapeShiftTxList : [] shapeShiftTxList.forEach((tx) => { - if (tx.response.status !== 'complete'){ + if (tx.response.status !== 'complete') { var requestListner = function (request) { tx.response = JSON.parse(this.responseText) - if (tx.status === 'complete') { - tx.completeTime = new Date().getTime() + if (tx.response.status === 'complete') { + tx.time = new Date().getTime() } } @@ -351,6 +351,7 @@ ConfigManager.prototype.getShapeShiftTxList = function () { shapShiftReq.send() } }) + this.setData(data) return shapeShiftTxList } @@ -358,10 +359,11 @@ ConfigManager.prototype.createShapeShiftTx = function (depositAddress, depositTy var data = this.getData() var shapeShiftTx = {depositAddress, depositType, key: 'shapeshift', time: new Date().getTime(), response: {}} - if(!data.shapeShiftTxList) { + if (!data.shapeShiftTxList) { data.shapeShiftTxList = [shapeShiftTx] } else { data.shapeShiftTxList.push(shapeShiftTx) } this.setData(data) } + diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 0b1d40148..218f1f72a 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -65,7 +65,7 @@ module.exports = class MetamaskController { // coinbase buyEth: this.buyEth.bind(this), // shapeshift - createShapeShiftTx : this.createShapeShiftTx.bind(this), + createShapeShiftTx: this.createShapeShiftTx.bind(this), } } @@ -319,10 +319,9 @@ module.exports = class MetamaskController { }) } - createShapeShiftTx (depositAddress, depositType) { + createShapeShiftTx (depositAddress, depositType) { this.configManager.createShapeShiftTx(depositAddress, depositType) } - } function noop () {} -- cgit v1.2.3