Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Remove colon from account path in Electron (polkadot-js#4361)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-jelski authored Jan 11, 2021
1 parent 78e59d5 commit 2c524ae
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/apps-electron/src/main/account-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ import { registerIpcHandler } from './register-ipc-handler';

const ACCOUNTS_SUBFOLDER = 'polkadot-accounts';

function safeWriteKey (key: string) {
return key.replace(/:/g, '-');
}

function safeReadKey (key: string) {
return key.replace(/-/g, ':');
}

export const accountStoreIpcHandler = (fileStore: FileStore): IpcMainHandler => ({
'account-store-all': () => {
let result: { key: string, value: KeyringJson }[] = [];

const collect = (key: string, value: KeyringJson) => {
result = [...result, { key, value }];
result = [...result, { key: safeReadKey(key), value }];
};

fileStore.all(collect);
Expand All @@ -27,16 +35,16 @@ export const accountStoreIpcHandler = (fileStore: FileStore): IpcMainHandler =>
},
'account-store-get': async (key: string) => new Promise((resolve) => {
try {
fileStore.get(key, resolve);
fileStore.get(safeWriteKey(key), resolve);
} catch (err) {
resolve(null);
}
}),
'account-store-remove': async (key: string) => new Promise((resolve) =>
fileStore.remove(key, () => resolve(undefined))
fileStore.remove(safeWriteKey(key), () => resolve(undefined))
),
'account-store-set': async (key: string, value: KeyringJson) => new Promise((resolve) =>
fileStore.set(key, value, () => resolve(undefined))
fileStore.set(safeWriteKey(key), value, () => resolve(undefined))
)
});

Expand Down

0 comments on commit 2c524ae

Please sign in to comment.