Skip to content

Commit

Permalink
Improve useGaslessGovernanceEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Feb 7, 2024
1 parent 4f239d8 commit 4aa5e61
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/membersList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const MembersList: React.FC<MembersListProps> = ({
// Gasless voting plugin support non wrapped tokens
// Used to hide delegation column in case of gasless voting plugin
const {data: daoDetails} = useDaoDetailsQuery();
const {isGovernanceEnabled} = useGaslessGovernanceEnabled(daoDetails);
const {isGovernanceEnabled} = useGaslessGovernanceEnabled({daoDetails});

const isTokenBasedDao = token != null;
const useCompactMode = isCompactMode ?? !isDesktop;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useExistingToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const useExistingToken = ({
} = {}) => {
const {api: provider} = useProviders();
const {data: daoDetailsFetched} = useDaoDetailsQuery();
const {isGovernanceEnabled} = useGaslessGovernanceEnabled(daoDetails);
const {isGovernanceEnabled} = useGaslessGovernanceEnabled({daoDetails});

const dao = useMemo(
() => daoDetails || daoDetailsFetched,
Expand Down
23 changes: 16 additions & 7 deletions src/hooks/useGaslessGovernanceEnabled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@ import {useVotingSettings} from '../services/aragon-sdk/queries/use-voting-setti
import {DaoDetails} from '@aragon/sdk-client';
import {GaslessPluginVotingSettings} from '@vocdoni/gasless-voting';

export const useGaslessGovernanceEnabled = (
daoDetails?: DaoDetails | null | undefined
) => {
const pluginType = daoDetails?.plugins[0].id as PluginTypes;
export const useGaslessGovernanceEnabled = ({
pluginType,
pluginAddress,
daoDetails,
}: {
pluginType?: PluginTypes;
pluginAddress?: string;
daoDetails?: DaoDetails | null | undefined;
}) => {
const pType =
pluginType ?? (daoDetails?.plugins[0].id as PluginTypes) ?? null;
const pAddress =
pluginAddress ?? (daoDetails?.plugins[0].instanceAddress as string) ?? null;
const {data: votingSettings} = useVotingSettings({
pluginAddress: daoDetails?.plugins[0].instanceAddress as string,
pluginType,
pluginAddress: pAddress,
pluginType: pType,
});

const isGasless = pluginType === GaselessPluginName;
const isGasless = pType === GaselessPluginName;
let isGovernanceEnabled = true;

if (isGasless) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/mintTokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const MintToken: React.FC = () => {
pluginAddress: daoDetails?.plugins[0].instanceAddress as string,
pluginType: daoDetails?.plugins[0].id as PluginTypes,
});
const {isGovernanceEnabled} = useGaslessGovernanceEnabled(daoDetails);
const {isGovernanceEnabled} = useGaslessGovernanceEnabled({daoDetails});

const {t} = useTranslation();
const {network} = useNetwork();
Expand Down
2 changes: 1 addition & 1 deletion src/services/aragon-sdk/queries/use-delegatee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useDelegatee = (
daoDetails: DaoDetails | null | undefined
) => {
const pluginType = daoDetails?.plugins[0].id as PluginTypes;
const {isGovernanceEnabled} = useGaslessGovernanceEnabled(daoDetails);
const {isGovernanceEnabled} = useGaslessGovernanceEnabled({daoDetails});

const client = usePluginClient(
pluginType === GaselessPluginName
Expand Down

0 comments on commit 4aa5e61

Please sign in to comment.