-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
maryia/87383/feat: connected proposal API + updated trade params #75
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ export const CONTRACT_SHADES = { | |
ASIAND: 'BELOW', | ||
MULTUP: 'ABOVE', | ||
MULTDOWN: 'BELOW', | ||
TURBOSLONG: 'ABOVE', | ||
TURBOSSHORT: 'BELOW', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added barriers for Turbos here so that they appear on the chart |
||
}; | ||
|
||
// Default non-shade according to number of barriers | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,17 +128,24 @@ export const getContractTypesConfig: TGetContractTypesConfig = symbol => ({ | |
], | ||
config: { hide_duration: true }, | ||
}, // hide Duration for Multiplier contracts for now | ||
turbos: { | ||
title: localize('Turbos'), | ||
trade_types: ['TURBOSLONG', 'TURBOSSHORT'], | ||
turboslong: { | ||
title: localize('Long'), | ||
trade_types: ['TURBOSLONG'], | ||
basis: ['stake'], | ||
barrier_count: 1, | ||
components: ['take_profit'], | ||
components: ['barrier', 'take_profit'], | ||
}, | ||
turbosshort: { | ||
title: localize('Short'), | ||
trade_types: ['TURBOSSHORT'], | ||
basis: ['stake'], | ||
barrier_count: 1, | ||
components: ['barrier', 'take_profit'], | ||
}, | ||
}); | ||
|
||
export const getContractCategoriesConfig = () => ({ | ||
Turbos: { name: localize('Turbos'), categories: ['turbos'] }, | ||
Turbos: { name: localize('Turbos'), categories: ['turboslong', 'turbosshort'] }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'turboslong' and 'turbosshort' are separate categories of Turbos trade type |
||
Multipliers: { name: localize('Multipliers'), categories: ['multiplier'] }, | ||
'Ups & Downs': { | ||
name: localize('Ups & Downs'), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ const PurchaseFieldset = ({ | |
is_multiplier, | ||
is_proposal_empty, | ||
is_proposal_error, | ||
is_turbos, | ||
purchased_states_arr, | ||
onClickPurchase, | ||
onHoverPurchase, | ||
|
@@ -38,7 +39,7 @@ const PurchaseFieldset = ({ | |
<PurchaseButton | ||
buy_info={buy_info} | ||
currency={currency} | ||
info={info} | ||
info={!is_turbos && info} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hiding info from purchase button for Turbos |
||
index={index} | ||
has_deal_cancellation={is_multiplier && has_cancellation} | ||
is_disabled={is_disabled} | ||
|
@@ -154,6 +155,7 @@ PurchaseFieldset.propTypes = { | |
is_multiplier: PropTypes.bool, | ||
is_proposal_empty: PropTypes.bool, | ||
is_proposal_error: PropTypes.bool, | ||
is_turbos: PropTypes.bool, | ||
onClickPurchase: PropTypes.func, | ||
onHoverPurchase: PropTypes.func, | ||
purchased_states_arr: PropTypes.array, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ const Amount = ({ | |
is_multiplier, | ||
is_nativepicker, | ||
is_single_currency, | ||
is_turbos, | ||
has_equals_only, | ||
onChange, | ||
setCurrentFocus, | ||
|
@@ -95,7 +96,7 @@ const Amount = ({ | |
return ( | ||
<Fieldset | ||
className='trade-container__fieldset center-text' | ||
header={is_multiplier ? localize('Stake') : undefined} | ||
header={is_multiplier || is_turbos ? localize('Stake') : undefined} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Showing Stake above the stake input for Turbos as well |
||
header_tooltip={ | ||
is_multiplier ? ( | ||
<Localize i18n_default_text='Your gross profit is the percentage change in market price times your stake and the multiplier chosen here.' /> | ||
|
@@ -191,6 +192,7 @@ Amount.propTypes = { | |
is_multiplier: PropTypes.bool, | ||
is_nativepicker: PropTypes.bool, | ||
is_single_currency: PropTypes.bool, | ||
is_turbos: PropTypes.bool, | ||
has_equals_only: PropTypes.bool, | ||
setCurrentFocus: PropTypes.func, | ||
onChange: PropTypes.func, | ||
|
@@ -212,6 +214,7 @@ export default connect(({ modules, client, ui }) => ({ | |
is_equal: modules.trade.is_equal, | ||
is_single_currency: client.is_single_currency, | ||
is_multiplier: modules.trade.is_multiplier, | ||
is_turbos: modules.trade.is_turbos, | ||
has_equals_only: modules.trade.has_equals_only, | ||
stop_out: modules.trade.stop_out, | ||
onChange: modules.trade.onChange, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ export const CONTRACT_SHADES = { | |
ASIAND: 'BELOW', | ||
MULTUP: 'ABOVE', | ||
MULTDOWN: 'BELOW', | ||
TURBOSLONG: 'ABOVE', | ||
TURBOSSHORT: 'BELOW', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added barriers for Turbos here so that they appear on the chart |
||
}; | ||
|
||
// Default non-shade according to number of barriers | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { getDecimalPlaces, getPropertyValue, convertToUnix, toMoment } from '@deriv/shared'; | ||
import { getDecimalPlaces, getPropertyValue, convertToUnix, isTurbosContract, toMoment } from '@deriv/shared'; | ||
|
||
const isVisible = elem => !(!elem || (elem.offsetWidth === 0 && elem.offsetHeight === 0)); | ||
|
||
|
@@ -41,6 +41,10 @@ export const getProposalInfo = (store, response, obj_prev_contract_basis) => { | |
|
||
const commission = proposal.commission; | ||
const cancellation = proposal.cancellation; | ||
const turbos_details = { | ||
barrier_choices: proposal.barrier_choices || response?.error?.details?.barrier_choices, | ||
number_of_contracts: proposal.number_of_contracts, | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. values specific for Turbos that we extract from proposal response |
||
|
||
return { | ||
commission, | ||
|
@@ -58,6 +62,7 @@ export const getProposalInfo = (store, response, obj_prev_contract_basis) => { | |
profit: profit.toFixed(getDecimalPlaces(store.currency)), | ||
returns: `${returns.toFixed(2)}%`, | ||
stake, | ||
...turbos_details, | ||
}; | ||
}; | ||
|
||
|
@@ -90,6 +95,7 @@ const setProposalMultiplier = (store, obj_multiplier) => { | |
const createProposalRequestForContract = (store, type_of_contract) => { | ||
const obj_expiry = {}; | ||
const obj_multiplier = {}; | ||
let limit_order; | ||
|
||
if (store.expiry_type === 'endtime') { | ||
const expiry_date = toMoment(store.expiry_date); | ||
|
@@ -100,6 +106,10 @@ const createProposalRequestForContract = (store, type_of_contract) => { | |
setProposalMultiplier(store, obj_multiplier); | ||
} | ||
|
||
if (isTurbosContract(store.contract_type) && store.has_take_profit && store.take_profit) { | ||
limit_order = { take_profit: +store.take_profit || 0 }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setting take profit for Turbos to send it in proposal request |
||
} | ||
|
||
return { | ||
proposal: 1, | ||
subscribe: 1, | ||
|
@@ -120,5 +130,6 @@ const createProposalRequestForContract = (store, type_of_contract) => { | |
}), | ||
...(store.barrier_count === 2 && { barrier2: store.barrier_2 }), | ||
...obj_multiplier, | ||
limit_order, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import { | |
getBarrierPipSize, | ||
isBarrierSupported, | ||
removeBarrier, | ||
isTurbosContract, | ||
} from '@deriv/shared'; | ||
import { localize } from '@deriv/translations'; | ||
import { getValidationRules, getMultiplierValidationRules } from 'Stores/Modules/Trading/Constants/validation-rules'; | ||
|
@@ -131,6 +132,7 @@ export default class TradeStore extends BaseStore { | |
cancellation_range_list = []; | ||
|
||
// Turbos trade params | ||
number_of_contracts = 0; | ||
turbos_barrier_choices = []; | ||
|
||
// Mobile | ||
|
@@ -275,6 +277,7 @@ export default class TradeStore extends BaseStore { | |
requestProposal: action.bound, | ||
forgetAllProposal: action.bound, | ||
setMarketStatus: action.bound, | ||
number_of_contracts: observable, | ||
onProposalResponse: action.bound, | ||
onChartBarrierChange: action.bound, | ||
onAllowEqualsChange: action.bound, | ||
|
@@ -297,6 +300,7 @@ export default class TradeStore extends BaseStore { | |
chartStateChange: action.bound, | ||
has_alternative_source: computed, | ||
is_multiplier: computed, | ||
is_turbos: computed, | ||
getFirstOpenMarket: action.bound, | ||
}); | ||
|
||
|
@@ -343,7 +347,7 @@ export default class TradeStore extends BaseStore { | |
() => [this.contract_type], | ||
() => { | ||
this.root_store.portfolio.setContractType(this.contract_type); | ||
if (this.contract_type === 'multiplier') { | ||
if (this.contract_type === 'multiplier' || this.is_turbos) { | ||
// when switching back to Multiplier contract, re-apply Stop loss / Take profit validation rules | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. validating take profit field for Turbos as well as for Multipliers |
||
Object.assign(this.validation_rules, getMultiplierValidationRules()); | ||
} else { | ||
|
@@ -680,6 +684,7 @@ export default class TradeStore extends BaseStore { | |
// create barrier only when it's available in response | ||
this.main_barrier = new ChartBarrierStore(barrier || high_barrier, low_barrier, this.onChartBarrierChange, { | ||
color, | ||
not_draggable: isTurbosContract(contract_type), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. made barrier on the chart non-draggable for Turbos |
||
}); | ||
// this.main_barrier.updateBarrierShade(true, contract_type); | ||
} else { | ||
|
@@ -1039,6 +1044,23 @@ export default class TradeStore extends BaseStore { | |
this.stop_out = limit_order?.stop_out?.order_amount; | ||
} | ||
|
||
if (this.is_turbos && this.proposal_info) { | ||
const contract_key = this.contract_type.toUpperCase(); | ||
if (this.proposal_info[contract_key]) { | ||
const { barrier_choices, number_of_contracts } = this.proposal_info[contract_key]; | ||
this.turbos_barrier_choices = barrier_choices || []; | ||
this.number_of_contracts = number_of_contracts ?? 0; | ||
if (barrier_choices && !barrier_choices.includes(this.barrier_1)) { | ||
this.onChange({ | ||
target: { | ||
name: 'barrier_1', | ||
value: barrier_choices[0], | ||
}, | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extracting necessary data for Turbos from proposal and setting them in trade-store. |
||
} | ||
} | ||
|
||
if (!this.main_barrier || !(this.main_barrier.shade !== 'NONE_SINGLE')) { | ||
this.setMainBarrier(response.echo_req); | ||
} | ||
|
@@ -1361,6 +1383,10 @@ export default class TradeStore extends BaseStore { | |
return this.contract_type === 'multiplier'; | ||
} | ||
|
||
get is_turbos() { | ||
return isTurbosContract(this.contract_type); | ||
} | ||
|
||
async getFirstOpenMarket(markets_to_search) { | ||
if (this.active_symbols?.length) { | ||
return findFirstOpenMarket(this.active_symbols, markets_to_search); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for Turbos we need only take_profit, not entire limit_order object