Skip to content
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
48 changes: 24 additions & 24 deletions .github/workflows/rerun-ci-on-skipped-e2e-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ env:
jobs:
rerun-ci:
if: >-
github.event.label.name == 'skip-smart-e2e-selection' ||
github.event.label.name == 'skip-e2e' ||
github.event.label.name == 'skip-e2e-flakiness-detection' ||
github.event.label.name == 'pr-not-ready-for-e2e' ||
github.event.label.name == 'force-builds'
github.event.pull_request.state == 'open' &&
(github.event.label.name == 'skip-smart-e2e-selection' ||
github.event.label.name == 'skip-e2e' ||
github.event.label.name == 'skip-e2e-flakiness-detection' ||
github.event.label.name == 'pr-not-ready-for-e2e' ||
github.event.label.name == 'force-builds')
runs-on: ubuntu-latest
permissions:
actions: write
Expand Down Expand Up @@ -49,6 +50,7 @@ jobs:
--repo "$REPO" \
--branch "$HEAD_REF" \
--workflow "ci.yml" \
--event pull_request \
--limit 1 \
--json databaseId \
--jq '.[0].databaseId')
Expand All @@ -61,42 +63,40 @@ jobs:
echo "run_id=$LATEST_RUN_ID" >> "$GITHUB_OUTPUT"

- name: Wait for cancellation to complete
if: steps.cancel.outputs.cancelled == 'true'
if: steps.cancel.outputs.cancelled == 'true' && steps.find.outputs.run_id
run: |
RUN_ID="${{ steps.find.outputs.run_id }}"
MAX_WAIT=600
ELAPSED=0
IN_PROGRESS=1

echo "Waiting up to ${MAX_WAIT}s for all CI runs to finish cancelling..."
echo "Waiting up to ${MAX_WAIT}s for workflow to finish cancelling..."

while [ $ELAPSED -lt $MAX_WAIT ]; do
IN_PROGRESS=$(gh run list \
--repo "$REPO" \
--branch "$HEAD_REF" \
--workflow "ci.yml" \
--json databaseId,status \
--jq '[.[] | select(.status == "in_progress" or .status == "queued")] | length')

echo "In-progress/queued runs: $IN_PROGRESS (${ELAPSED}s elapsed)"
STATUS=$(gh run view "$RUN_ID" --repo "$REPO" --json status --jq '.status')
echo "Status: $STATUS (${ELAPSED}s elapsed)"

if [ "$IN_PROGRESS" -eq 0 ]; then
echo "No active runs remaining — ready to rerun"
if [ "$STATUS" != "in_progress" ] && [ "$STATUS" != "queued" ]; then
echo "Workflow ready for rerun"
break
fi

sleep 15
ELAPSED=$((ELAPSED + 15))
done

if [ "$IN_PROGRESS" -gt 0 ]; then
echo "Timeout: $IN_PROGRESS run(s) still active after ${MAX_WAIT}s"
FINAL_STATUS=$(gh run view "$RUN_ID" --repo "$REPO" --json status --jq '.status')
if [ "$FINAL_STATUS" = "in_progress" ] || [ "$FINAL_STATUS" = "queued" ]; then
echo "Timeout: workflow still $FINAL_STATUS after ${MAX_WAIT}s"
exit 1
fi

