Skip to content

Commit

Permalink
Add claiming votes
Browse files Browse the repository at this point in the history
  • Loading branch information
vkulinich-cl committed Jun 6, 2024
1 parent bc8cb19 commit 1077d5b
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useMedia } from "react-use"
import { theme } from "theme"
import { useRpcProvider } from "providers/rpcProvider"
import { useAccount } from "sections/web3-connect/Web3Connect.utils"
import { useProcessedVotesIds } from "api/staking"

export const AvailableRewards = () => {
const { api, assets } = useRpcProvider()
Expand All @@ -29,6 +30,8 @@ export const AvailableRewards = () => {
const reward = useClaimReward()
const spotPrice = useDisplayPrice(assets.native.id)

const processedVotes = useProcessedVotesIds()

const { createTransaction } = useStore()
const queryClient = useQueryClient()

Expand All @@ -54,9 +57,16 @@ export const AvailableRewards = () => {
return memo
}, {} as ToastMessage)

const processedVoteIds = await processedVotes.mutateAsync()

await createTransaction(
{
tx: api.tx.staking.claim(reward.data?.positionId!),
tx: processedVoteIds.length
? api.tx.utility.batchAll([
...processedVoteIds.map((id) => api.tx.democracy.removeVote(id)),
api.tx.staking.claim(reward.data?.positionId!),
])
: api.tx.staking.claim(reward.data?.positionId!),
},
{ toast },
)
Expand Down Expand Up @@ -199,11 +209,7 @@ export const AvailableRewards = () => {
size="small"
variant="primary"
fullWidth
disabled={
!reward.data ||
reward.data.rewards.isZero() ||
account?.isExternalWalletConnected
}
disabled={!reward.data || reward.data.rewards.isZero()}
onClick={onClaimRewards}
>
{t("staking.dashboard.rewards.button")}
Expand Down

0 comments on commit 1077d5b

Please sign in to comment.