small refactoring

This commit is contained in:
DieMyst 2019-08-18 15:34:52 +03:00
parent 53c30d4671
commit 2146507ed9
4 changed files with 12 additions and 15 deletions

View File

@ -1,4 +1,4 @@
import {getMessages, saveMessage} from "../fluence/api"; import {changeConnection, getMessages, saveMessage} from "../fluence/api";
import { showLoading, hideLoading } from "react-redux-loading-bar"; import { showLoading, hideLoading } from "react-redux-loading-bar";
export const ADD_MESSAGE = "ADD_MESSAGE"; export const ADD_MESSAGE = "ADD_MESSAGE";
@ -11,18 +11,15 @@ function addMessage(message) {
}; };
} }
export function fetchPosts(counter, withBar) { export async function toggleConnection(devnet, appId = 412) {
return changeConnection(devnet, appId)
}
export function fetchPosts(counter) {
return dispatch => { return dispatch => {
if (withBar) {
dispatch(showLoading());
}
return getMessages().then((messages) => { return getMessages().then((messages) => {
dispatch(receiveMessages(messages, counter)); dispatch(receiveMessages(messages, counter));
}).finally(() => { })
if (withBar) {
dispatch(hideLoading());
}
});
}; };
} }

View File

@ -1,6 +1,6 @@
import React, {Component} from "react"; import React, {Component} from "react";
import {connect} from "react-redux"; import {connect} from "react-redux";
import {toggleConnection} from "../fluence/api"; import {toggleConnection} from "../actions/messages";
class ConnectionToggle extends Component { class ConnectionToggle extends Component {
constructor(props) { constructor(props) {
@ -20,7 +20,7 @@ class ConnectionToggle extends Component {
toggleDisabled: true, toggleDisabled: true,
devnetConnect: newConnect devnetConnect: newConnect
})); }));
toggleConnection(newConnect).finally(() => { toggleConnection(newConnect).then(() => {
this.setState(state => ({ this.setState(state => ({
toggleDisabled: false toggleDisabled: false
})); }));

View File

@ -12,11 +12,11 @@ class Dashboard extends Component {
} }
componentDidMount() { componentDidMount() {
this.props.dispatch(handleInitialData());
this.pollingMessages = setInterval( this.pollingMessages = setInterval(
() => this.getMessages(), () => this.getMessages(),
2000 1500
); );
this.props.dispatch(handleInitialData());
} }
componentWillUnmount() { componentWillUnmount() {

View File

@ -3,7 +3,7 @@ import * as fluence from "fluence";
let session = fluence.directConnect("localhost", 30000, 1); let session = fluence.directConnect("localhost", 30000, 1);
window.fluenceSession = session; window.fluenceSession = session;
export async function toggleConnection(devnet, appId = 412) { export async function changeConnection(devnet, appId = 412) {
if (devnet) { if (devnet) {
fluence.connect("0xeFF91455de6D4CF57C141bD8bF819E5f873c1A01", appId).then((s) => { fluence.connect("0xeFF91455de6D4CF57C141bD8bF819E5f873c1A01", appId).then((s) => {
session = s; session = s;