|
|
|
@ -13,16 +13,14 @@ export type State = Array<BlockchainNetwork>;
|
|
|
|
|
|
|
|
|
|
export const initialState: State = [];
|
|
|
|
|
|
|
|
|
|
const find = (state: State, name: string): number => {
|
|
|
|
|
return state.findIndex(b => b.name === name);
|
|
|
|
|
}
|
|
|
|
|
const find = (state: State, name: string): number => state.findIndex(b => b.name === name);
|
|
|
|
|
|
|
|
|
|
const connect = (state: State, action: any): State => {
|
|
|
|
|
const name = action.payload.coin.shortcut.toLowerCase();
|
|
|
|
|
const network: BlockchainNetwork = {
|
|
|
|
|
name,
|
|
|
|
|
connected: true,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const newState: State = [...state];
|
|
|
|
|
const index: number = find(newState, name);
|
|
|
|
|
if (index >= 0) {
|
|
|
|
@ -38,7 +36,7 @@ const disconnect = (state: State, action: any): State => {
|
|
|
|
|
const network: BlockchainNetwork = {
|
|
|
|
|
name,
|
|
|
|
|
connected: false,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const newState: State = [...state];
|
|
|
|
|
const index: number = find(newState, name);
|
|
|
|
|
if (index >= 0) {
|
|
|
|
@ -52,7 +50,6 @@ const disconnect = (state: State, action: any): State => {
|
|
|
|
|
|
|
|
|
|
export default (state: State = initialState, action: Action): State => {
|
|
|
|
|
switch (action.type) {
|
|
|
|
|
|
|
|
|
|
case BLOCKCHAIN.CONNECT:
|
|
|
|
|
return connect(state, action);
|
|
|
|
|
case BLOCKCHAIN.ERROR:
|
|
|
|
|