diff options
Diffstat (limited to 'app/scripts/controllers/shapeshift.js')
-rw-r--r-- | app/scripts/controllers/shapeshift.js | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/app/scripts/controllers/shapeshift.js b/app/scripts/controllers/shapeshift.js index 17994d2db..b2a1462c2 100644 --- a/app/scripts/controllers/shapeshift.js +++ b/app/scripts/controllers/shapeshift.js @@ -1,5 +1,6 @@ const ObservableStore = require('obs-store') const extend = require('xtend') +const log = require('loglevel') // every three seconds when an incomplete tx is waiting const POLLING_INTERVAL = 3000 @@ -31,7 +32,7 @@ class ShapeshiftController { * @property {string} depositAddress - An address at which to send a crypto deposit, so that eth can be sent to the * user's Metamask account * @property {string} depositType - An abbreviation of the type of crypto currency to be deposited. - * @constant {string} key - The 'shapeshift' key differentiates this from other types of txs in Metamask + * @property {string} key - The 'shapeshift' key differentiates this from other types of txs in Metamask * @property {number} time - The time at which the tx was created * @property {object} response - Initiated as an empty object, which will be replaced by a Response object. @see {@link * https://developer.mozilla.org/en-US/docs/Web/API/Response} @@ -41,38 +42,38 @@ class ShapeshiftController { // PUBLIC METHODS // - /** - * A getter for the shapeShiftTxList property - * - * @returns {array<ShapeShiftTx>} - * - */ + /** + * A getter for the shapeShiftTxList property + * + * @returns {array<ShapeShiftTx>} + * + */ getShapeShiftTxList () { const shapeShiftTxList = this.store.getState().shapeShiftTxList return shapeShiftTxList } - /** - * A getter for all ShapeShiftTx in the shapeShiftTxList that have not successfully completed a deposit. - * - * @returns {array<ShapeShiftTx>} Only includes ShapeShiftTx which has a response property with a status !== complete - * - */ + /** + * A getter for all ShapeShiftTx in the shapeShiftTxList that have not successfully completed a deposit. + * + * @returns {array<ShapeShiftTx>} Only includes ShapeShiftTx which has a response property with a status !== complete + * + */ getPendingTxs () { const txs = this.getShapeShiftTxList() const pending = txs.filter(tx => tx.response && tx.response.status !== 'complete') return pending } - /** - * A poll that exists as long as there are pending transactions. Each call attempts to update the data of any + /** + * A poll that exists as long as there are pending transactions. Each call attempts to update the data of any * pendingTxs, and then calls itself again. If there are no pending txs, the recursive call is not made and * the polling stops. * * this.updateTx is used to attempt the update to the pendingTxs in the ShapeShiftTxList, and that updated data * is saved with saveTx. - * - */ + * + */ pollForUpdates () { const pendingTxs = this.getPendingTxs() @@ -113,13 +114,13 @@ class ShapeshiftController { } } - /** - * Saves an updated to a ShapeShiftTx in the shapeShiftTxList. If the passed ShapeShiftTx is not in the + /** + * Saves an updated to a ShapeShiftTx in the shapeShiftTxList. If the passed ShapeShiftTx is not in the * shapeShiftTxList, nothing happens. - * - * @param {ShapeShiftTx} tx The updated tx to save, if it exists in the current shapeShiftTxList - * - */ + * + * @param {ShapeShiftTx} tx The updated tx to save, if it exists in the current shapeShiftTxList + * + */ saveTx (tx) { const { shapeShiftTxList } = this.store.getState() const index = shapeShiftTxList.indexOf(tx) @@ -129,12 +130,12 @@ class ShapeshiftController { } } - /** - * Removes a ShapeShiftTx from the shapeShiftTxList - * - * @param {ShapeShiftTx} tx The tx to remove - * - */ + /** + * Removes a ShapeShiftTx from the shapeShiftTxList + * + * @param {ShapeShiftTx} tx The tx to remove + * + */ removeShapeShiftTx (tx) { const { shapeShiftTxList } = this.store.getState() const index = shapeShiftTxList.indexOf(index) @@ -144,14 +145,14 @@ class ShapeshiftController { this.updateState({ shapeShiftTxList }) } - /** - * Creates a new ShapeShiftTx, adds it to the shapeShiftTxList, and initiates a new poll for updates of pending txs - * + /** + * Creates a new ShapeShiftTx, adds it to the shapeShiftTxList, and initiates a new poll for updates of pending txs + * * @param {string} depositAddress - An address at which to send a crypto deposit, so that eth can be sent to the * user's Metamask account * @param {string} depositType - An abbreviation of the type of crypto currency to be deposited. - * - */ + * + */ createShapeShiftTx (depositAddress, depositType) { const state = this.store.getState() let { shapeShiftTxList } = state |