Feat: validate axios request and enable commissions switch
This commit is contained in:
parent
95a1385a1e
commit
e325d6d2b1
4 changed files with 103 additions and 4 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
const hkdf = require('futoin-hkdf')
|
const hkdf = require('futoin-hkdf')
|
||||||
|
const yup = require("yup")
|
||||||
|
|
||||||
const pify = require('pify')
|
const pify = require('pify')
|
||||||
const fs = pify(require('fs'))
|
const fs = pify(require('fs'))
|
||||||
|
|
@ -114,6 +115,60 @@ function getMachines (rates, settings) {
|
||||||
.then(_.map(_.partial(mapMachine, [rates, settings])))
|
.then(_.map(_.partial(mapMachine, [rates, settings])))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validateData (data) {
|
||||||
|
const schema = yup.object().shape({
|
||||||
|
operatorId: yup.string().required('operatorId not provided'),
|
||||||
|
operator: yup.object().shape({
|
||||||
|
name: yup.string().nullable(),
|
||||||
|
phone: yup.string().nullable(),
|
||||||
|
email: yup.string().email().nullable()
|
||||||
|
}),
|
||||||
|
timestamp: yup.string().required('timestamp not provided'),
|
||||||
|
machines: yup.array().of(yup.object().shape({
|
||||||
|
machineId: yup.string().required('machineId not provided'),
|
||||||
|
address: yup.object().required('address object not provided').shape({
|
||||||
|
streetAddress: yup.string().nullable(),
|
||||||
|
city: yup.string().nullable(),
|
||||||
|
region: yup.string().nullable(),
|
||||||
|
postalCode: yup.string().nullable(),
|
||||||
|
country: yup.string().nullable()
|
||||||
|
}),
|
||||||
|
location: yup.object().required('location object not provided').shape({
|
||||||
|
name: yup.string().nullable(),
|
||||||
|
url: yup.string().nullable(),
|
||||||
|
phone: yup.string().nullable()
|
||||||
|
}),
|
||||||
|
status: yup.string().required('status not provided').oneOf(['online', 'offline']),
|
||||||
|
lastOnline: yup.string().required('date in isostring format not provided'),
|
||||||
|
cashIn: yup.boolean().required('cashIn boolean not defined'),
|
||||||
|
cashOut: yup.boolean().required('cashOut boolean not defined'),
|
||||||
|
manufacturer: yup.string().required('manufacturer not provided'),
|
||||||
|
cashInTxLimit: yup.number().nullable(),
|
||||||
|
cashOutTxLimit: yup.number().nullable(),
|
||||||
|
cashInDailyLimit: yup.number().nullable(),
|
||||||
|
cashOutDailyLimit: yup.number().nullable(),
|
||||||
|
fiatCurrency: yup.string().required('fiatCurrency not provided'),
|
||||||
|
identification: yup.object().shape({
|
||||||
|
isPhone: yup.boolean().required('isPhone boolean not defined'),
|
||||||
|
isPalmVein: yup.boolean().required('isPalmVein boolean not defined'),
|
||||||
|
isPhoto: yup.boolean().required('isPhoto boolean not defined'),
|
||||||
|
isIdDocScan: yup.boolean().required('isIdDocScan boolean not defined'),
|
||||||
|
isFingerprint: yup.boolean().required('isFingerprint boolean not defined')
|
||||||
|
}),
|
||||||
|
coins: yup.array().of(yup.object().shape({
|
||||||
|
cryptoCode: yup.string().required('cryptoCode not provided'),
|
||||||
|
cashInFee: yup.number().nullable(),
|
||||||
|
cashOutFee: yup.number().nullable(),
|
||||||
|
cashInFixedFee: yup.number().nullable(),
|
||||||
|
cashInRate: yup.number().nullable(),
|
||||||
|
cashOutRate: yup.number().nullable(),
|
||||||
|
}))
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
return schema.validate(data)
|
||||||
|
}
|
||||||
|
|
||||||
function sendRadar (data) {
|
function sendRadar (data) {
|
||||||
const url = _.get(['coinAtmRadar', 'url'], options)
|
const url = _.get(['coinAtmRadar', 'url'], options)
|
||||||
|
|
||||||
|
|
@ -130,7 +185,8 @@ function sendRadar (data) {
|
||||||
}
|
}
|
||||||
console.log('%j', data)
|
console.log('%j', data)
|
||||||
|
|
||||||
return axios(config)
|
return validateData(data)
|
||||||
|
.then(() => axios(config))
|
||||||
.then(r => console.log(r.status))
|
.then(r => console.log(r.status))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,12 +86,12 @@ const CoinATMRadar = memo(() => {
|
||||||
label={coinAtmRadarConfig.active ? 'Yes' : 'No'}
|
label={coinAtmRadarConfig.active ? 'Yes' : 'No'}
|
||||||
/>
|
/>
|
||||||
<H4>{'Machine info'}</H4>
|
<H4>{'Machine info'}</H4>
|
||||||
{/* <Row
|
<Row
|
||||||
title={'Commissions'}
|
title={'Commissions'}
|
||||||
disabled={!coinAtmRadarConfig.active}
|
disabled={!coinAtmRadarConfig.active}
|
||||||
checked={coinAtmRadarConfig.commissions}
|
checked={coinAtmRadarConfig.commissions}
|
||||||
save={value => save({ commissions: value })}
|
save={value => save({ commissions: value })}
|
||||||
/> */}
|
/>
|
||||||
<Row
|
<Row
|
||||||
title={'Limits and verification'}
|
title={'Limits and verification'}
|
||||||
disabled={!coinAtmRadarConfig.active}
|
disabled={!coinAtmRadarConfig.active}
|
||||||
|
|
|
||||||
42
package-lock.json
generated
42
package-lock.json
generated
|
|
@ -73,6 +73,21 @@
|
||||||
"js-tokens": "^4.0.0"
|
"js-tokens": "^4.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@babel/runtime": {
|
||||||
|
"version": "7.12.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.12.5.tgz",
|
||||||
|
"integrity": "sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==",
|
||||||
|
"requires": {
|
||||||
|
"regenerator-runtime": "^0.13.4"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"regenerator-runtime": {
|
||||||
|
"version": "0.13.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz",
|
||||||
|
"integrity": "sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"@concordance/react": {
|
"@concordance/react": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@concordance/react/-/react-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@concordance/react/-/react-2.0.0.tgz",
|
||||||
|
|
@ -6338,6 +6353,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
|
||||||
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
|
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
|
||||||
},
|
},
|
||||||
|
"lodash-es": {
|
||||||
|
"version": "4.17.15",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.15.tgz",
|
||||||
|
"integrity": "sha512-rlrc3yU3+JNOpZ9zj5pQtxnx2THmvRykwL4Xlxoa8I9lHBlVbbyPhgyPMioxVZ4NqyxaVVtaJnzsyOidQIhyyQ=="
|
||||||
|
},
|
||||||
"lodash.camelcase": {
|
"lodash.camelcase": {
|
||||||
"version": "4.3.0",
|
"version": "4.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz",
|
||||||
|
|
@ -8082,6 +8102,11 @@
|
||||||
"react-is": "^16.8.1"
|
"react-is": "^16.8.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"property-expr": {
|
||||||
|
"version": "2.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/property-expr/-/property-expr-2.0.4.tgz",
|
||||||
|
"integrity": "sha512-sFPkHQjVKheDNnPvotjQmm3KD3uk1fWKUN7CrpdbwmUx3CrG3QiM8QpTSimvig5vTXmTvjz7+TDvXOI9+4rkcg=="
|
||||||
|
},
|
||||||
"protobufjs": {
|
"protobufjs": {
|
||||||
"version": "6.10.1",
|
"version": "6.10.1",
|
||||||
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.10.1.tgz",
|
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-6.10.1.tgz",
|
||||||
|
|
@ -10343,6 +10368,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/toml/-/toml-2.3.6.tgz",
|
"resolved": "https://registry.npmjs.org/toml/-/toml-2.3.6.tgz",
|
||||||
"integrity": "sha512-gVweAectJU3ebq//Ferr2JUY4WKSDe5N+z0FvjDncLGyHmIDoxgY/2Ie4qfEIDm4IS7OA6Rmdm7pdEEdMcV/xQ=="
|
"integrity": "sha512-gVweAectJU3ebq//Ferr2JUY4WKSDe5N+z0FvjDncLGyHmIDoxgY/2Ie4qfEIDm4IS7OA6Rmdm7pdEEdMcV/xQ=="
|
||||||
},
|
},
|
||||||
|
"toposort": {
|
||||||
|
"version": "2.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/toposort/-/toposort-2.0.2.tgz",
|
||||||
|
"integrity": "sha1-riF2gXXRVZ1IvvNUILL0li8JwzA="
|
||||||
|
},
|
||||||
"touch": {
|
"touch": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz",
|
||||||
|
|
@ -11264,6 +11294,18 @@
|
||||||
"resolved": "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz",
|
||||||
"integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk="
|
"integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk="
|
||||||
},
|
},
|
||||||
|
"yup": {
|
||||||
|
"version": "0.31.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yup/-/yup-0.31.1.tgz",
|
||||||
|
"integrity": "sha512-Lf6648jDYOWR75IlWkVfwesPyW6oj+50NpxlKvsQlpPsB8eI+ndI7b4S1VrwbmeV9hIZDu1MzrlIL4W+gK1jPw==",
|
||||||
|
"requires": {
|
||||||
|
"@babel/runtime": "^7.10.5",
|
||||||
|
"lodash": "^4.17.20",
|
||||||
|
"lodash-es": "^4.17.11",
|
||||||
|
"property-expr": "^2.0.4",
|
||||||
|
"toposort": "^2.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"zen-observable": {
|
"zen-observable": {
|
||||||
"version": "0.8.15",
|
"version": "0.8.15",
|
||||||
"resolved": "https://registry.npmjs.org/zen-observable/-/zen-observable-0.8.15.tgz",
|
"resolved": "https://registry.npmjs.org/zen-observable/-/zen-observable-0.8.15.tgz",
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,8 @@
|
||||||
"winston-transport": "^4.3.0",
|
"winston-transport": "^4.3.0",
|
||||||
"ws": "^3.1.0",
|
"ws": "^3.1.0",
|
||||||
"xml-stream": "^0.4.5",
|
"xml-stream": "^0.4.5",
|
||||||
"xmlrpc": "^1.3.2"
|
"xmlrpc": "^1.3.2",
|
||||||
|
"yup": "^0.31.1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue