Skip to content

Commit

Permalink
fix: correct calculation of contract interface on read hook
Browse files Browse the repository at this point in the history
  • Loading branch information
aramalipoor committed Oct 7, 2022
1 parent 8630733 commit 5081125
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ A complete suite of Flair reusable components and clients for frontend and backe

## Packages

| Name | Description |
| :----------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------- |
| [@flair-sdk/react](./packages/react) | React hooks and components for features like Wallet, NFT Collections, Token Streams, etc. (browser only) |
| [@flair-sdk/metatx](./packages/metatx) | Extension to ether.js `Contract` classm to make all functions compatible with native meta transactions standard. (node.js and browser) |
| [@flair-sdk/registry](./packages/registry) | Compiled registry of Flair contract ABIs, bytecodes, addresses, and metadata for easy usage. (node.js and browser) |
| [@flair-sdk/ipfs](./packages/ipfs) | Utility functions to interact with IPFS, useful for NFT metadata storage. (node.js and browser) |
| Name | Description |
| :------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [@flair-sdk/react](./packages/react) | React hooks and components for features like Wallet, NFT Collections, Token Streams, etc. (browser only) |
| [@flair-sdk/metatx](./packages/metatx) | Extension to ether.js `Contract` class to make all functions compatible with native meta transactions standard ([ERC 2771](https://eips.ethereum.org/EIPS/eip-2771)). (node.js and browser) |
| [@flair-sdk/ipfs](./packages/ipfs) | Utility functions to interact with IPFS, useful for NFT metadata storage. (node.js and browser) |

## Documentation

Expand Down
6 changes: 5 additions & 1 deletion packages/metatx/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# `@flair-sdk/metatx`

A typescript (and Node.js) library to help construct and submit meta transactions using Flair's forwarder contracts.
A typescript (and Node.js) library to help construct and submit ([EIP-2771](https://eips.ethereum.org/EIPS/eip-2771)) meta transactions using Flair's forwarder contracts.

## Getting Started

#### Requirements

Your contracts need to have ERC-2771 support. [Flair](https://flair.dev) provides out-of-box support based on OpenZeppelin's ERC2771Context for contracts deployed.

### Installation

Install the package using NPM or Yarn:
Expand Down
23 changes: 14 additions & 9 deletions packages/react/src/common/hooks/useContractRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,20 @@ export const useContractRead = <ResultType = any, ArgsType = []>({
enabled && contractAddress && contractAddress !== ZERO_ADDRESS,
);

const finalContractInterface = useMemo(
() =>
contractDefinition?.artifact?.abi ||
contractInterface || [
`function ${
functionName.endsWith(')') ? functionName : `${functionName}()`
} view`,
],
[contractDefinition?.artifact?.abi, contractInterface, functionName],
);

const result = useContractReadWagmi({
addressOrName: contractAddress as string,
contractInterface: contractDefinition?.artifact?.abi ||
contractInterface || [`function ${functionName}`],
contractInterface: finalContractInterface,
functionName,
args,
enabled: readyToRead,
Expand All @@ -78,15 +88,10 @@ export const useContractRead = <ResultType = any, ArgsType = []>({

return new ethers.Contract(
contractAddress,
contractDefinition?.artifact?.abi || ['function ' + functionName],
finalContractInterface,
provider,
);
}, [
contractAddress,
contractDefinition?.artifact?.abi,
functionName,
provider,
]);
}, [contractAddress, finalContractInterface, provider]);

const call = useCallback(
async (overrides?: { args?: ArgsType }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useTieredSalesWalletMints = ({
contractInterface: [
'function walletMintedByTier(uint256 tierId, address wallet) external view returns (uint256)',
],
functionName: 'walletMintedByTier(uint256)',
functionName: 'walletMintedByTier(uint256,address)',
chainId,
contractAddress,
args: [tierId, walletAddress] as ArgsType,
Expand Down

0 comments on commit 5081125

Please sign in to comment.