-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from peeldao/dl-and-balance
Feat: add hooks for distributionLimit and projectBalance
- Loading branch information
Showing
4 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters