From f6547341f1eb747881bde48779355162a191586b Mon Sep 17 00:00:00 2001 From: Taranto Date: Tue, 22 Sep 2020 09:01:43 +0100 Subject: [PATCH] feat: reject address reuse --- lib/cash-in/cash-in-tx.js | 11 ++--- lib/new-config-manager.js | 5 +- lib/plugins.js | 15 +++++- new-lamassu-admin/src/components/Tooltip.js | 16 +++--- .../src/pages/Triggers/Triggers.js | 49 +++++++++++++++---- 5 files changed, 69 insertions(+), 27 deletions(-) diff --git a/lib/cash-in/cash-in-tx.js b/lib/cash-in/cash-in-tx.js index 19f9b76d..82d09bb6 100644 --- a/lib/cash-in/cash-in-tx.js +++ b/lib/cash-in/cash-in-tx.js @@ -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)) } diff --git a/lib/new-config-manager.js b/lib/new-config-manager.js index caddcbb4..7da4caad 100644 --- a/lib/new-config-manager.js +++ b/lib/new-config-manager.js @@ -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, diff --git a/lib/plugins.js b/lib/plugins.js index f7805af8..9953008f 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -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]) => { diff --git a/new-lamassu-admin/src/components/Tooltip.js b/new-lamassu-admin/src/components/Tooltip.js index c5ba9b94..92ef7e35 100644 --- a/new-lamassu-admin/src/components/Tooltip.js +++ b/new-lamassu-admin/src/components/Tooltip.js @@ -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 ( - + placement="bottom">
{children}
- +
) }) diff --git a/new-lamassu-admin/src/pages/Triggers/Triggers.js b/new-lamassu-admin/src/pages/Triggers/Triggers.js index 0b0d4cd0..95461e66 100644 --- a/new-lamassu-admin/src/pages/Triggers/Triggers.js +++ b/new-lamassu-admin/src/pages/Triggers/Triggers.js @@ -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 ( <> -
-
- Compliance Triggers -
-
+ + + +

Reject reused addresses

+ { + addressReuseSave({ rejectAddressReuse: event.target.checked }) + }} + value={rejectAddressReuse} + /> + + {rejectAddressReuse ? 'On' : 'Off'} + + +

+ 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. +

+
+
setWizard(true)}> + Add new trigger -
-
+ +