2018-02-20 09:30:36 +00:00
|
|
|
/* @flow */
|
2018-07-30 10:52:13 +00:00
|
|
|
|
2018-08-14 13:11:52 +00:00
|
|
|
import * as STORAGE from 'actions/constants/localStorage';
|
2018-02-20 09:30:36 +00:00
|
|
|
|
2018-08-14 12:56:47 +00:00
|
|
|
import type { Action } from 'flowtype';
|
2018-04-16 21:19:50 +00:00
|
|
|
|
2018-12-28 14:58:09 +00:00
|
|
|
type NetworkFeeLevel = {
|
|
|
|
name: string,
|
|
|
|
value: string, // ETH: gasPrice in gwei, XRP: fee in drops, BTC: sat/b
|
|
|
|
multiplier: number, // ETH specific
|
|
|
|
blocks: number, // BTC specific
|
|
|
|
recommended: boolean,
|
|
|
|
};
|
|
|
|
|
2018-10-15 13:44:10 +00:00
|
|
|
export type Network = {
|
2019-03-06 13:49:55 +00:00
|
|
|
order: number,
|
2019-03-04 12:33:02 +00:00
|
|
|
type: string,
|
|
|
|
name: string,
|
|
|
|
testnet?: boolean,
|
|
|
|
shortcut: string,
|
|
|
|
symbol: string,
|
|
|
|
bip44: string,
|
|
|
|
defaultGasLimit: number,
|
|
|
|
defaultGasLimitTokens: number,
|
|
|
|
defaultGasPrice: number,
|
|
|
|
chainId: number, // ETH specific
|
2018-05-05 11:52:03 +00:00
|
|
|
explorer: {
|
2019-03-04 12:33:02 +00:00
|
|
|
tx: string,
|
|
|
|
address: string,
|
|
|
|
},
|
|
|
|
tokens: string,
|
|
|
|
decimals: number,
|
2018-12-28 14:58:09 +00:00
|
|
|
fee: {
|
2019-03-04 12:33:02 +00:00
|
|
|
defaultFee: string,
|
|
|
|
minFee: string,
|
|
|
|
maxFee: string,
|
|
|
|
defaultGasLimit: string, // ETH specific
|
|
|
|
defaultGasLimitTokens: string, // ETH specific
|
|
|
|
levels: Array<NetworkFeeLevel>,
|
2018-12-28 14:58:09 +00:00
|
|
|
},
|
2018-05-05 11:52:03 +00:00
|
|
|
backends: Array<{
|
2019-03-04 12:33:02 +00:00
|
|
|
name: string,
|
|
|
|
urls: Array<string>,
|
|
|
|
}>,
|
|
|
|
web3: Array<string>,
|
|
|
|
};
|
2018-04-16 21:19:50 +00:00
|
|
|
|
|
|
|
export type NetworkToken = {
|
|
|
|
address: string,
|
|
|
|
name: string,
|
|
|
|
symbol: string,
|
2019-03-04 12:33:02 +00:00
|
|
|
decimals: number,
|
|
|
|
};
|
2018-04-16 21:19:50 +00:00
|
|
|
|
|
|
|
export type TokensCollection = { [network: string]: Array<NetworkToken> };
|
|
|
|
|
|
|
|
// type AbiField = {
|
|
|
|
// constant: boolean,
|
|
|
|
// inputs: Array<{
|
|
|
|
// name: string,
|
|
|
|
// type: string,
|
|
|
|
// }>,
|
|
|
|
// name: string,
|
|
|
|
// outputs: Array<{
|
|
|
|
// name: string,
|
|
|
|
// type: string,
|
|
|
|
// }>,
|
|
|
|
// payable: boolean,
|
|
|
|
// stateMutability: string,
|
|
|
|
// type: string
|
|
|
|
// }
|
|
|
|
|
|
|
|
export type FiatValueTicker = {
|
2019-03-04 12:33:02 +00:00
|
|
|
network: string,
|
|
|
|
url: string,
|
|
|
|
};
|
2018-04-16 21:19:50 +00:00
|
|
|
|
|
|
|
export type Config = {
|
2019-03-04 12:33:02 +00:00
|
|
|
networks: Array<Network>,
|
|
|
|
fiatValueTickers: Array<FiatValueTicker>,
|
|
|
|
};
|
2018-04-16 21:19:50 +00:00
|
|
|
|
|
|
|
export type State = {
|
2019-03-04 12:33:02 +00:00
|
|
|
initialized: boolean,
|
|
|
|
error: ?string,
|
|
|
|
config: Config,
|
|
|
|
ERC20Abi: Array<Object>,
|
|
|
|
tokens: TokensCollection,
|
|
|
|
};
|
2018-02-20 09:30:36 +00:00
|
|
|
|
|
|
|
const initialState: State = {
|
|
|
|
initialized: false,
|
|
|
|
error: null,
|
2018-04-16 21:19:50 +00:00
|
|
|
config: {
|
2018-10-15 13:44:10 +00:00
|
|
|
networks: [],
|
2018-07-30 10:52:13 +00:00
|
|
|
fiatValueTickers: [],
|
2018-04-16 21:19:50 +00:00
|
|
|
},
|
|
|
|
ERC20Abi: [],
|
|
|
|
tokens: {},
|
2018-02-20 09:30:36 +00:00
|
|
|
};
|
|
|
|
|
2018-04-16 21:19:50 +00:00
|
|
|
export default function localStorage(state: State = initialState, action: Action): State {
|
2018-02-20 09:30:36 +00:00
|
|
|
switch (action.type) {
|
2018-07-30 10:52:13 +00:00
|
|
|
case STORAGE.READY:
|
2018-02-20 09:30:36 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
initialized: true,
|
2018-03-29 09:35:27 +00:00
|
|
|
config: action.config,
|
|
|
|
ERC20Abi: action.ERC20Abi,
|
|
|
|
tokens: action.tokens,
|
2018-07-30 10:52:13 +00:00
|
|
|
error: null,
|
|
|
|
};
|
2018-02-20 09:30:36 +00:00
|
|
|
|
2018-07-30 10:52:13 +00:00
|
|
|
case STORAGE.ERROR:
|
2018-02-20 09:30:36 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2018-07-30 10:52:13 +00:00
|
|
|
error: action.error,
|
|
|
|
};
|
|
|
|
|
2018-02-20 09:30:36 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2018-04-16 21:19:50 +00:00
|
|
|
}
|