diff --git a/packages/next-common/components/pages/components/gov2/sidebar/tally/myVote/info/delegated.js b/packages/next-common/components/pages/components/gov2/sidebar/tally/myVote/info/delegated.js
index 6bdba37fb5..c1a52fe6d5 100644
--- a/packages/next-common/components/pages/components/gov2/sidebar/tally/myVote/info/delegated.js
+++ b/packages/next-common/components/pages/components/gov2/sidebar/tally/myVote/info/delegated.js
@@ -1,34 +1,33 @@
import { useSharedDelegatingTargetReferendumVote } from "next-common/context/referenda/myVote/delegating";
import { useOnchainData } from "next-common/context/post";
import DelegatingVotePanel from "./delegatingPanel";
+import { Conviction, isAye } from "next-common/utils/referendumCommon";
export default function DelegatedVotePanel({ delegating }) {
const [targetVote] = useSharedDelegatingTargetReferendumVote();
const { referendumIndex } = useOnchainData();
- if (!targetVote || !targetVote.isCasting) {
+ if (!targetVote || targetVote.type !== "Casting") {
return null;
}
- const casting = targetVote.asCasting;
- const voteItem = casting.votes.find(
- (item) => item[0].toNumber() === referendumIndex,
- );
+ const casting = targetVote.value;
+ const voteItem = casting.votes.find((item) => item[0] === referendumIndex);
if (!voteItem) {
return null;
}
const vote = voteItem[1];
- if (!vote.isStandard) {
+ if (vote.type !== "Standard") {
return null;
}
const balance = delegating.balance.toString();
- const conviction = delegating.conviction.toNumber();
+ const conviction = Conviction[delegating.conviction?.type] ?? 0;
return (
);
}
diff --git a/packages/next-common/components/pages/components/gov2/sidebar/tally/myVote/info/index.js b/packages/next-common/components/pages/components/gov2/sidebar/tally/myVote/info/index.js
index d42d3d9949..c1e2bf1a76 100644
--- a/packages/next-common/components/pages/components/gov2/sidebar/tally/myVote/info/index.js
+++ b/packages/next-common/components/pages/components/gov2/sidebar/tally/myVote/info/index.js
@@ -10,23 +10,23 @@ import { memo } from "react";
function CastingVoteInfo({ casting }) {
const { referendumIndex } = useOnchainData();
const votes = casting?.votes || [];
- const voteItem = votes.find((item) => item[0].toNumber() === referendumIndex);
+ const voteItem = votes.find((item) => item[0] === referendumIndex);
if (!voteItem) {
return null;
}
const vote = voteItem[1];
- if (vote.isStandard) {
+ if (vote.type === "Standard") {
return (
);
- } else if (vote.isSplit) {
- return ;
- } else if (vote.isSplitAbstain) {
- return ;
+ } else if (vote.type === "Split") {
+ return ;
+ } else if (vote.type === "SplitAbstain") {
+ return ;
} else {
return null;
}
@@ -57,9 +57,9 @@ export default function MyVoteOnActiveReferendum() {
if (!voting) {
return null;
- } else if (voting.isCasting) {
- return ;
- } else if (voting.isDelegating) {
- return ;
+ } else if (voting.type === "Casting") {
+ return ;
+ } else if (voting.type === "Delegating") {
+ return ;
}
}
diff --git a/packages/next-common/components/pages/components/gov2/sidebar/tally/myVote/info/standard.js b/packages/next-common/components/pages/components/gov2/sidebar/tally/myVote/info/standard.js
index 09cac02477..025d9627a5 100644
--- a/packages/next-common/components/pages/components/gov2/sidebar/tally/myVote/info/standard.js
+++ b/packages/next-common/components/pages/components/gov2/sidebar/tally/myVote/info/standard.js
@@ -1,4 +1,5 @@
import VotePanel from "./panel";
+import { isAye, getConviction } from "next-common/utils/referendumCommon";
import { memo } from "react";
function StandardVotePanel({ standard, delegations }) {
@@ -9,9 +10,9 @@ function StandardVotePanel({ standard, delegations }) {
const { vote, balance } = standard;
const normalized = {
isStandard: true,
- aye: vote.isAye,
+ aye: isAye(vote),
balance: balance.toString(),
- conviction: vote.conviction.toNumber(),
+ conviction: getConviction(vote),
};
return (
diff --git a/packages/next-common/context/referenda/myVote/delegating.js b/packages/next-common/context/referenda/myVote/delegating.js
index 0176447c84..278afda50e 100644
--- a/packages/next-common/context/referenda/myVote/delegating.js
+++ b/packages/next-common/context/referenda/myVote/delegating.js
@@ -1,5 +1,5 @@
import { createStateContext } from "react-use";
-import { useContextApi } from "next-common/context/api";
+import { useContextPapi } from "next-common/context/papi";
import { latestHeightSelector } from "next-common/store/reducers/chainSlice";
import { useSelector } from "react-redux";
import { useEffect } from "react";
@@ -8,19 +8,21 @@ const [useSharedDelegatingTargetReferendumVote, Provider] =
createStateContext(null);
function DataUpdater({ trackId, address, children }) {
- const api = useContextApi();
+ const { api, checkPallet } = useContextPapi();
const [, setTargetVote] = useSharedDelegatingTargetReferendumVote();
const height = useSelector(latestHeightSelector);
useEffect(() => {
- if (!api || !address || !api.query?.convictionVoting?.votingFor) {
+ if (!api || !address || !checkPallet("ConvictionVoting", "VotingFor")) {
return;
}
- api.query.convictionVoting.votingFor(address, trackId).then((voting) => {
- setTargetVote(voting);
- });
- }, [api, address, trackId, height, setTargetVote]);
+ api.query.ConvictionVoting.VotingFor.getValue(address, trackId).then(
+ (voting) => {
+ setTargetVote(voting);
+ },
+ );
+ }, [api, address, trackId, height, setTargetVote, checkPallet]);
return children;
}
diff --git a/packages/next-common/context/referenda/myVote/index.js b/packages/next-common/context/referenda/myVote/index.js
index c2a238de80..b6aab22d4b 100644
--- a/packages/next-common/context/referenda/myVote/index.js
+++ b/packages/next-common/context/referenda/myVote/index.js
@@ -1,5 +1,5 @@
import { createStateContext } from "react-use";
-import { useContextApi } from "next-common/context/api";
+import { useContextPapi } from "next-common/context/papi";
import { useEffect } from "react";
import { latestHeightSelector } from "next-common/store/reducers/chainSlice";
import { useSelector } from "react-redux";
@@ -8,19 +8,21 @@ import PopupOpenStateProvider from "next-common/context/popup/switch";
const [useSharedMyReferendumVote, Provider] = createStateContext(null);
function DataUpdater({ trackId, address, children }) {
- const api = useContextApi();
+ const { api, checkPallet } = useContextPapi();
const [, setMyVote] = useSharedMyReferendumVote();
const height = useSelector(latestHeightSelector);
useEffect(() => {
- if (!api || !address || !api.query?.convictionVoting?.votingFor) {
+ if (!api || !address || !checkPallet("ConvictionVoting", "VotingFor")) {
return;
}
- api.query.convictionVoting.votingFor(address, trackId).then((voting) => {
+ api.query.ConvictionVoting.VotingFor.getValue(address, trackId, {
+ at: "best",
+ }).then((voting) => {
setMyVote(voting);
});
- }, [api, address, trackId, height, setMyVote]);
+ }, [api, address, trackId, height, setMyVote, checkPallet]);
return children;
}