mirror of
https://github.com/ecency/ecency-mobile.git
synced 2025-01-03 03:25:24 +03:00
failover rpc
This commit is contained in:
parent
05d669d2ff
commit
01c91adf44
@ -23,7 +23,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.5.5",
|
||||
"@esteemapp/dsteem": "^0.11.5",
|
||||
"@esteemapp/dhive": "^0.11.6",
|
||||
"@esteemapp/esteem-render-helpers": "^1.3.8",
|
||||
"@esteemapp/react-native-autocomplete-input": "^4.2.1",
|
||||
"@esteemapp/react-native-modal-popover": "^0.0.15",
|
||||
@ -44,7 +44,7 @@
|
||||
"crypto-js": "^3.1.9-1",
|
||||
"currency-symbol-map": "^4.0.4",
|
||||
"diff-match-patch": "^1.0.4",
|
||||
"hivesigner": "^3.1.4",
|
||||
"hivesigner": "^3.1.5",
|
||||
"intl": "^1.2.5",
|
||||
"jsc-android": "^241213.1.0",
|
||||
"lodash": "^4.17.13",
|
||||
|
@ -2,7 +2,7 @@ import React, { PureComponent } from 'react';
|
||||
import { withNavigation } from 'react-navigation';
|
||||
|
||||
// Services and Actions
|
||||
import { getCommunity } from '../../../../providers/esteem/esteem';
|
||||
import { getCommunity } from '../../../../providers/steem/dsteem';
|
||||
// Middleware
|
||||
|
||||
// Constants
|
||||
@ -31,10 +31,12 @@ class TagContainer extends PureComponent {
|
||||
componentDidMount() {
|
||||
const { value } = this.props;
|
||||
|
||||
if (value.startsWith('hive-')) {
|
||||
if (value.startsWith('hive-1')) {
|
||||
getCommunity(value)
|
||||
.then((r) => {
|
||||
this.setState({ label: r });
|
||||
this.setState({
|
||||
label: r,
|
||||
});
|
||||
return r;
|
||||
})
|
||||
.catch(() => {});
|
||||
|
@ -416,7 +416,7 @@ export const getCommunity = (tag) =>
|
||||
}
|
||||
|
||||
axios
|
||||
.post('https://rpc.esteem.app', {
|
||||
.post('https://api.hive.blog', {
|
||||
jsonrpc: '2.0',
|
||||
method: 'bridge.get_community',
|
||||
params: {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as dsteem from '@esteemapp/dsteem';
|
||||
import * as dsteem from '@esteemapp/dhive';
|
||||
import sha256 from 'crypto-js/sha256';
|
||||
import Config from 'react-native-config';
|
||||
import get from 'lodash/get';
|
||||
|
@ -2,10 +2,11 @@
|
||||
// import '../../../shim';
|
||||
// import * as bitcoin from 'bitcoinjs-lib';
|
||||
|
||||
import { Client, PrivateKey } from '@esteemapp/dsteem';
|
||||
import { Client, PrivateKey } from '@esteemapp/dhive';
|
||||
import hivesigner from 'hivesigner';
|
||||
import Config from 'react-native-config';
|
||||
import { get, has } from 'lodash';
|
||||
import axios from 'axios';
|
||||
import { getServer } from '../../realm/realm';
|
||||
import { getUnreadActivityCount } from '../esteem/esteem';
|
||||
import { userActivity } from '../esteem/ePoint';
|
||||
@ -23,19 +24,28 @@ import { getDsteemDateErrorMessage } from '../../utils/dsteemUtils';
|
||||
// Constant
|
||||
import AUTH_TYPE from '../../constants/authType';
|
||||
|
||||
const DEFAULT_SERVER = 'https://rpc.esteem.app';
|
||||
let client = new Client(DEFAULT_SERVER);
|
||||
const DEFAULT_SERVER = [
|
||||
'https://rpc.esteem.app',
|
||||
'https://api.hive.blog',
|
||||
'https://anyx.io',
|
||||
'https://api.hivekings.com',
|
||||
];
|
||||
let client = new Client(DEFAULT_SERVER, {
|
||||
timeout: 3000,
|
||||
});
|
||||
|
||||
export const checkClient = async () => {
|
||||
let selectedServer = DEFAULT_SERVER;
|
||||
|
||||
await getServer().then((response) => {
|
||||
if (response) {
|
||||
selectedServer = response;
|
||||
selectedServer.unshift(response);
|
||||
}
|
||||
});
|
||||
|
||||
client = new Client(selectedServer);
|
||||
client = new Client(selectedServer, {
|
||||
timeout: 3000,
|
||||
});
|
||||
};
|
||||
|
||||
checkClient();
|
||||
@ -182,6 +192,40 @@ export const getUser = async (user) => {
|
||||
}
|
||||
};
|
||||
|
||||
const cache = {};
|
||||
const patt = /hive-\d\w+/g;
|
||||
export const getCommunity = async (tag) =>
|
||||
new Promise(async (resolve, reject) => {
|
||||
if (cache[tag] !== undefined) {
|
||||
resolve(cache[tag]);
|
||||
return;
|
||||
}
|
||||
console.log(tag);
|
||||
if (tag.match(patt).length > 0) {
|
||||
try {
|
||||
console.log('m', tag);
|
||||
const community = await client.call('bridge', 'get_community', {
|
||||
name: tag,
|
||||
observer: '',
|
||||
});
|
||||
console.log(community);
|
||||
if (community) {
|
||||
console.log('parsed tag');
|
||||
const { title } = community;
|
||||
cache[tag] = title;
|
||||
resolve(title);
|
||||
} else {
|
||||
console.log('plain tag');
|
||||
resolve(tag);
|
||||
}
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}
|
||||
|
||||
resolve(tag);
|
||||
});
|
||||
|
||||
// TODO: Move to utils folder
|
||||
export const vestToSteem = async (vestingShares, totalVestingShares, totalVestingFundSteem) =>
|
||||
(
|
||||
|
@ -126,7 +126,15 @@ class ApplicationContainer extends Component {
|
||||
const { isGlobalRenderRequired, dispatch } = this.props;
|
||||
|
||||
if (isGlobalRenderRequired !== prevProps.isGlobalRenderRequired && isGlobalRenderRequired) {
|
||||
this.setState({ isRenderRequire: false }, () => this.setState({ isRenderRequire: true }));
|
||||
this.setState(
|
||||
{
|
||||
isRenderRequire: false,
|
||||
},
|
||||
() =>
|
||||
this.setState({
|
||||
isRenderRequire: true,
|
||||
}),
|
||||
);
|
||||
dispatch(isRenderRequired(false));
|
||||
}
|
||||
}
|
||||
@ -182,11 +190,16 @@ class ApplicationContainer extends Component {
|
||||
if (permlink) {
|
||||
content = await getPost(author, permlink, currentAccount.name);
|
||||
routeName = ROUTES.SCREENS.POST;
|
||||
params = { content };
|
||||
params = {
|
||||
content,
|
||||
};
|
||||
} else {
|
||||
profile = await getUser(author);
|
||||
routeName = ROUTES.SCREENS.PROFILE;
|
||||
params = { username: get(profile, 'name'), reputation: get(profile, 'reputation') };
|
||||
params = {
|
||||
username: get(profile, 'name'),
|
||||
reputation: get(profile, 'reputation'),
|
||||
};
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@ -206,8 +219,12 @@ class ApplicationContainer extends Component {
|
||||
const { intl } = this.props;
|
||||
|
||||
Alert.alert(
|
||||
intl.formatMessage({ id: title || 'alert.warning' }),
|
||||
intl.formatMessage({ id: text || 'alert.unknow_error' }),
|
||||
intl.formatMessage({
|
||||
id: title || 'alert.warning',
|
||||
}),
|
||||
intl.formatMessage({
|
||||
id: text || 'alert.unknow_error',
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
@ -231,7 +248,9 @@ class ApplicationContainer extends Component {
|
||||
this._refreshGlobalProps();
|
||||
}
|
||||
setPreviousAppState();
|
||||
this.setState({ appState: nextAppState });
|
||||
this.setState({
|
||||
appState: nextAppState,
|
||||
});
|
||||
};
|
||||
|
||||
_startPinCodeTimer = () => {
|
||||
@ -248,7 +267,9 @@ class ApplicationContainer extends Component {
|
||||
await this._getSettings();
|
||||
await this._refreshGlobalProps();
|
||||
const userRealmObject = await this._getUserDataFromRealm();
|
||||
this.setState({ isReady: true });
|
||||
this.setState({
|
||||
isReady: true,
|
||||
});
|
||||
|
||||
const { isConnected } = this.props;
|
||||
if (isConnected && userRealmObject) {
|
||||
@ -329,7 +350,9 @@ class ApplicationContainer extends Component {
|
||||
|
||||
case 'transfer':
|
||||
routeName = ROUTES.TABBAR.PROFILE;
|
||||
params = { activePage: 2 };
|
||||
params = {
|
||||
activePage: 2,
|
||||
};
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -401,7 +424,9 @@ class ApplicationContainer extends Component {
|
||||
dispatch(login(false));
|
||||
dispatch(logoutDone());
|
||||
removePinCode();
|
||||
setAuthStatus({ isLoggedIn: false });
|
||||
setAuthStatus({
|
||||
isLoggedIn: false,
|
||||
});
|
||||
setExistUser(false);
|
||||
if (accountData.authType === AUTH_TYPE.STEEM_CONNECT) {
|
||||
removeSCAccount(accountData.username);
|
||||
@ -409,7 +434,11 @@ class ApplicationContainer extends Component {
|
||||
}
|
||||
removeUserData(accountData.username);
|
||||
} else {
|
||||
dispatch(addOtherAccount({ username: accountData.username }));
|
||||
dispatch(
|
||||
addOtherAccount({
|
||||
username: accountData.username,
|
||||
}),
|
||||
);
|
||||
// TODO: check post v2.2.5+ or remove setexistuser from login
|
||||
setExistUser(true);
|
||||
}
|
||||
@ -462,6 +491,7 @@ class ApplicationContainer extends Component {
|
||||
this._connectNotificationServer(accountData.name);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
Alert.alert(
|
||||
`${intl.formatMessage({ id: 'alert.fetch_error' })} \n${err.message.substr(0, 20)}`,
|
||||
);
|
||||
@ -479,7 +509,9 @@ class ApplicationContainer extends Component {
|
||||
settings.isDarkTheme === null ? nativeThemeInitialMode === 'dark' : settings.isDarkTheme,
|
||||
),
|
||||
);
|
||||
this.setState({ isThemeReady: true });
|
||||
this.setState({
|
||||
isThemeReady: true,
|
||||
});
|
||||
if (settings.isPinCodeOpen !== '') dispatch(isPinCodeOpen(settings.isPinCodeOpen));
|
||||
if (settings.language !== '') dispatch(setLanguage(settings.language));
|
||||
if (settings.server !== '') dispatch(setApi(settings.server));
|
||||
@ -489,7 +521,10 @@ class ApplicationContainer extends Component {
|
||||
if (settings.isDefaultFooter !== '') dispatch(isDefaultFooter(settings.isDefaultFooter));
|
||||
if (settings.notification !== '') {
|
||||
dispatch(
|
||||
changeNotificationSettings({ type: 'notification', action: settings.notification }),
|
||||
changeNotificationSettings({
|
||||
type: 'notification',
|
||||
action: settings.notification,
|
||||
}),
|
||||
);
|
||||
dispatch(changeAllNotificationSettings(settings));
|
||||
|
||||
@ -542,7 +577,9 @@ class ApplicationContainer extends Component {
|
||||
dispatch(updateCurrentAccount({}));
|
||||
dispatch(login(false));
|
||||
removePinCode();
|
||||
setAuthStatus({ isLoggedIn: false });
|
||||
setAuthStatus({
|
||||
isLoggedIn: false,
|
||||
});
|
||||
setExistUser(false);
|
||||
if (local === AUTH_TYPE.STEEM_CONNECT) {
|
||||
removeSCAccount(name);
|
||||
@ -553,6 +590,7 @@ class ApplicationContainer extends Component {
|
||||
dispatch(logoutDone());
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('remove', err);
|
||||
Alert.alert(
|
||||
`${intl.formatMessage({ id: 'alert.fetch_error' })} \n${err.message.substr(0, 20)}`,
|
||||
);
|
||||
@ -600,7 +638,15 @@ class ApplicationContainer extends Component {
|
||||
selectedLanguage !== nextProps.selectedLanguage ||
|
||||
(api !== nextProps.api && nextProps.api)
|
||||
) {
|
||||
this.setState({ isRenderRequire: false }, () => this.setState({ isRenderRequire: true }));
|
||||
this.setState(
|
||||
{
|
||||
isRenderRequire: false,
|
||||
},
|
||||
() =>
|
||||
this.setState({
|
||||
isRenderRequire: true,
|
||||
}),
|
||||
);
|
||||
if (nextProps.isDarkTheme) {
|
||||
changeNavigationBarColor('#1e2835');
|
||||
} else {
|
||||
@ -678,7 +724,12 @@ export default connect(
|
||||
(dispatch) => ({
|
||||
dispatch,
|
||||
actions: {
|
||||
...bindActionCreators({ fetchGlobalProperties }, dispatch),
|
||||
...bindActionCreators(
|
||||
{
|
||||
fetchGlobalProperties,
|
||||
},
|
||||
dispatch,
|
||||
),
|
||||
},
|
||||
}),
|
||||
)(injectIntl(ApplicationContainer));
|
||||
|
@ -3,7 +3,7 @@ import { Platform } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
import AppCenter from 'appcenter';
|
||||
import Push from 'appcenter-push';
|
||||
import { Client } from '@esteemapp/dsteem';
|
||||
import { Client } from '@esteemapp/dhive';
|
||||
import VersionNumber from 'react-native-version-number';
|
||||
import Config from 'react-native-config';
|
||||
import { injectIntl } from 'react-intl';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import CryptoJS from 'crypto-js';
|
||||
import * as dsteem from '@esteemapp/dsteem';
|
||||
import * as dsteem from '@esteemapp/dhive';
|
||||
import { Buffer } from 'buffer';
|
||||
import { proxifyImageSrc } from '@esteemapp/esteem-render-helpers';
|
||||
|
||||
@ -85,7 +85,7 @@ export const getResizedImage = (url, size = 640) => {
|
||||
return `${url.replace('img.esteem.app/', `img.esteem.app/${size}/`)}`;
|
||||
}
|
||||
*/
|
||||
return `https://avatars.esteem.app/${size}x0/${url}`;
|
||||
return `https://steemitimages.com/${size}x0/${url}`;
|
||||
};
|
||||
|
||||
export const getResizedAvatar = (author, sizeString = 'large') => {
|
||||
|
@ -104,12 +104,6 @@ export const parseComments = async (comments, currentUserName) => {
|
||||
const pArray = comments.map(async (comment) => {
|
||||
const activeVotes = await getActiveVotes(get(comment, 'author'), get(comment, 'permlink'));
|
||||
|
||||
if (comment.body.includes('Posted using [Partiko')) {
|
||||
comment.body = comment.body
|
||||
.split('\n')
|
||||
.filter((item) => item.includes('Posted using [Partiko') === false)
|
||||
.join('\n');
|
||||
}
|
||||
comment.pending_payout_value = parseFloat(get(comment, 'pending_payout_value', 0)).toFixed(3);
|
||||
comment.author_reputation = getReputation(get(comment, 'author_reputation'));
|
||||
comment.avatar = getResizedAvatar(get(comment, 'author'));
|
||||
|
16
yarn.lock
16
yarn.lock
@ -1123,10 +1123,10 @@
|
||||
exec-sh "^0.3.2"
|
||||
minimist "^1.2.0"
|
||||
|
||||
"@esteemapp/dsteem@^0.11.5":
|
||||
version "0.11.5"
|
||||
resolved "https://registry.yarnpkg.com/@esteemapp/dsteem/-/dsteem-0.11.5.tgz#d01e09db1d2dccfd6e82c1e577d1bef4c8e42439"
|
||||
integrity sha512-hAU7R+KigkxnyxLMAFWgUmA3JxBpvvKLZcU3Nb07rkF7Tjd/1tWUpdlVamTGSznRy3gRMA1yMrn5S1c17jx8Aw==
|
||||
"@esteemapp/dhive@^0.11.6":
|
||||
version "0.11.6"
|
||||
resolved "https://registry.yarnpkg.com/@esteemapp/dhive/-/dhive-0.11.6.tgz#d8be50ac44ea67d9bc356b1d1c4f49de42e38c94"
|
||||
integrity sha512-LBO8sWdQJKKrWKb+axLIiXXdk7vcSaPXYCGHwfB2hLEtEAjGam4Xv9fYRNA1QDXjpo3iFQcUitrro9kQ4cTsaw==
|
||||
dependencies:
|
||||
bs58 "^4.0.1"
|
||||
bytebuffer "^5.0.1"
|
||||
@ -4499,10 +4499,10 @@ hive-uri@^0.2.2:
|
||||
resolved "https://registry.yarnpkg.com/hive-uri/-/hive-uri-0.2.2.tgz#60d57a77a2c7a6394471f700e436f3f9822c737d"
|
||||
integrity sha512-95XH50GsJ+ZuWsLQaNcqYiZ6lmoVDawjG+BCgERqOkoy57b+OgHeNDPeYYY9qkNIi0ThcaYRi6RHVcLbI5EfBw==
|
||||
|
||||
hivesigner@^3.1.4:
|
||||
version "3.1.4"
|
||||
resolved "https://registry.yarnpkg.com/hivesigner/-/hivesigner-3.1.4.tgz#20461dd7cf13c1da131b363872c8f9cb726aeee6"
|
||||
integrity sha512-Mb2y1R/5a6+yvBSWC8+ju9NDb9SEZAETj6KNi94D+xoxwxrSMD1JDGCZx1QPqrIjCOSAGuBpMBHel1c+GCSpRg==
|
||||
hivesigner@^3.1.5:
|
||||
version "3.1.5"
|
||||
resolved "https://registry.yarnpkg.com/hivesigner/-/hivesigner-3.1.5.tgz#8226d0634e6a024602a97679dd20f6402edbc271"
|
||||
integrity sha512-amg6YNUA6zZvbQp6y4L7l0aPClvMCuA3QMiinyhWMfM5WsvUQOQT+w88bwImHOQPhXMN35QnIcipbr1EdhC94w==
|
||||
dependencies:
|
||||
babel-runtime "^6.26.0"
|
||||
cross-fetch "^3.0.1"
|
||||
|
Loading…
Reference in New Issue
Block a user