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

Replace login error page with toast #2570

Merged
merged 1 commit into from
Aug 27, 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
29 changes: 20 additions & 9 deletions src/frontend/src/components/authenticateBox.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ErrorOptions, displayError } from "$src/components/displayError";
import { withLoader } from "$src/components/loader";
import {
PinIdentityMaterial,
Expand Down Expand Up @@ -42,6 +41,8 @@ import { mkAnchorPicker } from "./anchorPicker";
import { mainWindow } from "./mainWindow";
import { promptUserNumber } from "./promptUserNumber";

import { displayError } from "$src/components/displayError";
import { toast } from "$src/components/toast";
import { DerEncodedPublicKey } from "@dfinity/agent";
import { landingPage } from "./landingPage";

Expand Down Expand Up @@ -390,10 +391,24 @@ const clarifyError: {
}),
};

const clarifyError_ = <K extends FlowError["kind"]>(
const flowErrorToastTemplate = <K extends FlowError["kind"]>(
flowError: KindToError<K> & { kind: K }
): Omit<ErrorOptions, "primaryButton"> =>
clarifyError[flowError.kind](flowError);
): TemplateResult => {
const props = clarifyError[flowError.kind](flowError);
const detailSlot = nonNullish(props.detail)
? html`<div class="l-stack">
<h4>Error details:</h4>
<pre data-role="error-detail" class="t-paragraph">${props.detail}</pre>
</div>`
: undefined;
return html`
<h3 data-error-code=${flowError.kind} class="t-title c-card__title">
${props.title}
</h3>
<div data-role="warning-message" class="t-paragraph">${props.message}</div>
${detailSlot}
`;
};

export const handleLoginFlowResult = async <E>(
result: (LoginSuccess & E) | FlowError
Expand All @@ -407,11 +422,7 @@ export const handleLoginFlowResult = async <E>(

result satisfies FlowError;

await displayError({
...clarifyError_(result),
errorCode: result.kind,
primaryButton: "Try again",
});
toast.error(flowErrorToastTemplate(result));
return undefined;
};

Expand Down
4 changes: 1 addition & 3 deletions src/frontend/src/test-e2e/pinAuthDisabled.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ test("Cannot auth with PIN if dapp disallows PIN", async () => {
const authenticateView = new AuthenticateView(browser);
await authenticateView.waitForDisplay();
await authenticateView.pickAnchor(userNumber);
await browser
.$('#errorContainer [data-error-code="pinNotAllowed"]')
.waitForDisplayed();
await browser.$('[data-error-code="pinNotAllowed"]').waitForDisplayed();
}, APPLE_USER_AGENT);
}, 300_000);
Loading