1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-28 03:08:30 +00:00

InstallBridge page with data from trezor-connect

This commit is contained in:
Szymon Lesisz 2018-10-04 17:08:02 +02:00
parent d5bf7e1ee9
commit d8f133ad84
4 changed files with 66 additions and 42 deletions

View File

@ -1,8 +0,0 @@
export default [
{ id: 'Windows', value: 'trezor-bridge-2.0.11-win32-install.exe', label: 'Windows' },
{ id: 'macOS', value: 'trezor-bridge-2.0.11.pkg', label: 'macOS' },
{ id: 'Linux', value: 'trezor-bridge_2.0.11_amd64.deb', label: 'Linux 64-bit (deb)' },
{ id: 'Linux-rpm', value: 'trezor-bridge_2.0.11_amd64.rpm', label: 'Linux 64-bit (rpm)' },
{ id: '01', value: 'trezor-bridge_2.0.11_amd32.deb', label: 'Linux 32-bit (deb)' },
{ id: '02', value: 'trezor-bridge_2.0.11_amd32.rpm', label: 'Linux 32-bit (rpm)' },
];

View File

@ -9,12 +9,24 @@ export type SelectedDevice = {
instance: ?number; instance: ?number;
} }
export type LatestBridge = {
version: Array<number>;
directory: string;
packages: Array<{ name: string; url: string; signature?: string; preferred: boolean; }>;
changelog: string;
}
export type State = { export type State = {
initialized: boolean; initialized: boolean;
error: ?string; error: ?string;
transport: ?{ transport: {
type: string; type: string;
version: string; version: string;
outdated: boolean;
bridge: LatestBridge;
} | {
type: null,
bridge: LatestBridge;
}; };
// browserState: { // browserState: {
// name: string; // name: string;
@ -30,7 +42,15 @@ export type State = {
const initialState: State = { const initialState: State = {
initialized: false, initialized: false,
error: null, error: null,
transport: null, transport: {
type: null,
bridge: {
version: [],
directory: '',
packages: [],
changelog: '',
},
},
browserState: {}, browserState: {},
acquiringDevice: false, acquiringDevice: false,
}; };
@ -63,9 +83,12 @@ export default function connect(state: State = initialState, action: Action): St
case TRANSPORT.ERROR: case TRANSPORT.ERROR:
return { return {
...state, ...state,
// error: action.payload, // message is wrapped in "device" field. It's dispatched from TrezorConnect.on(DEVICE_EVENT...) in TrezorConnectService // error: action.payload.error, // message is wrapped in "device" field. It's dispatched from TrezorConnect.on(DEVICE_EVENT...) in TrezorConnectService
error: 'Transport is missing', error: 'Transport is missing',
transport: null, transport: {
type: null,
bridge: action.payload.bridge,
},
}; };
case CONNECT.START_ACQUIRING: case CONNECT.START_ACQUIRING:

View File

@ -4,7 +4,6 @@ import React, { Component } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import colors from 'config/colors'; import colors from 'config/colors';
import { FONT_SIZE, FONT_WEIGHT } from 'config/variables'; import { FONT_SIZE, FONT_WEIGHT } from 'config/variables';
import installers from 'constants/bridge';
import { Select } from 'components/Select'; import { Select } from 'components/Select';
import Link from 'components/Link'; import Link from 'components/Link';
import Button from 'components/Button'; import Button from 'components/Button';
@ -13,24 +12,28 @@ import P from 'components/Paragraph';
import Icon from 'components/Icon'; import Icon from 'components/Icon';
import ICONS from 'config/icons'; import ICONS from 'config/icons';
import type { State as TrezorConnectState } from 'reducers/TrezorConnectReducer';
type InstallTarget = { type InstallTarget = {
id: string;
value: string; value: string;
label: string; label: string;
signature: ?string;
preferred: boolean;
} }
// { id: 'Windows', value: 'trezor-bridge-2.0.11-win32-install.exe', label: 'Windows' },
type State = { type State = {
version: string; currentVersion: string;
target: ?InstallTarget; latestVersion: string;
url: string; installers: Array<InstallTarget>;
target: InstallTarget;
uri: string;
} }
// import type { Props } from './index'; // import type { Props } from './index';
type Props = { type Props = {
browserState: { transport: $ElementType<TrezorConnectState, 'transport'>;
osname: string,
};
} }
const InstallBridgeWrapper = styled.div` const InstallBridgeWrapper = styled.div`
@ -85,21 +88,21 @@ export default class InstallBridge extends Component<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
const currentTarget: ?InstallTarget = installers.find(i => i.id === props.browserState.osname); const installers = props.transport.bridge.packages.map(p => ({
this.state = { label: p.name,
version: '2.0.12', value: p.url,
url: 'https://wallet.trezor.io/data/bridge/2.0.12/', signature: p.signature,
target: currentTarget, preferred: p.preferred,
}; }));
}
componentWillUpdate() { const currentTarget: ?InstallTarget = installers.find(i => i.preferred === true);
if (this.props.browserState.osname && !this.state.target) { this.state = {
const currentTarget: ?InstallTarget = installers.find(i => i.id === this.props.browserState.osname); currentVersion: props.transport.type ? `Your version ${props.transport.version}` : 'Not installed',
this.setState({ latestVersion: props.transport.bridge.version.join('.'),
target: currentTarget, installers,
}); target: currentTarget || installers[0],
} uri: 'https://wallet.trezor.io/data/',
};
} }
onChange(value: InstallTarget) { onChange(value: InstallTarget) {
@ -112,20 +115,18 @@ export default class InstallBridge extends Component<Props, State> {
if (!this.state.target) { if (!this.state.target) {
return <Loader text="Loading" size={100} />; return <Loader text="Loading" size={100} />;
} }
const { label } = this.state.target; const url = `${this.state.uri}${this.state.target.value}`;
const url = `${this.state.url}${this.state.target.value}`;
return ( return (
<InstallBridgeWrapper> <InstallBridgeWrapper>
<TitleHeader>TREZOR Bridge.<BridgeVersion>Version {this.state.version}</BridgeVersion></TitleHeader> <TitleHeader>TREZOR Bridge.<BridgeVersion>{this.state.currentVersion}</BridgeVersion></TitleHeader>
<P>New communication tool to facilitate the connection between your TREZOR and your internet browser.</P> <P>New communication tool to facilitate the connection between your TREZOR and your internet browser.</P>
<DownloadBridgeWrapper> <DownloadBridgeWrapper>
<SelectWrapper <SelectWrapper
isSearchable={false} isSearchable={false}
isClearable={false} isClearable={false}
value={this.state.target} value={this.state.target}
onChange={val => this.onChange(val)} onChange={v => this.onChange(v)}
options={installers} options={this.state.installers}
/> />
<Link href={url}> <Link href={url}>
<DownloadBridgeButton> <DownloadBridgeButton>
@ -134,7 +135,7 @@ export default class InstallBridge extends Component<Props, State> {
color={colors.WHITE} color={colors.WHITE}
size={30} size={30}
/> />
Download for {label} Download latest Bridge {this.state.latestVersion}
</DownloadBridgeButton> </DownloadBridgeButton>
</Link> </Link>
</DownloadBridgeWrapper> </DownloadBridgeWrapper>
@ -148,6 +149,14 @@ export default class InstallBridge extends Component<Props, State> {
>Changelog >Changelog
</Link> </Link>
</P> </P>
<P>
No, i dont want to upgrade Bridge now,
</P>
<P>
Take me <Link href="#/">back to the wallet</Link>
</P>
</InstallBridgeWrapper> </InstallBridgeWrapper>
); );
} }

View File

@ -103,7 +103,7 @@ export default (props: Props) => {
<Log /> <Log />
<LandingContent> <LandingContent>
{shouldShowUnsupportedBrowser && <BrowserNotSupported />} {shouldShowUnsupportedBrowser && <BrowserNotSupported />}
{shouldShowInstallBridge && <InstallBridge browserState={browserState} />} {shouldShowInstallBridge && <InstallBridge transport={transport} />}
{(shouldShowConnectDevice || shouldShowDisconnectDevice) && ( {(shouldShowConnectDevice || shouldShowDisconnectDevice) && (
<div> <div>