import { useQuery, useMutation } from '@apollo/react-hooks' 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 Tooltip from 'src/components/Tooltip' import { Link, Button } from 'src/components/buttons' import { Table as EditableTable } from 'src/components/editableTable' import { Switch } from 'src/components/inputs' import TitleSection from 'src/components/layout/TitleSection' import { P, Label2, H2 } from 'src/components/typography' import { fromNamespace, toNamespace, namespaces } from 'src/utils/config' import styles from './Triggers.styles' import Wizard from './Wizard' import { Schema, getElements, sortBy, fromServer, toServer } from './helper' const useStyles = makeStyles(styles) const SAVE_CONFIG = gql` mutation Save($config: JSONObject) { saveConfig(config: $config) } ` const GET_INFO = gql` query getData { config } ` const Triggers = () => { const classes = useStyles() const [wizard, setWizard] = useState(false) const [error, setError] = useState(false) const { data, loading } = 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), refetchQueries: () => ['getData'] }) const add = rawConfig => { const toSave = R.concat([{ id: v4(), direction: 'both', ...rawConfig }])( triggers ) setError(false) 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({ variables: { config: { triggers: toServer(config.triggers) } } }) } const currency = R.path(['fiatCurrency'])( fromNamespace(namespaces.LOCALE)(data?.config) ) return ( <>

Reject reused addresses

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

This option requires a user to scan a different cryptocurrency address if they attempt to scan one that had been previously used for a transaction in your network

{!loading && !R.isEmpty(triggers) && ( setWizard(true)}> + Add new trigger )} {wizard && ( setWizard(null)} /> )} {!loading && R.isEmpty(triggers) && (

It seems there are no active compliance triggers on your network

)} ) } export default Triggers