Skip to content

Commit

Permalink
Merge pull request #33 from peeldao/dl-and-balance
Browse files Browse the repository at this point in the history
Feat: add hooks for distributionLimit and projectBalance
  • Loading branch information
johnnyd-eth authored Nov 9, 2023
2 parents 6f95053 + 58f3199 commit 14238a2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "juice-hooks",
"version": "10.14.6-beta",
"version": "10.15.1-beta",
"description": "Wagmi hooks for Juicebox",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
18 changes: 18 additions & 0 deletions src/react/hooks/juicebox/useEthTerminalBalance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useJBContractContext } from "src/react/contexts";
import { useJbSingleTokenPaymentTerminalStoreBalanceOf } from "../../generated/hooks";

/**
* Returns the balance of a project's ETH payment terminal.
*
* @returns The balance of the ETH payment terminal (in wei) stored as a `bigint`.
*/
export function useEthTerminalBalance() {
const { contracts } = useJBContractContext();
const { primaryTerminalEthStore } = contracts;

const balance = useJbSingleTokenPaymentTerminalStoreBalanceOf({
address: primaryTerminalEthStore.data,
});

return balance;
}
28 changes: 28 additions & 0 deletions src/react/hooks/juicebox/useProjectDistributionLimit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useContext } from "react";
import { JBCurrency } from "../../../constants";
import { useJbFundAccessConstraintsStoreDistributionLimitOf } from "../../generated/hooks";
import { useJBContractContext } from "src/react/contexts";
import { Ether } from "src/utils";

/**
* Hook to retrieve the distribution limit for the current project.
*
* @returns The distribution limit (and distribution limit currency) for the current project.
*/
export function useProjectDistributionLimit() {
const { contracts: { fundAccessConstraintsStore } } = useJBContractContext();
const distributionLimit = useJbFundAccessConstraintsStoreDistributionLimitOf({
address: fundAccessConstraintsStore.data,
});

const currency = distributionLimit?.data?.[1]
const distributionLimitAmount = distributionLimit?.data?.[0]

return {
...distributionLimit,
data: {
distributionLimit: distributionLimitAmount ? new Ether(distributionLimitAmount) : undefined,
distributionLimitCurrency: currency as JBCurrency | undefined,
},
};
}
2 changes: 2 additions & 0 deletions src/react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export * from "./hooks/jb721Delegate/useJb721DelegateTiers";
export * from "./hooks/juicebox/pay/usePayEthPaymentTerminal";
export * from "./hooks/useFormattedEthAddress";
export * from "./hooks/juicebox/distribute/useDistributeEthPaymentTerminal";
export * from "./hooks/juicebox/useProjectDistributionLimit";
export * from "./hooks/juicebox/useEthTerminalBalance";

0 comments on commit 14238a2

Please sign in to comment.