- name: Rerun CI workflow
if: github.event.pull_request.state == 'open' && steps.find.outputs.run_id
if: steps.find.outputs.run_id
run: |
RUN_ID="${{ steps.find.outputs.run_id }}"
echo "Re-running CI workflow run $RUN_ID..."
gh run rerun "$RUN_ID" --repo "$REPO"
echo "CI workflow re-triggered successfully"
echo "Re-running workflow $RUN_ID..."
if gh run rerun "$RUN_ID" --repo "$REPO"; then
echo "CI workflow re-triggered successfully"
else
echo "Rerun not possible (run may not be in a retriable state)"
fi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { MOCK_ADDRESS_2 } from '../../../../../util/test/accountsControllerTestU
import { backgroundState } from '../../../../../util/test/initial-root-state';
import renderWithProvider from '../../../../../util/test/renderWithProvider';
import { MetaMetricsEvents } from '../../../../../core/Analytics';
import { getStakingNavbar } from '../../../Navbar';
import {
MOCK_AUSDT_MAINNET_ASSET,
MOCK_USDC_MAINNET_ASSET,
Expand Down Expand Up @@ -235,8 +234,6 @@ jest.mock('../../../../../util/trace', () => ({
}));

describe('EarnLendingDepositConfirmationView', () => {
jest.mocked(getStakingNavbar);

const mockExecuteLendingDeposit = jest.mocked(
Engine.context.EarnController.executeLendingDeposit,
);
Expand Down Expand Up @@ -345,6 +342,56 @@ describe('EarnLendingDepositConfirmationView', () => {
expect(mockGoBack).toHaveBeenCalledTimes(1);
});

describe('HeaderStandard', () => {
it('renders the supply title with the routed token ticker', () => {
const { getByText } = renderWithProvider(
<EarnLendingDepositConfirmationView />,
{ state: mockInitialState },
);

expect(
getByText(
`${strings('earn.supply')} ${MOCK_USDC_MAINNET_ASSET.ticker}`,
),
).toBeOnTheScreen();
});

it('falls back to the token symbol when the routed token has no ticker', () => {
(useRoute as jest.Mock).mockReturnValue({
...defaultRouteParams,
params: {
...defaultRouteParams.params,
token: {
...defaultRouteParams.params.token,
ticker: undefined,
symbol: 'AUSDC',
},
},
});

const { getByText } = renderWithProvider(
<EarnLendingDepositConfirmationView />,
{ state: mockInitialState },
);

expect(getByText(`${strings('earn.supply')} AUSDC`)).toBeOnTheScreen();
});

it('calls navigation.goBack when the back button is pressed', async () => {
const { getByLabelText } = renderWithProvider(
<EarnLendingDepositConfirmationView />,
{ state: mockInitialState },
);

const backButton = getByLabelText(strings('navigation.back'));
await act(async () => {
fireEvent.press(backButton);
});

expect(mockGoBack).toHaveBeenCalledTimes(1);
});
});

describe('USDT token allowance reset edge case', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
renderFromTokenMinimalUnit,
} from '../../../../../util/number';
import { useStyles } from '../../../../hooks/useStyles';
import { getStakingNavbar } from '../../../Navbar';
import { HeaderStandard } from '@metamask/design-system-react-native';
import { useAnalytics } from '../../../../hooks/useAnalytics/useAnalytics';
import {
MetaMetricsEvents,
Expand Down Expand Up @@ -73,7 +73,7 @@ const Steps = {
};

const EarnLendingDepositConfirmationView = () => {
const { styles, theme } = useStyles(styleSheet, {});
const { styles } = useStyles(styleSheet, {});
const currentCurrency = useSelector(selectCurrentCurrency);
const { params } =
useRoute<EarnLendingDepositConfirmationViewProps['route']>();
Expand All @@ -91,7 +91,14 @@ const EarnLendingDepositConfirmationView = () => {
const navigation = useNavigation();
const { trackEvent, createEventBuilder } = useAnalytics();

getStakingNavbar(strings('earn.supply'), navigation, theme.colors);
const headerTitle = useMemo(() => {
const tokenLabel = token?.ticker ?? token?.symbol ?? token?.name ?? '';
return `${strings('earn.supply')} ${tokenLabel}`;
}, [token?.ticker, token?.symbol, token?.name]);

const handleHeaderBackPress = useCallback(() => {
navigation.goBack();
}, [navigation]);

const network = useSelector((state: RootState) =>
selectNetworkConfigurationByChainId(state, token?.chainId as Hex),
Expand Down Expand Up @@ -221,18 +228,8 @@ const EarnLendingDepositConfirmationView = () => {
.addProperties(getTrackEventProperties('deposit'))
.build(),
);

const tokenLabel = token?.ticker ?? token?.symbol ?? token?.name ?? '';
const title = `${strings('earn.supply')} ${tokenLabel}`;

navigation.setOptions(
getStakingNavbar(title, navigation, theme.colors, {
hasCancelButton: false,
backgroundColor: theme.colors.background.default,
}),
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [navigation, theme.colors]);
}, []);

const emitTxMetaMetric = useCallback(
(txType: TransactionType) =>
Expand Down Expand Up @@ -793,6 +790,14 @@ const EarnLendingDepositConfirmationView = () => {

return (
<View style={styles.pageContainer}>
<HeaderStandard
title={headerTitle}
onBack={handleHeaderBackPress}
backButtonProps={{
accessibilityLabel: strings('navigation.back'),
}}
includesTopInset
/>
<ScrollView
style={styles.scrollView}
contentContainerStyle={styles.contentContainer}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LendingMarketWithPosition } from '@metamask/earn-controller';
import { mockTheme } from '../../../../../util/theme';
import { useRoute } from '@react-navigation/native';
import { act, fireEvent } from '@testing-library/react-native';
import React from 'react';
Expand All @@ -24,8 +23,6 @@ import {
} from '@metamask/transaction-controller';
import { AnalyticsEventBuilder } from '../../../../../util/analytics/AnalyticsEventBuilder';
import { useAnalytics } from '../../../../hooks/useAnalytics/useAnalytics';
// eslint-disable-next-line import-x/no-namespace
import * as NavbarUtils from '../../../Navbar';
import { MOCK_USDC_MAINNET_ASSET } from '../../../Stake/__mocks__/stakeMockData';
import useEarnToken from '../../hooks/useEarnToken';
import {
Expand All @@ -36,8 +33,6 @@ import Routes from '../../../../../constants/navigation/Routes';
import { trace, endTrace, TraceName } from '../../../../../util/trace';
import { RootState } from '../../../../../reducers';

const getStakingNavbarSpy = jest.spyOn(NavbarUtils, 'getStakingNavbar');

const mockGoBack = jest.fn();
const mockNavigate = jest.fn();

Expand Down Expand Up @@ -213,45 +208,65 @@ describe('EarnLendingWithdrawalConfirmationView', () => {
} as unknown as ReturnType<typeof useAnalytics>);
});

it('renders withdrawal confirmation with correct navbar title and cancel button', () => {
it('renders the withdrawal confirmation footer cancel button', () => {
const { getByTestId } = renderWithProvider(
<EarnLendingWithdrawalConfirmationView />,
{
state: mockInitialState,
},
);

// Assert Navbar was updated
expect(getStakingNavbarSpy).toHaveBeenCalledWith(
`${strings('earn.withdraw')} ${mockLineaAUsdc.symbol}`,
expect.any(Object), // navigation object
expect.any(Object), // theme.colors
{
hasCancelButton: false,
backgroundColor: mockTheme.colors.background.default,
},
{
backButtonEvent: {
event: {
category: 'Earn Lending Withdraw Confirmation Back Clicked',
},
properties: {
experience: 'STABLECOIN_LENDING',
location: 'EarnLendingWithdrawConfirmationView',
selected_provider: 'consensys',
token: 'AUSDC',
transaction_value: '1 AUSDC',
user_token_balance: '3.62106 AUSDC',
},
},
},
);

expect(
getByTestId(CONFIRMATION_FOOTER_BUTTON_TEST_IDS.CANCEL_BUTTON),
).toBeOnTheScreen();
});

describe('HeaderStandard', () => {
it('renders the withdraw title with the routed token symbol', () => {
const { getByText } = renderWithProvider(
<EarnLendingWithdrawalConfirmationView />,
{
state: mockInitialState,
},
);

expect(
getByText(`${strings('earn.withdraw')} ${mockLineaAUsdc.symbol}`),
).toBeOnTheScreen();
});

it('emits EARN_LENDING_WITHDRAW_CONFIRMATION_BACK_CLICKED and navigates back when the back button is pressed', async () => {
const { getByLabelText } = renderWithProvider(
<EarnLendingWithdrawalConfirmationView />,
{
state: mockInitialState,
},
);

mockTrackEvent.mockClear();

const backButton = getByLabelText(strings('navigation.back'));
await act(async () => {
fireEvent.press(backButton);
});

expect(mockTrackEvent).toHaveBeenCalledWith(
expect.objectContaining({
name: 'Earn Lending Withdraw Confirmation Back Clicked',
properties: expect.objectContaining({
selected_provider: 'consensys',
location: 'EarnLendingWithdrawConfirmationView',
experience: 'STABLECOIN_LENDING',
user_token_balance: '3.62106 AUSDC',
transaction_value: '1 AUSDC',
token: 'AUSDC',
}),
}),
);
expect(mockGoBack).toHaveBeenCalledTimes(1);
});
});

// TODO: https://consensyssoftware.atlassian.net/browse/STAKE-1044 Add back in v1.1
it.skip('displays advanced details section when user has detected borrow positions', () => {
(useRoute as jest.MockedFunction<typeof useRoute>).mockReturnValue({
Expand Down
Loading
Loading