chore: tidy up

This commit is contained in:
asiaznik
2023-01-19 12:28:26 +01:00
parent c6b440882b
commit 9aa79fefa4
3 changed files with 1 additions and 171 deletions
@@ -1,128 +0,0 @@
import { useCallback, useMemo } from 'react';
import type { ReactNode } from 'react';
import type { VegaTxState } from '@vegaprotocol/wallet';
import {
WalletError,
useVegaWallet,
useVegaWalletDialogStore,
ClientErrors,
} from '@vegaprotocol/wallet';
import * as Schema from '@vegaprotocol/types';
import { Button, Icon, Intent } from '@vegaprotocol/ui-toolkit';
import { t } from '@vegaprotocol/react-helpers';
interface ErrorContentProps {
transaction: VegaTxState;
reset: () => void;
}
export const ErrorContent = ({ transaction, reset }: ErrorContentProps) => {
const { openVegaWalletDialog } = useVegaWalletDialogStore((store) => ({
openVegaWalletDialog: store.openVegaWalletDialog,
}));
const { disconnect } = useVegaWallet();
const reconnect = useCallback(async () => {
reset();
await disconnect();
openVegaWalletDialog();
}, [reset, disconnect, openVegaWalletDialog]);
return useMemo(() => {
const { error } = transaction;
if (error) {
if (
error instanceof WalletError &&
error.code === ClientErrors.NO_SERVICE.code
) {
return (
<ul data-testid="connectors-list" className="mb-6">
<li className="mb-2 last:mb-0" data-testid={transaction.status}>
{t('The connection to your Vega Wallet has been lost.')}
</li>
<li className="mb-0 pt-2">
<Button onClick={reconnect}>{t('Connect vega wallet')}</Button>
</li>
</ul>
);
}
return (
<p data-testid={transaction.status}>
{error.message}{' '}
{error instanceof WalletError ? `: ${error.data}` : null}
</p>
);
}
return null;
}, [transaction, reconnect]);
};
export const getOrderDialogTitle = (
status?: Schema.OrderStatus
): string | undefined => {
if (!status) {
return;
}
switch (status) {
case Schema.OrderStatus.STATUS_ACTIVE:
return t('Order submitted');
case Schema.OrderStatus.STATUS_FILLED:
return t('Order filled');
case Schema.OrderStatus.STATUS_PARTIALLY_FILLED:
return t('Order partially filled');
case Schema.OrderStatus.STATUS_PARKED:
return t('Order parked');
case Schema.OrderStatus.STATUS_STOPPED:
return t('Order stopped');
case Schema.OrderStatus.STATUS_CANCELLED:
return t('Order cancelled');
case Schema.OrderStatus.STATUS_EXPIRED:
return t('Order expired');
case Schema.OrderStatus.STATUS_REJECTED:
return t('Order rejected');
default:
return t('Submission failed');
}
};
export const getOrderDialogIntent = (
status?: Schema.OrderStatus
): Intent | undefined => {
if (!status) {
return;
}
switch (status) {
case Schema.OrderStatus.STATUS_PARKED:
case Schema.OrderStatus.STATUS_EXPIRED:
case Schema.OrderStatus.STATUS_PARTIALLY_FILLED:
return Intent.Warning;
case Schema.OrderStatus.STATUS_REJECTED:
case Schema.OrderStatus.STATUS_STOPPED:
case Schema.OrderStatus.STATUS_CANCELLED:
return Intent.Danger;
case Schema.OrderStatus.STATUS_FILLED:
case Schema.OrderStatus.STATUS_ACTIVE:
return Intent.Success;
default:
return;
}
};
export const getOrderDialogIcon = (
status?: Schema.OrderStatus
): ReactNode | undefined => {
if (!status) {
return;
}
switch (status) {
case Schema.OrderStatus.STATUS_PARKED:
case Schema.OrderStatus.STATUS_EXPIRED:
return <Icon name="warning-sign" />;
case Schema.OrderStatus.STATUS_REJECTED:
case Schema.OrderStatus.STATUS_STOPPED:
case Schema.OrderStatus.STATUS_CANCELLED:
return <Icon name="error" />;
default:
return;
}
};
@@ -1,7 +1,6 @@
export * from './deal-ticket-amount';
export * from './deal-ticket-container';
export * from './deal-ticket-limit-amount';
export * from './deal-ticket-status';
export * from './deal-ticket-market-amount';
export * from './deal-ticket';
export * from './expiry-selector';
+1 -42
View File
@@ -1,9 +1,8 @@
import { useRef } from 'react';
import { AsyncRenderer, Icon, Intent } from '@vegaprotocol/ui-toolkit';
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
import { usePositionsData, PositionsTable } from '../';
import type { AgGridReact } from 'ag-grid-react';
import * as Schema from '@vegaprotocol/types';
import type { TransactionResult } from '@vegaprotocol/wallet';
import { useVegaTransactionStore } from '@vegaprotocol/wallet';
import { t } from '@vegaprotocol/react-helpers';
@@ -60,43 +59,3 @@ export const PositionsManager = ({ partyId }: PositionsManagerProps) => {
</div>
);
};
export const getDialogIntent = (transactionResult?: TransactionResult) => {
if (!transactionResult) {
return;
}
if (
transactionResult &&
'error' in transactionResult &&
transactionResult.error
) {
return Intent.Danger;
}
return Intent.Success;
};
export const getDialogIcon = (transactionResult?: TransactionResult) => {
if (!transactionResult) {
return;
}
if (transactionResult.status) {
return <Icon name="tick" />;
}
return <Icon name="error" />;
};
export const getDialogTitle = (transactionResult?: TransactionResult) => {
if (!transactionResult) {
return;
}
if (transactionResult.status) {
return t('Position closed');
}
return t('Position not closed');
};