Feature/PI-387 use fetch instead of request promise#555
Feature/PI-387 use fetch instead of request promise#555adrian-gierakowski merged 9 commits intodevfrom
Conversation
| const url = `${dvf.config.api}/v1/trading/r/estimatedNextBatchTime?t=${t}` | ||
| try { | ||
| const data = await get(url) | ||
| const data = await get(dvf, url) |
There was a problem hiding this comment.
generic-get prepends dvf.config.api to the 2nd arg so if you want to use it we should remove do:
const url = `/v1/trading/r/estimatedNextBatchTime?t=${t}`client-js/src/lib/dvf/get-generic.js
Line 6 in a51ee78
| try { | ||
| const data = await get(url) | ||
| const data = await get(dvf, url) | ||
| return JSON.parse(data) |
There was a problem hiding this comment.
I did a quick test and get-generic will return parsed data so we should just return data here
| const data = await get(dvf, url) | ||
| return JSON.parse(data) | ||
| } | ||
| catch(e) { |
There was a problem hiding this comment.
the catch here is unnecessary, so pulling all the comment together the function should become:
module.exports = async dvf => {
// avoid browser cache with timestamp as querystring
const t = Date.now()
const url = `/v1/trading/r/estimatedNextBatchTime?t=${t}`
return get(dvf, url)
}| module.exports = async (dvf) => { | ||
| try { | ||
| const res = await get(`${dvf.config.gasApi}/json/ethgasAPI.json?api-key=${dvf.config.gasStationApiKey || ''}`) | ||
| const res = await get(dvf, `${dvf.config.gasApi}/json/ethgasAPI.json?api-key=${dvf.config.gasStationApiKey || ''}`) |
There was a problem hiding this comment.
given the previous comments, we cannot use get-generic here as it prepend dvf.config.api and we need dvf.config.gasApi here, so let's switch to plain request.get from @rhino.fi/dvf-utils
There was a problem hiding this comment.
Do we need to parse the response in the following line then? As it looks like we don't, but I'm not sure
dvf.config.defaultGasPrice = parseInt((JSON.parse(res).average * 1.25 *100000000))
There was a problem hiding this comment.
I guess not, If you remove the JSON.parse I can test to confirm
| const post = require('../lib/dvf/post-generic') | ||
|
|
||
| module.exports = async (dvf, withdrawalData) => { | ||
| const url = dvf.config.api + '/v1/trading/w/fastWithdrawal' |
There was a problem hiding this comment.
as above
| const url = dvf.config.api + '/v1/trading/w/fastWithdrawal' | |
| const url = '/v1/trading/w/fastWithdrawal' |
| @@ -31,7 +31,7 @@ module.exports = async (dvf, token, amount, starkWithdrawal) => { | |||
| //console.log({ data }) | |||
| const url = dvf.config.api + '/v1/trading/w/withdraw' | |||
| const { value, error } = schema.validate(orderData) | ||
| // TODO handle error | ||
| return post(dvf.config.api + '/v1/trading/w/submitOrder', { | ||
| return post(dvf, dvf.config.api + '/v1/trading/w/submitOrder', { |
| ) | ||
|
|
||
| return post(dvf.config.api + '/v1/trading/w/submitOrder', { json }) | ||
| return post(dvf, dvf.config.api + '/v1/trading/w/submitOrder', { json }) |
| const post = require('../lib/dvf/post-generic') | ||
|
|
||
| module.exports = async (dvf, transferData, feeRecipient) => { | ||
| const url = dvf.config.api + '/v1/trading/w/transfer' |
| } | ||
| //console.log({ data }) | ||
| return post(url, { json: data }) | ||
| return post(dvf, url, { json: data }) |
adrian-gierakowski
left a comment
There was a problem hiding this comment.
did some more testing and it turns out that dvf-utils request has slightly different interface then request-promise so src/lib/dvf/post-generic.js shoud be changed to:
const { request } = require('@rhino.fi/dvf-utils')
const _omitBy = require('lodash/omitBy')
const _isNil = require('lodash/isNil')
module.exports = async (dvf, endpoint, json = {}, headers = {}) => {
const url = dvf.config.api + endpoint
const options = {
headers,
// removes null and undefined values
data: _omitBy(json, _isNil)
}
return request.post(url, options)
}…ttps://github.com/rhinofi/client-js into feature/PI-387-use-fetch-instead-of-request-promise
In order to allow the portal to migrate to Vite, we had to patch code in the @rhino.fi/client-js package. This is not ideal and so this PR is to change client-js to allow the portal patches to be removed.
The following files have been updated.
requestfromdvf_utilspost-genericorget-genericfunctions