fix: keep previous value when closing the configuration popup without
saving on locales screen refactor: renamed enableCoin function to configureCoin fix: keep previous value when closing the configuration popup without saving on wallets screen refactor: renamed enableThirdPartyService function to configureThirdPartyService
This commit is contained in:
parent
2a1aaaaf7e
commit
e09c972547
5 changed files with 44 additions and 21 deletions
|
|
@ -24,7 +24,7 @@ const AutocompleteFormik = ({ options, onChange, ...props }) => {
|
|||
<Autocomplete
|
||||
name={name}
|
||||
onChange={(event, item) => {
|
||||
onChange && onChange(value, item)
|
||||
onChange && onChange(value, item, () => setFieldValue(name, value))
|
||||
setFieldValue(name, item)
|
||||
}}
|
||||
onBlur={innerOnBlur}
|
||||
|
|
|
|||
|
|
@ -99,6 +99,9 @@ const FiatCurrencyChangeAlert = ({ open, close, save }) => {
|
|||
|
||||
const Locales = ({ name: SCREEN_KEY }) => {
|
||||
const [wizard, setWizard] = useState(false)
|
||||
const [cancelCryptoConfiguration, setCancelCryptoConfiguration] = useState(
|
||||
null
|
||||
)
|
||||
const [error, setError] = useState(false)
|
||||
const [isEditingDefault, setEditingDefault] = useState(false)
|
||||
const [isEditingOverrides, setEditingOverrides] = useState(false)
|
||||
|
|
@ -142,11 +145,14 @@ const Locales = ({ name: SCREEN_KEY }) => {
|
|||
return saveConfig({ variables: { config } })
|
||||
}
|
||||
|
||||
const enableCoin = it => {
|
||||
const configureCoin = (it, prev, cancel) => {
|
||||
if (!it) return
|
||||
|
||||
const namespaced = fromNamespace(it)(wallets)
|
||||
if (!WalletSchema.isValidSync(namespaced)) return setWizard(it)
|
||||
if (!WalletSchema.isValidSync(namespaced)) {
|
||||
setCancelCryptoConfiguration(() => () => cancel())
|
||||
setWizard(it)
|
||||
}
|
||||
}
|
||||
|
||||
const onEditingDefault = (it, editing) => setEditingDefault(editing)
|
||||
|
|
@ -170,7 +176,7 @@ const Locales = ({ name: SCREEN_KEY }) => {
|
|||
save={handleSave}
|
||||
validationSchema={LocaleSchema}
|
||||
data={R.of(locale)}
|
||||
elements={mainFields(data, enableCoin)}
|
||||
elements={mainFields(data, configureCoin)}
|
||||
setEditing={onEditingDefault}
|
||||
forceDisable={isEditingOverrides}
|
||||
/>
|
||||
|
|
@ -187,7 +193,7 @@ const Locales = ({ name: SCREEN_KEY }) => {
|
|||
save={saveOverrides}
|
||||
validationSchema={OverridesSchema}
|
||||
data={localeOverrides ?? []}
|
||||
elements={overrides(data, localeOverrides, enableCoin)}
|
||||
elements={overrides(data, localeOverrides, configureCoin)}
|
||||
disableAdd={R.compose(R.isEmpty, R.difference)(
|
||||
data?.machines.map(m => m.deviceId) ?? [],
|
||||
localeOverrides?.map(o => o.machine) ?? []
|
||||
|
|
@ -199,8 +205,14 @@ const Locales = ({ name: SCREEN_KEY }) => {
|
|||
{wizard && (
|
||||
<Wizard
|
||||
coin={R.find(R.propEq('code', wizard))(cryptoCurrencies)}
|
||||
onClose={() => setWizard(false)}
|
||||
save={rawConfig => save(toNamespace(namespaces.WALLETS)(rawConfig))}
|
||||
onClose={() => {
|
||||
cancelCryptoConfiguration && cancelCryptoConfiguration()
|
||||
setWizard(false)
|
||||
}}
|
||||
save={rawConfig => {
|
||||
save(toNamespace(namespaces.WALLETS)(rawConfig))
|
||||
setCancelCryptoConfiguration(null)
|
||||
}}
|
||||
error={error}
|
||||
cryptoCurrencies={cryptoCurrencies}
|
||||
userAccounts={data?.config?.accounts}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ import Autocomplete from 'src/components/inputs/formik/Autocomplete.js'
|
|||
|
||||
const LANGUAGE_SELECTION_LIMIT = 4
|
||||
|
||||
const getFields = (getData, names, enableCoin, auxElements = []) => {
|
||||
const getFields = (getData, names, configureCoin, auxElements = []) => {
|
||||
return R.filter(
|
||||
it => R.includes(it.name, names),
|
||||
allFields(getData, enableCoin, auxElements)
|
||||
allFields(getData, configureCoin, auxElements)
|
||||
)
|
||||
}
|
||||
|
||||
const allFields = (getData, enableCoin, auxElements = []) => {
|
||||
const allFields = (getData, configureCoin, auxElements = []) => {
|
||||
const getView = (data, code, compare) => it => {
|
||||
if (!data) return ''
|
||||
|
||||
|
|
@ -108,29 +108,30 @@ const allFields = (getData, enableCoin, auxElements = []) => {
|
|||
getLabel: R.path(['code']),
|
||||
multiple: true,
|
||||
optionsLimit: null,
|
||||
onChange: (prev, curr) => enableCoin(R.difference(curr, prev)[0])
|
||||
onChange: (prev, curr, cancel) =>
|
||||
configureCoin(R.difference(curr, prev)[0], prev, cancel)
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const mainFields = (auxData, enableCoin) => {
|
||||
const mainFields = (auxData, configureCoin) => {
|
||||
const getData = R.path(R.__, auxData)
|
||||
|
||||
return getFields(
|
||||
getData,
|
||||
['country', 'fiatCurrency', 'languages', 'cryptoCurrencies'],
|
||||
enableCoin
|
||||
configureCoin
|
||||
)
|
||||
}
|
||||
|
||||
const overrides = (auxData, auxElements, enableCoin) => {
|
||||
const overrides = (auxData, auxElements, configureCoin) => {
|
||||
const getData = R.path(R.__, auxData)
|
||||
|
||||
return getFields(
|
||||
getData,
|
||||
['machine', 'country', 'languages', 'cryptoCurrencies'],
|
||||
enableCoin,
|
||||
configureCoin,
|
||||
auxElements
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ const GET_INFO = gql`
|
|||
|
||||
const Wallet = ({ name: SCREEN_KEY }) => {
|
||||
const [editingSchema, setEditingSchema] = useState(null)
|
||||
const [cancelServiceConfiguration, setCancelServiceConfiguration] = useState(
|
||||
null
|
||||
)
|
||||
const [wizard, setWizard] = useState(false)
|
||||
const [error, setError] = useState(false)
|
||||
const { data } = useQuery(GET_INFO)
|
||||
|
|
@ -71,10 +74,13 @@ const Wallet = ({ name: SCREEN_KEY }) => {
|
|||
const cryptoCurrencies = data?.cryptoCurrencies ?? []
|
||||
const accounts = data?.accounts ?? []
|
||||
|
||||
const enableThirdPartyService = it => {
|
||||
const configureThirdPartyService = (it, cancel) => {
|
||||
if (!it) return
|
||||
|
||||
if (!accounts[it]) return setEditingSchema(schemas[it])
|
||||
if (!accounts[it]) {
|
||||
setEditingSchema(schemas[it])
|
||||
setCancelServiceConfiguration(() => () => cancel())
|
||||
}
|
||||
}
|
||||
|
||||
const shouldOverrideEdit = it => {
|
||||
|
|
@ -99,7 +105,7 @@ const Wallet = ({ name: SCREEN_KEY }) => {
|
|||
elements={getElements(
|
||||
cryptoCurrencies,
|
||||
accountsConfig,
|
||||
enableThirdPartyService
|
||||
configureThirdPartyService
|
||||
)}
|
||||
/>
|
||||
{wizard && (
|
||||
|
|
@ -118,7 +124,10 @@ const Wallet = ({ name: SCREEN_KEY }) => {
|
|||
<Modal
|
||||
title={`Edit ${editingSchema.name}`}
|
||||
width={478}
|
||||
handleClose={() => setEditingSchema(null)}
|
||||
handleClose={() => {
|
||||
cancelServiceConfiguration && cancelServiceConfiguration()
|
||||
setEditingSchema(null)
|
||||
}}
|
||||
open={true}>
|
||||
<FormRenderer
|
||||
save={it =>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ const WalletSchema = Yup.object().shape({
|
|||
const getElements = (
|
||||
cryptoCurrencies,
|
||||
accounts,
|
||||
enableThirdPartyService,
|
||||
configureThirdPartyService,
|
||||
wizard = false
|
||||
) => {
|
||||
const widthAdjust = wizard ? 11 : 0
|
||||
|
|
@ -38,7 +38,8 @@ const getElements = (
|
|||
filterCoins(it)(filterOptions(option))
|
||||
)
|
||||
|
||||
const onChange = (prev, curr) => enableThirdPartyService(curr)
|
||||
const onChange = (prev, curr, cancel) =>
|
||||
configureThirdPartyService(curr, cancel)
|
||||
|
||||
return [
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue