From e8eaf418581608832f781c6e997dd75f0e42d41c Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Wed, 4 Oct 2023 16:01:19 +0200 Subject: [PATCH] refactor: ScheduleProgress component from jsx to tsx --- .../{ScheduleProgress.jsx => ScheduleProgress.tsx} | 12 ++++++++---- src/context/ServiceInfoContext.tsx | 2 +- src/globals.d.ts | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) rename src/components/{ScheduleProgress.jsx => ScheduleProgress.tsx} (95%) diff --git a/src/components/ScheduleProgress.jsx b/src/components/ScheduleProgress.tsx similarity index 95% rename from src/components/ScheduleProgress.jsx rename to src/components/ScheduleProgress.tsx index 296a64b90..a9ae98027 100644 --- a/src/components/ScheduleProgress.jsx +++ b/src/components/ScheduleProgress.tsx @@ -1,9 +1,9 @@ -import React from 'react' import * as rb from 'react-bootstrap' import { Trans, useTranslation } from 'react-i18next' import styles from './ScheduleProgress.module.css' +import { Schedule } from '../context/ServiceInfoContext' -const scheduleToSteps = (schedule) => { +const scheduleToSteps = (schedule: Schedule) => { // Example Schedule: // // schedule = [ @@ -34,7 +34,7 @@ const scheduleToSteps = (schedule) => { // Calculate total wait time. Ignores the last element since there's no reason in waiting after the last element completed. // This is a lower bound estimate for the time the whole scheduler run will take since it doesn't take into account the time // it takes to find and talk to makers and wait for tx confirmations on the timechain. - const totalWaitTime = Math.max( + const totalWaitTime: Minutes = Math.max( 1, schedule.slice(0, schedule.length - 1).reduce((acc, tx) => acc + tx[4] * 60, 0), ) @@ -58,7 +58,11 @@ const scheduleToSteps = (schedule) => { } } -const ScheduleProgress = ({ schedule }) => { +interface ScheduleProgressProps { + schedule: Schedule +} + +const ScheduleProgress = ({ schedule }: ScheduleProgressProps) => { const { t } = useTranslation() const steps = scheduleToSteps(schedule) diff --git a/src/context/ServiceInfoContext.tsx b/src/context/ServiceInfoContext.tsx index 0847e7426..a7b6f3ba4 100644 --- a/src/context/ServiceInfoContext.tsx +++ b/src/context/ServiceInfoContext.tsx @@ -24,7 +24,7 @@ const SESSION_REQUEST_INTERVAL: Milliseconds = 10_000 type AmountFraction = number type AmountCounterparties = number type SchedulerDestinationAddress = 'INTERNAL' | Api.BitcoinAddress -type WaitTimeInMinutes = number +type WaitTimeInMinutes = Minutes type Rounding = number type StateFlag = 0 | 1 | Api.TxId diff --git a/src/globals.d.ts b/src/globals.d.ts index 30c01b0c8..a01f6db2e 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -4,6 +4,7 @@ declare type Unit = 'BTC' | 'sats' type Milliseconds = number type Seconds = number +type Minutes = number declare type MnemonicPhrase = string[]