mirror of https://github.com/trezor/trezor-wallet
commit
33cce4bcae
@ -0,0 +1,153 @@
|
|||||||
|
/* @flow */
|
||||||
|
|
||||||
|
import * as ACCOUNT from 'actions/constants/account';
|
||||||
|
import * as IMPORT from 'actions/constants/importAccount';
|
||||||
|
import * as NOTIFICATION from 'actions/constants/notification';
|
||||||
|
import type { AsyncAction, TrezorDevice, Network, Dispatch, GetState } from 'flowtype';
|
||||||
|
import * as BlockchainActions from 'actions/ethereum/BlockchainActions';
|
||||||
|
import * as LocalStorageActions from 'actions/LocalStorageActions';
|
||||||
|
import TrezorConnect from 'trezor-connect';
|
||||||
|
import { toDecimalAmount } from 'utils/formatUtils';
|
||||||
|
|
||||||
|
export type ImportAccountAction =
|
||||||
|
| {
|
||||||
|
type: typeof IMPORT.START,
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: typeof IMPORT.SUCCESS,
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: typeof IMPORT.FAIL,
|
||||||
|
error: ?string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const importAddress = (
|
||||||
|
address: string,
|
||||||
|
network: Network,
|
||||||
|
device: ?TrezorDevice
|
||||||
|
): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||||
|
if (!device) return;
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: IMPORT.START,
|
||||||
|
});
|
||||||
|
|
||||||
|
let payload;
|
||||||
|
const index = getState().accounts.filter(
|
||||||
|
a =>
|
||||||
|
a.imported === true &&
|
||||||
|
a.network === network.shortcut &&
|
||||||
|
device &&
|
||||||
|
a.deviceState === device.state
|
||||||
|
).length;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (network.type === 'ethereum') {
|
||||||
|
const account = await dispatch(
|
||||||
|
BlockchainActions.discoverAccount(device, address, network.shortcut)
|
||||||
|
);
|
||||||
|
|
||||||
|
const empty = account.nonce <= 0 && account.balance === '0';
|
||||||
|
payload = {
|
||||||
|
imported: true,
|
||||||
|
index,
|
||||||
|
network: network.shortcut,
|
||||||
|
deviceID: device.features ? device.features.device_id : '0',
|
||||||
|
deviceState: device.state || '0',
|
||||||
|
accountPath: account.path || [],
|
||||||
|
descriptor: account.descriptor,
|
||||||
|
|
||||||
|
balance: account.balance,
|
||||||
|
availableBalance: account.balance,
|
||||||
|
block: account.block,
|
||||||
|
transactions: account.transactions,
|
||||||
|
empty,
|
||||||
|
|
||||||
|
networkType: 'ethereum',
|
||||||
|
nonce: account.nonce,
|
||||||
|
};
|
||||||
|
dispatch({
|
||||||
|
type: ACCOUNT.CREATE,
|
||||||
|
payload,
|
||||||
|
});
|
||||||
|
dispatch({
|
||||||
|
type: IMPORT.SUCCESS,
|
||||||
|
});
|
||||||
|
dispatch(LocalStorageActions.setImportedAccount(payload));
|
||||||
|
dispatch({
|
||||||
|
type: NOTIFICATION.ADD,
|
||||||
|
payload: {
|
||||||
|
type: 'success',
|
||||||
|
title: 'The account has been successfully imported',
|
||||||
|
cancelable: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else if (network.type === 'ripple') {
|
||||||
|
const response = await TrezorConnect.rippleGetAccountInfo({
|
||||||
|
account: {
|
||||||
|
descriptor: address,
|
||||||
|
},
|
||||||
|
coin: network.shortcut,
|
||||||
|
});
|
||||||
|
|
||||||
|
// handle TREZOR response error
|
||||||
|
if (!response.success) {
|
||||||
|
throw new Error(response.payload.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
const account = response.payload;
|
||||||
|
const empty = account.sequence <= 0 && account.balance === '0';
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
imported: true,
|
||||||
|
index,
|
||||||
|
network: network.shortcut,
|
||||||
|
deviceID: device.features ? device.features.device_id : '0',
|
||||||
|
deviceState: device.state || '0',
|
||||||
|
accountPath: account.path || [],
|
||||||
|
descriptor: account.descriptor,
|
||||||
|
|
||||||
|
balance: toDecimalAmount(account.balance, network.decimals),
|
||||||
|
availableBalance: toDecimalAmount(account.availableBalance, network.decimals),
|
||||||
|
block: account.block,
|
||||||
|
transactions: account.transactions,
|
||||||
|
empty,
|
||||||
|
|
||||||
|
networkType: 'ripple',
|
||||||
|
sequence: account.sequence,
|
||||||
|
reserve: toDecimalAmount(account.reserve, network.decimals),
|
||||||
|
};
|
||||||
|
dispatch({
|
||||||
|
type: ACCOUNT.CREATE,
|
||||||
|
payload,
|
||||||
|
});
|
||||||
|
dispatch({
|
||||||
|
type: IMPORT.SUCCESS,
|
||||||
|
});
|
||||||
|
dispatch(LocalStorageActions.setImportedAccount(payload));
|
||||||
|
dispatch({
|
||||||
|
type: NOTIFICATION.ADD,
|
||||||
|
payload: {
|
||||||
|
type: 'success',
|
||||||
|
title: 'The account has been successfully imported',
|
||||||
|
cancelable: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
dispatch({
|
||||||
|
type: IMPORT.FAIL,
|
||||||
|
error: error.message,
|
||||||
|
});
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: NOTIFICATION.ADD,
|
||||||
|
payload: {
|
||||||
|
type: 'error',
|
||||||
|
title: 'Import account error',
|
||||||
|
message: error.message,
|
||||||
|
cancelable: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,5 @@
|
|||||||
|
/* @flow */
|
||||||
|
|
||||||
|
export const START: 'import__account__start' = 'import__account__start';
|
||||||
|
export const SUCCESS: 'import__account__success' = 'import__account__success';
|
||||||
|
export const FAIL: 'import__account__fail' = 'import__account__fail';
|
@ -1,41 +1,33 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { withRouter } from 'react-router-dom';
|
|
||||||
|
|
||||||
import * as WalletActions from 'actions/WalletActions';
|
import * as WalletActions from 'actions/WalletActions';
|
||||||
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
|
||||||
import type { State, Dispatch } from 'flowtype';
|
import type { State, Dispatch } from 'flowtype';
|
||||||
|
|
||||||
import LanguagePicker from './index';
|
import LanguagePicker from './index';
|
||||||
|
|
||||||
type StateProps = {
|
type StateProps = {|
|
||||||
language: string,
|
language: string,
|
||||||
};
|
|};
|
||||||
|
|
||||||
type DispatchProps = {
|
type DispatchProps = {|
|
||||||
fetchLocale: typeof WalletActions.fetchLocale,
|
fetchLocale: typeof WalletActions.fetchLocale,
|
||||||
};
|
|};
|
||||||
|
|
||||||
type OwnProps = {};
|
type OwnProps = {||};
|
||||||
|
|
||||||
export type Props = StateProps & DispatchProps;
|
export type Props = {| ...StateProps, ...DispatchProps, ...OwnProps |};
|
||||||
|
|
||||||
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (
|
const mapStateToProps = (state: State): StateProps => ({
|
||||||
state: State
|
|
||||||
): StateProps => ({
|
|
||||||
language: state.wallet.language,
|
language: state.wallet.language,
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (
|
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
|
||||||
dispatch: Dispatch
|
|
||||||
): DispatchProps => ({
|
|
||||||
fetchLocale: bindActionCreators(WalletActions.fetchLocale, dispatch),
|
fetchLocale: bindActionCreators(WalletActions.fetchLocale, dispatch),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default withRouter(
|
export default connect<Props, OwnProps, StateProps, DispatchProps, State, Dispatch>(
|
||||||
connect(
|
mapStateToProps,
|
||||||
mapStateToProps,
|
mapDispatchToProps
|
||||||
mapDispatchToProps
|
)(LanguagePicker);
|
||||||
)(LanguagePicker)
|
|
||||||
);
|
|
||||||
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 8.1 KiB |
@ -0,0 +1,259 @@
|
|||||||
|
/**
|
||||||
|
* Original implementation of this file by @marudor at https://github.com/marudor/flowInterfaces
|
||||||
|
* Copied here based on intention to merge with flow-typed expressed here:
|
||||||
|
* https://github.com/marudor/flowInterfaces/issues/6
|
||||||
|
*/
|
||||||
|
// Mostly from https://github.com/yahoo/react-intl/wiki/API#react-intl-api
|
||||||
|
declare module "react-intl" {
|
||||||
|
import type { Element, ChildrenArray } from "react";
|
||||||
|
|
||||||
|
declare type $npm$ReactIntl$LocaleData = {
|
||||||
|
locale: string,
|
||||||
|
[key: string]: any
|
||||||
|
};
|
||||||
|
|
||||||
|
declare type $npm$ReactIntl$MessageDescriptor = {
|
||||||
|
id: string,
|
||||||
|
description?: string,
|
||||||
|
defaultMessage?: string
|
||||||
|
};
|
||||||
|
|
||||||
|
declare type $npm$ReactIntl$IntlConfig = {
|
||||||
|
locale: string,
|
||||||
|
formats: Object,
|
||||||
|
messages: { [id: string]: string },
|
||||||
|
|
||||||
|
defaultLocale?: string,
|
||||||
|
defaultFormats?: Object
|
||||||
|
};
|
||||||
|
|
||||||
|
declare type $npm$ReactIntl$IntlProviderConfig = {
|
||||||
|
locale?: string,
|
||||||
|
formats?: Object,
|
||||||
|
messages?: { [id: string]: string },
|
||||||
|
|
||||||
|
defaultLocale?: string,
|
||||||
|
defaultFormats?: Object
|
||||||
|
};
|
||||||
|
|
||||||
|
declare type $npm$ReactIntl$IntlFormat = {
|
||||||
|
formatDate: (value: any, options?: Object) => string,
|
||||||
|
formatTime: (value: any, options?: Object) => string,
|
||||||
|
formatRelative: (value: any, options?: Object) => string,
|
||||||
|
formatNumber: (value: any, options?: Object) => string,
|
||||||
|
formatPlural: (value: any, options?: Object) => string,
|
||||||
|
formatMessage: (
|
||||||
|
messageDescriptor: $npm$ReactIntl$MessageDescriptor,
|
||||||
|
values?: Object
|
||||||
|
) => string,
|
||||||
|
formatHTMLMessage: (
|
||||||
|
messageDescriptor: $npm$ReactIntl$MessageDescriptor,
|
||||||
|
values?: Object
|
||||||
|
) => string
|
||||||
|
};
|
||||||
|
|
||||||
|
declare type $npm$ReactIntl$IntlShape = $npm$ReactIntl$IntlConfig &
|
||||||
|
$npm$ReactIntl$IntlFormat & { now: () => number };
|
||||||
|
|
||||||
|
declare type $npm$ReactIntl$DateTimeFormatOptions = {
|
||||||
|
localeMatcher?: "best fit" | "lookup",
|
||||||
|
formatMatcher?: "basic" | "best fit",
|
||||||
|
|
||||||
|
timeZone?: string,
|
||||||
|
hour12?: boolean,
|
||||||
|
|
||||||
|
weekday?: "narrow" | "short" | "long",
|
||||||
|
era?: "narrow" | "short" | "long",
|
||||||
|
year?: "numeric" | "2-digit",
|
||||||
|
month?: "numeric" | "2-digit" | "narrow" | "short" | "long",
|
||||||
|
day?: "numeric" | "2-digit",
|
||||||
|
hour?: "numeric" | "2-digit",
|
||||||
|
minute?: "numeric" | "2-digit",
|
||||||
|
second?: "numeric" | "2-digit",
|
||||||
|
timeZoneName?: "short" | "long"
|
||||||
|
};
|
||||||
|
|
||||||
|
declare type $npm$ReactIntl$RelativeFormatOptions = {
|
||||||
|
style?: "best fit" | "numeric",
|
||||||
|
units?: "second" | "minute" | "hour" | "day" | "month" | "year"
|
||||||
|
};
|
||||||
|
|
||||||
|
declare type $npm$ReactIntl$NumberFormatOptions = {
|
||||||
|
localeMatcher?: "best fit" | "lookup",
|
||||||
|
|
||||||
|
style?: "decimal" | "currency" | "percent",
|
||||||
|
|
||||||
|
currency?: string,
|
||||||
|
currencyDisplay?: "symbol" | "code" | "name",
|
||||||
|
|
||||||
|
useGrouping?: boolean,
|
||||||
|
|
||||||
|
minimumIntegerDigits?: number,
|
||||||
|
minimumFractionDigits?: number,
|
||||||
|
maximumFractionDigits?: number,
|
||||||
|
minimumSignificantDigits?: number,
|
||||||
|
maximumSignificantDigits?: number
|
||||||
|
};
|
||||||
|
|
||||||
|
declare type $npm$ReactIntl$PluralFormatOptions = {
|
||||||
|
style?: "cardinal" | "ordinal"
|
||||||
|
};
|
||||||
|
|
||||||
|
declare type $npm$ReactIntl$PluralCategoryString =
|
||||||
|
| "zero"
|
||||||
|
| "one"
|
||||||
|
| "two"
|
||||||
|
| "few"
|
||||||
|
| "many"
|
||||||
|
| "other";
|
||||||
|
|
||||||
|
declare type $npm$ReactIntl$DateParseable = number | string | Date;
|
||||||
|
// PropType checker
|
||||||
|
declare function intlShape(
|
||||||
|
props: Object,
|
||||||
|
propName: string,
|
||||||
|
componentName: string
|
||||||
|
): void;
|
||||||
|
declare function addLocaleData(
|
||||||
|
data: $npm$ReactIntl$LocaleData | Array<$npm$ReactIntl$LocaleData>
|
||||||
|
): void;
|
||||||
|
declare function defineMessages<
|
||||||
|
T: { [key: string]: $Exact<$npm$ReactIntl$MessageDescriptor> }
|
||||||
|
>(
|
||||||
|
messageDescriptors: T
|
||||||
|
): T;
|
||||||
|
|
||||||
|
declare type InjectIntlProvidedProps = {
|
||||||
|
intl: $npm$ReactIntl$IntlShape
|
||||||
|
}
|
||||||
|
|
||||||
|
declare type InjectIntlVoidProps = {
|
||||||
|
intl: $npm$ReactIntl$IntlShape | void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare type ComponentWithDefaultProps<DefaultProps: {}, Props: {}> =
|
||||||
|
| React$ComponentType<Props>
|
||||||
|
| React$StatelessFunctionalComponent<Props>
|
||||||
|
| ChildrenArray<void | null | boolean | string | number | Element<any>>;
|
||||||
|
|
||||||
|
declare type InjectIntlOptions = {
|
||||||
|
intlPropName?: string,
|
||||||
|
withRef?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
declare class IntlInjectedComponent<TOwnProps, TDefaultProps> extends React$Component<TOwnProps> {
|
||||||
|
static WrappedComponent: Class<React$Component<TOwnProps & InjectIntlProvidedProps>>,
|
||||||
|
static defaultProps: TDefaultProps,
|
||||||
|
props: TOwnProps
|
||||||
|
}
|
||||||
|
|
||||||
|
declare type IntlInjectedComponentClass<TOwnProps, TDefaultProps: {} = {}> = Class<
|
||||||
|
IntlInjectedComponent<TOwnProps, TDefaultProps>
|
||||||
|
>;
|
||||||
|
|
||||||
|
declare function injectIntl<P: {}, Component: React$ComponentType<P>>(
|
||||||
|
WrappedComponent: Component,
|
||||||
|
options?: InjectIntlOptions,
|
||||||
|
): React$ComponentType<
|
||||||
|
$Diff<React$ElementConfig<Component>, InjectIntlVoidProps>
|
||||||
|
>;
|
||||||
|
|
||||||
|
declare function formatMessage(
|
||||||
|
messageDescriptor: $npm$ReactIntl$MessageDescriptor,
|
||||||
|
values?: Object
|
||||||
|
): string;
|
||||||
|
declare function formatHTMLMessage(
|
||||||
|
messageDescriptor: $npm$ReactIntl$MessageDescriptor,
|
||||||
|
values?: Object
|
||||||
|
): string;
|
||||||
|
declare function formatDate(
|
||||||
|
value: any,
|
||||||
|
options?: $npm$ReactIntl$DateTimeFormatOptions & { format: string }
|
||||||
|
): string;
|
||||||
|
declare function formatTime(
|
||||||
|
value: any,
|
||||||
|
options?: $npm$ReactIntl$DateTimeFormatOptions & { format: string }
|
||||||
|
): string;
|
||||||
|
declare function formatRelative(
|
||||||
|
value: any,
|
||||||
|
options?: $npm$ReactIntl$RelativeFormatOptions & {
|
||||||
|
format: string,
|
||||||
|
now: any
|
||||||
|
}
|
||||||
|
): string;
|
||||||
|
declare function formatNumber(
|
||||||
|
value: any,
|
||||||
|
options?: $npm$ReactIntl$NumberFormatOptions & { format: string }
|
||||||
|
): string;
|
||||||
|
declare function formatPlural(
|
||||||
|
value: any,
|
||||||
|
options?: $npm$ReactIntl$PluralFormatOptions
|
||||||
|
): $npm$ReactIntl$PluralCategoryString;
|
||||||
|
|
||||||
|
declare class FormattedMessage extends React$Component<
|
||||||
|
$npm$ReactIntl$MessageDescriptor & {
|
||||||
|
values?: Object,
|
||||||
|
tagName?: string,
|
||||||
|
children?:
|
||||||
|
| ((...formattedMessage: Array<React$Node>) => React$Node)
|
||||||
|
| (string => React$Node)
|
||||||
|
}
|
||||||
|
> {}
|
||||||
|
declare class FormattedHTMLMessage extends React$Component<
|
||||||
|
$npm$ReactIntl$DateTimeFormatOptions & {
|
||||||
|
values?: Object,
|
||||||
|
tagName?: string,
|
||||||
|
children?: (...formattedMessage: Array<React$Node>) => React$Node
|
||||||
|
}
|
||||||
|
> {}
|
||||||
|
declare class FormattedDate extends React$Component<
|
||||||
|
$npm$ReactIntl$DateTimeFormatOptions & {
|
||||||
|
value: $npm$ReactIntl$DateParseable,
|
||||||
|
format?: string,
|
||||||
|
children?: (formattedDate: string) => React$Node
|
||||||
|
}
|
||||||
|
> {}
|
||||||
|
declare class FormattedTime extends React$Component<
|
||||||
|
$npm$ReactIntl$DateTimeFormatOptions & {
|
||||||
|
value: $npm$ReactIntl$DateParseable,
|
||||||
|
format?: string,
|
||||||
|
children?: (formattedDate: string) => React$Node
|
||||||
|
}
|
||||||
|
> {}
|
||||||
|
declare class FormattedRelative extends React$Component<
|
||||||
|
$npm$ReactIntl$RelativeFormatOptions & {
|
||||||
|
value: $npm$ReactIntl$DateParseable,
|
||||||
|
format?: string,
|
||||||
|
updateInterval?: number,
|
||||||
|
initialNow?: $npm$ReactIntl$DateParseable,
|
||||||
|
children?: (formattedDate: string) => React$Node
|
||||||
|
}
|
||||||
|
> {}
|
||||||
|
declare class FormattedNumber extends React$Component<
|
||||||
|
$npm$ReactIntl$NumberFormatOptions & {
|
||||||
|
value: number | string,
|
||||||
|
format?: string,
|
||||||
|
children?: (formattedNumber: string) => React$Node
|
||||||
|
}
|
||||||
|
> {}
|
||||||
|
declare class FormattedPlural extends React$Component<
|
||||||
|
$npm$ReactIntl$PluralFormatOptions & {
|
||||||
|
value: number | string,
|
||||||
|
other: React$Node,
|
||||||
|
zero?: React$Node,
|
||||||
|
one?: React$Node,
|
||||||
|
two?: React$Node,
|
||||||
|
few?: React$Node,
|
||||||
|
many?: React$Node,
|
||||||
|
children?: (formattedPlural: React$Node) => React$Node
|
||||||
|
}
|
||||||
|
> {}
|
||||||
|
declare class IntlProvider extends React$Component<
|
||||||
|
$npm$ReactIntl$IntlProviderConfig & {
|
||||||
|
children?: React$Node,
|
||||||
|
initialNow?: $npm$ReactIntl$DateParseable
|
||||||
|
}
|
||||||
|
> {}
|
||||||
|
declare type IntlShape = $npm$ReactIntl$IntlShape;
|
||||||
|
declare type MessageDescriptor = $npm$ReactIntl$MessageDescriptor;
|
||||||
|
}
|
@ -1,127 +1,275 @@
|
|||||||
// flow-typed signature: 59b0c4be0e1408f21e2446be96c79804
|
/**
|
||||||
// flow-typed version: 9092387fd2/react-redux_v5.x.x/flow_>=v0.54.x
|
The order of type arguments for connect() is as follows:
|
||||||
|
|
||||||
import type { Dispatch, Store } from 'redux';
|
connect<Props, OwnProps, StateProps, DispatchProps, State, Dispatch>(…)
|
||||||
|
|
||||||
declare module 'react-redux' {
|
In Flow v0.89 only the first two are mandatory to specify. Other 4 can be repaced with the new awesome type placeholder:
|
||||||
/*
|
|
||||||
|
|
||||||
S = State
|
connect<Props, OwnProps, _, _, _, _>(…)
|
||||||
A = Action
|
|
||||||
D = Dispatch
|
|
||||||
OP = OwnProps
|
|
||||||
SP = StateProps
|
|
||||||
DP = DispatchProps
|
|
||||||
|
|
||||||
*/
|
But beware, in case of weird type errors somewhere in random places
|
||||||
|
just type everything and get to a green field and only then try to
|
||||||
|
remove the definitions you see bogus.
|
||||||
|
|
||||||
declare type MapStateToProps<S, OP: Object, SP: Object> = (
|
Decrypting the abbreviations:
|
||||||
state: S,
|
WC = Component being wrapped
|
||||||
ownProps: OP
|
S = State
|
||||||
) => ((state: S, ownProps: OP) => SP) | SP;
|
D = Dispatch
|
||||||
|
OP = OwnProps
|
||||||
|
SP = StateProps
|
||||||
|
DP = DispatchProps
|
||||||
|
MP = Merge props
|
||||||
|
RSP = Returned state props
|
||||||
|
RDP = Returned dispatch props
|
||||||
|
RMP = Returned merge props
|
||||||
|
CP = Props for returned component
|
||||||
|
Com = React Component
|
||||||
|
ST = Static properties of Com
|
||||||
|
EFO = Extra factory options (used only in connectAdvanced)
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare module "react-redux" {
|
||||||
|
// ------------------------------------------------------------
|
||||||
|
// Typings for connect()
|
||||||
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
|
declare export type Options<S, OP, SP, MP> = {|
|
||||||
|
pure?: boolean,
|
||||||
|
withRef?: boolean,
|
||||||
|
areStatesEqual?: (next: S, prev: S) => boolean,
|
||||||
|
areOwnPropsEqual?: (next: OP, prev: OP) => boolean,
|
||||||
|
areStatePropsEqual?: (next: SP, prev: SP) => boolean,
|
||||||
|
areMergedPropsEqual?: (next: MP, prev: MP) => boolean,
|
||||||
|
storeKey?: string,
|
||||||
|
|};
|
||||||
|
|
||||||
declare type MapDispatchToProps<D, OP: Object, DP: Object> =
|
declare type MapStateToProps<-S, -OP, +SP> =
|
||||||
|
| ((state: S, ownProps: OP) => SP)
|
||||||
|
// If you want to use the factory function but get a strange error
|
||||||
|
// like "function is not an object" then just type the factory function
|
||||||
|
// like this:
|
||||||
|
// const factory: (State, OwnProps) => (State, OwnProps) => StateProps
|
||||||
|
// and provide the StateProps type to the SP type parameter.
|
||||||
|
| ((state: S, ownProps: OP) => (state: S, ownProps: OP) => SP);
|
||||||
|
|
||||||
|
declare type Bind<D> = <A, R>((...A) => R) => (...A) => $Call<D, R>;
|
||||||
|
|
||||||
|
declare type MapDispatchToPropsFn<D, -OP, +DP> =
|
||||||
| ((dispatch: D, ownProps: OP) => DP)
|
| ((dispatch: D, ownProps: OP) => DP)
|
||||||
| DP;
|
// If you want to use the factory function but get a strange error
|
||||||
|
// like "function is not an object" then just type the factory function
|
||||||
|
// like this:
|
||||||
|
// const factory: (Dispatch, OwnProps) => (Dispatch, OwnProps) => DispatchProps
|
||||||
|
// and provide the DispatchProps type to the DP type parameter.
|
||||||
|
| ((dispatch: D, ownProps: OP) => (dispatch: D, ownProps: OP) => DP);
|
||||||
|
|
||||||
|
declare class ConnectedComponent<OP, +WC> extends React$Component<OP> {
|
||||||
|
static +WrappedComponent: WC;
|
||||||
|
getWrappedInstance(): React$ElementRef<WC>;
|
||||||
|
}
|
||||||
|
declare type Connector<P, OP, MP: P> = <WC: React$ComponentType<P>>(
|
||||||
|
WC,
|
||||||
|
) => Class<ConnectedComponent<OP, WC>> & WC;
|
||||||
|
|
||||||
|
// No `mergeProps` argument
|
||||||
|
|
||||||
|
declare export function connect<-P, -OP, -SP, -DP, -S, -D>(
|
||||||
|
mapStateToProps?: null | void,
|
||||||
|
mapDispatchToProps?: null | void,
|
||||||
|
mergeProps?: null | void,
|
||||||
|
options?: ?Options<S, OP, {||}, {| ...OP, dispatch: D |}>,
|
||||||
|
// Got error like inexact OwnProps is incompatible with exact object type?
|
||||||
|
// Just make your OP parameter an exact object.
|
||||||
|
): Connector<P, OP, {| ...OP, dispatch: D |}>;
|
||||||
|
|
||||||
|
declare export function connect<-P, -OP, -SP, -DP, -S, -D>(
|
||||||
|
// If you get error here try adding return type to your mapStateToProps function
|
||||||
|
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||||
|
mapDispatchToProps?: null | void,
|
||||||
|
mergeProps?: null | void,
|
||||||
|
options?: ?Options<S, OP, SP, {| ...OP, ...SP |}>,
|
||||||
|
// Got error like inexact OwnProps is incompatible with exact object type?
|
||||||
|
// Just make your OP parameter an exact object.
|
||||||
|
): Connector<P, OP, {| ...OP, ...SP |}>;
|
||||||
|
|
||||||
|
// In this case DP is an object of functions which has been bound to dispatch
|
||||||
|
// by the given mapDispatchToProps function.
|
||||||
|
declare export function connect<-P, -OP, -SP, -DP, S, D>(
|
||||||
|
mapStateToProps: null | void,
|
||||||
|
mapDispatchToProps: MapDispatchToPropsFn<D, OP, DP>,
|
||||||
|
mergeProps?: null | void,
|
||||||
|
options?: ?Options<S, OP, {||}, {| ...OP, ...DP |}>,
|
||||||
|
// Got error like inexact OwnProps is incompatible with exact object type?
|
||||||
|
// Just make your OP parameter an exact object.
|
||||||
|
): Connector<P, OP, {| ...OP, ...DP |}>;
|
||||||
|
|
||||||
|
// In this case DP is an object of action creators not yet bound to dispatch,
|
||||||
|
// this difference is not important in the vanila redux,
|
||||||
|
// but in case of usage with redux-thunk, the return type may differ.
|
||||||
|
declare export function connect<-P, -OP, -SP, -DP, S, D>(
|
||||||
|
mapStateToProps: null | void,
|
||||||
|
mapDispatchToProps: DP,
|
||||||
|
mergeProps?: null | void,
|
||||||
|
options?: ?Options<S, OP, {||}, {| ...OP, ...DP |}>,
|
||||||
|
// Got error like inexact OwnProps is incompatible with exact object type?
|
||||||
|
// Just make your OP parameter an exact object.
|
||||||
|
): Connector<P, OP, {| ...OP, ...$ObjMap<DP, Bind<D>> |}>;
|
||||||
|
|
||||||
|
declare export function connect<-P, -OP, -SP, -DP, S, D>(
|
||||||
|
// If you get error here try adding return type to your mapStateToProps function
|
||||||
|
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||||
|
mapDispatchToProps: MapDispatchToPropsFn<D, OP, DP>,
|
||||||
|
mergeProps?: null | void,
|
||||||
|
options?: ?Options<S, OP, SP, {| ...OP, ...SP, ...DP |}>,
|
||||||
|
// Got error like inexact OwnProps is incompatible with exact object type?
|
||||||
|
// Just make your OP parameter an exact object.
|
||||||
|
): Connector<P, OP, {| ...OP, ...SP, ...DP |}>;
|
||||||
|
|
||||||
|
declare export function connect<-P, -OP, -SP, -DP, S, D>(
|
||||||
|
// If you get error here try adding return type to your mapStateToProps function
|
||||||
|
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||||
|
mapDispatchToProps: DP,
|
||||||
|
mergeProps?: null | void,
|
||||||
|
options?: ?Options<S, OP, SP, {| ...OP, ...SP, ...DP |}>,
|
||||||
|
// Got error like inexact OwnProps is incompatible with exact object type?
|
||||||
|
// Just make your OP parameter an exact object.
|
||||||
|
): Connector<P, OP, {| ...OP, ...SP, ...$ObjMap<DP, Bind<D>> |}>;
|
||||||
|
|
||||||
|
// With `mergeProps` argument
|
||||||
|
|
||||||
declare type MergeProps<SP, DP: Object, OP: Object, P: Object> = (
|
declare type MergeProps<+P, -OP, -SP, -DP> = (
|
||||||
stateProps: SP,
|
stateProps: SP,
|
||||||
dispatchProps: DP,
|
dispatchProps: DP,
|
||||||
ownProps: OP
|
ownProps: OP,
|
||||||
) => P;
|
) => P;
|
||||||
|
|
||||||
declare type Context = { store: Store<*, *> };
|
declare export function connect<-P, -OP, -SP: {||}, -DP: {||}, S, D>(
|
||||||
|
mapStateToProps: null | void,
|
||||||
|
mapDispatchToProps: null | void,
|
||||||
|
// If you get error here try adding return type to you mapStateToProps function
|
||||||
|
mergeProps: MergeProps<P, OP, {||}, {| dispatch: D |}>,
|
||||||
|
options?: ?Options<S, OP, {||}, P>,
|
||||||
|
): Connector<P, OP, P>;
|
||||||
|
|
||||||
declare type ComponentWithDefaultProps<DP: {}, P: {}, CP: P> = Class<React$Component<CP>> & { defaultProps: DP };
|
declare export function connect<-P, -OP, -SP, -DP: {||}, S, D>(
|
||||||
|
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||||
|
mapDispatchToProps: null | void,
|
||||||
|
// If you get error here try adding return type to you mapStateToProps function
|
||||||
|
mergeProps: MergeProps<P, OP, SP, {| dispatch: D |}>,
|
||||||
|
options?: ?Options<S, OP, SP, P>,
|
||||||
|
): Connector<P, OP, P>;
|
||||||
|
|
||||||
declare class ConnectedComponentWithDefaultProps<
|
// In this case DP is an object of functions which has been bound to dispatch
|
||||||
OP,
|
// by the given mapDispatchToProps function.
|
||||||
DP,
|
declare export function connect<-P, -OP, -SP: {||}, -DP, S, D>(
|
||||||
CP
|
mapStateToProps: null | void,
|
||||||
> extends React$Component<OP> {
|
mapDispatchToProps: MapDispatchToPropsFn<D, OP, DP>,
|
||||||
static defaultProps: DP, // <= workaround for https://github.com/facebook/flow/issues/4644
|
mergeProps: MergeProps<P, OP, {||}, DP>,
|
||||||
static WrappedComponent: Class<React$Component<CP>>,
|
options?: ?Options<S, OP, {||}, P>,
|
||||||
getWrappedInstance(): React$Component<CP>,
|
): Connector<P, OP, P>;
|
||||||
props: OP,
|
|
||||||
state: void
|
|
||||||
}
|
|
||||||
|
|
||||||
declare class ConnectedComponent<OP, P> extends React$Component<OP> {
|
// In this case DP is an object of action creators not yet bound to dispatch,
|
||||||
static WrappedComponent: Class<React$Component<P>>,
|
// this difference is not important in the vanila redux,
|
||||||
getWrappedInstance(): React$Component<P>,
|
// but in case of usage with redux-thunk, the return type may differ.
|
||||||
props: OP,
|
declare export function connect<-P, -OP, -SP: {||}, -DP, S, D>(
|
||||||
state: void
|
mapStateToProps: null | void,
|
||||||
}
|
mapDispatchToProps: DP,
|
||||||
|
mergeProps: MergeProps<P, OP, {||}, $ObjMap<DP, Bind<D>>>,
|
||||||
|
options?: ?Options<S, OP, {||}, P>,
|
||||||
|
): Connector<P, OP, P>;
|
||||||
|
|
||||||
declare type ConnectedComponentWithDefaultPropsClass<OP, DP, CP> = Class<ConnectedComponentWithDefaultProps<OP, DP, CP>>;
|
// In this case DP is an object of functions which has been bound to dispatch
|
||||||
|
// by the given mapDispatchToProps function.
|
||||||
|
declare export function connect<-P, -OP, -SP, -DP, S, D>(
|
||||||
|
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||||
|
mapDispatchToProps: MapDispatchToPropsFn<D, OP, DP>,
|
||||||
|
mergeProps: MergeProps<P, OP, SP, DP>,
|
||||||
|
options?: ?Options<S, OP, SP, P>,
|
||||||
|
): Connector<P, OP, P>;
|
||||||
|
|
||||||
declare type ConnectedComponentClass<OP, P> = Class<ConnectedComponent<OP, P>>;
|
// In this case DP is an object of action creators not yet bound to dispatch,
|
||||||
|
// this difference is not important in the vanila redux,
|
||||||
|
// but in case of usage with redux-thunk, the return type may differ.
|
||||||
|
declare export function connect<-P, -OP, -SP, -DP, S, D>(
|
||||||
|
mapStateToProps: MapStateToProps<S, OP, SP>,
|
||||||
|
mapDispatchToProps: DP,
|
||||||
|
mergeProps: MergeProps<P, OP, SP, $ObjMap<DP, Bind<D>>>,
|
||||||
|
options?: ?Options<S, OP, SP, P>,
|
||||||
|
): Connector<P, OP, P>;
|
||||||
|
|
||||||
declare type Connector<OP, P> = (<DP: {}, CP: {}>(
|
// ------------------------------------------------------------
|
||||||
component: ComponentWithDefaultProps<DP, P, CP>
|
// Typings for Provider
|
||||||
) => ConnectedComponentWithDefaultPropsClass<OP, DP, CP>) &
|
// ------------------------------------------------------------
|
||||||
((component: React$ComponentType<P>) => ConnectedComponentClass<OP, P>);
|
|
||||||
|
|
||||||
declare class Provider<S, A> extends React$Component<{
|
declare export class Provider<Store> extends React$Component<{
|
||||||
store: Store<S, A>,
|
store: Store,
|
||||||
children?: any
|
children?: React$Node,
|
||||||
}> {}
|
}> {}
|
||||||
|
|
||||||
declare function createProvider(
|
declare export function createProvider(
|
||||||
storeKey?: string,
|
storeKey?: string,
|
||||||
subKey?: string
|
subKey?: string,
|
||||||
): Provider<*, *>;
|
): Class<Provider<*>>;
|
||||||
|
|
||||||
declare type ConnectOptions = {
|
// ------------------------------------------------------------
|
||||||
pure?: boolean,
|
// Typings for connectAdvanced()
|
||||||
withRef?: boolean
|
// ------------------------------------------------------------
|
||||||
};
|
|
||||||
|
|
||||||
declare type Null = null | void;
|
declare type ConnectAdvancedOptions = {
|
||||||
|
getDisplayName?: (name: string) => string,
|
||||||
|
methodName?: string,
|
||||||
|
renderCountProp?: string,
|
||||||
|
shouldHandleStateChanges?: boolean,
|
||||||
|
storeKey?: string,
|
||||||
|
withRef?: boolean,
|
||||||
|
};
|
||||||
|
|
||||||
declare function connect<A, OP>(
|
declare type SelectorFactoryOptions<Com> = {
|
||||||
...rest: Array<void> // <= workaround for https://github.com/facebook/flow/issues/2360
|
getDisplayName: (name: string) => string,
|
||||||
): Connector<OP, $Supertype<{ dispatch: Dispatch<A> } & OP>>;
|
methodName: string,
|
||||||
|
renderCountProp: ?string,
|
||||||
|
shouldHandleStateChanges: boolean,
|
||||||
|
storeKey: string,
|
||||||
|
withRef: boolean,
|
||||||
|
displayName: string,
|
||||||
|
wrappedComponentName: string,
|
||||||
|
WrappedComponent: Com,
|
||||||
|
};
|
||||||
|
|
||||||
declare function connect<A, OP>(
|
declare type MapStateToPropsEx<S: Object, SP: Object, RSP: Object> = (
|
||||||
mapStateToProps: Null,
|
state: S,
|
||||||
mapDispatchToProps: Null,
|
props: SP,
|
||||||
mergeProps: Null,
|
) => RSP;
|
||||||
options: ConnectOptions
|
|
||||||
): Connector<OP, $Supertype<{ dispatch: Dispatch<A> } & OP>>;
|
|
||||||
|
|
||||||
declare function connect<S, A, OP, SP>(
|
declare type SelectorFactory<
|
||||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
Com: React$ComponentType<*>,
|
||||||
mapDispatchToProps: Null,
|
Dispatch,
|
||||||
mergeProps: Null,
|
S: Object,
|
||||||
options?: ConnectOptions
|
OP: Object,
|
||||||
): Connector<OP, $Supertype<SP & { dispatch: Dispatch<A> } & OP>>;
|
EFO: Object,
|
||||||
|
CP: Object,
|
||||||
declare function connect<A, OP, DP>(
|
> = (
|
||||||
mapStateToProps: Null,
|
dispatch: Dispatch,
|
||||||
mapDispatchToProps: MapDispatchToProps<A, OP, DP>,
|
factoryOptions: SelectorFactoryOptions<Com> & EFO,
|
||||||
mergeProps: Null,
|
) => MapStateToPropsEx<S, OP, CP>;
|
||||||
options?: ConnectOptions
|
|
||||||
): Connector<OP, $Supertype<DP & OP>>;
|
|
||||||
|
|
||||||
declare function connect<S, A, OP, SP, DP>(
|
|
||||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
|
||||||
mapDispatchToProps: MapDispatchToProps<A, OP, DP>,
|
|
||||||
mergeProps: Null,
|
|
||||||
options?: ConnectOptions
|
|
||||||
): Connector<OP, $Supertype<SP & DP & OP>>;
|
|
||||||
|
|
||||||
declare function connect<S, A, OP, SP, DP, P>(
|
declare export function connectAdvanced<
|
||||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
Com: React$ComponentType<*>,
|
||||||
mapDispatchToProps: Null,
|
D,
|
||||||
mergeProps: MergeProps<SP, DP, OP, P>,
|
S: Object,
|
||||||
options?: ConnectOptions
|
OP: Object,
|
||||||
): Connector<OP, P>;
|
CP: Object,
|
||||||
|
EFO: Object,
|
||||||
|
ST: { [_: $Keys<Com>]: any },
|
||||||
|
>(
|
||||||
|
selectorFactory: SelectorFactory<Com, D, S, OP, EFO, CP>,
|
||||||
|
connectAdvancedOptions: ?(ConnectAdvancedOptions & EFO),
|
||||||
|
): (component: Com) => React$ComponentType<OP> & $Shape<ST>;
|
||||||
|
|
||||||
declare function connect<S, A, OP, SP, DP, P>(
|
declare export default {
|
||||||
mapStateToProps: MapStateToProps<S, OP, SP>,
|
Provider: typeof Provider,
|
||||||
mapDispatchToProps: MapDispatchToProps<A, OP, DP>,
|
createProvider: typeof createProvider,
|
||||||
mergeProps: MergeProps<SP, DP, OP, P>,
|
connect: typeof connect,
|
||||||
options?: ConnectOptions
|
connectAdvanced: typeof connectAdvanced,
|
||||||
): Connector<OP, P>;
|
};
|
||||||
}
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/* @flow */
|
||||||
|
|
||||||
|
import * as IMPORT from 'actions/constants/importAccount';
|
||||||
|
|
||||||
|
import type { Action } from 'flowtype';
|
||||||
|
|
||||||
|
export type ImportState = {
|
||||||
|
loading: boolean,
|
||||||
|
error: ?string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const initialState: ImportState = {
|
||||||
|
loading: false,
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default (state: ImportState = initialState, action: Action): ImportState => {
|
||||||
|
switch (action.type) {
|
||||||
|
case IMPORT.START:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
loading: true,
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
case IMPORT.SUCCESS:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
loading: false,
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
case IMPORT.FAIL:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
loading: false,
|
||||||
|
error: action.error,
|
||||||
|
};
|
||||||
|
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
@ -1,42 +0,0 @@
|
|||||||
/* @flow */
|
|
||||||
import * as React from 'react';
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
import { bindActionCreators } from 'redux';
|
|
||||||
import * as RouterActions from 'actions/RouterActions';
|
|
||||||
|
|
||||||
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
|
||||||
import type { State, Dispatch } from 'flowtype';
|
|
||||||
import ImportView from './index';
|
|
||||||
|
|
||||||
export type StateProps = {
|
|
||||||
transport: $ElementType<$ElementType<State, 'connect'>, 'transport'>,
|
|
||||||
children?: React.Node,
|
|
||||||
};
|
|
||||||
|
|
||||||
type DispatchProps = {
|
|
||||||
selectFirstAvailableDevice: typeof RouterActions.selectFirstAvailableDevice,
|
|
||||||
};
|
|
||||||
|
|
||||||
type OwnProps = {};
|
|
||||||
|
|
||||||
export type Props = StateProps & DispatchProps;
|
|
||||||
|
|
||||||
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (
|
|
||||||
state: State
|
|
||||||
): StateProps => ({
|
|
||||||
transport: state.connect.transport,
|
|
||||||
});
|
|
||||||
|
|
||||||
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (
|
|
||||||
dispatch: Dispatch
|
|
||||||
): DispatchProps => ({
|
|
||||||
selectFirstAvailableDevice: bindActionCreators(
|
|
||||||
RouterActions.selectFirstAvailableDevice,
|
|
||||||
dispatch
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
export default connect(
|
|
||||||
mapStateToProps,
|
|
||||||
mapDispatchToProps
|
|
||||||
)(ImportView);
|
|
@ -1,28 +0,0 @@
|
|||||||
/* @flow */
|
|
||||||
|
|
||||||
import React from 'react';
|
|
||||||
import styled from 'styled-components';
|
|
||||||
import { Button, Link, Icon, H5, icons, colors } from 'trezor-ui-components';
|
|
||||||
import LandingWrapper from 'views/Landing/components/LandingWrapper';
|
|
||||||
|
|
||||||
const Wrapper = styled.div`
|
|
||||||
width: 100%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
`;
|
|
||||||
|
|
||||||
const Import = () => (
|
|
||||||
<LandingWrapper>
|
|
||||||
<Wrapper>
|
|
||||||
<Icon size={60} color={colors.WARNING_PRIMARY} icon={icons.WARNING} />
|
|
||||||
<H5>Import tool is under construction</H5>
|
|
||||||
<Link to="/">
|
|
||||||
<Button>Take me back</Button>
|
|
||||||
</Link>
|
|
||||||
</Wrapper>
|
|
||||||
</LandingWrapper>
|
|
||||||
);
|
|
||||||
|
|
||||||
export default Import;
|
|
@ -1,26 +1,20 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import type { MapStateToProps } from 'react-redux';
|
import type { State, Dispatch } from 'flowtype';
|
||||||
import type { State } from 'flowtype';
|
|
||||||
import Dashboard from './index';
|
import Dashboard from './index';
|
||||||
|
|
||||||
type OwnProps = {};
|
type OwnProps = {||};
|
||||||
|
|
||||||
type StateProps = {
|
type StateProps = {|
|
||||||
localStorage: $ElementType<State, 'localStorage'>,
|
localStorage: $ElementType<State, 'localStorage'>,
|
||||||
wallet: $ElementType<State, 'wallet'>,
|
wallet: $ElementType<State, 'wallet'>,
|
||||||
};
|
|};
|
||||||
|
|
||||||
export type Props = StateProps;
|
export type Props = {| ...StateProps |};
|
||||||
|
|
||||||
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (
|
const mapStateToProps = (state: State): StateProps => ({
|
||||||
state: State
|
|
||||||
): StateProps => ({
|
|
||||||
localStorage: state.localStorage,
|
localStorage: state.localStorage,
|
||||||
wallet: state.wallet,
|
wallet: state.wallet,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(
|
export default connect<Props, OwnProps, StateProps, _, State, Dispatch>(mapStateToProps)(Dashboard);
|
||||||
mapStateToProps,
|
|
||||||
null
|
|
||||||
)(Dashboard);
|
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
/* @flow */
|
||||||
|
import * as React from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { bindActionCreators } from 'redux';
|
||||||
|
import * as ImportAccountActions from 'actions/ImportAccountActions';
|
||||||
|
import type { State, Dispatch, TrezorDevice, Config } from 'flowtype';
|
||||||
|
import ImportView from './index';
|
||||||
|
|
||||||
|
type OwnProps = {|
|
||||||
|
children?: React.Node,
|
||||||
|
|};
|
||||||
|
export type StateProps = {|
|
||||||
|
device: ?TrezorDevice,
|
||||||
|
config: Config,
|
||||||
|
importAccount: $ElementType<State, 'importAccount'>,
|
||||||
|
|};
|
||||||
|
|
||||||
|
type DispatchProps = {|
|
||||||
|
importAddress: typeof ImportAccountActions.importAddress,
|
||||||
|
|};
|
||||||
|
|
||||||
|
export type Props = {| ...OwnProps, ...StateProps, ...DispatchProps |};
|
||||||
|
|
||||||
|
const mapStateToProps = (state: State): StateProps => ({
|
||||||
|
config: state.localStorage.config,
|
||||||
|
device: state.wallet.selectedDevice,
|
||||||
|
importAccount: state.importAccount,
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({
|
||||||
|
importAddress: bindActionCreators(ImportAccountActions.importAddress, dispatch),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect<Props, OwnProps, StateProps, DispatchProps, State, Dispatch>(
|
||||||
|
mapStateToProps,
|
||||||
|
mapDispatchToProps
|
||||||
|
)(ImportView);
|
@ -0,0 +1,105 @@
|
|||||||
|
/* @flow */
|
||||||
|
|
||||||
|
import React, { useState } from 'react';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
import { Select, Button, Input, Link, colors } from 'trezor-ui-components';
|
||||||
|
import l10nCommonMessages from 'views/common.messages';
|
||||||
|
import type { Props } from './Container';
|
||||||
|
|
||||||
|
const Wrapper = styled.div`
|
||||||
|
text-align: left;
|
||||||
|
flex-direction: column;
|
||||||
|
display: flex;
|
||||||
|
padding: 24px;
|
||||||
|
min-width: 300px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const StyledSelect = styled(Select)`
|
||||||
|
min-width: 100px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const InputRow = styled.div`
|
||||||
|
margin-bottom: 16px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Label = styled.div`
|
||||||
|
color: ${colors.TEXT_SECONDARY};
|
||||||
|
padding-bottom: 10px;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const ButtonActions = styled.div`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
|
||||||
|
justify-content: flex-end;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const ButtonWrapper = styled.div`
|
||||||
|
& + & {
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Import = (props: Props) => {
|
||||||
|
const [selectedNetwork, setSelectedNetwork] = useState(null);
|
||||||
|
const [address, setAddress] = useState('');
|
||||||
|
|
||||||
|
const { networks } = props.config;
|
||||||
|
return (
|
||||||
|
// <LandingWrapper>
|
||||||
|
<Wrapper>
|
||||||
|
<InputRow>
|
||||||
|
<Label>Select network</Label>
|
||||||
|
<StyledSelect
|
||||||
|
value={selectedNetwork}
|
||||||
|
options={networks
|
||||||
|
.sort((a, b) => a.shortcut.localeCompare(b.shortcut))
|
||||||
|
.map(net => ({
|
||||||
|
label: net.shortcut,
|
||||||
|
value: net,
|
||||||
|
}))}
|
||||||
|
onChange={option => setSelectedNetwork(option)}
|
||||||
|
/>
|
||||||
|
</InputRow>
|
||||||
|
|
||||||
|
<InputRow>
|
||||||
|
<Input
|
||||||
|
topLabel="Address"
|
||||||
|
name="cryptoAddress"
|
||||||
|
value={address}
|
||||||
|
onChange={e => setAddress(e.target.value)}
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
</InputRow>
|
||||||
|
<ButtonActions>
|
||||||
|
<ButtonWrapper>
|
||||||
|
<Link to="/">
|
||||||
|
<Button isWhite>
|
||||||
|
<FormattedMessage {...l10nCommonMessages.TR_CLOSE} />
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</ButtonWrapper>
|
||||||
|
|
||||||
|
<ButtonWrapper>
|
||||||
|
<Button
|
||||||
|
isDisabled={
|
||||||
|
!selectedNetwork || address === '' || props.importAccount.loading
|
||||||
|
}
|
||||||
|
onClick={() =>
|
||||||
|
props.importAddress(
|
||||||
|
address,
|
||||||
|
(selectedNetwork || {}).value,
|
||||||
|
props.device
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Import
|
||||||
|
</Button>
|
||||||
|
</ButtonWrapper>
|
||||||
|
</ButtonActions>
|
||||||
|
</Wrapper>
|
||||||
|
// </LandingWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default Import;
|
Loading…
Reference in new issue