fix voters info

This commit is contained in:
feruz 2020-10-19 23:11:41 +03:00
parent 33f830f1d1
commit 6817425804
10 changed files with 52 additions and 82 deletions

View File

@ -51,17 +51,9 @@ const CommentView = ({
const actionSheet = useRef(null);
useEffect(() => {
getActiveVotes(get(comment, 'author'), get(comment, 'permlink'))
.then((result) => {
result.sort((a, b) => b.rshares - a.rshares);
const _votes = parseActiveVotes(
{ ...comment, active_votes: result },
currentAccountUsername,
);
setActiveVotes(_votes);
})
.catch(() => {});
if (comment) {
setActiveVotes(get(comment, 'active_votes', []));
}
}, [comment]);
const _showSubCommentsToggle = () => {
@ -106,7 +98,7 @@ const CommentView = ({
onPress={() =>
handleOnVotersPress &&
activeVotes.length > 0 &&
handleOnVotersPress(activeVotes)
handleOnVotersPress(activeVotes, comment)
}
text={activeVotes.length}
textStyle={styles.voteCountText}

View File

@ -168,13 +168,12 @@ const CommentsContainer = ({
});
};
const _handleOnVotersPress = (activeVotes) => {
const _handleOnVotersPress = (activeVotes, content) => {
navigation.navigate({
routeName: ROUTES.SCREENS.VOTERS,
params: {
activeVotes,
content,
user: currentAccount,
},
key: get(content, 'permlink'),
});

View File

@ -30,7 +30,7 @@ const PostCardContainer = ({
}) => {
const [activeVotes, setActiveVotes] = useState([]);
const [reblogs, setReblogs] = useState([]);
const [_content, setContent] = useState(null);
const [_content, setContent] = useState(content);
useEffect(() => {
if (isRefresh) {
@ -45,6 +45,7 @@ const PostCardContainer = ({
getPostReblogs(content).then((result) => {
setReblogs(result);
});
setContent(content);
}
}, [content]);
@ -79,7 +80,6 @@ const PostCardContainer = ({
params: {
activeVotes,
content,
user: currentAccount,
},
key: get(content, 'permlink'),
});

View File

@ -60,7 +60,6 @@ const PostDisplayContainer = ({
params: {
activeVotes,
content: post,
user: currentAccount,
},
// TODO: make unic
key: post.permlink + activeVotes.length,

View File

@ -38,7 +38,7 @@ const VotersDisplayView = ({ votes, navigation }) => {
};
const _renderItem = ({ item, index }) => {
const value = `$ ${item.value}`;
const value = `$ ${item.reward}`;
const percent = `${item.percent}%`;
return (

View File

@ -341,7 +341,8 @@
"payloadTooLarge": "File size too big, please resize or upload smaller image",
"qoutaExceeded": "Upload quota exceeded",
"invalidImage": "Invalid image, try different file",
"something_wrong": "Something went wrong."
"something_wrong": "Something went wrong.",
"something_wrong_alt": "Try https://ecency.com"
},
"post": {
"reblog_alert": "Are you sure, you want to reblog?",

View File

@ -1,32 +1,20 @@
import { Component } from 'react';
import { Component, useState, useEffect } from 'react';
import { isBefore } from '../utils/time';
import ROUTES from '../constants/routeNames';
class AccountListContainer extends Component {
/* Props
* ------------------------------------------------
* @prop { type } name - Description....
*/
const AccountListContainer = ({ data, navigation, children }) => {
const [vdata, setVData] = useState(data);
const [filterResult, setFilterResult] = useState(null);
const [filterIndex, setFilterIndex] = useState(0);
constructor(props) {
super(props);
this.state = {
data: props.data,
filterResult: null,
filterIndex: 0,
};
}
useEffect(() => {
setVData(data);
}, [data]);
// Component Life Cycles
// Component Functions
_handleSearch = (searchText, key) => {
const { data, filterIndex } = this.state;
const newData = data.filter((item) => {
const _handleSearch = (searchText, key) => {
const newData = vdata.filter((item) => {
const itemName = item[key].toUpperCase();
const _text = searchText.toUpperCase();
@ -34,15 +22,14 @@ class AccountListContainer extends Component {
});
if (filterIndex !== 0) {
this._handleOnVotersDropdownSelect(filterIndex, '', newData);
_handleOnVotersDropdownSelect(filterIndex, '', newData);
} else {
this.setState({ filterResult: newData });
setFilterResult(newData);
}
};
_handleOnVotersDropdownSelect = (index, text, oldData) => {
const { data, filterIndex } = this.state;
const _data = Object.assign([], oldData || data);
const _handleOnVotersDropdownSelect = (index, text, oldData) => {
const _data = Object.assign([], oldData || vdata);
if (filterIndex === index) {
switch (index) {
@ -73,13 +60,11 @@ class AccountListContainer extends Component {
break;
}
}
this.setState({ filterResult: _data, filterIndex: index });
setFilterResult(_data);
setFilterIndex(index);
};
_handleOnUserPress = (username) => {
const { navigation } = this.props;
const _handleOnUserPress = (username) => {
navigation.navigate({
routeName: ROUTES.SCREENS.PROFILE,
params: {
@ -89,22 +74,17 @@ class AccountListContainer extends Component {
});
};
render() {
const { data, filterResult, filterIndex } = this.state;
const { children } = this.props;
return (
children &&
children({
data,
filterResult,
filterIndex,
handleOnVotersDropdownSelect: this._handleOnVotersDropdownSelect,
handleSearch: this._handleSearch,
handleOnUserPress: this._handleOnUserPress,
})
);
}
}
return (
children &&
children({
data,
filterResult,
filterIndex,
handleOnVotersDropdownSelect: _handleOnVotersDropdownSelect,
handleSearch: _handleSearch,
handleOnUserPress: _handleOnUserPress,
})
);
};
export default AccountListContainer;

View File

@ -33,11 +33,16 @@ class ErrorBoundary extends React.Component {
return (
<View style={{ justifyContent: 'center', alignItems: 'center', flex: 1 }}>
<Icon iconType="MaterialIcons" name="error-outline" size={56} />
<Text style={{ fontSize: 30 }}>
<Text style={{ fontSize: 25 }}>
{intl.formatMessage({
id: 'alert.something_wrong',
})}
</Text>
<Text style={{ fontSize: 15 }}>
{intl.formatMessage({
id: 'alert.something_wrong_alt',
})}
</Text>
</View>
);
}

View File

@ -17,32 +17,25 @@ const filterOptions = ['rewards', 'percent', 'time'];
const VotersScreen = ({ navigation }) => {
const intl = useIntl();
const [activeVotes, setActiveVotes] = useState([]);
const [content, setContent] = useState(get(navigation, 'state.params.content'));
const [activeVotes, setActiveVotes] = useState(get(content, 'active_votes') || []);
const [isLoading, setIsLoading] = useState(false);
const headerTitle = intl.formatMessage({
id: 'voters.voters_info',
});
const currentAccount = get(navigation, 'state.params.user');
useEffect(() => {
console.log('content', content);
if (content) {
getActiveVotes(get(content, 'author'), get(content, 'permlink'))
.then((result) => {
result.sort((a, b) => b.rshares - a.rshares);
const _votes = parseActiveVotes(
{ ...content, active_votes: result },
get(currentAccount, 'name'),
);
const _votes = parseActiveVotes({ ...content, active_votes: result });
setActiveVotes(_votes);
})
.catch(() => {});
}
}, []);
}, [content]);
//const activeVotes = get(navigation, 'state.params.activeVotes');
//const content = get(navigation, 'state.params.content');

View File

@ -127,16 +127,17 @@ export const isDownVoted = (activeVotes, currentUserName) => {
export const parseActiveVotes = (post) => {
const totalPayout =
post.total_payout ||
parseFloat(post.pending_payout_value) +
parseFloat(post.total_payout_value) +
parseFloat(post.curator_payout_value);
parseFloat(post.total_payout_value) +
parseFloat(post.curator_payout_value);
const voteRshares = post.active_votes.reduce((a, b) => a + parseFloat(b.rshares), 0);
const ratio = totalPayout / voteRshares || 0;
if (!isEmpty(post.active_votes)) {
forEach(post.active_votes, (value) => {
value.value = (value.rshares * ratio).toFixed(3);
value.reward = (value.rshares * ratio).toFixed(3);
//value.reputation = getReputation(get(value, 'reputation'));
value.percent /= 100;
value.is_down_vote = Math.sign(value.percent) < 0;