feat: reject address reuse
This commit is contained in:
parent
f2080c32e9
commit
f6547341f1
5 changed files with 69 additions and 27 deletions
|
|
@ -7,7 +7,7 @@ const db = require('../db')
|
|||
const plugins = require('../plugins')
|
||||
const logger = require('../logger')
|
||||
const settingsLoader = require('../new-settings-loader')
|
||||
// const configManager = require('../new-config-manager')
|
||||
const configManager = require('../new-config-manager')
|
||||
|
||||
const cashInAtomic = require('./cash-in-atomic')
|
||||
const cashInLow = require('./cash-in-low')
|
||||
|
|
@ -26,9 +26,7 @@ function post (machineTx, pi) {
|
|||
|
||||
return Promise.all([settingsLoader.loadLatest(), checkForBlacklisted(updatedTx)])
|
||||
.then(([{ config }, blacklistItems]) => {
|
||||
// TODO new-admin: addressReuse doesnt exist
|
||||
// const rejectAddressReuseActive = configManager.unscoped(config).rejectAddressReuseActive
|
||||
const rejectAddressReuseActive = false
|
||||
const rejectAddressReuseActive = configManager.getCompliance(config).rejectAddressReuse
|
||||
|
||||
if (_.some(it => it.created_by_operator === true)(blacklistItems)) {
|
||||
blacklisted = true
|
||||
|
|
@ -125,9 +123,8 @@ function postProcess (r, pi, isBlacklisted, addressReuse) {
|
|||
})
|
||||
.then(sendRec => {
|
||||
settingsLoader.loadLatest().then(it => {
|
||||
// TODO new-admin: addressReuse doesnt exist
|
||||
// const config = configManager.unscoped(it.config)
|
||||
if (false) {
|
||||
const rejectAddressReuseActive = configManager.getCompliance(it.config).rejectAddressReuse
|
||||
if (rejectAddressReuseActive) {
|
||||
blacklist.addToUsedAddresses(r.tx.toAddress, r.tx.cryptoCode)
|
||||
.catch(err => logger.error('Failure adding to addressReuse', err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ const namespaces = {
|
|||
RECEIPT: 'receipt',
|
||||
COIN_ATM_RADAR: 'coinAtmRadar',
|
||||
TERMS_CONDITIONS: 'termsConditions',
|
||||
CASH_OUT: 'cashOut'
|
||||
CASH_OUT: 'cashOut',
|
||||
COMPLIANCE: 'compliance'
|
||||
}
|
||||
|
||||
const stripl = _.curry((q, str) => _.startsWith(q, str) ? str.slice(q.length) : str)
|
||||
|
|
@ -48,6 +49,7 @@ const getOperatorInfo = fromNamespace(namespaces.OPERATOR_INFO)
|
|||
const getCoinAtmRadar = fromNamespace(namespaces.COIN_ATM_RADAR)
|
||||
const getTermsConditions = fromNamespace(namespaces.TERMS_CONDITIONS)
|
||||
const getReceipt = fromNamespace(namespaces.RECEIPT)
|
||||
const getCompliance = fromNamespace(namespaces.COMPLIANCE)
|
||||
|
||||
const getAllCryptoCurrencies = (config) => {
|
||||
const locale = fromNamespace(namespaces.LOCALE)(config)
|
||||
|
|
@ -85,6 +87,7 @@ module.exports = {
|
|||
getGlobalLocale,
|
||||
getCommissions,
|
||||
getReceipt,
|
||||
getCompliance,
|
||||
getCoinAtmRadar,
|
||||
getTermsConditions,
|
||||
getAllCryptoCurrencies,
|
||||
|
|
|
|||
|
|
@ -124,6 +124,18 @@ function plugins (settings, deviceId) {
|
|||
]
|
||||
}
|
||||
|
||||
function getLcmOrBigx2 (n1, n2) {
|
||||
let big = Math.max(n1, n2);
|
||||
let small = Math.min(n1, n2);
|
||||
|
||||
let i = big * 2;
|
||||
while(i % small !== 0){
|
||||
i += lar;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
function buildAvailableCassettes (excludeTxId) {
|
||||
const cashOutConfig = configManager.getCashOut(deviceId, settings.config)
|
||||
|
||||
|
|
@ -131,8 +143,7 @@ function plugins (settings, deviceId) {
|
|||
|
||||
const denominations = [cashOutConfig.top, cashOutConfig.bottom]
|
||||
|
||||
// TODO new-admin: will this actually be calculated?
|
||||
const virtualCassettes = [cashOutConfig.top + cashOutConfig.bottom]
|
||||
const virtualCassettes = [getLcmOrBigx2(cashOutConfig.top, cashOutConfig.bottom)]
|
||||
|
||||
return Promise.all([dbm.cassetteCounts(deviceId), cashOutHelper.redeemableTxs(deviceId, excludeTxId)])
|
||||
.then(([rec, _redeemableTxs]) => {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ const useStyles = makeStyles({
|
|||
border: 'none',
|
||||
backgroundColor: 'transparent',
|
||||
marginTop: 4,
|
||||
outline: 'none',
|
||||
cursor: 'pointer'
|
||||
},
|
||||
popoverContent: ({ width }) => ({
|
||||
|
|
@ -33,18 +34,19 @@ const Tooltip = memo(({ children, width, Icon = HelpIcon }) => {
|
|||
|
||||
return (
|
||||
<ClickAwayListener onClickAway={handleCloseHelpPopper}>
|
||||
<button
|
||||
className={classes.transparentButton}
|
||||
onClick={handleOpenHelpPopper}>
|
||||
<Icon />
|
||||
<div>
|
||||
<button
|
||||
className={classes.transparentButton}
|
||||
onClick={handleOpenHelpPopper}>
|
||||
<Icon />
|
||||
</button>
|
||||
<Popper
|
||||
open={helpPopperOpen}
|
||||
anchorEl={helpPopperAnchorEl}
|
||||
placement="bottom"
|
||||
onClose={handleCloseHelpPopper}>
|
||||
placement="bottom">
|
||||
<div className={classes.popoverContent}>{children}</div>
|
||||
</Popper>
|
||||
</button>
|
||||
</div>
|
||||
</ClickAwayListener>
|
||||
)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
import { useQuery, useMutation } from '@apollo/react-hooks'
|
||||
import { makeStyles } from '@material-ui/core'
|
||||
import { makeStyles, Box } from '@material-ui/core'
|
||||
import gql from 'graphql-tag'
|
||||
import * as R from 'ramda'
|
||||
import React, { useState } from 'react'
|
||||
import { v4 } from 'uuid'
|
||||
|
||||
import Title from 'src/components/Title'
|
||||
import Tooltip from 'src/components/Tooltip'
|
||||
import { Link } from 'src/components/buttons'
|
||||
import { Table as EditableTable } from 'src/components/editableTable'
|
||||
import { fromNamespace, namespaces } from 'src/utils/config'
|
||||
import { Switch } from 'src/components/inputs'
|
||||
import TitleSection from 'src/components/layout/TitleSection'
|
||||
import { P, Label2 } from 'src/components/typography'
|
||||
import { fromNamespace, toNamespace, namespaces } from 'src/utils/config'
|
||||
|
||||
import { mainStyles } from './Triggers.styles'
|
||||
import Wizard from './Wizard'
|
||||
|
|
@ -36,6 +39,10 @@ const Triggers = () => {
|
|||
const { data } = useQuery(GET_INFO)
|
||||
const triggers = fromServer(data?.config?.triggers ?? [])
|
||||
|
||||
const complianceConfig =
|
||||
data?.config && fromNamespace('compliance')(data.config)
|
||||
const rejectAddressReuse = complianceConfig?.rejectAddressReuse ?? false
|
||||
|
||||
const [saveConfig] = useMutation(SAVE_CONFIG, {
|
||||
onCompleted: () => setWizard(false),
|
||||
onError: () => setError(true),
|
||||
|
|
@ -48,6 +55,11 @@ const Triggers = () => {
|
|||
return saveConfig({ variables: { config: { triggers: toServer(toSave) } } })
|
||||
}
|
||||
|
||||
const addressReuseSave = rawConfig => {
|
||||
const config = toNamespace('compliance')(rawConfig)
|
||||
return saveConfig({ variables: { config } })
|
||||
}
|
||||
|
||||
const save = config => {
|
||||
setError(false)
|
||||
return saveConfig({
|
||||
|
|
@ -61,16 +73,33 @@ const Triggers = () => {
|
|||
|
||||
return (
|
||||
<>
|
||||
<div className={classes.titleWrapper}>
|
||||
<div className={classes.titleAndButtonsContainer}>
|
||||
<Title>Compliance Triggers</Title>
|
||||
</div>
|
||||
<div className={classes.headerLabels}>
|
||||
<TitleSection title="Compliance Triggers">
|
||||
<Box display="flex" alignItems="center">
|
||||
<Box display="flex" alignItems="center" justifyContent="end" mr={3}>
|
||||
<P>Reject reused addresses</P>
|
||||
<Switch
|
||||
checked={rejectAddressReuse}
|
||||
onChange={event => {
|
||||
addressReuseSave({ rejectAddressReuse: event.target.checked })
|
||||
}}
|
||||
value={rejectAddressReuse}
|
||||
/>
|
||||
<Label2 className={classes.switchLabel}>
|
||||
{rejectAddressReuse ? 'On' : 'Off'}
|
||||
</Label2>
|
||||
<Tooltip width={304}>
|
||||
<P>
|
||||
The "Reject reused addresses" option means that all addresses
|
||||
that are used once will be automatically rejected if there's an
|
||||
attempt to use them again on a new transaction.
|
||||
</P>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
<Link color="primary" onClick={() => setWizard(true)}>
|
||||
+ Add new trigger
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</Box>
|
||||
</TitleSection>
|
||||
<EditableTable
|
||||
data={triggers}
|
||||
name="triggers"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue