feat: move paper wallet only to admin

This commit is contained in:
José Oliveira 2021-09-05 00:19:08 +01:00
parent 4450e19f1f
commit 7157a11895
4 changed files with 118 additions and 3 deletions

View file

@ -81,6 +81,7 @@ function poll (req, res, next) {
const cashOutConfig = configManager.getCashOut(deviceId, settings.config) const cashOutConfig = configManager.getCashOut(deviceId, settings.config)
const receipt = configManager.getReceipt(settings.config) const receipt = configManager.getReceipt(settings.config)
const terms = configManager.getTermsConditions(settings.config) const terms = configManager.getTermsConditions(settings.config)
const enablePaperWalletOnly = configManager.getCompliance(settings.config).enablePaperWalletOnly
state.pids[operatorId] = { [deviceId]: { pid, ts: Date.now() } } state.pids[operatorId] = { [deviceId]: { pid, ts: Date.now() } }
@ -108,6 +109,7 @@ function poll (req, res, next) {
version, version,
receiptPrintingActive: receipt.active, receiptPrintingActive: receipt.active,
smsReceiptActive: receipt.sms, smsReceiptActive: receipt.sms,
enablePaperWalletOnly,
cassettes, cassettes,
twoWayMode: cashOutConfig.active, twoWayMode: cashOutConfig.active,
zeroConfLimits, zeroConfLimits,

View file

@ -36,6 +36,7 @@ export default {
const shadowSize = size === 'xl' ? 3 : height / 12 const shadowSize = size === 'xl' ? 3 : height / 12
const padding = size === 'xl' ? 20 : height / 2 const padding = size === 'xl' ? 20 : height / 2
const isGrey = backgroundColor === 'grey' const isGrey = backgroundColor === 'grey'
return { return {
extend: size === 'xl' ? h1 : h3, extend: size === 'xl' ? h1 : h3,
border: 'none', border: 'none',

View file

@ -1,5 +1,5 @@
import { useQuery, useMutation } from '@apollo/react-hooks' import { useQuery, useMutation } from '@apollo/react-hooks'
import { Box } from '@material-ui/core' import { Box, Dialog, DialogContent, DialogActions } from '@material-ui/core'
import Grid from '@material-ui/core/Grid' import Grid from '@material-ui/core/Grid'
import { makeStyles } from '@material-ui/core/styles' import { makeStyles } from '@material-ui/core/styles'
import gql from 'graphql-tag' import gql from 'graphql-tag'
@ -8,11 +8,12 @@ import * as R from 'ramda'
import React, { useState } from 'react' import React, { useState } from 'react'
import { HoverableTooltip } from 'src/components/Tooltip' import { HoverableTooltip } from 'src/components/Tooltip'
import { Link } from 'src/components/buttons' import { Link, Button, IconButton } from 'src/components/buttons'
import { Switch } from 'src/components/inputs' import { Switch } from 'src/components/inputs'
import Sidebar from 'src/components/layout/Sidebar' import Sidebar from 'src/components/layout/Sidebar'
import TitleSection from 'src/components/layout/TitleSection' import TitleSection from 'src/components/layout/TitleSection'
import { H4, Label2, P } from 'src/components/typography' import { H4, H2, Label2, P, Info3, Info2 } from 'src/components/typography'
import { ReactComponent as CloseIcon } from 'src/styling/icons/action/close/zodiac.svg'
import { fromNamespace, toNamespace } from 'src/utils/config' import { fromNamespace, toNamespace } from 'src/utils/config'
import styles from './Blacklist.styles' import styles from './Blacklist.styles'
@ -66,6 +67,50 @@ const ADD_ROW = gql`
} }
` `
const PaperWalletDialog = ({ onConfirmed, onDissmised, open, props }) => {
const classes = useStyles()
return (
<>
<Dialog
open={open}
aria-labelledby="form-dialog-title"
PaperProps={{
style: {
borderRadius: 8,
minWidth: 656,
bottom: 125,
right: 7
}
}}
{...props}>
<div className={classes.closeButton}>
<IconButton size={16} aria-label="close" onClick={onDissmised}>
<CloseIcon />
</IconButton>
</div>
<H2 className={classes.dialogTitle}>
{'Are you sure you want to enable this?'}
</H2>
<DialogContent className={classes.dialogContent}>
<Info3>{`This mode means that only paper wallets will be printed for users, and they won't be permitted to scan an address from their own wallet.`}</Info3>
<Info3>{`This mode is only useful for countries like Switzerland which mandates such a feature.\n`}</Info3>
<Info2>{`Don't enable this if you want users to be able to scan an address of their choosing.`}</Info2>
</DialogContent>
<DialogActions className={classes.dialogActions}>
<Button
backgroundColor="grey"
className={classes.cancelButton}
onClick={() => onDissmised()}>
Cancel
</Button>
<Button onClick={() => onConfirmed(true)}>Confirm</Button>
</DialogActions>
</Dialog>
</>
)
}
const Blacklist = () => { const Blacklist = () => {
const { data: blacklistResponse } = useQuery(GET_BLACKLIST) const { data: blacklistResponse } = useQuery(GET_BLACKLIST)
const { data: configData } = useQuery(GET_INFO) const { data: configData } = useQuery(GET_INFO)
@ -76,6 +121,7 @@ const Blacklist = () => {
}) })
const [errorMsg, setErrorMsg] = useState(null) const [errorMsg, setErrorMsg] = useState(null)
const [deleteDialog, setDeleteDialog] = useState(false) const [deleteDialog, setDeleteDialog] = useState(false)
const [confirmDialog, setConfirmDialog] = useState(false)
const [deleteEntry] = useMutation(DELETE_ROW, { const [deleteEntry] = useMutation(DELETE_ROW, {
onError: ({ message }) => { onError: ({ message }) => {
@ -108,6 +154,8 @@ const Blacklist = () => {
const rejectAddressReuse = complianceConfig?.rejectAddressReuse ?? false const rejectAddressReuse = complianceConfig?.rejectAddressReuse ?? false
const enablePaperWalletOnly = complianceConfig?.enablePaperWalletOnly ?? false
const addressReuseSave = rawConfig => { const addressReuseSave = rawConfig => {
const config = toNamespace('compliance')(rawConfig) const config = toNamespace('compliance')(rawConfig)
return saveConfig({ variables: { config } }) return saveConfig({ variables: { config } })
@ -121,6 +169,13 @@ const Blacklist = () => {
deleteEntry({ variables: { cryptoCode, address } }) deleteEntry({ variables: { cryptoCode, address } })
} }
const handleConfirmDialog = confirm => {
addressReuseSave({
enablePaperWalletOnly: confirm
})
setConfirmDialog(false)
}
const validateAddress = (cryptoCode, address) => { const validateAddress = (cryptoCode, address) => {
try { try {
return !R.isNil(coinUtils.parseUrl(cryptoCode, 'main', address)) return !R.isNil(coinUtils.parseUrl(cryptoCode, 'main', address))
@ -151,6 +206,13 @@ const Blacklist = () => {
return ( return (
<> <>
<PaperWalletDialog
open={confirmDialog}
onConfirmed={handleConfirmDialog}
onDissmised={() => {
setConfirmDialog(false)
}}
/>
<TitleSection title="Blacklisted addresses"> <TitleSection title="Blacklisted addresses">
<Box display="flex" justifyContent="flex-end"> <Box display="flex" justifyContent="flex-end">
<Link color="primary" onClick={() => setShowModal(true)}> <Link color="primary" onClick={() => setShowModal(true)}>
@ -172,6 +234,35 @@ const Blacklist = () => {
? `${clickedItem.display} blacklisted addresses` ? `${clickedItem.display} blacklisted addresses`
: ''}{' '} : ''}{' '}
</H4> </H4>
<Box
display="flex"
alignItems="center"
justifyContent="end"
mr="-140px">
<P>Enable paper wallet (only)</P>
<Switch
checked={enablePaperWalletOnly}
onChange={event => {
if (enablePaperWalletOnly) {
addressReuseSave({
enablePaperWalletOnly: event.target.checked
})
} else {
setConfirmDialog(true)
}
}}
value={enablePaperWalletOnly}
/>
<Label2>{enablePaperWalletOnly ? 'On' : 'Off'}</Label2>
<HoverableTooltip width={304}>
<P>
The "Enable paper wallet (only)" option means that all only
paper wallets paper wallets will be printed for users, and
they won't be permitted to scan an address from their own
wallet.
</P>
</HoverableTooltip>
</Box>
<Box <Box
display="flex" display="flex"
alignItems="center" alignItems="center"

View file

@ -33,6 +33,27 @@ const styles = {
}, },
error: { error: {
marginTop: 20 marginTop: 20
},
closeButton: {
display: 'flex',
padding: [[spacer * 2, spacer * 2, 0, spacer * 2]],
paddingRight: spacer * 1.5,
justifyContent: 'end'
},
dialogTitle: {
margin: [[0, spacer * 2, spacer, spacer * 2 + 4]]
},
dialogContent: {
width: 610,
paddingLeft: 20
},
dialogActions: {
padding: spacer * 4,
paddingTop: spacer * 2
},
cancelButton: {
marginRight: 8,
padding: 0
} }
} }