Transport error + reconnect proper view in landingpage

pull/2/merge
Szymon Lesisz 6 years ago
parent c268c16649
commit 1e316ea9d2

@ -55,12 +55,12 @@ export const init = (): any => {
try { try {
await TrezorConnect.init({ await TrezorConnect.init({
transportReconnect: false, transportReconnect: true,
// connectSrc: 'https://localhost:8088/', connectSrc: 'https://localhost:8088/',
connectSrc: 'https://sisyfos.trezor.io/', // connectSrc: 'https://sisyfos.trezor.io/',
debug: false, debug: true,
popup: false, popup: false,
// webusb: false webusb: false
}); });
setTimeout(() => { setTimeout(() => {
@ -89,6 +89,9 @@ export const postInit = (): any => {
// // dispatch( remove(device) ); // // dispatch( remove(device) );
// } // }
TrezorConnect.off(DEVICE.CONNECT, handleDeviceConnect);
TrezorConnect.off(DEVICE.CONNECT_UNACQUIRED, handleDeviceConnect);
TrezorConnect.on(DEVICE.CONNECT, handleDeviceConnect); TrezorConnect.on(DEVICE.CONNECT, handleDeviceConnect);
TrezorConnect.on(DEVICE.CONNECT_UNACQUIRED, handleDeviceConnect); TrezorConnect.on(DEVICE.CONNECT_UNACQUIRED, handleDeviceConnect);
@ -159,14 +162,22 @@ export function onSelectDevice(device: any): any {
} }
// TODO: as TrezorConnect method // TODO: as TrezorConnect method
const __getDeviceState = async (path, instance): Promise<any> => { const __getDeviceState = async (path, instance, state): Promise<any> => {
return await TrezorConnect.getPublicKey({ // return await TrezorConnect.getPublicKey({
// device: {
// path,
// instance
// },
// path: "m/1'/0'/0'",
// confirmation: false
// });
return await TrezorConnect.getDeviceState({
device: { device: {
path, path,
instance instance,
state
}, },
// selectedDevice: path,
instance: instance,
path: "m/1'/0'/0'", path: "m/1'/0'/0'",
confirmation: false confirmation: false
}); });
@ -216,13 +227,13 @@ export const getSelectedDeviceState = (): any => {
&& !selected.acquiring && !selected.acquiring
&& !selected.state) { && !selected.state) {
const response = await __getDeviceState(selected.path, selected.instance); const response = await __getDeviceState(selected.path, selected.instance, selected.state);
if (response && response.success) { if (response && response.success) {
dispatch({ dispatch({
type: CONNECT.AUTH_DEVICE, type: CONNECT.AUTH_DEVICE,
device: selected, device: selected,
state: response.payload.xpub state: response.payload.state
}); });
} else { } else {
dispatch({ dispatch({

@ -7,7 +7,8 @@ import TrezorConnect from 'trezor-connect';
export default class InstallBridge extends Component { export default class InstallBridge extends Component {
componentDidUpdate() { componentDidUpdate() {
if (this.props.transport.indexOf('webusb') >= 0) const transport = this.props.transport;
if (transport && transport.type.indexOf('webusb') >= 0)
TrezorConnect.renderWebUSBButton(); TrezorConnect.renderWebUSBButton();
} }
@ -16,7 +17,8 @@ export default class InstallBridge extends Component {
let connectClaim = 'Connect TREZOR to continue'; let connectClaim = 'Connect TREZOR to continue';
let and = null; let and = null;
let bridgeClaim = null; let bridgeClaim = null;
if (this.props.transport.indexOf('webusb') >= 0) { const transport = this.props.transport;
if (transport && transport.type.indexOf('webusb') >= 0) {
webusb = <button className="trezor-webusb-button">Check for devices</button>; webusb = <button className="trezor-webusb-button">Check for devices</button>;
connectClaim = 'Connect TREZOR'; connectClaim = 'Connect TREZOR';
and = <p>and</p>; and = <p>and</p>;

@ -52,18 +52,18 @@ export default (props: any): any => {
className="error" className="error"
/>); />);
css += ' config-error'; css += ' config-error';
} else if (!browserState.supported) { } else if (browserState.supported === false) {
css += ' browser-not-supported' css += ' browser-not-supported'
body = <BrowserNotSupported />; body = <BrowserNotSupported />;
} else if (connectError || bridgeRoute) { } else if (connectError || bridgeRoute) {
css += ' install-bridge'; css += ' install-bridge';
body = <InstallBridge browserState={ props.connect.browserState } />; body = <InstallBridge browserState={ props.connect.browserState } />;
} else { } else if (web3.length > 0 && devices.length < 1) {
css += ' connect-device'; css += ' connect-device';
body = <ConnectDevice transport={ transport } />; body = <ConnectDevice transport={ transport } />;
} }
if (notification || (web3.length > 0 && devices.length < 1)) { if (notification || body) {
return ( return (
<div className={ css }> <div className={ css }>
<Header /> <Header />

@ -16,6 +16,7 @@ export default class Receive extends AbstractAccount {
const _render = (props: any): any => { const _render = (props: any): any => {
const { const {
network,
deviceState, deviceState,
accountIndex, accountIndex,
addressVerified, addressVerified,

@ -27,6 +27,9 @@ export default class AbstractAccount extends Component {
} }
const device = this.props.devices.find(d => d.state === state.deviceState); const device = this.props.devices.find(d => d.state === state.deviceState);
if (!device) {
return (<section>Device with state {state.deviceState} not found</section>);
}
const discovery = props.discovery.find(d => d.deviceState === device.state && d.network === state.network); const discovery = props.discovery.find(d => d.deviceState === device.state && d.network === state.network);
const account = props.accounts.find(a => a.deviceState === state.deviceState && a.index === state.accountIndex && a.network === state.network); const account = props.accounts.find(a => a.deviceState === state.deviceState && a.index === state.accountIndex && a.network === state.network);

@ -144,12 +144,13 @@ export const DeviceSelect = (props: any): any => {
} }
console.log("DEVSEL", props) console.log("DEVSEL", props)
const disabled: boolean = (devices && devices.length <= 1 && transport && transport.type.indexOf('webusb') < 0);
return ( return (
<Value <Value
className="device-select" className="device-select"
onClick={ handleMenuClick } onClick={ handleMenuClick }
disabled={ (devices && devices.length <= 1 && transport.indexOf('webusb') < 0) } disabled={ disabled }
value={ selected } value={ selected }
opened={ props.deviceDropdownOpened } opened={ props.deviceDropdownOpened }
onOpen={ () => props.toggleDeviceDropdown(true) } onOpen={ () => props.toggleDeviceDropdown(true) }
@ -167,10 +168,9 @@ export class DeviceDropdown extends Component {
} }
componentDidUpdate() { componentDidUpdate() {
if (this.props.connect.transport.indexOf('webusb') >= 0) const transport: any = this.props.connect.transport;
if (transport && transport.type.indexOf('webusb') >= 0)
TrezorConnect.renderWebUSBButton(); TrezorConnect.renderWebUSBButton();
console.log("RENDER USB BUTTON")
} }
mouseDownHandler(event: MouseEvent): void { mouseDownHandler(event: MouseEvent): void {
@ -198,8 +198,8 @@ export class DeviceDropdown extends Component {
componentDidMount(): void { componentDidMount(): void {
window.addEventListener('mousedown', this.mouseDownHandler, false); window.addEventListener('mousedown', this.mouseDownHandler, false);
// window.addEventListener('blur', this.blurHandler, false); // window.addEventListener('blur', this.blurHandler, false);
const transport: any = this.props.connect.transport;
if (this.props.connect.transport.indexOf('webusb') >= 0) if (transport && transport.type.indexOf('webusb') >= 0)
TrezorConnect.renderWebUSBButton(); TrezorConnect.renderWebUSBButton();
} }
@ -214,7 +214,7 @@ export class DeviceDropdown extends Component {
const selected = findSelectedDevice(this.props.connect); const selected = findSelectedDevice(this.props.connect);
let webUsbButton = null; let webUsbButton = null;
if (transport.indexOf('webusb') >= 0) { if (transport && transport.type.indexOf('webusb') >= 0) {
webUsbButton = <button className="trezor-webusb-button">Check for devices</button>; webUsbButton = <button className="trezor-webusb-button">Check for devices</button>;
} }

@ -98,6 +98,15 @@ const mergeDevices = (current: TrezorDevice, upcoming: Object): TrezorDevice =>
} }
} }
if (upcoming.features && current.features) {
console.log("CZEKIN PASS PROT");
if (upcoming.features.passphrase_protection !== current.features.passphrase_protection) {
// device settings has been changed, reset state
dev.state = null;
console.log("RESTETTTT STATE!");
}
}
return dev; return dev;
} }
@ -155,14 +164,16 @@ const setDeviceState = (state: State, action: any): State => {
//const affectedDevice: ?TrezorDevice = state.devices.find(d => d.path === action.device.path && d.instance === action.device.instance); //const affectedDevice: ?TrezorDevice = state.devices.find(d => d.path === action.device.path && d.instance === action.device.instance);
const index: number = state.devices.findIndex(d => d.path === action.device.path && d.instance === action.device.instance); const index: number = state.devices.findIndex(d => d.path === action.device.path && d.instance === action.device.instance);
if (index > -1) { if (index > -1) {
const changedDevice: TrezorDevice = { console.warn("APGREDJS", newState.devices[index].state)
...newState.devices[index], // device could already have own state from firmware, do not override it
state: action.state if (!newState.devices[index].state) {
}; const changedDevice: TrezorDevice = {
newState.devices[index] = changedDevice; ...newState.devices[index],
//newState.selectedDevice = changedDevice; state: action.state
};
newState.devices[index] = changedDevice;
}
} }
return newState; return newState;
} }
@ -307,7 +318,6 @@ export default function connect(state: State = initialState, action: any): any {
browserState: action.payload.browser browserState: action.payload.browser
} }
case CONNECT.DUPLICATE : case CONNECT.DUPLICATE :
return duplicate(state, action.device); return duplicate(state, action.device);
@ -327,7 +337,8 @@ export default function connect(state: State = initialState, action: any): any {
case TRANSPORT.START : case TRANSPORT.START :
return { return {
...state, ...state,
transport: action.payload transport: action.payload,
error: null
} }
case TRANSPORT.ERROR : case TRANSPORT.ERROR :

@ -26,6 +26,8 @@ const TrezorConnectService = (store: any) => (next: any) => (action: any) => {
} else if (action.type === TRANSPORT.ERROR) { } else if (action.type === TRANSPORT.ERROR) {
store.dispatch( push('/') ); store.dispatch( push('/') );
} else if (action.type === TRANSPORT.START && store.getState().web3.length > 0 && prevState.devices.length > 0) {
store.dispatch( TrezorConnectActions.postInit() );
} else if (action.type === TRANSPORT.UNREADABLE) { } else if (action.type === TRANSPORT.UNREADABLE) {
store.dispatch({ store.dispatch({
type: NOTIFICATION.ADD, type: NOTIFICATION.ADD,

Loading…
Cancel
Save