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

update flowtype

This commit is contained in:
Szymon Lesisz 2018-09-12 13:05:48 +02:00
parent 84999a9061
commit 5babe75cda
4 changed files with 133 additions and 119 deletions

View File

@ -7,6 +7,8 @@ import type {
Middleware as ReduxMiddleware, Middleware as ReduxMiddleware,
ThunkAction as ReduxThunkAction, ThunkAction as ReduxThunkAction,
AsyncAction as ReduxAsyncAction, AsyncAction as ReduxAsyncAction,
PromiseAction as ReduxPromiseAction,
ThunkDispatch as ReduxThunkDispatch,
PlainDispatch as ReduxPlainDispatch, PlainDispatch as ReduxPlainDispatch,
} from 'redux'; } from 'redux';
@ -15,6 +17,7 @@ import type { ReducersState } from 'reducers';
// Actions // Actions
import type { SelectedAccountAction } from 'actions/SelectedAccountActions'; import type { SelectedAccountAction } from 'actions/SelectedAccountActions';
import type { AccountAction } from 'actions/AccountsActions'; import type { AccountAction } from 'actions/AccountsActions';
import type { BlockchainAction } from 'actions/BlockchainActions';
import type { DiscoveryAction } from 'actions/DiscoveryActions'; import type { DiscoveryAction } from 'actions/DiscoveryActions';
import type { StorageAction } from 'actions/LocalStorageActions'; import type { StorageAction } from 'actions/LocalStorageActions';
import type { LogAction } from 'actions/LogActions'; import type { LogAction } from 'actions/LogActions';
@ -37,6 +40,7 @@ import type {
DeviceFirmwareStatus, DeviceFirmwareStatus,
DeviceMessageType, DeviceMessageType,
TransportMessageType, TransportMessageType,
BlockchainMessageType,
UiMessageType, UiMessageType,
} from 'trezor-connect'; } from 'trezor-connect';
@ -102,6 +106,11 @@ type UiEventAction = {
// }, // },
} }
type BlockchainEventAction = {
type: BlockchainMessageType,
payload: any,
}
// TODO: join this message with uiMessage // TODO: join this message with uiMessage
type IFrameHandshake = { type IFrameHandshake = {
type: 'iframe_handshake', type: 'iframe_handshake',
@ -114,9 +123,11 @@ export type Action =
| TransportEventAction | TransportEventAction
| DeviceEventAction | DeviceEventAction
| UiEventAction | UiEventAction
| BlockchainEventAction
| SelectedAccountAction | SelectedAccountAction
| AccountAction | AccountAction
| BlockchainAction
| DiscoveryAction | DiscoveryAction
| StorageAction | StorageAction
| LogAction | LogAction
@ -154,6 +165,45 @@ export type Middleware = ReduxMiddleware<State, Action>;
export type ThunkAction = ReduxThunkAction<State, Action>; export type ThunkAction = ReduxThunkAction<State, Action>;
export type AsyncAction = ReduxAsyncAction<State, Action>; export type AsyncAction = ReduxAsyncAction<State, Action>;
export type PromiseAction<R> = ReduxPromiseAction<State, Action, R>;
export type Store = ReduxStore<State, Action>; export type Store = ReduxStore<State, Action>;
export type GetState = () => State; export type GetState = () => State;
// temporary types
export type AccountDiscovery = {
transactions: number;
block: number;
balance: string;
nonce: number;
}
import type { Token } from 'reducers/TokensReducer';
export type EthereumTxRequest = {
network: string;
token: ?Token;
from: string;
to: string;
amount: string;
data: string;
gasLimit: string;
gasPrice: string;
nonce: number;
}
// copypaste from trezor-connect
export type EthereumPreparedTx = {
to: string,
value: string,
gasPrice: string,
gasLimit: string,
nonce: string,
data?: string,
chainId?: number,
txType?: number,
v: string,
r: string,
s: string,
}

View File

@ -1,3 +1,5 @@
/* @flow */
declare module 'bignumber.js' { declare module 'bignumber.js' {
declare type $npm$big$number$object = number | string | T_BigNumber declare type $npm$big$number$object = number | string | T_BigNumber
declare type $npm$cmp$result = -1 | 0 | 1 declare type $npm$cmp$result = -1 | 0 | 1
@ -24,7 +26,7 @@ declare module 'bignumber.js' {
constructor(value: $npm$big$number$object): T_BigNumber; constructor(value: $npm$big$number$object): T_BigNumber;
// Methods // Methods
abs(): BigNumber; abs(): T_BigNumber;
cmp(n: $npm$big$number$object): $npm$cmp$result; cmp(n: $npm$big$number$object): $npm$cmp$result;
div(n: $npm$big$number$object): T_BigNumber; div(n: $npm$big$number$object): T_BigNumber;
dividedBy(n: $npm$big$number$object): T_BigNumber; dividedBy(n: $npm$big$number$object): T_BigNumber;

View File

@ -1,10 +1,12 @@
/* @flow */
declare module 'redux' { declare module 'redux' {
/* /*
S = State S = State
A = Action A = Action
D = Dispatch D = Dispatch
R = Promise response
*/ */
declare export type DispatchAPI<A> = (action: A) => A; declare export type DispatchAPI<A> = (action: A) => A;
@ -13,12 +15,14 @@ declare module 'redux' {
declare export type ThunkAction<S, A> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => void; declare export type ThunkAction<S, A> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => void;
declare export type AsyncAction<S, A> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => Promise<void>; declare export type AsyncAction<S, A> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => Promise<void>;
declare export type PromiseAction<S, A, R> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => Promise<R>;
declare export type ThunkDispatch<S, A> = (action: ThunkAction<S, A>) => void; declare export type ThunkDispatch<S, A> = (action: ThunkAction<S, A>) => void;
declare export type AsyncDispatch<S, A> = (action: AsyncAction<S, A>) => Promise<void>; declare export type AsyncDispatch<S, A> = (action: AsyncAction<S, A>) => Promise<void>;
declare export type PromiseDispatch<S, A> = <R>(action: PromiseAction<S, A, R>) => Promise<R>;
declare export type PlainDispatch<A: {type: $Subtype<string>}> = DispatchAPI<A>; declare export type PlainDispatch<A: {type: $Subtype<string>}> = DispatchAPI<A>;
/* NEW: Dispatch is now a combination of these different dispatch types */ /* NEW: Dispatch is now a combination of these different dispatch types */
declare export type ReduxDispatch<S, A> = PlainDispatch<A> & ThunkDispatch<S, A> & AsyncDispatch<S, A>; declare export type ReduxDispatch<S, A> = PlainDispatch<A> & ThunkDispatch<S, A> & AsyncDispatch<S, A> & PromiseDispatch<S, A>;
declare export type MiddlewareAPI<S, A> = { declare export type MiddlewareAPI<S, A> = {
// dispatch: Dispatch<S, A>; // dispatch: Dispatch<S, A>;

View File

@ -1,8 +1,10 @@
/* @flow */
import type BigNumber from 'bignumber.js'; import type BigNumber from 'bignumber.js';
import type { EthereumUnitT, EthereumAddressT } from 'ethereum-types'; import type { EthereumUnitT, EthereumAddressT } from 'ethereum-types';
declare module 'web3' { declare module 'web3' {
declare type ProviderT = { declare type HttpProviderT = {
host: string; host: string;
timeout: number; timeout: number;
isConnected: () => boolean; isConnected: () => boolean;
@ -10,14 +12,25 @@ declare module 'web3' {
sendAsync: (payload: any, callback: (error: Error, result: any) => void) => any; sendAsync: (payload: any, callback: (error: Error, result: any) => void) => any;
}; };
declare type WebsocketProviderT = {
on: (type: string, callback: () => any) => void;
removeAllListeners: (type: string) => void;
reset: () => void;
connected: boolean;
}
declare class Web3T { declare class Web3T {
static providers: { static providers: {
HttpProvider: (host: string, timeout?: number) => ProviderT; HttpProvider: (host: string, timeout?: number) => HttpProviderT;
WebsocketProvider: (host: string, options?: any) => WebsocketProviderT;
}; };
constructor(ProviderT): Web3T; // constructor(HttpProviderT): Web3T;
currentProvider: ProviderT; constructor(WebsocketProviderT): Web3T;
// currentProvider: HttpProviderT;
currentProvider: WebsocketProviderT;
eth: Eth; eth: Eth;
utils: Utils;
toHex: (str: string | number) => string; toHex: (str: string | number) => string;
isAddress: (address: string) => boolean; isAddress: (address: string) => boolean;
@ -78,20 +91,33 @@ declare module 'web3' {
transactionIndex: number transactionIndex: number
} }
//declare function F_CardanoGetAddress(params: (P.$Common & CARDANO.$CardanoGetAddress)): Promise<CARDANO.CardanoGetAddress$>;
//declare function F_CardanoGetAddress(params: (P.$Common & { bundle: Array<CARDANO.$CardanoGetAddress> })): Promise<CARDANO.CardanoGetAddress$$>;
declare type PromiseEvent<T> = {
once: typeof F_PromiseEventOn;
on: typeof F_PromiseEventOn;
off: (type: string, callback: Function) => PromiseEvent<T>;
then: () => (result: T) => PromiseEvent<T>;
catch: () => (error: Error) => PromiseEvent<T>;
}
declare function F_PromiseEventOn<T>(type: 'transactionHash', callback: (hash: string) => void): PromiseEvent<T>;
declare function F_PromiseEventOn<T>(type: 'receipt', callback: (receipt: TransactionReceipt) => void): PromiseEvent<T>;
declare function F_PromiseEventOn<T>(type: 'confirmation', callback: (confirmations: number, receipt: TransactionReceipt) => void): PromiseEvent<T>;
declare function F_PromiseEventOn<T>(type: 'error', callback: (error: Error) => void): PromiseEvent<T>;
declare class Eth { declare class Eth {
getGasPrice: (callback: (error: Error, gasPrice: string) => void) => void, getBalance: (address: string) => Promise<string>;
getBalance: (address: string, callback: (error: Error, balance: BigNumber) => void) => void, getTransactionCount: (address: string) => Promise<number>;
getTransactionCount: (address: string, callback: (error: Error, result: number) => void) => void, estimateGas: (options: EstimateGasOptions) => Promise<number>;
getTransaction: (txid: string, callback: (error: Error, result: TransactionStatus) => void) => void, getGasPrice: () => Promise<string>;
getTransactionReceipt: (txid: string, callback: (error: Error, result: TransactionReceipt) => void) => void, getBlockNumber: () => Promise<number>;
getBlockNumber: (callback: (error: Error, blockNumber: number) => void) => void, Contract: (abi: Array<Object>, options?: any) => Contract;
getBlock: (hash: string, callback: (error: Error, result: any) => void) => void, sendSignedTransaction: (tx: string) => PromiseEvent<TransactionReceipt>;
// getAccounts: (callback: (error: Error, accounts: Array<EthereumAddressT>) => void) => void, getTransaction: (txid: string) => Promise<TransactionStatus>;
// sign: (payload: string, signer: EthereumAddressT) => Promise<string>, getTransactionReceipt: (txid: string) => Promise<TransactionReceipt>;
contract: (abi: Array<Object>) => ContractFactory, subscribe: (type: string, callback: Function) => any;
estimateGas: (options: EstimateGasOptions, callback: (error: ?Error, gas: ?number) => void) => void,
sendRawTransaction: (tx: any, callback: (error: Error, result: string) => void) => void,
filter: (type: string) => Filter; // return intance with "watch"
} }
declare export class Filter { declare export class Filter {
@ -99,108 +125,40 @@ declare module 'web3' {
stopWatching: (callback: any) => void, stopWatching: (callback: any) => void,
} }
declare export class ContractFactory { declare type ContractMethod<T> = {
// constructor(abi: Array<Object>); call: () => Promise<T>;
eth: Eth;
abi: Array<Object>;
at: (address: string, callback: ?(error: Error, contract: Contract) => void) => Contract; // TODO
} }
declare export class Contract { declare export class Contract {
name: { clone: () => Contract;
call: (callback: (error: Error, name: string) => void) => void;
}, options: {
symbol: { address: string;
call: (callback: (error: Error, symbol: string) => void) => void; jsonInterface: JSON;
}, };
decimals: {
call: (callback: (error: Error, decimals: BigNumber) => void) => void; methods: {
}, name: () => ContractMethod<string>;
balanceOf: (address: string, callback: (error: Error, balance: BigNumber) => void) => void, symbol: () => ContractMethod<string>;
transfer: any, decimals: () => ContractMethod<number>;
balanceOf: (address: string) => ContractMethod<string>;
transfer: (to: string, amount: any) => {
encodeABI: () => string;
}
};
}
declare class Utils {
toHex: (str: string | number) => string;
hexToNumberString: (str: string) => string;
isAddress: (address: string) => boolean;
toWei: (number: BigNumber, unit?: EthereumUnitT) => BigNumber;
toWei: (number: string, unit?: EthereumUnitT) => string;
toDecimal: (number: BigNumber) => number;
toDecimal: (number: string) => number;
soliditySha3: (payload: string | number | BigNumber | Object) => String;
} }
declare export default typeof Web3T; declare export default typeof Web3T;
} }
//
//
/*declare module 'web3' {
module.exports = {
eth: {
_requestManager: any;
iban: {
(iban: string): void;
fromAddress: (address: string) => any;
fromBban: (bban: string) => any;
createIndirect: (options: any) => any;
isValid: (iban: string) => boolean;
};
sendIBANTransaction: any;
contract: (abi: any) => {
eth: any;
abi: any[];
new: (...args: any[]) => {
_eth: any;
transactionHash: any;
address: any;
abi: any[];
};
at: (address: any, callback: Function) => any;
getData: (...args: any[]) => any;
};
filter: (fil: any, callback: any, filterCreationErrorCallback: any) => {
requestManager: any;
options: any;
implementation: {
[x: string]: any;
};
filterId: any;
callbacks: any[];
getLogsCallbacks: any[];
pollFilters: any[];
formatter: any;
watch: (callback: any) => any;
stopWatching: (callback: any) => any;
get: (callback: any) => any;
};
namereg: () => {
eth: any;
abi: any[];
new: (...args: any[]) => {
_eth: any;
transactionHash: any;
address: any;
abi: any[];
};
at: (address: any, callback: Function) => any;
getData: (...args: any[]) => any;
};
icapNamereg: () => {
eth: any;
abi: any[];
new: (...args: any[]) => {
_eth: any;
transactionHash: any;
address: any;
abi: any[];
};
at: (address: any, callback: Function) => any;
getData: (...args: any[]) => any;
};
isSyncing: (callback: any) => {
requestManager: any;
pollId: string;
callbacks: any[];
lastSyncState: boolean;
addCallback: (callback: any) => any;
stopWatching: () => void;
};
}
}
}
*/