feat: advanced wallet settings
This commit is contained in:
parent
b99f98982b
commit
9ec7f6f296
6 changed files with 193 additions and 42 deletions
|
|
@ -113,6 +113,10 @@ const getCryptosFromWalletNamespace = config => {
|
||||||
|
|
||||||
const getCashInSettings = config => fromNamespace(namespaces.CASH_IN)(config)
|
const getCashInSettings = config => fromNamespace(namespaces.CASH_IN)(config)
|
||||||
|
|
||||||
|
const getCryptoUnits = (crypto, config) => {
|
||||||
|
return getWalletSettings(crypto, config).cryptoUnits
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getWalletSettings,
|
getWalletSettings,
|
||||||
getCashInSettings,
|
getCashInSettings,
|
||||||
|
|
@ -129,5 +133,6 @@ module.exports = {
|
||||||
getAllCryptoCurrencies,
|
getAllCryptoCurrencies,
|
||||||
getTriggers,
|
getTriggers,
|
||||||
getCashOut,
|
getCashOut,
|
||||||
getCryptosFromWalletNamespace
|
getCryptosFromWalletNamespace,
|
||||||
|
getCryptoUnits
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,7 @@ function plugins (settings, deviceId) {
|
||||||
const cashInCommission = new BN(commissions.cashIn)
|
const cashInCommission = new BN(commissions.cashIn)
|
||||||
const cashOutCommission = _.isNumber(commissions.cashOut) ? new BN(commissions.cashOut) : null
|
const cashOutCommission = _.isNumber(commissions.cashOut) ? new BN(commissions.cashOut) : null
|
||||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||||
|
const cryptoUnits = configManager.getCryptoUnits(cryptoCode, settings.config)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cryptoCode,
|
cryptoCode,
|
||||||
|
|
@ -213,13 +214,13 @@ function plugins (settings, deviceId) {
|
||||||
cashInFee,
|
cashInFee,
|
||||||
cashInCommission,
|
cashInCommission,
|
||||||
cashOutCommission,
|
cashOutCommission,
|
||||||
cryptoNetwork
|
cryptoNetwork,
|
||||||
|
cryptoUnits
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pollQueries (serialNumber, deviceTime, deviceRec, machineVersion, machineModel) {
|
function pollQueries (serialNumber, deviceTime, deviceRec, machineVersion, machineModel) {
|
||||||
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
||||||
|
|
||||||
const fiatCode = localeConfig.fiatCurrency
|
const fiatCode = localeConfig.fiatCurrency
|
||||||
const cryptoCodes = localeConfig.cryptoCurrencies
|
const cryptoCodes = localeConfig.cryptoCurrencies
|
||||||
const timezone = localeConfig.timezone.split(':')
|
const timezone = localeConfig.timezone.split(':')
|
||||||
|
|
|
||||||
22
migrations/1623975493095-add-crypto-units-to-config.js
Normal file
22
migrations/1623975493095-add-crypto-units-to-config.js
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
const { saveConfig } = require('../lib/new-settings-loader')
|
||||||
|
|
||||||
|
exports.up = function (next) {
|
||||||
|
const cryptoUnits = {
|
||||||
|
wallets_BTC_cryptoUnits: 'mUnits',
|
||||||
|
wallets_ETH_cryptoUnits: 'mUnits',
|
||||||
|
wallets_LTC_cryptoUnits: 'mUnits',
|
||||||
|
wallets_ZEC_cryptoUnits: 'mUnits',
|
||||||
|
wallets_BCH_cryptoUnits: 'mUnits'
|
||||||
|
}
|
||||||
|
|
||||||
|
return saveConfig(cryptoUnits)
|
||||||
|
.then(() => next())
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err.message)
|
||||||
|
return next(err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.down = function (next) {
|
||||||
|
next()
|
||||||
|
}
|
||||||
61
new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js
Normal file
61
new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
import { useQuery, useMutation } from '@apollo/react-hooks'
|
||||||
|
import gql from 'graphql-tag'
|
||||||
|
import * as R from 'ramda'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import { NamespacedTable as EditableTable } from 'src/components/editableTable'
|
||||||
|
import { fromNamespace, toNamespace, namespaces } from 'src/utils/config'
|
||||||
|
|
||||||
|
import { AdvancedWalletSchema, getAdvancedWalletElements } from './helper'
|
||||||
|
|
||||||
|
const SAVE_CONFIG = gql`
|
||||||
|
mutation Save($config: JSONObject, $accounts: JSONObject) {
|
||||||
|
saveConfig(config: $config)
|
||||||
|
saveAccounts(accounts: $accounts)
|
||||||
|
}
|
||||||
|
`
|
||||||
|
const GET_INFO = gql`
|
||||||
|
query getData {
|
||||||
|
config
|
||||||
|
accounts
|
||||||
|
cryptoCurrencies {
|
||||||
|
code
|
||||||
|
display
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const AdvancedWallet = () => {
|
||||||
|
const SCREEN_KEY = namespaces.WALLETS
|
||||||
|
const { data } = useQuery(GET_INFO)
|
||||||
|
|
||||||
|
const [saveConfig, { error }] = useMutation(SAVE_CONFIG, {
|
||||||
|
refetchQueries: () => ['getData']
|
||||||
|
})
|
||||||
|
|
||||||
|
const save = (rawConfig, accounts) => {
|
||||||
|
const config = toNamespace(SCREEN_KEY)(rawConfig)
|
||||||
|
return saveConfig({ variables: { config, accounts } })
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = data?.config && fromNamespace(SCREEN_KEY)(data.config)
|
||||||
|
const cryptoCurrencies = data?.cryptoCurrencies ?? []
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<EditableTable
|
||||||
|
name="advancedWallet"
|
||||||
|
namespaces={R.map(R.path(['code']))(cryptoCurrencies)}
|
||||||
|
data={config}
|
||||||
|
error={error?.message}
|
||||||
|
enableEdit
|
||||||
|
editWidth={174}
|
||||||
|
save={save}
|
||||||
|
validationSchema={AdvancedWalletSchema}
|
||||||
|
elements={getAdvancedWalletElements(cryptoCurrencies)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AdvancedWallet
|
||||||
|
|
@ -8,8 +8,11 @@ import { NamespacedTable as EditableTable } from 'src/components/editableTable'
|
||||||
import TitleSection from 'src/components/layout/TitleSection'
|
import TitleSection from 'src/components/layout/TitleSection'
|
||||||
import FormRenderer from 'src/pages/Services/FormRenderer'
|
import FormRenderer from 'src/pages/Services/FormRenderer'
|
||||||
import schemas from 'src/pages/Services/schemas'
|
import schemas from 'src/pages/Services/schemas'
|
||||||
|
import { ReactComponent as ReverseSettingsIcon } from 'src/styling/icons/circle buttons/settings/white.svg'
|
||||||
|
import { ReactComponent as SettingsIcon } from 'src/styling/icons/circle buttons/settings/zodiac.svg'
|
||||||
import { fromNamespace, toNamespace } from 'src/utils/config'
|
import { fromNamespace, toNamespace } from 'src/utils/config'
|
||||||
|
|
||||||
|
import AdvancedWallet from './AdvancedWallet'
|
||||||
import Wizard from './Wizard'
|
import Wizard from './Wizard'
|
||||||
import { WalletSchema, getElements } from './helper'
|
import { WalletSchema, getElements } from './helper'
|
||||||
|
|
||||||
|
|
@ -48,6 +51,7 @@ const Wallet = ({ name: SCREEN_KEY }) => {
|
||||||
const [editingSchema, setEditingSchema] = useState(null)
|
const [editingSchema, setEditingSchema] = useState(null)
|
||||||
const [onChangeFunction, setOnChangeFunction] = useState(null)
|
const [onChangeFunction, setOnChangeFunction] = useState(null)
|
||||||
const [wizard, setWizard] = useState(false)
|
const [wizard, setWizard] = useState(false)
|
||||||
|
const [advancedSettings, setAdvancedSettings] = useState(false)
|
||||||
const { data } = useQuery(GET_INFO)
|
const { data } = useQuery(GET_INFO)
|
||||||
|
|
||||||
const [saveConfig, { error }] = useMutation(SAVE_CONFIG, {
|
const [saveConfig, { error }] = useMutation(SAVE_CONFIG, {
|
||||||
|
|
@ -99,7 +103,17 @@ const Wallet = ({ name: SCREEN_KEY }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<TitleSection title="Wallet Settings" />
|
<TitleSection
|
||||||
|
title="Wallet Settings"
|
||||||
|
button={{
|
||||||
|
text: 'Advanced settings',
|
||||||
|
icon: SettingsIcon,
|
||||||
|
inverseIcon: ReverseSettingsIcon,
|
||||||
|
toggle: setAdvancedSettings
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{!advancedSettings && (
|
||||||
|
<>
|
||||||
<EditableTable
|
<EditableTable
|
||||||
name="test"
|
name="test"
|
||||||
namespaces={R.map(R.path(['code']))(cryptoCurrencies)}
|
namespaces={R.map(R.path(['code']))(cryptoCurrencies)}
|
||||||
|
|
@ -141,6 +155,9 @@ const Wallet = ({ name: SCREEN_KEY }) => {
|
||||||
</Modal>
|
</Modal>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
)}
|
||||||
|
{advancedSettings && <AdvancedWallet></AdvancedWallet>}
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,45 @@ const WalletSchema = Yup.object().shape({
|
||||||
.transform(transformNumber)
|
.transform(transformNumber)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const AdvancedWalletSchema = Yup.object().shape({
|
||||||
|
cryptoUnits: Yup.string().required()
|
||||||
|
})
|
||||||
|
|
||||||
|
const getAdvancedWalletElements = (cryptoCurrencies, config) => {
|
||||||
|
const viewCryptoCurrency = it =>
|
||||||
|
R.compose(
|
||||||
|
R.prop(['display']),
|
||||||
|
R.find(R.propEq('code', it))
|
||||||
|
)(cryptoCurrencies)
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
name: 'id',
|
||||||
|
header: 'Cryptocurrency',
|
||||||
|
width: 180,
|
||||||
|
view: viewCryptoCurrency,
|
||||||
|
size: 'sm',
|
||||||
|
editable: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'cryptoUnits',
|
||||||
|
size: 'sm',
|
||||||
|
stripe: true,
|
||||||
|
view: it => it,
|
||||||
|
width: 190,
|
||||||
|
input: Autocomplete,
|
||||||
|
inputProps: {
|
||||||
|
options: [
|
||||||
|
{ code: 'mUnits', display: 'mUnits' },
|
||||||
|
{ code: 'fUnits', display: 'fUnits' }
|
||||||
|
],
|
||||||
|
valueProp: 'code',
|
||||||
|
labelProp: 'display'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
const getElements = (cryptoCurrencies, accounts, onChange, wizard = false) => {
|
const getElements = (cryptoCurrencies, accounts, onChange, wizard = false) => {
|
||||||
const widthAdjust = wizard ? 11 : 0
|
const widthAdjust = wizard ? 11 : 0
|
||||||
const viewCryptoCurrency = it => {
|
const viewCryptoCurrency = it => {
|
||||||
|
|
@ -133,4 +172,10 @@ const getElements = (cryptoCurrencies, accounts, onChange, wizard = false) => {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
export { WalletSchema, getElements, filterClass }
|
export {
|
||||||
|
WalletSchema,
|
||||||
|
AdvancedWalletSchema,
|
||||||
|
getElements,
|
||||||
|
filterClass,
|
||||||
|
getAdvancedWalletElements
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue