mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-18 19:01:38 +03:00
hanled api changes
This commit is contained in:
parent
8242cf7191
commit
1deff92922
@ -2,6 +2,7 @@ import React, { Component } from 'react';
|
|||||||
import { Platform } from 'react-native';
|
import { Platform } from 'react-native';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import AppCenter from 'appcenter';
|
import AppCenter from 'appcenter';
|
||||||
|
import { Client } from 'dsteem';
|
||||||
|
|
||||||
// Realm
|
// Realm
|
||||||
import {
|
import {
|
||||||
@ -61,7 +62,6 @@ class SettingsContainer extends Component {
|
|||||||
// Component Functions
|
// Component Functions
|
||||||
_handleDropdownSelected = (action, actionType) => {
|
_handleDropdownSelected = (action, actionType) => {
|
||||||
const { dispatch } = this.props;
|
const { dispatch } = this.props;
|
||||||
const { serverList } = this.state;
|
|
||||||
|
|
||||||
switch (actionType) {
|
switch (actionType) {
|
||||||
case 'currency':
|
case 'currency':
|
||||||
@ -74,8 +74,7 @@ class SettingsContainer extends Component {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'api':
|
case 'api':
|
||||||
dispatch(setApi(serverList[action]));
|
this._changeApi(action);
|
||||||
setServer(serverList[action]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -83,6 +82,36 @@ class SettingsContainer extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_changeApi = async (action) => {
|
||||||
|
const { dispatch } = this.props;
|
||||||
|
const { serverList } = this.state;
|
||||||
|
const server = serverList[action];
|
||||||
|
let serverResp;
|
||||||
|
|
||||||
|
const client = new Client(server, { timeout: 3000 });
|
||||||
|
|
||||||
|
try {
|
||||||
|
serverResp = await client.database.getDynamicGlobalProperties();
|
||||||
|
} catch (e) {
|
||||||
|
alert(e);
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
alert('done');
|
||||||
|
}
|
||||||
|
|
||||||
|
const localTime = new Date(new Date().toISOString().split('.')[0]);
|
||||||
|
const serverTime = new Date(serverResp.time);
|
||||||
|
const isAlive = localTime - serverTime < 15000;
|
||||||
|
|
||||||
|
if (!isAlive) {
|
||||||
|
alert("server not alive");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(setApi(server));
|
||||||
|
setServer(server);
|
||||||
|
};
|
||||||
|
|
||||||
_currencyChange = (action) => {
|
_currencyChange = (action) => {
|
||||||
const { dispatch } = this.props;
|
const { dispatch } = this.props;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user