mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-02 11:15:35 +03:00
commit
84fccaed24
@ -9,6 +9,7 @@ import HeaderView from '../view/headerView';
|
|||||||
|
|
||||||
import { AccountContainer, ThemeContainer } from '../../../containers';
|
import { AccountContainer, ThemeContainer } from '../../../containers';
|
||||||
import { hidePostsThumbnails } from '../../../redux/actions/uiAction';
|
import { hidePostsThumbnails } from '../../../redux/actions/uiAction';
|
||||||
|
import { parseReputation } from '../../../utils/user';
|
||||||
|
|
||||||
const HeaderContainer = ({
|
const HeaderContainer = ({
|
||||||
selectedUser,
|
selectedUser,
|
||||||
@ -48,6 +49,7 @@ const HeaderContainer = ({
|
|||||||
{({ currentAccount, isLoggedIn, isLoginDone }) => {
|
{({ currentAccount, isLoggedIn, isLoginDone }) => {
|
||||||
const _user = isReverse && selectedUser ? selectedUser : currentAccount;
|
const _user = isReverse && selectedUser ? selectedUser : currentAccount;
|
||||||
|
|
||||||
|
const reputation = parseReputation(get(_user, 'reputation'));
|
||||||
return (
|
return (
|
||||||
<HeaderView
|
<HeaderView
|
||||||
displayName={get(_user, 'display_name')}
|
displayName={get(_user, 'display_name')}
|
||||||
@ -58,7 +60,7 @@ const HeaderContainer = ({
|
|||||||
isLoggedIn={isLoggedIn}
|
isLoggedIn={isLoggedIn}
|
||||||
isLoginDone={isLoginDone}
|
isLoginDone={isLoginDone}
|
||||||
isReverse={isReverse}
|
isReverse={isReverse}
|
||||||
reputation={get(_user, 'reputation')}
|
reputation={reputation}
|
||||||
username={get(_user, 'name')}
|
username={get(_user, 'name')}
|
||||||
hideUser={hideUser}
|
hideUser={hideUser}
|
||||||
enableViewModeToggle={enableViewModeToggle}
|
enableViewModeToggle={enableViewModeToggle}
|
||||||
|
@ -20,7 +20,7 @@ class PostHeaderDescription extends PureComponent {
|
|||||||
|
|
||||||
// Component Functions
|
// Component Functions
|
||||||
_handleOnUserPress = (username) => {
|
_handleOnUserPress = (username) => {
|
||||||
const { navigation, profileOnPress, reputation, currentAccountUsername } = this.props;
|
const { navigation, profileOnPress, reputation } = this.props;
|
||||||
|
|
||||||
if (profileOnPress) {
|
if (profileOnPress) {
|
||||||
profileOnPress(username);
|
profileOnPress(username);
|
||||||
@ -78,7 +78,6 @@ class PostHeaderDescription extends PureComponent {
|
|||||||
date,
|
date,
|
||||||
isHideImage,
|
isHideImage,
|
||||||
name,
|
name,
|
||||||
reputation,
|
|
||||||
size,
|
size,
|
||||||
tag,
|
tag,
|
||||||
content,
|
content,
|
||||||
@ -98,7 +97,6 @@ class PostHeaderDescription extends PureComponent {
|
|||||||
onPress={() => this._handleOnUserPress(name)}
|
onPress={() => this._handleOnUserPress(name)}
|
||||||
>
|
>
|
||||||
{!isHideImage && (
|
{!isHideImage && (
|
||||||
<>
|
|
||||||
<UserAvatar
|
<UserAvatar
|
||||||
style={[styles.avatar, { width: size, height: size, borderRadius: size / 2 }]}
|
style={[styles.avatar, { width: size, height: size, borderRadius: size / 2 }]}
|
||||||
disableSize
|
disableSize
|
||||||
@ -106,10 +104,6 @@ class PostHeaderDescription extends PureComponent {
|
|||||||
defaultSource={DEFAULT_IMAGE}
|
defaultSource={DEFAULT_IMAGE}
|
||||||
noAction
|
noAction
|
||||||
/>
|
/>
|
||||||
<View style={styles.reputationWrapper}>
|
|
||||||
<Text style={styles.reputation}>{reputation}</Text>
|
|
||||||
</View>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<View style={styles.leftContainer}>
|
<View style={styles.leftContainer}>
|
||||||
|
@ -24,8 +24,7 @@ import { userActivity } from '../ecency/ePoint';
|
|||||||
// Utils
|
// Utils
|
||||||
import { decryptKey } from '../../utils/crypto';
|
import { decryptKey } from '../../utils/crypto';
|
||||||
import { parsePosts, parsePost, parseComments } from '../../utils/postParser';
|
import { parsePosts, parsePost, parseComments } from '../../utils/postParser';
|
||||||
import { getName, getAvatar } from '../../utils/user';
|
import { getName, getAvatar, parseReputation } from '../../utils/user';
|
||||||
import { getReputation } from '../../utils/reputation';
|
|
||||||
import parseToken from '../../utils/parseToken';
|
import parseToken from '../../utils/parseToken';
|
||||||
import parseAsset from '../../utils/parseAsset';
|
import parseAsset from '../../utils/parseAsset';
|
||||||
import filterNsfwPost from '../../utils/filterNsfwPost';
|
import filterNsfwPost from '../../utils/filterNsfwPost';
|
||||||
@ -266,7 +265,7 @@ export const getUser = async (user, loggedIn = true) => {
|
|||||||
getCache('rcPower');
|
getCache('rcPower');
|
||||||
await setCache('rcPower', rcPower);
|
await setCache('rcPower', rcPower);
|
||||||
|
|
||||||
_account.reputation = getReputation(_account.reputation);
|
_account.reputation = parseReputation(_account.reputation);
|
||||||
_account.username = _account.name;
|
_account.username = _account.name;
|
||||||
_account.unread_activity_count = unreadActivityCount;
|
_account.unread_activity_count = unreadActivityCount;
|
||||||
_account.vp_manabar = client.rc.calculateVPMana(_account);
|
_account.vp_manabar = client.rc.calculateVPMana(_account);
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
export default (input) => {
|
|
||||||
if (!input) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input === 0) {
|
|
||||||
return 25;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!input) {
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
let neg = false;
|
|
||||||
|
|
||||||
if (input < 0) {
|
|
||||||
neg = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let reputationLevel = Math.log10(Math.abs(input));
|
|
||||||
reputationLevel = Math.max(reputationLevel - 9, 0);
|
|
||||||
|
|
||||||
if (reputationLevel < 0) {
|
|
||||||
reputationLevel = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (neg) {
|
|
||||||
reputationLevel *= -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
reputationLevel = reputationLevel * 9 + 25;
|
|
||||||
|
|
||||||
return Math.floor(reputationLevel);
|
|
||||||
};
|
|
@ -7,8 +7,8 @@ import FastImage from 'react-native-fast-image';
|
|||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import parseAsset from './parseAsset';
|
import parseAsset from './parseAsset';
|
||||||
import { getReputation } from './reputation';
|
import { getResizedAvatar } from './image';
|
||||||
import { getResizedAvatar, getResizedImage } from './image';
|
import { parseReputation } from './user';
|
||||||
|
|
||||||
const webp = Platform.OS === 'ios' ? false : true;
|
const webp = Platform.OS === 'ios' ? false : true;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ export const parsePost = (post, currentUserName, isPromoted, isList = false, isC
|
|||||||
post.image = catchPostImage(post, 600, 500, webp ? 'webp' : 'match');
|
post.image = catchPostImage(post, 600, 500, webp ? 'webp' : 'match');
|
||||||
post.thumbnail = catchPostImage(post, 10, 7, webp ? 'webp' : 'match');
|
post.thumbnail = catchPostImage(post, 10, 7, webp ? 'webp' : 'match');
|
||||||
|
|
||||||
post.author_reputation = getReputation(post.author_reputation);
|
post.author_reputation = parseReputation(post.author_reputation);
|
||||||
post.avatar = getResizedAvatar(get(post, 'author'));
|
post.avatar = getResizedAvatar(get(post, 'author'));
|
||||||
if (!isList) {
|
if (!isList) {
|
||||||
post.body = renderPostBody(post, true, webp);
|
post.body = renderPostBody(post, true, webp);
|
||||||
@ -77,7 +77,7 @@ export const parsePost = (post, currentUserName, isPromoted, isList = false, isC
|
|||||||
export const parseComments = async (comments) => {
|
export const parseComments = async (comments) => {
|
||||||
return comments.map((comment) => {
|
return comments.map((comment) => {
|
||||||
comment.pending_payout_value = parseFloat(get(comment, 'pending_payout_value', 0)).toFixed(3);
|
comment.pending_payout_value = parseFloat(get(comment, 'pending_payout_value', 0)).toFixed(3);
|
||||||
comment.author_reputation = getReputation(get(comment, 'author_reputation'));
|
comment.author_reputation = parseReputation(get(comment, 'author_reputation'));
|
||||||
comment.avatar = getResizedAvatar(get(comment, 'author'));
|
comment.avatar = getResizedAvatar(get(comment, 'author'));
|
||||||
comment.markdownBody = get(comment, 'body');
|
comment.markdownBody = get(comment, 'body');
|
||||||
comment.body = renderPostBody(comment, true, webp);
|
comment.body = renderPostBody(comment, true, webp);
|
||||||
@ -144,7 +144,6 @@ export const parseActiveVotes = (post) => {
|
|||||||
if (!isEmpty(post.active_votes)) {
|
if (!isEmpty(post.active_votes)) {
|
||||||
forEach(post.active_votes, (value) => {
|
forEach(post.active_votes, (value) => {
|
||||||
value.reward = (value.rshares * ratio).toFixed(3);
|
value.reward = (value.rshares * ratio).toFixed(3);
|
||||||
//value.reputation = getReputation(get(value, 'reputation'));
|
|
||||||
value.percent /= 100;
|
value.percent /= 100;
|
||||||
value.is_down_vote = Math.sign(value.percent) < 0;
|
value.is_down_vote = Math.sign(value.percent) < 0;
|
||||||
value.avatar = getResizedAvatar(get(value, 'voter'));
|
value.avatar = getResizedAvatar(get(value, 'voter'));
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
export const getReputation = (reputation) => {
|
|
||||||
if (reputation === null) {
|
|
||||||
return reputation;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isFloat(reputation)) {
|
|
||||||
return Math.floor(reputation);
|
|
||||||
}
|
|
||||||
|
|
||||||
let _reputation = String(parseInt(reputation, 10));
|
|
||||||
|
|
||||||
const neg = _reputation.charAt(0) === '-';
|
|
||||||
_reputation = neg ? _reputation.substring(1) : _reputation;
|
|
||||||
|
|
||||||
const str = _reputation;
|
|
||||||
const leadingDigits = parseInt(str.substring(0, 4), 10);
|
|
||||||
const log = Math.log(leadingDigits) / Math.log(10);
|
|
||||||
const n = str.length - 1;
|
|
||||||
let out = n + (log - parseInt(log, 10));
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-restricted-globals
|
|
||||||
if (isNaN(out)) {
|
|
||||||
out = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
out = Math.max(out - 9, 0);
|
|
||||||
out *= neg ? -1 : 1;
|
|
||||||
out = out * 9 + 25;
|
|
||||||
out = parseInt(out, 10);
|
|
||||||
|
|
||||||
return out;
|
|
||||||
};
|
|
||||||
|
|
||||||
function isFloat(n) {
|
|
||||||
return Number(n) === n && n % 1 !== 0;
|
|
||||||
}
|
|
@ -1,28 +1,35 @@
|
|||||||
export const getReputation = (input) => {
|
const isHumanReadable = (input: number): boolean => {
|
||||||
|
return Math.abs(input) > 0 && Math.abs(input) <= 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const parseReputation = (input: string | number): number => {
|
||||||
|
if (typeof input === 'number' && isHumanReadable(input)) {
|
||||||
|
return Math.floor(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof input === 'string') {
|
||||||
|
input = Number(input);
|
||||||
|
|
||||||
|
if (isHumanReadable(input)) {
|
||||||
|
return Math.floor(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (input === 0) {
|
if (input === 0) {
|
||||||
return 25;
|
return 25;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!input) {
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
let neg = false;
|
let neg = false;
|
||||||
|
|
||||||
if (input < 0) {
|
if (input < 0) neg = true;
|
||||||
neg = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let reputationLevel = Math.log10(Math.abs(input));
|
let reputationLevel = Math.log10(Math.abs(input));
|
||||||
reputationLevel = Math.max(reputationLevel - 9, 0);
|
reputationLevel = Math.max(reputationLevel - 9, 0);
|
||||||
|
|
||||||
if (reputationLevel < 0) {
|
if (reputationLevel < 0) reputationLevel = 0;
|
||||||
reputationLevel = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (neg) {
|
if (neg) reputationLevel *= -1;
|
||||||
reputationLevel *= -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
reputationLevel = reputationLevel * 9 + 25;
|
reputationLevel = reputationLevel * 9 + 25;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user