Skip to content

Commit

Permalink
fix: use url constructor instead of templating and optimise filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
LowderPlay committed Oct 6, 2023
1 parent bc5228c commit 74dcd23
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/managers/storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ export const StorageManagerProvider: FC<PropsWithChildren> = ({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]);

Expand Down

0 comments on commit 74dcd23

Please sign in to comment.