diff --git a/lib/new-admin/graphql/schema.js b/lib/new-admin/graphql/schema.js index a59fa041..08e0a4f4 100644 --- a/lib/new-admin/graphql/schema.js +++ b/lib/new-admin/graphql/schema.js @@ -196,7 +196,7 @@ const typeDefs = gql` uptime: [ProcessStatus] serverLogs: [ServerLog] transactions: [Transaction] - accounts: [JSONObject] + accounts: JSONObject config: JSONObject } @@ -221,8 +221,7 @@ const typeDefs = gql` setCustomer(customerId: ID!, customerInput: CustomerInput): Customer saveConfig(config: JSONObject): JSONObject createPairingTotem(name: String!): String - saveAccount(account: JSONObject): [JSONObject] - saveAccounts(accounts: [JSONObject]): [JSONObject] + saveAccounts(accounts: JSONObject): JSONObject } ` @@ -259,7 +258,6 @@ const resolvers = { machineSupportLogs: (...[, { deviceId }]) => supportLogs.insert(deviceId), createPairingTotem: (...[, { name }]) => pairing.totem(name), serverSupportLogs: () => serverLogs.insert(), - saveAccount: (...[, { account }]) => settingsLoader.saveAccounts([account]), saveAccounts: (...[, { accounts }]) => settingsLoader.saveAccounts(accounts), setCustomer: (...[, { customerId, customerInput } ]) => customers.updateCustomer(customerId, customerInput), saveConfig: (...[, { config }]) => settingsLoader.saveConfig(config) diff --git a/lib/new-settings-loader.js b/lib/new-settings-loader.js index 7ae6a3ab..e789a436 100644 --- a/lib/new-settings-loader.js +++ b/lib/new-settings-loader.js @@ -9,20 +9,11 @@ low(adapter).then(it => { db = it }) -function replace (array, index, value) { - return array.slice(0, index).concat([value]).concat(array.slice(index + 1)) -} - -function replaceOrAdd (accounts, account) { - const index = _.findIndex(['code', account.code], accounts) - return index !== -1 ? replace(accounts, index, account) : _.concat(accounts)(account) -} - function saveAccounts (accountsToSave) { const currentState = db.getState() || {} - const accounts = currentState.accounts || [] + const accounts = currentState.accounts || {} - const newAccounts = _.reduce(replaceOrAdd)(accounts)(accountsToSave) + const newAccounts = _.assign(accounts)(accountsToSave) const newState = _.set('accounts', newAccounts, currentState) db.setState(newState) diff --git a/new-lamassu-admin/src/pages/Services/Services.js b/new-lamassu-admin/src/pages/Services/Services.js index 62c5af9b..54103118 100644 --- a/new-lamassu-admin/src/pages/Services/Services.js +++ b/new-lamassu-admin/src/pages/Services/Services.js @@ -19,8 +19,8 @@ const GET_INFO = gql` ` const SAVE_ACCOUNT = gql` - mutation Save($account: JSONObject) { - saveAccount(account: $account) + mutation Save($accounts: JSONObject) { + saveAccounts(accounts: $accounts) } ` @@ -45,13 +45,11 @@ const Services = ({ key: SCREEN_KEY }) => { const classes = useStyles() - const accounts = data?.accounts ?? [] - - const getValue = code => R.find(R.propEq('code', code))(accounts) + const accounts = data?.accounts ?? {} const getItems = (code, elements) => { const faceElements = R.filter(R.prop('face'))(elements) - const values = getValue(code) || {} + const values = accounts[code] || {} return R.map(({ display, code, long }) => ({ label: display, value: long ? formatLong(values[code]) : values[code] @@ -81,12 +79,12 @@ const Services = ({ key: SCREEN_KEY }) => { saveAccount({ - variables: { account: { code: editingSchema.code, ...it } } + variables: { accounts: { [editingSchema.code]: it } } }) } elements={editingSchema.elements} validationSchema={editingSchema.validationSchema} - value={getValue(editingSchema.code)} + value={accounts[editingSchema.code]} /> )} diff --git a/new-lamassu-admin/src/pages/Wallet/Wallet.js b/new-lamassu-admin/src/pages/Wallet/Wallet.js index 9285969c..492916ed 100644 --- a/new-lamassu-admin/src/pages/Wallet/Wallet.js +++ b/new-lamassu-admin/src/pages/Wallet/Wallet.js @@ -11,7 +11,7 @@ import Wizard from './Wizard' import { WalletSchema, getElements } from './helper' const SAVE_CONFIG = gql` - mutation Save($config: JSONObject, $accounts: [JSONObject]) { + mutation Save($config: JSONObject, $accounts: JSONObject) { saveConfig(config: $config) saveAccounts(accounts: $accounts) } diff --git a/new-lamassu-admin/src/pages/Wallet/Wizard.js b/new-lamassu-admin/src/pages/Wallet/Wizard.js index 71fddde4..b75efd31 100644 --- a/new-lamassu-admin/src/pages/Wallet/Wizard.js +++ b/new-lamassu-admin/src/pages/Wallet/Wizard.js @@ -18,7 +18,7 @@ const filterConfig = (crypto, type) => const getItems = (accountsConfig, accounts, type, crypto) => { const fConfig = filterConfig(crypto, type)(accountsConfig) - const find = code => R.find(R.propEq('code', code))(accounts) + const find = code => accounts && accounts[code] const [filled, unfilled] = R.partition(({ code }) => { const account = find(code) @@ -35,7 +35,7 @@ const Wizard = ({ coin, onClose, accountsConfig, accounts, save, error }) => { const [{ step, config, accountsToSave }, setState] = useState({ step: 0, config: { active: true }, - accountsToSave: [] + accountsToSave: {} }) const title = `Enable ${coin.display}` @@ -48,9 +48,11 @@ const Wizard = ({ coin, onClose, accountsConfig, accounts, save, error }) => { const getValue = code => R.find(R.propEq('code', code))(accounts) - const onContinue = async (it, it2) => { - const newConfig = R.merge(config, it) - const newAccounts = it2 ? R.concat(accountsToSave, [it2]) : accountsToSave + const onContinue = async (stepConfig, stepAccount) => { + const newConfig = R.merge(config, stepConfig) + const newAccounts = stepAccount + ? R.merge(accountsToSave, stepAccount) + : accountsToSave if (isLastStep) { return save(toNamespace(coin.code, newConfig), newAccounts) diff --git a/new-lamassu-admin/src/pages/Wallet/WizardStep.js b/new-lamassu-admin/src/pages/Wallet/WizardStep.js index 4482764f..ed8dd072 100644 --- a/new-lamassu-admin/src/pages/Wallet/WizardStep.js +++ b/new-lamassu-admin/src/pages/Wallet/WizardStep.js @@ -13,6 +13,7 @@ import schema from 'src/pages/Services/schemas' import { startCase } from 'src/utils/string' import styles from './WizardStep.styles' + const useStyles = makeStyles(styles) const initialState = { @@ -41,7 +42,7 @@ const reducer = (state, action) => { iError: false } case 'error': - return R.merge(state, { iError: true }) + return R.merge(state, { innerError: true }) case 'reset': return initialState default: @@ -61,7 +62,7 @@ const WizardStep = ({ getValue }) => { const classes = useStyles() - const [{ iError, selected, form, isNew }, dispatch] = useReducer( + const [{ innerError, selected, form, isNew }, dispatch] = useReducer( reducer, initialState ) @@ -70,7 +71,7 @@ const WizardStep = ({ dispatch({ type: 'reset' }) }, [step]) - const iContinue = (config, account) => { + const innerContinue = (config, account) => { if (!config || !config[type]) { return dispatch({ type: 'error' }) } @@ -81,7 +82,7 @@ const WizardStep = ({ const displayName = name ?? type const subtitleClass = { [classes.subtitle]: true, - [classes.error]: iError + [classes.error]: innerError } return ( @@ -129,9 +130,7 @@ const WizardStep = ({ {form && ( - iContinue({ [type]: form.code }, R.merge(it, { code: form.code })) - } + save={it => innerContinue({ [type]: form.code }, { [form.code]: it })} elements={schema[form.code].elements} validationSchema={schema[form.code].validationSchema} value={getValue(form.code)} @@ -143,7 +142,7 @@ const WizardStep = ({ {error && Failed to save} diff --git a/new-lamassu-admin/src/utils/config.js b/new-lamassu-admin/src/utils/config.js index 9fca6ab0..f6c8efe8 100644 --- a/new-lamassu-admin/src/utils/config.js +++ b/new-lamassu-admin/src/utils/config.js @@ -8,7 +8,7 @@ const namespaces = { SERVICES: 'services', LOCALE: 'locale', COMMISSIONS: 'commissions', - CONTACT_INFO: 'contactInfo', + CONTACT_INFO: 'operatorInfo', RECEIPT: 'receipt', COIN_ATM_RADAR: 'coinAtmRadar', TERMS_CONDITIONS: 'termsConditions'