Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: WIP update #54

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions packages/daobox-use-aragon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@
"watch": "jest --watch"
},
"dependencies": {
"@aragon/osx-ethers": "^1.2.1",
"@aragon/sdk-client": "^1.3.1",
"@tanstack/react-query": "^4.28.0",
"@tanstack/react-query-devtools": "^4.29.0",
"@aragon/osx-ethers": "^1.3.0-rc0.2",
"@aragon/sdk-client": "1.12.0-rc1",
"@tanstack/react-query": "^4.32.6",
"@tanstack/react-query-devtools": "^4.32.6",
"@testing-library/react-hooks": "^8.0.1",
"ethers": "^5.7.2",
"graphql": "^16.6.0",
"graphql": "^16.8.0",
"graphql-request": "^5.2.0",
"wagmi": "~0.11.7",
"zod": "^3.21.4"
"zod": "^3.22.0"
},
"peerDependencies": {
"wagmi": "~0.11.7"
},
"devDependencies": {
"@daobox/tsconfig": "workspace:*",
"@graphql-codegen/cli": "^3.3.0",
"@graphql-codegen/client-preset": "^3.0.0",
"@testing-library/jest-dom": "^5.16.5",
"@graphql-codegen/cli": "^3.3.1",
"@graphql-codegen/client-preset": "^3.0.1",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^14.0.0",
"@types/jest": "^29.5.0",
"@types/jest": "^29.5.3",
"@types/mocha": "^10.0.1",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"eslint": "^7.32.0",
"eslint-config-daobox": "workspace:*",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.6.2",
"mocha": "^10.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"size-limit": "^8.2.4",
"ts-jest": "^29.0.5",
"size-limit": "^8.2.6",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tslib": "^2.5.0",
"tsup": "^5.10.1",
"tslib": "^2.6.1",
"tsup": "^5.12.9",
"typescript": "^4.9.5"
},
"publishConfig": {
Expand Down
101 changes: 49 additions & 52 deletions packages/daobox-use-aragon/src/context/AragonContext.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { createContext, useContext, useEffect, useState } from "react";
import {
Client,
Context,
ContextParams,
ContextPlugin,
TokenVotingClient,
Client,
Context,
TokenVotingClient,
type ContextParams,
} from "@aragon/sdk-client";
import { createContext, useContext, useEffect, useState } from "react";
import { CHAINS, settings } from "../constants";
import useConnectedWallet from "./useConnectedWallet";
import { SupportedChainIds } from "../types";
import { IpfsNode } from "./AragonProvider";

export interface AragonSDKContextValue {
context?: Context;
baseClient?: Client;
tokenVotingClient?: TokenVotingClient;
context?: Context;
baseClient?: Client;
tokenVotingClient?: TokenVotingClient;
}

const AragonSDKContext = createContext<AragonSDKContextValue>({});
Expand All @@ -24,60 +23,58 @@ const AragonSDKContext = createContext<AragonSDKContextValue>({});
* to the Aragon SDK.
*/
export function AragonSDKWrapper({
children,
ipfsNodes,
children,
ipfsNodes,
}: {
children: JSX.Element;
ipfsNodes?: IpfsNode[];
children: JSX.Element;
ipfsNodes?: IpfsNode[];
}): JSX.Element {
const { signer, chain } = useConnectedWallet();
const [context, setContext] = useState<Context | undefined>(undefined);
const [baseClient, setBaseClient] = useState<Client | undefined>(undefined);
const [tokenVotingClient, setTokenVotingClient] = useState<
TokenVotingClient | undefined
>(undefined);
const { signer, chain } = useConnectedWallet();
const [context, setContext] = useState<Context | undefined>(undefined);
const [baseClient, setBaseClient] = useState<Client | undefined>(undefined);
const [tokenVotingClient, setTokenVotingClient] = useState<
TokenVotingClient | undefined
>(undefined);

useEffect(() => {
if (!signer || !chain) return;
useEffect(() => {
if (!signer || !chain) return;

// check if chain is valid
if (!Object.values(CHAINS).includes(chain as SupportedChainIds)) {
console.error(`Invalid chain type: ${chain}`);
return;
}
// check if chain is valid
if (!Object.values(CHAINS).includes(chain as SupportedChainIds)) {
console.error(`Invalid chain type: ${chain}`);
return;
}

const aragonSDKContextParams: ContextParams = {
network: chain || 5,
signer,
...settings(chain as SupportedChainIds, ipfsNodes),
};
const contextInstance = new Context(aragonSDKContextParams);
const contextPlugin = ContextPlugin.fromContext(contextInstance);
setContext(contextInstance);
setBaseClient(new Client(contextInstance));
setTokenVotingClient(new TokenVotingClient(contextPlugin));
}, [signer, chain, ipfsNodes]);
const aragonSDKContextParams: ContextParams = {
network: chain || 5,
signer,
...settings(chain as SupportedChainIds, ipfsNodes),
};
const contextInstance = new Context(aragonSDKContextParams);
setContext(contextInstance);
setBaseClient(new Client(contextInstance));
}, [signer, chain, ipfsNodes]);

return (
<AragonSDKContext.Provider
value={{
context,
baseClient,
tokenVotingClient,
}}
>
{children}
</AragonSDKContext.Provider>
);
return (
<AragonSDKContext.Provider
value={{
context,
baseClient,
tokenVotingClient,
}}
>
{children}
</AragonSDKContext.Provider>
);
}

/**
* useAragon is a custom hook to access the AragonSDKContext.
* @throws {Error} if used outside of AragonSDKWrapper
*/
export function useAragon(): AragonSDKContextValue {
const context = useContext(AragonSDKContext);
if (!context)
throw new Error("useAragon hooks must be used within an AragonSDKWrapper");
return context;
const context = useContext(AragonSDKContext);
if (!context)
throw new Error("useAragon hooks must be used within an AragonSDKWrapper");
return context;
}
9 changes: 4 additions & 5 deletions packages/daobox-use-aragon/src/core/useNewDao.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
DaoCreationSteps,
DaoMetadata,
IPluginInstallItem,
DaoCreationSteps,
DaoMetadata,
} from "@aragon/sdk-client";
import { useState } from "react";
import { useMutation, UseMutationResult } from "@tanstack/react-query";
Expand Down Expand Up @@ -100,15 +99,15 @@ export function useNewDao({
* @property {string} [daoUri] - The URI for the new DAO.
* @property {string} ensSubdomain - The ENS subdomain for the new DAO.
* @property {string} [trustedForwarder] - The trusted forwarder address for the new DAO.
* @property {IPluginInstallItem[]} plugins - The plugins to be installed in the new DAO.
* @property {TokenVotingPluginInstall[]} plugins - The plugins to be installed in the new DAO.
* @property {(txHash: string) => void} [onCreateDaoTransaction] - A callback to be called when the DAO creation transaction is created.
*/
export type NewDaoParams = MutationConfig<NewDaoReturnData, Error> & {
daoMetadata: DaoMetadata;
daoUri?: string;
ensSubdomain: string;
trustedForwarder?: string;
plugins: IPluginInstallItem[];
plugins: [];
onCreateDaoTransaction?: (txHash: string) => void;
};

Expand Down
Loading
Loading