refactor(trading,governance,wallet): wallet rewrite (#5815)
Co-authored-by: bwallacee <ben@vega.xyz>
This commit is contained in:
parent
358c734e31
commit
28b4593a1d
@ -34,12 +34,6 @@ context('View functionality with public key', { tags: '@smoke' }, function () {
|
|||||||
cy.connectPublicKey(vegaWalletPubKey);
|
cy.connectPublicKey(vegaWalletPubKey);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Able to connect public key using url', function () {
|
|
||||||
cy.getByTestId('exit-view').click();
|
|
||||||
cy.visit(`/?address=${vegaWalletPubKey}`);
|
|
||||||
verifyConnectedToPubKey();
|
|
||||||
});
|
|
||||||
|
|
||||||
it.skip('Able to connect public key via wallet and view assets in wallet', function () {
|
it.skip('Able to connect public key via wallet and view assets in wallet', function () {
|
||||||
verifyConnectedToPubKey();
|
verifyConnectedToPubKey();
|
||||||
cy.getByTestId('currency-title', { timeout: 10000 })
|
cy.getByTestId('currency-title', { timeout: 10000 })
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as Sentry from '@sentry/react';
|
import * as Sentry from '@sentry/react';
|
||||||
import { toBigNum } from '@vegaprotocol/utils';
|
import { toBigNum } from '@vegaprotocol/utils';
|
||||||
import { Splash } from '@vegaprotocol/ui-toolkit';
|
import { Splash } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet, useEagerConnect } from '@vegaprotocol/wallet';
|
import { useVegaWallet, useEagerConnect } from '@vegaprotocol/wallet-react';
|
||||||
import { useFeatureFlags, useEnvironment } from '@vegaprotocol/environment';
|
import { useFeatureFlags, useEnvironment } from '@vegaprotocol/environment';
|
||||||
import { useWeb3React } from '@web3-react/core';
|
import { useWeb3React } from '@web3-react/core';
|
||||||
import React, { Suspense } from 'react';
|
import React, { Suspense } from 'react';
|
||||||
@ -15,20 +15,6 @@ import {
|
|||||||
} from './contexts/app-state/app-state-context';
|
} from './contexts/app-state/app-state-context';
|
||||||
import { useContracts } from './contexts/contracts/contracts-context';
|
import { useContracts } from './contexts/contracts/contracts-context';
|
||||||
import { useRefreshAssociatedBalances } from './hooks/use-refresh-associated-balances';
|
import { useRefreshAssociatedBalances } from './hooks/use-refresh-associated-balances';
|
||||||
import { useConnectors } from './lib/vega-connectors';
|
|
||||||
import { useSearchParams } from 'react-router-dom';
|
|
||||||
|
|
||||||
const useVegaWalletEagerConnect = () => {
|
|
||||||
const connectors = useConnectors();
|
|
||||||
const vegaConnecting = useEagerConnect(connectors);
|
|
||||||
const { pubKey, connect } = useVegaWallet();
|
|
||||||
const [searchParams] = useSearchParams();
|
|
||||||
const [query] = React.useState(searchParams.get('address'));
|
|
||||||
if (query && !pubKey) {
|
|
||||||
connect(connectors.view);
|
|
||||||
}
|
|
||||||
return vegaConnecting;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const AppLoader = ({ children }: { children: React.ReactElement }) => {
|
export const AppLoader = ({ children }: { children: React.ReactElement }) => {
|
||||||
const featureFlags = useFeatureFlags((state) => state.flags);
|
const featureFlags = useFeatureFlags((state) => state.flags);
|
||||||
@ -40,7 +26,7 @@ export const AppLoader = ({ children }: { children: React.ReactElement }) => {
|
|||||||
const { token, staking, vesting } = useContracts();
|
const { token, staking, vesting } = useContracts();
|
||||||
const setAssociatedBalances = useRefreshAssociatedBalances();
|
const setAssociatedBalances = useRefreshAssociatedBalances();
|
||||||
const [balancesLoaded, setBalancesLoaded] = React.useState(false);
|
const [balancesLoaded, setBalancesLoaded] = React.useState(false);
|
||||||
const vegaConnecting = useVegaWalletEagerConnect();
|
const vegaConnecting = useEagerConnect();
|
||||||
|
|
||||||
const loaded = balancesLoaded && !vegaConnecting;
|
const loaded = balancesLoaded && !vegaConnecting;
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import './i18n';
|
import './i18n';
|
||||||
|
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import * as Sentry from '@sentry/react';
|
|
||||||
import { BrowserRouter as Router, useLocation } from 'react-router-dom';
|
import { BrowserRouter as Router, useLocation } from 'react-router-dom';
|
||||||
import { AppLoader } from './app-loader';
|
import { AppLoader } from './app-loader';
|
||||||
import { NetworkInfo } from '@vegaprotocol/network-info';
|
import { NetworkInfo } from '@vegaprotocol/network-info';
|
||||||
@ -26,7 +25,7 @@ import {
|
|||||||
} 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, useChainId } from '@vegaprotocol/wallet';
|
import { WalletProvider } from '@vegaprotocol/wallet-react';
|
||||||
import {
|
import {
|
||||||
useVegaTransactionManager,
|
useVegaTransactionManager,
|
||||||
useVegaTransactionUpdater,
|
useVegaTransactionUpdater,
|
||||||
@ -36,26 +35,21 @@ import { useEthereumConfig } from '@vegaprotocol/web3';
|
|||||||
import {
|
import {
|
||||||
useEnvironment,
|
useEnvironment,
|
||||||
NetworkLoader,
|
NetworkLoader,
|
||||||
useInitializeEnv,
|
|
||||||
NodeGuard,
|
NodeGuard,
|
||||||
NodeSwitcherDialog,
|
NodeSwitcherDialog,
|
||||||
useNodeSwitcherStore,
|
useNodeSwitcherStore,
|
||||||
DocsLinks,
|
|
||||||
NodeFailure,
|
NodeFailure,
|
||||||
AppLoader as Loader,
|
AppLoader as Loader,
|
||||||
|
useInitializeEnv,
|
||||||
} from '@vegaprotocol/environment';
|
} from '@vegaprotocol/environment';
|
||||||
import { ENV } from './config';
|
|
||||||
import type { InMemoryCacheConfig } from '@apollo/client';
|
import type { InMemoryCacheConfig } from '@apollo/client';
|
||||||
import { CreateWithdrawalDialog } from '@vegaprotocol/withdraws';
|
import { CreateWithdrawalDialog } from '@vegaprotocol/withdraws';
|
||||||
import { SplashLoader } from './components/splash-loader';
|
import { SplashLoader } from './components/splash-loader';
|
||||||
import { ToastsManager } from './toasts-manager';
|
import { ToastsManager } from './toasts-manager';
|
||||||
import {
|
import { TelemetryDialog } from './components/telemetry-dialog/telemetry-dialog';
|
||||||
TelemetryDialog,
|
|
||||||
TELEMETRY_ON,
|
|
||||||
} from './components/telemetry-dialog/telemetry-dialog';
|
|
||||||
import { useLocalStorage } from '@vegaprotocol/react-helpers';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { isPartyNotFoundError } from './lib/party';
|
import { useSentryInit } from './hooks/use-sentry-init';
|
||||||
|
import { useVegaWalletConfig } from './hooks/use-vega-wallet-config';
|
||||||
|
|
||||||
const cache: InMemoryCacheConfig = {
|
const cache: InMemoryCacheConfig = {
|
||||||
typePolicies: {
|
typePolicies: {
|
||||||
@ -104,32 +98,12 @@ const Web3Container = ({
|
|||||||
/** Ethereum provider url */
|
/** Ethereum provider url */
|
||||||
providerUrl: string;
|
providerUrl: string;
|
||||||
}) => {
|
}) => {
|
||||||
const InitializeHandlers = () => {
|
|
||||||
useVegaTransactionManager();
|
|
||||||
useVegaTransactionUpdater();
|
|
||||||
useEthTransactionManager();
|
|
||||||
useEthTransactionUpdater();
|
|
||||||
useEthWithdrawApprovalsManager();
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const [connectors, initializeConnectors] = useWeb3ConnectStore((store) => [
|
const [connectors, initializeConnectors] = useWeb3ConnectStore((store) => [
|
||||||
store.connectors,
|
store.connectors,
|
||||||
store.initialize,
|
store.initialize,
|
||||||
]);
|
]);
|
||||||
const {
|
const { ETHEREUM_PROVIDER_URL, ETH_LOCAL_PROVIDER_URL, ETH_WALLET_MNEMONIC } =
|
||||||
ETHEREUM_PROVIDER_URL,
|
useEnvironment();
|
||||||
ETH_LOCAL_PROVIDER_URL,
|
|
||||||
ETH_WALLET_MNEMONIC,
|
|
||||||
VEGA_ENV,
|
|
||||||
VEGA_URL,
|
|
||||||
VEGA_EXPLORER_URL,
|
|
||||||
CHROME_EXTENSION_URL,
|
|
||||||
MOZILLA_EXTENSION_URL,
|
|
||||||
VEGA_WALLET_URL,
|
|
||||||
} = useEnvironment();
|
|
||||||
|
|
||||||
const vegaChainId = useChainId(VEGA_URL);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (chainId) {
|
if (chainId) {
|
||||||
@ -150,50 +124,31 @@ const Web3Container = ({
|
|||||||
ETH_LOCAL_PROVIDER_URL,
|
ETH_LOCAL_PROVIDER_URL,
|
||||||
ETH_WALLET_MNEMONIC,
|
ETH_WALLET_MNEMONIC,
|
||||||
]);
|
]);
|
||||||
const sideBar = React.useMemo(() => {
|
|
||||||
return [<EthWallet />, <VegaWallet />];
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (connectors.length === 0) {
|
const vegaWalletConfig = useVegaWalletConfig();
|
||||||
|
|
||||||
|
if (!vegaWalletConfig || connectors.length === 0) {
|
||||||
// Prevent loading when the connectors are not initialized
|
// Prevent loading when the connectors are not initialized
|
||||||
return <SplashLoader />;
|
return <SplashLoader />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
!VEGA_URL ||
|
|
||||||
!VEGA_WALLET_URL ||
|
|
||||||
!VEGA_EXPLORER_URL ||
|
|
||||||
!DocsLinks ||
|
|
||||||
!CHROME_EXTENSION_URL ||
|
|
||||||
!MOZILLA_EXTENSION_URL ||
|
|
||||||
!vegaChainId
|
|
||||||
) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Web3Provider connectors={connectors}>
|
<Web3Provider connectors={connectors}>
|
||||||
<Web3Connector connectors={connectors} chainId={Number(chainId)}>
|
<Web3Connector connectors={connectors} chainId={Number(chainId)}>
|
||||||
<VegaWalletProvider
|
<WalletProvider config={vegaWalletConfig}>
|
||||||
config={{
|
|
||||||
network: VEGA_ENV,
|
|
||||||
vegaUrl: VEGA_URL,
|
|
||||||
chainId: vegaChainId,
|
|
||||||
vegaWalletServiceUrl: VEGA_WALLET_URL,
|
|
||||||
links: {
|
|
||||||
explorer: VEGA_EXPLORER_URL,
|
|
||||||
concepts: DocsLinks?.VEGA_WALLET_CONCEPTS_URL,
|
|
||||||
chromeExtensionUrl: CHROME_EXTENSION_URL,
|
|
||||||
mozillaExtensionUrl: MOZILLA_EXTENSION_URL,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<ContractsProvider>
|
<ContractsProvider>
|
||||||
<AppLoader>
|
<AppLoader>
|
||||||
<BalanceManager>
|
<BalanceManager>
|
||||||
<>
|
<>
|
||||||
<AppLayout>
|
<AppLayout>
|
||||||
<TemplateSidebar sidebar={sideBar}>
|
<TemplateSidebar
|
||||||
|
sidebar={
|
||||||
|
<>
|
||||||
|
<EthWallet />
|
||||||
|
<VegaWallet />
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
>
|
||||||
<AppRouter />
|
<AppRouter />
|
||||||
</TemplateSidebar>
|
</TemplateSidebar>
|
||||||
<footer className="p-4 break-all border-t border-neutral-700">
|
<footer className="p-4 break-all border-t border-neutral-700">
|
||||||
@ -211,7 +166,7 @@ const Web3Container = ({
|
|||||||
</BalanceManager>
|
</BalanceManager>
|
||||||
</AppLoader>
|
</AppLoader>
|
||||||
</ContractsProvider>
|
</ContractsProvider>
|
||||||
</VegaWalletProvider>
|
</WalletProvider>
|
||||||
</Web3Connector>
|
</Web3Connector>
|
||||||
</Web3Provider>
|
</Web3Provider>
|
||||||
);
|
);
|
||||||
@ -231,20 +186,9 @@ const ScrollToTop = () => {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeQueryParams = (url: string) => {
|
|
||||||
return url.split('?')[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
const AppContainer = () => {
|
const AppContainer = () => {
|
||||||
const { config, loading, error } = useEthereumConfig();
|
const { config, loading, error } = useEthereumConfig();
|
||||||
const {
|
const { VEGA_URL, ETHEREUM_PROVIDER_URL } = useEnvironment();
|
||||||
VEGA_ENV,
|
|
||||||
VEGA_URL,
|
|
||||||
GIT_COMMIT_HASH,
|
|
||||||
GIT_BRANCH,
|
|
||||||
ETHEREUM_PROVIDER_URL,
|
|
||||||
} = useEnvironment();
|
|
||||||
const [telemetryOn] = useLocalStorage(TELEMETRY_ON);
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [nodeSwitcherOpen, setNodeSwitcher] = useNodeSwitcherStore((store) => [
|
const [nodeSwitcherOpen, setNodeSwitcher] = useNodeSwitcherStore((store) => [
|
||||||
store.dialogOpen,
|
store.dialogOpen,
|
||||||
@ -254,70 +198,7 @@ const AppContainer = () => {
|
|||||||
// Hacky skip all the loading & web3 init for geo restricted users
|
// Hacky skip all the loading & web3 init for geo restricted users
|
||||||
const isRestricted = document?.location?.pathname?.includes('/restricted');
|
const isRestricted = document?.location?.pathname?.includes('/restricted');
|
||||||
|
|
||||||
useEffect(() => {
|
useSentryInit();
|
||||||
if (ENV.dsn && telemetryOn === 'true') {
|
|
||||||
Sentry.init({
|
|
||||||
dsn: ENV.dsn,
|
|
||||||
tracesSampleRate: 0.1,
|
|
||||||
enabled: true,
|
|
||||||
environment: VEGA_ENV,
|
|
||||||
release: GIT_COMMIT_HASH,
|
|
||||||
beforeSend(event, hint) {
|
|
||||||
const error = hint?.originalException;
|
|
||||||
const errorIsString = typeof error === 'string';
|
|
||||||
const errorIsObject = error instanceof Error;
|
|
||||||
const requestUrl = event.request?.url;
|
|
||||||
const transaction = event.transaction;
|
|
||||||
|
|
||||||
if (
|
|
||||||
(errorIsString && isPartyNotFoundError({ message: error })) ||
|
|
||||||
(errorIsObject && isPartyNotFoundError(error))
|
|
||||||
) {
|
|
||||||
// This error is caused by a pubkey making an API request before
|
|
||||||
// it has interacted with the chain. This isn't needed in Sentry.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedRequest =
|
|
||||||
requestUrl && requestUrl.includes('/claim?')
|
|
||||||
? { ...event.request, url: removeQueryParams(requestUrl) }
|
|
||||||
: event.request;
|
|
||||||
|
|
||||||
const updatedTransaction =
|
|
||||||
transaction && transaction.includes('/claim?')
|
|
||||||
? removeQueryParams(transaction)
|
|
||||||
: transaction;
|
|
||||||
|
|
||||||
const updatedBreadcrumbs = event.breadcrumbs?.map((breadcrumb) => {
|
|
||||||
if (
|
|
||||||
breadcrumb.type === 'navigation' &&
|
|
||||||
breadcrumb.data?.to?.includes('/claim?')
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
...breadcrumb,
|
|
||||||
data: {
|
|
||||||
...breadcrumb.data,
|
|
||||||
to: removeQueryParams(breadcrumb.data.to),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return breadcrumb;
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
...event,
|
|
||||||
request: updatedRequest,
|
|
||||||
transaction: updatedTransaction,
|
|
||||||
breadcrumbs: updatedBreadcrumbs ?? event.breadcrumbs,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
Sentry.setTag('branch', GIT_BRANCH);
|
|
||||||
Sentry.setTag('commit', GIT_COMMIT_HASH);
|
|
||||||
} else {
|
|
||||||
Sentry.close();
|
|
||||||
}
|
|
||||||
}, [GIT_COMMIT_HASH, GIT_BRANCH, VEGA_ENV, telemetryOn]);
|
|
||||||
|
|
||||||
if (isRestricted) {
|
if (isRestricted) {
|
||||||
return (
|
return (
|
||||||
@ -359,6 +240,15 @@ const AppContainer = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const InitializeHandlers = () => {
|
||||||
|
useVegaTransactionManager();
|
||||||
|
useVegaTransactionUpdater();
|
||||||
|
useEthTransactionManager();
|
||||||
|
useEthTransactionUpdater();
|
||||||
|
useEthWithdrawApprovalsManager();
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
useInitializeEnv();
|
useInitializeEnv();
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import { useGetAssociationBreakdown } from '../../hooks/use-get-association-brea
|
|||||||
import { useGetUserBalances } from '../../hooks/use-get-user-balances';
|
import { useGetUserBalances } from '../../hooks/use-get-user-balances';
|
||||||
import { useBalances } from '../../lib/balances/balances-store';
|
import { useBalances } from '../../lib/balances/balances-store';
|
||||||
import type { ReactElement } from 'react';
|
import type { ReactElement } from 'react';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useListenForStakingEvents as useListenForAssociationEvents } from '../../hooks/use-listen-for-staking-events';
|
import { useListenForStakingEvents as useListenForAssociationEvents } from '../../hooks/use-listen-for-staking-events';
|
||||||
import { useTranches } from '../../lib/tranches/tranches-store';
|
import { useTranches } from '../../lib/tranches/tranches-store';
|
||||||
import { useUserTrancheBalances } from '../../routes/redemption/hooks';
|
import { useUserTrancheBalances } from '../../routes/redemption/hooks';
|
||||||
|
@ -1,18 +1,13 @@
|
|||||||
import { Button } from '@vegaprotocol/ui-toolkit';
|
import { Button } from '@vegaprotocol/ui-toolkit';
|
||||||
import React from 'react';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useDialogStore } from '@vegaprotocol/wallet-react';
|
||||||
|
|
||||||
export const ConnectToVega = () => {
|
export const ConnectToVega = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { openVegaWalletDialog } = useVegaWalletDialogStore((store) => ({
|
const openVegaWalletDialog = useDialogStore((store) => store.open);
|
||||||
openVegaWalletDialog: store.openVegaWalletDialog,
|
|
||||||
}));
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={openVegaWalletDialog}
|
||||||
openVegaWalletDialog();
|
|
||||||
}}
|
|
||||||
data-testid="connect-to-vega-wallet-btn"
|
data-testid="connect-to-vega-wallet-btn"
|
||||||
variant="primary"
|
variant="primary"
|
||||||
>
|
>
|
||||||
|
@ -6,8 +6,8 @@ import {
|
|||||||
Intent,
|
Intent,
|
||||||
Icon,
|
Icon,
|
||||||
} from '@vegaprotocol/ui-toolkit';
|
} from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet } from '../use-vega-wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useT } from '../use-t';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
export interface VegaManageDialogProps {
|
export interface VegaManageDialogProps {
|
||||||
dialogOpen: boolean;
|
dialogOpen: boolean;
|
||||||
@ -18,7 +18,7 @@ export const VegaManageDialog = ({
|
|||||||
dialogOpen,
|
dialogOpen,
|
||||||
setDialogOpen,
|
setDialogOpen,
|
||||||
}: VegaManageDialogProps) => {
|
}: VegaManageDialogProps) => {
|
||||||
const t = useT();
|
const { t } = useTranslation();
|
||||||
const { pubKey, pubKeys, selectPubKey, disconnect } = useVegaWallet();
|
const { pubKey, pubKeys, selectPubKey, disconnect } = useVegaWallet();
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
@ -1,5 +1,5 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import { AnnouncementBanner } from '@vegaprotocol/announcements';
|
import { AnnouncementBanner } from '@vegaprotocol/announcements';
|
||||||
import { Nav } from '../nav';
|
import { Nav } from '../nav';
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import React from 'react';
|
import { Children, type ReactNode } from 'react';
|
||||||
|
|
||||||
export interface TemplateSidebarProps {
|
export interface TemplateSidebarProps {
|
||||||
children: React.ReactNode;
|
children: ReactNode;
|
||||||
sidebar: React.ReactNode[];
|
sidebar: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TemplateSidebar({ children, sidebar }: TemplateSidebarProps) {
|
export function TemplateSidebar({ children, sidebar }: TemplateSidebarProps) {
|
||||||
@ -12,9 +12,9 @@ export function TemplateSidebar({ children, sidebar }: TemplateSidebarProps) {
|
|||||||
{children}
|
{children}
|
||||||
</main>
|
</main>
|
||||||
<aside className="col-start-2 row-start-1 row-span-2 hidden lg:block p-4 bg-banner bg-contain border-l border-neutral-700">
|
<aside className="col-start-2 row-start-1 row-span-2 hidden lg:block p-4 bg-banner bg-contain border-l border-neutral-700">
|
||||||
{sidebar.map((Component, i) => (
|
{Children.map(sidebar, (child, i) => (
|
||||||
<section className="mb-4 last:mb-0" key={i}>
|
<section className="mb-4 last:mb-0" key={i}>
|
||||||
{Component}
|
{child}
|
||||||
</section>
|
</section>
|
||||||
))}
|
))}
|
||||||
</aside>
|
</aside>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Button } from '@vegaprotocol/ui-toolkit';
|
import { Button } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useVegaWallet, useDialogStore } from '@vegaprotocol/wallet-react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
@ -10,9 +10,7 @@ interface VegaWalletContainerProps {
|
|||||||
export const VegaWalletContainer = ({ children }: VegaWalletContainerProps) => {
|
export const VegaWalletContainer = ({ children }: VegaWalletContainerProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { pubKey } = useVegaWallet();
|
const { pubKey } = useVegaWallet();
|
||||||
const { openVegaWalletDialog } = useVegaWalletDialogStore((store) => ({
|
const openVegaWalletDialog = useDialogStore((store) => store.open);
|
||||||
openVegaWalletDialog: store.openVegaWalletDialog,
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (!pubKey) {
|
if (!pubKey) {
|
||||||
return (
|
return (
|
||||||
|
@ -9,7 +9,7 @@ import Routes from '../../routes/routes';
|
|||||||
export const RiskMessage = () => {
|
export const RiskMessage = () => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="bg-vega-light-100 dark:bg-vega-dark-100 p-6 mb-6">
|
<div className="bg-vega-light-100 dark:bg-vega-dark-100 p-6">
|
||||||
<ul className="list-[square] ml-4">
|
<ul className="list-[square] ml-4">
|
||||||
<li>
|
<li>
|
||||||
{t(
|
{t(
|
||||||
@ -23,7 +23,7 @@ export const RiskMessage = () => {
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<p className="mb-8">
|
<p>
|
||||||
{t(
|
{t(
|
||||||
'By using the Vega Governance App, you acknowledge that you have read and understood the'
|
'By using the Vega Governance App, you acknowledge that you have read and understood the'
|
||||||
)}{' '}
|
)}{' '}
|
||||||
|
@ -1,25 +1,39 @@
|
|||||||
import {
|
import {
|
||||||
VegaConnectDialog,
|
ConnectDialogWithRiskAck,
|
||||||
VegaManageDialog,
|
useDialogStore,
|
||||||
ViewAsDialog,
|
} from '@vegaprotocol/wallet-react';
|
||||||
} from '@vegaprotocol/wallet';
|
|
||||||
import {
|
import {
|
||||||
AppStateActionType,
|
AppStateActionType,
|
||||||
useAppState,
|
useAppState,
|
||||||
} from '../../contexts/app-state/app-state-context';
|
} from '../../contexts/app-state/app-state-context';
|
||||||
import { useConnectors } from '../../lib/vega-connectors';
|
|
||||||
import { RiskMessage } from './risk-message';
|
import { RiskMessage } from './risk-message';
|
||||||
|
import { VegaManageDialog } from '../manage-dialog';
|
||||||
|
import { useLocalStorage } from '@vegaprotocol/react-helpers';
|
||||||
|
import { Networks, useEnvironment } from '@vegaprotocol/environment';
|
||||||
|
|
||||||
export const VegaWalletDialogs = () => {
|
export const VegaWalletDialogs = () => {
|
||||||
|
const { VEGA_ENV } = useEnvironment();
|
||||||
const { appState, appDispatch } = useAppState();
|
const { appState, appDispatch } = useAppState();
|
||||||
const connectors = useConnectors();
|
const [riskAccepted, setRiskAccepted] = useLocalStorage(
|
||||||
|
'vega_wallet_risk_accepted'
|
||||||
|
);
|
||||||
|
const vegaWalletDialogOpen = useDialogStore((store) => store.isOpen);
|
||||||
|
const setVegaWalletDialog = useDialogStore((store) => store.set);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<VegaConnectDialog
|
<ConnectDialogWithRiskAck
|
||||||
connectors={connectors}
|
open={vegaWalletDialogOpen}
|
||||||
riskMessage={<RiskMessage />}
|
onChange={setVegaWalletDialog}
|
||||||
|
riskAccepted={
|
||||||
|
VEGA_ENV === Networks.TESTNET ? riskAccepted === 'true' : true
|
||||||
|
}
|
||||||
|
riskAckContent={<RiskMessage />}
|
||||||
|
onRiskAccepted={() => setRiskAccepted('true')}
|
||||||
|
onRiskRejected={() => {
|
||||||
|
setRiskAccepted('false');
|
||||||
|
setVegaWalletDialog(false);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<VegaManageDialog
|
<VegaManageDialog
|
||||||
dialogOpen={appState.vegaWalletManageOverlay}
|
dialogOpen={appState.vegaWalletManageOverlay}
|
||||||
setDialogOpen={(open) =>
|
setDialogOpen={(open) =>
|
||||||
@ -29,8 +43,6 @@ export const VegaWalletDialogs = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ViewAsDialog connector={connectors.view} />
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,7 @@ import vegaBlack from '../../images/vega_black.png';
|
|||||||
import vegaVesting from '../../images/vega_vesting.png';
|
import vegaVesting from '../../images/vega_vesting.png';
|
||||||
import { BigNumber } from '../../lib/bignumber';
|
import { BigNumber } from '../../lib/bignumber';
|
||||||
import { type WalletCardAssetProps } from '../wallet-card';
|
import { type WalletCardAssetProps } from '../wallet-card';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useContracts } from '../../contexts/contracts/contracts-context';
|
import { useContracts } from '../../contexts/contracts/contracts-context';
|
||||||
import * as Schema from '@vegaprotocol/types';
|
import * as Schema from '@vegaprotocol/types';
|
||||||
import {
|
import {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ButtonLink, Link } from '@vegaprotocol/ui-toolkit';
|
import { ButtonLink, Link } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { ExternalLinks } from '@vegaprotocol/environment';
|
import { ExternalLinks } from '@vegaprotocol/environment';
|
||||||
import { useViewAsDialog } from '@vegaprotocol/wallet';
|
import { useConnect } from '@vegaprotocol/wallet-react';
|
||||||
|
|
||||||
export const VegaWalletPrompt = () => {
|
export const VegaWalletPrompt = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const setViewAsDialog = useViewAsDialog((state) => state.setOpen);
|
const { connect } = useConnect();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h3 className="mt-4 mb-2">{t('getWallet')}</h3>
|
<h3 className="mt-4 mb-2">{t('getWallet')}</h3>
|
||||||
@ -16,7 +16,7 @@ export const VegaWalletPrompt = () => {
|
|||||||
<ButtonLink
|
<ButtonLink
|
||||||
className="text-neutral-500"
|
className="text-neutral-500"
|
||||||
data-testid="view-as-user"
|
data-testid="view-as-user"
|
||||||
onClick={() => setViewAsDialog(true)}
|
onClick={() => connect('viewParty')}
|
||||||
>
|
>
|
||||||
{t('viewAsParty')}
|
{t('viewAsParty')}
|
||||||
</ButtonLink>
|
</ButtonLink>
|
||||||
|
@ -25,7 +25,7 @@ import {
|
|||||||
} from '../wallet-card';
|
} from '../wallet-card';
|
||||||
import { VegaWalletPrompt } from './vega-wallet-prompt';
|
import { VegaWalletPrompt } from './vega-wallet-prompt';
|
||||||
import { usePollForDelegations } from './hooks';
|
import { usePollForDelegations } from './hooks';
|
||||||
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useVegaWallet, useDialogStore } from '@vegaprotocol/wallet-react';
|
||||||
import { Button, ButtonLink } from '@vegaprotocol/ui-toolkit';
|
import { Button, ButtonLink } from '@vegaprotocol/ui-toolkit';
|
||||||
import { toBigNum } from '@vegaprotocol/utils';
|
import { toBigNum } from '@vegaprotocol/utils';
|
||||||
import { usePendingBalancesStore } from '../../hooks/use-pending-balances-manager';
|
import { usePendingBalancesStore } from '../../hooks/use-pending-balances-manager';
|
||||||
@ -34,16 +34,17 @@ import omit from 'lodash/omit';
|
|||||||
|
|
||||||
export const VegaWallet = () => {
|
export const VegaWallet = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { pubKey, pubKeys } = useVegaWallet();
|
const { status, pubKey, pubKeys } = useVegaWallet();
|
||||||
const pubKeyObj = useMemo(() => {
|
const pubKeyObj = useMemo(() => {
|
||||||
return pubKeys?.find((pk) => pk.publicKey === pubKey);
|
return pubKeys?.find((pk) => pk.publicKey === pubKey);
|
||||||
}, [pubKey, pubKeys]);
|
}, [pubKey, pubKeys]);
|
||||||
|
|
||||||
const child = !pubKeys ? (
|
const child =
|
||||||
<VegaWalletNotConnected />
|
status === 'connected' ? (
|
||||||
) : (
|
<VegaWalletConnected vegaKeys={pubKeys.map((pk) => pk.publicKey)} />
|
||||||
<VegaWalletConnected vegaKeys={pubKeys.map((pk) => pk.publicKey)} />
|
) : (
|
||||||
);
|
<VegaWalletNotConnected />
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="vega-wallet" data-testid="vega-wallet">
|
<section className="vega-wallet" data-testid="vega-wallet">
|
||||||
@ -75,9 +76,7 @@ export const VegaWallet = () => {
|
|||||||
|
|
||||||
const VegaWalletNotConnected = () => {
|
const VegaWalletNotConnected = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { openVegaWalletDialog } = useVegaWalletDialogStore((store) => ({
|
const openVegaWalletDialog = useDialogStore((store) => store.open);
|
||||||
openVegaWalletDialog: store.openVegaWalletDialog,
|
|
||||||
}));
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
|
@ -7,7 +7,7 @@ import { useWeb3React } from '@web3-react/core';
|
|||||||
|
|
||||||
export const useListenForStakingEvents = (
|
export const useListenForStakingEvents = (
|
||||||
contract: Contract | undefined,
|
contract: Contract | undefined,
|
||||||
vegaPublicKey: string | null,
|
vegaPublicKey: string | undefined,
|
||||||
numberOfConfirmations: number
|
numberOfConfirmations: number
|
||||||
) => {
|
) => {
|
||||||
const { account } = useWeb3React();
|
const { account } = useWeb3React();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as Sentry from '@sentry/react';
|
import * as Sentry from '@sentry/react';
|
||||||
import { toBigNum } from '@vegaprotocol/utils';
|
import { toBigNum } from '@vegaprotocol/utils';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useEthereumConfig } from '@vegaprotocol/web3';
|
import { useEthereumConfig } from '@vegaprotocol/web3';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
81
apps/governance/src/hooks/use-sentry-init.ts
Normal file
81
apps/governance/src/hooks/use-sentry-init.ts
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import * as Sentry from '@sentry/react';
|
||||||
|
import { useLocalStorage } from '@vegaprotocol/react-helpers';
|
||||||
|
import { TELEMETRY_ON } from '../components/telemetry-dialog/telemetry-dialog';
|
||||||
|
import { useEnvironment } from '@vegaprotocol/environment';
|
||||||
|
import { ENV } from '../config';
|
||||||
|
import { isPartyNotFoundError } from '../lib/party';
|
||||||
|
|
||||||
|
export const useSentryInit = () => {
|
||||||
|
const { VEGA_ENV, GIT_COMMIT_HASH, GIT_BRANCH } = useEnvironment();
|
||||||
|
const [telemetryOn] = useLocalStorage(TELEMETRY_ON);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (ENV.dsn && telemetryOn === 'true') {
|
||||||
|
Sentry.init({
|
||||||
|
dsn: ENV.dsn,
|
||||||
|
tracesSampleRate: 0.1,
|
||||||
|
enabled: true,
|
||||||
|
environment: VEGA_ENV,
|
||||||
|
release: GIT_COMMIT_HASH,
|
||||||
|
beforeSend(event, hint) {
|
||||||
|
const error = hint?.originalException;
|
||||||
|
const errorIsString = typeof error === 'string';
|
||||||
|
const errorIsObject = error instanceof Error;
|
||||||
|
const requestUrl = event.request?.url;
|
||||||
|
const transaction = event.transaction;
|
||||||
|
|
||||||
|
if (
|
||||||
|
(errorIsString && isPartyNotFoundError({ message: error })) ||
|
||||||
|
(errorIsObject && isPartyNotFoundError(error))
|
||||||
|
) {
|
||||||
|
// This error is caused by a pubkey making an API request before
|
||||||
|
// it has interacted with the chain. This isn't needed in Sentry.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedRequest =
|
||||||
|
requestUrl && requestUrl.includes('/claim?')
|
||||||
|
? { ...event.request, url: removeQueryParams(requestUrl) }
|
||||||
|
: event.request;
|
||||||
|
|
||||||
|
const updatedTransaction =
|
||||||
|
transaction && transaction.includes('/claim?')
|
||||||
|
? removeQueryParams(transaction)
|
||||||
|
: transaction;
|
||||||
|
|
||||||
|
const updatedBreadcrumbs = event.breadcrumbs?.map((breadcrumb) => {
|
||||||
|
if (
|
||||||
|
breadcrumb.type === 'navigation' &&
|
||||||
|
breadcrumb.data?.to?.includes('/claim?')
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
...breadcrumb,
|
||||||
|
data: {
|
||||||
|
...breadcrumb.data,
|
||||||
|
to: removeQueryParams(breadcrumb.data.to),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return breadcrumb;
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
...event,
|
||||||
|
request: updatedRequest,
|
||||||
|
transaction: updatedTransaction,
|
||||||
|
breadcrumbs: updatedBreadcrumbs ?? event.breadcrumbs,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
Sentry.setTag('branch', GIT_BRANCH);
|
||||||
|
Sentry.setTag('commit', GIT_COMMIT_HASH);
|
||||||
|
} else {
|
||||||
|
Sentry.close();
|
||||||
|
}
|
||||||
|
}, [GIT_COMMIT_HASH, GIT_BRANCH, VEGA_ENV, telemetryOn]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeQueryParams = (url: string) => {
|
||||||
|
return url.split('?')[0];
|
||||||
|
};
|
41
apps/governance/src/hooks/use-vega-wallet-config.ts
Normal file
41
apps/governance/src/hooks/use-vega-wallet-config.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import { useMemo } from 'react';
|
||||||
|
import {
|
||||||
|
InjectedConnector,
|
||||||
|
JsonRpcConnector,
|
||||||
|
SnapConnector,
|
||||||
|
ViewPartyConnector,
|
||||||
|
createConfig,
|
||||||
|
fairground,
|
||||||
|
stagnet,
|
||||||
|
mainnet,
|
||||||
|
} from '@vegaprotocol/wallet';
|
||||||
|
import { useEnvironment } from '@vegaprotocol/environment';
|
||||||
|
|
||||||
|
export const useVegaWalletConfig = () => {
|
||||||
|
const { VEGA_ENV, VEGA_URL, VEGA_WALLET_URL } = useEnvironment();
|
||||||
|
return useMemo(() => {
|
||||||
|
if (!VEGA_ENV || !VEGA_URL || !VEGA_WALLET_URL) return;
|
||||||
|
|
||||||
|
const injected = new InjectedConnector();
|
||||||
|
|
||||||
|
const jsonRpc = new JsonRpcConnector({
|
||||||
|
url: VEGA_WALLET_URL,
|
||||||
|
});
|
||||||
|
|
||||||
|
const snap = new SnapConnector({
|
||||||
|
node: new URL(VEGA_URL).origin,
|
||||||
|
snapId: 'npm:@vegaprotocol/snap',
|
||||||
|
version: '1.0.1',
|
||||||
|
});
|
||||||
|
|
||||||
|
const viewParty = new ViewPartyConnector();
|
||||||
|
|
||||||
|
const config = createConfig({
|
||||||
|
chains: [mainnet, fairground, stagnet],
|
||||||
|
defaultChainId: fairground.id,
|
||||||
|
connectors: [injected, snap, jsonRpc, viewParty],
|
||||||
|
});
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}, [VEGA_ENV, VEGA_URL, VEGA_WALLET_URL]);
|
||||||
|
};
|
@ -31,7 +31,7 @@ i18n
|
|||||||
load: 'languageOnly',
|
load: 'languageOnly',
|
||||||
debug: isInDev,
|
debug: isInDev,
|
||||||
// have a common namespace used around the full app
|
// have a common namespace used around the full app
|
||||||
ns: ['governance'],
|
ns: ['governance', 'wallet', 'wallet-react'],
|
||||||
defaultNS: 'governance',
|
defaultNS: 'governance',
|
||||||
keySeparator: false, // we use content as keys
|
keySeparator: false, // we use content as keys
|
||||||
nsSeparator: false,
|
nsSeparator: false,
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
import { useFeatureFlags } from '@vegaprotocol/environment';
|
|
||||||
import { useMemo } from 'react';
|
|
||||||
import {
|
|
||||||
JsonRpcConnector,
|
|
||||||
ViewConnector,
|
|
||||||
InjectedConnector,
|
|
||||||
SnapConnector,
|
|
||||||
DEFAULT_SNAP_ID,
|
|
||||||
} from '@vegaprotocol/wallet';
|
|
||||||
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
|
|
||||||
export const jsonRpc = new JsonRpcConnector();
|
|
||||||
export const injected = new InjectedConnector();
|
|
||||||
export const view = new ViewConnector(urlParams.get('address'));
|
|
||||||
|
|
||||||
export const snap = new SnapConnector(DEFAULT_SNAP_ID);
|
|
||||||
|
|
||||||
export const useConnectors = () => {
|
|
||||||
const featureFlags = useFeatureFlags((state) => state.flags);
|
|
||||||
return useMemo(
|
|
||||||
() => ({
|
|
||||||
injected,
|
|
||||||
jsonRpc,
|
|
||||||
view,
|
|
||||||
snap: featureFlags.METAMASK_SNAPS ? snap : undefined,
|
|
||||||
}),
|
|
||||||
[featureFlags.METAMASK_SNAPS]
|
|
||||||
);
|
|
||||||
};
|
|
@ -5,7 +5,6 @@ import {
|
|||||||
ProposalState,
|
ProposalState,
|
||||||
VoteValue,
|
VoteValue,
|
||||||
} from '@vegaprotocol/types';
|
} from '@vegaprotocol/types';
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
||||||
import {
|
import {
|
||||||
generateNoVotes,
|
generateNoVotes,
|
||||||
@ -16,9 +15,7 @@ import { ProposalHeader, NewTransferSummary } from './proposal-header';
|
|||||||
import {
|
import {
|
||||||
lastWeek,
|
lastWeek,
|
||||||
nextWeek,
|
nextWeek,
|
||||||
mockWalletContext,
|
|
||||||
createUserVoteQueryMock,
|
createUserVoteQueryMock,
|
||||||
networkParamsQueryMock,
|
|
||||||
} from '../../test-helpers/mocks';
|
} from '../../test-helpers/mocks';
|
||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
import { VoteState } from '../vote-details/use-user-vote';
|
import { VoteState } from '../vote-details/use-user-vote';
|
||||||
@ -45,14 +42,12 @@ const renderComponent = (
|
|||||||
render(
|
render(
|
||||||
<AppStateProvider>
|
<AppStateProvider>
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<MockedProvider mocks={[networkParamsQueryMock, ...mocks]}>
|
<MockedProvider mocks={mocks}>
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
<ProposalHeader
|
||||||
<ProposalHeader
|
proposal={proposal}
|
||||||
proposal={proposal}
|
isListItem={isListItem}
|
||||||
isListItem={isListItem}
|
voteState={voteState}
|
||||||
voteState={voteState}
|
/>
|
||||||
/>
|
|
||||||
</VegaWalletContext.Provider>
|
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</AppStateProvider>
|
</AppStateProvider>
|
||||||
@ -160,7 +155,7 @@ describe('Proposal header', () => {
|
|||||||
screen.queryByTestId('proposal-description')
|
screen.queryByTestId('proposal-description')
|
||||||
).not.toBeInTheDocument();
|
).not.toBeInTheDocument();
|
||||||
expect(screen.getByTestId('proposal-details')).toHaveTextContent(
|
expect(screen.getByTestId('proposal-details')).toHaveTextContent(
|
||||||
'Update to market: MarketId'
|
/Update to market: MarketId/
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { MemoryRouter } from 'react-router-dom';
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import { MockedProvider } from '@apollo/client/testing';
|
import { MockedProvider } from '@apollo/client/testing';
|
||||||
import { VegaWalletProvider } from '@vegaprotocol/wallet';
|
|
||||||
import { type VegaWalletConfig } from '@vegaprotocol/wallet';
|
|
||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
import { generateProposal } from '../../test-helpers/generate-proposals';
|
import { generateProposal } from '../../test-helpers/generate-proposals';
|
||||||
import { Proposal } from './proposal';
|
import { Proposal } from './proposal';
|
||||||
import { ProposalState } from '@vegaprotocol/types';
|
import { ProposalState } from '@vegaprotocol/types';
|
||||||
import { type Proposal as IProposal } from '../../types';
|
import { type Proposal as IProposal } from '../../types';
|
||||||
|
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
||||||
|
import { MockedWalletProvider } from '@vegaprotocol/wallet-react/testing';
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/network-parameters', () => ({
|
jest.mock('@vegaprotocol/network-parameters', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/network-parameters'),
|
...jest.requireActual('@vegaprotocol/network-parameters'),
|
||||||
@ -24,45 +24,44 @@ jest.mock('@vegaprotocol/network-parameters', () => ({
|
|||||||
error: null,
|
error: null,
|
||||||
})),
|
})),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../proposal-detail-header/proposal-header', () => ({
|
jest.mock('../proposal-detail-header/proposal-header', () => ({
|
||||||
ProposalHeader: () => <div data-testid="proposal-header"></div>,
|
ProposalHeader: () => <div data-testid="proposal-header"></div>,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../proposal-change-table', () => ({
|
jest.mock('../proposal-change-table', () => ({
|
||||||
ProposalChangeTable: () => <div data-testid="proposal-change-table"></div>,
|
ProposalChangeTable: () => <div data-testid="proposal-change-table"></div>,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../proposal-json', () => ({
|
jest.mock('../proposal-json', () => ({
|
||||||
ProposalJson: () => <div data-testid="proposal-json"></div>,
|
ProposalJson: () => <div data-testid="proposal-json"></div>,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../list-asset', () => ({
|
jest.mock('../list-asset', () => ({
|
||||||
ListAsset: () => <div data-testid="proposal-list-asset"></div>,
|
ListAsset: () => <div data-testid="proposal-list-asset"></div>,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('./proposal-change-details', () => ({
|
jest.mock('../list-asset', () => ({
|
||||||
ProposalChangeDetails: () => (
|
ListAsset: () => <div data-testid="proposal-list-asset"></div>,
|
||||||
<div data-testid="proposal-change-details"></div>
|
|
||||||
),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const vegaWalletConfig: VegaWalletConfig = {
|
jest.mock('../vote-details', () => ({
|
||||||
network: 'TESTNET',
|
UserVote: () => <div data-testid="user-vote"></div>,
|
||||||
vegaUrl: 'https://vega.xyz',
|
}));
|
||||||
vegaWalletServiceUrl: 'https://wallet.vega.xyz',
|
|
||||||
links: {
|
jest.mock('./proposal-change-details', () => ({
|
||||||
explorer: 'explorer',
|
ProposalChangeDetails: () => <div data-testid="proposal-change-details" />,
|
||||||
concepts: 'concepts',
|
}));
|
||||||
chromeExtensionUrl: 'chrome',
|
|
||||||
mozillaExtensionUrl: 'mozilla',
|
|
||||||
},
|
|
||||||
chainId: 'VEGA_CHAIN_ID',
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderComponent = (proposal: IProposal) => {
|
const renderComponent = (proposal: IProposal) => {
|
||||||
render(
|
return render(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<MockedProvider>
|
<MockedProvider>
|
||||||
<VegaWalletProvider config={vegaWalletConfig}>
|
<MockedWalletProvider>
|
||||||
<Proposal restData={null} proposal={proposal} />
|
<AppStateProvider>
|
||||||
</VegaWalletProvider>
|
<Proposal restData={null} proposal={proposal} />
|
||||||
|
</AppStateProvider>
|
||||||
|
</MockedWalletProvider>
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
);
|
);
|
||||||
|
@ -23,7 +23,7 @@ export interface ProposalProps {
|
|||||||
|
|
||||||
export const Proposal = ({ proposal, restData }: ProposalProps) => {
|
export const Proposal = ({ proposal, restData }: ProposalProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { submit, Dialog, finalizedVote, transaction } = useVoteSubmit();
|
const { submit, finalizedVote, transaction } = useVoteSubmit();
|
||||||
const { voteState, voteDatetime } = useUserVote(proposal?.id, finalizedVote);
|
const { voteState, voteDatetime } = useUserVote(proposal?.id, finalizedVote);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -88,7 +88,6 @@ export const Proposal = ({ proposal, restData }: ProposalProps) => {
|
|||||||
<UserVote
|
<UserVote
|
||||||
proposal={proposal}
|
proposal={proposal}
|
||||||
submit={submit}
|
submit={submit}
|
||||||
dialog={Dialog}
|
|
||||||
transaction={transaction}
|
transaction={transaction}
|
||||||
voteState={voteState}
|
voteState={voteState}
|
||||||
voteDatetime={voteDatetime}
|
voteDatetime={voteDatetime}
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
import { BrowserRouter as Router } from 'react-router-dom';
|
import { BrowserRouter as Router } from 'react-router-dom';
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
|
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
||||||
import { ProposalsListItemDetails } from './proposals-list-item-details';
|
import { ProposalsListItemDetails } from './proposals-list-item-details';
|
||||||
import { mockWalletContext } from '../../test-helpers/mocks';
|
|
||||||
|
|
||||||
const renderComponent = (id: string) =>
|
const renderComponent = (id: string) =>
|
||||||
render(
|
render(
|
||||||
<Router>
|
<Router>
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
<AppStateProvider>
|
||||||
<ProposalsListItemDetails id={id} />
|
<ProposalsListItemDetails id={id} />
|
||||||
</VegaWalletContext.Provider>
|
</AppStateProvider>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,25 +1,32 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import { act, render, screen } from '@testing-library/react';
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
import {
|
||||||
|
MockedWalletProvider,
|
||||||
|
mockConfig,
|
||||||
|
} from '@vegaprotocol/wallet-react/testing';
|
||||||
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
||||||
import { ProposalFormSubmit } from './proposal-form-submit';
|
import { ProposalFormSubmit } from './proposal-form-submit';
|
||||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
|
||||||
|
|
||||||
const renderComponent = (
|
const renderComponent = (isSubmitting: boolean) => {
|
||||||
context: VegaWalletContextShape,
|
|
||||||
isSubmitting: boolean
|
|
||||||
) => {
|
|
||||||
render(
|
render(
|
||||||
<AppStateProvider>
|
<MockedWalletProvider>
|
||||||
<VegaWalletContext.Provider value={context}>
|
<AppStateProvider>
|
||||||
<ProposalFormSubmit isSubmitting={isSubmitting} />
|
<ProposalFormSubmit isSubmitting={isSubmitting} />
|
||||||
</VegaWalletContext.Provider>
|
</AppStateProvider>
|
||||||
</AppStateProvider>
|
</MockedWalletProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('Proposal Form Submit', () => {
|
describe('Proposal Form Submit', () => {
|
||||||
|
const pubKey = { publicKey: '123456__123456', name: 'test' };
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
act(() => {
|
||||||
|
mockConfig.reset();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should display connection message and button if wallet not connected', () => {
|
it('should display connection message and button if wallet not connected', () => {
|
||||||
renderComponent({ pubKey: null } as VegaWalletContextShape, false);
|
renderComponent(false);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
screen.getByText('Connect your wallet to submit a proposal')
|
screen.getByText('Connect your wallet to submit a proposal')
|
||||||
@ -30,28 +37,22 @@ describe('Proposal Form Submit', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should display submit button if wallet is connected', () => {
|
it('should display submit button if wallet is connected', () => {
|
||||||
const pubKey = { publicKey: '123456__123456', name: 'test' };
|
mockConfig.store.setState({
|
||||||
renderComponent(
|
pubKey: pubKey.publicKey,
|
||||||
{
|
keys: [pubKey],
|
||||||
pubKey: pubKey.publicKey,
|
});
|
||||||
pubKeys: [pubKey],
|
renderComponent(false);
|
||||||
} as VegaWalletContextShape,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
expect(screen.getByTestId('proposal-submit')).toHaveTextContent(
|
expect(screen.getByTestId('proposal-submit')).toHaveTextContent(
|
||||||
'Submit proposal'
|
'Submit proposal'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display submitting button text if wallet is connected and submitting', () => {
|
it('should display submitting button text if wallet is connected and submitting', () => {
|
||||||
const pubKey = { publicKey: '123456__123456', name: 'test' };
|
mockConfig.store.setState({
|
||||||
renderComponent(
|
pubKey: pubKey.publicKey,
|
||||||
{
|
keys: [pubKey],
|
||||||
pubKey: pubKey.publicKey,
|
});
|
||||||
pubKeys: [pubKey],
|
renderComponent(true);
|
||||||
} as VegaWalletContextShape,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
expect(screen.getByTestId('proposal-submit')).toHaveTextContent(
|
expect(screen.getByTestId('proposal-submit')).toHaveTextContent(
|
||||||
'Submitting proposal'
|
'Submitting proposal'
|
||||||
);
|
);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Button } from '@vegaprotocol/ui-toolkit';
|
import { Button } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { VegaWalletContainer } from '../../../../components/vega-wallet-container';
|
import { VegaWalletContainer } from '../../../../components/vega-wallet-container';
|
||||||
|
|
||||||
interface ProposalFormSubmitProps {
|
interface ProposalFormSubmitProps {
|
||||||
|
@ -1,19 +1,24 @@
|
|||||||
import {
|
import {
|
||||||
|
VegaTransactionDialog,
|
||||||
getProposalDialogIcon,
|
getProposalDialogIcon,
|
||||||
getProposalDialogIntent,
|
getProposalDialogIntent,
|
||||||
useGetProposalDialogTitle,
|
useGetProposalDialogTitle,
|
||||||
} from '@vegaprotocol/proposals';
|
} from '@vegaprotocol/proposals';
|
||||||
import type { ProposalEventFieldsFragment } from '@vegaprotocol/proposals';
|
import type {
|
||||||
import type { DialogProps } from '@vegaprotocol/proposals';
|
ProposalEventFieldsFragment,
|
||||||
|
VegaTxState,
|
||||||
|
} from '@vegaprotocol/proposals';
|
||||||
|
|
||||||
interface ProposalFormTransactionDialogProps {
|
interface ProposalFormTransactionDialogProps {
|
||||||
finalizedProposal: ProposalEventFieldsFragment | null;
|
finalizedProposal: ProposalEventFieldsFragment | null;
|
||||||
TransactionDialog: (props: DialogProps) => JSX.Element;
|
transaction: VegaTxState;
|
||||||
|
onChange: (open: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProposalFormTransactionDialog = ({
|
export const ProposalFormTransactionDialog = ({
|
||||||
finalizedProposal,
|
finalizedProposal,
|
||||||
TransactionDialog,
|
transaction,
|
||||||
|
onChange,
|
||||||
}: ProposalFormTransactionDialogProps) => {
|
}: ProposalFormTransactionDialogProps) => {
|
||||||
const title = useGetProposalDialogTitle(finalizedProposal?.state);
|
const title = useGetProposalDialogTitle(finalizedProposal?.state);
|
||||||
// Render a custom complete UI if the proposal was rejected otherwise
|
// Render a custom complete UI if the proposal was rejected otherwise
|
||||||
@ -24,13 +29,16 @@ export const ProposalFormTransactionDialog = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div data-testid="proposal-transaction-dialog">
|
<div data-testid="proposal-transaction-dialog">
|
||||||
<TransactionDialog
|
<VegaTransactionDialog
|
||||||
title={title}
|
title={title}
|
||||||
intent={getProposalDialogIntent(finalizedProposal?.state)}
|
intent={getProposalDialogIntent(finalizedProposal?.state)}
|
||||||
icon={getProposalDialogIcon(finalizedProposal?.state)}
|
icon={getProposalDialogIcon(finalizedProposal?.state)}
|
||||||
content={{
|
content={{
|
||||||
Complete: completeContent,
|
Complete: completeContent,
|
||||||
}}
|
}}
|
||||||
|
transaction={transaction}
|
||||||
|
isOpen={transaction.dialogOpen}
|
||||||
|
onChange={onChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
import { BrowserRouter as Router } from 'react-router-dom';
|
import { BrowserRouter as Router } from 'react-router-dom';
|
||||||
import { MockedProvider } from '@apollo/client/testing';
|
import { MockedProvider } from '@apollo/client/testing';
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import {
|
import {
|
||||||
lastWeek,
|
lastWeek,
|
||||||
mockWalletContext,
|
|
||||||
networkParamsQueryMock,
|
networkParamsQueryMock,
|
||||||
nextWeek,
|
nextWeek,
|
||||||
} from '../../test-helpers/mocks';
|
} from '../../test-helpers/mocks';
|
||||||
@ -48,9 +46,7 @@ const renderComponent = (
|
|||||||
render(
|
render(
|
||||||
<Router>
|
<Router>
|
||||||
<MockedProvider mocks={mocks}>
|
<MockedProvider mocks={mocks}>
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
<VoteBreakdown proposal={proposal} />
|
||||||
<VoteBreakdown proposal={proposal} />
|
|
||||||
</VegaWalletContext.Provider>
|
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
@ -60,6 +56,7 @@ describe('VoteBreakdown', () => {
|
|||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
jest.setSystemTime(0);
|
jest.setSystemTime(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
jest.useRealTimers();
|
jest.useRealTimers();
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { captureMessage } from '@sentry/minimal';
|
import { captureMessage } from '@sentry/minimal';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { VoteValue } from '@vegaprotocol/types';
|
import { VoteValue } from '@vegaprotocol/types';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useUserVoteQuery } from './__generated__/Vote';
|
import { useUserVoteQuery } from './__generated__/Vote';
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Icon, ExternalLink } from '@vegaprotocol/ui-toolkit';
|
import { Icon, ExternalLink } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { ProposalState } from '@vegaprotocol/types';
|
import { ProposalState } from '@vegaprotocol/types';
|
||||||
import { ConnectToVega } from '../../../../components/connect-to-vega';
|
import { ConnectToVega } from '../../../../components/connect-to-vega';
|
||||||
import { VoteButtonsContainer } from './vote-buttons';
|
import { VoteButtonsContainer } from './vote-buttons';
|
||||||
import { SubHeading } from '../../../../components/heading';
|
import { SubHeading } from '../../../../components/heading';
|
||||||
import { type VoteValue } from '@vegaprotocol/types';
|
import { type VoteValue } from '@vegaprotocol/types';
|
||||||
import { type DialogProps, type VegaTxState } from '@vegaprotocol/proposals';
|
import { type VegaTxState } from '@vegaprotocol/proposals';
|
||||||
import { type VoteState } from './use-user-vote';
|
import { type VoteState } from './use-user-vote';
|
||||||
import { type Proposal, type BatchProposal } from '../../types';
|
import { type Proposal, type BatchProposal } from '../../types';
|
||||||
|
|
||||||
interface UserVoteProps {
|
interface UserVoteProps {
|
||||||
proposal: Proposal | BatchProposal;
|
proposal: Proposal | BatchProposal;
|
||||||
transaction: VegaTxState | null;
|
transaction: VegaTxState;
|
||||||
submit: (voteValue: VoteValue, proposalId: string | null) => Promise<void>;
|
submit: (voteValue: VoteValue, proposalId: string | null) => Promise<void>;
|
||||||
dialog: (props: DialogProps) => JSX.Element;
|
|
||||||
voteState: VoteState | null;
|
voteState: VoteState | null;
|
||||||
voteDatetime: Date | null;
|
voteDatetime: Date | null;
|
||||||
}
|
}
|
||||||
@ -23,7 +22,6 @@ export const UserVote = ({
|
|||||||
proposal,
|
proposal,
|
||||||
submit,
|
submit,
|
||||||
transaction,
|
transaction,
|
||||||
dialog,
|
|
||||||
voteState,
|
voteState,
|
||||||
voteDatetime,
|
voteDatetime,
|
||||||
}: UserVoteProps) => {
|
}: UserVoteProps) => {
|
||||||
@ -56,7 +54,6 @@ export const UserVote = ({
|
|||||||
className="flex"
|
className="flex"
|
||||||
submit={submit}
|
submit={submit}
|
||||||
transaction={transaction}
|
transaction={transaction}
|
||||||
dialog={dialog}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
|
@ -2,33 +2,20 @@ import { render, screen } from '@testing-library/react';
|
|||||||
import { VoteTransactionDialog } from './vote-transaction-dialog';
|
import { VoteTransactionDialog } from './vote-transaction-dialog';
|
||||||
import { VoteState } from './use-user-vote';
|
import { VoteState } from './use-user-vote';
|
||||||
import { VegaTxStatus } from '@vegaprotocol/proposals';
|
import { VegaTxStatus } from '@vegaprotocol/proposals';
|
||||||
|
import { ConnectorErrors, unknownError } from '@vegaprotocol/wallet';
|
||||||
|
|
||||||
describe('VoteTransactionDialog', () => {
|
describe('VoteTransactionDialog', () => {
|
||||||
const mockTransactionDialog = jest.fn(({ title, content }) => (
|
|
||||||
<div>
|
|
||||||
<div>{title}</div>
|
|
||||||
<div>{content?.Complete}</div>
|
|
||||||
</div>
|
|
||||||
));
|
|
||||||
|
|
||||||
it('renders without crashing', () => {
|
|
||||||
render(
|
|
||||||
<VoteTransactionDialog
|
|
||||||
voteState={VoteState.Yes}
|
|
||||||
transaction={null}
|
|
||||||
TransactionDialog={mockTransactionDialog}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(screen.getByTestId('vote-transaction-dialog')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders with txRequested title when voteState is Requested', () => {
|
it('renders with txRequested title when voteState is Requested', () => {
|
||||||
render(
|
render(
|
||||||
<VoteTransactionDialog
|
<VoteTransactionDialog
|
||||||
voteState={VoteState.Requested}
|
voteState={VoteState.Requested}
|
||||||
transaction={null}
|
transaction={{
|
||||||
TransactionDialog={mockTransactionDialog}
|
error: null,
|
||||||
|
txHash: null,
|
||||||
|
signature: null,
|
||||||
|
status: VegaTxStatus.Requested,
|
||||||
|
dialogOpen: true,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -39,8 +26,13 @@ describe('VoteTransactionDialog', () => {
|
|||||||
render(
|
render(
|
||||||
<VoteTransactionDialog
|
<VoteTransactionDialog
|
||||||
voteState={VoteState.Pending}
|
voteState={VoteState.Pending}
|
||||||
transaction={null}
|
transaction={{
|
||||||
TransactionDialog={mockTransactionDialog}
|
error: null,
|
||||||
|
txHash: null,
|
||||||
|
signature: null,
|
||||||
|
status: VegaTxStatus.Pending,
|
||||||
|
dialogOpen: true,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -51,8 +43,13 @@ describe('VoteTransactionDialog', () => {
|
|||||||
render(
|
render(
|
||||||
<VoteTransactionDialog
|
<VoteTransactionDialog
|
||||||
voteState={VoteState.Yes} // or any other state other than Requested or Pending
|
voteState={VoteState.Yes} // or any other state other than Requested or Pending
|
||||||
transaction={null}
|
transaction={{
|
||||||
TransactionDialog={mockTransactionDialog}
|
error: null,
|
||||||
|
txHash: null,
|
||||||
|
signature: null,
|
||||||
|
status: VegaTxStatus.Complete,
|
||||||
|
dialogOpen: true,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -65,17 +62,18 @@ describe('VoteTransactionDialog', () => {
|
|||||||
<VoteTransactionDialog
|
<VoteTransactionDialog
|
||||||
voteState={VoteState.Failed}
|
voteState={VoteState.Failed}
|
||||||
transaction={{
|
transaction={{
|
||||||
error: { message: 'Custom error test message', name: 'blah' },
|
error: unknownError(),
|
||||||
txHash: null,
|
txHash: null,
|
||||||
signature: null,
|
signature: null,
|
||||||
status: VegaTxStatus.Error,
|
status: VegaTxStatus.Error,
|
||||||
dialogOpen: false,
|
dialogOpen: true,
|
||||||
}}
|
}}
|
||||||
TransactionDialog={mockTransactionDialog}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(screen.getByText('Custom error test message')).toBeInTheDocument();
|
expect(
|
||||||
|
screen.getByText(ConnectorErrors.unknown.message)
|
||||||
|
).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders default error message when voteState is failed and no error message exists on the tx', () => {
|
it('renders default error message when voteState is failed and no error message exists on the tx', () => {
|
||||||
@ -86,10 +84,9 @@ describe('VoteTransactionDialog', () => {
|
|||||||
error: null,
|
error: null,
|
||||||
txHash: null,
|
txHash: null,
|
||||||
signature: null,
|
signature: null,
|
||||||
status: VegaTxStatus.Error,
|
status: VegaTxStatus.Complete,
|
||||||
dialogOpen: false,
|
dialogOpen: true,
|
||||||
}}
|
}}
|
||||||
TransactionDialog={mockTransactionDialog}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -100,8 +97,13 @@ describe('VoteTransactionDialog', () => {
|
|||||||
render(
|
render(
|
||||||
<VoteTransactionDialog
|
<VoteTransactionDialog
|
||||||
voteState={VoteState.Yes}
|
voteState={VoteState.Yes}
|
||||||
transaction={null}
|
transaction={{
|
||||||
TransactionDialog={mockTransactionDialog}
|
error: null,
|
||||||
|
txHash: null,
|
||||||
|
signature: null,
|
||||||
|
status: VegaTxStatus.Default,
|
||||||
|
dialogOpen: true,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,120 +1,77 @@
|
|||||||
import { fireEvent, render, screen } from '@testing-library/react';
|
import { act, fireEvent, render, screen } from '@testing-library/react';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import { VoteButtons } from './vote-buttons';
|
import { VoteButtons, type VoteButtonsProps } from './vote-buttons';
|
||||||
import { VoteState } from './use-user-vote';
|
import { VoteState } from './use-user-vote';
|
||||||
import { ProposalState } from '@vegaprotocol/types';
|
import { ProposalState } from '@vegaprotocol/types';
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
|
||||||
import { mockWalletContext } from '../../test-helpers/mocks';
|
|
||||||
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
||||||
import { MockedProvider } from '@apollo/react-testing';
|
import { MockedProvider } from '@apollo/react-testing';
|
||||||
|
import { VegaTxStatus } from '@vegaprotocol/proposals';
|
||||||
|
import {
|
||||||
|
MockedWalletProvider,
|
||||||
|
mockConfig,
|
||||||
|
} from '@vegaprotocol/wallet-react/testing';
|
||||||
|
|
||||||
describe('Vote buttons', () => {
|
describe('Vote buttons', () => {
|
||||||
it('should render successfully', () => {
|
const key = { publicKey: '0x123', name: 'key 1' };
|
||||||
const { baseElement } = render(
|
const transaction = {
|
||||||
|
status: VegaTxStatus.Default,
|
||||||
|
error: null,
|
||||||
|
txHash: null,
|
||||||
|
signature: null,
|
||||||
|
dialogOpen: false,
|
||||||
|
};
|
||||||
|
const props = {
|
||||||
|
voteState: VoteState.NotCast,
|
||||||
|
voteDatetime: null,
|
||||||
|
proposalState: ProposalState.STATE_OPEN,
|
||||||
|
proposalId: null,
|
||||||
|
minVoterBalance: null,
|
||||||
|
spamProtectionMinTokens: null,
|
||||||
|
currentStakeAvailable: new BigNumber(1),
|
||||||
|
submit: () => Promise.resolve(),
|
||||||
|
transaction,
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderComponent = (testProps?: Partial<VoteButtonsProps>) => {
|
||||||
|
return render(
|
||||||
<AppStateProvider>
|
<AppStateProvider>
|
||||||
<MockedProvider>
|
<MockedProvider>
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
<MockedWalletProvider>
|
||||||
<VoteButtons
|
<VoteButtons {...props} {...testProps} />
|
||||||
voteState={VoteState.NotCast}
|
</MockedWalletProvider>
|
||||||
voteDatetime={null}
|
|
||||||
proposalState={ProposalState.STATE_OPEN}
|
|
||||||
proposalId={null}
|
|
||||||
minVoterBalance={null}
|
|
||||||
spamProtectionMinTokens={null}
|
|
||||||
currentStakeAvailable={new BigNumber(1)}
|
|
||||||
dialog={() => <div>Blah</div>}
|
|
||||||
submit={() => Promise.resolve()}
|
|
||||||
transaction={null}
|
|
||||||
/>
|
|
||||||
</VegaWalletContext.Provider>
|
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
</AppStateProvider>
|
</AppStateProvider>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockConfig.store.setState({ pubKey: key.publicKey, keys: [key] });
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
act(() => {
|
||||||
|
mockConfig.reset();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render successfully', () => {
|
||||||
|
const { baseElement } = renderComponent();
|
||||||
expect(baseElement).toBeTruthy();
|
expect(baseElement).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should explain that voting is closed if the proposal is not open', () => {
|
it('should explain that voting is closed if the proposal is not open', () => {
|
||||||
render(
|
renderComponent({ proposalState: ProposalState.STATE_PASSED });
|
||||||
<AppStateProvider>
|
|
||||||
<MockedProvider>
|
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
|
||||||
<VoteButtons
|
|
||||||
voteState={VoteState.NotCast}
|
|
||||||
voteDatetime={null}
|
|
||||||
proposalState={ProposalState.STATE_PASSED}
|
|
||||||
proposalId={null}
|
|
||||||
minVoterBalance={null}
|
|
||||||
spamProtectionMinTokens={null}
|
|
||||||
currentStakeAvailable={new BigNumber(1)}
|
|
||||||
dialog={() => <div>Blah</div>}
|
|
||||||
submit={() => Promise.resolve()}
|
|
||||||
transaction={null}
|
|
||||||
/>
|
|
||||||
</VegaWalletContext.Provider>
|
|
||||||
</MockedProvider>
|
|
||||||
</AppStateProvider>
|
|
||||||
);
|
|
||||||
expect(screen.getByText('Voting has ended.')).toBeTruthy();
|
expect(screen.getByText('Voting has ended.')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should provide a connect wallet prompt if no pubkey', () => {
|
it('should provide a connect wallet prompt if no pubkey', () => {
|
||||||
const mockWalletNoPubKeyContext = {
|
mockConfig.reset();
|
||||||
pubKey: null,
|
renderComponent();
|
||||||
pubKeys: [],
|
|
||||||
isReadOnly: false,
|
|
||||||
sendTx: jest.fn().mockReturnValue(Promise.resolve(null)),
|
|
||||||
connect: jest.fn(),
|
|
||||||
disconnect: jest.fn(),
|
|
||||||
selectPubKey: jest.fn(),
|
|
||||||
connector: null,
|
|
||||||
} as unknown as VegaWalletContextShape;
|
|
||||||
|
|
||||||
render(
|
|
||||||
<AppStateProvider>
|
|
||||||
<MockedProvider>
|
|
||||||
<VegaWalletContext.Provider value={mockWalletNoPubKeyContext}>
|
|
||||||
<VoteButtons
|
|
||||||
voteState={VoteState.NotCast}
|
|
||||||
voteDatetime={null}
|
|
||||||
proposalState={ProposalState.STATE_OPEN}
|
|
||||||
proposalId={null}
|
|
||||||
minVoterBalance={null}
|
|
||||||
spamProtectionMinTokens={null}
|
|
||||||
currentStakeAvailable={new BigNumber(1)}
|
|
||||||
dialog={() => <div>Blah</div>}
|
|
||||||
submit={() => Promise.resolve()}
|
|
||||||
transaction={null}
|
|
||||||
/>
|
|
||||||
</VegaWalletContext.Provider>
|
|
||||||
</MockedProvider>
|
|
||||||
</AppStateProvider>
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(screen.getByTestId('connect-wallet')).toBeTruthy();
|
expect(screen.getByTestId('connect-wallet')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should tell the user they need tokens if their current stake is 0', () => {
|
it('should tell the user they need tokens if their current stake is 0', () => {
|
||||||
render(
|
renderComponent({ currentStakeAvailable: new BigNumber(0) });
|
||||||
<AppStateProvider>
|
|
||||||
<MockedProvider>
|
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
|
||||||
<VoteButtons
|
|
||||||
voteState={VoteState.NotCast}
|
|
||||||
voteDatetime={null}
|
|
||||||
proposalState={ProposalState.STATE_OPEN}
|
|
||||||
proposalId={null}
|
|
||||||
minVoterBalance={null}
|
|
||||||
spamProtectionMinTokens={null}
|
|
||||||
currentStakeAvailable={new BigNumber(0)}
|
|
||||||
dialog={() => <div>Blah</div>}
|
|
||||||
submit={() => Promise.resolve()}
|
|
||||||
transaction={null}
|
|
||||||
/>
|
|
||||||
</VegaWalletContext.Provider>
|
|
||||||
</MockedProvider>
|
|
||||||
</AppStateProvider>
|
|
||||||
);
|
|
||||||
expect(
|
expect(
|
||||||
screen.getByText(
|
screen.getByText(
|
||||||
'You need some VEGA tokens to participate in governance.'
|
'You need some VEGA tokens to participate in governance.'
|
||||||
@ -123,26 +80,10 @@ describe('Vote buttons', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should tell the user of the minimum requirements if they have some, but not enough tokens', () => {
|
it('should tell the user of the minimum requirements if they have some, but not enough tokens', () => {
|
||||||
render(
|
renderComponent({
|
||||||
<AppStateProvider>
|
minVoterBalance: '2000000000000000000',
|
||||||
<MockedProvider>
|
spamProtectionMinTokens: '1000000000000000000',
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
});
|
||||||
<VoteButtons
|
|
||||||
voteState={VoteState.NotCast}
|
|
||||||
voteDatetime={null}
|
|
||||||
proposalState={ProposalState.STATE_OPEN}
|
|
||||||
proposalId={null}
|
|
||||||
minVoterBalance="2000000000000000000"
|
|
||||||
spamProtectionMinTokens="1000000000000000000"
|
|
||||||
currentStakeAvailable={new BigNumber(1)}
|
|
||||||
dialog={() => <div>Blah</div>}
|
|
||||||
submit={() => Promise.resolve()}
|
|
||||||
transaction={null}
|
|
||||||
/>
|
|
||||||
</VegaWalletContext.Provider>
|
|
||||||
</MockedProvider>
|
|
||||||
</AppStateProvider>
|
|
||||||
);
|
|
||||||
expect(
|
expect(
|
||||||
screen.getByText(
|
screen.getByText(
|
||||||
'You must have at least 2 VEGA associated to vote on this proposal'
|
'You must have at least 2 VEGA associated to vote on this proposal'
|
||||||
@ -151,51 +92,23 @@ describe('Vote buttons', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show you voted if vote state is correct, and if the proposal is still open, it will display a change vote button', () => {
|
it('should show you voted if vote state is correct, and if the proposal is still open, it will display a change vote button', () => {
|
||||||
render(
|
renderComponent({
|
||||||
<AppStateProvider>
|
voteState: VoteState.Yes,
|
||||||
<MockedProvider>
|
minVoterBalance: '2000000000000000000',
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
spamProtectionMinTokens: '1000000000000000000',
|
||||||
<VoteButtons
|
currentStakeAvailable: new BigNumber(10),
|
||||||
voteState={VoteState.Yes}
|
});
|
||||||
voteDatetime={null}
|
|
||||||
proposalState={ProposalState.STATE_OPEN}
|
|
||||||
proposalId={null}
|
|
||||||
minVoterBalance="2000000000000000000"
|
|
||||||
spamProtectionMinTokens="1000000000000000000"
|
|
||||||
currentStakeAvailable={new BigNumber(10)}
|
|
||||||
dialog={() => <div>Blah</div>}
|
|
||||||
submit={() => Promise.resolve()}
|
|
||||||
transaction={null}
|
|
||||||
/>
|
|
||||||
</VegaWalletContext.Provider>
|
|
||||||
</MockedProvider>
|
|
||||||
</AppStateProvider>
|
|
||||||
);
|
|
||||||
expect(screen.getByTestId('you-voted')).toBeInTheDocument();
|
expect(screen.getByTestId('you-voted')).toBeInTheDocument();
|
||||||
expect(screen.getByTestId('change-vote-button')).toBeInTheDocument();
|
expect(screen.getByTestId('change-vote-button')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow you to change your vote', () => {
|
it('should allow you to change your vote', () => {
|
||||||
render(
|
renderComponent({
|
||||||
<AppStateProvider>
|
voteState: VoteState.No,
|
||||||
<MockedProvider>
|
minVoterBalance: '2000000000000000000',
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
spamProtectionMinTokens: '1000000000000000000',
|
||||||
<VoteButtons
|
currentStakeAvailable: new BigNumber(10),
|
||||||
voteState={VoteState.No}
|
});
|
||||||
voteDatetime={null}
|
|
||||||
proposalState={ProposalState.STATE_OPEN}
|
|
||||||
proposalId={null}
|
|
||||||
minVoterBalance="2000000000000000000"
|
|
||||||
spamProtectionMinTokens="1000000000000000000"
|
|
||||||
currentStakeAvailable={new BigNumber(10)}
|
|
||||||
dialog={() => <div>Blah</div>}
|
|
||||||
submit={() => Promise.resolve()}
|
|
||||||
transaction={null}
|
|
||||||
/>
|
|
||||||
</VegaWalletContext.Provider>
|
|
||||||
</MockedProvider>
|
|
||||||
</AppStateProvider>
|
|
||||||
);
|
|
||||||
fireEvent.click(screen.getByTestId('change-vote-button'));
|
fireEvent.click(screen.getByTestId('change-vote-button'));
|
||||||
expect(screen.getByTestId('vote-buttons')).toBeInTheDocument();
|
expect(screen.getByTestId('vote-buttons')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useVegaWallet, useDialogStore } from '@vegaprotocol/wallet-react';
|
||||||
import {
|
import {
|
||||||
AsyncRenderer,
|
AsyncRenderer,
|
||||||
Button,
|
Button,
|
||||||
@ -17,7 +17,7 @@ import { VoteState } from './use-user-vote';
|
|||||||
import { ProposalMinRequirements, ProposalUserAction } from '../shared';
|
import { ProposalMinRequirements, ProposalUserAction } from '../shared';
|
||||||
import { VoteTransactionDialog } from './vote-transaction-dialog';
|
import { VoteTransactionDialog } from './vote-transaction-dialog';
|
||||||
import { useVoteButtonsQuery } from './__generated__/Stake';
|
import { useVoteButtonsQuery } from './__generated__/Stake';
|
||||||
import type { DialogProps, VegaTxState } from '@vegaprotocol/proposals';
|
import type { VegaTxState } from '@vegaprotocol/proposals';
|
||||||
import { filterAcceptableGraphqlErrors } from '../../../../lib/party';
|
import { filterAcceptableGraphqlErrors } from '../../../../lib/party';
|
||||||
import {
|
import {
|
||||||
NetworkParams,
|
NetworkParams,
|
||||||
@ -32,8 +32,7 @@ interface VoteButtonsContainerProps {
|
|||||||
proposalId: string | null;
|
proposalId: string | null;
|
||||||
proposalState: ProposalState;
|
proposalState: ProposalState;
|
||||||
submit: (voteValue: VoteValue, proposalId: string | null) => Promise<void>;
|
submit: (voteValue: VoteValue, proposalId: string | null) => Promise<void>;
|
||||||
transaction: VegaTxState | null;
|
transaction: VegaTxState;
|
||||||
dialog: (props: DialogProps) => JSX.Element;
|
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,17 +135,16 @@ export const VoteButtonsContainer = (props: VoteButtonsContainerProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
interface VoteButtonsProps {
|
export interface VoteButtonsProps {
|
||||||
voteState: VoteState | null;
|
voteState: VoteState | null;
|
||||||
voteDatetime: Date | null;
|
voteDatetime: Date | null;
|
||||||
proposalId: string | null;
|
|
||||||
proposalState: ProposalState;
|
proposalState: ProposalState;
|
||||||
submit: (voteValue: VoteValue, proposalId: string | null) => Promise<void>;
|
proposalId: string | null;
|
||||||
transaction: VegaTxState | null;
|
|
||||||
dialog: (props: DialogProps) => JSX.Element;
|
|
||||||
currentStakeAvailable: BigNumber;
|
currentStakeAvailable: BigNumber;
|
||||||
minVoterBalance: string | null;
|
minVoterBalance: string | null;
|
||||||
spamProtectionMinTokens: string | null;
|
spamProtectionMinTokens: string | null;
|
||||||
|
submit: (voteValue: VoteValue, proposalId: string | null) => Promise<void>;
|
||||||
|
transaction: VegaTxState;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const VoteButtons = ({
|
export const VoteButtons = ({
|
||||||
@ -159,13 +157,10 @@ export const VoteButtons = ({
|
|||||||
spamProtectionMinTokens,
|
spamProtectionMinTokens,
|
||||||
submit,
|
submit,
|
||||||
transaction,
|
transaction,
|
||||||
dialog: Dialog,
|
|
||||||
}: VoteButtonsProps) => {
|
}: VoteButtonsProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { pubKey } = useVegaWallet();
|
const { pubKey } = useVegaWallet();
|
||||||
const { openVegaWalletDialog } = useVegaWalletDialogStore((store) => ({
|
const openVegaWalletDialog = useDialogStore((store) => store.open);
|
||||||
openVegaWalletDialog: store.openVegaWalletDialog,
|
|
||||||
}));
|
|
||||||
const [changeVote, setChangeVote] = React.useState(false);
|
const [changeVote, setChangeVote] = React.useState(false);
|
||||||
const proposalVotable = useMemo(
|
const proposalVotable = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@ -184,11 +179,7 @@ export const VoteButtons = ({
|
|||||||
if (!pubKey) {
|
if (!pubKey) {
|
||||||
return (
|
return (
|
||||||
<div data-testid="connect-wallet">
|
<div data-testid="connect-wallet">
|
||||||
<ButtonLink
|
<ButtonLink onClick={openVegaWalletDialog}>
|
||||||
onClick={() => {
|
|
||||||
openVegaWalletDialog();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t('connectVegaWallet')}
|
{t('connectVegaWallet')}
|
||||||
</ButtonLink>{' '}
|
</ButtonLink>{' '}
|
||||||
{t('toVote')}
|
{t('toVote')}
|
||||||
@ -301,11 +292,7 @@ export const VoteButtons = ({
|
|||||||
</p>
|
</p>
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
<VoteTransactionDialog
|
<VoteTransactionDialog voteState={voteState} transaction={transaction} />
|
||||||
voteState={voteState}
|
|
||||||
transaction={transaction}
|
|
||||||
TransactionDialog={Dialog}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import { t } from '@vegaprotocol/i18n';
|
import { t } from '@vegaprotocol/i18n';
|
||||||
import { VoteState } from './use-user-vote';
|
import { VoteState } from './use-user-vote';
|
||||||
import type { DialogProps, VegaTxState } from '@vegaprotocol/proposals';
|
import {
|
||||||
|
VegaTransactionDialog,
|
||||||
|
type VegaTxState,
|
||||||
|
} from '@vegaprotocol/proposals';
|
||||||
|
|
||||||
interface VoteTransactionDialogProps {
|
interface VoteTransactionDialogProps {
|
||||||
voteState: VoteState;
|
voteState: VoteState;
|
||||||
transaction: VegaTxState | null;
|
transaction: VegaTxState;
|
||||||
TransactionDialog: (props: DialogProps) => JSX.Element;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const dialogTitle = (voteState: VoteState): string | undefined => {
|
const dialogTitle = (voteState: VoteState): string | undefined => {
|
||||||
@ -22,22 +24,23 @@ const dialogTitle = (voteState: VoteState): string | undefined => {
|
|||||||
export const VoteTransactionDialog = ({
|
export const VoteTransactionDialog = ({
|
||||||
voteState,
|
voteState,
|
||||||
transaction,
|
transaction,
|
||||||
TransactionDialog,
|
|
||||||
}: VoteTransactionDialogProps) => {
|
}: VoteTransactionDialogProps) => {
|
||||||
// Render a custom message if the voting fails otherwise
|
// Render a custom message if the voting fails otherwise
|
||||||
// pass undefined so that the default vega transaction dialog UI gets used
|
// pass undefined so that the default vega transaction dialog UI gets used
|
||||||
const customMessage =
|
const customMessage =
|
||||||
voteState === VoteState.Failed ? (
|
voteState === VoteState.Failed ? (
|
||||||
<p>{transaction?.error?.message || t('voteError')}</p>
|
<p>{transaction.error?.message || t('voteError')}</p>
|
||||||
) : undefined;
|
) : undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div data-testid="vote-transaction-dialog">
|
<div data-testid="vote-transaction-dialog">
|
||||||
<TransactionDialog
|
<VegaTransactionDialog
|
||||||
title={dialogTitle(voteState)}
|
title={dialogTitle(voteState)}
|
||||||
|
transaction={transaction}
|
||||||
content={{
|
content={{
|
||||||
Complete: customMessage,
|
Complete: customMessage,
|
||||||
}}
|
}}
|
||||||
|
isOpen={transaction.dialogOpen}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
import { ProposeFreeform } from './propose-freeform';
|
import { ProposeFreeform } from './propose-freeform';
|
||||||
import { MockedProvider } from '@apollo/client/testing';
|
import { MockedProvider } from '@apollo/client/testing';
|
||||||
import { mockWalletContext } from '../../test-helpers/mocks';
|
|
||||||
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import { MemoryRouter as Router } from 'react-router-dom';
|
import { MemoryRouter as Router } from 'react-router-dom';
|
||||||
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
||||||
import type { MockedResponse } from '@apollo/client/testing';
|
import type { MockedResponse } from '@apollo/client/testing';
|
||||||
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
||||||
|
import { MockedWalletProvider } from '@vegaprotocol/wallet-react/testing';
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/environment', () => ({
|
jest.mock('@vegaprotocol/environment', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/environment'),
|
...jest.requireActual('@vegaprotocol/environment'),
|
||||||
@ -72,18 +71,19 @@ const updateMarketNetworkParamsQueryMock: MockedResponse<NetworkParamsQuery> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderComponent = () =>
|
const renderComponent = () => {
|
||||||
render(
|
return render(
|
||||||
<Router>
|
<Router>
|
||||||
<MockedProvider mocks={[updateMarketNetworkParamsQueryMock]}>
|
<MockedProvider mocks={[updateMarketNetworkParamsQueryMock]}>
|
||||||
<AppStateProvider>
|
<MockedWalletProvider>
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
<AppStateProvider>
|
||||||
<ProposeFreeform />
|
<ProposeFreeform />
|
||||||
</VegaWalletContext.Provider>
|
</AppStateProvider>
|
||||||
</AppStateProvider>
|
</MockedWalletProvider>
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Note: form submission is tested in propose-raw.spec.tsx. Reusable form
|
// Note: form submission is tested in propose-raw.spec.tsx. Reusable form
|
||||||
// components are tested in their own directory.
|
// components are tested in their own directory.
|
||||||
|
@ -51,7 +51,8 @@ export const ProposeFreeform = () => {
|
|||||||
watch,
|
watch,
|
||||||
trigger,
|
trigger,
|
||||||
} = useForm<FreeformProposalFormFields>();
|
} = useForm<FreeformProposalFormFields>();
|
||||||
const { finalizedProposal, submit, Dialog } = useProposalSubmit();
|
const { finalizedProposal, transaction, submit, setTransaction } =
|
||||||
|
useProposalSubmit();
|
||||||
|
|
||||||
const assembleProposal = (fields: FreeformProposalFormFields) => {
|
const assembleProposal = (fields: FreeformProposalFormFields) => {
|
||||||
const isVoteDeadlineAtMinimum =
|
const isVoteDeadlineAtMinimum =
|
||||||
@ -169,7 +170,8 @@ export const ProposeFreeform = () => {
|
|||||||
<ProposalFormDownloadJson downloadJson={viewJson} />
|
<ProposalFormDownloadJson downloadJson={viewJson} />
|
||||||
<ProposalFormTransactionDialog
|
<ProposalFormTransactionDialog
|
||||||
finalizedProposal={finalizedProposal}
|
finalizedProposal={finalizedProposal}
|
||||||
TransactionDialog={Dialog}
|
transaction={transaction}
|
||||||
|
onChange={(open) => setTransaction({ dialogOpen: open })}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
import { fireEvent, render, screen } from '@testing-library/react';
|
import { fireEvent, render, screen } from '@testing-library/react';
|
||||||
import { ProposeNetworkParameter } from './propose-network-parameter';
|
import { ProposeNetworkParameter } from './propose-network-parameter';
|
||||||
import { MockedProvider } from '@apollo/client/testing';
|
import { MockedProvider } from '@apollo/client/testing';
|
||||||
import { mockWalletContext } from '../../test-helpers/mocks';
|
|
||||||
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import { MemoryRouter as Router } from 'react-router-dom';
|
import { MemoryRouter as Router } from 'react-router-dom';
|
||||||
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
||||||
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
||||||
import type { MockedResponse } from '@apollo/client/testing';
|
import type { MockedResponse } from '@apollo/client/testing';
|
||||||
|
import { MockedWalletProvider } from '@vegaprotocol/wallet-react/testing';
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/environment', () => ({
|
jest.mock('@vegaprotocol/environment', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/environment'),
|
...jest.requireActual('@vegaprotocol/environment'),
|
||||||
@ -72,26 +71,27 @@ const updateMarketNetworkParamsQueryMock: MockedResponse<NetworkParamsQuery> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderComponent = () =>
|
const renderComponent = () => {
|
||||||
render(
|
return render(
|
||||||
<Router>
|
<Router>
|
||||||
<MockedProvider mocks={[updateMarketNetworkParamsQueryMock]}>
|
<MockedProvider mocks={[updateMarketNetworkParamsQueryMock]}>
|
||||||
<AppStateProvider>
|
<MockedWalletProvider>
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
<AppStateProvider>
|
||||||
<ProposeNetworkParameter />
|
<ProposeNetworkParameter />
|
||||||
</VegaWalletContext.Provider>
|
</AppStateProvider>
|
||||||
</AppStateProvider>
|
</MockedWalletProvider>
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Note: form submission is tested in propose-raw.spec.tsx. Reusable form
|
// Note: form submission is tested in propose-raw.spec.tsx. Reusable form
|
||||||
// components are tested in their own directory.
|
// components are tested in their own directory.
|
||||||
|
|
||||||
describe('Propose Network Parameter', () => {
|
describe('Propose Network Parameter', () => {
|
||||||
it('should render successfully', async () => {
|
it('should render successfully', () => {
|
||||||
const { baseElement } = renderComponent();
|
const { baseElement } = renderComponent();
|
||||||
await expect(baseElement).toBeTruthy();
|
expect(baseElement).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render the correct title', async () => {
|
it('should render the correct title', async () => {
|
||||||
|
@ -91,7 +91,8 @@ export const ProposeNetworkParameter = () => {
|
|||||||
watch,
|
watch,
|
||||||
trigger,
|
trigger,
|
||||||
} = useForm<NetworkParameterProposalFormFields>();
|
} = useForm<NetworkParameterProposalFormFields>();
|
||||||
const { finalizedProposal, submit, Dialog } = useProposalSubmit();
|
const { finalizedProposal, transaction, submit, setTransaction } =
|
||||||
|
useProposalSubmit();
|
||||||
|
|
||||||
const selectedParamEntry = params
|
const selectedParamEntry = params
|
||||||
? Object.entries(params).find(([key]) => key === selectedNetworkParam)
|
? Object.entries(params).find(([key]) => key === selectedNetworkParam)
|
||||||
@ -312,7 +313,8 @@ export const ProposeNetworkParameter = () => {
|
|||||||
<ProposalFormDownloadJson downloadJson={viewJson} />
|
<ProposalFormDownloadJson downloadJson={viewJson} />
|
||||||
<ProposalFormTransactionDialog
|
<ProposalFormTransactionDialog
|
||||||
finalizedProposal={finalizedProposal}
|
finalizedProposal={finalizedProposal}
|
||||||
TransactionDialog={Dialog}
|
transaction={transaction}
|
||||||
|
onChange={(open) => setTransaction({ dialogOpen: open })}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
import { MockedProvider } from '@apollo/client/testing';
|
import { MockedProvider } from '@apollo/client/testing';
|
||||||
import { MemoryRouter as Router } from 'react-router-dom';
|
import { MemoryRouter as Router } from 'react-router-dom';
|
||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
||||||
import { mockWalletContext } from '../../test-helpers/mocks';
|
|
||||||
import { ProposeNewAsset } from './propose-new-asset';
|
import { ProposeNewAsset } from './propose-new-asset';
|
||||||
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
||||||
import type { MockedResponse } from '@apollo/client/testing';
|
import type { MockedResponse } from '@apollo/client/testing';
|
||||||
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
||||||
|
import { MockedWalletProvider } from '@vegaprotocol/wallet-react/testing';
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/environment', () => ({
|
jest.mock('@vegaprotocol/environment', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/environment'),
|
...jest.requireActual('@vegaprotocol/environment'),
|
||||||
@ -72,26 +71,27 @@ const newAssetNetworkParamsQueryMock: MockedResponse<NetworkParamsQuery> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderComponent = () =>
|
const renderComponent = () => {
|
||||||
render(
|
return render(
|
||||||
<Router>
|
<Router>
|
||||||
<MockedProvider mocks={[newAssetNetworkParamsQueryMock]}>
|
<MockedProvider mocks={[newAssetNetworkParamsQueryMock]}>
|
||||||
<AppStateProvider>
|
<MockedWalletProvider>
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
<AppStateProvider>
|
||||||
<ProposeNewAsset />
|
<ProposeNewAsset />
|
||||||
</VegaWalletContext.Provider>
|
</AppStateProvider>
|
||||||
</AppStateProvider>
|
</MockedWalletProvider>
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Note: form submission is tested in propose-raw.spec.tsx. Reusable form
|
// Note: form submission is tested in propose-raw.spec.tsx. Reusable form
|
||||||
// components are tested in their own directory.
|
// components are tested in their own directory.
|
||||||
|
|
||||||
describe('Propose New Asset', () => {
|
describe('Propose New Asset', () => {
|
||||||
it('should render successfully', async () => {
|
it('should render successfully', () => {
|
||||||
const { baseElement } = renderComponent();
|
const { baseElement } = renderComponent();
|
||||||
await expect(baseElement).toBeTruthy();
|
expect(baseElement).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render the title', async () => {
|
it('should render the title', async () => {
|
||||||
|
@ -64,7 +64,8 @@ export const ProposeNewAsset = () => {
|
|||||||
watch,
|
watch,
|
||||||
trigger,
|
trigger,
|
||||||
} = useForm<NewAssetProposalFormFields>();
|
} = useForm<NewAssetProposalFormFields>();
|
||||||
const { finalizedProposal, submit, Dialog } = useProposalSubmit();
|
const { finalizedProposal, transaction, submit, setTransaction } =
|
||||||
|
useProposalSubmit();
|
||||||
|
|
||||||
const assembleProposal = (fields: NewAssetProposalFormFields) => {
|
const assembleProposal = (fields: NewAssetProposalFormFields) => {
|
||||||
const isVoteDeadlineAtMinimum = doesValueEquateToParam(
|
const isVoteDeadlineAtMinimum = doesValueEquateToParam(
|
||||||
@ -232,7 +233,8 @@ export const ProposeNewAsset = () => {
|
|||||||
<ProposalFormDownloadJson downloadJson={viewJson} />
|
<ProposalFormDownloadJson downloadJson={viewJson} />
|
||||||
<ProposalFormTransactionDialog
|
<ProposalFormTransactionDialog
|
||||||
finalizedProposal={finalizedProposal}
|
finalizedProposal={finalizedProposal}
|
||||||
TransactionDialog={Dialog}
|
transaction={transaction}
|
||||||
|
onChange={(open) => setTransaction({ dialogOpen: open })}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
import { ProposeNewMarket } from './propose-new-market';
|
import { ProposeNewMarket } from './propose-new-market';
|
||||||
import { MockedProvider } from '@apollo/client/testing';
|
import { MockedProvider } from '@apollo/client/testing';
|
||||||
import { mockWalletContext } from '../../test-helpers/mocks';
|
|
||||||
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import { BrowserRouter as Router } from 'react-router-dom';
|
import { BrowserRouter as Router } from 'react-router-dom';
|
||||||
import type { MockedResponse } from '@apollo/client/testing';
|
import type { MockedResponse } from '@apollo/client/testing';
|
||||||
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
||||||
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
||||||
|
import { MockedWalletProvider } from '@vegaprotocol/wallet-react/testing';
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/environment', () => ({
|
jest.mock('@vegaprotocol/environment', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/environment'),
|
...jest.requireActual('@vegaprotocol/environment'),
|
||||||
@ -72,26 +71,27 @@ const newMarketNetworkParamsQueryMock: MockedResponse<NetworkParamsQuery> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderComponent = () =>
|
const renderComponent = () => {
|
||||||
render(
|
return render(
|
||||||
<Router>
|
<Router>
|
||||||
<MockedProvider mocks={[newMarketNetworkParamsQueryMock]}>
|
<MockedProvider mocks={[newMarketNetworkParamsQueryMock]}>
|
||||||
<AppStateProvider>
|
<MockedWalletProvider>
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
<AppStateProvider>
|
||||||
<ProposeNewMarket />
|
<ProposeNewMarket />
|
||||||
</VegaWalletContext.Provider>
|
</AppStateProvider>
|
||||||
</AppStateProvider>
|
</MockedWalletProvider>
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Note: form submission is tested in propose-raw.spec.tsx. Reusable form
|
// Note: form submission is tested in propose-raw.spec.tsx. Reusable form
|
||||||
// components are tested in their own directory.
|
// components are tested in their own directory.
|
||||||
|
|
||||||
describe('Propose New Market', () => {
|
describe('Propose New Market', () => {
|
||||||
it('should render successfully', async () => {
|
it('should render successfully', () => {
|
||||||
const { baseElement } = renderComponent();
|
const { baseElement } = renderComponent();
|
||||||
await expect(baseElement).toBeTruthy();
|
expect(baseElement).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render the form components', async () => {
|
it('should render the form components', async () => {
|
||||||
|
@ -62,7 +62,8 @@ export const ProposeNewMarket = () => {
|
|||||||
watch,
|
watch,
|
||||||
trigger,
|
trigger,
|
||||||
} = useForm<NewMarketProposalFormFields>();
|
} = useForm<NewMarketProposalFormFields>();
|
||||||
const { finalizedProposal, submit, Dialog } = useProposalSubmit();
|
const { finalizedProposal, transaction, submit, setTransaction } =
|
||||||
|
useProposalSubmit();
|
||||||
|
|
||||||
const assembleProposal = (fields: NewMarketProposalFormFields) => {
|
const assembleProposal = (fields: NewMarketProposalFormFields) => {
|
||||||
const isVoteDeadlineAtMinimum = doesValueEquateToParam(
|
const isVoteDeadlineAtMinimum = doesValueEquateToParam(
|
||||||
@ -214,7 +215,8 @@ export const ProposeNewMarket = () => {
|
|||||||
<ProposalFormDownloadJson downloadJson={viewJson} />
|
<ProposalFormDownloadJson downloadJson={viewJson} />
|
||||||
<ProposalFormTransactionDialog
|
<ProposalFormTransactionDialog
|
||||||
finalizedProposal={finalizedProposal}
|
finalizedProposal={finalizedProposal}
|
||||||
TransactionDialog={Dialog}
|
transaction={transaction}
|
||||||
|
onChange={(open) => setTransaction({ dialogOpen: open })}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,8 +3,6 @@ import type { MockedResponse } from '@apollo/client/testing';
|
|||||||
import { addHours, getTime } from 'date-fns';
|
import { addHours, getTime } from 'date-fns';
|
||||||
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
||||||
import { MockedProvider } from '@apollo/client/testing';
|
import { MockedProvider } from '@apollo/client/testing';
|
||||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import * as Schema from '@vegaprotocol/types';
|
import * as Schema from '@vegaprotocol/types';
|
||||||
import { ProposeRaw } from './propose-raw';
|
import { ProposeRaw } from './propose-raw';
|
||||||
import { ProposalEventDocument } from '@vegaprotocol/proposals';
|
import { ProposalEventDocument } from '@vegaprotocol/proposals';
|
||||||
@ -12,6 +10,11 @@ import type { ProposalEventSubscription } from '@vegaprotocol/proposals';
|
|||||||
|
|
||||||
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
||||||
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
||||||
|
import {
|
||||||
|
MockedWalletProvider,
|
||||||
|
mockConfig,
|
||||||
|
} from '@vegaprotocol/wallet-react/testing';
|
||||||
|
import { userRejectedError } from '@vegaprotocol/wallet';
|
||||||
|
|
||||||
const paramsDelay = 20;
|
const paramsDelay = 20;
|
||||||
|
|
||||||
@ -103,23 +106,15 @@ describe('Raw proposal form', () => {
|
|||||||
},
|
},
|
||||||
delay: 300,
|
delay: 300,
|
||||||
};
|
};
|
||||||
const setup = (mockSendTx = jest.fn()) => {
|
const setup = () => {
|
||||||
return render(
|
return render(
|
||||||
<AppStateProvider>
|
<AppStateProvider>
|
||||||
<MockedProvider
|
<MockedProvider
|
||||||
mocks={[rawProposalNetworkParamsQueryMock, mockProposalEvent]}
|
mocks={[rawProposalNetworkParamsQueryMock, mockProposalEvent]}
|
||||||
>
|
>
|
||||||
<VegaWalletContext.Provider
|
<MockedWalletProvider>
|
||||||
value={
|
|
||||||
{
|
|
||||||
pubKey,
|
|
||||||
sendTx: mockSendTx,
|
|
||||||
links: { explorer: 'explorer' },
|
|
||||||
} as unknown as VegaWalletContextShape
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<ProposeRaw />
|
<ProposeRaw />
|
||||||
</VegaWalletContext.Provider>
|
</MockedWalletProvider>
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
</AppStateProvider>
|
</AppStateProvider>
|
||||||
);
|
);
|
||||||
@ -127,15 +122,22 @@ describe('Raw proposal form', () => {
|
|||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
|
mockConfig.store.setState({ status: 'connected', pubKey: '0x123' });
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
jest.useRealTimers();
|
jest.useRealTimers();
|
||||||
|
mockConfig.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles validation', async () => {
|
it('handles validation', async () => {
|
||||||
const mockSendTx = jest.fn().mockReturnValue(Promise.resolve());
|
const mockSendTx = jest.spyOn(mockConfig, 'sendTransaction');
|
||||||
setup(mockSendTx);
|
|
||||||
|
setup();
|
||||||
|
|
||||||
expect(await screen.findByTestId('proposal-submit')).toBeTruthy();
|
expect(await screen.findByTestId('proposal-submit')).toBeTruthy();
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@ -162,20 +164,25 @@ describe('Raw proposal form', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('sends the transaction', async () => {
|
it('sends the transaction', async () => {
|
||||||
const mockSendTx = jest.fn().mockReturnValue(
|
const mockSendTx = jest
|
||||||
new Promise((resolve) => {
|
.spyOn(mockConfig, 'sendTransaction')
|
||||||
setTimeout(
|
.mockReturnValue(
|
||||||
() =>
|
new Promise((resolve) => {
|
||||||
resolve({
|
setTimeout(
|
||||||
transactionHash: 'tx-hash',
|
() =>
|
||||||
signature:
|
resolve({
|
||||||
'cfe592d169f87d0671dd447751036d0dddc165b9c4b65e5a5060e2bbadd1aa726d4cbe9d3c3b327bcb0bff4f83999592619a2493f9bbd251fae99ce7ce766909',
|
transactionHash: 'tx-hash',
|
||||||
}),
|
signature:
|
||||||
100
|
'cfe592d169f87d0671dd447751036d0dddc165b9c4b65e5a5060e2bbadd1aa726d4cbe9d3c3b327bcb0bff4f83999592619a2493f9bbd251fae99ce7ce766909',
|
||||||
);
|
sentAt: new Date().toISOString(),
|
||||||
})
|
receivedAt: new Date().toISOString(),
|
||||||
);
|
}),
|
||||||
setup(mockSendTx);
|
100
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
setup();
|
||||||
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
jest.advanceTimersByTime(paramsDelay);
|
jest.advanceTimersByTime(paramsDelay);
|
||||||
@ -206,8 +213,12 @@ describe('Raw proposal form', () => {
|
|||||||
fireEvent.click(screen.getByTestId('proposal-submit'));
|
fireEvent.click(screen.getByTestId('proposal-submit'));
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(mockSendTx).toHaveBeenCalledWith(pubKey, {
|
expect(mockSendTx).toHaveBeenCalledWith({
|
||||||
proposalSubmission: JSON.parse(inputJSON),
|
publicKey: pubKey,
|
||||||
|
sendingMode: 'TYPE_SYNC',
|
||||||
|
transaction: {
|
||||||
|
proposalSubmission: JSON.parse(inputJSON),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(screen.getByTestId('dialog-title')).toHaveTextContent(
|
expect(screen.getByTestId('dialog-title')).toHaveTextContent(
|
||||||
@ -232,12 +243,12 @@ describe('Raw proposal form', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can be rejected by the user', async () => {
|
it('can be rejected by the user', async () => {
|
||||||
const mockSendTx = jest.fn().mockReturnValue(
|
jest.spyOn(mockConfig, 'sendTransaction').mockReturnValue(
|
||||||
new Promise((resolve) => {
|
new Promise((_, reject) => {
|
||||||
setTimeout(() => resolve(null), 100);
|
setTimeout(() => reject(userRejectedError()), 100);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
setup(mockSendTx);
|
setup();
|
||||||
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
jest.advanceTimersByTime(paramsDelay);
|
jest.advanceTimersByTime(paramsDelay);
|
||||||
|
@ -52,7 +52,8 @@ export const ProposeRaw = () => {
|
|||||||
handleSubmit,
|
handleSubmit,
|
||||||
formState: { isSubmitting, errors },
|
formState: { isSubmitting, errors },
|
||||||
} = useForm<RawProposalFormFields>();
|
} = useForm<RawProposalFormFields>();
|
||||||
const { finalizedProposal, submit, Dialog } = useProposalSubmit();
|
const { finalizedProposal, transaction, submit, setTransaction } =
|
||||||
|
useProposalSubmit();
|
||||||
|
|
||||||
const hasError = Boolean(errors.rawProposalData?.message);
|
const hasError = Boolean(errors.rawProposalData?.message);
|
||||||
|
|
||||||
@ -152,7 +153,8 @@ export const ProposeRaw = () => {
|
|||||||
<ProposalFormSubmit isSubmitting={isSubmitting} />
|
<ProposalFormSubmit isSubmitting={isSubmitting} />
|
||||||
<ProposalFormTransactionDialog
|
<ProposalFormTransactionDialog
|
||||||
finalizedProposal={finalizedProposal}
|
finalizedProposal={finalizedProposal}
|
||||||
TransactionDialog={Dialog}
|
transaction={transaction}
|
||||||
|
onChange={(open) => setTransaction({ dialogOpen: open })}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
import { MockedProvider } from '@apollo/client/testing';
|
import { MockedProvider } from '@apollo/client/testing';
|
||||||
import { MemoryRouter as Router } from 'react-router-dom';
|
import { MemoryRouter as Router } from 'react-router-dom';
|
||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
||||||
import { mockWalletContext } from '../../test-helpers/mocks';
|
|
||||||
import { ProposeUpdateAsset } from './propose-update-asset';
|
import { ProposeUpdateAsset } from './propose-update-asset';
|
||||||
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
||||||
import type { MockedResponse } from '@apollo/client/testing';
|
import type { MockedResponse } from '@apollo/client/testing';
|
||||||
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
||||||
|
import { MockedWalletProvider } from '@vegaprotocol/wallet-react/testing';
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/environment', () => ({
|
jest.mock('@vegaprotocol/environment', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/environment'),
|
...jest.requireActual('@vegaprotocol/environment'),
|
||||||
@ -72,26 +71,27 @@ const updateAssetNetworkParamsQueryMock: MockedResponse<NetworkParamsQuery> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderComponent = () =>
|
const renderComponent = () => {
|
||||||
render(
|
return render(
|
||||||
<Router>
|
<Router>
|
||||||
<MockedProvider mocks={[updateAssetNetworkParamsQueryMock]}>
|
<MockedProvider mocks={[updateAssetNetworkParamsQueryMock]}>
|
||||||
<AppStateProvider>
|
<MockedWalletProvider>
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
<AppStateProvider>
|
||||||
<ProposeUpdateAsset />
|
<ProposeUpdateAsset />
|
||||||
</VegaWalletContext.Provider>
|
</AppStateProvider>
|
||||||
</AppStateProvider>
|
</MockedWalletProvider>
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Note: form submission is tested in propose-raw.spec.tsx. Reusable form
|
// Note: form submission is tested in propose-raw.spec.tsx. Reusable form
|
||||||
// components are tested in their own directory.
|
// components are tested in their own directory.
|
||||||
|
|
||||||
describe('Propose Update Asset', () => {
|
describe('Propose Update Asset', () => {
|
||||||
it('should render successfully', async () => {
|
it('should render successfully', () => {
|
||||||
const { baseElement } = renderComponent();
|
const { baseElement } = renderComponent();
|
||||||
await expect(baseElement).toBeTruthy();
|
expect(baseElement).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render the title', async () => {
|
it('should render the title', async () => {
|
||||||
|
@ -62,7 +62,8 @@ export const ProposeUpdateAsset = () => {
|
|||||||
watch,
|
watch,
|
||||||
trigger,
|
trigger,
|
||||||
} = useForm<UpdateAssetProposalFormFields>();
|
} = useForm<UpdateAssetProposalFormFields>();
|
||||||
const { finalizedProposal, submit, Dialog } = useProposalSubmit();
|
const { finalizedProposal, transaction, submit, setTransaction } =
|
||||||
|
useProposalSubmit();
|
||||||
|
|
||||||
const assembleProposal = (fields: UpdateAssetProposalFormFields) => {
|
const assembleProposal = (fields: UpdateAssetProposalFormFields) => {
|
||||||
const isVoteDeadlineAtMinimum = doesValueEquateToParam(
|
const isVoteDeadlineAtMinimum = doesValueEquateToParam(
|
||||||
@ -218,7 +219,8 @@ export const ProposeUpdateAsset = () => {
|
|||||||
<ProposalFormDownloadJson downloadJson={viewJson} />
|
<ProposalFormDownloadJson downloadJson={viewJson} />
|
||||||
<ProposalFormTransactionDialog
|
<ProposalFormTransactionDialog
|
||||||
finalizedProposal={finalizedProposal}
|
finalizedProposal={finalizedProposal}
|
||||||
TransactionDialog={Dialog}
|
transaction={transaction}
|
||||||
|
onChange={(open) => setTransaction({ dialogOpen: open })}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,15 +2,14 @@ import type { MockedResponse } from '@apollo/client/testing';
|
|||||||
import { MockedProvider } from '@apollo/client/testing';
|
import { MockedProvider } from '@apollo/client/testing';
|
||||||
import { MemoryRouter as Router } from 'react-router-dom';
|
import { MemoryRouter as Router } from 'react-router-dom';
|
||||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
import { AppStateProvider } from '../../../../contexts/app-state/app-state-provider';
|
||||||
import { mockWalletContext } from '../../test-helpers/mocks';
|
|
||||||
import { ProposeUpdateMarket } from './propose-update-market';
|
import { ProposeUpdateMarket } from './propose-update-market';
|
||||||
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
||||||
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
||||||
import type { ProposalMarketsQueryQuery } from './__generated__/UpdateMarket';
|
import type { ProposalMarketsQueryQuery } from './__generated__/UpdateMarket';
|
||||||
import { ProposalMarketsQueryDocument } from './__generated__/UpdateMarket';
|
import { ProposalMarketsQueryDocument } from './__generated__/UpdateMarket';
|
||||||
import { ProposalState } from '@vegaprotocol/types';
|
import { ProposalState } from '@vegaprotocol/types';
|
||||||
|
import { MockedWalletProvider } from '@vegaprotocol/wallet-react/testing';
|
||||||
|
|
||||||
const updateMarketNetworkParamsQueryMock: MockedResponse<NetworkParamsQuery> = {
|
const updateMarketNetworkParamsQueryMock: MockedResponse<NetworkParamsQuery> = {
|
||||||
request: {
|
request: {
|
||||||
@ -217,29 +216,30 @@ const marketQueryMock: MockedResponse<ProposalMarketsQueryQuery> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderComponent = () =>
|
const renderComponent = () => {
|
||||||
render(
|
return render(
|
||||||
<MockedProvider
|
<MockedProvider
|
||||||
mocks={[updateMarketNetworkParamsQueryMock, marketQueryMock]}
|
mocks={[updateMarketNetworkParamsQueryMock, marketQueryMock]}
|
||||||
addTypename={false}
|
addTypename={false}
|
||||||
>
|
>
|
||||||
<Router>
|
<Router>
|
||||||
<AppStateProvider>
|
<MockedWalletProvider>
|
||||||
<VegaWalletContext.Provider value={mockWalletContext}>
|
<AppStateProvider>
|
||||||
<ProposeUpdateMarket />
|
<ProposeUpdateMarket />
|
||||||
</VegaWalletContext.Provider>
|
</AppStateProvider>
|
||||||
</AppStateProvider>
|
</MockedWalletProvider>
|
||||||
</Router>
|
</Router>
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Note: form submission is tested in propose-raw.spec.tsx. Reusable form
|
// Note: form submission is tested in propose-raw.spec.tsx. Reusable form
|
||||||
// components are tested in their own directory.
|
// components are tested in their own directory.
|
||||||
|
|
||||||
describe('Propose Update Market', () => {
|
describe('Propose Update Market', () => {
|
||||||
it('should render successfully', async () => {
|
it('should render successfully', () => {
|
||||||
const { baseElement } = renderComponent();
|
const { baseElement } = renderComponent();
|
||||||
await expect(baseElement).toBeTruthy();
|
expect(baseElement).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render the title', async () => {
|
it('should render the title', async () => {
|
||||||
|
@ -109,7 +109,8 @@ export const ProposeUpdateMarket = () => {
|
|||||||
watch,
|
watch,
|
||||||
trigger,
|
trigger,
|
||||||
} = useForm<UpdateMarketProposalFormFields>();
|
} = useForm<UpdateMarketProposalFormFields>();
|
||||||
const { finalizedProposal, submit, Dialog } = useProposalSubmit();
|
const { finalizedProposal, transaction, submit, setTransaction } =
|
||||||
|
useProposalSubmit();
|
||||||
|
|
||||||
const assembleProposal = (fields: UpdateMarketProposalFormFields) => {
|
const assembleProposal = (fields: UpdateMarketProposalFormFields) => {
|
||||||
const isVoteDeadlineAtMinimum = doesValueEquateToParam(
|
const isVoteDeadlineAtMinimum = doesValueEquateToParam(
|
||||||
@ -323,7 +324,8 @@ export const ProposeUpdateMarket = () => {
|
|||||||
<ProposalFormDownloadJson downloadJson={viewJson} />
|
<ProposalFormDownloadJson downloadJson={viewJson} />
|
||||||
<ProposalFormTransactionDialog
|
<ProposalFormTransactionDialog
|
||||||
finalizedProposal={finalizedProposal}
|
finalizedProposal={finalizedProposal}
|
||||||
TransactionDialog={Dialog}
|
transaction={transaction}
|
||||||
|
onChange={(open) => setTransaction({ dialogOpen: open })}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,28 +1,17 @@
|
|||||||
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
import { NetworkParamsDocument } from '@vegaprotocol/network-parameters';
|
||||||
import type { MockedResponse } from '@apollo/client/testing';
|
import type { MockedResponse } from '@apollo/client/testing';
|
||||||
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
import type { NetworkParamsQuery } from '@vegaprotocol/network-parameters';
|
||||||
import type { PubKey, VegaWalletContextShape } from '@vegaprotocol/wallet';
|
|
||||||
import type { VoteValue } from '@vegaprotocol/types';
|
import type { VoteValue } from '@vegaprotocol/types';
|
||||||
import type { UserVoteQuery } from '../components/vote-details/__generated__/Vote';
|
import type { UserVoteQuery } from '../components/vote-details/__generated__/Vote';
|
||||||
import { UserVoteDocument } from '../components/vote-details/__generated__/Vote';
|
import { UserVoteDocument } from '../components/vote-details/__generated__/Vote';
|
||||||
import faker from 'faker';
|
import faker from 'faker';
|
||||||
|
import { type Key } from '@vegaprotocol/wallet';
|
||||||
|
|
||||||
export const mockPubkey: PubKey = {
|
export const mockPubkey: Key = {
|
||||||
publicKey: '0x123',
|
publicKey: '0x123',
|
||||||
name: 'test key 1',
|
name: 'test key 1',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mockWalletContext = {
|
|
||||||
pubKey: mockPubkey.publicKey,
|
|
||||||
pubKeys: [mockPubkey],
|
|
||||||
isReadOnly: false,
|
|
||||||
sendTx: jest.fn().mockReturnValue(Promise.resolve(null)),
|
|
||||||
connect: jest.fn(),
|
|
||||||
disconnect: jest.fn(),
|
|
||||||
selectPubKey: jest.fn(),
|
|
||||||
connector: null,
|
|
||||||
} as unknown as VegaWalletContextShape;
|
|
||||||
|
|
||||||
const mockEthereumConfig = {
|
const mockEthereumConfig = {
|
||||||
network_id: '3',
|
network_id: '3',
|
||||||
chain_id: '3',
|
chain_id: '3',
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useDialogStore } from '@vegaprotocol/wallet-react';
|
||||||
import { Button } from '@vegaprotocol/ui-toolkit';
|
import { Button } from '@vegaprotocol/ui-toolkit';
|
||||||
import { SubHeading } from '../../components/heading';
|
import { SubHeading } from '../../components/heading';
|
||||||
|
|
||||||
export const ConnectToSeeRewards = () => {
|
export const ConnectToSeeRewards = () => {
|
||||||
const { openVegaWalletDialog } = useVegaWalletDialogStore((store) => ({
|
const openVegaWalletDialog = useDialogStore((store) => store.open);
|
||||||
openVegaWalletDialog: store.openVegaWalletDialog,
|
|
||||||
}));
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const classes = classNames(
|
const classes = classNames(
|
||||||
|
@ -4,7 +4,7 @@ import { AsyncRenderer, Pagination } from '@vegaprotocol/ui-toolkit';
|
|||||||
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
||||||
import type { EpochFieldsFragment } from '../home/__generated__/Rewards';
|
import type { EpochFieldsFragment } from '../home/__generated__/Rewards';
|
||||||
import { useRewardsQuery } from '../home/__generated__/Rewards';
|
import { useRewardsQuery } from '../home/__generated__/Rewards';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { EpochIndividualRewardsTable } from './epoch-individual-rewards-table';
|
import { EpochIndividualRewardsTable } from './epoch-individual-rewards-table';
|
||||||
import { generateEpochIndividualRewardsList } from './generate-epoch-individual-rewards-list';
|
import { generateEpochIndividualRewardsList } from './generate-epoch-individual-rewards-list';
|
||||||
import { calculateEpochOffset } from '../../../lib/epoch-pagination';
|
import { calculateEpochOffset } from '../../../lib/epoch-pagination';
|
||||||
|
@ -10,7 +10,7 @@ import {
|
|||||||
Toggle,
|
Toggle,
|
||||||
ExternalLink,
|
ExternalLink,
|
||||||
} from '@vegaprotocol/ui-toolkit';
|
} from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import {
|
import {
|
||||||
useNetworkParams,
|
useNetworkParams,
|
||||||
NetworkParams,
|
NetworkParams,
|
||||||
|
@ -33,8 +33,8 @@ let mockVegaWalletHookValue: {
|
|||||||
pubKey: null,
|
pubKey: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/wallet', () => ({
|
jest.mock('@vegaprotocol/wallet-react', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/wallet'),
|
...jest.requireActual('@vegaprotocol/wallet-react'),
|
||||||
useVegaWallet: jest.fn(() => mockVegaWalletHookValue),
|
useVegaWallet: jest.fn(() => mockVegaWalletHookValue),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { useWeb3React } from '@web3-react/core';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { EthConnectPrompt } from '../../../../../components/eth-connect-prompt';
|
import { EthConnectPrompt } from '../../../../../components/eth-connect-prompt';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { ConnectToVega } from '../../../../../components/connect-to-vega';
|
import { ConnectToVega } from '../../../../../components/connect-to-vega';
|
||||||
|
|
||||||
export const StakingWalletsContainer = ({
|
export const StakingWalletsContainer = ({
|
||||||
|
@ -33,8 +33,8 @@ let mockVegaWalletHookValue: {
|
|||||||
pubKey: null,
|
pubKey: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/wallet', () => ({
|
jest.mock('@vegaprotocol/wallet-react', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/wallet'),
|
...jest.requireActual('@vegaprotocol/wallet-react'),
|
||||||
useVegaWallet: jest.fn(() => mockVegaWalletHookValue),
|
useVegaWallet: jest.fn(() => mockVegaWalletHookValue),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useWeb3React } from '@web3-react/core';
|
import { useWeb3React } from '@web3-react/core';
|
||||||
import { EthConnectPrompt } from '../../../components/eth-connect-prompt';
|
import { EthConnectPrompt } from '../../../components/eth-connect-prompt';
|
||||||
import { DisassociatePage } from './components/disassociate-page';
|
import { DisassociatePage } from './components/disassociate-page';
|
||||||
|
@ -5,7 +5,7 @@ import { useStakingQuery } from '../__generated__/Staking';
|
|||||||
import { usePreviousEpochQuery } from '../__generated__/PreviousEpoch';
|
import { usePreviousEpochQuery } from '../__generated__/PreviousEpoch';
|
||||||
import { ValidatorTables } from './validator-tables';
|
import { ValidatorTables } from './validator-tables';
|
||||||
import { useRefreshAfterEpoch } from '../../../hooks/use-refresh-after-epoch';
|
import { useRefreshAfterEpoch } from '../../../hooks/use-refresh-after-epoch';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { getMultisigStatusInfo } from '../../../lib/get-multisig-status-info';
|
import { getMultisigStatusInfo } from '../../../lib/get-multisig-status-info';
|
||||||
import { MultisigIncorrectNotice } from '../../../components/multisig-incorrect-notice';
|
import { MultisigIncorrectNotice } from '../../../components/multisig-incorrect-notice';
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
|
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import {
|
import {
|
||||||
addDecimal,
|
addDecimal,
|
||||||
removePaginationWrapper,
|
removePaginationWrapper,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Callout, Intent, Splash } from '@vegaprotocol/ui-toolkit';
|
import { Callout, Intent, Splash } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useRefreshAfterEpoch } from '../../../hooks/use-refresh-after-epoch';
|
import { useRefreshAfterEpoch } from '../../../hooks/use-refresh-after-epoch';
|
||||||
import { SplashLoader } from '../../../components/splash-loader';
|
import { SplashLoader } from '../../../components/splash-loader';
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import * as Sentry from '@sentry/react';
|
|
||||||
import { Button, Callout, Intent, Loader } from '@vegaprotocol/ui-toolkit';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { useAppState } from '../../../contexts/app-state/app-state-context';
|
|
||||||
import type { BigNumber } from '../../../lib/bignumber';
|
|
||||||
import type { UndelegateSubmissionBody } from '@vegaprotocol/wallet';
|
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
|
||||||
import { removeDecimal } from '@vegaprotocol/utils';
|
|
||||||
|
|
||||||
interface PendingStakeProps {
|
|
||||||
pendingAmount: BigNumber;
|
|
||||||
nodeId: string;
|
|
||||||
pubKey: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum FormState {
|
|
||||||
Default,
|
|
||||||
Pending,
|
|
||||||
Success,
|
|
||||||
Failure,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PendingStake = ({
|
|
||||||
pendingAmount,
|
|
||||||
nodeId,
|
|
||||||
pubKey,
|
|
||||||
}: PendingStakeProps) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const { sendTx } = useVegaWallet();
|
|
||||||
const { appState } = useAppState();
|
|
||||||
const [formState, setFormState] = React.useState(FormState.Default);
|
|
||||||
|
|
||||||
const removeStakeNow = async () => {
|
|
||||||
setFormState(FormState.Pending);
|
|
||||||
try {
|
|
||||||
const command: UndelegateSubmissionBody = {
|
|
||||||
undelegateSubmission: {
|
|
||||||
nodeId,
|
|
||||||
amount: removeDecimal(pendingAmount.toString(), appState.decimals),
|
|
||||||
method: 'METHOD_NOW',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
await sendTx(pubKey, command);
|
|
||||||
} catch (err) {
|
|
||||||
setFormState(FormState.Failure);
|
|
||||||
Sentry.captureException(err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (formState === FormState.Failure) {
|
|
||||||
return (
|
|
||||||
<Callout
|
|
||||||
intent={Intent.Danger}
|
|
||||||
title={t('failedToRemovePendingStake', { pendingAmount })}
|
|
||||||
>
|
|
||||||
<p>{t('pleaseTryAgain')}</p>
|
|
||||||
</Callout>
|
|
||||||
);
|
|
||||||
} else if (formState === FormState.Pending) {
|
|
||||||
return (
|
|
||||||
<Callout
|
|
||||||
icon={<Loader size="small" />}
|
|
||||||
title={t('removingPendingStake', { pendingAmount })}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="py-4">
|
|
||||||
<h2>{t('pendingNomination')}</h2>
|
|
||||||
<p>{t('pendingNominationNextEpoch', { pendingAmount })}</p>
|
|
||||||
<Button onClick={() => removeStakeNow()}>
|
|
||||||
{t('cancelPendingEpochNomination')}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
@ -27,11 +27,11 @@ import {
|
|||||||
NetworkParams,
|
NetworkParams,
|
||||||
} from '@vegaprotocol/network-parameters';
|
} from '@vegaprotocol/network-parameters';
|
||||||
import { useBalances } from '../../../lib/balances/balances-store';
|
import { useBalances } from '../../../lib/balances/balances-store';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { SubHeading } from '../../../components/heading';
|
import { SubHeading } from '../../../components/heading';
|
||||||
import type {
|
import {
|
||||||
DelegateSubmissionBody,
|
type DelegateSubmissionBody,
|
||||||
UndelegateSubmissionBody,
|
type UndelegateSubmissionBody,
|
||||||
} from '@vegaprotocol/wallet';
|
} from '@vegaprotocol/wallet';
|
||||||
import Routes from '../../routes';
|
import Routes from '../../routes';
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
useWithdrawalDialog,
|
useWithdrawalDialog,
|
||||||
WithdrawalsTable,
|
WithdrawalsTable,
|
||||||
} from '@vegaprotocol/withdraws';
|
} from '@vegaprotocol/withdraws';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||||
import { useDocumentTitle } from '../../hooks/use-document-title';
|
import { useDocumentTitle } from '../../hooks/use-document-title';
|
||||||
import type { RouteChildProps } from '../index';
|
import type { RouteChildProps } from '../index';
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
VegaIconNames,
|
VegaIconNames,
|
||||||
useToasts,
|
useToasts,
|
||||||
} from '@vegaprotocol/ui-toolkit';
|
} from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useDialogStore } from '@vegaprotocol/wallet-react';
|
||||||
import {
|
import {
|
||||||
useEthereumTransactionToasts,
|
useEthereumTransactionToasts,
|
||||||
useEthereumWithdrawApprovalsToasts,
|
useEthereumWithdrawApprovalsToasts,
|
||||||
@ -19,9 +19,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
const WalletDisconnectAdditionalContent = () => {
|
const WalletDisconnectAdditionalContent = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { hideToast } = useWalletDisconnectToastActions();
|
const { hideToast } = useWalletDisconnectToastActions();
|
||||||
const openVegaWalletDialog = useVegaWalletDialogStore(
|
const openVegaWalletDialog = useDialogStore((store) => store.open);
|
||||||
(store) => store.openVegaWalletDialog
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<p className="mt-2">
|
<p className="mt-2">
|
||||||
<TradingButton
|
<TradingButton
|
||||||
|
@ -5,7 +5,7 @@ import {
|
|||||||
VegaIcon,
|
VegaIcon,
|
||||||
VegaIconNames,
|
VegaIconNames,
|
||||||
} from '@vegaprotocol/ui-toolkit';
|
} from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useVegaWallet, useDialogStore } from '@vegaprotocol/wallet-react';
|
||||||
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
||||||
import { useT } from '../../lib/use-t';
|
import { useT } from '../../lib/use-t';
|
||||||
import { useReferralSetTransaction } from '../../lib/hooks/use-referral-set-transaction';
|
import { useReferralSetTransaction } from '../../lib/hooks/use-referral-set-transaction';
|
||||||
@ -26,9 +26,7 @@ export const CompetitionsCreateTeam = () => {
|
|||||||
usePageTitle(t('Create a team'));
|
usePageTitle(t('Create a team'));
|
||||||
|
|
||||||
const { isReadOnly, pubKey } = useVegaWallet();
|
const { isReadOnly, pubKey } = useVegaWallet();
|
||||||
const openWalletDialog = useVegaWalletDialogStore(
|
const openWalletDialog = useDialogStore((store) => store.open);
|
||||||
(store) => store.openVegaWalletDialog
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ErrorBoundary feature="create-team">
|
<ErrorBoundary feature="create-team">
|
||||||
|
@ -31,7 +31,7 @@ import { TeamStats } from '../../components/competitions/team-stats';
|
|||||||
import { usePageTitle } from '../../lib/hooks/use-page-title';
|
import { usePageTitle } from '../../lib/hooks/use-page-title';
|
||||||
import { ErrorBoundary } from '../../components/error-boundary';
|
import { ErrorBoundary } from '../../components/error-boundary';
|
||||||
import { LayoutWithGradient } from '../../components/layouts-inner';
|
import { LayoutWithGradient } from '../../components/layouts-inner';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { JoinTeam } from './join-team';
|
import { JoinTeam } from './join-team';
|
||||||
import { UpdateTeamButton } from './update-team-button';
|
import { UpdateTeamButton } from './update-team-button';
|
||||||
import {
|
import {
|
||||||
|
@ -2,7 +2,7 @@ import { ErrorBoundary } from '../../components/error-boundary';
|
|||||||
import { usePageTitle } from '../../lib/hooks/use-page-title';
|
import { usePageTitle } from '../../lib/hooks/use-page-title';
|
||||||
import { Box } from '../../components/competitions/box';
|
import { Box } from '../../components/competitions/box';
|
||||||
import { useT } from '../../lib/use-t';
|
import { useT } from '../../lib/use-t';
|
||||||
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useVegaWallet, useDialogStore } from '@vegaprotocol/wallet-react';
|
||||||
import {
|
import {
|
||||||
Intent,
|
Intent,
|
||||||
Loader,
|
Loader,
|
||||||
@ -24,9 +24,7 @@ export const CompetitionsUpdateTeam = () => {
|
|||||||
const t = useT();
|
const t = useT();
|
||||||
usePageTitle([t('Competitions'), t('Update a team')]);
|
usePageTitle([t('Competitions'), t('Update a team')]);
|
||||||
const { pubKey, isReadOnly } = useVegaWallet();
|
const { pubKey, isReadOnly } = useVegaWallet();
|
||||||
const openWalletDialog = useVegaWalletDialogStore(
|
const openWalletDialog = useDialogStore((store) => store.open);
|
||||||
(store) => store.openVegaWalletDialog
|
|
||||||
);
|
|
||||||
const { teamId } = useParams<{ teamId: string }>();
|
const { teamId } = useParams<{ teamId: string }>();
|
||||||
if (!teamId) {
|
if (!teamId) {
|
||||||
return <Navigate to={Links.COMPETITIONS()} />;
|
return <Navigate to={Links.COMPETITIONS()} />;
|
||||||
|
@ -29,7 +29,7 @@ describe('JoinButton', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('disables button if not connected', async () => {
|
it('disables button if not connected', async () => {
|
||||||
render(<JoinButton {...props} pubKey={null} />);
|
render(<JoinButton {...props} pubKey={undefined} />);
|
||||||
const button = screen.getByRole('button');
|
const button = screen.getByRole('button');
|
||||||
expect(button).toBeDisabled();
|
expect(button).toBeDisabled();
|
||||||
await userEvent.hover(button);
|
await userEvent.hover(button);
|
||||||
|
@ -6,7 +6,10 @@ import {
|
|||||||
VegaIcon,
|
VegaIcon,
|
||||||
VegaIconNames,
|
VegaIconNames,
|
||||||
} from '@vegaprotocol/ui-toolkit';
|
} from '@vegaprotocol/ui-toolkit';
|
||||||
import { useSimpleTransaction, useVegaWallet } from '@vegaprotocol/wallet';
|
import {
|
||||||
|
useSimpleTransaction,
|
||||||
|
useVegaWallet,
|
||||||
|
} from '@vegaprotocol/wallet-react';
|
||||||
import { useT } from '../../lib/use-t';
|
import { useT } from '../../lib/use-t';
|
||||||
import { type Team } from '../../lib/hooks/use-team';
|
import { type Team } from '../../lib/hooks/use-team';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
@ -59,7 +62,7 @@ export const JoinButton = ({
|
|||||||
partyTeam,
|
partyTeam,
|
||||||
onJoin,
|
onJoin,
|
||||||
}: {
|
}: {
|
||||||
pubKey: string | null;
|
pubKey: string | undefined;
|
||||||
isReadOnly: boolean;
|
isReadOnly: boolean;
|
||||||
team: Team;
|
team: Team;
|
||||||
partyTeam?: Team;
|
partyTeam?: Team;
|
||||||
|
@ -14,11 +14,11 @@ import { URL_REGEX, isValidVegaPublicKey } from '@vegaprotocol/utils';
|
|||||||
import { type useReferralSetTransaction } from '../../lib/hooks/use-referral-set-transaction';
|
import { type useReferralSetTransaction } from '../../lib/hooks/use-referral-set-transaction';
|
||||||
import { useT } from '../../lib/use-t';
|
import { useT } from '../../lib/use-t';
|
||||||
import { useForm, Controller } from 'react-hook-form';
|
import { useForm, Controller } from 'react-hook-form';
|
||||||
import type {
|
import {
|
||||||
CreateReferralSet,
|
type CreateReferralSet,
|
||||||
UpdateReferralSet,
|
type UpdateReferralSet,
|
||||||
Status,
|
|
||||||
} from '@vegaprotocol/wallet';
|
} from '@vegaprotocol/wallet';
|
||||||
|
import { type Status } from '@vegaprotocol/wallet-react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { useLayoutEffect, useState } from 'react';
|
import { useLayoutEffect, useState } from 'react';
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { type Team } from '../../lib/hooks/use-team';
|
import { type Team } from '../../lib/hooks/use-team';
|
||||||
import { type ComponentProps } from 'react';
|
import { type ComponentProps } from 'react';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { Intent, TradingAnchorButton } from '@vegaprotocol/ui-toolkit';
|
import { Intent, TradingAnchorButton } from '@vegaprotocol/ui-toolkit';
|
||||||
import { Links } from '../../lib/links';
|
import { Links } from '../../lib/links';
|
||||||
import { useT } from '../../lib/use-t';
|
import { useT } from '../../lib/use-t';
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
|
import classNames from 'classnames';
|
||||||
import { Intent, TradingAnchorButton } from '@vegaprotocol/ui-toolkit';
|
import { Intent, TradingAnchorButton } from '@vegaprotocol/ui-toolkit';
|
||||||
import { GetStartedCheckList } from '../../components/welcome-dialog';
|
import { GetStartedCheckList } from '../../components/welcome-dialog';
|
||||||
|
import { useOnboardingStore } from '../../stores/onboarding';
|
||||||
import {
|
import {
|
||||||
useGetOnboardingStep,
|
useGetOnboardingStep,
|
||||||
useOnboardingStore,
|
|
||||||
OnboardingStep,
|
OnboardingStep,
|
||||||
} from '../../components/welcome-dialog/use-get-onboarding-step';
|
} from '../../lib/hooks/use-get-onboarding-step';
|
||||||
import { Links } from '../../lib/links';
|
import { Links } from '../../lib/links';
|
||||||
import classNames from 'classnames';
|
|
||||||
import { useT } from '../../lib/use-t';
|
import { useT } from '../../lib/use-t';
|
||||||
|
|
||||||
export const DepositGetStarted = () => {
|
export const DepositGetStarted = () => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { matchFilter, lpAggregatedDataProvider } from '@vegaprotocol/liquidity';
|
import { matchFilter, lpAggregatedDataProvider } from '@vegaprotocol/liquidity';
|
||||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||||
import { Tab, Tabs } from '@vegaprotocol/ui-toolkit';
|
import { Tab, Tabs } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { LiquidityContainer } from '../../components/liquidity-container';
|
import { LiquidityContainer } from '../../components/liquidity-container';
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { act, render, screen, waitFor, within } from '@testing-library/react';
|
import { act, render, screen, waitFor, within } from '@testing-library/react';
|
||||||
// import userEvent from '@testing-library/user-event';
|
|
||||||
import { MemoryRouter } from 'react-router-dom';
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import { Closed } from './closed';
|
import { Closed } from './closed';
|
||||||
import { MarketStateMapping, PropertyKeyType } from '@vegaprotocol/types';
|
import { MarketStateMapping, PropertyKeyType } from '@vegaprotocol/types';
|
||||||
@ -18,8 +17,6 @@ import {
|
|||||||
MarketsDocument,
|
MarketsDocument,
|
||||||
getAsset,
|
getAsset,
|
||||||
} from '@vegaprotocol/markets';
|
} from '@vegaprotocol/markets';
|
||||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
||||||
import {
|
import {
|
||||||
createMarketFragment,
|
createMarketFragment,
|
||||||
@ -37,7 +34,6 @@ describe('Closed', () => {
|
|||||||
3
|
3
|
||||||
).toISOString();
|
).toISOString();
|
||||||
const settlementDateTag = `settlement-expiry-date:${settlementDateMetaDate}`;
|
const settlementDateTag = `settlement-expiry-date:${settlementDateMetaDate}`;
|
||||||
const pubKey = 'pubKey';
|
|
||||||
const marketId = 'market-0';
|
const marketId = 'market-0';
|
||||||
const settlementDataProperty = 'spec-binding';
|
const settlementDataProperty = 'spec-binding';
|
||||||
const settlementDataId = 'settlement-data-oracle-id';
|
const settlementDataId = 'settlement-data-oracle-id';
|
||||||
@ -175,11 +171,7 @@ describe('Closed', () => {
|
|||||||
render(
|
render(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<MockedProvider mocks={mocks}>
|
<MockedProvider mocks={mocks}>
|
||||||
<VegaWalletContext.Provider
|
<Closed />
|
||||||
value={{ pubKey } as VegaWalletContextShape}
|
|
||||||
>
|
|
||||||
<Closed />
|
|
||||||
</VegaWalletContext.Provider>
|
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
);
|
);
|
||||||
|
@ -14,7 +14,7 @@ import { useT } from '../../lib/use-t';
|
|||||||
import { useScreenDimensions } from '@vegaprotocol/react-helpers';
|
import { useScreenDimensions } from '@vegaprotocol/react-helpers';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useVegaWallet, useDialogStore } from '@vegaprotocol/wallet-react';
|
||||||
|
|
||||||
const ViewInitializer = () => {
|
const ViewInitializer = () => {
|
||||||
const currentRouteId = useGetCurrentRouteId();
|
const currentRouteId = useGetCurrentRouteId();
|
||||||
@ -34,9 +34,7 @@ export const MarketsMobileSidebar = () => {
|
|||||||
const t = useT();
|
const t = useT();
|
||||||
const currentRouteId = useGetCurrentRouteId();
|
const currentRouteId = useGetCurrentRouteId();
|
||||||
const { pubKeys, isReadOnly } = useVegaWallet();
|
const { pubKeys, isReadOnly } = useVegaWallet();
|
||||||
const openVegaWalletDialog = useVegaWalletDialogStore(
|
const openVegaWalletDialog = useDialogStore((store) => store.open);
|
||||||
(store) => store.openVegaWalletDialog
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Routes>
|
<Routes>
|
||||||
|
@ -15,8 +15,6 @@ import {
|
|||||||
MarketsDocument,
|
MarketsDocument,
|
||||||
MarketsCandlesDocument,
|
MarketsCandlesDocument,
|
||||||
} from '@vegaprotocol/markets';
|
} from '@vegaprotocol/markets';
|
||||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import {
|
import {
|
||||||
marketsQuery,
|
marketsQuery,
|
||||||
marketsDataQuery,
|
marketsDataQuery,
|
||||||
@ -27,7 +25,6 @@ import userEvent from '@testing-library/user-event';
|
|||||||
describe('Open', () => {
|
describe('Open', () => {
|
||||||
let originalNow: typeof Date.now;
|
let originalNow: typeof Date.now;
|
||||||
const mockNowTimestamp = 1672531200000;
|
const mockNowTimestamp = 1672531200000;
|
||||||
const pubKey = 'pubKey';
|
|
||||||
|
|
||||||
const marketsQueryData = marketsQuery();
|
const marketsQueryData = marketsQuery();
|
||||||
const marketsMock: MockedResponse<MarketsQuery> = {
|
const marketsMock: MockedResponse<MarketsQuery> = {
|
||||||
@ -80,11 +77,7 @@ describe('Open', () => {
|
|||||||
<MockedProvider
|
<MockedProvider
|
||||||
mocks={[marketsMock, marketsCandlesMock, marketsDataMock]}
|
mocks={[marketsMock, marketsCandlesMock, marketsDataMock]}
|
||||||
>
|
>
|
||||||
<VegaWalletContext.Provider
|
<OpenMarkets />
|
||||||
value={{ pubKey } as VegaWalletContextShape}
|
|
||||||
>
|
|
||||||
<OpenMarkets />
|
|
||||||
</VegaWalletContext.Provider>
|
|
||||||
</MockedProvider>
|
</MockedProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
);
|
);
|
||||||
|
@ -14,8 +14,8 @@ import { RainbowButton } from '../../components/rainbow-button';
|
|||||||
import {
|
import {
|
||||||
useSimpleTransaction,
|
useSimpleTransaction,
|
||||||
useVegaWallet,
|
useVegaWallet,
|
||||||
useVegaWalletDialogStore,
|
useDialogStore,
|
||||||
} from '@vegaprotocol/wallet';
|
} from '@vegaprotocol/wallet-react';
|
||||||
import { useIsInReferralSet, useReferral } from './hooks/use-referral';
|
import { useIsInReferralSet, useReferral } from './hooks/use-referral';
|
||||||
import { Routes } from '../../lib/links';
|
import { Routes } from '../../lib/links';
|
||||||
import { Statistics, useStats } from './referral-statistics';
|
import { Statistics, useStats } from './referral-statistics';
|
||||||
@ -83,9 +83,7 @@ export const ApplyCodeForm = ({ onSuccess }: { onSuccess?: () => void }) => {
|
|||||||
const t = useT();
|
const t = useT();
|
||||||
const program = useReferralProgram();
|
const program = useReferralProgram();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const openWalletDialog = useVegaWalletDialogStore(
|
const openWalletDialog = useDialogStore((store) => store.open);
|
||||||
(store) => store.openVegaWalletDialog
|
|
||||||
);
|
|
||||||
|
|
||||||
const { isReadOnly, pubKey } = useVegaWallet();
|
const { isReadOnly, pubKey } = useVegaWallet();
|
||||||
const { isEligible, requiredFunds } = useFundsAvailable();
|
const { isEligible, requiredFunds } = useFundsAvailable();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useVegaWallet, useDialogStore } from '@vegaprotocol/wallet-react';
|
||||||
import { RainbowButton } from '../../components/rainbow-button';
|
import { RainbowButton } from '../../components/rainbow-button';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import {
|
import {
|
||||||
@ -28,9 +28,7 @@ export const CreateCodeContainer = () => {
|
|||||||
const t = useT();
|
const t = useT();
|
||||||
const { pubKey, isReadOnly } = useVegaWallet();
|
const { pubKey, isReadOnly } = useVegaWallet();
|
||||||
const isInReferralSet = useIsInReferralSet(pubKey);
|
const isInReferralSet = useIsInReferralSet(pubKey);
|
||||||
const openWalletDialog = useVegaWalletDialogStore(
|
const openWalletDialog = useDialogStore((store) => store.open);
|
||||||
(store) => store.openVegaWalletDialog
|
|
||||||
);
|
|
||||||
|
|
||||||
// Navigate to the index page when already in the referral set.
|
// Navigate to the index page when already in the referral set.
|
||||||
if (isInReferralSet) {
|
if (isInReferralSet) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useFundsAvailableQuery } from './__generated__/FundsAvailable';
|
import { useFundsAvailableQuery } from './__generated__/FundsAvailable';
|
||||||
import compact from 'lodash/compact';
|
import compact from 'lodash/compact';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
} from '@vegaprotocol/ui-toolkit';
|
} from '@vegaprotocol/ui-toolkit';
|
||||||
import { useReferral } from './use-referral';
|
import { useReferral } from './use-referral';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useT } from '../../../lib/use-t';
|
import { useT } from '../../../lib/use-t';
|
||||||
import { matchPath, useLocation, useNavigate } from 'react-router-dom';
|
import { matchPath, useLocation, useNavigate } from 'react-router-dom';
|
||||||
|
@ -15,7 +15,7 @@ export const DEFAULT_AGGREGATION_DAYS = 30;
|
|||||||
export type Role = 'referrer' | 'referee';
|
export type Role = 'referrer' | 'referee';
|
||||||
type UseReferralArgs = (
|
type UseReferralArgs = (
|
||||||
| { code: string | undefined }
|
| { code: string | undefined }
|
||||||
| { pubKey: string | null; role: Role }
|
| { pubKey: string | undefined; role: Role }
|
||||||
) & {
|
) & {
|
||||||
aggregationEpochs?: number;
|
aggregationEpochs?: number;
|
||||||
};
|
};
|
||||||
@ -188,7 +188,7 @@ const retrieveReferralSetData = (data: ReferralSetsQuery | undefined) =>
|
|||||||
? data.referralSets.edges[0]?.node
|
? data.referralSets.edges[0]?.node
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
export const useIsInReferralSet = (pubKey: string | null) => {
|
export const useIsInReferralSet = (pubKey: string | undefined) => {
|
||||||
const [asRefereeVariables, asRefereeSkip] = prepareVariables({
|
const [asRefereeVariables, asRefereeSkip] = prepareVariables({
|
||||||
pubKey,
|
pubKey,
|
||||||
role: 'referee',
|
role: 'referee',
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
import { MockedProvider, type MockedResponse } from '@apollo/react-testing';
|
import { MockedProvider, type MockedResponse } from '@apollo/react-testing';
|
||||||
import { render, screen, waitFor } from '@testing-library/react';
|
import { render, screen, waitFor } from '@testing-library/react';
|
||||||
import {
|
|
||||||
VegaWalletContext,
|
|
||||||
type VegaWalletContextShape,
|
|
||||||
} from '@vegaprotocol/wallet';
|
|
||||||
import { ReferralStatistics } from './referral-statistics';
|
import { ReferralStatistics } from './referral-statistics';
|
||||||
import {
|
import {
|
||||||
ReferralProgramDocument,
|
ReferralProgramDocument,
|
||||||
@ -25,9 +21,22 @@ import {
|
|||||||
type RefereesQuery,
|
type RefereesQuery,
|
||||||
} from './hooks/__generated__/Referees';
|
} from './hooks/__generated__/Referees';
|
||||||
import { MemoryRouter } from 'react-router-dom';
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
|
import {
|
||||||
|
mockConfig,
|
||||||
|
MockedWalletProvider,
|
||||||
|
} from '@vegaprotocol/wallet-react/testing';
|
||||||
|
|
||||||
const MOCK_PUBKEY =
|
const mockKeys = [
|
||||||
'1234567890123456789012345678901234567890123456789012345678901234';
|
{
|
||||||
|
name: 'Key 1',
|
||||||
|
publicKey: '1'.repeat(64),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Key 2',
|
||||||
|
publicKey: '2'.repeat(64),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const MOCK_PUBKEY = mockKeys[0].publicKey;
|
||||||
|
|
||||||
const MOCK_STAKE_AVAILABLE: StakeAvailableQuery = {
|
const MOCK_STAKE_AVAILABLE: StakeAvailableQuery = {
|
||||||
networkParameter: {
|
networkParameter: {
|
||||||
@ -301,23 +310,29 @@ const refereesMock30: MockedResponse<RefereesQuery, RefereesQueryVariables> = {
|
|||||||
|
|
||||||
describe('ReferralStatistics', () => {
|
describe('ReferralStatistics', () => {
|
||||||
const renderComponent = (mocks: MockedResponse[]) => {
|
const renderComponent = (mocks: MockedResponse[]) => {
|
||||||
const walletContext = {
|
|
||||||
pubKey: MOCK_PUBKEY,
|
|
||||||
isReadOnly: false,
|
|
||||||
sendTx: jest.fn(),
|
|
||||||
} as unknown as VegaWalletContextShape;
|
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
<MemoryRouter>
|
<MemoryRouter>
|
||||||
<VegaWalletContext.Provider value={walletContext}>
|
<MockedProvider mocks={mocks} showWarnings={false}>
|
||||||
<MockedProvider mocks={mocks} showWarnings={false}>
|
<MockedWalletProvider>
|
||||||
<ReferralStatistics />
|
<ReferralStatistics />
|
||||||
</MockedProvider>
|
</MockedWalletProvider>
|
||||||
</VegaWalletContext.Provider>
|
</MockedProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
mockConfig.store.setState({
|
||||||
|
status: 'connected',
|
||||||
|
keys: mockKeys,
|
||||||
|
pubKey: mockKeys[0].publicKey,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
mockConfig.reset();
|
||||||
|
});
|
||||||
|
|
||||||
it('displays apply code when no data has been found for given pubkey', () => {
|
it('displays apply code when no data has been found for given pubkey', () => {
|
||||||
renderComponent([]);
|
renderComponent([]);
|
||||||
expect(
|
expect(
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
truncateMiddle,
|
truncateMiddle,
|
||||||
TextChildrenTooltip as Tooltip,
|
TextChildrenTooltip as Tooltip,
|
||||||
} from '@vegaprotocol/ui-toolkit';
|
} from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import {
|
import {
|
||||||
addDecimalsFormatNumber,
|
addDecimalsFormatNumber,
|
||||||
formatNumber,
|
formatNumber,
|
||||||
|
@ -9,7 +9,7 @@ import { TiersContainer } from './tiers';
|
|||||||
import { TabLink } from './buttons';
|
import { TabLink } from './buttons';
|
||||||
import { Outlet, useMatch } from 'react-router-dom';
|
import { Outlet, useMatch } from 'react-router-dom';
|
||||||
import { Routes } from '../../lib/links';
|
import { Routes } from '../../lib/links';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useReferral } from './hooks/use-referral';
|
import { useReferral } from './hooks/use-referral';
|
||||||
import { REFERRAL_DOCS_LINK } from './constants';
|
import { REFERRAL_DOCS_LINK } from './constants';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { Splash } from '@vegaprotocol/ui-toolkit';
|
import { Splash } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useAssetDetailsDialogStore } from '@vegaprotocol/assets';
|
import { useAssetDetailsDialogStore } from '@vegaprotocol/assets';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import type { PinnedAsset } from '@vegaprotocol/accounts';
|
import type { PinnedAsset } from '@vegaprotocol/accounts';
|
||||||
import { AccountManager } from '@vegaprotocol/accounts';
|
import { AccountManager } from '@vegaprotocol/accounts';
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
|
@ -2,42 +2,24 @@ import type { InMemoryCacheConfig } from '@apollo/client';
|
|||||||
import {
|
import {
|
||||||
AppFailure,
|
AppFailure,
|
||||||
AppLoader,
|
AppLoader,
|
||||||
DocsLinks,
|
|
||||||
NetworkLoader,
|
NetworkLoader,
|
||||||
NodeFailure,
|
NodeFailure,
|
||||||
NodeGuard,
|
NodeGuard,
|
||||||
useEnvironment,
|
useEnvironment,
|
||||||
} from '@vegaprotocol/environment';
|
} from '@vegaprotocol/environment';
|
||||||
import { VegaWalletProvider } from '@vegaprotocol/wallet';
|
import { type ReactNode } from 'react';
|
||||||
import type { ReactNode } from 'react';
|
|
||||||
import { Web3Provider } from './web3-provider';
|
import { Web3Provider } from './web3-provider';
|
||||||
import { useT } from '../../lib/use-t';
|
import { useT } from '../../lib/use-t';
|
||||||
import { DataLoader } from './data-loader';
|
import { DataLoader } from './data-loader';
|
||||||
import { useChainId } from '@vegaprotocol/wallet';
|
import { WalletProvider } from '@vegaprotocol/wallet-react';
|
||||||
|
import { useVegaWalletConfig } from '../../lib/hooks/use-vega-wallet-config';
|
||||||
|
|
||||||
export const Bootstrapper = ({ children }: { children: ReactNode }) => {
|
export const Bootstrapper = ({ children }: { children: ReactNode }) => {
|
||||||
const t = useT();
|
const t = useT();
|
||||||
const {
|
const { error, VEGA_URL } = useEnvironment();
|
||||||
error,
|
const config = useVegaWalletConfig();
|
||||||
VEGA_URL,
|
|
||||||
VEGA_ENV,
|
|
||||||
VEGA_WALLET_URL,
|
|
||||||
VEGA_EXPLORER_URL,
|
|
||||||
MOZILLA_EXTENSION_URL,
|
|
||||||
CHROME_EXTENSION_URL,
|
|
||||||
} = useEnvironment();
|
|
||||||
|
|
||||||
const chainId = useChainId(VEGA_URL);
|
if (!config) {
|
||||||
|
|
||||||
if (
|
|
||||||
!VEGA_URL ||
|
|
||||||
!VEGA_WALLET_URL ||
|
|
||||||
!VEGA_EXPLORER_URL ||
|
|
||||||
!CHROME_EXTENSION_URL ||
|
|
||||||
!MOZILLA_EXTENSION_URL ||
|
|
||||||
!DocsLinks ||
|
|
||||||
!chainId
|
|
||||||
) {
|
|
||||||
return <AppLoader />;
|
return <AppLoader />;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,22 +54,7 @@ export const Bootstrapper = ({ children }: { children: ReactNode }) => {
|
|||||||
<AppFailure title={t('Could not configure web3 provider')} />
|
<AppFailure title={t('Could not configure web3 provider')} />
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<VegaWalletProvider
|
<WalletProvider config={config}>{children}</WalletProvider>
|
||||||
config={{
|
|
||||||
network: VEGA_ENV,
|
|
||||||
vegaUrl: VEGA_URL,
|
|
||||||
chainId,
|
|
||||||
vegaWalletServiceUrl: VEGA_WALLET_URL,
|
|
||||||
links: {
|
|
||||||
explorer: VEGA_EXPLORER_URL,
|
|
||||||
concepts: DocsLinks.VEGA_WALLET_CONCEPTS_URL,
|
|
||||||
chromeExtensionUrl: CHROME_EXTENSION_URL,
|
|
||||||
mozillaExtensionUrl: MOZILLA_EXTENSION_URL,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</VegaWalletProvider>
|
|
||||||
</Web3Provider>
|
</Web3Provider>
|
||||||
</DataLoader>
|
</DataLoader>
|
||||||
</NodeGuard>
|
</NodeGuard>
|
||||||
|
@ -2,7 +2,7 @@ import { Splash } from '@vegaprotocol/ui-toolkit';
|
|||||||
import { DepositsTable } from '@vegaprotocol/deposits';
|
import { DepositsTable } from '@vegaprotocol/deposits';
|
||||||
import { depositsProvider } from '@vegaprotocol/deposits';
|
import { depositsProvider } from '@vegaprotocol/deposits';
|
||||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useT } from '../../lib/use-t';
|
import { useT } from '../../lib/use-t';
|
||||||
|
|
||||||
export const DepositsContainer = () => {
|
export const DepositsContainer = () => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import maxBy from 'lodash/maxBy';
|
import maxBy from 'lodash/maxBy';
|
||||||
import minBy from 'lodash/minBy';
|
import minBy from 'lodash/minBy';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import {
|
import {
|
||||||
useNetworkParams,
|
useNetworkParams,
|
||||||
NetworkParams,
|
NetworkParams,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { FillsManager } from '@vegaprotocol/fills';
|
import { FillsManager } from '@vegaprotocol/fills';
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
import { persist } from 'zustand/middleware';
|
import { persist } from 'zustand/middleware';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { FundingPaymentsManager } from '@vegaprotocol/funding-payments';
|
import { FundingPaymentsManager } from '@vegaprotocol/funding-payments';
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
import { persist } from 'zustand/middleware';
|
import { persist } from 'zustand/middleware';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { LedgerExportForm } from '@vegaprotocol/ledger';
|
import { LedgerExportForm } from '@vegaprotocol/ledger';
|
||||||
import { Loader, Splash } from '@vegaprotocol/ui-toolkit';
|
import { Loader, Splash } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useEnvironment } from '@vegaprotocol/environment';
|
import { useEnvironment } from '@vegaprotocol/environment';
|
||||||
import type { PartyAssetFieldsFragment } from '@vegaprotocol/assets';
|
import type { PartyAssetFieldsFragment } from '@vegaprotocol/assets';
|
||||||
import { usePartyAssetsQuery } from '@vegaprotocol/assets';
|
import { usePartyAssetsQuery } from '@vegaprotocol/assets';
|
||||||
|
@ -1,47 +1,38 @@
|
|||||||
import { render, screen, within } from '@testing-library/react';
|
import { act, render, screen, within } from '@testing-library/react';
|
||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import { MemoryRouter } from 'react-router-dom';
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
|
||||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
||||||
import { Navbar } from './navbar';
|
import { Navbar } from './navbar';
|
||||||
import { useGlobalStore } from '../../stores';
|
import { useGlobalStore } from '../../stores';
|
||||||
import { ENV, useFeatureFlags } from '@vegaprotocol/environment';
|
import { ENV, useFeatureFlags } from '@vegaprotocol/environment';
|
||||||
|
import {
|
||||||
|
mockConfig,
|
||||||
|
MockedWalletProvider,
|
||||||
|
} from '@vegaprotocol/wallet-react/testing';
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/proposals', () => ({
|
jest.mock('@vegaprotocol/proposals', () => ({
|
||||||
ProtocolUpgradeCountdown: () => null,
|
ProtocolUpgradeCountdown: () => null,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('Navbar', () => {
|
describe('Navbar', () => {
|
||||||
const pubKey = '000';
|
const mockKeys = [
|
||||||
const pubKeys = [
|
|
||||||
{
|
{
|
||||||
publicKey: pubKey,
|
name: 'Key 1',
|
||||||
name: 'Pub key 0',
|
publicKey: '1'.repeat(64),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
publicKey: '111',
|
name: 'Key 2',
|
||||||
name: 'Pub key 1',
|
publicKey: '2'.repeat(64),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const marketId = 'abc';
|
const marketId = 'abc';
|
||||||
const navbarContent = 'navbar-menu-content';
|
const navbarContent = 'navbar-menu-content';
|
||||||
|
|
||||||
const renderComponent = (
|
const renderComponent = (initialEntries?: string[]) => {
|
||||||
initialEntries?: string[],
|
|
||||||
walletContext?: Partial<VegaWalletContextShape>
|
|
||||||
) => {
|
|
||||||
const context = {
|
|
||||||
pubKey,
|
|
||||||
pubKeys,
|
|
||||||
selectPubKey: jest.fn(),
|
|
||||||
disconnect: jest.fn(),
|
|
||||||
...walletContext,
|
|
||||||
} as VegaWalletContextShape;
|
|
||||||
return render(
|
return render(
|
||||||
<MemoryRouter initialEntries={initialEntries}>
|
<MemoryRouter initialEntries={initialEntries}>
|
||||||
<VegaWalletContext.Provider value={context}>
|
<MockedWalletProvider>
|
||||||
<Navbar />
|
<Navbar />
|
||||||
</VegaWalletContext.Provider>
|
</MockedWalletProvider>
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -57,6 +48,12 @@ describe('Navbar', () => {
|
|||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
act(() => {
|
||||||
|
mockConfig.reset();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should be properly rendered', () => {
|
it('should be properly rendered', () => {
|
||||||
renderComponent();
|
renderComponent();
|
||||||
|
|
||||||
@ -125,26 +122,38 @@ describe('Navbar', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can open wallet menu on small screens and change pubkey', async () => {
|
it('can open wallet menu on small screens and change pubkey', async () => {
|
||||||
const mockSelectPubKey = jest.fn();
|
mockConfig.store.setState({
|
||||||
renderComponent(undefined, { selectPubKey: mockSelectPubKey });
|
status: 'connected',
|
||||||
|
keys: mockKeys,
|
||||||
|
pubKey: mockKeys[0].publicKey,
|
||||||
|
});
|
||||||
|
const mockSelectPubKey = jest.spyOn(mockConfig.store, 'setState');
|
||||||
|
renderComponent(undefined);
|
||||||
await userEvent.click(screen.getByRole('button', { name: 'Wallet' }));
|
await userEvent.click(screen.getByRole('button', { name: 'Wallet' }));
|
||||||
|
|
||||||
const menuEl = screen.getByTestId(navbarContent);
|
const menuEl = screen.getByTestId(navbarContent);
|
||||||
expect(menuEl).toBeInTheDocument();
|
expect(menuEl).toBeInTheDocument();
|
||||||
const menu = within(menuEl);
|
const menu = within(menuEl);
|
||||||
|
|
||||||
expect(menu.getAllByTestId(/key-\d+-mobile/)).toHaveLength(pubKeys.length);
|
expect(menu.getAllByTestId(/key-\d+-mobile/)).toHaveLength(mockKeys.length);
|
||||||
|
|
||||||
const activeKey = within(menu.getByTestId('key-000-mobile'));
|
const activeKey = within(menu.getByTestId(/key-1+-mobile/));
|
||||||
expect(activeKey.getByText(pubKeys[0].name)).toBeInTheDocument();
|
expect(activeKey.getByText(mockKeys[0].name)).toBeInTheDocument();
|
||||||
expect(activeKey.getByTestId('icon-tick')).toBeInTheDocument();
|
expect(activeKey.getByTestId('icon-tick')).toBeInTheDocument();
|
||||||
|
|
||||||
const inactiveKey = within(menu.getByTestId('key-111-mobile'));
|
const inactiveKey = within(menu.getByTestId(/key-2+-mobile/));
|
||||||
await userEvent.click(inactiveKey.getByText(pubKeys[1].name));
|
await userEvent.click(inactiveKey.getByText(mockKeys[1].name));
|
||||||
expect(mockSelectPubKey).toHaveBeenCalledWith(pubKeys[1].publicKey);
|
expect(mockSelectPubKey).toHaveBeenCalledWith({
|
||||||
|
pubKey: mockKeys[1].publicKey,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can transfer and close menu', async () => {
|
it('can transfer and close menu', async () => {
|
||||||
|
mockConfig.store.setState({
|
||||||
|
status: 'connected',
|
||||||
|
keys: mockKeys,
|
||||||
|
pubKey: mockKeys[0].publicKey,
|
||||||
|
});
|
||||||
renderComponent();
|
renderComponent();
|
||||||
await userEvent.click(screen.getByRole('button', { name: 'Wallet' }));
|
await userEvent.click(screen.getByRole('button', { name: 'Wallet' }));
|
||||||
|
|
||||||
@ -158,8 +167,13 @@ describe('Navbar', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can disconnect and close menu', async () => {
|
it('can disconnect and close menu', async () => {
|
||||||
const mockDisconnect = jest.fn();
|
mockConfig.store.setState({
|
||||||
renderComponent(undefined, { disconnect: mockDisconnect });
|
status: 'connected',
|
||||||
|
keys: mockKeys,
|
||||||
|
pubKey: mockKeys[0].publicKey,
|
||||||
|
});
|
||||||
|
const mockDisconnect = jest.spyOn(mockConfig, 'disconnect');
|
||||||
|
renderComponent(undefined);
|
||||||
await userEvent.click(screen.getByRole('button', { name: 'Wallet' }));
|
await userEvent.click(screen.getByRole('button', { name: 'Wallet' }));
|
||||||
|
|
||||||
const menuEl = screen.getByTestId(navbarContent);
|
const menuEl = screen.getByTestId(navbarContent);
|
||||||
|
@ -25,7 +25,7 @@ import { NavLink } from 'react-router-dom';
|
|||||||
import { Links } from '../../lib/links';
|
import { Links } from '../../lib/links';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { VegaWalletMenu } from '../vega-wallet';
|
import { VegaWalletMenu } from '../vega-wallet';
|
||||||
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
import { useDialogStore, useWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { WalletIcon } from '../icons/wallet';
|
import { WalletIcon } from '../icons/wallet';
|
||||||
import { ProtocolUpgradeCountdown } from '@vegaprotocol/proposals';
|
import { ProtocolUpgradeCountdown } from '@vegaprotocol/proposals';
|
||||||
import { useT, useI18n } from '../../lib/use-t';
|
import { useT, useI18n } from '../../lib/use-t';
|
||||||
@ -40,13 +40,9 @@ export const Navbar = ({ theme = 'system' }: { theme?: Theme }) => {
|
|||||||
// menu state for small screens
|
// menu state for small screens
|
||||||
const [menu, setMenu] = useState<MenuState>(null);
|
const [menu, setMenu] = useState<MenuState>(null);
|
||||||
|
|
||||||
const { pubKey } = useVegaWallet();
|
const status = useWallet((store) => store.status);
|
||||||
|
|
||||||
const openVegaWalletDialog = useVegaWalletDialogStore(
|
const openVegaWalletDialog = useDialogStore((store) => store.open);
|
||||||
(store) => store.openVegaWalletDialog
|
|
||||||
);
|
|
||||||
|
|
||||||
const isConnected = pubKey !== null;
|
|
||||||
|
|
||||||
const navTextClasses = 'text-vega-clight-200 dark:text-vega-cdark-200';
|
const navTextClasses = 'text-vega-clight-200 dark:text-vega-cdark-200';
|
||||||
const rootClasses = classNames(
|
const rootClasses = classNames(
|
||||||
@ -88,7 +84,7 @@ export const Navbar = ({ theme = 'system' }: { theme?: Theme }) => {
|
|||||||
</div>
|
</div>
|
||||||
<NavbarMobileButton
|
<NavbarMobileButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (isConnected) {
|
if (status === 'connected') {
|
||||||
setMenu((x) => (x === 'wallet' ? null : 'wallet'));
|
setMenu((x) => (x === 'wallet' ? null : 'wallet'));
|
||||||
} else {
|
} else {
|
||||||
openVegaWalletDialog();
|
openVegaWalletDialog();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useDataGridEvents } from '@vegaprotocol/datagrid';
|
import { useDataGridEvents } from '@vegaprotocol/datagrid';
|
||||||
import { Filter, OrderListManager } from '@vegaprotocol/orders';
|
import { Filter, OrderListManager } from '@vegaprotocol/orders';
|
||||||
import { Splash } from '@vegaprotocol/ui-toolkit';
|
import { Splash } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import { useNavigateWithMeta } from '../../lib/hooks/use-market-click-handler';
|
import { useNavigateWithMeta } from '../../lib/hooks/use-market-click-handler';
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
import { persist } from 'zustand/middleware';
|
import { persist } from 'zustand/middleware';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useDataGridEvents } from '@vegaprotocol/datagrid';
|
import { useDataGridEvents } from '@vegaprotocol/datagrid';
|
||||||
import { PositionsManager } from '@vegaprotocol/positions';
|
import { PositionsManager } from '@vegaprotocol/positions';
|
||||||
import { Splash } from '@vegaprotocol/ui-toolkit';
|
import { Splash } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import type { DataGridSlice } from '../../stores/datagrid-store-slice';
|
import type { DataGridSlice } from '../../stores/datagrid-store-slice';
|
||||||
import { createDataGridSlice } from '../../stores/datagrid-store-slice';
|
import { createDataGridSlice } from '../../stores/datagrid-store-slice';
|
||||||
import type { StateCreator } from 'zustand';
|
import type { StateCreator } from 'zustand';
|
||||||
|
@ -172,7 +172,9 @@ describe('Vesting', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('doesnt use multiplier if not connected', () => {
|
it('doesnt use multiplier if not connected', () => {
|
||||||
render(<Vesting baseRate={'0.25'} pubKey={null} multiplier={undefined} />);
|
render(
|
||||||
|
<Vesting baseRate={'0.25'} pubKey={undefined} multiplier={undefined} />
|
||||||
|
);
|
||||||
|
|
||||||
expect(screen.getByTestId('vesting-rate')).toHaveTextContent('25%');
|
expect(screen.getByTestId('vesting-rate')).toHaveTextContent('25%');
|
||||||
|
|
||||||
@ -199,7 +201,11 @@ describe('Multipliers', () => {
|
|||||||
|
|
||||||
it('shows not connected state', () => {
|
it('shows not connected state', () => {
|
||||||
render(
|
render(
|
||||||
<Multipliers pubKey={null} streakMultiplier="3" hoarderMultiplier="2" />
|
<Multipliers
|
||||||
|
pubKey={undefined}
|
||||||
|
streakMultiplier="3"
|
||||||
|
hoarderMultiplier="2"
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
useNetworkParams,
|
useNetworkParams,
|
||||||
} from '@vegaprotocol/network-parameters';
|
} from '@vegaprotocol/network-parameters';
|
||||||
import { AccountType } from '@vegaprotocol/types';
|
import { AccountType } from '@vegaprotocol/types';
|
||||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
import { useVegaWallet } from '@vegaprotocol/wallet-react';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
@ -309,7 +309,7 @@ type VestingBalances = NonNullable<
|
|||||||
>['vestingBalancesSummary'];
|
>['vestingBalancesSummary'];
|
||||||
|
|
||||||
export type RewardPotProps = {
|
export type RewardPotProps = {
|
||||||
pubKey: string | null;
|
pubKey: string | undefined;
|
||||||
accounts: Account[] | null;
|
accounts: Account[] | null;
|
||||||
assetId: string; // VEGA
|
assetId: string; // VEGA
|
||||||
vestingBalancesSummary: VestingBalances | undefined;
|
vestingBalancesSummary: VestingBalances | undefined;
|
||||||
@ -469,7 +469,7 @@ export const Vesting = ({
|
|||||||
baseRate,
|
baseRate,
|
||||||
multiplier,
|
multiplier,
|
||||||
}: {
|
}: {
|
||||||
pubKey: string | null;
|
pubKey: string | undefined;
|
||||||
baseRate: string;
|
baseRate: string;
|
||||||
multiplier?: string;
|
multiplier?: string;
|
||||||
}) => {
|
}) => {
|
||||||
@ -506,7 +506,7 @@ export const Multipliers = ({
|
|||||||
streakMultiplier,
|
streakMultiplier,
|
||||||
hoarderMultiplier,
|
hoarderMultiplier,
|
||||||
}: {
|
}: {
|
||||||
pubKey: string | null;
|
pubKey: string | undefined;
|
||||||
streakMultiplier?: string;
|
streakMultiplier?: string;
|
||||||
hoarderMultiplier?: string;
|
hoarderMultiplier?: string;
|
||||||
}) => {
|
}) => {
|
||||||
|
@ -25,7 +25,7 @@ export const RewardsHistoryContainer = ({
|
|||||||
pubKey,
|
pubKey,
|
||||||
assets,
|
assets,
|
||||||
}: {
|
}: {
|
||||||
pubKey: string | null;
|
pubKey: string | undefined;
|
||||||
epoch: number;
|
epoch: number;
|
||||||
assets: Record<string, AssetFieldsFragment>;
|
assets: Record<string, AssetFieldsFragment>;
|
||||||
}) => {
|
}) => {
|
||||||
@ -129,7 +129,7 @@ export const RewardHistoryTable = ({
|
|||||||
epochRewardSummaries: RewardsHistoryQuery['epochRewardSummaries'];
|
epochRewardSummaries: RewardsHistoryQuery['epochRewardSummaries'];
|
||||||
partyRewards: PartyRewardsConnection;
|
partyRewards: PartyRewardsConnection;
|
||||||
assets: Record<string, AssetFieldsFragment> | null;
|
assets: Record<string, AssetFieldsFragment> | null;
|
||||||
pubKey: string | null;
|
pubKey: string | undefined;
|
||||||
epoch: number;
|
epoch: number;
|
||||||
epochVariables: {
|
epochVariables: {
|
||||||
from: number;
|
from: number;
|
||||||
@ -145,7 +145,7 @@ export const RewardHistoryTable = ({
|
|||||||
epochRewardSummaries,
|
epochRewardSummaries,
|
||||||
partyRewards,
|
partyRewards,
|
||||||
assets,
|
assets,
|
||||||
partyId: isParty ? pubKey : null,
|
partyId: isParty ? pubKey : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const columnDefs = useMemo<ColDef<RewardRow>[]>(() => {
|
const columnDefs = useMemo<ColDef<RewardRow>[]>(() => {
|
||||||
|
@ -97,7 +97,7 @@ export const useRewardsRowData = ({
|
|||||||
partyRewards: PartyRewardsConnection;
|
partyRewards: PartyRewardsConnection;
|
||||||
epochRewardSummaries: RewardsHistoryQuery['epochRewardSummaries'];
|
epochRewardSummaries: RewardsHistoryQuery['epochRewardSummaries'];
|
||||||
assets: Record<string, Asset> | null;
|
assets: Record<string, Asset> | null;
|
||||||
partyId: string | null;
|
partyId: string | undefined;
|
||||||
}) => {
|
}) => {
|
||||||
if (partyId) {
|
if (partyId) {
|
||||||
const rewards = removePaginationWrapper(partyRewards?.edges).map((r) => ({
|
const rewards = removePaginationWrapper(partyRewards?.edges).map((r) => ({
|
||||||
|
1
apps/trading/components/risk-ack-content/index.ts
Normal file
1
apps/trading/components/risk-ack-content/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { RiskAckContent } from './risk-ack-content';
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user