fix(trading): when order is rejected change tx toast intent (#2851)

This commit is contained in:
m.ray 2023-02-06 06:44:04 -05:00 committed by GitHub
parent 536859e067
commit 73de2fed43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 5 deletions

View File

@ -50,6 +50,15 @@ const intentMap: { [s in VegaTxStatus]: Intent } = {
Complete: Intent.Success,
};
const getIntent = (tx: VegaStoredTxState) => {
// Transaction can be successful
// But the order can be rejected by the network
if (tx.order?.rejectionReason) {
return Intent.Danger;
}
return intentMap[tx.status];
};
const isClosePositionTransaction = (tx: VegaStoredTxState) => {
if (isBatchMarketInstructionsTransaction(tx.body)) {
const amendments =
@ -461,6 +470,26 @@ const VegaTxCompleteToastsContent = ({ tx }: VegaTxToastContentProps) => {
);
}
if (isOrderSubmissionTransaction(tx.body) && tx.order?.rejectionReason) {
return (
<div>
<h3 className="font-bold">{t('Order rejected')}</h3>
<p>{t('Your order was rejected.')}</p>
{tx.txHash && (
<p className="break-all">
<ExternalLink
href={explorerLink(EXPLORER_TX.replace(':hash', tx.txHash))}
rel="noreferrer"
>
{t('View in block explorer')}
</ExternalLink>
</p>
)}
<VegaTransactionDetails tx={tx} />
</div>
);
}
return (
<div>
<h3 className="font-bold">{t('Confirmed')}</h3>
@ -545,7 +574,7 @@ export const useVegaTransactionToasts = () => {
}
return {
id: `vega-${tx.id}`,
intent: intentMap[tx.status],
intent: getIntent(tx),
onClose: () => dismissVegaTransaction(tx.id),
loader: tx.status === VegaTxStatus.Pending,
content,

View File

@ -19,7 +19,6 @@ import {
signedNumberCssClassRules,
DateRangeFilter,
addDecimalsFormatNumber,
PriceCell,
} from '@vegaprotocol/react-helpers';
import { AgGridDynamic as AgGrid, Link } from '@vegaprotocol/ui-toolkit';
import { AgGridColumn } from 'ag-grid-react';
@ -85,7 +84,7 @@ export const PositionsTable = forwardRef<AgGridReact, Props>(
filterParams: { buttons: ['reset'] },
tooltipComponent: TooltipCellComponent,
}}
components={{ AmountCell, PriceFlashCell, PriceCell, ProgressBarCell }}
components={{ AmountCell, PriceFlashCell, ProgressBarCell }}
{...props}
>
<AgGridColumn
@ -336,7 +335,6 @@ export const PositionsTable = forwardRef<AgGridReact, Props>(
? undefined
: addDecimalsFormatNumber(data.realisedPNL, data.decimals);
}}
cellRenderer="PriceCell"
headerTooltip={t(
'Profit or loss is realised whenever your position is reduced to zero and the margin is released back to your collateral balance. P&L excludes any fees paid.'
)}
@ -361,7 +359,6 @@ export const PositionsTable = forwardRef<AgGridReact, Props>(
? undefined
: addDecimalsFormatNumber(data.unrealisedPNL, data.decimals)
}
cellRenderer="PriceCell"
headerTooltip={t(
'Unrealised profit is the current profit on your open position. Margin is still allocated to your position.'
)}