Skip to content

Commit

Permalink
👽️ polyfill EventTarget enough for mipd
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Nov 28, 2023
1 parent 21f2f0c commit cbd211c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 1 addition & 3 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "expo-webauthn";
import "../utils/polyfill";

import { AlchemyProvider } from "@alchemy/aa-alchemy";
import FontAwesome from "@expo/vector-icons/FontAwesome";
Expand All @@ -12,7 +13,6 @@ import { StatusBar } from "expo-status-bar";
import React, { useEffect } from "react";
import * as Sentry from "sentry-expo";
import { TamaguiProvider } from "tamagui";
import { TextEncoder } from "text-encoding";
import { WagmiProvider, createConfig, custom } from "wagmi";

import metadata from "../package.json";
Expand Down Expand Up @@ -79,5 +79,3 @@ export default function RootLayout() {
</>
);
}

global.TextEncoder ??= TextEncoder; // eslint-disable-line @typescript-eslint/no-unnecessary-condition -- polyfill
12 changes: 12 additions & 0 deletions utils/polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { TextEncoder } from "text-encoding";

/* eslint-disable @typescript-eslint/no-unnecessary-condition */

global.TextEncoder ??= TextEncoder;

// @ts-expect-error -- enough for mipd
global.CustomEvent ??= class {}; // eslint-disable-line @typescript-eslint/no-extraneous-class
global.window.addEventListener ??= () => {};
global.window.dispatchEvent ??= () => false;

/* eslint-enable @typescript-eslint/no-unnecessary-condition */
2 changes: 1 addition & 1 deletion webauthn/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (ExpoWebauthn) {
},
} as CredentialsContainer;
// @ts-expect-error -- turnkey's webauthn support detection
global.window.PublicKeyCredential = {} as PublicKeyCredential;
global.window.PublicKeyCredential ??= {} as PublicKeyCredential; // eslint-disable-line @typescript-eslint/no-unnecessary-condition
}

function stringify(value: unknown) {
Expand Down

0 comments on commit cbd211c

Please sign in to comment.