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

fix: default for collaborators set to 1 and added dev tag #820

Merged
Merged
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
31 changes: 20 additions & 11 deletions src/components/Send/CollaboratorsSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useMemo, useState } from 'react'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useField, useFormikContext } from 'formik'
import { useSettings } from '../../context/SettingsContext'
import * as rb from 'react-bootstrap'
import classNames from 'classnames'
import styles from './CollaboratorsSelector.module.css'
import { isValidNumCollaborators } from './helpers'
import styles from './CollaboratorsSelector.module.css'

type CollaboratorsSelectorProps = {
name: string
Expand Down Expand Up @@ -36,14 +36,23 @@ const CollaboratorsSelector = ({
return field.value === undefined || String(field.value) === customNumCollaboratorsInput
}, [field.value, customNumCollaboratorsInput])

const validateAndSetCustomNumCollaborators = (candidate: string) => {
const parsed = parseInt(candidate, 10)
if (isValidNumCollaborators(parsed, minNumCollaborators)) {
form.setFieldValue(field.name, parsed, true)
} else {
form.setFieldValue(field.name, undefined, true)
const validateAndSetCustomNumCollaborators = useCallback(
(candidate: string) => {
const parsed = parseInt(candidate, 10)
if (isValidNumCollaborators(parsed, minNumCollaborators)) {
form.setFieldValue(field.name, parsed, true)
} else {
form.setFieldValue(field.name, undefined, true)
}
},
[form, field.name, minNumCollaborators],
)

useEffect(() => {
if (!defaultCollaboratorsSelection.includes(field.value)) {
setCustomNumCollaboratorsInput(String(field.value))
}
}
}, [validateAndSetCustomNumCollaborators, field.value, defaultCollaboratorsSelection, setCustomNumCollaboratorsInput])

return (
<rb.Form.Group className={styles.collaboratorsSelector}>
Expand All @@ -55,13 +64,13 @@ const CollaboratorsSelector = ({
</div>
<div className="d-flex flex-row flex-wrap gap-2">
{defaultCollaboratorsSelection.map((number) => {
const isSelected = !usesCustomNumCollaborators && field.value === number
const currentlySelected = !usesCustomNumCollaborators && field.value === number
return (
<rb.Button
key={number}
variant={settings.theme === 'light' ? 'white' : 'dark'}
className={classNames(styles.collaboratorsSelectorElement, 'border', 'border-1', {
[styles.selected]: isSelected,
[styles.selected]: currentlySelected,
})}
onClick={() => {
validateAndSetCustomNumCollaborators(String(number))
Expand Down
3 changes: 2 additions & 1 deletion src/components/Send/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { isValidNumber } from '../../utils'

export const MAX_NUM_COLLABORATORS = 99

export const initialNumCollaborators = (minValue: number) => {
export const initialNumCollaborators = (minValue: number): number => {
if (minValue > 8) {
return minValue + pseudoRandomNumber(0, 2)
}

return pseudoRandomNumber(8, 10)
}

Expand Down
10 changes: 8 additions & 2 deletions src/components/Send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FormikProps } from 'formik'
import { useTranslation } from 'react-i18next'
import * as rb from 'react-bootstrap'
import * as Api from '../../libs/JmWalletApi'
import { isDevMode } from '../../constants/debugFeatures'
import PageTitle from '../PageTitle'
import Sprite from '../Sprite'
import { SendForm, SendFormValues } from './SendForm'
Expand All @@ -18,14 +19,16 @@ import { useLoadConfigValue } from '../../context/ServiceConfigContext'
import { useWaitForUtxosToBeSpent } from '../../hooks/WaitForUtxosToBeSpent'
import { routes } from '../../constants/routes'
import { JM_MINIMUM_MAKERS_DEFAULT } from '../../constants/config'

import { initialNumCollaborators } from './helpers'

const INITIAL_DESTINATION = null
const INITIAL_SOURCE_JAR_INDEX = null
const INITIAL_AMOUNT = null
const INITIAL_IS_COINJOIN = true

// set the default to one collaborat
const DEV_INITIAL_NUM_COLLABORATORS_INPUT = 1

type MaxFeeConfigMissingAlertProps = {
onSuccess: () => void
}
Expand Down Expand Up @@ -98,7 +101,10 @@ export default function Send({ wallet }: SendProps) {
const [alert, setAlert] = useState<SimpleAlert>()
const [isSending, setIsSending] = useState(false)
const [minNumCollaborators, setMinNumCollaborators] = useState(JM_MINIMUM_MAKERS_DEFAULT)
const initNumCollaborators = useMemo(() => initialNumCollaborators(minNumCollaborators), [minNumCollaborators])
const initNumCollaborators = useMemo(
() => (isDevMode() ? DEV_INITIAL_NUM_COLLABORATORS_INPUT : initialNumCollaborators(minNumCollaborators)),
[minNumCollaborators],
)

const [feeConfigValues, reloadFeeConfigValues] = useFeeConfigValues()
const maxFeesConfigMissing = useMemo(
Expand Down