diff --git a/packages/components/stories/page-error/README.md b/packages/components/stories/page-error/README.md index 2859d4576daf..749ef306b500 100644 --- a/packages/components/stories/page-error/README.md +++ b/packages/components/stories/page-error/README.md @@ -20,8 +20,8 @@ const DummyComponent = props => ( | messages | {array} | null | Array of strings as error text | | image_url | {string} | null | This image will be shown beside the error text | | classNameImage | {string} | null | | -| redirect_label | {string} | null | Redirect button text | -| redirect_url | {string} | null | Where you want to land user after clicking on redirect button | +| redirect_labels | {array} | null | Redirect button text | +| redirect_urls | {array} | null | Where you want to land user after clicking on redirect button | | setError | {function} | null | Function to remove error on the parent component | | should_clear_error_on_click | {boolean} | null | Set it to true to disable error on parent component on redirect. `setError` must be defined | @@ -36,9 +36,9 @@ const DummyComponent = props => ( messages={props.messages} classNameImage='may-class' image_url={props.image_url} - redirect_label={props.redirect_label} + redirect_labels={props.redirect_labels} buttonOnClick={props.buttonOnClick} - redirect_url={props.redirect_url} + redirect_urls={props.redirect_urls} /> ); ``` diff --git a/packages/shared/src/utils/helpers/__tests__/durations.ts b/packages/shared/src/utils/helpers/__tests__/durations.ts index a0712b4e0ada..5bd730446184 100644 --- a/packages/shared/src/utils/helpers/__tests__/durations.ts +++ b/packages/shared/src/utils/helpers/__tests__/durations.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import * as Duration from '../duration.js'; +import * as Duration from '../duration'; import moment from 'moment'; describe('buildDurationConfig', () => { @@ -29,6 +29,7 @@ describe('buildDurationConfig', () => { max: 31536000, }, }, + forward: {}, }, units_display: { spot: [ @@ -41,7 +42,7 @@ describe('buildDurationConfig', () => { }; it('Returns correct value when durations is not passed', () => { - expect(Duration.buildDurationConfig(contract)).to.eql(durations); + expect(Duration.buildDurationConfig(contract, durations)).to.eql(durations); }); it('Returns correct value when durations passed', () => { diff --git a/packages/shared/src/utils/helpers/duration.ts b/packages/shared/src/utils/helpers/duration.ts index d86da73fc179..e16638ba88aa 100644 --- a/packages/shared/src/utils/helpers/duration.ts +++ b/packages/shared/src/utils/helpers/duration.ts @@ -18,10 +18,10 @@ type TUnit = { value: string; }; -type TDurations = { +export type TDurations = { min_max: { - spot?: Partial>; - forward?: Record<'intraday', TMaxMin>; + spot: Partial>; + forward: Partial>; }; units_display: Partial>; }; @@ -34,7 +34,7 @@ type TDurationMinMax = { }; const getDurationMaps = () => ({ - t: { display: localize('Ticks'), order: 1, to_second: 0 }, + t: { display: localize('Ticks'), order: 1, to_second: null }, s: { display: localize('Seconds'), order: 2, to_second: 1 }, m: { display: localize('Minutes'), order: 3, to_second: 60 }, h: { display: localize('Hours'), order: 4, to_second: 60 * 60 }, @@ -43,25 +43,25 @@ const getDurationMaps = () => ({ export const buildDurationConfig = ( contract: TContract, - durations: TDurations = { min_max: {}, units_display: {} } + durations: TDurations = { min_max: { spot: {}, forward: {} }, units_display: {} } ) => { type TDurationMaps = keyof typeof duration_maps; - let duration_min_max = durations.min_max[contract.start_type as keyof typeof durations.min_max]; - let duration_units = durations.units_display[contract.start_type as keyof typeof durations.units_display]; - - duration_min_max = duration_min_max || {}; - duration_units = duration_units || []; + durations.units_display[contract.start_type as keyof typeof durations.units_display] = + durations.units_display[contract.start_type as keyof typeof durations.units_display] || []; + const duration_min_max = durations.min_max[contract.start_type as keyof typeof durations.min_max]; const obj_min = getDurationFromString(contract.min_contract_duration); const obj_max = getDurationFromString(contract.max_contract_duration); - duration_min_max[contract.expiry_type as keyof typeof duration_min_max] = { + durations.min_max[contract.start_type as keyof typeof durations.min_max][ + contract.expiry_type as keyof typeof duration_min_max + ] = { min: convertDurationUnit(obj_min.duration, obj_min.unit, 's') || 0, max: convertDurationUnit(obj_max.duration, obj_max.unit, 's') || 0, }; const arr_units: string[] = []; - duration_units.forEach(obj => { + durations?.units_display?.[contract.start_type as keyof typeof durations.units_display]?.forEach?.(obj => { arr_units.push(obj.value); }); @@ -84,10 +84,9 @@ export const buildDurationConfig = ( }); } - duration_units = arr_units + durations.units_display[contract.start_type as keyof typeof durations.units_display] = arr_units .sort((a, b) => (duration_maps[a as TDurationMaps].order > duration_maps[b as TDurationMaps].order ? 1 : -1)) .reduce((o, c) => [...o, { text: duration_maps[c as TDurationMaps].display, value: c }], [] as TUnit[]); - return durations; }; @@ -98,13 +97,13 @@ export const convertDurationUnit = (value: number, from_unit: string, to_unit: s const duration_maps = getDurationMaps(); - if (from_unit === to_unit || !('to_second' in duration_maps[from_unit as keyof typeof duration_maps])) { + if (from_unit === to_unit || duration_maps[from_unit as keyof typeof duration_maps].to_second === null) { return value; } return ( - (value * duration_maps[from_unit as keyof typeof duration_maps].to_second) / - duration_maps[to_unit as keyof typeof duration_maps].to_second + (value * (duration_maps[from_unit as keyof typeof duration_maps]?.to_second ?? 1)) / + (duration_maps[to_unit as keyof typeof duration_maps]?.to_second ?? 1) ); }; diff --git a/packages/shared/src/utils/validation/declarative-validation-rules.ts b/packages/shared/src/utils/validation/declarative-validation-rules.ts index df5e87b550ed..7b7d0ab34ff2 100644 --- a/packages/shared/src/utils/validation/declarative-validation-rules.ts +++ b/packages/shared/src/utils/validation/declarative-validation-rules.ts @@ -11,19 +11,19 @@ export type TOptions = { regex?: RegExp; }; -const validRequired = (value?: string /* , options, field */) => { +const validRequired = (value?: string | number /* , options, field */) => { if (value === undefined || value === null) { return false; } - const str = value.replace(/\s/g, ''); + const str = value.toString().replace(/\s/g, ''); return str.length > 0; }; export const validAddress = (value: string) => !/[`~!$%^&*_=+[}{\]\\"?><|]+/.test(value); export const validPostCode = (value: string) => value === '' || /^[A-Za-z0-9][A-Za-z0-9\s-]*$/.test(value); export const validTaxID = (value: string) => /(?!^$|\s+)[A-Za-z0-9./\s-]$/.test(value); export const validPhone = (value: string) => /^\+?([0-9-]+\s)*[0-9-]+$/.test(value); -export const validLetterSymbol = (value: string) => /^[A-Za-z]+([a-zA-Z\.' -])*[a-zA-Z\.' -]+$/.test(value); +export const validLetterSymbol = (value: string) => /^[A-Za-z]+([a-zA-Z.' -])*[a-zA-Z.' -]+$/.test(value); export const validLength = (value = '', options: TOptions) => (options.min ? value.length >= options.min : true) && (options.max ? value.length <= options.max : true); export const validPassword = (value: string) => /(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]+/.test(value);