Skip to content

Commit

Permalink
Merge pull request #3 from SweetmanTech/sweets/heno
Browse files Browse the repository at this point in the history
Sweets/heno
  • Loading branch information
SweetmanTech authored Jan 18, 2024
2 parents b4e42f0 + 5667ff5 commit cc5ba0f
Show file tree
Hide file tree
Showing 9 changed files with 1,232 additions and 7,504 deletions.
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
# onchain-magic

## 0.2.6

### Patch Changes

- I read drop price using saleStrategy instead of hard-coded.

## 0.2.5

### Patch Changes

- I try adding useZoraFixedPriceSaleStrategy again.

## 0.2.4

### Patch Changes

- I rollback to stable.

## 0.3.0

### Minor Changes

- I init useZoraFixedPriceSaleStrategy hook.

## 0.2.3

### Patch Changes

- I reduce lines for import in use1155Collect.

## 0.2.2

### Patch Changes

- I update ethers import for defaultAbiEncoder.

## 0.2.1

### Patch Changes

- I add use1155Collect to exports for package.

## 0.2.0

### Minor Changes

- init use1155Collect

## 0.1.26

### Patch Changes
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Getting started

- Documentation can be found here: [docs.onchainmagic.xyz](https://docs.onchainmagic.xyz)

```bash
npm install onchain-magic
# or
Expand Down
48 changes: 48 additions & 0 deletions hooks/use1155Collect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useMemo } from "react";
import { BigNumber, Contract, utils } from "ethers";
import { useEthersSigner } from "./useEthersSigner";
import abi from "../lib/abi/Zora1155Drop.json";
import { useZoraFixedPriceSaleStrategy } from "..";

const use1155Collect = (zora1155Drop: string, minterAddress: string) => {
const signer = useEthersSigner();
const zora1155DropContract = useMemo(
() => new Contract(zora1155Drop, abi, signer),
[zora1155Drop, signer]
);
const { sale } = useZoraFixedPriceSaleStrategy(minterAddress);

const mintWithRewards = async (
tokenId: string,
to: string,
referral: string,
comment = "🪄🪄🪄"
) => {
const response = await sale(zora1155Drop, "1");
const zoraFee = BigNumber.from("777000000000000");
const value = BigNumber.from(response.pricePerToken.toString()).add(
zoraFee
);
const minterArguments = utils.defaultAbiCoder.encode(
["address", "string"],
[to, comment]
);
const tx = await zora1155DropContract.mintWithRewards(
minterAddress,
tokenId,
1,
minterArguments,
referral,
{
value,
}
);

const receipt = await tx.wait();
return receipt;
};

return { mintWithRewards };
};

export default use1155Collect;
25 changes: 25 additions & 0 deletions hooks/useZoraFixedPriceSaleStrategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Contract } from "ethers";
import { useMemo } from "react";
import { useEthersSigner } from "./useEthersSigner";
import abi from "../lib/abi/ZoraCreatorFixedPriceSaleStrategy.json";

const useZoraFixedPriceSaleStrategy = (saleConfig: string) => {
const signer = useEthersSigner();
const saleConfigContract = useMemo(
() => new Contract(saleConfig, abi, signer),
[saleConfig, signer]
);

const sale = async (tokenContract: string, tokenId: string) => {
try {
const response = await saleConfigContract.sale(tokenContract, tokenId);
return response;
} catch (error) {
return error;
}
};

return { sale };
};

export default useZoraFixedPriceSaleStrategy;
4 changes: 4 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import useCreate1155Contract from "./hooks/useCreate1155Contract";
import { useEthersSigner } from "./hooks/useEthersSigner"
import { uploadToIpfs, store } from "./lib/ipfs"
import type { Create1155ContractArgs } from "./lib/types/Create1155ContractArgs"
import use1155Collect from "./hooks/use1155Collect";
import useZoraFixedPriceSaleStrategy from "./hooks/useZoraFixedPriceSaleStrategy";

export {
// IPFS
Expand All @@ -11,6 +13,8 @@ export {
// ZORA
useCreate1155Contract,
type Create1155ContractArgs,
use1155Collect,
useZoraFixedPriceSaleStrategy,

// ETHERS
useEthersSigner
Expand Down
Loading

0 comments on commit cc5ba0f

Please sign in to comment.