NO MIXED TABS AND SPACES

feature/default_network_editable
Dan 7 years ago
parent 6d96b1a2ab
commit e80bd230b9
  1. 46
      app/scripts/controllers/currency.js
  2. 162
      app/scripts/controllers/preferences.js
  3. 66
      app/scripts/controllers/shapeshift.js

@ -6,12 +6,12 @@ const POLLING_INTERVAL = 600000
class CurrencyController { class CurrencyController {
/** /**
* Controller responsible for managing data associated with the currently selected currency. * Controller responsible for managing data associated with the currently selected currency.
* *
* @typedef {Object} CurrencyController * @typedef {Object} CurrencyController
* @param {object} opts Overrides 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 CurrencyController. Can contain an * @property {array} opts.initState initializes the the state of the CurrencyController. Can contain an
* currentCurrency, conversionRate and conversionDate properties * currentCurrency, conversionRate and conversionDate properties
* @property {string} currentCurrency A 2-4 character shorthand that describes a specific currency, currently * @property {string} currentCurrency A 2-4 character shorthand that describes a specific currency, currently
* selected by the user * selected by the user
@ -20,8 +20,8 @@ class CurrencyController {
* since midnight of January 1, 1970 * since midnight of January 1, 1970
* @property {number} conversionInterval The id of the interval created by the scheduleConversionInterval method. * @property {number} conversionInterval The id of the interval created by the scheduleConversionInterval method.
* Used to clear an existing interval on subsequent calls of that method. * Used to clear an existing interval on subsequent calls of that method.
* *
*/ */
constructor (opts = {}) { constructor (opts = {}) {
const initState = extend({ const initState = extend({
currentCurrency: 'usd', currentCurrency: 'usd',
@ -35,22 +35,22 @@ class CurrencyController {
// PUBLIC METHODS // PUBLIC METHODS
// //
/** /**
* A getter for the currentCurrency property * A getter for the currentCurrency property
* *
* @returns {string} A 2-4 character shorthand that describes a specific currency, currently selected by the user * @returns {string} A 2-4 character shorthand that describes a specific currency, currently selected by the user
* *
*/ */
getCurrentCurrency () { getCurrentCurrency () {
return this.store.getState().currentCurrency return this.store.getState().currentCurrency
} }
/** /**
* A setter for the currentCurrency property * A setter for the currentCurrency property
* *
* @param {string} currentCurrency The new currency to set as the currentCurrency in the store * @param {string} currentCurrency The new currency to set as the currentCurrency in the store
* *
*/ */
setCurrentCurrency (currentCurrency) { setCurrentCurrency (currentCurrency) {
this.store.updateState({ currentCurrency }) this.store.updateState({ currentCurrency })
} }
@ -117,12 +117,12 @@ class CurrencyController {
} }
} }
/** /**
* Creates a new poll, using setInterval, to periodically call updateConversionRate. The id of the interval is * Creates a new poll, using setInterval, to periodically call updateConversionRate. The id of the interval is
* stored at the controller's conversionInterval property. If it is called and such an id already exists, the * stored at the controller's conversionInterval property. If it is called and such an id already exists, the
* previous interval is clear and a new one is created. * previous interval is clear and a new one is created.
* *
*/ */
scheduleConversionInterval () { scheduleConversionInterval () {
if (this.conversionInterval) { if (this.conversionInterval) {
clearInterval(this.conversionInterval) clearInterval(this.conversionInterval)

@ -4,12 +4,12 @@ const extend = require('xtend')
class PreferencesController { class PreferencesController {
/** /**
* *
* @typedef {Object} PreferencesController * @typedef {Object} PreferencesController
* @param {object} opts Overrides the defaults for the initial state of this.store * @param {object} opts Overrides the defaults for the initial state of this.store
* @property {object} store The an object containing a users preferences, stored in local storage * @property {object} store The an object containing a users preferences, stored in local storage
* @property {array} store.frequentRpcList A list of custom rpcs to provide the user * @property {array} store.frequentRpcList A list of custom rpcs to provide the user
* @property {string} store.currentAccountTab Indicates the selected tab in the ui * @property {string} store.currentAccountTab Indicates the selected tab in the ui
* @property {array} store.tokens The tokens the user wants display in their token lists * @property {array} store.tokens The tokens the user wants display in their token lists
* @property {boolean} store.useBlockie The users preference for blockie identicons within the UI * @property {boolean} store.useBlockie The users preference for blockie identicons within the UI
@ -18,7 +18,7 @@ class PreferencesController {
* @property {string} store.currentLocale The preferred language locale key * @property {string} store.currentLocale The preferred language locale key
* @property {string} store.selectedAddress A hex string that matches the currently selected address in the app * @property {string} store.selectedAddress A hex string that matches the currently selected address in the app
* *
*/ */
constructor (opts = {}) { constructor (opts = {}) {
const initState = extend({ const initState = extend({
frequentRpcList: [], frequentRpcList: [],
@ -32,43 +32,43 @@ class PreferencesController {
} }
// PUBLIC METHODS // PUBLIC METHODS
/** /**
* Setter for the `useBlockie` property * Setter for the `useBlockie` property
* *
* @param {boolean} val Whether or not the user prefers blockie indicators * @param {boolean} val Whether or not the user prefers blockie indicators
* *
*/ */
setUseBlockie (val) { setUseBlockie (val) {
this.store.updateState({ useBlockie: val }) this.store.updateState({ useBlockie: val })
} }
/** /**
* Getter for the `useBlockie` property * Getter for the `useBlockie` property
* *
* @returns {boolean} this.store.useBlockie * @returns {boolean} this.store.useBlockie
* *
*/ */
getUseBlockie () { getUseBlockie () {
return this.store.getState().useBlockie return this.store.getState().useBlockie
} }
/** /**
* Setter for the `currentLocale` property * Setter for the `currentLocale` property
* *
* @param {string} key he preferred language locale key * @param {string} key he preferred language locale key
* *
*/ */
setCurrentLocale (key) { setCurrentLocale (key) {
this.store.updateState({ currentLocale: key }) this.store.updateState({ currentLocale: key })
} }
/** /**
* Setter for the `selectedAddress` property * Setter for the `selectedAddress` property
* *
* @param {string} _address A new hex address for an account * @param {string} _address A new hex address for an account
* @returns {Promise<void>} Promise resolves with undefined * @returns {Promise<void>} Promise resolves with undefined
* *
*/ */
setSelectedAddress (_address) { setSelectedAddress (_address) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const address = normalizeAddress(_address) const address = normalizeAddress(_address)
@ -129,13 +129,13 @@ class PreferencesController {
return Promise.resolve(tokens) return Promise.resolve(tokens)
} }
/** /**
* Removes a specified token from the tokens array. * Removes a specified token from the tokens array.
* *
* @param {string} rawAddress Hex address of the token contract to remove. * @param {string} rawAddress Hex address of the token contract to remove.
* @returns {Promise<array> The new array of AddedToken objects * @returns {Promise<array> The new array of AddedToken objects
* *
*/ */
removeToken (rawAddress) { removeToken (rawAddress) {
const tokens = this.store.getState().tokens const tokens = this.store.getState().tokens
@ -145,23 +145,23 @@ class PreferencesController {
return Promise.resolve(updatedTokens) return Promise.resolve(updatedTokens)
} }
/** /**
* A getter for the `tokens` property * A getter for the `tokens` property
* *
* @returns {array} The current array of AddedToken objects * @returns {array} The current array of AddedToken objects
* *
*/ */
getTokens () { getTokens () {
return this.store.getState().tokens return this.store.getState().tokens
} }
/** /**
* Gets an updated rpc list from this.addToFrequentRpcList() and sets the `frequentRpcList` to this update list. * Gets an updated rpc list from this.addToFrequentRpcList() and sets the `frequentRpcList` to this update list.
* *
* @param {string} _url The the new rpc url to add to the updated list * @param {string} _url The the new rpc url to add to the updated list
* @returns {Promise<void>} Promise resolves with undefined * @returns {Promise<void>} Promise resolves with undefined
* *
*/ */
updateFrequentRpcList (_url) { updateFrequentRpcList (_url) {
return this.addToFrequentRpcList(_url) return this.addToFrequentRpcList(_url)
.then((rpcList) => { .then((rpcList) => {
@ -170,13 +170,13 @@ class PreferencesController {
}) })
} }
/** /**
* Setter for the `currentAccountTab` property * Setter for the `currentAccountTab` property
* *
* @param {string} currentAccountTab Specifies the new tab to be marked as current * @param {string} currentAccountTab Specifies the new tab to be marked as current
* @returns {Promise<void>} Promise resolves with undefined * @returns {Promise<void>} Promise resolves with undefined
* *
*/ */
setCurrentAccountTab (currentAccountTab) { setCurrentAccountTab (currentAccountTab) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.store.updateState({ currentAccountTab }) this.store.updateState({ currentAccountTab })
@ -184,15 +184,15 @@ class PreferencesController {
}) })
} }
/** /**
* Returns an updated rpcList based on the passed url and the current list. * Returns an updated rpcList based on the passed url and the current list.
* The returned list will have a max length of 2. If the _url currently exists it the list, it will be moved to the * The returned list will have a max length of 2. If the _url currently exists it the list, it will be moved to the
* end of the list. The current list is modified and returned as a promise. * end of the list. The current list is modified and returned as a promise.
* *
* @param {string} _url The rpc url to add to the frequentRpcList. * @param {string} _url The rpc url to add to the frequentRpcList.
* @returns {Promise<array>} The updated frequentRpcList. * @returns {Promise<array>} The updated frequentRpcList.
* *
*/ */
addToFrequentRpcList (_url) { addToFrequentRpcList (_url) {
const rpcList = this.getFrequentRpcList() const rpcList = this.getFrequentRpcList()
const index = rpcList.findIndex((element) => { return element === _url }) const index = rpcList.findIndex((element) => { return element === _url })
@ -208,24 +208,24 @@ class PreferencesController {
return Promise.resolve(rpcList) return Promise.resolve(rpcList)
} }
/** /**
* Getter for the `frequentRpcList` property. * Getter for the `frequentRpcList` property.
* *
* @returns {array<string>} An array of one or two rpc urls. * @returns {array<string>} An array of one or two rpc urls.
* *
*/ */
getFrequentRpcList () { getFrequentRpcList () {
return this.store.getState().frequentRpcList return this.store.getState().frequentRpcList
} }
/** /**
* Updates the `featureFlags` property, which is an object. One property within that object will be set to a boolean. * Updates the `featureFlags` property, which is an object. One property within that object will be set to a boolean.
* *
* @param {string} feature A key that corresponds to a UI feature. * @param {string} feature A key that corresponds to a UI feature.
* @param {boolean} activated Indicates whether or not the UI feature should be displayed * @param {boolean} activated Indicates whether or not the UI feature should be displayed
* @returns {Promise<object>} Promises a new object; the updated featureFlags object. * @returns {Promise<object>} Promises a new object; the updated featureFlags object.
* *
*/ */
setFeatureFlag (feature, activated) { setFeatureFlag (feature, activated) {
const currentFeatureFlags = this.store.getState().featureFlags const currentFeatureFlags = this.store.getState().featureFlags
const updatedFeatureFlags = { const updatedFeatureFlags = {
@ -238,13 +238,13 @@ class PreferencesController {
return Promise.resolve(updatedFeatureFlags) return Promise.resolve(updatedFeatureFlags)
} }
/** /**
* A getter for the `featureFlags` property * A getter for the `featureFlags` property
* *
* @returns {object} A key-boolean map, where keys refer to features and booleans to whether the * @returns {object} A key-boolean map, where keys refer to features and booleans to whether the
* user wishes to see that feature * user wishes to see that feature
* *
*/ */
getFeatureFlags () { getFeatureFlags () {
return this.store.getState().featureFlags return this.store.getState().featureFlags
} }

@ -41,38 +41,38 @@ class ShapeshiftController {
// PUBLIC METHODS // PUBLIC METHODS
// //
/** /**
* A getter for the shapeShiftTxList property * A getter for the shapeShiftTxList property
* *
* @returns {array<ShapeShiftTx>} * @returns {array<ShapeShiftTx>}
* *
*/ */
getShapeShiftTxList () { getShapeShiftTxList () {
const shapeShiftTxList = this.store.getState().shapeShiftTxList const shapeShiftTxList = this.store.getState().shapeShiftTxList
return shapeShiftTxList return shapeShiftTxList
} }
/** /**
* A getter for all ShapeShiftTx in the shapeShiftTxList that have not successfully completed a deposit. * 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 * @returns {array<ShapeShiftTx>} Only includes ShapeShiftTx which has a response property with a status !== complete
* *
*/ */
getPendingTxs () { getPendingTxs () {
const txs = this.getShapeShiftTxList() const txs = this.getShapeShiftTxList()
const pending = txs.filter(tx => tx.response && tx.response.status !== 'complete') const pending = txs.filter(tx => tx.response && tx.response.status !== 'complete')
return pending 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 * pendingTxs, and then calls itself again. If there are no pending txs, the recursive call is not made and
* the polling stops. * the polling stops.
* *
* this.updateTx is used to attempt the update to the pendingTxs in the ShapeShiftTxList, and that updated data * this.updateTx is used to attempt the update to the pendingTxs in the ShapeShiftTxList, and that updated data
* is saved with saveTx. * is saved with saveTx.
* *
*/ */
pollForUpdates () { pollForUpdates () {
const pendingTxs = this.getPendingTxs() 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. * 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) { saveTx (tx) {
const { shapeShiftTxList } = this.store.getState() const { shapeShiftTxList } = this.store.getState()
const index = shapeShiftTxList.indexOf(tx) const index = shapeShiftTxList.indexOf(tx)
@ -129,12 +129,12 @@ class ShapeshiftController {
} }
} }
/** /**
* Removes a ShapeShiftTx from the shapeShiftTxList * Removes a ShapeShiftTx from the shapeShiftTxList
* *
* @param {ShapeShiftTx} tx The tx to remove * @param {ShapeShiftTx} tx The tx to remove
* *
*/ */
removeShapeShiftTx (tx) { removeShapeShiftTx (tx) {
const { shapeShiftTxList } = this.store.getState() const { shapeShiftTxList } = this.store.getState()
const index = shapeShiftTxList.indexOf(index) const index = shapeShiftTxList.indexOf(index)
@ -144,14 +144,14 @@ class ShapeshiftController {
this.updateState({ shapeShiftTxList }) 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 * @param {string} depositAddress - An address at which to send a crypto deposit, so that eth can be sent to the
* user's Metamask account * user's Metamask account
* @param {string} depositType - An abbreviation of the type of crypto currency to be deposited. * @param {string} depositType - An abbreviation of the type of crypto currency to be deposited.
* *
*/ */
createShapeShiftTx (depositAddress, depositType) { createShapeShiftTx (depositAddress, depositType) {
const state = this.store.getState() const state = this.store.getState()
let { shapeShiftTxList } = state let { shapeShiftTxList } = state

Loading…
Cancel
Save