1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-18 06:18:12 +00:00
trezor-wallet/src/reducers/LocalStorageReducer.js

119 lines
2.3 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
export type Coin = {
name: string;
network: string;
symbol: string;
bip44: string;
defaultGasLimit: number;
defaultGasLimitTokens: number;
defaultGasPrice: number;
2018-05-22 08:26:34 +00:00
chainId: number;
2018-05-05 11:52:03 +00:00
explorer: {
tx: string;
address: string;
};
2018-04-16 21:19:50 +00:00
tokens: string;
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 = {
coins: Array<Coin>;
fiatValueTickers: Array<FiatValueTicker>;
}
2018-05-07 13:33:34 +00:00
export type CustomBackend = {
name: string;
url: string;
}
2018-04-16 21:19:50 +00:00
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-05-07 13:33:34 +00:00
customBackend: Array<CustomBackend>;
2018-02-20 09:30:36 +00:00
}
const initialState: State = {
initialized: false,
error: null,
2018-04-16 21:19:50 +00:00
config: {
coins: [],
2018-07-30 10:52:13 +00:00
fiatValueTickers: [],
2018-04-16 21:19:50 +00:00
},
ERC20Abi: [],
tokens: {},
2018-05-07 13:33:34 +00:00
customBackend: [
{
2018-07-30 10:52:13 +00:00
name: 'Custom1',
slug: 'custom1',
url: 'http://google.com',
},
],
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
}