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

Commit

Permalink
feat: update webpack
Browse files Browse the repository at this point in the history
TEMP COMMIT2

TEMP disable all thingse that break
  • Loading branch information
kyranjamie committed Dec 22, 2020
1 parent 69d740d commit 00293c0
Show file tree
Hide file tree
Showing 28 changed files with 2,112 additions and 329 deletions.
3 changes: 1 addition & 2 deletions app/app-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
<div class="draggable-bar"></div>
<div id="root"></div>
<script>
window.Buffer = electron.Buffer;
window.__dirname = electron.__dirname;
window.fs = electron.fs;
window.__filename = electron.__filename;

if (electron.scriptsToLoad.length) {
document.write(
Expand Down
6 changes: 5 additions & 1 deletion app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
<title>Stacks Wallet</title>
<meta
http-equiv="Content-Security-Policy"
content="default-src 'none'; font-src 'self'; img-src data:; style-src 'unsafe-inline'; script-src 'self' 'unsafe-eval' 'nonce-6ca3c3e1fcd34bbc8cfaeceaa8106e36'; connect-src *;"
content="default-src 'none'; font-src 'self'; img-src data:; style-src 'unsafe-inline'; script-src 'self' 'unsafe-eval' 'nonce-6ca3c3e1fcd34bbc8cfaeceaa8106e36' 'nonce-6ca3c3e1fcd34bbc8cfaeceaa8106e37'; connect-src *;"
/>
</head>

<body>
<div class="draggable-bar"></div>
<div id="root"></div>
<script nonce="6ca3c3e1fcd34bbc8cfaeceaa8106e37">
window.__dirname = electron.__dirname;
window.__filename = electron.__filename;
</script>
<script src="./dist/renderer.prod.js" nonce="6ca3c3e1fcd34bbc8cfaeceaa8106e36"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { remote } from 'electron';
// import { remote } from 'electron';
import { useClipboard } from '@blockstack/ui';
import { Transaction } from '@blockstack/stacks-blockchain-api-types';

Expand Down Expand Up @@ -29,50 +29,46 @@ interface TxListContextMenu {
}

export function createTxListContextMenu(event: Event, { tx, copy }: TxListContextMenu) {
event.preventDefault();
const { Menu, MenuItem } = remote;
const menu = new Menu();

const menuItems: Electron.MenuItemConstructorOptions[] = [
{
label: 'Copy to clipboard',
enabled: false,
},
{ type: 'separator' },
{
label: 'Transaction ID',
click: () => copy.txid.onCopy(),
},
{
label: 'Recipient address',
visible: !!getRecipientAddress(tx),
click: () => copy.recipientAddress.onCopy(),
},
{
label: 'Memo',
visible: hasMemo(tx),
click: () => copy.memo.onCopy(),
},
{
label: 'Timestamp',
click: () => copy.date.onCopy(),
},
{
label: 'Transaction (as JSON)',
click: () => copy.txDetails.onCopy(),
},
{
label: 'Explorer link',
click: () => copy.explorerLink.onCopy(),
},
];

menuItems.forEach(item => menu.append(new MenuItem(item)));

menu.popup({ window: remote.getCurrentWindow() });

menu.once('menu-will-close', () => {
// `destroy` call untyped
(menu as any).destroy();
});
// event.preventDefault();
// const { Menu, MenuItem } = remote;
// const menu = new Menu();
// const menuItems: Electron.MenuItemConstructorOptions[] = [
// {
// label: 'Copy to clipboard',
// enabled: false,
// },
// { type: 'separator' },
// {
// label: 'Transaction ID',
// click: () => copy.txid.onCopy(),
// },
// {
// label: 'Recipient address',
// visible: !!getRecipientAddress(tx),
// click: () => copy.recipientAddress.onCopy(),
// },
// {
// label: 'Memo',
// visible: hasMemo(tx),
// click: () => copy.memo.onCopy(),
// },
// {
// label: 'Timestamp',
// click: () => copy.date.onCopy(),
// },
// {
// label: 'Transaction (as JSON)',
// click: () => copy.txDetails.onCopy(),
// },
// {
// label: 'Explorer link',
// click: () => copy.explorerLink.onCopy(),
// },
// ];
// menuItems.forEach(item => menu.append(new MenuItem(item)));
// menu.popup({ window: remote.getCurrentWindow() });
// menu.once('menu-will-close', () => {
// // `destroy` call untyped
// (menu as any).destroy();
// });
}
5 changes: 0 additions & 5 deletions app/crypto/key-generation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { memoizeWith, identity } from 'ramda';
import argon2, { ArgonType } from 'argon2-browser';

import { delay } from '@utils/delay';

export async function deriveKey({ pass, salt }: { pass: string; salt: string }) {
// Without this additional delay of 1ms, an odd behaviour with the argon2 library
// causes the promise to be render blocking
await delay(1);
const result = await argon2.hash({
pass,
salt,
Expand Down
161 changes: 76 additions & 85 deletions app/hooks/use-ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,89 +14,80 @@ export enum LedgerConnectStep {
}

export function useLedger() {
const [step, setStep] = useState(LedgerConnectStep.Disconnected);
const [usbError, setUsbError] = useState<string | null>(null);

const transport = useRef<Transport | null>(null);
const disconnectTimeouts = useRef<number>(0);
const listeningForAddEvent = useRef(true);

const SAFE_ASSUME_REAL_DEVICE_DISCONNECT_TIME = 1000;
const POLL_LEDGER_INTERVAL = 250;

const createListener = useCallback(() => {
const tHid = TransportNodeHid.listen({
next: async event => {
if (event.type === 'add') {
clearTimeout(disconnectTimeouts.current);
tHid.unsubscribe();

const [error, t] = await safeAwait(TransportNodeHid.open(event.descriptor));

if (error) {
setUsbError('Unable to connect to device. You may need to configure your udev rules.');
return;
}

if (t) {
setUsbError(null);
t.on('disconnect', async () => {
listeningForAddEvent.current = true;
transport.current = null;
await t.close();
const timer = setTimeout(() => {
setStep(LedgerConnectStep.Disconnected);
}, SAFE_ASSUME_REAL_DEVICE_DISCONNECT_TIME);
disconnectTimeouts.current = (timer as unknown) as number;
createListener();
});

listeningForAddEvent.current = false;
transport.current = t;
}
}
},
error: () => ({}),
complete: () => ({}),
});
return tHid;
}, []);

useEffect(() => {
const subscription = createListener();
return () => {
subscription.unsubscribe();
if (transport.current) {
void transport.current.close();
transport.current = null;
}
};
}, [createListener]);

useInterval(() => {
if (
transport.current &&
step !== LedgerConnectStep.HasAddress &&
!listeningForAddEvent.current
) {
// There's a bug with the node-hid library where it doesn't
// fire disconnect event until next time an operation using it is called.
// Here we poll a request to ensure the event is fired
void new BlockstackApp(transport.current)
.getVersion()
.then(resp => {
if (resp.returnCode === LedgerError.AppDoesNotSeemToBeOpen)
return setStep(LedgerConnectStep.ConnectedAppClosed);
if (resp.returnCode === LedgerError.NoErrors)
return setStep(LedgerConnectStep.ConnectedAppOpen);
})
.catch(() => ({}));
}
}, POLL_LEDGER_INTERVAL);

return {
transport: transport.current,
step,
error: usbError,
};
// const [step, setStep] = useState(LedgerConnectStep.Disconnected);
// const [usbError, setUsbError] = useState<string | null>(null);
// const transport = useRef<Transport | null>(null);
// const disconnectTimeouts = useRef<number>(0);
// const listeningForAddEvent = useRef(true);
// const SAFE_ASSUME_REAL_DEVICE_DISCONNECT_TIME = 1000;
// const POLL_LEDGER_INTERVAL = 250;
// const createListener = useCallback(() => {
// const tHid = TransportNodeHid.listen({
// next: async event => {
// if (event.type === 'add') {
// clearTimeout(disconnectTimeouts.current);
// tHid.unsubscribe();
// const [error, t] = await safeAwait(TransportNodeHid.open(event.descriptor));
// if (error) {
// console.log(error);
// setUsbError('Unable to connect to device. You may need to configure your udev rules.');
// return;
// }
// if (t) {
// setUsbError(null);
// t.on('disconnect', async () => {
// listeningForAddEvent.current = true;
// transport.current = null;
// await t.close();
// const timer = setTimeout(() => {
// setStep(LedgerConnectStep.Disconnected);
// }, SAFE_ASSUME_REAL_DEVICE_DISCONNECT_TIME);
// disconnectTimeouts.current = (timer as unknown) as number;
// createListener();
// });
// listeningForAddEvent.current = false;
// transport.current = t;
// }
// }
// },
// error: () => ({}),
// complete: () => ({}),
// });
// return tHid;
// }, []);
// useEffect(() => {
// const subscription = createListener();
// return () => {
// subscription.unsubscribe();
// if (transport.current) {
// void transport.current.close();
// transport.current = null;
// }
// };
// }, [createListener]);
// useInterval(() => {
// if (
// transport.current &&
// step !== LedgerConnectStep.HasAddress &&
// !listeningForAddEvent.current
// ) {
// // There's a bug with the node-hid library where it doesn't
// // fire disconnect event until next time an operation using it is called.
// // Here we poll a request to ensure the event is fired
// void new BlockstackApp(transport.current)
// .getVersion()
// .then(resp => {
// if (resp.returnCode === LedgerError.AppDoesNotSeemToBeOpen)
// return setStep(LedgerConnectStep.ConnectedAppClosed);
// if (resp.returnCode === LedgerError.NoErrors)
// return setStep(LedgerConnectStep.ConnectedAppOpen);
// })
// .catch(() => ({}));
// }
// }, POLL_LEDGER_INTERVAL);
// return {
// transport: transport.current,
// step,
// error: usbError,
// };
}
44 changes: 20 additions & 24 deletions app/hooks/use-window-focus.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
import { remote } from 'electron';
// import { remote } from 'electron';
import { useState, useEffect, useCallback } from 'react';

export type WindowActiveState = 'focused' | 'blurred';

export function useWindowFocus() {
const [win] = remote.BrowserWindow.getAllWindows();
const [windowState, setWindowState] = useState<WindowActiveState>(
win.isFocused() ? 'focused' : 'blurred'
);

const focusHandler = useCallback(() => setWindowState('focused'), []);
const blurHandler = useCallback(() => setWindowState('blurred'), []);

useEffect(() => {
win.on('focus', focusHandler);
win.on('blur', blurHandler);

window.addEventListener('beforeunload', () => {
win.removeListener('focus', focusHandler);
win.removeListener('blur', blurHandler);
});

return () => {
win.removeListener('focus', focusHandler);
win.removeListener('blur', blurHandler);
};
}, [blurHandler, focusHandler, win]);
return windowState;
// const [win] = remote.BrowserWindow.getAllWindows();
// const [windowState, setWindowState] = useState<WindowActiveState>(
// win.isFocused() ? 'focused' : 'blurred'
// );
// const focusHandler = useCallback(() => setWindowState('focused'), []);
// const blurHandler = useCallback(() => setWindowState('blurred'), []);
// useEffect(() => {
// win.on('focus', focusHandler);
// win.on('blur', blurHandler);
// window.addEventListener('beforeunload', () => {
// win.removeListener('focus', focusHandler);
// win.removeListener('blur', blurHandler);
// });
// return () => {
// win.removeListener('focus', focusHandler);
// win.removeListener('blur', blurHandler);
// };
// }, [blurHandler, focusHandler, win]);
// return windowState;
}
8 changes: 0 additions & 8 deletions app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ import { render } from 'react-dom';
import { AppContainer as ReactHotAppContainer } from 'react-hot-loader';

import { configureStore, history } from './store/configureStore';
import { ipcRenderer, contextBridge } from 'electron';

const { store, persistor } = configureStore();

const AppContainer = process.env.PLAIN_HMR ? Fragment : ReactHotAppContainer;

// contextBridge.exposeInMainWorld('api', {
// xxx: 123,
// });

// console.log('dddddddddd', require('safe-buffer'));
// (window as any).Buffer = require('safe-buffer').Buffer;

document.addEventListener('DOMContentLoaded', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Root = require('./pages/root').default;
Expand Down
Loading

0 comments on commit 00293c0

Please sign in to comment.