-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from dappforce/deploy/leaderboard
Add Post Reward
- Loading branch information
Showing
14 changed files
with
212 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import clsx from 'clsx' | ||
import { ComponentProps } from 'react' | ||
import { TbCoins } from 'react-icons/tb' | ||
import { FormatBalance } from 'src/components/common/balances' | ||
import { useSelectPostReward } from 'src/rtk/features/activeStaking/hooks' | ||
|
||
export type PostRewardStatProps = ComponentProps<'div'> & { postId: string } | ||
|
||
export default function PostRewardStat({ postId, ...props }: PostRewardStatProps) { | ||
const postEarn = useSelectPostReward(postId) | ||
if (!postEarn?.isNotZero) return null | ||
|
||
return ( | ||
<div | ||
{...props} | ||
className={clsx('d-flex align-items-center GapMini FontWeightMedium', props.className)} | ||
style={{ alignSelf: 'end', ...props.style }} | ||
> | ||
<span className='d-flex align-items-center GapMini ColorMuted'> | ||
<TbCoins className='FontNormal' /> | ||
<span>Post earned:</span> | ||
</span> | ||
<span className='FontWeightSemibold'> | ||
<FormatBalance | ||
currency='SUB' | ||
decimals={10} | ||
precision={2} | ||
withMutedDecimals={false} | ||
value={postEarn.amount} | ||
/> | ||
</span> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { createEntityAdapter, createSlice } from '@reduxjs/toolkit' | ||
import { getPostRewards } from 'src/components/utils/datahub/super-likes' | ||
import { RootState } from 'src/rtk/app/rootReducer' | ||
import { createSimpleManyFetchWrapper } from 'src/rtk/app/wrappers' | ||
|
||
export type PostRewards = { | ||
postId: string | ||
amount: string | ||
isNotZero: boolean | ||
} | ||
|
||
const sliceName = 'postRewards' | ||
|
||
const adapter = createEntityAdapter<PostRewards>({ | ||
selectId: data => data.postId, | ||
}) | ||
const selectors = adapter.getSelectors<RootState>(state => state.postReward) | ||
|
||
export const selectPostReward = selectors.selectById | ||
|
||
export const fetchPostRewards = createSimpleManyFetchWrapper<{ postIds: string[] }, PostRewards>({ | ||
sliceName, | ||
fetchData: async function ({ postIds }) { | ||
return await getPostRewards(postIds) | ||
}, | ||
getCachedData: (state, id) => selectPostReward(state, id), | ||
saveToCacheAction: data => slice.actions.setPostRewards(data), | ||
shouldFetchCondition: ({ postIds }) => postIds?.length !== 0, | ||
filterNewArgs: ({ postIds }, isNewId) => { | ||
const newPostIds = postIds?.filter(postId => isNewId(postId)) | ||
return { postIds: newPostIds } | ||
}, | ||
}) | ||
|
||
const slice = createSlice({ | ||
name: sliceName, | ||
initialState: adapter.getInitialState(), | ||
reducers: { | ||
setPostRewards: adapter.upsertMany, | ||
}, | ||
}) | ||
|
||
export default slice.reducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.