test: fix out of sync ethereum address with form

This commit is contained in:
Matthew Russell
2023-07-11 14:31:18 +01:00
parent f6418118cd
commit cae93e35c2
4 changed files with 20 additions and 12 deletions
@@ -20,8 +20,8 @@ describe('deposit form validation', { tags: '@smoke' }, () => {
cy.get('main[data-testid="/portfolio"]').should('exist');
cy.getByTestId('Deposits').click();
cy.getByTestId('deposit-button').click();
cy.wait('@Assets');
connectEthereumWallet('MetaMask');
cy.wait('@Assets');
}
before(() => {
@@ -102,8 +102,6 @@ describe('deposit actions', { tags: '@smoke' }, () => {
cy.mockSubscription();
cy.setVegaWallet();
cy.visit('/#/markets/market-1');
cy.wait('@MarketsCandles');
cy.getByTestId('dialog-close').click();
});
it('Deposit to trade is visble', () => {
@@ -10,6 +10,7 @@ describe('trades', { tags: '@smoke' }, () => {
cy.mockTradingPage();
cy.mockSubscription();
});
before(() => {
cy.mockTradingPage();
cy.mockSubscription();
@@ -60,11 +61,8 @@ describe('trades', { tags: '@smoke' }, () => {
/(\d{1,2})\/(\d{1,2})\/(\d{4}), (\d{1,2}):(\d{1,2}):(\d{1,2})/gm;
cy.getByTestId(tradesTable)
.get(`.ag-center-cols-container ${colIdCreatedAt}`)
.each(($tradeDateTime, index) => {
if (index != 0) {
//ignore header
cy.wrap($tradeDateTime).invoke('text').should('match', dateTimeRegex);
}
.each(($tradeDateTime) => {
cy.wrap($tradeDateTime).invoke('text').should('match', dateTimeRegex);
});
});
+9 -3
View File
@@ -27,7 +27,7 @@ import { useVegaWallet } from '@vegaprotocol/wallet';
import { useWeb3React } from '@web3-react/core';
import BigNumber from 'bignumber.js';
import type { ButtonHTMLAttributes, ChangeEvent, ReactNode } from 'react';
import { useMemo, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { useWatch, Controller, useForm } from 'react-hook-form';
import { DepositLimits } from './deposit-limits';
import { useAssetDetailsDialogStore } from '@vegaprotocol/assets';
@@ -90,17 +90,18 @@ export const DepositForm = ({
const [approveNotificationIntent, setApproveNotificationIntent] =
useState<Intent>(Intent.Warning);
const [persistedDeposit] = usePersistentDeposit(selectedAsset?.id);
console.log('deposit-form', account);
const {
register,
handleSubmit,
setValue,
clearErrors,
trigger,
control,
formState: { errors },
} = useForm<FormFields>({
defaultValues: {
from: account,
from: account || '',
to: pubKey ? pubKey : undefined,
asset: selectedAsset?.id,
amount: persistedDeposit?.amount,
@@ -137,6 +138,11 @@ export const DepositForm = ({
return _pubKeys ? _pubKeys.map((pk) => pk.publicKey) : [];
}, [_pubKeys]);
useEffect(() => {
setValue('from', account || '');
trigger('from');
}, [account]);
const approved =
balances && balances.allowance.isGreaterThan(0) ? true : false;
+7 -1
View File
@@ -22,7 +22,7 @@ import {
} from '@vegaprotocol/ui-toolkit';
import { useWeb3React } from '@web3-react/core';
import BigNumber from 'bignumber.js';
import type { ButtonHTMLAttributes } from 'react';
import { useEffect, type ButtonHTMLAttributes } from 'react';
import type { ControllerRenderProps } from 'react-hook-form';
import { formatDistanceToNow } from 'date-fns';
import { useForm, Controller, useWatch } from 'react-hook-form';
@@ -111,6 +111,7 @@ export const WithdrawForm = ({
register,
handleSubmit,
setValue,
trigger,
clearErrors,
control,
formState: { errors },
@@ -138,6 +139,11 @@ export const WithdrawForm = ({
});
};
useEffect(() => {
setValue('to', address || '');
trigger('to');
}, [address]);
const renderAssetsSelector = ({
field,
}: {