Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add component for selecting rpc #230

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 44 additions & 12 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"helmet": {
"directives": {
"childSrc": "'self'",
"connectSrc":
"'self' steemit.com https://api.steemit.com https://testnet.steemitdev.com www.googletagmanager.com www.google-analytics.com pagead2.googlesyndication.com googleads.g.doubleclick.net api.trongrid.io",
"connectSrc": "'self' steemit.com https://api.steemit.com https://testnet.steemitdev.com www.googletagmanager.com www.google-analytics.com pagead2.googlesyndication.com googleads.g.doubleclick.net api.trongrid.io",
"defaultSrc": "'self'",
"fontSrc": "data: fonts.gstatic.com",
"frameAncestors": "'none'",
Expand All @@ -21,7 +20,7 @@
"reportOnly": false,
"setAllHeaders": true
},
"img_proxy_prefix": "https://steemitdevimages.com/",
"img_proxy_prefix": "https://steemitimages.com/",
"ipfs_prefix": false,
"mixpanel": false,
"newrelic": false,
Expand Down Expand Up @@ -72,29 +71,62 @@
"upload_image": false,
"steemd_connection_client": "https://api.steemit.com",
"steemd_connection_server": "https://api.steemit.com",
"rpc_list": [
"https://api.steemit.com",
"https://api.steemitdev.com",
"https://api.steem.fans",
"https://steem.61bts.com",
"https://api.steemyy.com",
"https://cn.steems.top",
"https://api.steems.top",
"https://api.wherein.io",
"https://justyy.azurewebsites.net/api/steem",
"https://api.justyy.com",
"https://steemapi.boylikegirl.club",
"https://api.steem.buzz",
"https://api.futureshock.world",
"https://api.worldofxpilar.com"
// "https://api.pennsif.net",
// "https://api.upvu.org",
// "https://api.supporter.dev",
// "https://steemyy.com/node/",
// "https://api.dlike.io",
// "https://api.steem-fanbase.com",
// "https://fullsteem.3dkrender.com",
// "https://api.steemzzang.com",
// "https://api.symbionts.io",
// "https://steemd.steemworld.org",
// "https://api.steememory.com",
// "https://api.cotina.org",
// "https://steemapi.3dkrender.com",
// "https://api.protoss20.com",
// "https://rpc.amarbangla.net",
// "https://steem.senior.workers.dev",
// "https://api.campingclub.me",
// "https://api.blokfield.io"
],
"steemd_use_appbase": false,
"chain_id":
"0000000000000000000000000000000000000000000000000000000000000000",
"chain_id": "0000000000000000000000000000000000000000000000000000000000000000",
"address_prefix": "STM",
"conveyor_posting_wif": false,
"conveyor_username": false,
"social_url": "https://steemit.com",
"tron_reward": {
"switch": "on",
"vests_per_trx": 10000,
"unbind_tip_limit": 5
"switch": "on",
"vests_per_trx": 10000,
"unbind_tip_limit": 5
},
"redis_url": "redis://127.0.0.1:6379",
"redis_env": "develop",
"tron_create_key": "ade06c9d42d42c7e24bf93dcbb0a481193a6869400ddee21855d4cf585eaad8a",
"tron_create_node": "https://api.shasta.trongrid.io",
"tron_create_address":"xxxxx",
"white_list":"steemit.com localhost steemit-sdc 127.0.0.1",
"tron_create_address": "xxxxx",
"white_list": "steemit.com localhost steemit-sdc 127.0.0.1",
"steem_market_endpoint": "http://34.196.9.171",
"steem_market_token": "xxxx",
"steem_market_cache": {
"ttl": 7200,
"key": "steem-market"
"ttl": 7200,
"key": "steem-market"
},
"internal_api_token": "xxxx",
"steem_whale": 10000,
Expand Down
12 changes: 11 additions & 1 deletion src/app/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,18 @@ function runApp(initial_state) {
console.log('Initial state', initial_state);

const config = initial_state.offchain.config;

const steemSelectedRpc = localStorage.getItem('steemSelectedRpc');

if (!steemSelectedRpc) {
localStorage.setItem(
'steemSelectedRpc',
config.steemd_connection_client
);
}

steem.api.setOptions({
url: config.steemd_connection_client,
url: steemSelectedRpc || config.steemd_connection_client,
retry: true,
useAppbaseApi: !!config.steemd_use_appbase,
});
Expand Down
83 changes: 82 additions & 1 deletion src/app/components/modules/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,61 @@ import React from 'react';
import { connect } from 'react-redux';
import tt from 'counterpart';
import * as appActions from 'app/redux/AppReducer';
import o2j from 'shared/clash/object2json';
import * as steem from '@steemit/steem-js';

class Settings extends React.Component {
constructor(props) {
super();

this.state = {
rpcNode:
(props.user_preferences &&
props.user_preferences.selectedRpc) ||
$STM_Config.steemd_connection_client,
rpcError: '',
};
}

validateUrlFormat(url) {
if (!url) return false;
if (
!/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/.test(
url
)
)
return false;
return true;
}

handleSelectRPCNode = event => {
const selectedUrl = event.target.value;

if (this.validateUrlFormat(selectedUrl) === false) {
this.setState({
rpcError: tt('settings_jsx.invalid_url'),
});
return;
} else {
this.setState({
rpcNode: selectedUrl,
rpcError: '',
});
}

this.props.setUserPreferences({
...this.props.user_preferences,
selectedRpc: selectedUrl,
});

// Store RPC Node in localStorage
localStorage.setItem('steemSelectedRpc', selectedUrl);

// Set at the same time as selection
steem.api.setOptions({
url: selectedUrl,
});
};

handleLanguageChange = event => {
const locale = event.target.value;
const userPreferences = { ...this.props.user_preferences, locale };
Expand All @@ -13,8 +65,37 @@ class Settings extends React.Component {

render() {
const { user_preferences } = this.props;

const { rpcNode, rpcError } = this.state;
return (
<div className="Settings">
<div className="row">
<div className="small-12 medium-4 large-4 columns">
<br />
<br />
<h4>{tt('settings_jsx.rpc_title')}</h4>

<label>{tt('settings_jsx.rpc_select')}</label>
<select
defaultValue={rpcNode}
onChange={this.handleSelectRPCNode}
>
{$STM_Config.steemd_rpc_list.map(rpc => (
<option key={rpc} value={rpc}>
{rpc}
</option>
))}
</select>
<label>
{rpcError ||
tt('settings_jsx.selected_rpc', {
rpc: rpcNode,
})}
</label>
<br />
<br />
</div>
</div>
<div className="row">
<div className="small-12 medium-6 large-4 columns">
<h4>{tt('settings_jsx.preferences')}</h4>
Expand Down
5 changes: 4 additions & 1 deletion src/app/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,10 @@
"profile_about": "About",
"profile_location": "Location",
"profile_website": "Website",
"saved": "Saved!"
"saved": "Saved!",
"rpc_title": "RPC Node List",
"rpc_select": "Select RPC Node",
"selected_rpc": "Selected RPC Node : %(rpc)s"
},
"transfer_jsx": {
"amount_is_in_form": "Amount is in the form 99999.999",
Expand Down
6 changes: 5 additions & 1 deletion src/app/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,11 @@
"profile_name": "Nombre de visualización",
"profile_about": "Sobre",
"profile_location": "Localización",
"profile_website": "Página Web"
"profile_website": "Página Web",
"saved": "salvado!",
"rpc_title": "RPC Node List",
"rpc_select": "RPC Node seleccionar",
"selected_rpc": "seleccionar RPC Node : %(rpc)s"
},
"transfer_jsx": {
"amount_is_in_form": "La cantidad está en el formato 99999.999",
Expand Down
6 changes: 5 additions & 1 deletion src/app/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,11 @@
"profile_name": "Nom à afficher",
"profile_about": "A propos",
"profile_location": "Lieu",
"profile_website": "Site internet"
"profile_website": "Site internet",
"saved": "enregistré!",
"rpc_title": "RPC Node List",
"rpc_select": "RPC Node sélectionner",
"selected_rpc": "sélectionner RPC Node : %(rpc)s"
},
"transfer_jsx": {
"amount_is_in_form": "Montant dans le format 99999.999",
Expand Down
6 changes: 5 additions & 1 deletion src/app/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,11 @@
"profile_name": "Mostra nome",
"profile_about": "About",
"profile_location": "Località",
"profile_website": "Sito"
"profile_website": "Sito",
"saved": "salvato!",
"rpc_title": "RPC Node List",
"rpc_select": "RPC Node Selezionare",
"selected_rpc": "Selezionare RPC Node : %(rpc)s"
},
"transfer_jsx": {
"amount_is_in_form": "La quantita deve essere della forma 99999.999",
Expand Down
6 changes: 5 additions & 1 deletion src/app/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,11 @@
"profile_name": "表示名",
"profile_about": "概要",
"profile_location": "場所",
"profile_website": "ウェブサイト"
"profile_website": "ウェブサイト",
"saved": "保存済み!",
"rpc_title": "RPC Node List",
"rpc_select": "RPC Node 選択",
"selected_rpc": "選択 RPC Node : %(rpc)s"
},
"transfer_jsx": {
"amount_is_in_form": "金額は99999.999の形式です",
Expand Down
6 changes: 5 additions & 1 deletion src/app/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,11 @@
"profile_name": "닉네임",
"profile_about": "한 줄 소개",
"profile_location": "지역",
"profile_website": "웹사이트"
"profile_website": "웹사이트",
"saved": "저장됨!",
"rpc_title": "RPC Node List",
"rpc_select": "RPC Node 선택",
"selected_rpc": "선택된 RPC Node : %(rpc)s"
},
"transfer_jsx": {
"amount_is_in_form": "Amount is in the form 99999.999",
Expand Down
6 changes: 5 additions & 1 deletion src/app/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,11 @@
"profile_name": "Wyświetlana nazwa",
"profile_about": "Opis",
"profile_location": "Lokalizacja",
"profile_website": "Strona www"
"profile_website": "Strona www",
"saved": "zapisane!",
"rpc_title": "RPC Node List",
"rpc_select": "RPC Node wybierać",
"selected_rpc": "Wybrany RPC Node : %(rpc)s"
},
"transfer_jsx": {
"amount_is_in_form": "Podana kwota musi być w formacie 99999.999",
Expand Down
6 changes: 5 additions & 1 deletion src/app/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,11 @@
"profile_name": "Отображаемое имя",
"profile_about": "О себе",
"profile_location": "Местоположение",
"profile_website": "Веб-сайт"
"profile_website": "Веб-сайт",
"saved": "сохранен!",
"rpc_title": "RPC Node List",
"rpc_select": "RPC Node выбирать",
"selected_rpc": "выбран RPC Node : %(rpc)s"
},
"transfer_jsx": {
"amount_is_in_form": "Сумма должна быть в формате 99999.999",
Expand Down
6 changes: 5 additions & 1 deletion src/app/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,11 @@
"profile_name": "显示名称",
"profile_about": "关于",
"profile_location": "位置",
"profile_website": "网站"
"profile_website": "网站",
"saved": "已保存",
"rpc_title": "RPC Node List",
"rpc_select": "RPC Node 选择",
"selected_rpc": "选择 RPC Node : %(rpc)s"
},
"transfer_jsx": {
"amount_is_in_form": "金额以99999.999的形式出现",
Expand Down
1 change: 1 addition & 0 deletions src/app/redux/AppReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const defaultState = Map({
user_preferences: Map({
locale: null,
nightmode: false,
selectedRpc: '',
}),
featureFlags: Map({}),
modalLoading: false,
Expand Down
1 change: 1 addition & 0 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ global.$STM_Config = {
fb_app: config.get('facebook_app_id'),
steemd_connection_client: config.get('steemd_connection_client'),
steemd_connection_server: config.get('steemd_connection_server'),
steemd_rpc_list: config.get('rpc_list'),
steemd_use_appbase: config.get('steemd_use_appbase'),
chain_id: config.get('chain_id'),
address_prefix: config.get('address_prefix'),
Expand Down