fix: make accounts a object
This commit is contained in:
parent
ec73f0b022
commit
6b3db134e7
7 changed files with 26 additions and 38 deletions
|
|
@ -196,7 +196,7 @@ const typeDefs = gql`
|
||||||
uptime: [ProcessStatus]
|
uptime: [ProcessStatus]
|
||||||
serverLogs: [ServerLog]
|
serverLogs: [ServerLog]
|
||||||
transactions: [Transaction]
|
transactions: [Transaction]
|
||||||
accounts: [JSONObject]
|
accounts: JSONObject
|
||||||
config: JSONObject
|
config: JSONObject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -221,8 +221,7 @@ const typeDefs = gql`
|
||||||
setCustomer(customerId: ID!, customerInput: CustomerInput): Customer
|
setCustomer(customerId: ID!, customerInput: CustomerInput): Customer
|
||||||
saveConfig(config: JSONObject): JSONObject
|
saveConfig(config: JSONObject): JSONObject
|
||||||
createPairingTotem(name: String!): String
|
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),
|
machineSupportLogs: (...[, { deviceId }]) => supportLogs.insert(deviceId),
|
||||||
createPairingTotem: (...[, { name }]) => pairing.totem(name),
|
createPairingTotem: (...[, { name }]) => pairing.totem(name),
|
||||||
serverSupportLogs: () => serverLogs.insert(),
|
serverSupportLogs: () => serverLogs.insert(),
|
||||||
saveAccount: (...[, { account }]) => settingsLoader.saveAccounts([account]),
|
|
||||||
saveAccounts: (...[, { accounts }]) => settingsLoader.saveAccounts(accounts),
|
saveAccounts: (...[, { accounts }]) => settingsLoader.saveAccounts(accounts),
|
||||||
setCustomer: (...[, { customerId, customerInput } ]) => customers.updateCustomer(customerId, customerInput),
|
setCustomer: (...[, { customerId, customerInput } ]) => customers.updateCustomer(customerId, customerInput),
|
||||||
saveConfig: (...[, { config }]) => settingsLoader.saveConfig(config)
|
saveConfig: (...[, { config }]) => settingsLoader.saveConfig(config)
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,11 @@ low(adapter).then(it => {
|
||||||
db = 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) {
|
function saveAccounts (accountsToSave) {
|
||||||
const currentState = db.getState() || {}
|
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)
|
const newState = _.set('accounts', newAccounts, currentState)
|
||||||
db.setState(newState)
|
db.setState(newState)
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ const GET_INFO = gql`
|
||||||
`
|
`
|
||||||
|
|
||||||
const SAVE_ACCOUNT = gql`
|
const SAVE_ACCOUNT = gql`
|
||||||
mutation Save($account: JSONObject) {
|
mutation Save($accounts: JSONObject) {
|
||||||
saveAccount(account: $account)
|
saveAccounts(accounts: $accounts)
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
@ -45,13 +45,11 @@ const Services = ({ key: SCREEN_KEY }) => {
|
||||||
|
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
|
|
||||||
const accounts = data?.accounts ?? []
|
const accounts = data?.accounts ?? {}
|
||||||
|
|
||||||
const getValue = code => R.find(R.propEq('code', code))(accounts)
|
|
||||||
|
|
||||||
const getItems = (code, elements) => {
|
const getItems = (code, elements) => {
|
||||||
const faceElements = R.filter(R.prop('face'))(elements)
|
const faceElements = R.filter(R.prop('face'))(elements)
|
||||||
const values = getValue(code) || {}
|
const values = accounts[code] || {}
|
||||||
return R.map(({ display, code, long }) => ({
|
return R.map(({ display, code, long }) => ({
|
||||||
label: display,
|
label: display,
|
||||||
value: long ? formatLong(values[code]) : values[code]
|
value: long ? formatLong(values[code]) : values[code]
|
||||||
|
|
@ -81,12 +79,12 @@ const Services = ({ key: SCREEN_KEY }) => {
|
||||||
<FormRenderer
|
<FormRenderer
|
||||||
save={it =>
|
save={it =>
|
||||||
saveAccount({
|
saveAccount({
|
||||||
variables: { account: { code: editingSchema.code, ...it } }
|
variables: { accounts: { [editingSchema.code]: it } }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
elements={editingSchema.elements}
|
elements={editingSchema.elements}
|
||||||
validationSchema={editingSchema.validationSchema}
|
validationSchema={editingSchema.validationSchema}
|
||||||
value={getValue(editingSchema.code)}
|
value={accounts[editingSchema.code]}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import Wizard from './Wizard'
|
||||||
import { WalletSchema, getElements } from './helper'
|
import { WalletSchema, getElements } from './helper'
|
||||||
|
|
||||||
const SAVE_CONFIG = gql`
|
const SAVE_CONFIG = gql`
|
||||||
mutation Save($config: JSONObject, $accounts: [JSONObject]) {
|
mutation Save($config: JSONObject, $accounts: JSONObject) {
|
||||||
saveConfig(config: $config)
|
saveConfig(config: $config)
|
||||||
saveAccounts(accounts: $accounts)
|
saveAccounts(accounts: $accounts)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ const filterConfig = (crypto, type) =>
|
||||||
|
|
||||||
const getItems = (accountsConfig, accounts, type, crypto) => {
|
const getItems = (accountsConfig, accounts, type, crypto) => {
|
||||||
const fConfig = filterConfig(crypto, type)(accountsConfig)
|
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 [filled, unfilled] = R.partition(({ code }) => {
|
||||||
const account = find(code)
|
const account = find(code)
|
||||||
|
|
@ -35,7 +35,7 @@ const Wizard = ({ coin, onClose, accountsConfig, accounts, save, error }) => {
|
||||||
const [{ step, config, accountsToSave }, setState] = useState({
|
const [{ step, config, accountsToSave }, setState] = useState({
|
||||||
step: 0,
|
step: 0,
|
||||||
config: { active: true },
|
config: { active: true },
|
||||||
accountsToSave: []
|
accountsToSave: {}
|
||||||
})
|
})
|
||||||
|
|
||||||
const title = `Enable ${coin.display}`
|
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 getValue = code => R.find(R.propEq('code', code))(accounts)
|
||||||
|
|
||||||
const onContinue = async (it, it2) => {
|
const onContinue = async (stepConfig, stepAccount) => {
|
||||||
const newConfig = R.merge(config, it)
|
const newConfig = R.merge(config, stepConfig)
|
||||||
const newAccounts = it2 ? R.concat(accountsToSave, [it2]) : accountsToSave
|
const newAccounts = stepAccount
|
||||||
|
? R.merge(accountsToSave, stepAccount)
|
||||||
|
: accountsToSave
|
||||||
|
|
||||||
if (isLastStep) {
|
if (isLastStep) {
|
||||||
return save(toNamespace(coin.code, newConfig), newAccounts)
|
return save(toNamespace(coin.code, newConfig), newAccounts)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import schema from 'src/pages/Services/schemas'
|
||||||
import { startCase } from 'src/utils/string'
|
import { startCase } from 'src/utils/string'
|
||||||
|
|
||||||
import styles from './WizardStep.styles'
|
import styles from './WizardStep.styles'
|
||||||
|
|
||||||
const useStyles = makeStyles(styles)
|
const useStyles = makeStyles(styles)
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
|
|
@ -41,7 +42,7 @@ const reducer = (state, action) => {
|
||||||
iError: false
|
iError: false
|
||||||
}
|
}
|
||||||
case 'error':
|
case 'error':
|
||||||
return R.merge(state, { iError: true })
|
return R.merge(state, { innerError: true })
|
||||||
case 'reset':
|
case 'reset':
|
||||||
return initialState
|
return initialState
|
||||||
default:
|
default:
|
||||||
|
|
@ -61,7 +62,7 @@ const WizardStep = ({
|
||||||
getValue
|
getValue
|
||||||
}) => {
|
}) => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const [{ iError, selected, form, isNew }, dispatch] = useReducer(
|
const [{ innerError, selected, form, isNew }, dispatch] = useReducer(
|
||||||
reducer,
|
reducer,
|
||||||
initialState
|
initialState
|
||||||
)
|
)
|
||||||
|
|
@ -70,7 +71,7 @@ const WizardStep = ({
|
||||||
dispatch({ type: 'reset' })
|
dispatch({ type: 'reset' })
|
||||||
}, [step])
|
}, [step])
|
||||||
|
|
||||||
const iContinue = (config, account) => {
|
const innerContinue = (config, account) => {
|
||||||
if (!config || !config[type]) {
|
if (!config || !config[type]) {
|
||||||
return dispatch({ type: 'error' })
|
return dispatch({ type: 'error' })
|
||||||
}
|
}
|
||||||
|
|
@ -81,7 +82,7 @@ const WizardStep = ({
|
||||||
const displayName = name ?? type
|
const displayName = name ?? type
|
||||||
const subtitleClass = {
|
const subtitleClass = {
|
||||||
[classes.subtitle]: true,
|
[classes.subtitle]: true,
|
||||||
[classes.error]: iError
|
[classes.error]: innerError
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -129,9 +130,7 @@ const WizardStep = ({
|
||||||
</div>
|
</div>
|
||||||
{form && (
|
{form && (
|
||||||
<FormRenderer
|
<FormRenderer
|
||||||
save={it =>
|
save={it => innerContinue({ [type]: form.code }, { [form.code]: it })}
|
||||||
iContinue({ [type]: form.code }, R.merge(it, { code: form.code }))
|
|
||||||
}
|
|
||||||
elements={schema[form.code].elements}
|
elements={schema[form.code].elements}
|
||||||
validationSchema={schema[form.code].validationSchema}
|
validationSchema={schema[form.code].validationSchema}
|
||||||
value={getValue(form.code)}
|
value={getValue(form.code)}
|
||||||
|
|
@ -143,7 +142,7 @@ const WizardStep = ({
|
||||||
{error && <ErrorMessage>Failed to save</ErrorMessage>}
|
{error && <ErrorMessage>Failed to save</ErrorMessage>}
|
||||||
<Button
|
<Button
|
||||||
className={classes.button}
|
className={classes.button}
|
||||||
onClick={() => iContinue({ [type]: selected })}>
|
onClick={() => innerContinue({ [type]: selected })}>
|
||||||
{label}
|
{label}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ const namespaces = {
|
||||||
SERVICES: 'services',
|
SERVICES: 'services',
|
||||||
LOCALE: 'locale',
|
LOCALE: 'locale',
|
||||||
COMMISSIONS: 'commissions',
|
COMMISSIONS: 'commissions',
|
||||||
CONTACT_INFO: 'contactInfo',
|
CONTACT_INFO: 'operatorInfo',
|
||||||
RECEIPT: 'receipt',
|
RECEIPT: 'receipt',
|
||||||
COIN_ATM_RADAR: 'coinAtmRadar',
|
COIN_ATM_RADAR: 'coinAtmRadar',
|
||||||
TERMS_CONDITIONS: 'termsConditions'
|
TERMS_CONDITIONS: 'termsConditions'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue