Skip to content

Commit

Permalink
Merge pull request #103 from BibliothecaDAO/claim-bug-fix
Browse files Browse the repository at this point in the history
bug
  • Loading branch information
ponderingdemocritus authored Jan 22, 2024
2 parents 3d95e91 + eb61296 commit 8fad3f3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
57 changes: 35 additions & 22 deletions apps/nextjs/src/app/staking/StakingContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const StakingContainer = () => {
functionName: "lordsAvailable",
args: [address as `0x${string}`],
});

const {
data: galleonClaimData,
isPending: isGalleonClaimLoading,
Expand Down Expand Up @@ -104,32 +105,40 @@ export const StakingContainer = () => {
isLoading: poolWithdrawalsLoading,
isFetched,
} = useReadContract({
address: stakingAddresses["MAIN"].paymentPool as `0x${string}`,
address: stakingAddresses[NETWORK_NAME].paymentPool as `0x${string}`,
abi: paymentPoolAbi,
functionName: "withdrawals",
args: [address as `0x${string}`],
// query: { enabled: !!address && !!poolTotal },
// query: { enabled: !!address && !!poolTotal }
});

console.log(poolTotal);

useEffect(() => {
if (addressL1) {
fetch(`/api/staking/${addressL1}`)
.then((res) => res.json())
.then((data) => {
const fetchStakingData = async () => {
if (addressL1 && !poolWithdrawalsLoading) {
try {
const response = await fetch(`/api/staking/${addressL1}`);
const data = await response.json();
console.log(data);
setHexProof(data.proof);
data.amount && setPoolTotal(parseEther(data.amount?.toString()));
});
}
if (isFetched && poolWithdrawlsData && !calculatedPoolAmount && poolTotal) {
console.log("poolWithdrawlsData", poolWithdrawlsData);
const claimable = poolTotal - poolWithdrawlsData;
setPoolClaimAmount(claimable);
setCalculatedPoolAmount(true);
}
}, [isFetched]);
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);
}
} catch (error) {
console.error("Error fetching staking data:", error);
}
}
};

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

if (isConnected && addressL1) {
return (
Expand Down Expand Up @@ -234,7 +243,11 @@ export const StakingContainer = () => {
size={"sm"}
className="self-center"
variant={"outline"}
onClick={() =>
onClick={() => {
console.log(
parseUnits(poolClaimAmount?.toString() ?? "0", 0),
hexProof as any,
);
claimPoolLords({
address: stakingAddresses[NETWORK_NAME]
.paymentPool as `0x${string}`,
Expand All @@ -244,8 +257,8 @@ export const StakingContainer = () => {
parseUnits(poolClaimAmount?.toString() ?? "0", 0),
hexProof as any,
],
})
}
});
}}
>
{isPoolClaimLoading ? (
<>
Expand Down Expand Up @@ -373,7 +386,7 @@ const StakingModal = ({
address: realmsAddress as `0x${string}`,
abi: ERC721,
functionName: "isApprovedForAll",
args: [address, galleonAddress],
args: [address as `0x${string}`, galleonAddress],
});

const { data: approvedTransactionData, isSuccess } =
Expand Down
1 change: 1 addition & 0 deletions apps/nextjs/src/hooks/useStaking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const useStaking = () => {};

0 comments on commit 8fad3f3

Please sign in to comment.