Skip to content

Commit

Permalink
reset inside store instead of composibles
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaituVR committed Jan 8, 2025
1 parent ea3866e commit fe90b0a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 70 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 };
}
18 changes: 15 additions & 3 deletions apps/ui/src/stores/votingPowers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type VotingPowerItem = {
error: utils.errors.VotingPowerDetailsError | null;
canPropose: boolean;
canVote: boolean;
account: string;
};

export function getIndex(space: SpaceDetails, block: number | null): string {
Expand Down Expand Up @@ -45,6 +44,8 @@ function isSpaceMember(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 All @@ -65,8 +66,7 @@ export const useVotingPowersStore = defineStore('votingPowers', () => {
symbol: space.voting_power_symbol,
error: null,
canPropose: false,
canVote: false,
account
canVote: false
};

if (existingVotingPower) {
Expand Down Expand Up @@ -135,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
20 changes: 5 additions & 15 deletions apps/ui/src/views/Space/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,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 @@ -327,15 +324,8 @@ function handleFetchPropositionPower() {
watch(
[() => web3.value.account, () => web3.value.authLoading],
([toAccount, toAuthLoading], [fromAccount]) => {
if (
(fromAccount && toAccount && fromAccount !== toAccount) ||
propositionPower.value?.account !== toAccount
) {
resetPropositionPower();
}
if (toAuthLoading || !toAccount) return;
([account, authLoading]) => {
if (!account || authLoading) return;
handleFetchPropositionPower();
},
Expand Down Expand Up @@ -410,7 +400,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 fe90b0a

Please sign in to comment.