diff --git a/src/js/actions/TrezorConnectActions.js b/src/js/actions/TrezorConnectActions.js index e7d2568f..5f26ba80 100644 --- a/src/js/actions/TrezorConnectActions.js +++ b/src/js/actions/TrezorConnectActions.js @@ -55,12 +55,12 @@ export const init = (): any => { try { await TrezorConnect.init({ - transportReconnect: false, - // connectSrc: 'https://localhost:8088/', - connectSrc: 'https://sisyfos.trezor.io/', - debug: false, + transportReconnect: true, + connectSrc: 'https://localhost:8088/', + // connectSrc: 'https://sisyfos.trezor.io/', + debug: true, popup: false, - // webusb: false + webusb: false }); setTimeout(() => { @@ -89,6 +89,9 @@ export const postInit = (): any => { // // dispatch( remove(device) ); // } + TrezorConnect.off(DEVICE.CONNECT, handleDeviceConnect); + TrezorConnect.off(DEVICE.CONNECT_UNACQUIRED, handleDeviceConnect); + TrezorConnect.on(DEVICE.CONNECT, handleDeviceConnect); TrezorConnect.on(DEVICE.CONNECT_UNACQUIRED, handleDeviceConnect); @@ -159,14 +162,22 @@ export function onSelectDevice(device: any): any { } // TODO: as TrezorConnect method -const __getDeviceState = async (path, instance): Promise => { - return await TrezorConnect.getPublicKey({ +const __getDeviceState = async (path, instance, state): Promise => { + // return await TrezorConnect.getPublicKey({ + // device: { + // path, + // instance + // }, + // path: "m/1'/0'/0'", + // confirmation: false + // }); + + return await TrezorConnect.getDeviceState({ device: { path, - instance + instance, + state }, - // selectedDevice: path, - instance: instance, path: "m/1'/0'/0'", confirmation: false }); @@ -216,13 +227,13 @@ export const getSelectedDeviceState = (): any => { && !selected.acquiring && !selected.state) { - const response = await __getDeviceState(selected.path, selected.instance); + const response = await __getDeviceState(selected.path, selected.instance, selected.state); if (response && response.success) { dispatch({ type: CONNECT.AUTH_DEVICE, device: selected, - state: response.payload.xpub + state: response.payload.state }); } else { dispatch({ diff --git a/src/js/components/landing/ConnectDevice.js b/src/js/components/landing/ConnectDevice.js index 7fb78238..e0e6816f 100644 --- a/src/js/components/landing/ConnectDevice.js +++ b/src/js/components/landing/ConnectDevice.js @@ -7,7 +7,8 @@ import TrezorConnect from 'trezor-connect'; export default class InstallBridge extends Component { componentDidUpdate() { - if (this.props.transport.indexOf('webusb') >= 0) + const transport = this.props.transport; + if (transport && transport.type.indexOf('webusb') >= 0) TrezorConnect.renderWebUSBButton(); } @@ -16,7 +17,8 @@ export default class InstallBridge extends Component { let connectClaim = 'Connect TREZOR to continue'; let and = null; let bridgeClaim = null; - if (this.props.transport.indexOf('webusb') >= 0) { + const transport = this.props.transport; + if (transport && transport.type.indexOf('webusb') >= 0) { webusb = ; connectClaim = 'Connect TREZOR'; and =

and

; diff --git a/src/js/components/landing/LandingPage.js b/src/js/components/landing/LandingPage.js index 7bb2bf29..6f1c88c3 100644 --- a/src/js/components/landing/LandingPage.js +++ b/src/js/components/landing/LandingPage.js @@ -52,18 +52,18 @@ export default (props: any): any => { className="error" />); css += ' config-error'; - } else if (!browserState.supported) { + } else if (browserState.supported === false) { css += ' browser-not-supported' body = ; } else if (connectError || bridgeRoute) { css += ' install-bridge'; body = ; - } else { + } else if (web3.length > 0 && devices.length < 1) { css += ' connect-device'; body = ; } - if (notification || (web3.length > 0 && devices.length < 1)) { + if (notification || body) { return (
diff --git a/src/js/components/wallet/Receive.js b/src/js/components/wallet/Receive.js index 75a19a65..cd9ef2ef 100644 --- a/src/js/components/wallet/Receive.js +++ b/src/js/components/wallet/Receive.js @@ -16,6 +16,7 @@ export default class Receive extends AbstractAccount { const _render = (props: any): any => { const { + network, deviceState, accountIndex, addressVerified, diff --git a/src/js/components/wallet/account/AbstractAccount.js b/src/js/components/wallet/account/AbstractAccount.js index 245bbe72..e994dbb3 100644 --- a/src/js/components/wallet/account/AbstractAccount.js +++ b/src/js/components/wallet/account/AbstractAccount.js @@ -27,6 +27,9 @@ export default class AbstractAccount extends Component { } const device = this.props.devices.find(d => d.state === state.deviceState); + if (!device) { + return (
Device with state {state.deviceState} not found
); + } 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); diff --git a/src/js/components/wallet/aside/DeviceSelection.js b/src/js/components/wallet/aside/DeviceSelection.js index 1ed7b723..f9600a5a 100644 --- a/src/js/components/wallet/aside/DeviceSelection.js +++ b/src/js/components/wallet/aside/DeviceSelection.js @@ -144,12 +144,13 @@ export const DeviceSelect = (props: any): any => { } console.log("DEVSEL", props) + const disabled: boolean = (devices && devices.length <= 1 && transport && transport.type.indexOf('webusb') < 0); return ( props.toggleDeviceDropdown(true) } @@ -167,10 +168,9 @@ export class DeviceDropdown extends Component { } 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(); - - console.log("RENDER USB BUTTON") } mouseDownHandler(event: MouseEvent): void { @@ -198,8 +198,8 @@ export class DeviceDropdown extends Component { componentDidMount(): void { window.addEventListener('mousedown', this.mouseDownHandler, false); // window.addEventListener('blur', this.blurHandler, false); - - if (this.props.connect.transport.indexOf('webusb') >= 0) + const transport: any = this.props.connect.transport; + if (transport && transport.type.indexOf('webusb') >= 0) TrezorConnect.renderWebUSBButton(); } @@ -214,7 +214,7 @@ export class DeviceDropdown extends Component { const selected = findSelectedDevice(this.props.connect); let webUsbButton = null; - if (transport.indexOf('webusb') >= 0) { + if (transport && transport.type.indexOf('webusb') >= 0) { webUsbButton = ; } diff --git a/src/js/reducers/TrezorConnectReducer.js b/src/js/reducers/TrezorConnectReducer.js index 8e103403..f4c0f5ea 100644 --- a/src/js/reducers/TrezorConnectReducer.js +++ b/src/js/reducers/TrezorConnectReducer.js @@ -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; } @@ -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 index: number = state.devices.findIndex(d => d.path === action.device.path && d.instance === action.device.instance); if (index > -1) { - const changedDevice: TrezorDevice = { - ...newState.devices[index], - state: action.state - }; - newState.devices[index] = changedDevice; - //newState.selectedDevice = changedDevice; + console.warn("APGREDJS", newState.devices[index].state) + // device could already have own state from firmware, do not override it + if (!newState.devices[index].state) { + const changedDevice: TrezorDevice = { + ...newState.devices[index], + state: action.state + }; + newState.devices[index] = changedDevice; + } } - return newState; } @@ -307,7 +318,6 @@ export default function connect(state: State = initialState, action: any): any { browserState: action.payload.browser } - case CONNECT.DUPLICATE : return duplicate(state, action.device); @@ -327,7 +337,8 @@ export default function connect(state: State = initialState, action: any): any { case TRANSPORT.START : return { ...state, - transport: action.payload + transport: action.payload, + error: null } case TRANSPORT.ERROR : diff --git a/src/js/services/TrezorConnectService.js b/src/js/services/TrezorConnectService.js index e2b3c7ca..9fe3a12a 100644 --- a/src/js/services/TrezorConnectService.js +++ b/src/js/services/TrezorConnectService.js @@ -26,6 +26,8 @@ const TrezorConnectService = (store: any) => (next: any) => (action: any) => { } else if (action.type === TRANSPORT.ERROR) { 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) { store.dispatch({ type: NOTIFICATION.ADD,