Skip to content
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

feat: update #997

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 25 additions & 30 deletions src/components/position_updated_modal/position_updated_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,39 +225,34 @@ const PositionUpdatedModal = ({
? t('POSITION_MODAL.GUARANTEED_STOP_YES')
: t('POSITION_MODAL.GUARANTEED_STOP_NO');

const displayedTakeProfit =
updatedProps?.takeProfit !== undefined
? updatedProps.takeProfit === 0
? '-'
: updatedProps.takeProfit !== 0
? `$ ${updatedProps.takeProfit.toLocaleString(
UNIVERSAL_NUMBER_FORMAT_LOCALE,
FRACTION_DIGITS
)}`
: undefined
: openCfdDetails?.takeProfit
? `$ ${openCfdDetails?.takeProfit.toLocaleString(
const displayedTakeProfit = !!updatedProps?.takeProfit
? updatedProps.takeProfit === 0
? '-'
: updatedProps.takeProfit !== 0
? `$ ${updatedProps.takeProfit.toLocaleString(
UNIVERSAL_NUMBER_FORMAT_LOCALE,
FRACTION_DIGITS
)}`
: '-';

const displayedStopLoss =
updatedProps?.stopLoss !== undefined
? updatedProps.stopLoss === 0
? '-'
: updatedProps.stopLoss !== 0
? `$ ${updatedProps.stopLoss.toLocaleString(
UNIVERSAL_NUMBER_FORMAT_LOCALE,
FRACTION_DIGITS
)}`
: undefined
: openCfdDetails?.stopLoss
? `$ ${openCfdDetails?.stopLoss.toLocaleString(
UNIVERSAL_NUMBER_FORMAT_LOCALE,
FRACTION_DIGITS
)}`
: '-';
: undefined
: openCfdDetails?.takeProfit
? `$ ${openCfdDetails?.takeProfit.toLocaleString(
UNIVERSAL_NUMBER_FORMAT_LOCALE,
FRACTION_DIGITS
)}`
: '-';

const displayedStopLoss = !!updatedProps?.stopLoss
? updatedProps.stopLoss === 0
? '-'
: updatedProps.stopLoss !== 0
? `$ ${updatedProps.stopLoss.toLocaleString(UNIVERSAL_NUMBER_FORMAT_LOCALE, FRACTION_DIGITS)}`
: undefined
: openCfdDetails?.stopLoss
? `$ ${openCfdDetails?.stopLoss.toLocaleString(
UNIVERSAL_NUMBER_FORMAT_LOCALE,
FRACTION_DIGITS
)}`
: '-';

const displayedTypeOfPosition =
openCfdDetails?.typeOfPosition === TypeOfPosition.BUY
Expand Down
8 changes: 4 additions & 4 deletions src/components/update_form_modal/update_form_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -645,13 +645,13 @@ const UpdateFormModal = ({
setTpUpperLimit(caledTpUpperLimit);

setTpValue(
openCfdDetails.takeProfit === 0 || openCfdDetails.takeProfit === undefined
openCfdDetails.takeProfit === 0 || !openCfdDetails.takeProfit
? openCfdDetails.suggestion.takeProfit
: openCfdDetails.takeProfit
);

setSlValue(
openCfdDetails.stopLoss === 0 || openCfdDetails.stopLoss === undefined
openCfdDetails.stopLoss === 0 || !openCfdDetails.stopLoss
? suggestedSl
: openCfdDetails.stopLoss
);
Expand Down Expand Up @@ -796,13 +796,13 @@ const UpdateFormModal = ({
<div className="text-lightGray">{t('POSITION_MODAL.TP_AND_SL')}</div>
<div className="">
<span className={`text-lightWhite`}>
{cfdTp === undefined || cfdTp === 0
{!cfdTp || cfdTp === 0
? '-'
: cfdTp.toLocaleString(UNIVERSAL_NUMBER_FORMAT_LOCALE, FRACTION_DIGITS)}
</span>{' '}
/{' '}
<span className={`text-lightWhite`}>
{cfdSl === undefined || cfdSl === 0
{!cfdSl || cfdSl === 0
? '-'
: cfdSl.toLocaleString(UNIVERSAL_NUMBER_FORMAT_LOCALE, FRACTION_DIGITS)}
</span>
Expand Down
19 changes: 5 additions & 14 deletions src/contexts/user_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -840,18 +840,9 @@ export const UserProvider = ({children}: IUserProvider) => {
};

const getCFD = (id: string) => {
const CFD = CFDsRef.current[id];
// Deprecate: [debug] (20230707 - tzuhan)
// eslint-disable-next-line no-console
// console.log(`getCFD CFD`, CFD);
/** Deprecate: [debug] (20230707 - tzuhan)
const histories = historiesRef.current.filter(
history => history.receipt.orderSnapshot.id === id
);
// Deprecate: [debug] (20230707 - tzuhan)
// eslint-disable-next-line no-console
console.log(`getCFD histories`, histories);
*/
let CFD: ICFDOrder | null = CFDsRef.current[id] ?? null;
if (!CFD) CFD = openCFDsRef.current.find(openCFD => openCFD.id === id) ?? null;
if (!CFD) CFD = closedCFDsRef.current.find(closeCFD => closeCFD.id === id) ?? null;
return CFD;
};

Expand Down Expand Up @@ -1049,7 +1040,7 @@ export const UserProvider = ({children}: IUserProvider) => {
try {
if (!enableServiceTermRef.current) throw new CustomError(Code.SERVICE_TERM_DISABLE);
if (!applyCloseCFDOrder) throw new CustomError(Code.INVAILD_ORDER_INPUTS);
const closeAppliedCFD = CFDs[applyCloseCFDOrder.referenceId];
const closeAppliedCFD = getCFD(applyCloseCFDOrder.referenceId);
if (!closeAppliedCFD) throw new CustomError(Code.CFD_ORDER_NOT_FOUND);
if (closeAppliedCFD.state !== OrderState.OPENING)
throw new CustomError(Code.CFD_ORDER_IS_ALREADY_CLOSED);
Expand Down Expand Up @@ -1166,7 +1157,7 @@ export const UserProvider = ({children}: IUserProvider) => {
try {
if (!enableServiceTermRef.current) throw new CustomError(Code.SERVICE_TERM_DISABLE);
if (!applyUpdateCFDOrder) throw new CustomError(Code.INVAILD_ORDER_INPUTS);
const updateAppliedCFD = CFDs[applyUpdateCFDOrder.referenceId];
const updateAppliedCFD = getCFD(applyUpdateCFDOrder.referenceId);
if (!updateAppliedCFD) throw new CustomError(Code.CFD_ORDER_NOT_FOUND);
if (updateAppliedCFD.state !== OrderState.OPENING)
throw new CustomError(Code.CFD_ORDER_IS_ALREADY_CLOSED);
Expand Down