Commit f34933a4 authored by Jason Salyers's avatar Jason Salyers Committed by roeland lanparty
Browse files

[JES] Add options for new failover stuff. Add option for user to specify a preferred endpoint

parent c5e1c06d
......@@ -4,7 +4,7 @@
"helmet": {
"directives": {
"childSrc": "'self' 3speak.online emb.d.tube player.twitch.tv www.youtube.com staticxx.facebook.com w.soundcloud.com player.vimeo.com",
"connectSrc": "https://images.hive.blog 'self' hive.blog https://api.hive.blog api.blocktrades.us",
"connectSrc": "https://images.hive.blog 'self' hive.blog https://api.hive.blog api.blocktrades.us https://anyx.io",
"defaultSrc": "tpc.googlesyndication.com 'self' img.3speakcontent.online emb.d.tube www.youtube.com staticxx.facebook.com player.vimeo.com *.streamrail.com",
"fontSrc": "data: fonts.gstatic.com",
"frameAncestors": "'none'",
......@@ -39,6 +39,8 @@
"steemd_connection_server": "https://api.hive.blog",
"steemd_use_appbase": false,
"chain_id": "0000000000000000000000000000000000000000000000000000000000000000",
"alternative_api_endpoints": ["https://api.hive.blog", "https://anyx.io"],
"failover_threshold": 3,
"address_prefix": "STM",
"conveyor_posting_wif": false,
"conveyor_username": false,
......
......@@ -19,7 +19,7 @@ services:
SDC_IMAGE_PROXY_PREFIX: https://images.hive.blog/
SDC_UPLOAD_IMAGE_URL: https://images.hive.blog
SDC_HELMET_CONNECTSRC: "'self' http://hiveblog.local https://api.hive.blog https://images.hive.blog"
SDC_HELMET_CONNECTSRC: "'self' http://hiveblog.local https://api.hive.blog https://images.hive.blog https://anyx.io"
volumes:
- ./yarn.lock:/var/app/yarn.lock
- ./package.json:/var/app/package.json
......
......@@ -24,7 +24,7 @@
"license": "MIT",
"dependencies": {
"@hivechain/hivescript": "^1.1.3",
"@hiveio/hive-js": "0.0.1",
"@hiveio/hive-js": "^0.0.2",
"@steem/crypto-session": "git+https://github.com/steemit/crypto-session.git#83a90b319ce5bc6a70362d52a15a815de7e729bb",
"assert": "1.4.1",
"autoprefixer-loader": "3.2.0",
......
......@@ -85,12 +85,22 @@ function runApp(initial_state) {
const config = initial_state.offchain.config;
steem.api.setOptions({
url: config.steemd_connection_client,
url:
localStorage.getItem('user_preferred_api_endpoint') === null
? config.steemd_connection_client
: localStorage.getItem('user_preferred_api_endpoint'),
retry: true,
useAppbaseApi: !!config.steemd_use_appbase,
alternative_api_endpoints: config.alternative_api_endpoints,
failover_threshold: config.failover_threshold,
});
steem.config.set('address_prefix', config.address_prefix);
steem.config.set('chain_id', config.chain_id);
steem.config.set('failover_threshold', config.failover_threshold);
steem.config.set(
'alternative_api_endpoints',
config.alternative_api_endpoints
);
window.$STM_Config = config;
plugins(config);
if (initial_state.offchain.serverBusy) {
......
......@@ -10,6 +10,7 @@ import reactForm from 'app/utils/ReactForm';
import Dropzone from 'react-dropzone';
import MuteList from 'app/components/elements/MuteList';
import { isLoggedIn } from 'app/utils/UserUtil';
import * as api from '@hiveio/hive-js';
class Settings extends React.Component {
constructor(props) {
......@@ -232,6 +233,36 @@ class Settings extends React.Component {
this.props.setUserPreferences(userPreferences);
};
generateAPIEndpointOptions = () => {
let endpoints = api.config.get('alternative_api_endpoints');
let preferred_api_endpoint = '';
if (typeof window !== 'undefined')
preferred_api_endpoint =
localStorage.getItem('user_preferred_api_endpoint') === null
? 'https://api.hive.blog'
: localStorage.getItem('user_preferred_api_endpoint');
if (endpoints === null || endpoints === undefined) {
return null;
}
let entries = [];
for (var endpoint of endpoints) {
if (endpoint === preferred_api_endpoint) continue; //this one is always present even if the api config call fails
let entry = <option value={endpoint}>{endpoint}</option>;
entries.push(entry);
}
return entries;
};
handlePreferredAPIEndpointChange = event => {
if (typeof window !== 'undefined') {
localStorage.setItem(
'user_preferred_api_endpoint',
event.target.value
);
api.api.setOptions({ url: event.target.value });
}
};
render() {
const { state, props } = this;
const {
......@@ -261,6 +292,14 @@ class Settings extends React.Component {
progress,
} = this.state;
let preferred_api_endpoint = 'https://api.hive.blog';
if (typeof window !== 'undefined') {
preferred_api_endpoint =
localStorage.getItem('user_preferred_api_endpoint') === null
? 'https://api.hive.blog'
: localStorage.getItem('user_preferred_api_endpoint');
}
return (
<div className="Settings">
<div className="row">
......@@ -511,6 +550,24 @@ class Settings extends React.Component {
</option>
</select>
</label>
<label>
{tt(
'settings_jsx.choose_preferred_api_endpoint'
)}
<select
defaultValue={preferred_api_endpoint}
onChange={
this.handlePreferredAPIEndpointChange
}
>
<option value={preferred_api_endpoint}>
{preferred_api_endpoint}
</option>
{this.generateAPIEndpointOptions()}
</select>
</label>
<br />
</div>
</div>
......
......@@ -712,7 +712,8 @@
"profile_about": "About",
"profile_location": "Location",
"profile_website": "Website",
"saved": "Saved!"
"saved": "Saved!",
"choose_preferred_api_endpoint": "Choose Your Preferred API Node"
},
"transfer_jsx": {
"amount_is_in_form": "Amount is in the form 99999.999",
......
......@@ -623,7 +623,8 @@
"profile_name": "Nombre de visualización",
"profile_about": "Sobre",
"profile_location": "Localización",
"profile_website": "Página Web"
"profile_website": "Página Web",
"choose_preferred_api_endpoint": "Elija su nodo de API preferido"
},
"transfer_jsx": {
"amount_is_in_form": "La cantidad está en el formato 99999.999",
......
......@@ -645,7 +645,8 @@
"profile_name": "Nom à afficher",
"profile_about": "A propos",
"profile_location": "Lieu",
"profile_website": "Site internet"
"profile_website": "Site internet",
"choose_preferred_api_endpoint": "Choisissez votre nœud d'API préféré"
},
"transfer_jsx": {
"amount_is_in_form": "Montant dans le format 99999.999",
......
......@@ -630,7 +630,8 @@
"profile_name": "Mostra nome",
"profile_about": "About",
"profile_location": "Località",
"profile_website": "Sito"
"profile_website": "Sito",
"choose_preferred_api_endpoint": "Scegli il tuo nodo API preferito"
},
"transfer_jsx": {
"amount_is_in_form": "La quantita deve essere della forma 99999.999",
......
......@@ -627,7 +627,8 @@
"profile_name": "表示名",
"profile_about": "概要",
"profile_location": "場所",
"profile_website": "ウェブサイト"
"profile_website": "ウェブサイト",
"choose_preferred_api_endpoint": "優先APIノードを選択してください"
},
"transfer_jsx": {
"amount_is_in_form": "金額は99999.999の形式です",
......
......@@ -625,7 +625,8 @@
"profile_name": "닉네임",
"profile_about": "한 줄 소개",
"profile_location": "지역",
"profile_website": "웹사이트"
"profile_website": "웹사이트",
"choose_preferred_api_endpoint": "기본 API 노드 선택"
},
"transfer_jsx": {
"amount_is_in_form": "Amount is in the form 99999.999",
......
......@@ -724,7 +724,8 @@
"profile_about": "Opis",
"profile_location": "Lokalizacja",
"profile_website": "Strona www",
"saved": "Zapisano!"
"saved": "Zapisano!",
"choose_preferred_api_endpoint": "Wybierz preferowany węzeł API"
},
"transfer_jsx": {
"amount_is_in_form": "Podana kwota musi być w formacie 99999.999",
......
......@@ -648,7 +648,9 @@
"profile_name": "Отображаемое имя",
"profile_about": "О себе",
"profile_location": "Местоположение",
"profile_website": "Веб-сайт"
"profile_website": "Веб-сайт",
"choose_preferred_api_endpoint":
"Выберите свой предпочтительный узел API"
},
"transfer_jsx": {
"amount_is_in_form": "Сумма должна быть в формате 99999.999",
......
......@@ -574,7 +574,8 @@
"profile_name": "显示名称",
"profile_about": "关于",
"profile_location": "位置",
"profile_website": "网站"
"profile_website": "网站",
"choose_preferred_api_endpoint": "选择您的首选API节点"
},
"transfer_jsx": {
"amount_is_in_form": "金额以99999.999的形式出现",
......
......@@ -30,6 +30,8 @@ global.$STM_Config = {
site_domain: config.get('site_domain'),
google_analytics_id: config.get('google_analytics_id'),
wallet_url: config.get('wallet_url'),
failover_threshold: config.get('failover_threshold'),
alternative_api_endpoints: config.get('alternative_api_endpoints'),
};
const WebpackIsomorphicTools = require('webpack-isomorphic-tools');
......@@ -50,9 +52,16 @@ global.webpackIsomorphicTools.server(ROOT, () => {
randomize: true,
},
useAppbaseApi: !!config.steemd_use_appbase,
alternative_api_endpoints: config.get('alternative_api_endpoints'),
failover_threshold: config.get('failover_threshold'),
});
steem.config.set('address_prefix', config.get('address_prefix'));
steem.config.set('chain_id', config.get('chain_id'));
steem.config.set(
'alternative_api_endpoints',
config.get('alternative_api_endpoints')
);
steem.config.set('failover_threshold', config.get('failover_threshold'));
// const CliWalletClient = require('shared/api_client/CliWalletClient').default;
// if (process.env.NODE_ENV === 'production') connect_promises.push(CliWalletClient.instance().connect_promise());
......
......@@ -15,10 +15,10 @@
resolved "https://registry.yarnpkg.com/@hivechain/hivescript/-/hivescript-1.1.3.tgz#9142447cba2edfe7cb08c50ecefa9a8d87983570"
integrity sha512-B3JeGq/SXbQdFZCvw5m0cpjXR61i8oclx7XuQq/pv/Y64e/sYzE0FMnGee3LFB7iKd3r+q77U+dZLXu9cT9dpg==
"@hiveio/hive-js@0.0.1":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@hiveio/hive-js/-/hive-js-0.0.1.tgz#2acdce5550adc3f2cc23cb3aad17539360770549"
integrity sha512-aFX58gzLzZvZnPJdEafGRkVYNwQY6Lfqqr5yjr/yFNRXahPd2+m/f/n0e84R894DXB1HcgYASsxR/VwOpNscVg==
"@hiveio/hive-js@^0.0.2":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@hiveio/hive-js/-/hive-js-0.0.2.tgz#6f4a6fa133a1528534d410ad5f9bd4fee2b738aa"
integrity sha512-eHNAuYynOTXLTNBpftKEu3raWc2Ot6kj5Fti2OkQdSZaFFryl0hwjI8pH8fTmFnOg7YULOFonYs1Zo+4qhOMeQ==
dependencies:
"@steemit/rpc-auth" "^1.1.1"
bigi "^1.4.2"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment