diff --git a/src/components/comment/view/commentView.tsx b/src/components/comment/view/commentView.tsx index fab798246b..4779889aa7 100644 --- a/src/components/comment/view/commentView.tsx +++ b/src/components/comment/view/commentView.tsx @@ -63,7 +63,11 @@ const CommentView = ({ const _currentUsername = currentAccountUsername || currentAccount?.username; const _showSubCommentsToggle = async (force = false) => { - if (!!handleOnToggleReplies && !!comment.commentKey && ((replies && replies.length > 0) || force)) { + if ( + !!handleOnToggleReplies && + !!comment.commentKey && + ((replies && replies.length > 0) || force) + ) { setIsOpeningReplies(true); await delay(10); // hack to rendering inidcator first before start loading comments handleOnToggleReplies(comment.commentKey); diff --git a/src/components/commentsModal/container/commentsModal.tsx b/src/components/commentsModal/container/commentsModal.tsx index 490048b3dc..379b81063f 100644 --- a/src/components/commentsModal/container/commentsModal.tsx +++ b/src/components/commentsModal/container/commentsModal.tsx @@ -7,9 +7,9 @@ import Comments from '../../comments'; import styles from '../styles/commentsModal.styles'; /** - * NOTE: this comments modal is in draft stage, right now rendering of - * content works great but actions do not respond as expected since most - * of action reply on modals and action sheets which causes a conflict with + * NOTE: this comments modal is in draft stage, right now rendering of + * content works great but actions do not respond as expected since most + * of action reply on modals and action sheets which causes a conflict with * rendering comments in existing modal, similarly some actions require navigation * to different screen while comments modal is still visible on screen. */ diff --git a/src/components/index.tsx b/src/components/index.tsx index 6da10f0f73..d9624d611a 100644 --- a/src/components/index.tsx +++ b/src/components/index.tsx @@ -273,6 +273,5 @@ export { PostTranslationModal, ImageViewer, WalkthroughMarker, - ProposalVoteRequest - + ProposalVoteRequest, }; diff --git a/src/components/postComments/children/botCommentsPreview.tsx b/src/components/postComments/children/botCommentsPreview.tsx index 564b63f67b..1dadb7c5bb 100644 --- a/src/components/postComments/children/botCommentsPreview.tsx +++ b/src/components/postComments/children/botCommentsPreview.tsx @@ -1,63 +1,59 @@ import React, { useRef } from 'react'; import { View, TouchableOpacity, Text } from 'react-native'; import EStyleSheet from 'react-native-extended-stylesheet'; -import { CommentsModal, Icon, UserAvatar } from '../..'; -import styles from '../styles/botCommentsPreview.styles'; import { useIntl } from 'react-intl'; import { useNavigation } from '@react-navigation/native'; +import { CommentsModal, Icon, UserAvatar } from '../..'; +import styles from '../styles/botCommentsPreview.styles'; import ROUTES from '../../../constants/routeNames'; interface BotCommentsProps { - comments: any[]; + comments: any[]; } export const BotCommentsPreview = ({ comments }: BotCommentsProps) => { - const intl = useIntl(); - const navigation = useNavigation(); - - const commentsModalRef = useRef(); + const intl = useIntl(); + const navigation = useNavigation(); - if (!comments?.length) { - return null; - } + const commentsModalRef = useRef(); - const _onPress = () => { - navigation.navigate({ - name: ROUTES.MODALS.BOT_COMMENTS, - params: { - comments - } - }); - } + if (!comments?.length) { + return null; + } - return ( - - - - {intl.formatMessage({ id: 'comments.bot_comments' })} - - - - - - {comments.map((comment) => { - return ( - - - - ); - })} - - + const _onPress = () => { + navigation.navigate({ + name: ROUTES.MODALS.BOT_COMMENTS, + params: { + comments, + }, + }); + }; - + return ( + + + {intl.formatMessage({ id: 'comments.bot_comments' })} + + + + + {comments.map((comment) => { + return ( + + + + ); + })} - ); + + + + + ); }; diff --git a/src/components/postsList/container/postsListContainer.tsx b/src/components/postsList/container/postsListContainer.tsx index 8d4f9b2211..1348cff785 100644 --- a/src/components/postsList/container/postsListContainer.tsx +++ b/src/components/postsList/container/postsListContainer.tsx @@ -208,7 +208,7 @@ const postsListContainer = ( } }; - const _renderSeparator = () => + const _renderSeparator = () => ; const _renderItem = ({ item }: { item: any }) => { // get image height from cache if available @@ -231,7 +231,6 @@ const postsListContainer = ( } /> ); - }; return ( diff --git a/src/components/postsList/view/postsListStyles.tsx b/src/components/postsList/view/postsListStyles.tsx index 04958cb892..0fa8b7ac1a 100644 --- a/src/components/postsList/view/postsListStyles.tsx +++ b/src/components/postsList/view/postsListStyles.tsx @@ -11,8 +11,8 @@ export default EStyleSheet.create({ placeholderWrapper: { flex: 1, }, - separator:{ - backgroundColor:'$primaryLightBackground', - marginBottom:8 - } + separator: { + backgroundColor: '$primaryLightBackground', + marginBottom: 8, + }, }); diff --git a/src/components/proposalVoteRequest/container/proposalVoteRequest.tsx b/src/components/proposalVoteRequest/container/proposalVoteRequest.tsx index afe94e7eac..186f1a2d6e 100644 --- a/src/components/proposalVoteRequest/container/proposalVoteRequest.tsx +++ b/src/components/proposalVoteRequest/container/proposalVoteRequest.tsx @@ -1,133 +1,129 @@ import React, { useMemo, useState } from 'react'; -import { Image, Text, View } from "react-native"; -import styles from "../styles/ProposalVoteRequest.styles"; -import { TextButton } from "../../../components/buttons"; -import { MainButton } from "../../../components/mainButton"; -import { useDispatch, useSelector } from "react-redux"; -import { showActionModal } from "../../../redux/actions/uiAction"; -import { ButtonTypes } from "../../../components/actionModal/container/actionModalContainer"; +import { Image, Text, View } from 'react-native'; +import { useDispatch, useSelector } from 'react-redux'; +import { useIntl } from 'react-intl'; +import styles from '../styles/ProposalVoteRequest.styles'; +import { TextButton } from '../../buttons'; +import { MainButton } from '../../mainButton'; +import { showActionModal } from '../../../redux/actions/uiAction'; +import { ButtonTypes } from '../../actionModal/container/actionModalContainer'; import { useProposalVotedQuery, useProposalVoteMutation } from '../../../providers/queries'; import { updateProposalVoteMeta } from '../../../redux/actions/cacheActions'; -import { useIntl } from 'react-intl'; const ECENCY_PROPOSAL_ID = 283; -const RE_REQUEST_INTERVAL = 259200000; //3 days; +const RE_REQUEST_INTERVAL = 259200000; // 3 days; export const ProposalVoteRequest = () => { - const intl = useIntl(); - const dispatch = useDispatch(); - - const proposalVotedQuery = useProposalVotedQuery(ECENCY_PROPOSAL_ID); - const proposalVoteMutation = useProposalVoteMutation(); - - const currentAccount = useSelector(state => state.account.currentAccount); - - //assess if user should be promopted to vote proposal - //makes sure this logic is only calculated once on launch - const [skipOnLaunch] = useState(!currentAccount || - proposalVotedQuery.data || - proposalVotedQuery.meta?.processed); - - - //render or no render based on dimiss action performed - const skipRender = useMemo(() => { - if (!skipOnLaunch && proposalVotedQuery.meta) { - const curTime = new Date().getTime(); - const nextRequestTime = proposalVotedQuery.meta.dismissedAt + RE_REQUEST_INTERVAL - return nextRequestTime > curTime; - } - return skipOnLaunch; - }, [proposalVotedQuery.meta]) - - - if (skipRender) { - return null; - } - - const voteCasted = proposalVoteMutation.isSuccess; - - const _voteAction = () => { - proposalVoteMutation.mutate({ proposalId: ECENCY_PROPOSAL_ID }) + const intl = useIntl(); + const dispatch = useDispatch(); + + const proposalVotedQuery = useProposalVotedQuery(ECENCY_PROPOSAL_ID); + const proposalVoteMutation = useProposalVoteMutation(); + + const currentAccount = useSelector((state) => state.account.currentAccount); + + // assess if user should be promopted to vote proposal + // makes sure this logic is only calculated once on launch + const [skipOnLaunch] = useState( + !currentAccount || proposalVotedQuery.data || proposalVotedQuery.meta?.processed, + ); + + // render or no render based on dimiss action performed + const skipRender = useMemo(() => { + if (!skipOnLaunch && proposalVotedQuery.meta) { + const curTime = new Date().getTime(); + const nextRequestTime = proposalVotedQuery.meta.dismissedAt + RE_REQUEST_INTERVAL; + return nextRequestTime > curTime; } - - - const _remindLater = () => { - dispatch(showActionModal({ - title: intl.formatMessage({id:'proposal.title-action-dismiss'}) ,// "Dismiss Vote Request", - buttons: [ - { - text: intl.formatMessage({id:'proposal.btn-ignore'}), - type: ButtonTypes.CANCEL, - onPress: () => { - console.log('Ignore'); - dispatch(updateProposalVoteMeta( - ECENCY_PROPOSAL_ID, - currentAccount.username, - true, - new Date().getTime() - )) - }, - }, - { - text: intl.formatMessage({id:'proposal.btn-later'}), - onPress: () => { - dispatch(updateProposalVoteMeta( - ECENCY_PROPOSAL_ID, - currentAccount.username, - false, - new Date().getTime() - )) - }, - }, - ], - })) - }; - - - const _actionPanel = () => { - return ( - - - - - ); - } - - const titleTextId = voteCasted ? "proposal.title-voted" : "proposal.title"; - const descTextId = voteCasted ? "proposal.desc-voted" : "proposal.desc" - + return skipOnLaunch; + }, [proposalVotedQuery.meta]); + + if (skipRender) { + return null; + } + + const voteCasted = proposalVoteMutation.isSuccess; + + const _voteAction = () => { + proposalVoteMutation.mutate({ proposalId: ECENCY_PROPOSAL_ID }); + }; + + const _remindLater = () => { + dispatch( + showActionModal({ + title: intl.formatMessage({ id: 'proposal.title-action-dismiss' }), // "Dismiss Vote Request", + buttons: [ + { + text: intl.formatMessage({ id: 'proposal.btn-ignore' }), + type: ButtonTypes.CANCEL, + onPress: () => { + console.log('Ignore'); + dispatch( + updateProposalVoteMeta( + ECENCY_PROPOSAL_ID, + currentAccount.username, + true, + new Date().getTime(), + ), + ); + }, + }, + { + text: intl.formatMessage({ id: 'proposal.btn-later' }), + onPress: () => { + dispatch( + updateProposalVoteMeta( + ECENCY_PROPOSAL_ID, + currentAccount.username, + false, + new Date().getTime(), + ), + ); + }, + }, + ], + }), + ); + }; + + const _actionPanel = () => { return ( - - - - - {intl.formatMessage({id:titleTextId})} - - - - {intl.formatMessage({id:descTextId})} - - - - - - - {!voteCasted && _actionPanel()} + + + + + ); + }; + + const titleTextId = voteCasted ? 'proposal.title-voted' : 'proposal.title'; + const descTextId = voteCasted ? 'proposal.desc-voted' : 'proposal.desc'; + + return ( + + + + {intl.formatMessage({ id: titleTextId })} + + {intl.formatMessage({ id: descTextId })} - ) -}; \ No newline at end of file + + + + {!voteCasted && _actionPanel()} + + ); +}; diff --git a/src/components/proposalVoteRequest/index.ts b/src/components/proposalVoteRequest/index.ts index 6001eff8e6..de437d3979 100644 --- a/src/components/proposalVoteRequest/index.ts +++ b/src/components/proposalVoteRequest/index.ts @@ -1 +1 @@ -export * from './container/proposalVoteRequest'; \ No newline at end of file +export * from './container/proposalVoteRequest'; diff --git a/src/components/proposalVoteRequest/styles/ProposalVoteRequest.styles.ts b/src/components/proposalVoteRequest/styles/ProposalVoteRequest.styles.ts index f8454eb82b..eb9592d891 100644 --- a/src/components/proposalVoteRequest/styles/ProposalVoteRequest.styles.ts +++ b/src/components/proposalVoteRequest/styles/ProposalVoteRequest.styles.ts @@ -1,33 +1,33 @@ -import { TextStyle, ViewStyle } from "react-native"; -import EStyleSheet from "react-native-extended-stylesheet"; +import { TextStyle, ViewStyle } from 'react-native'; +import EStyleSheet from 'react-native-extended-stylesheet'; export default EStyleSheet.create({ - container:{ - backgroundColor:"$primaryLightBackground", - marginTop:16, - marginBottom:8, - padding:16, - flex: 1 - } as ViewStyle, - content:{ - flexDirection:'row', - alignItems:'center', - } as ViewStyle, - title:{ - color:'$primaryDarkText', - fontSize: 18, - fontWeight: '600' - } as TextStyle, - description:{ - color:'$primaryDarkText', - marginVertical:8 - } as TextStyle, - actionPanel:{ - flexDirection:'row', - alignItems:'center', - marginTop:8 - } as ViewStyle, - voteBtnTitle:{ - // color: '$primaryBlue' - } as TextStyle -}) \ No newline at end of file + container: { + backgroundColor: '$primaryLightBackground', + marginTop: 16, + marginBottom: 8, + padding: 16, + flex: 1, + } as ViewStyle, + content: { + flexDirection: 'row', + alignItems: 'center', + } as ViewStyle, + title: { + color: '$primaryDarkText', + fontSize: 18, + fontWeight: '600', + } as TextStyle, + description: { + color: '$primaryDarkText', + marginVertical: 8, + } as TextStyle, + actionPanel: { + flexDirection: 'row', + alignItems: 'center', + marginTop: 8, + } as ViewStyle, + voteBtnTitle: { + // color: '$primaryBlue' + } as TextStyle, +}); diff --git a/src/components/tabbedPosts/view/postsTabContent.tsx b/src/components/tabbedPosts/view/postsTabContent.tsx index 6497634e4c..8792873d12 100644 --- a/src/components/tabbedPosts/view/postsTabContent.tsx +++ b/src/components/tabbedPosts/view/postsTabContent.tsx @@ -138,15 +138,11 @@ const PostsTabContent = ({ } }; - const _renderHeader = () => { if (pageType === 'main' && isInitialTab) { - return ( - - ) + return ; } - - } + }; // view rendereres const _renderEmptyContent = () => { const _isNoPost = !feedQuery.isLoading && feedQuery.data.length == 0; diff --git a/src/navigation/stackNavigator.tsx b/src/navigation/stackNavigator.tsx index 166414a313..1d67a2fb63 100644 --- a/src/navigation/stackNavigator.tsx +++ b/src/navigation/stackNavigator.tsx @@ -38,11 +38,10 @@ import { BackupKeysScreen, AccountList, PollWizardScreen, - BotComments + BotComments, } from '../screens'; import { DrawerNavigator } from './drawerNavigator'; - const RootStack = createNativeStackNavigator(); const MainStack = createNativeStackNavigator(); @@ -86,11 +85,7 @@ const MainStackNavigator = () => { component={AccountList} options={{ presentation: 'modal' }} /> - + ); diff --git a/src/providers/hive/dhive.js b/src/providers/hive/dhive.js index 7baf3b939a..63944067a3 100644 --- a/src/providers/hive/dhive.js +++ b/src/providers/hive/dhive.js @@ -649,16 +649,19 @@ export const getProposalsVoted = async (username) => { console.log('Getting proposals voted:', username); - const votedProposals = await client.call( - 'condenser_api', - 'list_proposal_votes', - [[username], 100, "by_voter_proposal", "ascending", "active"]); + const votedProposals = await client.call('condenser_api', 'list_proposal_votes', [ + [username], + 100, + 'by_voter_proposal', + 'ascending', + 'active', + ]); if (!Array.isArray(votedProposals)) { throw new Error('invalid data'); } - const filteredProposals = votedProposals.filter(item => item.voter === username); + const filteredProposals = votedProposals.filter((item) => item.voter === username); console.log(`Returning filtered proposals`, filteredProposals); return filteredProposals; @@ -666,7 +669,7 @@ export const getProposalsVoted = async (username) => { bugsnapInstance.notify(error); return []; } -} +}; export const getActiveVotes = (author, permlink) => new Promise((resolve, reject) => { @@ -1005,13 +1008,12 @@ const _vote = (currentAccount, pin, author, permlink, weight) => { ); }; - /** * Update Hive Proposal Vote with current account as voter - * @param {*} currentAccount - * @param {*} pin - * @param {*} proposalId - * @returns + * @param {*} currentAccount + * @param {*} pin + * @param {*} proposalId + * @returns */ export const voteProposal = (currentAccount, pinHash, proposalId) => { const digitPinCode = getDigitPinCode(pinHash); @@ -1020,13 +1022,13 @@ export const voteProposal = (currentAccount, pinHash, proposalId) => { const voter = currentAccount.name; const opArray = [ [ - "update_proposal_votes", + 'update_proposal_votes', { - voter: voter, + voter, proposal_ids: [proposalId], approve: true, - extensions: [] - } + extensions: [], + }, ], ]; diff --git a/src/providers/queries/postQueries/postQueries.ts b/src/providers/queries/postQueries/postQueries.ts index 5a63368b05..f7ca8063ef 100644 --- a/src/providers/queries/postQueries/postQueries.ts +++ b/src/providers/queries/postQueries/postQueries.ts @@ -114,10 +114,6 @@ export const useDiscussionQuery = (_author?: string, _permlink?: string) => { ); const lastCacheUpdate: LastUpdateMeta = useAppSelector((state) => state.cache.lastUpdate); - const useBotAuthersQuery = useQuery([QUERIES.POST.GET_BOT_AUTHERS], getBotAuthers, { - initialData: [], - }); - const [author, setAuthor] = useState(_author); const [permlink, setPermlink] = useState(_permlink); @@ -125,6 +121,8 @@ export const useDiscussionQuery = (_author?: string, _permlink?: string) => { const [botComments, setBotComments] = useState([]); const [sectionedData, setSectionedData] = useState([]); + const botAuthorsQuery = useBotAuthorsQuery(); + const _fetchComments = async () => getDiscussionCollection(author, permlink); const query = useQuery<{ [key: string]: Comment }>( [QUERIES.POST.GET_DISCUSSION, author, permlink], @@ -141,7 +139,7 @@ export const useDiscussionQuery = (_author?: string, _permlink?: string) => { useEffect(() => { restructureData(); - }, [data, useBotAuthersQuery.data]); + }, [data, botAuthorsQuery.data]); // traverse discussion collection to curate sections const restructureData = async () => { @@ -195,10 +193,10 @@ export const useDiscussionQuery = (_author?: string, _permlink?: string) => { // filter comments using botsdata const _botComments = comments.filter((comment) => - useBotAuthersQuery.data.includes(comment.author), + botAuthorsQuery.data.includes(comment.author), ); const _userComments = comments.filter( - (comment) => !useBotAuthersQuery.data.includes(comment.author), + (comment) => !botAuthorsQuery.data.includes(comment.author), ); setBotComments(_botComments); @@ -215,6 +213,12 @@ export const useDiscussionQuery = (_author?: string, _permlink?: string) => { }; }; +export const useBotAuthorsQuery = () => + useQuery([QUERIES.POST.GET_BOT_AUTHERS], getBotAuthers, { + cacheTime: 1000 * 60 * 60 * 24 * 30, // 30 days cache timer + initialData: [], // TODO: initialise authors with already known bots, + }); + /** * * @param _data single post content or array of posts diff --git a/src/providers/queries/postQueries/wavesQueries.ts b/src/providers/queries/postQueries/wavesQueries.ts index 1f8ca6eaea..c80e1f7b00 100644 --- a/src/providers/queries/postQueries/wavesQueries.ts +++ b/src/providers/queries/postQueries/wavesQueries.ts @@ -21,6 +21,7 @@ import { } from '../../../utils/postParser'; import { useAppSelector } from '../../../hooks'; import { toastNotification } from '../../../redux/actions/uiAction'; +import { useBotAuthorsQuery } from './postQueries'; export const useWavesQuery = (host: string) => { const queryClient = useQueryClient(); @@ -32,6 +33,9 @@ export const useWavesQuery = (host: string) => { const currentAccount = useAppSelector((state) => state.account.currentAccount); const pinCode = useAppSelector((state) => state.application.pin); + // TOTO: import bot authors query here + const botAuthorsQuery = useBotAuthorsQuery(); + const cacheRef = useRef(cache); const cachedVotes = cache.votesCollection; @@ -183,17 +187,22 @@ export const useWavesQuery = (host: string) => { throw new Error('Failed to parse waves'); } - _threadedComments.filter( - (item) => item.net_rshares >= 0 && !item.stats?.gray && !item.stats.hide, + const _filteredComments = _threadedComments.filter( + (item) => + item.net_rshares >= 0 && + !item.stats?.gray && + !item.stats.hide && + !botAuthorsQuery.data.includes(item.author), ); - _threadedComments.sort((a, b) => (new Date(a.created) > new Date(b.created) ? -1 : 1)); - _threadedComments.forEach((item) => { + + _filteredComments.sort((a, b) => (new Date(a.created) > new Date(b.created) ? -1 : 1)); + _filteredComments.forEach((item) => { wavesIndexCollection.current[`${item.author}/${item.permlink}`] = pagePermlink; }); - console.log('new waves fetched', _threadedComments); + console.log('new waves fetched', _filteredComments); - return _threadedComments || []; + return _filteredComments || []; }; const _fetchNextPage = () => { diff --git a/src/providers/queries/proposalQueries.ts b/src/providers/queries/proposalQueries.ts index 2981b09db1..8a43819842 100644 --- a/src/providers/queries/proposalQueries.ts +++ b/src/providers/queries/proposalQueries.ts @@ -1,66 +1,59 @@ -import { useMutation, useQuery } from "@tanstack/react-query" -import QUERIES from "./queryKeys" -import { useSelector } from "react-redux" -import { getProposalsVoted, voteProposal } from "../../providers/hive/dhive"; -import { useAppDispatch, useAppSelector } from "../../hooks"; -import { useIntl } from "react-intl"; -import { toastNotification } from "../../redux/actions/uiAction"; -import { updateProposalVoteMeta } from "../../redux/actions/cacheActions"; -import { ProposalVoteMeta } from "redux/reducers/cacheReducer"; - +import { useMutation, useQuery } from '@tanstack/react-query'; +import { useSelector } from 'react-redux'; +import { useIntl } from 'react-intl'; +import { ProposalVoteMeta } from 'redux/reducers/cacheReducer'; +import QUERIES from './queryKeys'; +import { getProposalsVoted, voteProposal } from '../hive/dhive'; +import { useAppDispatch, useAppSelector } from '../../hooks'; +import { toastNotification } from '../../redux/actions/uiAction'; +import { updateProposalVoteMeta } from '../../redux/actions/cacheActions'; export const useProposalVotedQuery = (proposalId: number) => { + const currentAccount = useSelector((state) => state.account.currentAccount); + const proposalsVoteMeta = useSelector((state) => state.cache.proposalsVoteMeta); - const currentAccount = useSelector(state => state.account.currentAccount); - const proposalsVoteMeta = useSelector(state => state.cache.proposalsVoteMeta); - - //form meta id - const _cacheId = `${proposalId}_${currentAccount.username}` - const _proposalVoteMeta:ProposalVoteMeta|null = proposalsVoteMeta[_cacheId] - - const _getProposalVoteStatus = async () => { - const votedProposals = await getProposalsVoted(currentAccount.username); - const isVoted = votedProposals.some(item => item.proposal.proposal_id === proposalId) + // form meta id + const _cacheId = `${proposalId}_${currentAccount.username}`; + const _proposalVoteMeta: ProposalVoteMeta | null = proposalsVoteMeta[_cacheId]; - console.log('is proposal voted', isVoted); - return isVoted; - } + const _getProposalVoteStatus = async () => { + const votedProposals = await getProposalsVoted(currentAccount.username); + const isVoted = votedProposals.some((item) => item.proposal.proposal_id === proposalId); - const query = useQuery( - [QUERIES.PROPOSALS.GET_VOTES, currentAccount.name, proposalId], - _getProposalVoteStatus, - { initialData: true } - ); + console.log('is proposal voted', isVoted); + return isVoted; + }; - return { - ...query, - meta:_proposalVoteMeta - }; -} + const query = useQuery( + [QUERIES.PROPOSALS.GET_VOTES, currentAccount.name, proposalId], + _getProposalVoteStatus, + { initialData: true }, + ); + return { + ...query, + meta: _proposalVoteMeta, + }; +}; export const useProposalVoteMutation = () => { - const dispatch = useAppDispatch(); - const intl = useIntl(); - - const currentAccount = useAppSelector(state => state.account.currentAccount); - const pinHash = useAppSelector(state => state.application.pin); - - - return useMutation( - ({proposalId}) => voteProposal(currentAccount, pinHash, proposalId), - { - retry: 3, - onSuccess: (_,{proposalId}) => { - dispatch(toastNotification(intl.formatMessage({ id: 'alert.thankyou' }))); - dispatch(updateProposalVoteMeta( - proposalId, - currentAccount.username, - true - )) - }, - onError: () => { - dispatch(toastNotification(intl.formatMessage({ id: 'alert.fail' }))); - }, - }); -} \ No newline at end of file + const dispatch = useAppDispatch(); + const intl = useIntl(); + + const currentAccount = useAppSelector((state) => state.account.currentAccount); + const pinHash = useAppSelector((state) => state.application.pin); + + return useMutation( + ({ proposalId }) => voteProposal(currentAccount, pinHash, proposalId), + { + retry: 3, + onSuccess: (_, { proposalId }) => { + dispatch(toastNotification(intl.formatMessage({ id: 'alert.thankyou' }))); + dispatch(updateProposalVoteMeta(proposalId, currentAccount.username, true)); + }, + onError: () => { + dispatch(toastNotification(intl.formatMessage({ id: 'alert.fail' }))); + }, + }, + ); +}; diff --git a/src/providers/queries/queryKeys.ts b/src/providers/queries/queryKeys.ts index ef1568b92d..6b2aca814f 100644 --- a/src/providers/queries/queryKeys.ts +++ b/src/providers/queries/queryKeys.ts @@ -51,8 +51,8 @@ const QUERIES = { GET_BOOST_PLUS_PRICES: 'REDEEM_GET_BOOST_PLUS_PRICES', }, PROPOSALS: { - GET_VOTES:'QUERY_PROPOSAL_GET_VOTES' - } + GET_VOTES: 'QUERY_PROPOSAL_GET_VOTES', + }, }; export default QUERIES; diff --git a/src/redux/actions/cacheActions.ts b/src/redux/actions/cacheActions.ts index 20baeffd80..681eb7f308 100644 --- a/src/redux/actions/cacheActions.ts +++ b/src/redux/actions/cacheActions.ts @@ -18,7 +18,7 @@ import { DELETE_CLAIM_CACHE_ENTRY, UPDATE_ANNOUNCEMENTS_META, UPDATE_POLL_VOTE_CACHE, - UPDATE_PROPOSALS_VOTE_META + UPDATE_PROPOSALS_VOTE_META, } from '../constants/constants'; import { Comment, @@ -188,17 +188,22 @@ export const updateAnnoucementsMeta = (id: string, processed: boolean) => ({ }); /** - * + * * @param id proposalId - * @param username - * @param processed - * @returns + * @param username + * @param processed + * @returns */ -export const updateProposalVoteMeta = (id:number, username: string, processed:boolean, dismissedAt:number = 0) => ({ +export const updateProposalVoteMeta = ( + id: number, + username: string, + processed: boolean, + dismissedAt = 0, +) => ({ payload: { - id: id + "_" + username, + id: `${id}_${username}`, processed, - dismissedAt + dismissedAt, }, type: UPDATE_PROPOSALS_VOTE_META, }); diff --git a/src/redux/reducers/cacheReducer.ts b/src/redux/reducers/cacheReducer.ts index 8c3a85b106..0a1bd0fb86 100644 --- a/src/redux/reducers/cacheReducer.ts +++ b/src/redux/reducers/cacheReducer.ts @@ -15,7 +15,7 @@ import { DELETE_CLAIM_CACHE_ENTRY, UPDATE_ANNOUNCEMENTS_META, UPDATE_POLL_VOTE_CACHE, - UPDATE_PROPOSALS_VOTE_META + UPDATE_PROPOSALS_VOTE_META, } from '../constants/constants'; export enum CacheStatus { @@ -122,7 +122,7 @@ interface State { subscribedCommunities: Map; pointActivities: Map; announcementsMeta: { [key: string]: AnnouncementMeta }; - proposalsVoteMeta: { [key: string]: ProposalVoteMeta }; //proposal cache id: [proposalId]_[username] + proposalsVoteMeta: { [key: string]: ProposalVoteMeta }; // proposal cache id: [proposalId]_[username] lastUpdate: LastUpdateMeta; } @@ -303,7 +303,7 @@ const cacheReducer = (state = initialState, action) => { state.proposalsVoteMeta = { ...state.proposalsVoteMeta, [payload.id]: { - processed:payload.processed, + processed: payload.processed, dismissedAt: payload.dismissedAt, } as ProposalVoteMeta, }; @@ -311,7 +311,6 @@ const cacheReducer = (state = initialState, action) => { ...state, // spread operator in requried here, otherwise persist do not register change }; - case UPDATE_ANNOUNCEMENTS_META: if (!state.announcementsMeta) { state.announcementsMeta = {}; diff --git a/src/screens/botComments/index.ts b/src/screens/botComments/index.ts index e9571f9609..b787902acf 100644 --- a/src/screens/botComments/index.ts +++ b/src/screens/botComments/index.ts @@ -1 +1 @@ -export * from './screen/botComments'; \ No newline at end of file +export * from './screen/botComments'; diff --git a/src/screens/botComments/screen/botComments.tsx b/src/screens/botComments/screen/botComments.tsx index a4f85bd528..94c9b4818e 100644 --- a/src/screens/botComments/screen/botComments.tsx +++ b/src/screens/botComments/screen/botComments.tsx @@ -3,39 +3,36 @@ import React, { useState } from 'react'; // Services and Actions import { View } from 'react-native'; -import { Comments, BasicHeader } from '../../../components'; -import styles from '../styles/botComments.styles'; import { useIntl } from 'react-intl'; import { SafeAreaView } from 'react-native-safe-area-context'; - +import { Comments, BasicHeader } from '../../../components'; +import styles from '../styles/botComments.styles'; export const BotComments = ({ route }) => { - const intl = useIntl(); - - const [comments] = useState(route.params?.comments || []); - - - const _renderContent = ( - - { - console.log('implement fetch if required'); - }} - - /> - - ); - - return ( - - - - {_renderContent} - - - ); + const intl = useIntl(); + + const [comments] = useState(route.params?.comments || []); + + const _renderContent = ( + + { + console.log('implement fetch if required'); + }} + /> + + ); + + return ( + + + + {_renderContent} + + + ); }; diff --git a/src/screens/botComments/styles/botComments.styles.ts b/src/screens/botComments/styles/botComments.styles.ts index 39b99d7536..bb9f820f74 100644 --- a/src/screens/botComments/styles/botComments.styles.ts +++ b/src/screens/botComments/styles/botComments.styles.ts @@ -1,10 +1,8 @@ import EStyleSheet from 'react-native-extended-stylesheet'; export default EStyleSheet.create({ - - container: { - backgroundColor:'$primaryBackgroundColor', - flex:1 - }, - + container: { + backgroundColor: '$primaryBackgroundColor', + flex: 1, + }, }); diff --git a/src/screens/index.js b/src/screens/index.js index c85063f14d..4af57eecd6 100755 --- a/src/screens/index.js +++ b/src/screens/index.js @@ -75,5 +75,5 @@ export { AssetsSelect, BackupKeysScreen, PollWizardScreen, - BotComments + BotComments, }; diff --git a/src/utils/migrationHelpers.ts b/src/utils/migrationHelpers.ts index e3f1d769c6..ce7d08428d 100644 --- a/src/utils/migrationHelpers.ts +++ b/src/utils/migrationHelpers.ts @@ -316,7 +316,7 @@ const reduxMigrations = { 11: (state) => { state.cache.proposalsVoteMeta = {}; return state; - } + }, }; export default {