Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove underlyingTokenAddress and loadUnderlyingERC20Token #2625

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 3 additions & 35 deletions src/hooks/DAO/loaders/governance/useERC20LinearToken.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { abis } from '@fractal-framework/fractal-contracts';
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useCallback, useEffect, useRef } from 'react';
import { getContract } from 'viem';
import { useAccount, usePublicClient } from 'wagmi';
import { useFractal } from '../../../../providers/App/AppProvider';
Expand All @@ -10,25 +10,13 @@ export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) =
const tokenAccount = useRef<string>();

const {
governanceContracts: { votesTokenAddress, underlyingTokenAddress },
governanceContracts: { votesTokenAddress },
action,
} = useFractal();
const user = useAccount();
const account = user.address;
const publicClient = usePublicClient();

const underlyingTokenContract = useMemo(() => {
if (!underlyingTokenAddress || !publicClient) {
return;
}

return getContract({
abi: abis.VotesERC20,
address: underlyingTokenAddress,
client: publicClient,
});
}, [publicClient, underlyingTokenAddress]);

const loadERC20Token = useCallback(async () => {
if (!votesTokenAddress || !publicClient) {
return;
Expand Down Expand Up @@ -57,26 +45,6 @@ export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) =
action.dispatch({ type: FractalGovernanceAction.SET_TOKEN_DATA, payload: tokenData });
}, [action, publicClient, votesTokenAddress]);

const loadUnderlyingERC20Token = useCallback(async () => {
if (!underlyingTokenContract) {
return;
}

const [tokenName, tokenSymbol] = await Promise.all([
underlyingTokenContract.read.name(),
underlyingTokenContract.read.symbol(),
]);
const tokenData = {
name: tokenName,
symbol: tokenSymbol,
address: underlyingTokenContract.address,
};
action.dispatch({
type: FractalGovernanceAction.SET_UNDERLYING_TOKEN_DATA,
payload: tokenData,
});
}, [underlyingTokenContract, action]);

const loadERC20TokenAccountData = useCallback(async () => {
if (!account || !votesTokenAddress || !publicClient) {
action.dispatch({ type: FractalGovernanceAction.RESET_TOKEN_ACCOUNT_DATA });
Expand Down Expand Up @@ -209,5 +177,5 @@ export const useERC20LinearToken = ({ onMount = true }: { onMount?: boolean }) =
};
}, [account, loadERC20TokenAccountData, onMount, publicClient, votesTokenAddress]);

return { loadERC20Token, loadUnderlyingERC20Token, loadERC20TokenAccountData };
return { loadERC20Token, loadERC20TokenAccountData };
};
4 changes: 1 addition & 3 deletions src/hooks/DAO/loaders/useFractalGovernance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useFractalGovernance = () => {
const loadDAOProposals = useLoadDAOProposals();
const loadERC20Strategy = useERC20LinearStrategy();
const loadERC721Strategy = useERC721LinearStrategy();
const { loadERC20Token, loadUnderlyingERC20Token } = useERC20LinearToken({});
const { loadERC20Token } = useERC20LinearToken({});
const { loadLockedVotesToken } = useLockRelease({});
const loadERC721Tokens = useERC721Tokens();
const ipfsClient = useIPFSClient();
Expand Down Expand Up @@ -117,7 +117,6 @@ export const useFractalGovernance = () => {
});
loadERC20Strategy();
loadERC20Token();
loadUnderlyingERC20Token();
if (lockReleaseAddress) {
loadLockedVotesToken();
}
Expand All @@ -138,7 +137,6 @@ export const useFractalGovernance = () => {
}
}, [
governanceContracts,
loadUnderlyingERC20Token,
loadERC20Strategy,
loadERC20Token,
loadLockedVotesToken,
Expand Down
2 changes: 0 additions & 2 deletions src/hooks/DAO/loaders/useGovernanceContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const useGovernanceContracts = () => {
let linearVotingErc20WithHatsWhitelistingAddress: Address | undefined;
let linearVotingErc721WithHatsWhitelistingAddress: Address | undefined;
let votesTokenAddress: Address | undefined;
let underlyingTokenAddress: Address | undefined;
let lockReleaseAddress: Address | undefined;

const setGovTokenAddress = async (erc20VotingStrategyAddress: Address) => {
Expand Down Expand Up @@ -122,7 +121,6 @@ export const useGovernanceContracts = () => {
linearVotingErc721Address,
linearVotingErc721WithHatsWhitelistingAddress,
votesTokenAddress,
underlyingTokenAddress,
lockReleaseAddress,
moduleAzoriusAddress: azoriusModule.moduleAddress,
},
Expand Down
6 changes: 0 additions & 6 deletions src/providers/App/governance/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
FractalProposalState,
VotesData,
VotingStrategy,
UnderlyingTokenData,
GovernanceType,
ERC721TokenData,
} from '../../../types';
Expand All @@ -30,7 +29,6 @@ export enum FractalGovernanceAction {
SET_TOKEN_ACCOUNT_DATA = 'SET_TOKEN_ACCOUNT_DATA',
SET_CLAIMING_CONTRACT = 'SET_CLAIMING_CONTRACT',
RESET_TOKEN_ACCOUNT_DATA = 'RESET_TOKEN_ACCOUNT_DATA',
SET_UNDERLYING_TOKEN_DATA = 'SET_UNDERLYING_TOKEN_DATA',
PENDING_PROPOSAL_ADD = 'PENDING_PROPOSAL_ADD',
}

Expand Down Expand Up @@ -88,10 +86,6 @@ export type FractalGovernanceActions =
type: FractalGovernanceAction.SET_TOKEN_DATA;
payload: ERC20TokenData;
}
| {
type: FractalGovernanceAction.SET_UNDERLYING_TOKEN_DATA;
payload: UnderlyingTokenData;
}
| {
type: FractalGovernanceAction.SET_TOKEN_ACCOUNT_DATA;
payload: VotesData;
Expand Down
4 changes: 0 additions & 4 deletions src/providers/App/governance/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ export const governanceReducer = (state: FractalGovernance, action: FractalGover
case FractalGovernanceAction.SET_ERC721_TOKENS_DATA: {
return { ...state, erc721Tokens: action.payload };
}
case FractalGovernanceAction.SET_UNDERLYING_TOKEN_DATA: {
const { votesToken } = state as AzoriusGovernance;
return { ...state, votesToken: { ...votesToken, underlyingTokenData: action.payload } };
}
case FractalGovernanceAction.SET_TOKEN_ACCOUNT_DATA: {
const { votesToken } = state as AzoriusGovernance;
return { ...state, votesToken: { ...votesToken, ...action.payload } };
Expand Down
5 changes: 0 additions & 5 deletions src/types/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ export interface VotesData {
delegatee: Address | null;
votingWeight: bigint | null;
}
export type UnderlyingTokenData = Omit<
ERC20TokenData,
'totalSupply' | 'decimals' | 'underlyingTokenData'
>;

export interface BaseTokenData {
name: string;
Expand All @@ -19,7 +15,6 @@ export interface BaseTokenData {
export interface ERC20TokenData extends BaseTokenData {
decimals: number;
totalSupply: bigint;
underlyingTokenData?: UnderlyingTokenData;
}

export interface ERC721TokenData extends BaseTokenData {
Expand Down
1 change: 0 additions & 1 deletion src/types/fractal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ export interface FractalGovernanceContracts {
moduleAzoriusAddress?: Address;
votesTokenAddress?: Address;
lockReleaseAddress?: Address;
underlyingTokenAddress?: Address;
isLoaded: boolean;
}

Expand Down
Loading