const getValidationRules = () => ({
    amount: {
        rules: [
            ['req'    , { message: localize('Amount is a required field.') }],
            ['number' , { min: 0, type: 'float' }],
        ],
    },
    barrier_1: {
        rules: [
            ['req'    , { condition: store => store.barrier_count && store.form_components.indexOf('barrier') > -1, message: localize('Barrier is a required field.') }],
            ['barrier', { condition: store => store.contract_expiry_type !== 'daily' && store.barrier_count }],
            ['number' , { condition: store => store.contract_expiry_type === 'daily' && store.barrier_count, type: 'float' }],
            ['custom' , { func: (value, options, store, inputs) => store.barrier_count > 1 ? +value > +inputs.barrier_2 : true, message: localize('Higher barrier must be higher than lower barrier.') }],
        ],
        trigger: 'barrier_2',
    },
    barrier_2: {
        rules: [
            ['req'    , { condition: store => store.barrier_count > 1 && store.form_components.indexOf('barrier') > -1, message: localize('Barrier is a required field.') }],
            ['barrier', { condition: store => store.contract_expiry_type !== 'daily' && store.barrier_count }],
            ['number' , { condition: store => store.contract_expiry_type === 'daily' && store.barrier_count, type: 'float' }],
            ['custom', { func: (value, options, store, inputs) => (/^[+-]/g.test(inputs.barrier_1) && /^[+-]/g.test(value)) || (/^(?![+-])/g.test(inputs.barrier_1) && /^(?![+-])/g.test(value)), message: localize('Both barriers should be relative or absolute') }],
            ['custom' , { func: (value, options, store, inputs) => +inputs.barrier_1 > +value, message: localize('Lower barrier must be lower than higher barrier.') }],
        ],
        trigger: 'barrier_1',
    },
    duration: {
        rules: [
            ['req'    , { message: localize('Duration is a required field.') }],
        ],
    },
});
const validNumber = (value, opts) => {
    const options = cloneObject(opts);
    let message = null;
    if (options.allow_empty && value.length === 0) {
        return true;
    }

    let is_ok = true;
    if ('min' in options && typeof options.min === 'function') {
        options.min = options.min();
    }
    if ('max' in options && typeof options.max === 'function') {
        options.max = options.max();
    }

    if (!(options.type === 'float' ? /^\d*(\.\d+)?$/ : /^\d+$/).test(value) || isNaN(value)) {
        is_ok   = false;
        message = localize('Should be a valid number.');
    } else if (options.type === 'float' && options.decimals &&
        !(new RegExp(`^\\d+(\\.\\d{0,${options.decimals}})?$`).test(value))) {
        is_ok   = false;
        message = localize('Up to [_1] decimal places are allowed.', [options.decimals]);
    } else if ('min' in options && 'max' in options && +options.min === +options.max && +value !== +options.min) {
        is_ok   = false;
        message = localize('Should be [_1]', [addComma(options.min, options.format_money ? getDecimalPlaces(Client.get('currency')) : undefined)]);
    } else if ('min' in options && 'max' in options && (+value < +options.min || isMoreThanMax(value, options))) {
        is_ok   = false;
        message = localize('Should be between [_1] and [_2]', [addComma(options.min, options.format_money ? getDecimalPlaces(Client.get('currency')) : undefined), addComma(options.max, options.format_money ? getDecimalPlaces(Client.get('currency')) : undefined)]);
    } else if ('min' in options && +value < +options.min) {
        is_ok   = false;
        message = localize('Should be more than [_1]', [addComma(options.min, options.format_money ? getDecimalPlaces(Client.get('currency')) : undefined)]);
    } else if ('max' in options && isMoreThanMax(value, options)) {
        is_ok   = false;
        message = localize('Should be less than [_1]', [addComma(options.max, options.format_money ? getDecimalPlaces(Client.get('currency')) : undefined)]);
    }

    getPreBuildDVRs().number.message = message;
    return is_ok;
};
Ejemplo n.º 3
0
export const getHeaderConfig = () => ({
    purchased: { title: localize('Contract Purchased'), icon: <IconTick /> },
    won      : { title: localize('Contract Won'),       icon: <IconFlag /> },
    lost     : { title: localize('Contract Lost'),      icon: <IconFlag /> },
});
Ejemplo n.º 4
0
const getValidationRules = () => ({
    amount: {
        rules: [
            ['req'    , { message: localize('Amount is a required field.') }],
            ['number' , { min: 0, type: 'float' }],
        ],
    },
    barrier_1: {
        rules: [
            ['req'    , { condition: store => store.barrier_count && store.form_components.indexOf('barrier') > -1, message: localize('Barrier is a required field.') }],
            ['barrier', { condition: store => store.barrier_count }],
            ['custom' , { func: (value, options, store, inputs) => store.barrier_count > 1 ? +value > +inputs.barrier_2 : true, message: localize('Higher barrier must be higher than lower barrier.') }],
        ],
        trigger: 'barrier_2',
    },
    barrier_2: {
        rules: [
            ['req'    , { condition: store => store.barrier_count > 1 && store.form_components.indexOf('barrier') > -1, message: localize('Barrier is a required field.') }],
            ['barrier', { condition: store => store.barrier_count }],
            ['custom' , { func: (value, options, store, inputs) => (/^[+-]/g.test(inputs.barrier_1) && /^[+-]/g.test(value)) || (/^(?![+-])/g.test(inputs.barrier_1) && /^(?![+-])/g.test(value)), message: localize('Both barriers should be relative or absolute') }],
            ['custom' , { func: (value, options, store, inputs) => +inputs.barrier_1 > +value, message: localize('Lower barrier must be lower than higher barrier.') }],
        ],
        trigger: 'barrier_1',
    },
    duration: {
        rules: [
            ['req'    , { message: localize('Duration is a required field.') }],
        ],
    },
    start_date: {
        trigger: 'start_time',
    },
    expiry_date: {
        trigger: 'expiry_time',
    },
    start_time: {
        rules: [
            ['custom' , { func: (value, options, store) => store.contract_start_type === 'spot' || isTimeValid(value)  , message: localize('Please enter the start time in the format "HH:MM".') }],
            ['custom' , { func: (value, options, store) => store.contract_start_type === 'spot' || isHourValid(value)  , message: localize('Hour must be between 0 and 23.') }],
            ['custom' , { func: (value, options, store) => store.contract_start_type === 'spot' || isMinuteValid(value), message: localize('Minute must be between 0 and 59.') }],
            ['custom' , { func: (value, options, store) => {
                if (store.contract_start_type === 'spot') return true;
                if (!isTimeValid(value)) return false;
                const start_moment       = toMoment(store.start_date);
                const start_moment_clone = start_moment.clone();
                const [h, m] = value.split(':');
                return isSessionAvailable(store.sessions, start_moment_clone.hour(h).minute(m), start_moment);
            }, message: localize('Start time cannot be in the past.') }],
        ],
    },
    expiry_time: {
        rules: [
            ['custom' , { func: (value, options, store) => store.contract_start_type === 'spot' || isTimeValid(value)  , message: localize('Please enter the start time in the format "HH:MM".') }],
            ['custom' , { func: (value, options, store) => store.contract_start_type === 'spot' || isHourValid(value)  , message: localize('Hour must be between 0 and 23.') }],
            ['custom' , { func: (value, options, store) => store.contract_start_type === 'spot' || isMinuteValid(value), message: localize('Minute must be between 0 and 59.') }],
            ['custom' , { func: (value, options, store) => {
                if (store.contract_start_type === 'spot') return true;
                if (!isTimeValid(value)) return false;
                const start_moment       = toMoment(store.start_date);
                const start_moment_clone = start_moment.clone();
                const [h, m] = value.split(':');
                return isSessionAvailable(store.sessions, start_moment_clone.hour(h).minute(m), start_moment);
            }, message: localize('Expiry time cannot be in the past.') }],
        ],
    },
});
const initPreBuildDVRs = () => ({
    address      : { func: validAddress,      message: localize('Only letters, numbers, space, and these special characters are allowed: [_1]', ['- . \' # ; : ( ) , @ /']) },
    barrier      : { func: validBarrier,      message: localize('Only numbers and these special characters are allowed: [_1]', ['+ - .']) },
    compare      : { func: validCompare,      message: localize('The two passwords that you entered do not match.') },
    email        : { func: validEmail,        message: localize('Invalid email address.') },
    general      : { func: validGeneral,      message: localize('Only letters, numbers, space, hyphen, period, and apostrophe are allowed.') },
    length       : { func: validLength,       message: localize('You should enter [_1] characters.', ['[_1]']) },
    letter_symbol: { func: validLetterSymbol, message: localize('Only letters, space, hyphen, period, and apostrophe are allowed.') },
    min          : { func: validMin,          message: localize('Minimum of [_1] characters required.', ['[_1]']) },
    not_equal    : { func: validNotEqual,     message: localize('[_1] and [_2] cannot be the same.', ['[_1]', '[_2]']) },
    number       : { func: validNumber,       message: '' },
    password     : { func: validPassword,     message: localize('Password should have lower and uppercase letters with numbers.') },
    phone        : { func: validPhone,        message: localize('Only numbers and spaces are allowed.') },
    postcode     : { func: validPostCode,     message: localize('Only letters, numbers, space, and hyphen are allowed.') },
    regular      : { func: validRegular,      message: '' },
    req          : { func: validRequired,     message: '' },
    signup_token : { func: validEmailToken,   message: localize('The length of token should be 8.') },
    tax_id       : { func: validTaxID,        message: localize('Should start with letter or number, and may contain hyphen and underscore.') },
});
Ejemplo n.º 6
0
        ContentComponent: MarkerSpotLabel,
        xPositioner     : MARKER_X_POSITIONER.EPOCH,
        yPositioner     : MARKER_Y_POSITIONER.VALUE,
    },
    SPOT_ENTRY: {
        ContentComponent: MarkerSpot,
        xPositioner     : MARKER_X_POSITIONER.EPOCH,
        yPositioner     : MARKER_Y_POSITIONER.VALUE,
    },
};

