diff --git a/config/default.json b/config/default.json index 292cd9e5..7ef011fc 100644 --- a/config/default.json +++ b/config/default.json @@ -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'", @@ -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, @@ -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, diff --git a/src/app/Main.js b/src/app/Main.js index f86a8219..2256c701 100644 --- a/src/app/Main.js +++ b/src/app/Main.js @@ -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, }); diff --git a/src/app/components/modules/Settings.jsx b/src/app/components/modules/Settings.jsx index f4464d36..ae22d08c 100644 --- a/src/app/components/modules/Settings.jsx +++ b/src/app/components/modules/Settings.jsx @@ -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 }; @@ -13,8 +65,37 @@ class Settings extends React.Component { render() { const { user_preferences } = this.props; + + const { rpcNode, rpcError } = this.state; return (