feat(governance): transfers destination field can fallback to type (#5092)
This commit is contained in:
parent
097bf7c08c
commit
a98ab775c3
@ -12,18 +12,19 @@ import {
|
|||||||
generateProposal,
|
generateProposal,
|
||||||
generateYesVotes,
|
generateYesVotes,
|
||||||
} from '../../test-helpers/generate-proposals';
|
} from '../../test-helpers/generate-proposals';
|
||||||
import { ProposalHeader } from './proposal-header';
|
import { ProposalHeader, NewTransferSummary } from './proposal-header';
|
||||||
import {
|
import {
|
||||||
lastWeek,
|
lastWeek,
|
||||||
nextWeek,
|
nextWeek,
|
||||||
mockWalletContext,
|
mockWalletContext,
|
||||||
createUserVoteQueryMock,
|
createUserVoteQueryMock,
|
||||||
} from '../../test-helpers/mocks';
|
} from '../../test-helpers/mocks';
|
||||||
import type { ProposalQuery } from '../../proposal/__generated__/Proposal';
|
|
||||||
import type { MockedResponse } from '@apollo/client/testing';
|
|
||||||
import { FLAGS } from '@vegaprotocol/environment';
|
import { FLAGS } from '@vegaprotocol/environment';
|
||||||
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';
|
||||||
|
import { useNewTransferProposalDetails } from '@vegaprotocol/proposals';
|
||||||
|
import type { ProposalQuery } from '../../proposal/__generated__/Proposal';
|
||||||
|
import type { MockedResponse } from '@apollo/client/testing';
|
||||||
|
|
||||||
jest.mock('@vegaprotocol/proposals', () => ({
|
jest.mock('@vegaprotocol/proposals', () => ({
|
||||||
...jest.requireActual('@vegaprotocol/proposals'),
|
...jest.requireActual('@vegaprotocol/proposals'),
|
||||||
@ -31,6 +32,7 @@ jest.mock('@vegaprotocol/proposals', () => ({
|
|||||||
code: 'PARENT_CODE',
|
code: 'PARENT_CODE',
|
||||||
parentMarketId: 'PARENT_ID',
|
parentMarketId: 'PARENT_ID',
|
||||||
}),
|
}),
|
||||||
|
useNewTransferProposalDetails: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const renderComponent = (
|
const renderComponent = (
|
||||||
@ -418,3 +420,78 @@ describe('Proposal header', () => {
|
|||||||
expect(await screen.findByTestId('user-voted-yes')).toBeInTheDocument();
|
expect(await screen.findByTestId('user-voted-yes')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jest.mock('@vegaprotocol/proposals');
|
||||||
|
|
||||||
|
describe('<NewTransferSummary />', () => {
|
||||||
|
it('renders null if no details are provided', () => {
|
||||||
|
(useNewTransferProposalDetails as jest.Mock).mockReturnValue(null);
|
||||||
|
const { container } = render(<NewTransferSummary proposalId="1" />);
|
||||||
|
expect(container.firstChild).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles OneOffGovernanceTransfer', () => {
|
||||||
|
(useNewTransferProposalDetails as jest.Mock).mockReturnValue({
|
||||||
|
kind: { __typename: 'OneOffGovernanceTransfer', deliverOn: null },
|
||||||
|
source: '0x123',
|
||||||
|
sourceType: 'wallet',
|
||||||
|
destination: '0x456',
|
||||||
|
destinationType: 'contract',
|
||||||
|
});
|
||||||
|
const { getByText } = render(<NewTransferSummary proposalId="1" />);
|
||||||
|
const textMatch = (content: string) => content.includes('One off transfer');
|
||||||
|
expect(getByText(textMatch)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles RecurringGovernanceTransfer', () => {
|
||||||
|
(useNewTransferProposalDetails as jest.Mock).mockReturnValue({
|
||||||
|
kind: {
|
||||||
|
__typename: 'RecurringGovernanceTransfer',
|
||||||
|
startEpoch: 1,
|
||||||
|
endEpoch: 5,
|
||||||
|
},
|
||||||
|
source: '0x123',
|
||||||
|
sourceType: 'wallet',
|
||||||
|
destination: '0x456',
|
||||||
|
destinationType: 'contract',
|
||||||
|
});
|
||||||
|
const { getByText } = render(<NewTransferSummary proposalId="1" />);
|
||||||
|
const textMatch = (content: string) =>
|
||||||
|
content.includes('Recurring transfer');
|
||||||
|
expect(getByText(textMatch)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fallback to translated sourceType when source is not set', () => {
|
||||||
|
(useNewTransferProposalDetails as jest.Mock).mockReturnValue({
|
||||||
|
kind: {
|
||||||
|
__typename: 'RecurringGovernanceTransfer',
|
||||||
|
startEpoch: 1,
|
||||||
|
endEpoch: 5,
|
||||||
|
},
|
||||||
|
source: undefined,
|
||||||
|
sourceType: 'ACCOUNT_TYPE_GENERAL',
|
||||||
|
destination: '0x456',
|
||||||
|
destinationType: 'ACCOUNT_TYPE_GENERAL',
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<NewTransferSummary proposalId="1" />);
|
||||||
|
expect(screen.getByText('General account')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fallback to translated destinationType when destination is not set', () => {
|
||||||
|
(useNewTransferProposalDetails as jest.Mock).mockReturnValue({
|
||||||
|
kind: {
|
||||||
|
__typename: 'RecurringGovernanceTransfer',
|
||||||
|
startEpoch: 1,
|
||||||
|
endEpoch: 5,
|
||||||
|
},
|
||||||
|
source: '0x123',
|
||||||
|
sourceType: 'ACCOUNT_TYPE_GENERAL',
|
||||||
|
destination: undefined,
|
||||||
|
destinationType: 'ACCOUNT_TYPE_GLOBAL_INSURANCE',
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<NewTransferSummary proposalId="1" />);
|
||||||
|
expect(screen.getByText('Global insurance account')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -237,7 +237,11 @@ export const ProposalHeader = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const SuccessorCode = ({ proposalId }: { proposalId?: string | null }) => {
|
export const SuccessorCode = ({
|
||||||
|
proposalId,
|
||||||
|
}: {
|
||||||
|
proposalId?: string | null;
|
||||||
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const successor = useSuccessorMarketProposalDetails(proposalId);
|
const successor = useSuccessorMarketProposalDetails(proposalId);
|
||||||
|
|
||||||
@ -254,7 +258,11 @@ const SuccessorCode = ({ proposalId }: { proposalId?: string | null }) => {
|
|||||||
) : null;
|
) : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const NewTransferSummary = ({ proposalId }: { proposalId?: string | null }) => {
|
export const NewTransferSummary = ({
|
||||||
|
proposalId,
|
||||||
|
}: {
|
||||||
|
proposalId?: string | null;
|
||||||
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const details = useNewTransferProposalDetails(proposalId);
|
const details = useNewTransferProposalDetails(proposalId);
|
||||||
|
|
||||||
@ -265,14 +273,21 @@ const NewTransferSummary = ({ proposalId }: { proposalId?: string | null }) => {
|
|||||||
{GovernanceTransferKindMapping[details.kind.__typename]}{' '}
|
{GovernanceTransferKindMapping[details.kind.__typename]}{' '}
|
||||||
{t('transfer from')}{' '}
|
{t('transfer from')}{' '}
|
||||||
<Lozenge>
|
<Lozenge>
|
||||||
{truncateMiddle(details.source) || t(details.sourceType)}
|
{details.source
|
||||||
|
? truncateMiddle(details.source)
|
||||||
|
: t(details.sourceType)}
|
||||||
</Lozenge>{' '}
|
</Lozenge>{' '}
|
||||||
{t('to')} <Lozenge>{truncateMiddle(details.destination)}</Lozenge>
|
{t('to')}{' '}
|
||||||
|
<Lozenge>
|
||||||
|
{details.destination
|
||||||
|
? truncateMiddle(details.destination)
|
||||||
|
: t(details.destinationType)}
|
||||||
|
</Lozenge>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const CancelTransferSummary = ({
|
export const CancelTransferSummary = ({
|
||||||
proposalId,
|
proposalId,
|
||||||
}: {
|
}: {
|
||||||
proposalId?: string | null;
|
proposalId?: string | null;
|
||||||
|
Loading…
Reference in New Issue
Block a user