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

View File

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