diff --git a/next.config.mjs b/next.config.mjs index 1470c8d524..07d1f2a35d 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -32,7 +32,7 @@ const nextConfig = { dirs: ['src'], }, experimental: { - optimizePackageImports: ['@mui/material', '@mui/icons-material', 'lodash', 'date-fns'] + optimizePackageImports: ['@mui/material', '@mui/icons-material', 'lodash', 'date-fns'], }, webpack(config) { config.module.rules.push({ diff --git a/src/hooks/wallets/mpc/useMPC.ts b/src/hooks/wallets/mpc/useMPC.ts index ef580a0f14..94663b4391 100644 --- a/src/hooks/wallets/mpc/useMPC.ts +++ b/src/hooks/wallets/mpc/useMPC.ts @@ -44,7 +44,7 @@ export const useInitMPC = () => { web3AuthClientId: SOCIAL_WALLET_OPTIONS.web3AuthClientId, // Available networks are "sapphire_devnet", "sapphire_mainnet" web3AuthNetwork: WEB3AUTH_NETWORK.MAINNET, - baseUrl: `${window.location.origin}/serviceworker`, + baseUrl: `${window.location.origin}/`, uxMode: 'popup', enableLogging: true, chainConfig, diff --git a/src/service-workers/index.ts b/src/service-workers/index.ts index 0ed829a135..70f1e849e8 100644 --- a/src/service-workers/index.ts +++ b/src/service-workers/index.ts @@ -3,5 +3,8 @@ /// import { firebaseMessagingSw } from './firebase-messaging/firebase-messaging-sw' +import { mpcCoreKitServiceWorker } from './mpc-core-kit-sw' firebaseMessagingSw() + +mpcCoreKitServiceWorker() diff --git a/public/serviceworker/sw.js b/src/service-workers/mpc-core-kit-sw.ts similarity index 93% rename from public/serviceworker/sw.js rename to src/service-workers/mpc-core-kit-sw.ts index ad32a6ed6d..76b47bf211 100644 --- a/public/serviceworker/sw.js +++ b/src/service-workers/mpc-core-kit-sw.ts @@ -1,24 +1,30 @@ -/* eslint-disable */ -function getScope() { - return self.registration.scope -} +/// + +declare const self: ServiceWorkerGlobalScope -self.addEventListener('message', function (event) { - if (event.data && event.data.type === 'SKIP_WAITING') { - self.skipWaiting() +export const mpcCoreKitServiceWorker = () => { + /* eslint-disable */ + function getScope() { + return self.registration.scope } -}) -self.addEventListener('fetch', function (event) { - try { - const url = new URL(event.request.url) - const redirectURL = self.location.url - if (url.pathname.includes('redirect') && url.href.includes(getScope())) { - event.respondWith( - new Response( - new Blob( - [ - ` + self.addEventListener('message', function (event) { + if (event.data && event.data.type === 'SKIP_WAITING') { + self.skipWaiting() + } + }) + + self.addEventListener('fetch', function (event) { + try { + const url = new URL(event.request.url) + //@ts-expect-error + const redirectURL = self.location.url + if (url.pathname.includes('redirect') && url.href.includes(getScope())) { + event.respondWith( + new Response( + new Blob( + [ + ` @@ -306,13 +312,14 @@ self.addEventListener('fetch', function (event) { ${''} `, - ], - { type: 'text/html' }, + ], + { type: 'text/html' }, + ), ), - ), - ) + ) + } + } catch (error) { + console.error(error) } - } catch (error) { - console.error(error) - } -}) + }) +}