mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-02-11 10:36:53 +00:00
36 lines
990 B
TypeScript
36 lines
990 B
TypeScript
import { AppState } from 'reducers';
|
|
import { getScheduleTimestamp } from './fields';
|
|
import moment from 'moment';
|
|
import { EAC_SCHEDULING_CONFIG } from 'libs/scheduling';
|
|
|
|
const fiveMinFromNow = moment()
|
|
.add(5, 'm')
|
|
.toDate();
|
|
|
|
interface ICurrentScheduleTimestamp {
|
|
raw: string;
|
|
value: Date | null;
|
|
}
|
|
|
|
const isValidCurrentScheduleTimestamp = (state: AppState) => {
|
|
const currentScheduleTimestamp = getScheduleTimestamp(state);
|
|
const raw = currentScheduleTimestamp.raw;
|
|
const value = currentScheduleTimestamp.value;
|
|
|
|
return value && value > fiveMinFromNow && isCorrectFormat(raw);
|
|
};
|
|
|
|
const isCorrectFormat = (dateString: string) => {
|
|
return moment(dateString, EAC_SCHEDULING_CONFIG.SCHEDULE_TIMESTAMP_FORMAT, true).isValid();
|
|
};
|
|
|
|
const getCurrentScheduleTimestamp = (state: AppState): ICurrentScheduleTimestamp =>
|
|
getScheduleTimestamp(state);
|
|
|
|
export {
|
|
getCurrentScheduleTimestamp,
|
|
ICurrentScheduleTimestamp,
|
|
isValidCurrentScheduleTimestamp,
|
|
fiveMinFromNow
|
|
};
|