fix(governance): added toasts for withdrawals (#3621)
This commit is contained in:
parent
91e3460e9d
commit
7a5c6f3a25
@ -20,12 +20,17 @@ import type { EthereumConfig } from '@vegaprotocol/web3';
|
|||||||
import {
|
import {
|
||||||
createConnectors,
|
createConnectors,
|
||||||
useEthTransactionManager,
|
useEthTransactionManager,
|
||||||
|
useEthTransactionUpdater,
|
||||||
useEthWithdrawApprovalsManager,
|
useEthWithdrawApprovalsManager,
|
||||||
useWeb3ConnectStore,
|
useWeb3ConnectStore,
|
||||||
} from '@vegaprotocol/web3';
|
} from '@vegaprotocol/web3';
|
||||||
import { Web3Provider } from '@vegaprotocol/web3';
|
import { Web3Provider } from '@vegaprotocol/web3';
|
||||||
import { VegaWalletDialogs } from './components/vega-wallet-dialogs';
|
import { VegaWalletDialogs } from './components/vega-wallet-dialogs';
|
||||||
import { VegaWalletProvider } from '@vegaprotocol/wallet';
|
import {
|
||||||
|
useVegaTransactionManager,
|
||||||
|
useVegaTransactionUpdater,
|
||||||
|
VegaWalletProvider,
|
||||||
|
} from '@vegaprotocol/wallet';
|
||||||
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useEthereumConfig } from '@vegaprotocol/web3';
|
import { useEthereumConfig } from '@vegaprotocol/web3';
|
||||||
import {
|
import {
|
||||||
@ -37,6 +42,7 @@ import { ENV } from './config';
|
|||||||
import type { InMemoryCacheConfig } from '@apollo/client';
|
import type { InMemoryCacheConfig } from '@apollo/client';
|
||||||
import { WithdrawalDialog } from '@vegaprotocol/withdraws';
|
import { WithdrawalDialog } from '@vegaprotocol/withdraws';
|
||||||
import { SplashLoader } from './components/splash-loader';
|
import { SplashLoader } from './components/splash-loader';
|
||||||
|
import { ToastsManager } from './toasts-manager';
|
||||||
|
|
||||||
const cache: InMemoryCacheConfig = {
|
const cache: InMemoryCacheConfig = {
|
||||||
typePolicies: {
|
typePolicies: {
|
||||||
@ -81,7 +87,10 @@ const Web3Container = ({
|
|||||||
providerUrl: string;
|
providerUrl: string;
|
||||||
}) => {
|
}) => {
|
||||||
const InitializeHandlers = () => {
|
const InitializeHandlers = () => {
|
||||||
|
useVegaTransactionManager();
|
||||||
|
useVegaTransactionUpdater();
|
||||||
useEthTransactionManager();
|
useEthTransactionManager();
|
||||||
|
useEthTransactionUpdater();
|
||||||
useEthWithdrawApprovalsManager();
|
useEthWithdrawApprovalsManager();
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
@ -135,6 +144,7 @@ const Web3Container = ({
|
|||||||
<NetworkInfo />
|
<NetworkInfo />
|
||||||
</footer>
|
</footer>
|
||||||
</AppLayout>
|
</AppLayout>
|
||||||
|
<ToastsManager />
|
||||||
<InitializeHandlers />
|
<InitializeHandlers />
|
||||||
<VegaWalletDialogs />
|
<VegaWalletDialogs />
|
||||||
<TransactionModal />
|
<TransactionModal />
|
||||||
|
17
apps/governance/src/toasts-manager.tsx
Normal file
17
apps/governance/src/toasts-manager.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { ToastsContainer, useToasts } from '@vegaprotocol/ui-toolkit';
|
||||||
|
import {
|
||||||
|
useEthereumTransactionToasts,
|
||||||
|
useEthereumWithdrawApprovalsToasts,
|
||||||
|
useVegaTransactionToasts,
|
||||||
|
} from '@vegaprotocol/web3';
|
||||||
|
|
||||||
|
export const ToastsManager = () => {
|
||||||
|
useVegaTransactionToasts();
|
||||||
|
useEthereumTransactionToasts();
|
||||||
|
useEthereumWithdrawApprovalsToasts();
|
||||||
|
|
||||||
|
const toasts = useToasts((store) => store.toasts);
|
||||||
|
return <ToastsContainer order="desc" toasts={toasts} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ToastsManager;
|
@ -1,8 +1,8 @@
|
|||||||
import { ToastsContainer, useToasts } from '@vegaprotocol/ui-toolkit';
|
import { ToastsContainer, useToasts } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useUpdateNetworkParametersToasts } from '@vegaprotocol/proposals';
|
import { useUpdateNetworkParametersToasts } from '@vegaprotocol/proposals';
|
||||||
import { useVegaTransactionToasts } from '../lib/hooks/use-vega-transaction-toasts';
|
import { useVegaTransactionToasts } from '@vegaprotocol/web3';
|
||||||
import { useEthereumTransactionToasts } from '../lib/hooks/use-ethereum-transaction-toasts';
|
import { useEthereumTransactionToasts } from '@vegaprotocol/web3';
|
||||||
import { useEthereumWithdrawApprovalsToasts } from '../lib/hooks/use-ethereum-withdraw-approval-toasts';
|
import { useEthereumWithdrawApprovalsToasts } from '@vegaprotocol/web3';
|
||||||
|
|
||||||
export const ToastsManager = () => {
|
export const ToastsManager = () => {
|
||||||
useUpdateNetworkParametersToasts();
|
useUpdateNetworkParametersToasts();
|
||||||
|
@ -22,3 +22,7 @@ export * from './lib/web3-connect-dialog';
|
|||||||
export * from './lib/web3-connect-store';
|
export * from './lib/web3-connect-store';
|
||||||
export * from './lib/web3-connectors';
|
export * from './lib/web3-connectors';
|
||||||
export * from './lib/web3-provider';
|
export * from './lib/web3-provider';
|
||||||
|
export * from './lib/use-vega-transaction-toasts';
|
||||||
|
export * from './lib/use-ethereum-transaction-toasts';
|
||||||
|
export * from './lib/use-ethereum-withdraw-approval-toasts';
|
||||||
|
export * from './lib/withdrawal-approval-status';
|
||||||
|
@ -11,13 +11,11 @@ import { useToasts } from '@vegaprotocol/ui-toolkit';
|
|||||||
import { Intent, ProgressBar } from '@vegaprotocol/ui-toolkit';
|
import { Intent, ProgressBar } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import compact from 'lodash/compact';
|
import compact from 'lodash/compact';
|
||||||
import type { EthStoredTxState } from '@vegaprotocol/web3';
|
import type { EthStoredTxState } from './use-ethereum-transaction-store';
|
||||||
import {
|
import { EthTxStatus } from './use-ethereum-transaction';
|
||||||
EthTxStatus,
|
import { isEthereumError } from './ethereum-error';
|
||||||
isEthereumError,
|
import { TransactionContent } from './ethereum-transaction-dialog';
|
||||||
TransactionContent,
|
import { useEthTransactionStore } from './use-ethereum-transaction-store';
|
||||||
useEthTransactionStore,
|
|
||||||
} from '@vegaprotocol/web3';
|
|
||||||
|
|
||||||
const intentMap: { [s in EthTxStatus]: Intent } = {
|
const intentMap: { [s in EthTxStatus]: Intent } = {
|
||||||
Default: Intent.Primary,
|
Default: Intent.Primary,
|
@ -6,11 +6,12 @@ import { Panel } from '@vegaprotocol/ui-toolkit';
|
|||||||
import { CLOSE_AFTER } from '@vegaprotocol/ui-toolkit';
|
import { CLOSE_AFTER } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useToasts } from '@vegaprotocol/ui-toolkit';
|
import { useToasts } from '@vegaprotocol/ui-toolkit';
|
||||||
import { Intent } from '@vegaprotocol/ui-toolkit';
|
import { Intent } from '@vegaprotocol/ui-toolkit';
|
||||||
import { ApprovalStatus, VerificationStatus } from '@vegaprotocol/withdraws';
|
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import compact from 'lodash/compact';
|
import compact from 'lodash/compact';
|
||||||
import type { EthWithdrawalApprovalState } from '@vegaprotocol/web3';
|
import type { EthWithdrawalApprovalState } from './use-ethereum-withdraw-approvals-store';
|
||||||
import { useEthWithdrawApprovalsStore } from '@vegaprotocol/web3';
|
import { useEthWithdrawApprovalsStore } from './use-ethereum-withdraw-approvals-store';
|
||||||
|
import { ApprovalStatus } from './use-ethereum-withdraw-approvals-store';
|
||||||
|
import { VerificationStatus } from './withdrawal-approval-status';
|
||||||
|
|
||||||
const intentMap: { [s in ApprovalStatus]: Intent } = {
|
const intentMap: { [s in ApprovalStatus]: Intent } = {
|
||||||
Pending: Intent.Warning,
|
Pending: Intent.Warning,
|
@ -37,7 +37,7 @@ import {
|
|||||||
} from '@vegaprotocol/utils';
|
} from '@vegaprotocol/utils';
|
||||||
import { t } from '@vegaprotocol/i18n';
|
import { t } from '@vegaprotocol/i18n';
|
||||||
import { useAssetsDataProvider } from '@vegaprotocol/assets';
|
import { useAssetsDataProvider } from '@vegaprotocol/assets';
|
||||||
import { useEthWithdrawApprovalsStore } from '@vegaprotocol/web3';
|
import { useEthWithdrawApprovalsStore } from './use-ethereum-withdraw-approvals-store';
|
||||||
import { DApp, EXPLORER_TX, useLinks } from '@vegaprotocol/environment';
|
import { DApp, EXPLORER_TX, useLinks } from '@vegaprotocol/environment';
|
||||||
import {
|
import {
|
||||||
getOrderToastIntent,
|
getOrderToastIntent,
|
36
libs/web3/src/lib/withdrawal-approval-status.tsx
Normal file
36
libs/web3/src/lib/withdrawal-approval-status.tsx
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { t } from '@vegaprotocol/i18n';
|
||||||
|
import { getDateTimeFormat } from '@vegaprotocol/utils';
|
||||||
|
import type { EthWithdrawalApprovalState } from './use-ethereum-withdraw-approvals-store';
|
||||||
|
import { ApprovalStatus } from './use-ethereum-withdraw-approvals-store';
|
||||||
|
|
||||||
|
export const VerificationStatus = ({
|
||||||
|
state,
|
||||||
|
}: {
|
||||||
|
state: EthWithdrawalApprovalState;
|
||||||
|
}) => {
|
||||||
|
if (state.status === ApprovalStatus.Error) {
|
||||||
|
return <p>{state.message || t('Something went wrong')}</p>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.status === ApprovalStatus.Pending) {
|
||||||
|
return <p>{t('Verifying...')}</p>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.status === ApprovalStatus.Delayed && state.completeTimestamp) {
|
||||||
|
const formattedTime = getDateTimeFormat().format(
|
||||||
|
new Date(state.completeTimestamp)
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<p>{t("The amount you're withdrawing has triggered a time delay")}</p>
|
||||||
|
<p>{t(`Cannot be completed until ${formattedTime}`)}</p>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.status === ApprovalStatus.Ready) {
|
||||||
|
return <p>{t('The withdrawal has been approved.')}</p>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
@ -4,25 +4,18 @@ import BigNumber from 'bignumber.js';
|
|||||||
import { addDecimal } from '@vegaprotocol/utils';
|
import { addDecimal } from '@vegaprotocol/utils';
|
||||||
import { t } from '@vegaprotocol/i18n';
|
import { t } from '@vegaprotocol/i18n';
|
||||||
import {
|
import {
|
||||||
useGetWithdrawThreshold,
|
ApprovalStatus,
|
||||||
useGetWithdrawDelay,
|
useGetWithdrawDelay,
|
||||||
|
useGetWithdrawThreshold,
|
||||||
} from '@vegaprotocol/web3';
|
} from '@vegaprotocol/web3';
|
||||||
import type { WithdrawalFieldsFragment } from './__generated__/Withdrawal';
|
import type { WithdrawalFieldsFragment } from './__generated__/Withdrawal';
|
||||||
import { Erc20ApprovalDocument } from './__generated__/Erc20Approval';
|
|
||||||
import type {
|
import type {
|
||||||
Erc20ApprovalQuery,
|
Erc20ApprovalQuery,
|
||||||
Erc20ApprovalQueryVariables,
|
Erc20ApprovalQueryVariables,
|
||||||
} from './__generated__/Erc20Approval';
|
} from './__generated__/Erc20Approval';
|
||||||
|
import { Erc20ApprovalDocument } from './__generated__/Erc20Approval';
|
||||||
import { useApolloClient } from '@apollo/client';
|
import { useApolloClient } from '@apollo/client';
|
||||||
|
|
||||||
export enum ApprovalStatus {
|
|
||||||
Idle = 'Idle',
|
|
||||||
Pending = 'Pending',
|
|
||||||
Delayed = 'Delayed',
|
|
||||||
Error = 'Error',
|
|
||||||
Ready = 'Ready',
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface VerifyState {
|
export interface VerifyState {
|
||||||
status: ApprovalStatus;
|
status: ApprovalStatus;
|
||||||
message?: string;
|
message?: string;
|
||||||
|
@ -2,26 +2,24 @@ import { useRef } from 'react';
|
|||||||
import type { AgGridReact } from 'ag-grid-react';
|
import type { AgGridReact } from 'ag-grid-react';
|
||||||
import { AgGridColumn } from 'ag-grid-react';
|
import { AgGridColumn } from 'ag-grid-react';
|
||||||
import {
|
import {
|
||||||
getDateTimeFormat,
|
|
||||||
truncateByChars,
|
|
||||||
addDecimalsFormatNumber,
|
addDecimalsFormatNumber,
|
||||||
|
getDateTimeFormat,
|
||||||
isNumeric,
|
isNumeric,
|
||||||
|
truncateByChars,
|
||||||
} from '@vegaprotocol/utils';
|
} from '@vegaprotocol/utils';
|
||||||
import { useBottomPlaceholder } from '@vegaprotocol/react-helpers';
|
import { useBottomPlaceholder } from '@vegaprotocol/react-helpers';
|
||||||
import { t } from '@vegaprotocol/i18n';
|
import { t } from '@vegaprotocol/i18n';
|
||||||
import { ButtonLink } from '@vegaprotocol/ui-toolkit';
|
import { ButtonLink } from '@vegaprotocol/ui-toolkit';
|
||||||
import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid';
|
|
||||||
import type {
|
import type {
|
||||||
TypedDataAgGrid,
|
TypedDataAgGrid,
|
||||||
VegaICellRendererParams,
|
VegaICellRendererParams,
|
||||||
VegaValueFormatterParams,
|
VegaValueFormatterParams,
|
||||||
} from '@vegaprotocol/datagrid';
|
} from '@vegaprotocol/datagrid';
|
||||||
|
import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid';
|
||||||
import { EtherscanLink } from '@vegaprotocol/environment';
|
import { EtherscanLink } from '@vegaprotocol/environment';
|
||||||
import type { WithdrawalFieldsFragment } from './__generated__/Withdrawal';
|
import type { WithdrawalFieldsFragment } from './__generated__/Withdrawal';
|
||||||
import { useEthWithdrawApprovalsStore } from '@vegaprotocol/web3';
|
import { useEthWithdrawApprovalsStore } from '@vegaprotocol/web3';
|
||||||
import * as Schema from '@vegaprotocol/types';
|
import * as Schema from '@vegaprotocol/types';
|
||||||
import type { VerifyState } from './use-verify-withdrawal';
|
|
||||||
import { ApprovalStatus } from './use-verify-withdrawal';
|
|
||||||
|
|
||||||
export const WithdrawalsTable = (
|
export const WithdrawalsTable = (
|
||||||
props: TypedDataAgGrid<WithdrawalFieldsFragment>
|
props: TypedDataAgGrid<WithdrawalFieldsFragment>
|
||||||
@ -195,31 +193,3 @@ const RecipientCell = ({
|
|||||||
</EtherscanLink>
|
</EtherscanLink>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const VerificationStatus = ({ state }: { state: VerifyState }) => {
|
|
||||||
if (state.status === ApprovalStatus.Error) {
|
|
||||||
return <p>{state.message || t('Something went wrong')}</p>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.status === ApprovalStatus.Pending) {
|
|
||||||
return <p>{t('Verifying...')}</p>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.status === ApprovalStatus.Delayed && state.completeTimestamp) {
|
|
||||||
const formattedTime = getDateTimeFormat().format(
|
|
||||||
new Date(state.completeTimestamp)
|
|
||||||
);
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<p>{t("The amount you're withdrawing has triggered a time delay")}</p>
|
|
||||||
<p>{t(`Cannot be completed until ${formattedTime}`)}</p>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.status === ApprovalStatus.Ready) {
|
|
||||||
return <p>{t('The withdrawal has been approved.')}</p>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user