forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from ahmadtaimoor-deriv/f_contract_details
chore: Cancel Close Contracts and TP,SL actions
- Loading branch information
Showing
15 changed files
with
362 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 71 additions & 3 deletions
74
packages/trader/src/AppV2/Components/ContractDetailsFooter/contract-details-footer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,80 @@ | ||
import { Button } from '@deriv-com/quill-ui'; | ||
import { TContractInfo, getCardLabels, isMultiplierContract, isValidToCancel, isValidToSell } from '@deriv/shared'; | ||
import { useStore } from '@deriv/stores'; | ||
import { getRemainingTime } from 'AppV2/Utils/helper'; | ||
import { observer } from 'mobx-react'; | ||
import React from 'react'; | ||
|
||
const ContractDetailsFooter = () => { | ||
type ContractInfoProps = { | ||
contract_info: TContractInfo; | ||
}; | ||
|
||
const ContractDetailsFooter = observer(({ contract_info }: ContractInfoProps) => { | ||
const { | ||
bid_price, | ||
currency, | ||
contract_id, | ||
cancellation: { date_expiry: cancellation_date_expiry } = {}, | ||
profit, | ||
contract_type, | ||
} = contract_info; | ||
|
||
const { contract_replay, common } = useStore(); | ||
const { server_time } = common; | ||
const { onClickCancel, onClickSell, is_sell_requested } = contract_replay; | ||
const is_valid_to_sell = isValidToSell(contract_info); | ||
const is_valid_to_cancel = isValidToCancel(contract_info); | ||
const is_multiplier = isMultiplierContract(contract_type); | ||
|
||
return ( | ||
<div className='contract-details-footer--container'> | ||
<Button variant='secondary' label='Close @ 9.00 USD' color='black' size='lg' fullWidth /> | ||
{is_multiplier ? ( | ||
<> | ||
<Button | ||
variant='secondary' | ||
label={`${getCardLabels().CLOSE} ${!is_valid_to_cancel ? `@${bid_price} ${currency}` : ''}`} | ||
color='black' | ||
size='lg' | ||
isLoading={is_sell_requested} | ||
disabled={is_sell_requested || (Number(profit) < 0 && is_valid_to_cancel)} | ||
onClick={() => onClickSell(contract_id)} | ||
fullWidth | ||
/> | ||
{is_valid_to_cancel && ( | ||
<Button | ||
onClick={() => onClickCancel(contract_id)} | ||
variant='secondary' | ||
label={`${getCardLabels().CANCEL} ${getRemainingTime({ | ||
end_time: cancellation_date_expiry, | ||
format: 'mm:ss', | ||
getCardLabels, | ||
start_time: server_time, | ||
})}`} | ||
color='black' | ||
disabled={Number(profit) >= 0} | ||
size='lg' | ||
fullWidth | ||
/> | ||
)} | ||
</> | ||
) : ( | ||
<Button | ||
variant='secondary' | ||
label={ | ||
is_valid_to_sell | ||
? `${getCardLabels().CLOSE} @ ${bid_price} ${currency}` | ||
: getCardLabels().RESALE_NOT_OFFERED | ||
} | ||
color='black' | ||
size='lg' | ||
isLoading={is_sell_requested && is_valid_to_sell} | ||
onClick={is_valid_to_sell ? () => onClickSell(contract_id) : undefined} | ||
fullWidth | ||
disabled={!is_valid_to_sell} | ||
/> | ||
)} | ||
</div> | ||
); | ||
}; | ||
}); | ||
|
||
export default ContractDetailsFooter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.