Skip to content

Commit

Permalink
feat(stake page): useBalance for OP Sepolia
Browse files Browse the repository at this point in the history
  • Loading branch information
solidovic committed Sep 19, 2024
1 parent 79ccaeb commit a36d0b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions consts/staking-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import invariant from 'tiny-invariant';
import { PartialStakingRouterAbi__factory } from 'generated/factories/PartialStakingRouterAbi__factory';

export const STAKING_ROUTER_BY_NETWORK: {
[key in CHAINS]?: string;
[key in CHAINS]?: string | null;
} = {
[CHAINS.Mainnet]: '0xFdDf38947aFB03C621C71b06C9C70bce73f12999',
[CHAINS.Holesky]: '0xd6EbF043D30A7fe46D1Db32BA90a0A51207FE229',
[CHAINS.Sepolia]: '0x4F36aAEb18Ab56A4e380241bea6ebF215b9cb12c',
[CHAINS.OptimismSepolia]: null,
};

export const getStakingRouterAddress = (chainId: CHAINS): string => {
export const getStakingRouterAddress = (chainId: CHAINS): string | null => {
const address = STAKING_ROUTER_BY_NETWORK[chainId];
invariant(address, 'chain is not supported');
invariant(address !== undefined, 'chain is not supported');
return address;
};

Expand Down
18 changes: 12 additions & 6 deletions shared/hooks/use-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { AbstractLidoSDKErc20 } from '@lidofinance/lido-ethereum-sdk/erc20'
import type { GetBalanceData } from 'wagmi/query';
import type { Address, WatchContractEventOnLogsFn } from 'viem';
import { config } from 'config';
import { CHAINS } from 'consts/chains';

const nativeToBN = (data: bigint) => BigNumber.from(data.toString());

Expand Down Expand Up @@ -251,17 +252,19 @@ export const useStethBalance = ({
account,
shouldSubscribeToUpdates = true,
}: UseBalanceProps = {}) => {
const { address } = useAccount();
const { address, chainId } = useAccount();
const mergedAccount = account ?? address;

const { steth, core } = useLidoSDK();
const { steth, core, l2 } = useLidoSDK();

const isL2 = chainId === CHAINS.OPSepoliaTestnet;

const { data: contract, isLoading } = useQuery({
queryKey: ['steth-contract', core.chainId],
enabled: !!mergedAccount,

staleTime: Infinity,
queryFn: async () => steth.getContract(),
queryFn: async () => (isL2 ? l2.steth.getContract() : steth.getContract()),
});

const balanceData = useTokenBalance(
Expand All @@ -277,16 +280,19 @@ export const useWstethBalance = ({
account,
shouldSubscribeToUpdates = true,
}: UseBalanceProps = {}) => {
const { address } = useAccount();
const { address, chainId } = useAccount();
const mergedAccount = account ?? address;

const { wsteth, core } = useLidoSDK();
const { wsteth, core, l2 } = useLidoSDK();

const isL2 = chainId === CHAINS.OPSepoliaTestnet;

const { data: contract, isLoading } = useQuery({
queryKey: ['wsteth-contract', core.chainId],
enabled: !!mergedAccount,
staleTime: Infinity,
queryFn: async () => wsteth.getContract(),
queryFn: async () =>
isL2 ? l2.wsteth.getContract() : wsteth.getContract(),
});

const balanceData = useTokenBalance(
Expand Down

0 comments on commit a36d0b2

Please sign in to comment.