Skip to content

Commit

Permalink
Merge pull request #1 from SweetmanTech/sweets/0.1.1
Browse files Browse the repository at this point in the history
Sweets/0.1.1
  • Loading branch information
sweetmantech authored Dec 17, 2023
2 parents 3e21097 + 9e8d1b7 commit 5a3d287
Show file tree
Hide file tree
Showing 26 changed files with 22,857 additions and 27,122 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
63 changes: 63 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Lint

on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- main
pull_request:
branches:
- main
- test

jobs:
run-linters:
name: Run linters
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/[email protected]

- name: Set up Node.js
uses: actions/[email protected]
with:
node-version: 18
registry-url: "https://npm.pkg.github.com"

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache yarn cache
uses: actions/[email protected]
id: cache-yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-dev-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-dev-
- name: Cache node_modules
id: cache-node-modules
uses: actions/[email protected]
with:
path: node_modules
key: ${{ runner.os }}-${{ matrix.node-version }}-nodemodules-dev-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.node-version }}-nodemodules-dev-
- name: Install Dependencies
run: npm install --frozen-lockfile --prefer-offline

- name: Fix Formatting
run: yarn format

- name: Check linting
run: yarn run lint && yarn run build

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply formatting changes
branch: ${{ github.head_ref }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# npm
dist
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# onchain-magic

## 0.1.20

### Patch Changes

- I add description to Create1155ContractArgs

## 0.1.19

### Patch Changes

- 565fba7: I rearrange console logs and reduce the setupActions to try debugging final hiccups for first prototype.
- 4684a88: I update ethers imports in useCreate1155Contract hook to only reference top-level ethers package.
- 565fba7: I remove the get1155ProxyAddress lib. Now, all chains are deployed to deterministic Zora Factory1155 address: 0x777777C338d93e2C7adf08D102d45CA7CC4Ed021"
- f7e3af4: I update export structure.
- 687833f: I update tsconfig module type from NextJS to ES2020."
- 37e69dc: I add all exports necessary for initial version of subparticles with ProducedByDav."
- e87779c: I follow a new youtube tutorial: Blazing Fast Tips: Publishing to NPM
- b4dc219: fix type declarations on returns of ipfs lib.
- cff4fa6: I update tsconfig to attempt to resolve zoralabs import error.
81 changes: 18 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,25 @@
# Getting Started with Create React App
# Getting Started with OnchainMagic 🪄

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Getting started

## Available Scripts
```
yarn add onchain-magic
```

In the project directory, you can run:
```
import { useCreate1155Contract } from 'onchain-magic';
### `npm start`
const MyComponent = () => {
const { createContract } = useCreate1155Contract
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
const handleClick = () => {
createContract()
}
The page will reload when you make changes.\
You may also see any lint errors in the console.
return(
<button onClick={handleClick}>Deploy on Zora</button>
)
}
### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
export default MyComponent
```
60 changes: 60 additions & 0 deletions hooks/useCreate1155Contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import abi from "../lib/abi/Zora1155CreatorProxy.json";
import { getZoraBlob, store } from "../lib/ipfs";
import { Contract } from "ethers";
import { useAccount } from "wagmi";
import { useEthersSigner } from "./useEthersSigner";
import type { Create1155ContractArgs } from "../lib/types/Create1155ContractArgs";

const useCreate1155Contract = () => {
const signer = useEthersSigner();
const { address } = useAccount() as any;
const factoryAddress = "0x777777C338d93e2C7adf08D102d45CA7CC4Ed021";
const defaultContractName = "ONCHAINMAGIC🪄";

const signTransaction = async (args: any[]) => {
const factory = new Contract(factoryAddress, abi, signer);
const tx = await factory.createContract(...args);
const response = await tx.wait();
return response;
};

const createContract = async (contractArgs?: Create1155ContractArgs) => {
if (!signer)
return {
error: "Please connect a wallet client using wagmi / ethers / viem.",
};

try {
const ipfs =
contractArgs?.contentURI ||
(await store(
getZoraBlob(address),
defaultContractName,
contractArgs?.description || "",
address
));
const setupActions = contractArgs?.setupActions || ([] as any[]);
const royaltyConfig = contractArgs?.royaltyConfig || {
royaltyRecipient: "0x0000000000000000000000000000000000000000",
royaltyMintSchedule: 0,
royaltyBPS: 0,
};
const args = [
`ipfs://${ipfs}`,
contractArgs?.name || defaultContractName,
royaltyConfig,
contractArgs?.defaultAdmin || address,
setupActions,
];
await signTransaction(args);
} catch (error) {
return { error };
}
};

return {
deploy: createContract,
};
};

export default useCreate1155Contract;
24 changes: 24 additions & 0 deletions hooks/useEthersSigner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from "react";
import { type WalletClient, useWalletClient } from "wagmi";
import { providers } from "ethers";

export function walletClientToSigner(walletClient: WalletClient) {
const { account, chain, transport } = walletClient;
const network = {
chainId: chain.id,
name: chain.name,
ensAddress: chain.contracts?.ensRegistry?.address,
};
const provider = new providers.Web3Provider(transport, network);
const signer = provider.getSigner(account.address);
return signer;
}

/** Hook to convert a viem Wallet Client to an ethers.js Signer. */
export function useEthersSigner({ chainId }: { chainId?: number } = {}) {
const { data: walletClient } = useWalletClient({ chainId });
return React.useMemo(
() => (walletClient ? walletClientToSigner(walletClient) : undefined),
[walletClient]
);
}
18 changes: 18 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import useCreate1155Contract from "./hooks/useCreate1155Contract";
import { useEthersSigner } from "./hooks/useEthersSigner"
import { uploadToIpfs, store } from "./lib/ipfs"
import type { Create1155ContractArgs } from "./lib/types/Create1155ContractArgs"

export {
// IPFS
store,
uploadToIpfs,

// ZORA
useCreate1155Contract,
type Create1155ContractArgs,

// ETHERS
useEthersSigner
};

Loading

0 comments on commit 5a3d287

Please sign in to comment.