Skip to content

Commit

Permalink
feat(jam): remove "keep funds in jam" (#484)
Browse files Browse the repository at this point in the history
* feat(scheduler): remove "external" switch

* Revert "feat(scheduler): remove "external" switch"

This reverts commit ca30545.

* feat(scheduler): remove toggle, external=default

* feat(send): prefill w/ internal when testing

* feat(scheduler): remove destinationIsExternal

* feat(scheduler): re-word description texts

* fix(scheduler): add missing hook

* feat(scheduler): remove unused i18n keys
  • Loading branch information
dergigi committed Aug 24, 2022
1 parent 308873a commit 5ada591
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 42 deletions.
61 changes: 23 additions & 38 deletions src/components/Jam.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default function Jam() {

const [alert, setAlert] = useState(null)
const [isLoading, setIsLoading] = useState(true)
const [destinationIsExternal, setDestinationIsExternal] = useState(false)
const [collaborativeOperationRunning, setCollaborativeOperationRunning] = useState(false)

const startJarUtxos = useMemo(() => {
Expand Down Expand Up @@ -94,11 +93,8 @@ export default function Jam() {
const initialFormValues = useMemo(() => {
const addressCount = 3

let destinationAddresses = []
if (destinationIsExternal) {
// prefill with empty addresses
destinationAddresses = Array(addressCount).fill('')
} else {
let destinationAddresses = Array(addressCount).fill('')
if (useInsecureTestingSettings) {
try {
// prefill with addresses marked as "new"
destinationAddresses = getNewAddressesForAccounts(INTERNAL_DEST_ACCOUNTS)
Expand All @@ -109,7 +105,7 @@ export default function Jam() {
}

return destinationAddresses.reduce((obj, addr, index) => ({ ...obj, [`dest${index + 1}`]: addr }), {})
}, [destinationIsExternal, getNewAddressesForAccounts])
}, [useInsecureTestingSettings, getNewAddressesForAccounts])

useEffect(() => {
const abortCtrl = new AbortController()
Expand Down Expand Up @@ -364,35 +360,6 @@ export default function Jam() {
<rb.Form onSubmit={handleSubmit} noValidate>
{!collaborativeOperationRunning && (
<>
<rb.Form.Group className="mb-4" controlId="offertype">
<ToggleSwitch
label={t('scheduler.toggle_internal_destination_title')}
subtitle={t('scheduler.toggle_internal_destination_subtitle')}
toggledOn={destinationIsExternal}
onToggle={async (isToggled) => {
if (!isToggled) {
try {
const newAddresses = getNewAddressesForAccounts(INTERNAL_DEST_ACCOUNTS)
setFieldValue('dest1', newAddresses[0], true)
setFieldValue('dest2', newAddresses[1], true)
setFieldValue('dest3', newAddresses[2], true)
} catch (e) {
console.error('Could not get internal addresses.', e)
setFieldValue('dest1', '', true)
setFieldValue('dest2', '', true)
setFieldValue('dest3', '', true)
}
} else {
setFieldValue('dest1', '', false)
setFieldValue('dest2', '', false)
setFieldValue('dest3', '', false)
}

setDestinationIsExternal(isToggled)
}}
disabled={isSubmitting}
/>
</rb.Form.Group>
{isDebugFeatureEnabled('insecureScheduleTesting') && (
<rb.Form.Group className="mb-4" controlId="offertype">
<ToggleSwitch
Expand All @@ -401,15 +368,33 @@ export default function Jam() {
"This is completely insecure but makes testing the schedule much faster. This option won't be available in production."
}
toggledOn={useInsecureTestingSettings}
onToggle={(isToggled) => setUseInsecureTestingSettings(isToggled)}
onToggle={async (isToggled) => {
setUseInsecureTestingSettings(isToggled)
if (isToggled) {
try {
const newAddresses = getNewAddressesForAccounts(INTERNAL_DEST_ACCOUNTS)
setFieldValue('dest1', newAddresses[0], true)
setFieldValue('dest2', newAddresses[1], true)
setFieldValue('dest3', newAddresses[2], true)
} catch (e) {
console.error('Could not get internal addresses.', e)
setFieldValue('dest1', '', true)
setFieldValue('dest2', '', true)
setFieldValue('dest3', '', true)
}
} else {
setFieldValue('dest1', '', false)
setFieldValue('dest2', '', false)
setFieldValue('dest3', '', false)
}
}}
disabled={isSubmitting}
/>
</rb.Form.Group>
)}
</>
)}
{!collaborativeOperationRunning &&
destinationIsExternal &&
[1, 2, 3].map((i) => {
return (
<rb.Form.Group className="mb-4" key={i} controlId={`dest${i}`}>
Expand Down
6 changes: 2 additions & 4 deletions src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,14 @@
},
"scheduler": {
"title": "Jam Scheduler (Experimental)",
"subtitle": "Execute multiple transactions using random amounts and time intervals to increase the privacy of yourself and others. Every scheduled transaction is a collaborative transaction. The scheduler will use all available funds that aren't frozen.",
"subtitle": "Execute multiple transactions using random amounts and time intervals to increase the privacy of yourself and others. Every scheduled transaction is a collaborative transaction.",
"error_starting_schedule_failed": "Starting the scheduler failed.",
"error_stopping_schedule_failed": "Stopping the scheduler failed.",
"complete_wallet_title": "Complete Wallet",
"complete_wallet_subtitle": "This will use all of your non-frozen funds.",
"description_destination_addresses": "You can choose to send your funds to an external wallet after completion automatically. However, this feature requires you to provide multiple destination addresses to preserve your privacy.",
"description_destination_addresses": "The scheduler will send all available funds to multiple destinations, splitting them up in random chunks.",
"feedback_invalid_destination_address": "Please enter valid a destination address.",
"feedback_reused_destination_address": "This address is already used. To preserve your privacy please choose another one.",
"toggle_internal_destination_title": "Send to external wallet",
"toggle_internal_destination_subtitle": "Specify destination addresses to send funds to an external wallet.",
"label_destination_input": "Destination {{ destination }}",
"placeholder_destination_input": "Enter destination address...",
"description_fees": "The scheduler will pay all occurring fees automatically.",
Expand Down

0 comments on commit 5ada591

Please sign in to comment.