Skip to content

Commit

Permalink
fix: reset voting power store while switching accounts (#1070)
Browse files Browse the repository at this point in the history
* fix: voting power check while switching accounts

* reset inside store instead of composibles
  • Loading branch information
ChaituVR authored Jan 9, 2025
1 parent 572446d commit ca9f7f7
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 64 deletions.
7 changes: 1 addition & 6 deletions apps/ui/src/components/Modal/Vote.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ const emit = defineEmits<{
const { vote } = useActions();
const { web3 } = useWeb3();
const {
get: getVotingPower,
fetch: fetchVotingPower,
reset: resetVotingPower
} = useVotingPower();
const { get: getVotingPower, fetch: fetchVotingPower } = useVotingPower();
const proposalsStore = useProposalsStore();
const { loadVotes, votes } = useAccount();
const route = useRoute();
Expand Down Expand Up @@ -138,7 +134,6 @@ watch(
if (fromAccount && toAccount && fromAccount !== toAccount) {
loading.value = true;
resetVotingPower();
form.value.reason = '';
await loadVotes(props.proposal.network, [props.proposal.space.id]);
}
Expand Down
13 changes: 1 addition & 12 deletions apps/ui/src/composables/usePropositionPower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,5 @@ export function usePropositionPower() {
);
}

function reset() {
votingPowersStore.reset();
}

watch(
() => web3.value.account,
account => {
if (!account) reset();
}
);

return { fetch, get, reset };
return { fetch, get };
}
13 changes: 1 addition & 12 deletions apps/ui/src/composables/useVotingPower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,5 @@ export function useVotingPower() {
);
}

function reset() {
votingPowersStore.reset();
}

watch(
() => web3.value.account,
account => {
if (!account) reset();
}
);

return { get, fetch, reset };
return { get, fetch };
}
14 changes: 14 additions & 0 deletions apps/ui/src/stores/votingPowers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ function getIsSpaceMember(space: Space, account: string): boolean {
}

export const useVotingPowersStore = defineStore('votingPowers', () => {
const { web3 } = useWeb3();

const votingPowers = reactive<Map<string, VotingPowerItem>>(new Map());

async function fetch(
Expand Down Expand Up @@ -133,6 +135,18 @@ export const useVotingPowersStore = defineStore('votingPowers', () => {
votingPowers.clear();
}

watch(
() => web3.value.account,
(fromAccount, toAccount) => {
if (
!toAccount ||
(fromAccount && toAccount && fromAccount !== toAccount)
) {
reset();
}
}
);

return {
votingPowers,
fetch,
Expand Down
14 changes: 3 additions & 11 deletions apps/ui/src/views/Proposal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ const props = defineProps<{
const route = useRoute();
const proposalsStore = useProposalsStore();
const {
get: getVotingPower,
fetch: fetchVotingPower,
reset: resetVotingPower
} = useVotingPower();
const { get: getVotingPower, fetch: fetchVotingPower } = useVotingPower();
const { setTitle } = useTitle();
const { web3 } = useWeb3();
const { modalAccountOpen } = useModal();
Expand Down Expand Up @@ -128,12 +124,8 @@ function handleFetchVotingPower() {
watch(
[proposal, () => web3.value.account, () => web3.value.authLoading],
([toProposal, toAccount, toAuthLoading], [, fromAccount]) => {
if (fromAccount && toAccount && fromAccount !== toAccount) {
resetVotingPower();
}
if (toAuthLoading || !toProposal || !toAccount) return;
([proposal, account, authLoading]) => {
if (authLoading || !proposal || !account) return;
handleFetchVotingPower();
},
Expand Down
17 changes: 5 additions & 12 deletions apps/ui/src/views/Space/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ const {
reset
} = useWalletConnectTransaction();
const proposalsStore = useProposalsStore();
const {
get: getPropositionPower,
fetch: fetchPropositionPower,
reset: resetPropositionPower
} = usePropositionPower();
const { get: getPropositionPower, fetch: fetchPropositionPower } =
usePropositionPower();
const { strategiesWithTreasuries } = useTreasuries(props.space);
const termsStore = useTermsStore();
const timestamp = useTimestamp({ interval: 1000 });
Expand Down Expand Up @@ -345,12 +342,8 @@ function handleFetchPropositionPower() {
watch(
[() => web3.value.account, () => web3.value.authLoading],
([toAccount, toAuthLoading], [fromAccount]) => {
if (fromAccount && toAccount && fromAccount !== toAccount) {
resetPropositionPower();
}
if (toAuthLoading || !toAccount) return;
([account, authLoading]) => {
if (!account || authLoading) return;
handleFetchPropositionPower();
},
Expand Down Expand Up @@ -425,7 +418,7 @@ watchEffect(() => {
!!web3.account &&
(sending ||
!propositionPower ||
propositionPower.status === 'loading')
propositionPower?.status === 'loading')
"
:disabled="!canSubmit"
@click="handleProposeClick"
Expand Down
14 changes: 3 additions & 11 deletions apps/ui/src/views/Space/Proposals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import { Space } from '@/types';
const props = defineProps<{ space: Space }>();
const { setTitle } = useTitle();
const {
get: getVotingPower,
fetch: fetchVotingPower,
reset: resetVotingPower
} = useVotingPower();
const { get: getVotingPower, fetch: fetchVotingPower } = useVotingPower();
const { web3 } = useWeb3();
const router = useRouter();
const route = useRoute();
Expand Down Expand Up @@ -97,12 +93,8 @@ watch(
watch(
[props.space, () => web3.value.account, () => web3.value.authLoading],
([toSpace, toAccount, toAuthLoading], [, fromAccount]) => {
if (fromAccount && toAccount && fromAccount !== toAccount) {
resetVotingPower();
}
if (toAuthLoading || !toSpace || !toAccount) return;
([proposal, account, authLoading]) => {
if (authLoading || !proposal || !account) return;
handleFetchVotingPower();
},
Expand Down

0 comments on commit ca9f7f7

Please sign in to comment.