Skip to content

Commit

Permalink
fix(SFOX): move fetch with length to buy/sell modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Welber committed May 29, 2018
1 parent 6460e84 commit 87fd0a7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 35 deletions.
14 changes: 1 addition & 13 deletions packages/blockchain-wallet-v4/src/network/api/sfox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,8 @@ export default ({ url }) => {
}).then(res => {
return res
})
const fetchTradesWithLength = (token, num, apiKey, prod) => {
let headers = {}
headers['Authorization'] = 'Bearer ' + token
headers['X-SFOX-PARTNER-ID'] = apiKey
headers['content-type'] = 'application/json'
console.log('fetchTradesWithLength running')
return fetch(`https://api${prod ? '' : '.staging'}.sfox.com/v2/partner/blockchain/transaction?page_size=${num}`, {
method: 'GET',
headers: headers
}).then(res => res.json())
}

return {
uploadVerificationDocument,
fetchTradesWithLength
uploadVerificationDocument
}
}
24 changes: 2 additions & 22 deletions packages/blockchain-wallet-v4/src/redux/data/sfox/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,10 @@ export default ({ api, options }) => {
try {
yield put(A.fetchTradesLoading())

// get number of trades from metadata
const kvTrades = yield select(buySellSelectors.getSfoxTrades)
const numberOfTrades = kvTrades.length

// get args for api call
const meta = yield select(buySellSelectors.getMetadata)
let token = meta.data.value.sfox.account_token
const state = yield select()
const options = state.walletOptionsPath.data
const configPath = (partner, key) => ['platforms', 'web', partner, 'config', key]
let apiKey = path(configPath('sfox', 'apiKey'), options)
let production = path(configPath('sfox', 'production'), options)

// fetch trades with length
const trades = yield call(api.fetchTradesWithLength, token, numberOfTrades, apiKey, production)

// delegate to create trade class
const delegate = sfox._delegate

let allTrades = trades.map(trade => {
return new sfox._TradeClass(trade, api, delegate)
})

yield put(A.fetchTradesSuccess(allTrades))
const trades = yield apply(sfox, sfox.getTrades, [numberOfTrades])
yield put(A.fetchTradesSuccess(trades))
} catch (e) {
yield put(A.fetchTradesFailure(e))
}
Expand Down

0 comments on commit 87fd0a7

Please sign in to comment.