Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add simulation metrics when simulation UI is not visible #28427

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ const NativeTransferInfo = () => {
<>
<NativeSendHeading />
<TransactionFlowSection />
{!isWalletInitiated && (
{
<ConfirmInfoSection noPadding>
<SimulationDetails
transaction={transactionMeta}
isTransactionsRedesign
enableMetrics
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, can we assume this automatically if metricsOnly is true?

metricsOnly={isWalletInitiated}
/>
</ConfirmInfoSection>
)}
}
<TokenDetailsSection />
<GasFeesSection />
<AdvancedDetails />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ const NFTTokenTransferInfo = () => {
<>
<NFTSendHeading />
<TransactionFlowSection />
{!isWalletInitiated && (
{
<ConfirmInfoSection noPadding>
<SimulationDetails
transaction={transactionMeta}
isTransactionsRedesign
enableMetrics
metricsOnly={isWalletInitiated}
/>
</ConfirmInfoSection>
)}
}
<TokenDetailsSection />
<GasFeesSection />
<AdvancedDetails />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ const TokenTransferInfo = () => {
<>
<SendHeading />
<TransactionFlowSection />
{!isWalletInitiated && (
{
<ConfirmInfoSection noPadding>
<SimulationDetails
transaction={transactionMeta}
isTransactionsRedesign
enableMetrics
metricsOnly={isWalletInitiated}
/>
</ConfirmInfoSection>
)}
}
<TokenDetailsSection />
<GasFeesSection />
<AdvancedDetails />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ jest.mock('../../context/confirm', () => ({
})),
}));

const renderSimulationDetails = (simulationData?: Partial<SimulationData>) =>
const renderSimulationDetails = (
simulationData?: Partial<SimulationData>,
metricsOnly?: boolean,
) =>
renderWithProvider(
<SimulationDetails
transaction={
{ id: 'testTransactionId', simulationData } as TransactionMeta
}
metricsOnly={metricsOnly}
/>,
store,
);
Expand Down Expand Up @@ -141,4 +145,9 @@ describe('SimulationDetails', () => {
{},
);
});

it('does not render any UI elements when metricsOnly is true', () => {
const { container } = renderSimulationDetails({}, true);
expect(container).toBeEmptyDOMElement();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { useSimulationMetrics } from './useSimulationMetrics';
export type SimulationDetailsProps = {
enableMetrics?: boolean;
isTransactionsRedesign?: boolean;
metricsOnly?: boolean;
transaction: TransactionMeta;
};

Expand Down Expand Up @@ -225,11 +226,13 @@ const SimulationDetailsLayout: React.FC<{
* @param props.enableMetrics - Whether to enable simulation metrics.
* @param props.isTransactionsRedesign - Whether or not the component is being
* used inside the transaction redesign flow.
* @param props.metricsOnly - Whether to only track metrics and not render the UI.
*/
export const SimulationDetails: React.FC<SimulationDetailsProps> = ({
transaction,
enableMetrics = false,
isTransactionsRedesign = false,
metricsOnly = false,
}: SimulationDetailsProps) => {
const t = useI18nContext();
const { chainId, id: transactionId, simulationData } = transaction;
Expand All @@ -244,6 +247,10 @@ export const SimulationDetails: React.FC<SimulationDetailsProps> = ({
transactionId,
});

if (metricsOnly) {
return null;
}

if (loading) {
return (
<SimulationDetailsLayout
Expand Down