Skip to content

Commit

Permalink
Remove wagmi dependency to allow for web3js integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
philipjames44 committed Jul 9, 2024
1 parent 850c4c6 commit 40d158b
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 157 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "boring-vault-ui",
"version": "1.5.2",
"version": "1.6.0",
"description": "A reusable package to quickly integrate boring vaults onto a UI.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
13 changes: 7 additions & 6 deletions src/components/v1/DelayWithdrawButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { Token } from "../../types";
import { Contract, formatUnits } from "ethers";
import { erc20Abi } from "viem";
import { useEthersSigner } from "../../hooks/ethers";
import { useAccount } from "wagmi";

interface DelayWithdrawButtonProps {
buttonText: string;
Expand Down Expand Up @@ -70,8 +71,6 @@ const DelayWithdrawButton: React.FC<DelayWithdrawButtonProps> = ({
const { isOpen, onOpen, onClose } = useDisclosure();
const {
withdrawTokens,
isConnected,
userAddress,
ethersProvider,
withdrawStatus,
delayWithdraw,
Expand All @@ -88,10 +87,12 @@ const DelayWithdrawButton: React.FC<DelayWithdrawButtonProps> = ({

useEffect(() => {
async function fetchBalance() {
if (!userAddress || !ethersProvider) return;
if (!signer || !ethersProvider) return;

try {
const shareBalance = await fetchUserShares();
const shareBalance = await fetchUserShares(
await signer.getAddress(),
);
setBalance(shareBalance);
} catch (error) {
console.error("Failed to fetch share balance:", error);
Expand All @@ -100,7 +101,7 @@ const DelayWithdrawButton: React.FC<DelayWithdrawButtonProps> = ({
}

fetchBalance();
}, [userAddress, ethersProvider]);
}, [signer, ethersProvider]);

const handleSelectChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const newTokenAddress = event.target.value;
Expand Down Expand Up @@ -144,7 +145,7 @@ const DelayWithdrawButton: React.FC<DelayWithdrawButtonProps> = ({

return (
<>
<Button onClick={onOpen} isDisabled={!isConnected} {...buttonProps}>
<Button onClick={onOpen} isDisabled={!useAccount().isConnected} {...buttonProps}>
{buttonText}
</Button>
<Modal isOpen={isOpen} onClose={onClose} isCentered {...modalProps}>
Expand Down
11 changes: 5 additions & 6 deletions src/components/v1/DepositButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { Token } from "../../types";
import { Contract, formatUnits } from "ethers";
import { erc20Abi } from "viem";
import { useEthersSigner } from "../../hooks/ethers";
import { useAccount } from "wagmi";

interface DepositButtonProps {
buttonText: string;
Expand Down Expand Up @@ -70,8 +71,6 @@ const DepositButton: React.FC<DepositButtonProps> = ({
const { isOpen, onOpen, onClose } = useDisclosure();
const {
depositTokens,
isConnected,
userAddress,
ethersProvider,
deposit,
depositStatus,
Expand All @@ -88,7 +87,7 @@ const DepositButton: React.FC<DepositButtonProps> = ({
async function fetchBalance() {
console.log("Token:", selectedToken);

if (!userAddress || !selectedToken || !ethersProvider) return;
if (!signer || !selectedToken || !ethersProvider) return;

try {
const tokenContract = new Contract(
Expand All @@ -97,7 +96,7 @@ const DepositButton: React.FC<DepositButtonProps> = ({
ethersProvider
);

const tokenBalance = await tokenContract.balanceOf(userAddress);
const tokenBalance = await tokenContract.balanceOf(await signer.getAddress());
const formattedBalance = parseFloat(
formatUnits(tokenBalance, selectedToken.decimals)
);
Expand All @@ -109,7 +108,7 @@ const DepositButton: React.FC<DepositButtonProps> = ({
}

fetchBalance();
}, [userAddress, selectedToken, ethersProvider]);
}, [signer, selectedToken, ethersProvider]);

const handleSelectChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const newTokenAddress = event.target.value;
Expand Down Expand Up @@ -153,7 +152,7 @@ const DepositButton: React.FC<DepositButtonProps> = ({

return (
<>
<Button onClick={onOpen} isDisabled={!isConnected} {...buttonProps}>
<Button onClick={onOpen} isDisabled={!useAccount().isConnected} {...buttonProps}>
{buttonText}
</Button>
<Modal isOpen={isOpen} onClose={onClose} isCentered {...modalProps}>
Expand Down
4 changes: 3 additions & 1 deletion src/components/v1/PendingDelayedWithdraws.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const PendingDelayedWithdraws: React.FC<PendingDelayedWithdrawsProps> = ({
title,
...pendingDelayWithdrawProps
}) => {
const { isConnected, userAddress, ethersProvider, delayWithdrawStatuses } =
const { ethersProvider, delayWithdrawStatuses } =
useBoringVaultV1();
const [statuses, setStatuses] = useState<any[]>([]); // State to store fetched statuses
const signer = useEthersSigner();

useEffect(() => {
const fetchStatuses = async () => {
if (!signer) return;

const fetchedStatuses = await delayWithdrawStatuses(signer!);
setStatuses(fetchedStatuses);
};
Expand Down
5 changes: 3 additions & 2 deletions src/components/v1/PendingWithdrawQueueStatuses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ interface PendingWithdrawQueueStatusesProps {
const PendingWithdrawQueueStatuses: React.FC<
PendingWithdrawQueueStatusesProps
> = ({ title, ...pendingWithdrawQueueProps }) => {
const { isConnected, userAddress, ethersProvider, withdrawQueueStatuses } =
useBoringVaultV1();
const { ethersProvider, withdrawQueueStatuses } = useBoringVaultV1();
const [statuses, setStatuses] = useState<any[]>([]); // State to store fetched statuses
const signer = useEthersSigner();

useEffect(() => {
const fetchStatuses = async () => {
if (!signer) return;

const fetchedStatuses: WithdrawQueueStatus[] =
await withdrawQueueStatuses(signer!);
setStatuses(fetchedStatuses);
Expand Down
13 changes: 7 additions & 6 deletions src/components/v1/WithdrawQueueButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { Token } from "../../types";
import { Contract, formatUnits } from "ethers";
import { erc20Abi } from "viem";
import { useEthersSigner } from "../../hooks/ethers";
import { useAccount } from "wagmi";

interface WithdrawQueueButtonProps {
buttonText: string;
Expand Down Expand Up @@ -71,8 +72,6 @@ const WithdrawQueueButton: React.FC<WithdrawQueueButtonProps> = ({
const { isOpen, onOpen, onClose } = useDisclosure();
const {
withdrawTokens,
isConnected,
userAddress,
ethersProvider,
withdrawStatus,
queueWithdraw,
Expand All @@ -90,10 +89,12 @@ const WithdrawQueueButton: React.FC<WithdrawQueueButtonProps> = ({

useEffect(() => {
async function fetchBalance() {
if (!userAddress || !ethersProvider) return;
if (!signer || !ethersProvider) return;

try {
const shareBalance = await fetchUserShares();
const shareBalance = await fetchUserShares(
await signer.getAddress(),
);
setBalance(shareBalance);
} catch (error) {
console.error("Failed to fetch share balance:", error);
Expand All @@ -102,7 +103,7 @@ const WithdrawQueueButton: React.FC<WithdrawQueueButtonProps> = ({
}

fetchBalance();
}, [userAddress, ethersProvider]);
}, [signer, ethersProvider]);

const handleSelectChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
const newTokenAddress = event.target.value;
Expand Down Expand Up @@ -146,7 +147,7 @@ const WithdrawQueueButton: React.FC<WithdrawQueueButtonProps> = ({

return (
<>
<Button onClick={onOpen} isDisabled={!isConnected} {...buttonProps}>
<Button onClick={onOpen} isDisabled={!useAccount().isConnected} {...buttonProps}>
{buttonText}
</Button>
<Modal isOpen={isOpen} onClose={onClose} isCentered {...modalProps}>
Expand Down
Loading

0 comments on commit 40d158b

Please sign in to comment.