Skip to content

Commit

Permalink
Reuse unknownToRec (#1048)
Browse files Browse the repository at this point in the history
This makes use of the new helper `unknownToRecord` in
`postMessageInterface`.
  • Loading branch information
nmattia authored Nov 23, 2022
1 parent 3ce5c5b commit 0515a6e
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/frontend/src/flows/authenticate/postMessageInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Principal } from "@dfinity/principal";
import { fetchDelegation } from "./fetchDelegation";
import { LoginData } from "../login/flowResult";
import { validateDerivationOrigin } from "./validateDerivationOrigin";
import { hasOwnProperty } from "../../utils/utils";
import { hasOwnProperty, unknownToRecord } from "../../utils/utils";

export interface Delegation {
delegation: {
Expand Down Expand Up @@ -39,19 +39,12 @@ export interface AuthRequest {

/** Try to read unknown data as authentication request */
const asAuthRequest = (msg: unknown): AuthRequest | undefined => {
if (typeof msg !== "object") {
return undefined;
}
const obj = unknownToRecord(msg);

if (msg === null) {
if (obj === undefined) {
return undefined;
}

// Some extra conversions to take typescript by the hand
// eslint-disable-next-line
const tmp: {} = msg;
const obj: Record<string, unknown> = tmp;

if (!hasOwnProperty(obj, "kind") || obj.kind !== "authorize-client") {
return undefined;
}
Expand Down

0 comments on commit 0515a6e

Please sign in to comment.