diff --git a/app/_layout.tsx b/app/_layout.tsx index 120e90b5..56e63cdb 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -1,4 +1,5 @@ import "expo-webauthn"; +import "../utils/polyfill"; import { AlchemyProvider } from "@alchemy/aa-alchemy"; import FontAwesome from "@expo/vector-icons/FontAwesome"; @@ -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"; @@ -79,5 +79,3 @@ export default function RootLayout() { ); } - -global.TextEncoder ??= TextEncoder; // eslint-disable-line @typescript-eslint/no-unnecessary-condition -- polyfill diff --git a/utils/polyfill.ts b/utils/polyfill.ts new file mode 100644 index 00000000..0580cd87 --- /dev/null +++ b/utils/polyfill.ts @@ -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 */ diff --git a/webauthn/src/index.ts b/webauthn/src/index.ts index 15420deb..3d47705b 100644 --- a/webauthn/src/index.ts +++ b/webauthn/src/index.ts @@ -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) {