Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp 3rd party services screen #1382

Open
wants to merge 1 commit into
base: future-stuff-old-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/lamassu-eth-sweep-to-new-wallet
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ function fetchWallet (settings, cryptoCode) {

const masterSeed = mnemonicHelpers.toEntropyBuffer(mnemonic)
const plugin = configManager.getWalletSettings(cryptoCode, settings.config).wallet
const wallet = ph.load(ph.WALLET, plugin)
const rawAccount = settings.accounts[plugin]
const wallet = ph.load(ph.WALLET, plugin, rawAccount?.enabled)
const account = _.set('seed', computeSeed(masterSeed), rawAccount)
if (_.isFunction(wallet.run)) wallet.run(account)
const operatorId = computeOperatorId(masterSeed)
Expand Down
2 changes: 1 addition & 1 deletion lib/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function sendMessage (settings, rec) {
return Promise.resolve()
.then(() => {
const pluginCode = settings.config.api_service_email
const plugin = ph.load(ph.EMAIL, pluginCode)
const account = settings.accounts[pluginCode]
const plugin = ph.load(ph.EMAIL, pluginCode, account?.enabled)

return plugin.sendMessage(account, rec)
})
Expand Down
4 changes: 2 additions & 2 deletions lib/layer2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ function fetch (settings, cryptoCode) {

if (_.isEmpty(plugin) || plugin === 'no-layer2') return Promise.resolve()

const layer2 = ph.load(ph.LAYER2, plugin)
const account = settings.accounts[plugin]
const layer2 = ph.load(ph.LAYER2, plugin, account?.enabled)

return Promise.resolve({layer2, account})
}
Expand All @@ -34,8 +34,8 @@ function getStatus (settings, tx) {

function cryptoNetwork (settings, cryptoCode) {
const plugin = configManager.getWalletSettings(cryptoCode, settings.config).layer2
const layer2 = ph.load(ph.LAYER2, plugin)
const account = settings.accounts[plugin]
const layer2 = ph.load(ph.LAYER2, plugin, account?.enabled)

if (!layer2.cryptoNetwork) return Promise.resolve(false)
return layer2.cryptoNetwork(account, cryptoCode)
Expand Down
1 change: 1 addition & 0 deletions lib/new-admin/graphql/resolvers/settings.resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const resolvers = {
Mutation: {
saveAccounts: (...[, { accounts }]) => settingsLoader.saveAccounts(accounts),
// resetAccounts: (...[, { schemaVersion }]) => settingsLoader.resetAccounts(schemaVersion),
resetAccount: (...[, { accountId }]) => settingsLoader.resetAccount(accountId),
saveConfig: (...[, { config }]) => settingsLoader.saveConfig(config),
// resetConfig: (...[, { schemaVersion }]) => settingsLoader.resetConfig(schemaVersion),
// migrateConfigAndAccounts: () => settingsLoader.migrate()
Expand Down
1 change: 1 addition & 0 deletions lib/new-admin/graphql/types/settings.type.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const typeDef = gql`
type Mutation {
saveAccounts(accounts: JSONObject): JSONObject @auth
# resetAccounts(schemaVersion: Int): JSONObject @auth
resetAccount(accountId: String): JSONObject @auth
saveConfig(config: JSONObject): JSONObject @auth
# resetConfig(schemaVersion: Int): JSONObject @auth
# migrateConfigAndAccounts: JSONObject @auth
Expand Down
17 changes: 17 additions & 0 deletions lib/new-settings-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function saveAccounts (accounts) {
}).catch(console.error)
})
}

function resetAccounts (schemaVersion) {
return db.none(
accountsSql,
Expand All @@ -76,6 +77,21 @@ function resetAccounts (schemaVersion) {
)
}

function resetAccount (accountId, schemaVersion = NEW_SETTINGS_LOADER_SCHEMA_VERSION) {
return loadAccounts(schemaVersion)
.then(accs => {
return db.none(
accountsSql,
[
'accounts',
{ accounts: _.omit(accountId, accs) },
true,
schemaVersion
]
)
})
}

function loadAccounts (schemaVersion) {
const sql = `select data
from user_config
Expand Down Expand Up @@ -227,6 +243,7 @@ module.exports = {
resetConfig,
saveAccounts,
resetAccounts,
resetAccount,
loadAccounts,
showAccounts,
loadLatest,
Expand Down
4 changes: 3 additions & 1 deletion lib/plugin-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const pluginCodes = {

module.exports = _.assign({load}, pluginCodes)

function load (type, pluginCode) {
function load (type, pluginCode, isEnabled = true) {
if (!_.includes(type, _.values(pluginCodes))) {
throw new Error(`Unallowed plugin type: ${type}`)
}
Expand All @@ -27,5 +27,7 @@ function load (type, pluginCode) {
throw new Error(`Unallowed plugin name: ${pluginCode}`)
}

if (!isEnabled) throw new Error(`Plugin '${pluginCode}' is disabled. Please check your 3rd party services options`)

return require(`./plugins/${type}/${pluginCode}/${pluginCode}`)
}
2 changes: 1 addition & 1 deletion lib/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function getSms (event, phone, content) {

function getPlugin (settings) {
const pluginCode = argv.mockSms ? 'mock-sms' : settings.config.api_service_sms
const plugin = ph.load(ph.SMS, pluginCode)
const account = settings.accounts[pluginCode]
const plugin = ph.load(ph.SMS, pluginCode, account?.enabled)

return { plugin, account }
}
Expand Down
2 changes: 1 addition & 1 deletion lib/wallet-scoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const configManager = require('./new-config-manager')
function loadWalletScoring (settings, cryptoCode) {
const pluginCode = argv.mockScoring ? 'mock-scoring' : 'ciphertrace'
const wallet = cryptoCode ? ph.load(ph.WALLET, configManager.getWalletSettings(cryptoCode, settings.config).wallet) : null
const plugin = ph.load(ph.WALLET_SCORING, pluginCode)
const account = settings.accounts[pluginCode]
const plugin = ph.load(ph.WALLET_SCORING, pluginCode, account?.enabled)

return { plugin, account, wallet }
}
Expand Down
4 changes: 2 additions & 2 deletions lib/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ function fetchWallet (settings, cryptoCode) {
.then(mnemonic => {
const masterSeed = mnemonicHelpers.toEntropyBuffer(mnemonic)
const plugin = configManager.getWalletSettings(cryptoCode, settings.config).wallet
const wallet = ph.load(ph.WALLET, plugin)
const rawAccount = settings.accounts[plugin]
const wallet = ph.load(ph.WALLET, plugin, rawAccount?.enabled)
const account = _.set('seed', computeSeed(masterSeed), rawAccount)
if (_.isFunction(wallet.run)) wallet.run(account)
const operatorId = computeOperatorId(masterSeed)
Expand Down Expand Up @@ -181,8 +181,8 @@ function authorizeZeroConf (settings, tx, machineId) {

if (plugin === 'none') return Promise.resolve(true)

const zeroConf = ph.load(ph.ZERO_CONF, plugin)
const account = settings.accounts[plugin]
const zeroConf = ph.load(ph.ZERO_CONF, plugin, account?.enabled)

return zeroConf.authorize(account, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode, isBitcoindAvailable)
}
Expand Down
16 changes: 16 additions & 0 deletions migrations/1663862352999-add-services-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const _ = require('lodash/fp')
const { saveAccounts, loadLatest } = require('../lib/new-settings-loader')

exports.up = function (next) {
loadLatest()
.then(({ accounts }) => saveAccounts(_.mapValues(it => ({ ...it, enabled: true }), _.cloneDeep(accounts))))
.then(() => next())
.catch(err => {
console.log(err.message)
return next(err)
})
}

exports.down = function (next) {
next()
}
45 changes: 45 additions & 0 deletions new-lamassu-admin/src/components/buttons/LinkDropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Paper, ClickAwayListener } from '@material-ui/core'
import { makeStyles } from '@material-ui/core/styles'
import React, { memo, useState } from 'react'

import { TL2, Label1 } from '../typography'

import Link from './Link'
import styles from './LinkDropdown.styles'

const useStyles = makeStyles(styles)

const LinkDropdown = memo(({ options = [], ...props }) => {
const classes = useStyles({ x: 50, y: 50 })
const [isOpen, setOpen] = useState(false)

const onClick = e => {
if (props.onClick) props.onClick(e)
setOpen(!isOpen)
}

const onItemClick = it => {
setOpen(false)
if (props.onItemClick) props.onItemClick(it)
}

return (
<div className={classes.wrapper}>
<Link {...props} onClick={onClick} />
{isOpen && (
<ClickAwayListener onClickAway={() => setOpen(false)}>
<Paper className={classes.optionList}>
{options.map(it => (
<div className={classes.option} onClick={() => onItemClick(it)}>
<TL2 noMargin>{`${it.name}`}</TL2>
<Label1 noMargin>{`${it.category}`}</Label1>
</div>
))}
</Paper>
</ClickAwayListener>
)}
</div>
)
})

export default LinkDropdown
26 changes: 26 additions & 0 deletions new-lamassu-admin/src/components/buttons/LinkDropdown.styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { subheaderColor } from 'src/styling/variables'

export default {
wrapper: {
display: 'flex',
justifyContent: 'flex-end'
},
optionList: {
display: 'flex',
flexDirection: 'column',
position: 'absolute',
zIndex: 999,
marginTop: 25,
width: 225
},
option: {
padding: '15px 20px',
cursor: 'pointer',
'&:hover': {
backgroundColor: subheaderColor
},
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between'
}
}
2 changes: 2 additions & 0 deletions new-lamassu-admin/src/components/buttons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import FeatureButton from './FeatureButton'
import IDButton from './IDButton'
import IconButton from './IconButton'
import Link from './Link'
import LinkDropdown from './LinkDropdown'
import SimpleButton from './SimpleButton'
import SubpageButton from './SubpageButton'
import SupportLinkButton from './SupportLinkButton'

export {
Button,
Link,
LinkDropdown,
SimpleButton,
ActionButton,
FeatureButton,
Expand Down
19 changes: 19 additions & 0 deletions new-lamassu-admin/src/components/layout/HorizontalSeparator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { makeStyles } from '@material-ui/core'
import React from 'react'

import { Label1 } from '../typography'

import styles from './HorizontalSeparator.styles'

const useStyles = makeStyles(styles)

const HorizontalSeparator = ({ title }) => {
const classes = useStyles()
return (
<div className={classes.separator}>
<Label1>{title}</Label1>
</div>
)
}

export default HorizontalSeparator
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { offColor } from 'src/styling/variables'

export default {
separator: {
display: 'flex',
alignItems: 'center',
textAlign: 'center',
margin: '25px 0px',
'&::before': {
content: "''",
flex: 1,
borderBottom: `1px solid ${offColor}`
},
'&::after': {
content: "''",
flex: 9,
borderBottom: `1px solid ${offColor}`
},
'&:not(:empty)::before': {
marginRight: '1em'
},
'&:not(:empty)::after': {
marginLeft: '1em'
}
}
}
Loading