vega-frontend-monorepo/libs/web3/src/lib/ethereum-transaction-dialog/ethereum-transaction-dialog.tsx
Matthew Russell 5eb06254de
feat (#896): large withdraws (#1180)
* feat: add deposits table to deposits tab on portfolio page

* feat: refactor use-withdraw hook to not invoke eth tx

* feat: rename hook for clarity

* feat: fix withdrawal creation test

* feat: update withdraw-manager and withrawals-table tests

* chore: fix lint

* feat: remove web3 input to avoid double dialog

* chore: use renderHook from testing-library/react

* chore: update to use non deprecated fields

* chore: remove usage of all bridge contract

* feat: correctly merge cache update in withdrawals table

* feat: changes to support token app withdrawals

* chore: add height to ag grid table wrapping element

* feat: add txhash col to withdraw table

* feat: provide better ui if withdrawal is not ready to be completed

* feat: use separate dialogs for txs

* feat: allow user to immediately complete withdrawal if delay not triggered

* feat: add withdraw store to tidy up state management

* chore: fix tests

* chore: convert callback to promises, fix tests, delete withdraw page

* chore: fix lint errors

* fix: withdrawals link in nav

* feat: style changes after design update

* fix: proposal form test

* chore: tidy error ui logic

* feat: review comments

* chore: lint

* feat: add better typing for tables

* chore: put withdrawals tab at the end

* chore: update i18n

* fix: dialog in positions manager due to rename

* chore: increase spacing in withdrawal form

* chore: update tests

* chore: lint

* chore: use new assetsConnection and update cy test

* fix: incorrect shape of withdrawal generate function

* feat: delete withdrawals page now that its shown on the portfolio page

* chore: update tests to check for withdrawals page

* chore: fix tests again

* fix: page title test
2022-09-05 18:30:13 -07:00

126 lines
3.1 KiB
TypeScript

import { t } from '@vegaprotocol/react-helpers';
import { Dialog, Icon, Intent, Loader } from '@vegaprotocol/ui-toolkit';
import { isEthereumError } from '../ethereum-error';
import type { EthTxState, TxError } from '../use-ethereum-transaction';
import { EthTxStatus } from '../use-ethereum-transaction';
import { ConfirmRow, TxRow, ConfirmationEventRow } from './dialog-rows';
export interface EthereumTransactionDialogProps {
title: string;
onChange: (isOpen: boolean) => void;
transaction: EthTxState;
// Undefined means this dialog isn't expecting an additional event for a complete state, a boolean
// value means it is but hasn't been received yet
requiredConfirmations?: number;
}
export const EthereumTransactionDialog = ({
onChange,
title,
transaction,
requiredConfirmations = 1,
}: EthereumTransactionDialogProps) => {
const { status, error, confirmations, txHash } = transaction;
return (
<Dialog
open={transaction.dialogOpen}
onChange={onChange}
size="small"
{...getWrapperProps(title, status)}
>
<TransactionContent
status={status}
error={error}
txHash={txHash}
confirmations={confirmations}
requiredConfirmations={requiredConfirmations}
/>
</Dialog>
);
};
export const TransactionContent = ({
status,
error,
txHash,
confirmations,
requiredConfirmations = 1,
}: {
status: EthTxStatus;
error: TxError | null;
txHash: string | null;
confirmations: number;
requiredConfirmations?: number;
}) => {
if (status === EthTxStatus.Error) {
let errorMessage = '';
if (isEthereumError(error)) {
errorMessage = error.reason;
} else if (error instanceof Error) {
errorMessage = error.message;
}
return (
<p className="break-all">
{t('Error')}: {errorMessage}
</p>
);
}
return (
<div className="text-sm">
<ConfirmRow status={status} />
<TxRow
status={status}
txHash={txHash}
confirmations={confirmations}
requiredConfirmations={requiredConfirmations}
highlightComplete={false}
/>
<ConfirmationEventRow status={status} />
</div>
);
};
export const getWrapperProps = (title: string, status: EthTxStatus) => {
const propsMap = {
[EthTxStatus.Default]: {
title: '',
icon: null,
intent: undefined,
},
[EthTxStatus.Error]: {
title: t(`${title} failed`),
icon: <Icon name="warning-sign" />,
intent: Intent.Danger,
},
[EthTxStatus.Requested]: {
title: t('Confirm transaction'),
icon: <Icon name="hand-up" />,
intent: Intent.Warning,
},
[EthTxStatus.Pending]: {
title: t(`${title} pending`),
icon: (
<span className="mt-1">
<Loader size="small" />
</span>
),
intent: Intent.None,
},
[EthTxStatus.Complete]: {
title: t(`${title} pending`),
icon: <Loader size="small" />,
intent: Intent.None,
},
[EthTxStatus.Confirmed]: {
title: t(`${title} complete`),
icon: <Icon name="tick" />,
intent: Intent.Success,
},
};
return propsMap[status];
};