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

feat: add a button to claim withdrawals #27

Merged
merged 1 commit into from
Nov 6, 2023
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
36,222 changes: 4,698 additions & 31,524 deletions package-lock.json

Large diffs are not rendered by default.

429 changes: 169 additions & 260 deletions src/abis/deposit.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/hooks/use-claim-balance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useEffect, useState } from "react";
import useDepositContract from "./use-deposit-contract";

function useClaimBalance(depositContractAddress, wallet) {
const contract = useDepositContract(depositContractAddress, wallet);
const [balance, setBalance] = useState(0n);

useEffect(() => {
if (!contract) {
return;
}

contract.withdrawableAmount(wallet.address).then(setBalance);
}, [contract, wallet.address]);

return balance;
}

export default useClaimBalance;
25 changes: 25 additions & 0 deletions src/hooks/use-deposit-contract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useEffect, useState } from "react";
import { Contract } from "ethers";

import depositAbi from "../abis/deposit";

function useDepositContract(depositContractAddress, wallet) {
const [contract, setContract] = useState();

useEffect(() => {
if (!depositContractAddress || !wallet) {
return;
}

const contract = new Contract(
depositContractAddress,
depositAbi,
wallet.provider.getSigner()
);
setContract(contract);
}, [depositContractAddress, wallet]);

return contract;
}

export default useDepositContract;
1 change: 1 addition & 0 deletions src/hooks/use-stepper-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const Step = {
DepositPending: 'deposit_pending',
DepositOverview: 'deposit_overview',
ValidatorStatus: 'validator_status',
WithdrawalClaim: 'withdrawal_claim'
}

function useStepperData () {
Expand Down
12 changes: 11 additions & 1 deletion src/views/stepper/stepper.view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import ValidatorStatus from '../validator-status/validator-status.view'
import useDappnodeWhitelist from '../../hooks/use-dappnode-whitelist'
import useDappnodeContract from '../../hooks/use-dappnode-contract'
import { NETWORKS } from '../../constants';
import WithdrawalClaim from '../withdrawal-claim/withdrawal-claim.view'

function Stepper () {
const classes = useStepperStyles()
Expand All @@ -41,6 +42,7 @@ function Stepper () {
const tabs = [{ name: 'Deposit', step: Step.Deposit }]
if(network && network.addresses.dappnodeDeposit)
tabs.push({ name: 'DAppNode', step: Step.DappNodeDeposit })
tabs.push({name:'Withdrawal Claim', step: Step.WithdrawalClaim })
tabs.push({ name: 'Validator Status', step: Step.ValidatorStatus })

const [activeTab, setActiveTab] = useState(tabs[0].name)
Expand Down Expand Up @@ -82,7 +84,7 @@ function Stepper () {
key={tab.name}
className={activeTab === tab.name ? classes.tabActive : classes.tab}
onClick={() => selectTab(tab)}
disabled={![Step.Deposit, Step.DappNodeDeposit, Step.DepositOverview, Step.ValidatorStatus].includes(step)}
disabled={![Step.Deposit, Step.DappNodeDeposit, Step.DepositOverview, Step.ValidatorStatus, Step.WithdrawalClaim].includes(step)}
>
<span className={classes.tabName}>{tab.name}</span>
</button>
Expand Down Expand Up @@ -204,6 +206,14 @@ function Stepper () {
/>
)
}
case Step.WithdrawalClaim: {
return <WithdrawalClaim
wallet={wallet}
network={network}
tokenInfo={tokenInfo}
balance={tokenBalance}
onDisconnectWallet={disconnectWallet} />
}
default: {
return <></>
}
Expand Down
32 changes: 32 additions & 0 deletions src/views/withdrawal-claim/withdrawal-claim.styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createUseStyles } from "react-jss";

const useStyles = createUseStyles((theme) => ({
container: {
flex: 1,
display: "flex",
flexDirection: "column",
alignItems: "center",
paddingTop: theme.spacing(0),
paddingBottom: theme.spacing(4),
},
claimButton: {
fontSize: theme.spacing(2),
fontWeight: theme.fontWeights.bold,
margin: `${theme.spacing(12)}px auto ${theme.spacing(4)}px`,
padding: `${theme.spacing(3)}px 0`,
background: theme.palette.primary,
color: theme.palette.white,
width: "40%",
borderRadius: theme.spacing(12.5),
appearance: "none",
border: "none",
transition: theme.buttonTransition,
cursor: "pointer",
"&:disabled": {
background: theme.palette.grey.dark,
cursor: "default",
},
},
}));

export default useStyles;
55 changes: 55 additions & 0 deletions src/views/withdrawal-claim/withdrawal-claim.view.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Header from "../shared/header/header.view";
import useStyles from "./withdrawal-claim.styles";
import useClaimBalance from "../../hooks/use-claim-balance";
import { formatUnits } from "ethers/lib/utils";
import useDepositContract from "../../hooks/use-deposit-contract";
import { useState } from "react";

function WithdrawalClaim({ network, wallet, onDisconnectWallet, tokenInfo }) {
const classes = useStyles();
const claimBalance = useClaimBalance(network.addresses.deposit, wallet);
const contract = useDepositContract(network.addresses.deposit, wallet);
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");

const onClaim = async () => {
setLoading(true);
setError("");

try {
await contract.claimWithdrawal(wallet.address);
} catch (err) {
setError(err.message);
} finally {
setLoading(false);
}
};

return (
<div className={classes.container}>
<Header
address={wallet.address}
title="Gnosis Withdrawal Claims"
onDisconnectWallet={onDisconnectWallet}
tokenInfo={tokenInfo}
network={network}
/>

<div style={{ marginTop: "64px" }}>
Claimable balance:{" "}
{Number(formatUnits(claimBalance, tokenInfo.decimals))}{" "}
{tokenInfo.symbol}
</div>
<button
className={classes.claimButton}
onClick={onClaim}
disabled={loading}
>
Claim
</button>
{error}
</div>
);
}

export default WithdrawalClaim;