Skip to content

Commit

Permalink
fix: streamline variables
Browse files Browse the repository at this point in the history
  • Loading branch information
chaotixkilla committed Feb 6, 2023
1 parent 36efe64 commit 3d46f59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
13 changes: 6 additions & 7 deletions new-lamassu-admin/src/pages/Services/Services.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,15 @@ const Services = () => {
const isServiceDisabled = service =>
!R.isNil(accounts[service.code]) && !accounts[service.code]?.enabled

const enabledServices = R.filter(isServiceEnabled, R.values(schemas))
const disabledServices = R.filter(isServiceDisabled, R.values(schemas))
const usedServices = R.filter(
it => isServiceDisabled(it) || isServiceEnabled(it),
const [enabledServices, limbo] = R.partition(
isServiceEnabled,
R.values(schemas)
)
const unusedServices = R.filter(
it => !isServiceDisabled(it) && !isServiceEnabled(it),
R.values(schemas)
const [disabledServices, unusedServices] = R.partition(
isServiceDisabled,
limbo
)
const usedServices = R.concat(enabledServices, disabledServices)

const enableService = service =>
saveAccount({
Expand Down
28 changes: 15 additions & 13 deletions new-lamassu-admin/src/pages/Services/schemas/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,31 @@ const leadingZerosTest = (value, context) => {

const buildCurrencyOptions = markets => {
return R.map(it => {
const unavailableCryptos = R.difference(ALL_CRYPTOS, markets[it])
const unavailableCryptosFiltered = R.difference(unavailableCryptos, [it]) // As the markets can have stablecoins to trade against other crypto, filter them out, as there can't be pairs such as USDT/USDT
// As the markets can have stablecoins to trade against other crypto, filter them out, as there can't be pairs such as USDT/USDT
const unavailableCryptos = R.difference(
ALL_CRYPTOS,
R.prepend(it, markets[it])
)

const unavailableMarketsStr =
R.length(unavailableCryptosFiltered) > 1
? `${R.join(
', ',
R.slice(0, -1, unavailableCryptosFiltered)
)} and ${R.last(unavailableCryptosFiltered)}`
: unavailableCryptosFiltered[0]

const warningLevel = R.isEmpty(unavailableCryptosFiltered)
R.length(unavailableCryptos) > 1
? `${R.join(', ', R.dropLast(1, unavailableCryptos))} and ${R.last(
unavailableCryptos
)}`
: unavailableCryptos[0]

const warningLevel = R.isEmpty(unavailableCryptos)
? WARNING_LEVELS.CLEAN
: !R.isEmpty(unavailableCryptosFiltered) &&
R.length(unavailableCryptosFiltered) < R.length(ALL_CRYPTOS)
: !R.isEmpty(unavailableCryptos) &&
R.length(unavailableCryptos) < R.length(ALL_CRYPTOS)
? WARNING_LEVELS.PARTIAL
: WARNING_LEVELS.IMPORTANT

return {
code: R.toUpper(it),
display: R.toUpper(it),
warning: warningLevel,
warningMessage: !R.isEmpty(unavailableCryptosFiltered)
warningMessage: !R.isEmpty(unavailableCryptos)
? `No market pairs available for ${unavailableMarketsStr}`
: `All market pairs are available`
}
Expand Down

0 comments on commit 3d46f59

Please sign in to comment.