Skip to content

Commit

Permalink
Merge pull request #4 from zakibinary/contract_and_reports_update
Browse files Browse the repository at this point in the history
zaki/markets_trade_types_toolip_popover
  • Loading branch information
easteregg committed Jun 16, 2019
2 parents 21917a2 + 43ed09b commit 77472a9
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 15 deletions.
74 changes: 71 additions & 3 deletions src/javascript/app/Constants/contract.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,64 @@
import { localize } from '_common/localize';

export const getMarketNamesMap = () => ({
FRXAUDCAD : localize('AUD/CAD'),
FRXAUDCHF : localize('AUD/CHF'),
FRXAUDJPY : localize('AUD/JPY'),
FRXAUDNZD : localize('AUD/NZD'),
FRXAUDPLN : localize('AUD/PLN'),
FRXAUDUSD : localize('AUD/USD'),
FRXBROUSD : localize('Oil/USD'),
FRXEURAUD : localize('EUR/AUD'),
FRXEURCAD : localize('EUR/CAD'),
FRXEURCHF : localize('EUR/CHF'),
FRXEURGBP : localize('EUR/GBP'),
FRXEURJPY : localize('EUR/JPY'),
FRXEURNZD : localize('EUR/NZD'),
FRXEURUSD : localize('EUR/USD'),
FRXGBPAUD : localize('GBP/AUD'),
FRXGBPCAD : localize('GBP/CAD'),
FRXGBPCHF : localize('GBP/CHF'),
FRXGBPJPY : localize('GBP/JPY'),
FRXGBPNOK : localize('GBP/NOK'),
FRXGBPUSD : localize('GBP/USD'),
FRXNZDJPY : localize('NZD/JPY'),
FRXNZDUSD : localize('NZD/USD'),
FRXUSDCAD : localize('USD/CAD'),
FRXUSDCHF : localize('USD/CHF'),
FRXUSDJPY : localize('USD/JPY'),
FRXUSDNOK : localize('USD/NOK'),
FRXUSDPLN : localize('USD/PLN'),
FRXUSDSEK : localize('USD/SEK'),
FRXXAGUSD : localize('Silver/USD'),
FRXXAUUSD : localize('Gold/USD'),
FRXXPDUSD : localize('Palladium/USD'),
FRXXPTUSD : localize('Platinum/USD'),
OTC_AEX : localize('Dutch Index'),
OTC_AS51 : localize('Australian Index'),
OTC_DJI : localize('Wall Street Index'),
OTC_FCHI : localize('French Index'),
OTC_FTSE : localize('UK Index'),
OTC_GDAXI : localize('German Index'),
OTC_HSI : localize('Hong Kong Index'),
OTC_IBEX35: localize('Spanish Index'),
OTC_N225 : localize('Japanese Index'),
OTC_NDX : localize('US Tech Index'),
OTC_SPC : localize('US Index'),
OTC_SSMI : localize('Swiss Index'),
OTC_SX5E : localize('Euro 50 Index'),
R_10 : localize('Volatility 10 Index'),
R_25 : localize('Volatility 25 Index'),
R_50 : localize('Volatility 50 Index'),
R_75 : localize('Volatility 75 Index'),
R_100 : localize('Volatility 100 Index'),
RDBEAR : localize('Bear Market Index'),
RDBULL : localize('Bull Market Index'),
WLDAUD : localize('AUD Index'),
WLDEUR : localize('EUR Index'),
WLDGBP : localize('GBP Index'),
WLDUSD : localize('USD Index'),
});

