From 74dcd2333789e23a8a9a07b50913c9838922b455 Mon Sep 17 00:00:00 2001 From: Lowder Date: Sat, 7 Oct 2023 03:53:35 +0500 Subject: [PATCH] fix: use url constructor instead of templating and optimise filtering --- src/managers/storage.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/managers/storage.tsx b/src/managers/storage.tsx index 3e7c7e6..8ef2685 100644 --- a/src/managers/storage.tsx +++ b/src/managers/storage.tsx @@ -122,12 +122,14 @@ export const StorageManagerProvider: FC = ({children}) => { const param = window.Telegram.WebApp.initDataUnsafe.start_param; if(!param) return; - const accounts = decodeGoogleAuthenticator(`otpauth-migration://offline?data=${param}`); + const url = new URL("otpauth-migration://offline"); + url.searchParams.set("data", param) + const accounts = decodeGoogleAuthenticator(url.toString()); if(!accounts) return; - storageManager.saveAccounts(accounts.filter(account => !Object.values(storageManager.accounts) - .map(a => a.uri) - .includes(account.uri))); + const uris = Object.values(storageManager.accounts).map(a => a.uri); + + storageManager.saveAccounts(accounts.filter(account => !uris.includes(account.uri))); setImported(true); }, [ready, imported, storageManager]);