1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-02-10 23:22:40 +00:00
trezor-wallet/src/reducers/LocalStorageReducer.js

125 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-02-20 09:30:36 +00:00
/* @flow */
2018-07-30 10:52:13 +00:00
2018-02-20 09:30:36 +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 = {
type: string;
2018-04-16 21:19:50 +00:00
name: string;
testnet?: boolean;
2018-10-15 13:44:10 +00:00
shortcut: string;
2018-04-16 21:19:50 +00:00
symbol: string;
bip44: string;
defaultGasLimit: number;
defaultGasLimitTokens: number;
defaultGasPrice: number;
2018-12-28 14:58:09 +00:00
chainId: number; // ETH specific
2018-05-05 11:52:03 +00:00
explorer: {
tx: string;
address: string;
};
2018-04-16 21:19:50 +00:00
tokens: string;
2018-12-28 14:58:09 +00:00
decimals: number;
fee: {
defaultFee: string;
minFee: string;
maxFee: string;
defaultGasLimit: string; // ETH specific
defaultGasLimitTokens: string; // ETH specific
levels: Array<NetworkFeeLevel>;
},
2018-05-05 11:52:03 +00:00
backends: Array<{
name: string;
urls: Array<string>;
2018-09-12 11:25:32 +00:00
}>;
web3: Array<string>;
2018-04-16 21:19:50 +00:00
}
export type NetworkToken = {
address: string,
name: string,
symbol: string,
decimals: number
}
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 = {
network: string;
url: string;
}
export type Config = {
2018-10-15 13:44:10 +00:00
networks: Array<Network>;
2018-04-16 21:19:50 +00:00
fiatValueTickers: Array<FiatValueTicker>;
}
export type State = {
2018-02-20 09:30:36 +00:00
initialized: boolean;
2018-04-16 21:19:50 +00:00
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,
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
}