Skip to content

Commit

Permalink
fix: remove unnecessary array concat
Browse files Browse the repository at this point in the history
fix: normalize config query and mutation names
  • Loading branch information
chaotixkilla committed Aug 1, 2022
1 parent d4d9d12 commit 736442d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
24 changes: 12 additions & 12 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const { CONFIG_NAMESPACES } = require('./constants')

const {
pickAdvanced,
pickWallet,
pickWallets,
pickOperatorInfo,
pickNotifications,
pickLocale,
pickLocales,
pickCommissions,
pickReceipt,
pickCoinAtmRadar,
Expand All @@ -20,11 +20,11 @@ const {
const { saveConfig, loadLatestConfigOrNone } = require('./new-settings-loader')

// Pick only the fields from the correct namespace to avoid tampering with fields from another namespace without the required permissions to do so
const saveWalletAdvanced = _.flow(pickAdvanced(CONFIG_NAMESPACES.WALLETS), saveConfig)
const saveWallet = _.flow(pickWallet, saveConfig)
const saveAdvancedWallet = _.flow(pickAdvanced(CONFIG_NAMESPACES.WALLETS), saveConfig)
const saveWallets = _.flow(pickWallets, saveConfig)
const saveOperatorInfo = _.flow(pickOperatorInfo, saveConfig)
const saveNotifications = _.flow(pickNotifications, saveConfig)
const saveLocale = _.flow(pickLocale, saveConfig)
const saveLocales = _.flow(pickLocales, saveConfig)
const saveCommissions = _.flow(pickCommissions, saveConfig)
const saveReceipt = _.flow(pickReceipt, saveConfig)
const saveCoinAtmRadar = _.flow(pickCoinAtmRadar, saveConfig)
Expand All @@ -35,11 +35,11 @@ const saveCompliance = _.flow(pickCompliance, saveConfig)
const saveTriggers = _.flow(pickTriggers, saveConfig)
const saveTriggersConfig = _.flow(pickTriggersConfig, saveConfig)

const loadWalletAdvanced = () => loadLatestConfigOrNone().then(pickAdvanced(CONFIG_NAMESPACES.WALLETS))
const loadAdvancedWallet = () => loadLatestConfigOrNone().then(pickAdvanced(CONFIG_NAMESPACES.WALLETS))
const loadWallet = () => loadLatestConfigOrNone().then(pickWallet)
const loadOperatorInfo = () => loadLatestConfigOrNone().then(pickOperatorInfo)
const loadNotifications = () => loadLatestConfigOrNone().then(pickNotifications)
const loadLocale = () => loadLatestConfigOrNone().then(pickLocale)
const loadLocales = () => loadLatestConfigOrNone().then(pickLocales)
const loadCommissions = () => loadLatestConfigOrNone().then(pickCommissions)
const loadReceipt = () => loadLatestConfigOrNone().then(pickReceipt)
const loadCoinAtmRadar = () => loadLatestConfigOrNone().then(pickCoinAtmRadar)
Expand All @@ -51,11 +51,11 @@ const loadTriggers = () => loadLatestConfigOrNone().then(pickTriggers)
const loadTriggersConfig = () => loadLatestConfigOrNone().then(pickTriggersConfig)

module.exports = {
saveWalletAdvanced,
saveWallet,
saveAdvancedWallet,
saveWallets,
saveOperatorInfo,
saveNotifications,
saveLocale,
saveLocales,
saveCommissions,
saveReceipt,
saveCoinAtmRadar,
Expand All @@ -65,11 +65,11 @@ module.exports = {
saveCompliance,
saveTriggers,
saveTriggersConfig,
loadWalletAdvanced,
loadAdvancedWallet,
loadWallet,
loadOperatorInfo,
loadNotifications,
loadLocale,
loadLocales,
loadCommissions,
loadReceipt,
loadCoinAtmRadar,
Expand Down
10 changes: 5 additions & 5 deletions lib/new-admin/graphql/resolvers/settings.resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const configHelper = require('../../../config')
const resolvers = {
Query: {
accounts: () => settingsLoader.showAccounts(),
advancedWalletConfig: () => configHelper.loadWalletAdvanced(),
advancedWalletConfig: () => configHelper.loadAdvancedWallet(),
cashInConfig: () => configHelper.loadCashIn(),
cashOutConfig: () => configHelper.loadCashOut(),
coinAtmRadarConfig: () => configHelper.loadCoinAtmRadar(),
commissionsConfig: () => configHelper.loadCommissions(),
complianceConfig: () => configHelper.loadCompliance(),
localesConfig: () => configHelper.loadLocale(),
localesConfig: () => configHelper.loadLocales(),
notificationsConfig: () => configHelper.loadNotifications(),
operatorInfoConfig: () => configHelper.loadOperatorInfo(),
receiptConfig: () => configHelper.loadReceipt(),
Expand All @@ -26,15 +26,15 @@ const resolvers = {
saveCoinAtmRadar: (...[, { config }]) => settingsLoader.saveCoinAtmRadar(config),
saveCommissions: (...[, { config }]) => configHelper.saveCommissions(config),
saveCompliance: (...[, { config }]) => configHelper.saveCompliance(config),
saveLocales: (...[, { config }]) => configHelper.saveLocale(config),
saveLocales: (...[, { config }]) => configHelper.saveLocales(config),
saveNotifications: (...[, { config }]) => configHelper.saveNotifications(config),
saveOperatorInfo: (...[, { config }]) => configHelper.saveOperatorInfo(config),
saveReceipt: (...[, { config }]) => configHelper.saveReceipt(config),
saveTermsAndConditions: (...[, { config }]) => configHelper.saveTermsAndConditions(config),
saveTriggers: (...[, { config }]) => configHelper.saveTriggers(config),
saveTriggersConfig: (...[, { config }]) => configHelper.saveTriggersConfig(config),
saveWalletAdvanced: (...[, { config }]) => configHelper.saveWalletAdvanced(config),
saveWallets: (...[, { config }]) => configHelper.saveWallet(config)
saveAdvancedWallet: (...[, { config }]) => configHelper.saveAdvancedWallet(config),
saveWallets: (...[, { config }]) => configHelper.saveWallets(config)
// resetAccounts: (...[, { schemaVersion }]) => settingsLoader.resetAccounts(schemaVersion),
// resetConfig: (...[, { schemaVersion }]) => settingsLoader.resetConfig(schemaVersion),
// migrateConfigAndAccounts: () => settingsLoader.migrate()
Expand Down
2 changes: 1 addition & 1 deletion lib/new-admin/graphql/types/settings.type.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const typeDef = gql`
saveTermsAndConditions(config: JSONObject): JSONObject @auth(permissions: ["termsAndConditions:update"])
saveTriggers(config: JSONObject): JSONObject @auth(permissions: ["triggers:update"])
saveTriggersConfig(config: JSONObject): JSONObject @auth(permissions: ["triggersConfig:update"])
saveWalletAdvanced(config: JSONObject): JSONObject @auth(permissions: ["advancedWallet:update"])
saveAdvancedWallet(config: JSONObject): JSONObject @auth(permissions: ["advancedWallet:update"])
saveWallets(config: JSONObject): JSONObject @auth(permissions: ["wallets:update"])
# resetAccounts(schemaVersion: Int): JSONObject @auth(permissions: ["config:update"])
# resetConfig(schemaVersion: Int): JSONObject @auth(permissions: ["config:update"])
Expand Down
8 changes: 4 additions & 4 deletions lib/new-config-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ const getReceipt = fromNamespace(CONFIG_NAMESPACES.RECEIPT)
const getCompliance = fromNamespace(CONFIG_NAMESPACES.COMPLIANCE)

const pickAdvanced = nameSpace => selectFromNamespace(`${nameSpace}_${CONFIG_NAMESPACES.ADVANCED}`)
const pickWallet = selectFromNamespace(CONFIG_NAMESPACES.WALLETS)
const pickWallets = selectFromNamespace(CONFIG_NAMESPACES.WALLETS)
const pickOperatorInfo = selectFromNamespace(CONFIG_NAMESPACES.OPERATOR_INFO)
const pickNotifications = selectFromNamespace(CONFIG_NAMESPACES.NOTIFICATIONS)
const pickLocale = selectFromNamespace(CONFIG_NAMESPACES.LOCALE)
const pickLocales = selectFromNamespace(CONFIG_NAMESPACES.LOCALE)
const pickCommissions = selectFromNamespace(CONFIG_NAMESPACES.COMMISSIONS)
const pickReceipt = selectFromNamespace(CONFIG_NAMESPACES.RECEIPT)
const pickCoinAtmRadar = selectFromNamespace(CONFIG_NAMESPACES.COIN_ATM_RADAR)
Expand Down Expand Up @@ -183,10 +183,10 @@ module.exports = {
getCryptoUnits,
setTermsConditions,
pickAdvanced,
pickWallet,
pickWallets,
pickOperatorInfo,
pickNotifications,
pickLocale,
pickLocales,
pickCommissions,
pickReceipt,
pickCoinAtmRadar,
Expand Down
2 changes: 1 addition & 1 deletion migrations/1658351820982-role-based-access-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ exports.up = function (next) {
role_id UUID NOT NULL REFERENCES user_roles(id),
permission_id INT NOT NULL REFERENCES system_permissions(id)
)`,
..._.map(it => `INSERT INTO system_permissions (name, description) VALUES ('${it.name}', '${it.description}')`, _.uniq(_.concat(userPermissions, superuserPermissions))),
..._.map(it => `INSERT INTO system_permissions (name, description) VALUES ('${it.name}', '${it.description}')`, _.uniq(superuserPermissions)),
`INSERT INTO user_roles (id, name) VALUES ('${userRoleId}', 'user')`,
`INSERT INTO user_roles (id, name) VALUES ('${superuserRoleId}', 'superuser')`,
`ALTER TABLE users ADD COLUMN role_id UUID REFERENCES user_roles(id)`,
Expand Down
10 changes: 5 additions & 5 deletions new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
OverridesSchema
} from './helper'

const SAVE_WALLET_ADVANCED = gql`
const SAVE_ADVANCED_WALLET = gql`
mutation Save($config: JSONObject) {
saveWalletAdvanced(config: $config)
saveAdvancedWallet(config: $config)
}
`

Expand All @@ -41,20 +41,20 @@ const AdvancedWallet = () => {
const [isEditingDefault, setEditingDefault] = useState(false)
const [isEditingOverrides, setEditingOverrides] = useState(false)

const [saveWalletAdvanced, { error }] = useMutation(SAVE_WALLET_ADVANCED, {
const [saveAdvancedWallet, { error }] = useMutation(SAVE_ADVANCED_WALLET, {
refetchQueries: () => ['getData']
})

const save = rawConfig => {
const config = toNamespace(SCREEN_KEY)(
toNamespace(ADVANCED)(rawConfig.wallets[0])
)
return saveWalletAdvanced({ variables: { config } })
return saveAdvancedWallet({ variables: { config } })
}

const saveOverrides = rawConfig => {
const config = toNamespace(SCREEN_KEY)(toNamespace(ADVANCED)(rawConfig))
return saveWalletAdvanced({ variables: { config } })
return saveAdvancedWallet({ variables: { config } })
}

const onEditingDefault = (it, editing) => setEditingDefault(editing)
Expand Down

0 comments on commit 736442d

Please sign in to comment.