Merge master

pull/3/head
Vladimir Volek 6 years ago
commit c3c617955c

@ -60,7 +60,7 @@
"redux-thunk": "^2.2.0",
"styled-components": "^3.3.3",
"styled-normalize": "^8.0.0",
"trezor-connect": "^5.0.28",
"trezor-connect": "5.0.30",
"web3": "^0.19.0",
"webpack": "^4.16.3",
"whatwg-fetch": "^2.0.4",

@ -78,6 +78,7 @@ export type UnknownDevice = $Exact<{
ts: number;
}>
export type { Device } from 'trezor-connect';
export type TrezorDevice = AcquiredDevice | UnknownDevice;
export type RouterLocationState = LocationState;

@ -2,7 +2,6 @@
import TrezorConnect, { UI, UI_EVENT } from 'trezor-connect';
import type { Device } from 'trezor-connect';
import * as MODAL from 'actions/constants/modal';
import * as CONNECT from 'actions/constants/TrezorConnect';

@ -67,7 +67,7 @@ export const updateSelectedValues = (prevState: State, action: Action): AsyncAct
const web3 = stateUtils.getWeb3(state);
const payload: $ElementType<State, 'selectedAccount'> = {
// location: location.pathname,
location: location.pathname,
account,
network,
discovery,

@ -32,7 +32,7 @@ type SelectOptions = {
// action from component <reactSelect>
export const load = (input: string, network: string): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<any> => {
if (input.length < 1) return;
if (input.length < 1) input = '0x';
const tokens = getState().localStorage.tokens[network];
const value = input.toLowerCase();

@ -8,13 +8,12 @@ import * as TOKEN from 'actions/constants/token';
import * as CONNECT from 'actions/constants/TrezorConnect';
import * as NOTIFICATION from 'actions/constants/notification';
import * as WALLET from 'actions/constants/wallet';
import { getDuplicateInstanceNumber } from 'reducers/utils';
import { push } from 'react-router-redux';
import { resolveAfter } from 'utils/promiseUtils';
import type {
Device,
DeviceMessage,
UiMessage,
TransportMessage,
@ -29,6 +28,7 @@ import type {
Action,
ThunkAction,
AsyncAction,
Device,
TrezorDevice,
RouterLocationState,
} from 'flowtype';
@ -112,8 +112,9 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
});
// $FlowIssue LOCAL not declared
window.__TREZOR_CONNECT_SRC = typeof LOCAL === 'string' ? LOCAL : 'https://sisyfos.trezor.io/connect/';
// window.__TREZOR_CONNECT_SRC = typeof LOCAL === 'string' ? LOCAL : 'https://connect.trezor.io/5/';
window.__TREZOR_CONNECT_SRC = 'https://sisyfos.trezor.io/connect/';
//window.__TREZOR_CONNECT_SRC = 'https://sisyfos.trezor.io/connect/';
// window.__TREZOR_CONNECT_SRC = 'https://localhost:8088/';
try {
@ -401,9 +402,16 @@ export const forget = (device: TrezorDevice): Action => ({
});
export const duplicateDevice = (device: TrezorDevice): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
// dispatch({
// type: CONNECT.TRY_TO_DUPLICATE,
// device,
// });
const instance: number = getDuplicateInstanceNumber(getState().devices, device);
const extended: Object = { instance };
dispatch({
type: CONNECT.TRY_TO_DUPLICATE,
device,
type: CONNECT.DUPLICATE,
device: { ...device, ...extended },
});
};

@ -6,7 +6,6 @@ import * as WALLET from 'actions/constants/wallet';
import * as CONNECT from 'actions/constants/TrezorConnect';
import * as stateUtils from 'reducers/utils';
import type { Device } from 'trezor-connect';
import type
{
Account,
@ -14,6 +13,7 @@ import type
Discovery,
Token,
Web3Instance,
Device,
TrezorDevice,
RouterLocationState,
ThunkAction,

@ -0,0 +1,114 @@
/* @flow */
import React, { Component } from 'react';
import TrezorConnect from 'trezor-connect';
import type { State, TrezorDevice } from '~/flowtype';
type Props = {
transport: $PropertyType<$ElementType<State, 'connect'>, 'transport'>;
disconnectRequest: ?TrezorDevice;
}
const DisconnectDevice = (props: Props) => {
if (!props.disconnectRequest) return null;
return (
<main>
<h2 className="claim">The private bank in your hands.</h2>
<p>TREZOR Wallet is an easy-to-use interface for your TREZOR.</p>
<p>TREZOR Wallet allows you to easily control your funds, manage your balance and initiate transfers.</p>
<div className="row">
<p className="connect">
<span>
Unplug { props.disconnectRequest.label } device.
</span>
</p>
</div>
<div className="image" />
</main>
);
};
const ConnectHIDDevice = (props: Props) => (
<main>
<h2 className="claim">The private bank in your hands.</h2>
<p>TREZOR Wallet is an easy-to-use interface for your TREZOR.</p>
<p>TREZOR Wallet allows you to easily control your funds, manage your balance and initiate transfers.</p>
<div className="row">
<p className="connect">
<span>
<svg width="12px" height="35px" viewBox="0 0 20 57">
<g stroke="none" strokeWidth="1" fill="none" transform="translate(1, 1)">
<rect className="connect-usb-pin" fill="#01B757" x="6" y="39" width="6" height="5" />
<rect className="connect-usb-cable" stroke="#01B757" strokeWidth="1" x="8.5" y="44.5" width="1" height="11" />
<path stroke="#01B757" d="M8.90856859,33.9811778 L6.43814432,33.9811778 C5.45301486,34.0503113 4.69477081,33.6889084 4.1634122,32.8969691 C3.36637428,31.7090602 -0.000402169348,26.3761977 0.0748097911,23.2982514 C0.124878873,21.2492429 0.0999525141,14.5598149 3.07156595e-05,3.22996744 C-0.000274213164,3.1963928 0.00243636275,3.162859 0.00812115776,3.12976773 C0.28477346,1.51937083 1.22672004,0.617538852 2.8339609,0.424271782 C4.45813658,0.228968338 6.54411954,0.0875444105 9.09190977,0 L9.09190977,0.0169167084 C11.5566027,0.104886477 13.5814718,0.244169993 15.1665175,0.434768145 C16.7530267,0.625542287 17.6912941,1.50671985 17.9813196,3.07830083 C17.9943481,3.14889902 18.0005888,3.22058224 17.9999563,3.29236974 L17.9999901,3.29237004 C17.9004498,14.5907444 17.875676,21.2628703 17.9256686,23.3087478 C18.0008805,26.3866941 14.6341041,31.7195566 13.8370662,32.9074655 C13.3057075,33.6994047 12.5474635,34.0608076 11.562334,33.9916742 L8.90856859,33.9916742 L8.90856859,33.9811778 Z" />
<rect fill="#01B757" x="2" y="7" width="14" height="7" rx="0.5625" />
</g>
</svg>
Connect TREZOR to continue
</span>
</p>
</div>
<div className="image">
<p>
<span>Don't have TREZOR? <a href="https://trezor.io/" className="green" target="_blank" rel="noreferrer noopener">Get one</a></span>
</p>
</div>
</main>
);
class ConnectWebUsbDevice extends Component<Props> {
componentDidMount(): void {
TrezorConnect.renderWebUSBButton();
}
componentDidUpdate() {
TrezorConnect.renderWebUSBButton();
}
render() {
return (
<main>
<h2 className="claim">The private bank in your hands.</h2>
<p>TREZOR Wallet is an easy-to-use interface for your TREZOR.</p>
<p>TREZOR Wallet allows you to easily control your funds, manage your balance and initiate transfers.</p>
<div className="row webusb">
<p className="connect">
<span>
<svg width="12px" height="35px" viewBox="0 0 20 57">
<g stroke="none" strokeWidth="1" fill="none" transform="translate(1, 1)">
<rect className="connect-usb-pin" fill="#01B757" x="6" y="39" width="6" height="5" />
<rect className="connect-usb-cable" stroke="#01B757" strokeWidth="1" x="8.5" y="44.5" width="1" height="11" />
<path stroke="#01B757" d="M8.90856859,33.9811778 L6.43814432,33.9811778 C5.45301486,34.0503113 4.69477081,33.6889084 4.1634122,32.8969691 C3.36637428,31.7090602 -0.000402169348,26.3761977 0.0748097911,23.2982514 C0.124878873,21.2492429 0.0999525141,14.5598149 3.07156595e-05,3.22996744 C-0.000274213164,3.1963928 0.00243636275,3.162859 0.00812115776,3.12976773 C0.28477346,1.51937083 1.22672004,0.617538852 2.8339609,0.424271782 C4.45813658,0.228968338 6.54411954,0.0875444105 9.09190977,0 L9.09190977,0.0169167084 C11.5566027,0.104886477 13.5814718,0.244169993 15.1665175,0.434768145 C16.7530267,0.625542287 17.6912941,1.50671985 17.9813196,3.07830083 C17.9943481,3.14889902 18.0005888,3.22058224 17.9999563,3.29236974 L17.9999901,3.29237004 C17.9004498,14.5907444 17.875676,21.2628703 17.9256686,23.3087478 C18.0008805,26.3866941 14.6341041,31.7195566 13.8370662,32.9074655 C13.3057075,33.6994047 12.5474635,34.0608076 11.562334,33.9916742 L8.90856859,33.9916742 L8.90856859,33.9811778 Z" />
<rect fill="#01B757" x="2" y="7" width="14" height="7" rx="0.5625" />
</g>
</svg>
Connect TREZOR
</span>
</p>
<p className="webusb-and">and</p>
<button className="trezor-webusb-button">Check for devices</button>
</div>
<div className="image">
<p>
<span>Device not recognized? <a href="#/bridge" className="green">Try installing the TREZOR Bridge.</a></span>
<span>Don't have TREZOR? <a href="https://trezor.io/" className="green" target="_blank" rel="noreferrer noopener">Get one</a></span>
</p>
</div>
</main>
);
}
}
const ConnectDevice = (props: Props) => {
const { transport, disconnectRequest } = props;
if (disconnectRequest) {
return <DisconnectDevice {...props} />;
} if (transport && transport.version.indexOf('webusb') >= 0) {
return <ConnectWebUsbDevice {...props} />;
}
return <ConnectHIDDevice {...props} />;
};
export default ConnectDevice;

@ -2,7 +2,7 @@
import React, { Component } from 'react';
import { getNewInstance } from 'reducers/DevicesReducer';
import { getDuplicateInstanceNumber } from 'reducers/utils';
import type { Props } from './index';
type State = {
@ -25,7 +25,7 @@ export default class DuplicateDevice extends Component<Props, State> {
const device = props.modal.opened ? props.modal.device : null;
if (!device) return;
const instance = getNewInstance(props.devices, device);
const instance = getDuplicateInstanceNumber(props.devices, device);
this.state = {
defaultName: `${device.label} (${instance.toString()})`,

@ -39,7 +39,7 @@ export default class PinModal extends Component<Props, State> {
let singleInput = false;
if (selected && selected.path === device.path) {
deviceLabel = selected.instanceLabel;
singleInput = selected.remember;
singleInput = selected.remember || selected.state !== null;
}
this.state = {

@ -1,10 +1,11 @@
/* @flow */
import { TRANSPORT, DEVICE } from 'trezor-connect';
import { DEVICE } from 'trezor-connect';
import type { Device } from 'trezor-connect';
import * as CONNECT from 'actions/constants/TrezorConnect';
import * as WALLET from 'actions/constants/wallet';
import { getDuplicateInstanceNumber } from 'reducers/utils';
import type { Action, TrezorDevice } from 'flowtype';
@ -121,7 +122,7 @@ const addDevice = (state: State, device: Device): State => {
// edge case: freshly connected device has different "passphrase_protection" than saved instances
// need to automatically create another instance with default instance name
// if (hasDifferentPassphraseSettings && !hasInstancesWithPassphraseSettings) {
// const instance = getNewInstance(affectedDevices, device);
// const instance = getDuplicateInstanceNumber(affectedDevices, device);
// newDevice.instance = instance;
// newDevice.instanceLabel = `${device.label} (${instance})`;
@ -149,7 +150,7 @@ const duplicate = (state: State, device: TrezorDevice): State => {
const newState: State = [...state];
const instance: number = getNewInstance(state, device);
const instance: number = getDuplicateInstanceNumber(state, device);
const newDevice: TrezorDevice = {
...device,
@ -295,20 +296,4 @@ export default function devices(state: State = initialState, action: Action): St
default:
return state;
}
}
// UTILS
export const getNewInstance = (devices: State, device: Device | TrezorDevice): number => {
const affectedDevices: State = devices.filter(d => d.features && device.features && d.features.device_id === device.features.device_id)
.sort((a, b) => {
if (!a.instance) {
return -1;
}
return !b.instance || a.instance > b.instance ? 1 : -1;
});
const instance: number = affectedDevices.reduce((inst, dev) => (dev.instance ? dev.instance + 1 : inst + 1), 0);
return instance;
};
}

@ -2,11 +2,10 @@
import { TRANSPORT, DEVICE, UI } from 'trezor-connect';
import type { Device } from 'trezor-connect';
import * as CONNECT from 'actions/constants/TrezorConnect';
import * as WALLET from 'actions/constants/wallet';
import type { Action, TrezorDevice } from 'flowtype';
import type { Action } from 'flowtype';
export type SelectedDevice = {
id: string; // could be device path if unacquired or features.device_id

@ -15,6 +15,7 @@ import type {
Action,
AsyncAction,
GetState,
Device,
TrezorDevice,
Account,
Coin,
@ -53,6 +54,23 @@ export const findDevice = (devices: Array<TrezorDevice>, deviceId: string, devic
return false;
});
// get next instance number
export const getDuplicateInstanceNumber = (devices: Array<TrezorDevice>, device: Device | TrezorDevice): number => {
// find device(s) with the same features.device_id
// and sort them by instance number
const affectedDevices: Array<TrezorDevice> = devices.filter(d => d.features && device.features && d.features.device_id === device.features.device_id)
.sort((a, b) => {
if (!a.instance) {
return -1;
}
return !b.instance || a.instance > b.instance ? 1 : -1;
});
// calculate new instance number
const instance: number = affectedDevices.reduce((inst, dev) => (dev.instance ? dev.instance + 1 : inst + 1), 0);
return instance;
};
export const getSelectedAccount = (state: State): ?Account => {
const device = state.wallet.selectedDevice;
const locationState = state.router.location.state;

@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { H2 } from 'components/Heading';
const DisconnectDevice = ({ instanceLabel }) => (
const DisconnectDevice = ({ label }) => (
<main>
<H2 claim>The private bank in your hands.</H2>
<p>TREZOR Wallet is an easy-to-use interface for your TREZOR.</p>
@ -10,7 +10,7 @@ const DisconnectDevice = ({ instanceLabel }) => (
<div className="row">
<p className="connect">
<span>
Unplug { instanceLabel } device.
Unplug { label } device.
</span>
</p>
</div>
@ -19,7 +19,7 @@ const DisconnectDevice = ({ instanceLabel }) => (
);
DisconnectDevice.propTypes = {
instanceLabel: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
};
export default DisconnectDevice;

@ -18,7 +18,7 @@ type Props = {
const ConnectDevice = (props: Props) => {
const { transport, disconnectRequest } = props;
if (disconnectRequest) {
return <DisconnectDevice instanceLabel={props.disconnectRequest.instanceLabel} />;
return <DisconnectDevice label={props.disconnectRequest.label} />;
} if (transport && transport.version.indexOf('webusb') >= 0) {
return <ConnectWebUsbDevice {...props} />;
}

@ -152,7 +152,7 @@ export class DeviceDropdown extends Component<Props> {
deviceMenuItems.push({ type: 'settings', label: 'Device settings' });
if (selected.features.passphrase_protection && selected.connected && selected.available) {
deviceMenuItems.push({ type: 'clone', label: 'Clone device' });
deviceMenuItems.push({ type: 'clone', label: 'Create hidden wallet' });
}
//if (selected.remember) {
deviceMenuItems.push({ type: 'forget', label: 'Forget device' });
@ -169,7 +169,11 @@ export class DeviceDropdown extends Component<Props> {
);
}
const deviceList = devices.map((dev, index) => {
const sortByInstance = (a: TrezorDevice, b: TrezorDevice) => {
if (!a.instance || !b.instance) return -1;
return a.instance > b.instance ? 1 : -1;
}
const deviceList = devices.sort(sortByInstance).map((dev, index) => {
if (dev === selected) return null;
let deviceStatus: string = 'Connected';

@ -18,14 +18,14 @@ type Props = {
const SummaryTokens = (props: Props) => {
if (!props.tokens || props.tokens.length < 1) return null;
const bgColor = new ColorHash({ lightness: 0.7 });
const bgColor = new ColorHash({ lightness: 0.16 } );
const textColor = new ColorHash();
const tokens = props.tokens.map((token, index) => {
const iconColor = {
color: textColor.hex(token.name),
background: bgColor.hex(token.name),
borderColor: bgColor.hex(token.name),
color: textColor.hex(token.address),
background: bgColor.hex(token.address),
borderColor: bgColor.hex(token.address),
};
const pendingAmount: BigNumber = stateUtils.getPendingAmount(props.pending, token.symbol, true);

@ -75,7 +75,7 @@ const Summary = (props: Props) => {
<AsyncSelect
className="token-select"
multi={false}
autoload={false}
autoload={true}
ignoreCase
backspaceRemoves
value={null}

@ -9493,11 +9493,10 @@ tr46@^1.0.1:
dependencies:
punycode "^2.1.0"
trezor-connect@^5.0.28:
version "5.0.28"
resolved "https://registry.yarnpkg.com/trezor-connect/-/trezor-connect-5.0.28.tgz#eb39bb0aa2a7555623251f0fb301233886fcdd09"
trezor-connect@5.0.30:
version "5.0.30"
resolved "https://registry.yarnpkg.com/trezor-connect/-/trezor-connect-5.0.30.tgz#3a71613a6d6e63532c7880c1dc25abca18f0b0e7"
dependencies:
babel-polyfill "^6.26.0"
babel-runtime "^6.26.0"
events "^1.1.1"
whatwg-fetch "^2.0.4"

Loading…
Cancel
Save