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(sweep): wait for scheduler start/stop #529

Merged
merged 1 commit into from
Oct 3, 2022
Merged
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
34 changes: 26 additions & 8 deletions src/components/Jam.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export default function Jam() {

const [alert, setAlert] = useState(null)
const [isLoading, setIsLoading] = useState(true)
const [collaborativeOperationRunning, setCollaborativeOperationRunning] = useState(false)
const [isWaitingSchedulerStart, setIsWaitingSchedulerStart] = useState(false)
const [isWaitingSchedulerStop, setIsWaitingSchedulerStop] = useState(false)
const collaborativeOperationRunning = useMemo(
() => serviceInfo?.coinjoinInProgress || serviceInfo?.makerRunning || false,
[serviceInfo]
)

const schedulerPreconditionSummary = useMemo(
() => buildCoinjoinRequirementSummary(walletInfo?.data.utxos.utxos || []),
Expand Down Expand Up @@ -119,9 +124,12 @@ export default function Jam() {
}, [reloadServiceInfo, reloadCurrentWalletInfo, t])

useEffect(() => {
setCollaborativeOperationRunning(serviceInfo?.coinjoinInProgress || serviceInfo?.makerRunning || false)
if (!serviceInfo) return

setIsWaitingSchedulerStart((current) => (current && serviceInfo.schedule ? false : current))
setIsWaitingSchedulerStop((current) => (current && !serviceInfo.schedule ? false : current))

if (serviceInfo?.schedule && process.env.NODE_ENV === 'development') {
if (serviceInfo.schedule && process.env.NODE_ENV === 'development') {
console.table(serviceInfo.schedule)
}
}, [serviceInfo])
Expand All @@ -133,6 +141,7 @@ export default function Jam() {

setAlert(null)
setIsLoading(true)
setIsWaitingSchedulerStart(true)

const destinations = [values.dest1, values.dest2, values.dest3]

Expand All @@ -158,11 +167,15 @@ export default function Jam() {
return Api.postSchedulerStart({ signal: abortCtrl.signal, walletName: wallet.name, token: wallet.token }, body)
.then((res) => (res.ok ? true : Api.Helper.throwError(res, t('scheduler.error_starting_schedule_failed'))))
.then((_) => reloadServiceInfo({ signal: abortCtrl.signal }))
.then((_) => setCollaborativeOperationRunning(true))
.catch((err) => {
if (abortCtrl.signal.aborted) return
setAlert({ variant: 'danger', message: err.message })
setIsWaitingSchedulerStart(false)
})
.finally(() => {
if (abortCtrl.signal.aborted) return
setIsLoading(false)
})
.finally(() => setIsLoading(false))
}

const stopSchedule = async () => {
Expand All @@ -172,29 +185,34 @@ export default function Jam() {

setAlert(null)
setIsLoading(true)
setIsWaitingSchedulerStop(true)

const abortCtrl = new AbortController()
return Api.getTakerStop({ signal: abortCtrl.signal, walletName: wallet.name, token: wallet.token })
.then((res) => (res.ok ? true : Api.Helper.throwError(res, t('scheduler.error_stopping_schedule_failed'))))
.then((_) => setCollaborativeOperationRunning(false))
.then((_) =>
Promise.all([
reloadServiceInfo({ signal: abortCtrl.signal }),
reloadCurrentWalletInfo({ signal: abortCtrl.signal }),
])
)
.catch((err) => {
if (abortCtrl.signal.aborted) return
setAlert({ variant: 'danger', message: err.message })
setIsWaitingSchedulerStop(false)
})
.finally(() => {
if (abortCtrl.signal.aborted) return
setIsLoading(false)
})
.finally(() => setIsLoading(false))
}

return (
<>
<PageTitle title={t('scheduler.title')} subtitle={t('scheduler.subtitle')} />
{alert && <rb.Alert variant={alert.variant}>{alert.message}</rb.Alert>}

{isLoading ? (
{isLoading || isWaitingSchedulerStart || isWaitingSchedulerStop ? (
<rb.Placeholder as="div" animation="wave">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but I thought I'd mention it anyway: I'm not sure how animation="wave" should look like, but this is how the loading state looks for me when starting/stopping the scheduler:

Screenshot 2022-10-03 at 18 27 31

Independent of the changes in this PR, and independent of browser (Firefox and Chromium).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is "expected". Should resemble either the "start"/"stop" button or the "Service already running"-alert.
Any inputs highly appreciated.

<rb.Placeholder xs={12} className={styles['input-loader']} />
</rb.Placeholder>
Expand Down