export const MARKER_TYPES_CONFIG = {
    LINE_END: {
        type          : 'LINE_END',
        marker_config : MARKER_CONTENT_TYPES.LINE,
        content_config: { line_style: 'dash',  label: localize('End Time') },
    },
    LINE_PURCHASE: {
        type          : 'LINE_PURCHASE',
        marker_config : MARKER_CONTENT_TYPES.LINE,
        content_config: { line_style: 'solid', label: localize('Purchase Time') },
    },
    LINE_START: {
        type          : 'LINE_START',
        marker_config : MARKER_CONTENT_TYPES.LINE,
        content_config: { line_style: 'solid', label: localize('Start Time') },
    },
    SPOT_ENTRY: {
        type          : 'SPOT_ENTRY',
        marker_config : MARKER_CONTENT_TYPES.SPOT_ENTRY,
        content_config: { className: 'chart-spot__entry' },
Ejemplo n.º 7
0
import React        from 'react';
import { localize } from '_common/localize';
import {
    // IconStatement,
    IconTrade }     from 'Assets/Header/NavBar/index';
import { routes }   from 'Constants/index';

const header_links = [
    {
        icon   : <IconTrade className='header__icon' />,
        text   : localize('Trade'),
        link_to: routes.trade,
    },
    // {
    //     icon      : <IconStatement className='header__icon' />,
    //     text      : localize('Reports'),
    //     link_to   : routes.statement,
    //     login_only: true,
    // },
];

export default header_links;