1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 15:50:28 +01:00

Got ShapeShiftController back to working

This commit is contained in:
Dan Finlay 2017-02-03 21:12:18 -08:00
parent 13ee92909c
commit 4dc71ed57b
2 changed files with 43 additions and 12 deletions

View File

@ -9,8 +9,9 @@ class ShapeshiftController {
constructor (opts = {}) { constructor (opts = {}) {
const initState = extend({ const initState = extend({
shapeShiftTxList: [], shapeShiftTxList: [],
}, opts) }, opts.initState)
this.store = new ObservableStore(initState) this.store = new ObservableStore(initState)
this.pollForUpdates()
} }
// //
@ -19,19 +20,12 @@ class ShapeshiftController {
getShapeShiftTxList () { getShapeShiftTxList () {
const shapeShiftTxList = this.store.getState().shapeShiftTxList const shapeShiftTxList = this.store.getState().shapeShiftTxList
shapeShiftTxList.forEach((tx) => {
if (tx.response.status === 'no_deposits') {
this.updateTx(tx)
}
})
console.dir({shapeShiftTxList})
return shapeShiftTxList return shapeShiftTxList
} }
getPendingTxs () { getPendingTxs () {
const txs = this.getShapeShiftTxList() const txs = this.getShapeShiftTxList()
const pending = txs.filter(tx => tx.response.status !== 'complete') const pending = txs.filter(tx => tx.response && tx.response.status !== 'complete')
return pending return pending
} }
@ -47,7 +41,7 @@ class ShapeshiftController {
})) }))
.then((results) => { .then((results) => {
results.forEach(tx => this.saveTx(tx)) results.forEach(tx => this.saveTx(tx))
setTimeout(this.pollForUpdates.bind(this), POLLING_INTERVAL) this.timeout = setTimeout(this.pollForUpdates.bind(this), POLLING_INTERVAL)
}) })
} }
@ -55,7 +49,9 @@ class ShapeshiftController {
const url = `https://shapeshift.io/txStat/${tx.depositAddress}` const url = `https://shapeshift.io/txStat/${tx.depositAddress}`
return fetch(url) return fetch(url)
.then((response) => { .then((response) => {
tx.response = response.json() return response.json()
}).then((json) => {
tx.response = json
if (tx.response.status === 'complete') { if (tx.response.status === 'complete') {
tx.time = new Date().getTime() tx.time = new Date().getTime()
} }
@ -89,7 +85,6 @@ class ShapeshiftController {
} else { } else {
shapeShiftTxList.push(shapeShiftTx) shapeShiftTxList.push(shapeShiftTx)
} }
console.dir({ shapeShiftTxList })
this.store.updateState({ shapeShiftTxList }) this.store.updateState({ shapeShiftTxList })
this.pollForUpdates() this.pollForUpdates()

View File

@ -0,0 +1,36 @@
const version = 10
/*
This migration breaks out the CurrencyController substate
*/
const merge = require('deep-extend')
module.exports = {
version,
migrate: function (versionedData) {
versionedData.meta.version = version
try {
const state = versionedData.data
const newState = transformState(state)
versionedData.data = newState
} catch (err) {
console.warn(`MetaMask Migration #${version}` + err.stack)
}
return Promise.resolve(versionedData)
},
}
function transformState (state) {
const newState = merge({}, state, {
ShapeShiftController: {
shapeShiftTxList: state.shapeShiftTxList || [],
},
})
delete newState.shapeShiftTxList
return newState
}