implemented points mutation on voting

This commit is contained in:
noumantahir 2022-10-14 00:13:14 +05:00
parent 0f7ce49999
commit 0bb051d675
2 changed files with 19 additions and 4 deletions

View File

@ -22,6 +22,9 @@ import { vote } from '../../../providers/hive/dhive';
import styles from './upvoteStyles';
import { useAppSelector } from '../../../hooks';
import postTypes from '../../../constants/postTypes';
import { useUserActivityMutation } from '../../../providers/queries';
import { generateRndStr } from '../../../utils/editor';
import { EPointActivityIds } from '../../../providers/ecency/ecency.types';
interface UpvoteViewProps {
isDeclinedPayout: boolean;
@ -76,6 +79,7 @@ const UpvoteView = ({
parentType,
}: UpvoteViewProps) => {
const intl = useIntl();
const userActivityMutation = useUserActivityMutation();
const isLoggedIn = useAppSelector((state) => state.application.isLoggedIn);
const currentAccount = useAppSelector((state) => state.account.currentAccount);
@ -133,8 +137,14 @@ const UpvoteView = ({
console.log('casting up vote: ' + weight);
vote(currentAccount, pinCode, author, permlink, weight)
.then((response) => {
//TODO: update user points
console.log('Vote response: ', response);
//record user points
userActivityMutation.mutate({
localId: generateRndStr(),
pointsTy: EPointActivityIds.VOTE,
transactionId: response.id
})
if (!response || !response.id) {
Alert.alert(
intl.formatMessage({
@ -202,8 +212,13 @@ const UpvoteView = ({
console.log('casting down vote: ' + weight);
vote(currentAccount, pinCode, author, permlink, weight)
.then(() => {
//TODO: update usr points
.then((response) => {
//record usr points
userActivityMutation.mutate({
localId: generateRndStr(),
pointsTy: EPointActivityIds.VOTE,
transactionId: response.id
})
setUpvote(!!sliderValue);
setIsVoting(false);
onVote(amount, true);

View File

@ -793,7 +793,7 @@ export const vote = async (account, pin, author, permlink, weight) => {
console.log('Returning vote response', resp);
//TODO: remove userActivity
userActivity(120, resp.id);
// userActivity(120, resp.id);
return resp;
} catch (err) {
console.warn('Failed to complete vote', err);