From 7129d7c0f3ce11839f8b8a576eb1e2c093fb96cc Mon Sep 17 00:00:00 2001 From: bitpshr Date: Thu, 12 Apr 2018 17:06:59 -0400 Subject: Require loglevel singleton in each module that uses it --- app/scripts/controllers/shapeshift.js | 1 + 1 file changed, 1 insertion(+) (limited to 'app/scripts/controllers/shapeshift.js') diff --git a/app/scripts/controllers/shapeshift.js b/app/scripts/controllers/shapeshift.js index 3bbfaa1c5..b38b3812d 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 -- cgit v1.2.3 From 20a075657f9c8133b65ea9cf6e8f1f633bc8a8e6 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 16 Apr 2018 14:38:04 -0230 Subject: Documentation for various controllers and libs --- app/scripts/controllers/shapeshift.js | 74 +++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'app/scripts/controllers/shapeshift.js') diff --git a/app/scripts/controllers/shapeshift.js b/app/scripts/controllers/shapeshift.js index 3bbfaa1c5..b24b010ea 100644 --- a/app/scripts/controllers/shapeshift.js +++ b/app/scripts/controllers/shapeshift.js @@ -6,6 +6,17 @@ const POLLING_INTERVAL = 3000 class ShapeshiftController { + /** + * Controller responsible for managing the list of shapeshift transactions. On construction, it initiates a poll + * that queries a shapeshift.io API for updates to any pending shapeshift transactions + * + * @typedef {Object} ShapeshiftController + * @param {object} opts Overides the defaults for the initial state of this.store + * @property {array} opts.initState initializes the the state of the ShapeshiftController. Can contain an + * shapeShiftTxList array. + * @property {array} shapeShiftTxList An array of ShapeShiftTx objects + * + */ constructor (opts = {}) { const initState = extend({ shapeShiftTxList: [], @@ -14,21 +25,54 @@ class ShapeshiftController { this.pollForUpdates() } + /** + * Represents, and contains data about, a single shapeshift transaction. + * @typedef {Object} ShapeShiftTx + * @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 {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} + */ + // // PUBLIC METHODS // + /** + * A getter for the shapeShiftTxList property + * + * @returns {array} + * + */ 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} 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 + * 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() @@ -45,6 +89,15 @@ class ShapeshiftController { }) } + /** + * Attempts to update a ShapeShiftTx with data from a shapeshift.io API. Both the response and time properties + * can be updated. The response property is updated with every call, but the time property is only updated when + * the response status updates to 'complete'. This will occur once the user makes a deposit as the ShapeShiftTx + * depositAddress + * + * @param {ShapeShiftTx} tx The tx to update + * + */ async updateTx (tx) { try { const url = `https://shapeshift.io/txStat/${tx.depositAddress}` @@ -60,6 +113,13 @@ class ShapeshiftController { } } + /** + * Saves an updated to a ShapeShiftTx in the shapeShiftTxList. If the passed ShapeShiftTx is not in the + * shapeShiftTxList, nothing happens. + * + * @params {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) @@ -69,6 +129,12 @@ class ShapeshiftController { } } + /** + * Removes a ShapeShiftTx from the shapeShiftTxList + * + * @params {ShapeShiftTx} tx The tx to remove + * + */ removeShapeShiftTx (tx) { const { shapeShiftTxList } = this.store.getState() const index = shapeShiftTxList.indexOf(index) @@ -78,6 +144,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 + * + * @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 -- cgit v1.2.3 From 23acddf8f6fe4cb2d23e9b508c9b95f1f50fe32a Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 16 Apr 2018 19:45:27 -0230 Subject: @params -> @param fix --- app/scripts/controllers/shapeshift.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/scripts/controllers/shapeshift.js') diff --git a/app/scripts/controllers/shapeshift.js b/app/scripts/controllers/shapeshift.js index b24b010ea..10753b722 100644 --- a/app/scripts/controllers/shapeshift.js +++ b/app/scripts/controllers/shapeshift.js @@ -117,7 +117,7 @@ class ShapeshiftController { * Saves an updated to a ShapeShiftTx in the shapeShiftTxList. If the passed ShapeShiftTx is not in the * shapeShiftTxList, nothing happens. * - * @params {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) { @@ -132,7 +132,7 @@ class ShapeshiftController { /** * Removes a ShapeShiftTx from the shapeShiftTxList * - * @params {ShapeShiftTx} tx The tx to remove + * @param {ShapeShiftTx} tx The tx to remove * */ removeShapeShiftTx (tx) { -- cgit v1.2.3 From e9ca7199ab9b63ef728fa93f8e98295c3096c553 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 16 Apr 2018 21:23:29 -0230 Subject: Typo fixes, type fixes on the return clauses of the buyEthUrl and getPrefferedLangCode functions. --- app/scripts/controllers/shapeshift.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/controllers/shapeshift.js') diff --git a/app/scripts/controllers/shapeshift.js b/app/scripts/controllers/shapeshift.js index 10753b722..17994d2db 100644 --- a/app/scripts/controllers/shapeshift.js +++ b/app/scripts/controllers/shapeshift.js @@ -11,7 +11,7 @@ class ShapeshiftController { * that queries a shapeshift.io API for updates to any pending shapeshift transactions * * @typedef {Object} ShapeshiftController - * @param {object} opts Overides the defaults for the initial state of this.store + * @param {object} opts Overrides the defaults for the initial state of this.store * @property {array} opts.initState initializes the the state of the ShapeshiftController. Can contain an * shapeShiftTxList array. * @property {array} shapeShiftTxList An array of ShapeShiftTx objects -- cgit v1.2.3 From 6d96b1a2ab0ac09ca8e5948ff11d2924faef4cd7 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 18 Apr 2018 16:08:08 -0230 Subject: Documentation fix: @constant -> @property --- app/scripts/controllers/shapeshift.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/controllers/shapeshift.js') diff --git a/app/scripts/controllers/shapeshift.js b/app/scripts/controllers/shapeshift.js index 17994d2db..d4e734ee9 100644 --- a/app/scripts/controllers/shapeshift.js +++ b/app/scripts/controllers/shapeshift.js @@ -31,7 +31,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} -- cgit v1.2.3 From e80bd230b9bb6ac9ff05d7095f74dd2fd7ebb3af Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 18 Apr 2018 16:11:39 -0230 Subject: NO MIXED TABS AND SPACES --- app/scripts/controllers/shapeshift.js | 66 +++++++++++++++++------------------ 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'app/scripts/controllers/shapeshift.js') diff --git a/app/scripts/controllers/shapeshift.js b/app/scripts/controllers/shapeshift.js index d4e734ee9..203dd99bd 100644 --- a/app/scripts/controllers/shapeshift.js +++ b/app/scripts/controllers/shapeshift.js @@ -41,38 +41,38 @@ class ShapeshiftController { // PUBLIC METHODS // - /** - * A getter for the shapeShiftTxList property - * - * @returns {array} - * - */ + /** + * A getter for the shapeShiftTxList property + * + * @returns {array} + * + */ 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} 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} 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 +113,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 +129,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 +144,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 -- cgit v1.2.3