Skip to content

Commit

Permalink
Merge pull request #108 from BibliothecaDAO/main
Browse files Browse the repository at this point in the history
Fix wk11-35 Claim
  • Loading branch information
RedBeardEth authored Jan 28, 2024
2 parents 3e98aca + 11d7ea5 commit aca7749
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
1 change: 1 addition & 0 deletions apps/nextjs/src/app/providers/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const config = getDefaultConfig({
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
[mainnet.id]: http(),
},
});

Expand Down
51 changes: 23 additions & 28 deletions apps/nextjs/src/app/staking/StakingContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ const realmsAddress = getTokenContractAddresses("realms").L1;

export const StakingContainer = () => {
const { address: addressL1, isConnected } = useAccount();

const [hexProof, setHexProof] = useState();
const [poolTotal, setPoolTotal] = useState<bigint>(0n);
const [poolClaimAmount, setPoolClaimAmount] = useState<bigint>();
const [calculatedPoolAmount, setCalculatedPoolAmount] = useState(false);

const [poolTotal, setPoolTotal] = useState<bigint>();
const address = addressL1 ? addressL1.toLowerCase() : "0x";

const { data: realmsData, isLoading: realmsDataIsLoading } = useQuery({
Expand Down Expand Up @@ -98,38 +94,33 @@ export const StakingContainer = () => {
data: poolClaimData,
isPending: isPoolClaimLoading,
writeContract: claimPoolLords,
error: poolClaimError,
} = useWriteContract();

const {
data: poolWithdrawlsData,
isLoading: poolWithdrawalsLoading,
error,
isFetched,
} = useReadContract({
address: stakingAddresses[NETWORK_NAME].paymentPool as `0x${string}`,
abi: paymentPoolAbi,
functionName: "withdrawals",
args: [address as `0x${string}`],
args: [addressL1 as `0x${string}`],
// query: { enabled: !!address && !!poolTotal }
});

useEffect(() => {
const fetchStakingData = async () => {
if (addressL1 && !poolWithdrawalsLoading) {
if (addressL1) {
try {
const response = await fetch(`/api/staking/${addressL1}`);
const data = await response.json();
console.log(data);
setHexProof(data.proof);
if (data.amount) {
setPoolTotal(parseEther(data.amount.toString()));

const claimable =
BigInt(data.amount.toString()) -
BigInt(poolWithdrawlsData ?? "0");

console.log("Claimable:", parseEther(claimable.toString()));
setPoolClaimAmount(parseEther(claimable.toString()));
setCalculatedPoolAmount(true);
} else {
setPoolTotal(0n);
}
} catch (error) {
console.error("Error fetching staking data:", error);
Expand All @@ -138,11 +129,19 @@ export const StakingContainer = () => {
};

fetchStakingData();
}, [addressL1, isFetched, poolWithdrawlsData]);
}, [addressL1]);

const wk1135ClaimAmount =
poolTotal && poolWithdrawlsData
? formatEther(poolTotal - poolWithdrawlsData)
: "0";

if (isConnected && addressL1) {
return (
<div className="text-center">
{poolClaimError && (
<Alert message={poolClaimError.toString()} variant="warning" />
)}
<div className="col-span-2 flex flex-col ">
<h3>Your Realms</h3>
<div className="flex flex-col rounded border bg-dark-green pb-8 pt-6">
Expand Down Expand Up @@ -235,28 +234,24 @@ export const StakingContainer = () => {
<span className="mr-6 text-sm">Epoch 11-35:</span>
<span className="mr-3 flex">
<Lords className="mr-2 h-5 w-5 fill-current" />
{formatEther(poolClaimAmount ?? 0n).toLocaleString()} /{" "}
{formatEther(poolTotal ?? 0n).toLocaleString() ?? 0n}
{poolWithdrawlsData !== undefined && poolTotal !== undefined
? wk1135ClaimAmount.toLocaleString()
: "Loading"}
/ {formatEther(poolTotal ?? 0n).toLocaleString() ?? 0n}
</span>
<Button
disabled={poolClaimAmount == 0n || isPoolClaimLoading}
disabled={wk1135ClaimAmount == "0"}
size={"sm"}
className="self-center"
variant={"outline"}
onClick={() => {
console.log(
parseUnits(poolClaimAmount?.toString() ?? "0", 0),
hexProof as any,
);
console.log(parseEther(wk1135ClaimAmount), hexProof as any);
claimPoolLords({
address: stakingAddresses[NETWORK_NAME]
.paymentPool as `0x${string}`,
abi: paymentPoolAbi,
functionName: "withdraw",
args: [
parseUnits(poolClaimAmount?.toString() ?? "0", 0),
hexProof as any,
],
args: [parseEther(wk1135ClaimAmount), hexProof as any],
});
}}
>
Expand Down

0 comments on commit aca7749

Please sign in to comment.