export const getUnsupportedContracts = () => ({
EXPIRYMISS: {
name : localize('Ends Outside'),
Expand Down Expand Up @@ -122,10 +181,19 @@ export const getSupportedContracts = is_high_low => ({
},
});

const getContractConfig = is_high_low => ({
export const getContractConfig = is_high_low => ({
...getSupportedContracts(is_high_low),
...getUnsupportedContracts(),
});

export const getContractTypeDisplay = (type, is_high_low = false) => (getContractConfig(is_high_low)[type.toUpperCase()] ? getContractConfig(is_high_low)[type.toUpperCase()].name : '');
export const getContractTypePosition = (type, is_high_low = false) => (getContractConfig(is_high_low)[type.toUpperCase()] ? getContractConfig(is_high_low)[type.toUpperCase()].position : 'top');
export const getContractTypeDisplay = (
type,
is_high_low = false) => (
getContractConfig(is_high_low)[type] ? getContractConfig(is_high_low)[type.toUpperCase()].name : ''
);

export const getContractTypePosition = (
type,
is_high_low = false) => (
getContractConfig(is_high_low)[type] ? getContractConfig(is_high_low)[type.toUpperCase()].position : 'top'
);
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import React from 'react';
import { UnderlyingIcon } from 'App/Components/Elements/underlying-icon.jsx';
import { Popover } from 'App/Components/Elements/Popover';
import Icon from 'Assets/icon.jsx';
import { getContractTypeDisplay } from 'Constants';
import { getMarketInformation } from '../Helpers/market-underyling';
import { getMarketName,
getTradeTypeName,
getMarketInformation } from '../Helpers/market-underlying';

const MarketSymbolIconRow = ({ payload, show_description }) => {
const should_show_category_icon = typeof payload.shortcode === 'string';
Expand All @@ -15,9 +16,10 @@ const MarketSymbolIconRow = ({ payload, show_description }) => {
<div className='market-symbol-icon'>
<div className='market-symbol-icon-name'>
<Popover
classNameBubble='market-symbol-icon__tooltip'
classNameTarget='market-symbol-icon__popover'
classNameBubble='market-symbol-icon__popover-bubble'
alignment='top'
message={payload.display_name}
message={getMarketName(market_information.underlying)}
disable_target_icon
>
<UnderlyingIcon market={market_information.underlying} />
Expand All @@ -27,9 +29,10 @@ const MarketSymbolIconRow = ({ payload, show_description }) => {

<div className='market-symbol-icon-category'>
<Popover
classNameBubble='market-symbol-icon__tooltip'
classNameTarget='category-type-icon__popover'
classNameBubble='category-type-icon__popover-bubble'
alignment='top'
message={getContractTypeDisplay(market_information.category)}
message={getTradeTypeName(market_information.category)}
disable_target_icon
>
<Icon icon='IconTradeType' type={market_information.category} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import EmptyTradeHistoryMessage from '../Components/empty-trade-history
import PlaceholderComponent from '../Components/placeholder-component.jsx';
import { ReportsMeta } from '../Components/reports-meta.jsx';
import { getProfitTableColumnsTemplate } from '../Constants/data-table-constants';
import { getMarketInformation } from '../Helpers/market-underyling';
import { getMarketInformation } from '../Helpers/market-underlying';

class ProfitTable extends React.Component {
componentDidMount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { getStatementTableColumnsTemplate } from '../Constants/data-table-consta
import PlaceholderComponent from '../Components/placeholder-component.jsx';
import { ReportsMeta } from '../Components/reports-meta.jsx';
import EmptyTradeHistoryMessage from '../Components/empty-trade-history-message.jsx';
import { getMarketInformation } from '../Helpers/market-underyling';
import { getMarketInformation } from '../Helpers/market-underlying';

class Statement extends React.Component {
componentDidMount() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { getMarketNamesMap, getContractConfig } from 'Constants';

export const getMarketInformation = (payload) => {
const market_info = {
category : '',
underlying: '',
};

const pattern = new RegExp('^([A-Z]+)_((OTC_[A-Z0-9]+)|R_[\\d]{2,3}|[A-Z]+)_'); // Used to get market name from shortcode
const extracted = pattern.exec(typeof payload === 'string' ? payload : payload.shortcode);
const extracted = pattern.exec(payload.shortcode);
if (extracted !== null) {
market_info.category = extracted[1].toLowerCase();
market_info.underlying = extracted[2];
}

return market_info;
};

export const getMarketName = (underlying) => underlying ? getMarketNamesMap()[underlying.toUpperCase()] : null;

export const getTradeTypeName = (category) => category ? getContractConfig()[category.toUpperCase()].name : null;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getUnsupportedContracts } from 'Constants';
import { getSymbolDisplayName } from '../../Trading/Helpers/active-symbols';
import { getMarketInformation } from '../../../../Modules/Reports/Helpers/market-underyling';
import { getMarketInformation } from '../../../../Modules/Reports/Helpers/market-underlying';

export const formatPortfolioPosition = (portfolio_pos, active_symbols = []) => {
const purchase = parseFloat(portfolio_pos.buy_price);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { formatMoney } from '_common/base/currency_base';
import { toMoment } from 'Utils/Date';
import { getMarketInformation } from '../../../../Modules/Reports/Helpers/market-underyling';
import { getMarketInformation } from '../../../../Modules/Reports/Helpers/market-underlying';
import { getSymbolDisplayName } from '../../Trading/Helpers/active-symbols';

export const formatProfitTableTransactions = (transaction, currency, active_symbols = []) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { localize } from '_common/localize';
import { toTitleCase } from '_common/string_util';
import { toMoment } from 'Utils/Date';
import { getSymbolDisplayName } from '../../Trading/Helpers/active-symbols';
import { getMarketInformation } from '../../../../Modules/Reports/Helpers/market-underyling';
import { getMarketInformation } from '../../../../Modules/Reports/Helpers/market-underlying';

export const formatStatementTransaction = (transaction, currency, active_symbols = []) => {
const format_string = 'DD MMM YYYY - HH:mm:ss';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,36 @@ export const getSymbolDisplayName = (active_symbols = [], symbol) => (
(active_symbols.find(symbol_info => symbol_info.symbol.toUpperCase() === symbol.toUpperCase()) || { display_name: '' })
.display_name
);

export const pickDefaultSymbol = (active_symbols = []) => {
if (!active_symbols.length) return '';
return getFavoriteOpenSymbol(active_symbols) || getFirstOpenSymbol(active_symbols);
};

const getFavoriteOpenSymbol = (active_symbols) => {
const chart_favorites = LocalStore.get('cq-favorites');
if (!chart_favorites) return undefined;
const client_favorite_markets = JSON.parse(chart_favorites)['chartTitle&Comparison'];

const client_favorite_list = client_favorite_markets
.map(client_fav_symbol => active_symbols
.find(symbol_info => symbol_info.symbol === client_fav_symbol));
if (client_favorite_list) {
const client_first_open_symbol = client_favorite_list
.filter(symbol => symbol).find(isSymbolOpen);
if (client_first_open_symbol) return client_first_open_symbol.symbol;
}
return undefined;
};

const getFirstOpenSymbol = (active_symbols) => {
const first_open_symbol = active_symbols
.filter(symbol_info => /major_pairs|random_index/.test(symbol_info.submarket))
.find(isSymbolOpen);
if (first_open_symbol) return first_open_symbol.symbol;
return active_symbols.find(symbol_info => symbol_info.submarket === 'major_pairs').symbol;
};

const isSymbolOpen = (symbol) => (
symbol.exchange_is_open === 1
);

0 comments on commit 77472a9

Please sign in to comment.