Skip to content

Commit 4339c06

Browse files
committed
feat: Add clear functionality to SRP import error banner
1 parent 1dd7251 commit 4339c06

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

ui/components/multichain/multi-srp/import-srp/import-srp.test.tsx

+35
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,41 @@ describe('ImportSRP', () => {
153153
expect(mockClearClipboard).toHaveBeenCalled();
154154
});
155155

156+
it('clears the SRP input fields and error message when Clear button is clicked', async () => {
157+
const onActionComplete = jest.fn();
158+
const render = renderWithProvider(
159+
<ImportSrp onActionComplete={onActionComplete} />,
160+
store,
161+
);
162+
const { getByText, queryByTestId, getByTestId } = render;
163+
164+
// Input an invalid SRP to trigger error
165+
const invalidSRP = VALID_SECRET_RECOVERY_PHRASE.replace('input', 'inptu');
166+
pasteSrpIntoFirstInput(render, invalidSRP);
167+
168+
// Verify error message is shown
169+
const bannerAlert = await waitFor(() => getByTestId('bannerAlert'));
170+
expect(bannerAlert).toBeInTheDocument();
171+
172+
// Click Clear button
173+
const clearButton = getByText('Clear');
174+
fireEvent.click(clearButton);
175+
176+
// Verify error message is cleared
177+
expect(queryByTestId('bannerAlert')).not.toBeInTheDocument();
178+
179+
// Verify all input fields are cleared
180+
for (let i = 0; i < 12; i++) {
181+
const input = getByTestId(`import-srp__srp-word-${i}`).querySelector(
182+
'input',
183+
);
184+
expect(input).toHaveValue('');
185+
}
186+
187+
// Verify Import wallet button is disabled
188+
expect(getByText('Import wallet')).not.toBeEnabled();
189+
});
190+
156191
it('logs an error and not call onActionComplete on import failure', async () => {
157192
(actions.importMnemonicToVault as jest.Mock).mockImplementation(() =>
158193
jest.fn().mockRejectedValue(new Error('error')),

ui/components/multichain/multi-srp/import-srp/import-srp.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ export const ImportSrp = ({
265265
<BannerAlert
266266
severity={BannerAlertSeverity.Danger}
267267
description={srpError}
268+
actionButtonLabel={'Clear'}
269+
actionButtonOnClick={() => {
270+
onSrpChange(Array(defaultNumberOfWords).fill(''));
271+
setSrpError('');
272+
}}
273+
data-testid="bannerAlert"
268274
/>
269275
) : null}
270276

0 commit comments

Comments
 (0)