Skip to content

Commit

Permalink
fix: remove electron-store from preload
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jan 14, 2021
1 parent 850aa75 commit 40b6194
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/hooks/use-ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function useLedger() {
const transport = useRef<Transport | null>(null);
const disconnectTimeouts = useRef<number>(0);
const listeningForAddEvent = useRef(true);
// eslint-disable-next-line @typescript-eslint/no-empty-function
const closeTransport = useRef(() => {});
const SAFE_ASSUME_REAL_DEVICE_DISCONNECT_TIME = 1000;
const POLL_LEDGER_INTERVAL = 250;
Expand Down
6 changes: 5 additions & 1 deletion app/main.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,13 @@ const store = new Store();
ipcMain.handle('store-set', (_e, { key, value }: any) => store.set(key, value));
ipcMain.handle('store-get', (_e, { key }: any) => store.get(key));
ipcMain.handle('store-delete', (_e, { key }: any) => store.delete(key));
ipcMain.handle('store-getEntireStore', () => store.store);
// ipcMain.handle('store-getEntireStore', () => store.store);
ipcMain.handle('store-clear', () => store.clear());

ipcMain.on('store-getEntireStore', (event, arg) => {
event.returnValue = store.store;
});

ipcMain.handle('derive-key', async (_e, args) => {
return deriveKey(args);
});
7 changes: 1 addition & 6 deletions app/preload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const { contextBridge, ipcRenderer, app } = require('electron');
const Store = require('electron-store');

const TransportNodeHid = require('@ledgerhq/hw-transport-node-hid').default;

Expand Down Expand Up @@ -29,8 +28,6 @@ contextBridge.exposeInMainWorld('electron', {
// SECURITY: don't expose entire process obj
contextBridge.exposeInMainWorld('process', { ...process });

const store = new Store();

contextBridge.exposeInMainWorld('api', {
// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
Expand All @@ -39,12 +36,10 @@ contextBridge.exposeInMainWorld('api', {
get: key => ipcRenderer.invoke('store-get', { key }),
delete: key => ipcRenderer.invoke('store-delete', { key }),
clear: () => ipcRenderer.invoke('store-clear'),
getEntireStore: () => ipcRenderer.invoke('store-getEntireStore'),
initialValue: store.store,
initialValue: () => ipcRenderer.sendSync('store-getEntireStore'),
},

deriveKey: async args => {
console.log('deriveKey', args);
return ipcRenderer.invoke('derive-key', args);
},

Expand Down
2 changes: 1 addition & 1 deletion app/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ declare const api: {
delete(key: string): void;
clear(): void;
getEntireStore(): any;
initialValue: Record<string, unknown>;
initialValue(): Record<string, unknown>;
};

nodeHid: {
Expand Down
2 changes: 1 addition & 1 deletion app/utils/disk-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const persistWalletType = (walletType: WalletType) => {

export const getInitialStateFromDisk = () => {
console.log('getting entire disk store', api.store.initialValue);
return (api.store.initialValue as unknown) as DiskStore;
return (api.store.initialValue() as unknown) as DiskStore;
};

export const clearDiskStorage = () => api.store.clear();

0 comments on commit 40b6194

Please sign in to comment.