Skip to content

Commit

Permalink
Remove redundant exports from taco package (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec authored Jan 8, 2024
2 parents 8333cc2 + 447be5b commit 9d75ea2
Show file tree
Hide file tree
Showing 39 changed files with 214 additions and 238 deletions.
2 changes: 1 addition & 1 deletion demos/taco-demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function App() {
useEthers();

const [loading, setLoading] = useState(false);
const [condition, setCondition] = useState<conditions.Condition>();
const [condition, setCondition] = useState<conditions.condition.Condition>();
const [encryptedMessage, setEncryptedMessage] =
useState<ThresholdMessageKit>();
const [decryptedMessage, setDecryptedMessage] = useState<string>();
Expand Down
8 changes: 4 additions & 4 deletions demos/taco-demo/src/ConditionBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { Mumbai, useEthers } from '@usedapp/core';
import React, { useState } from 'react';

interface Props {
condition?: conditions.Condition | undefined;
setConditions: (value: conditions.Condition) => void;
condition?: conditions.condition.Condition | undefined;
setConditions: (value: conditions.condition.Condition) => void;
enabled: boolean;
}

const rpcCondition = new conditions.RpcCondition({
const rpcCondition = new conditions.base.rpc.RpcCondition({
chain: Mumbai.chainId,
method: 'eth_getBalance',
parameters: [':userAddress'],
Expand Down Expand Up @@ -59,7 +59,7 @@ export const ConditionBuilder = ({

const onCreateCondition = (e: any) => {
e.preventDefault();
setConditions(conditions.Condition.fromObj(JSON.parse(conditionString)));
setConditions(conditions.ConditionFactory.conditionFromProps(JSON.parse(conditionString)));
};

return (
Expand Down
2 changes: 1 addition & 1 deletion demos/taco-nft-demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function App() {
useEthers();

const [loading, setLoading] = useState(false);
const [condition, setCondition] = useState<conditions.Condition>();
const [condition, setCondition] = useState<conditions.condition.Condition>();
const [encryptedMessage, setEncryptedMessage] =
useState<ThresholdMessageKit>();
const [decryptedMessage, setDecryptedMessage] = useState<string>();
Expand Down
10 changes: 5 additions & 5 deletions demos/taco-nft-demo/src/NFTConditionBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useEthers } from '@usedapp/core';
import React, { useState } from 'react';

interface Props {
condition?: conditions.Condition | undefined;
setConditions: (value: conditions.Condition) => void;
condition?: conditions.condition.Condition | undefined;
setConditions: (value: conditions.condition.Condition) => void;
enabled: boolean;
}

Expand Down Expand Up @@ -49,9 +49,9 @@ export const NFTConditionBuilder = ({
const tokenIdInput = makeInput(setTokenId);
const chainInput = makeChainInput(setChain, 5);

const makeCondition = (): conditions.Condition => {
const makeCondition = (): conditions.condition.Condition => {
if (tokenId) {
return new conditions.ContractCondition({
return new conditions.base.contract.ContractCondition({
contractAddress,
chain,
standardContractType: 'ERC721',
Expand All @@ -63,7 +63,7 @@ export const NFTConditionBuilder = ({
},
});
}
return new conditions.ContractCondition({
return new conditions.base.contract.ContractCondition({
contractAddress,
chain,
standardContractType: 'ERC721',
Expand Down
2 changes: 1 addition & 1 deletion examples/taco/nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function App() {
setEncrypting(true)
try {
const signer = provider.getSigner();
const hasPositiveBalance = new conditions.RpcCondition({
const hasPositiveBalance = new conditions.base.rpc.RpcCondition({
chain: 80001,
method: 'eth_getBalance',
parameters: [':userAddress', 'latest'],
Expand Down
2 changes: 1 addition & 1 deletion examples/taco/nextjs/src/hooks/useTaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function useTaco({
const encryptDataToBytes = useCallback(
async (
message: string,
condition: conditions.Condition,
condition: conditions.condition.Condition,
encryptorSigner: ethers.Signer,
) => {
if (!isInit || !provider) return;
Expand Down
2 changes: 1 addition & 1 deletion examples/taco/nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const encryptToBytes = async (messageString: string) => {
const message = toBytes(messageString);
console.log(format('Encrypting message ("%s") ...', messageString));

const hasPositiveBalance = new conditions.RpcCondition({
const hasPositiveBalance = new conditions.base.rpc.RpcCondition({
chain: 80001,
method: 'eth_getBalance',
parameters: [':userAddress', 'latest'],
Expand Down
2 changes: 1 addition & 1 deletion examples/taco/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function App() {
setEncrypting(true)
try {
const signer = provider.getSigner();
const hasPositiveBalance = new conditions.RpcCondition({
const hasPositiveBalance = new conditions.base.rpc.RpcCondition({
chain: 80001,
method: 'eth_getBalance',
parameters: [':userAddress', 'latest'],
Expand Down
4 changes: 2 additions & 2 deletions examples/taco/react/src/hooks/useTaco.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
conditions,
decrypt,
Domain,
encrypt,
getPorterUri,
initialize,
ThresholdMessageKit,
} from '@nucypher/taco';
import { Condition } from '@nucypher/taco/src/conditions';
import { ethers } from 'ethers';
import { useCallback, useEffect, useState } from 'react';

Expand Down Expand Up @@ -43,7 +43,7 @@ export default function useTaco({
const encryptDataToBytes = useCallback(
async (
message: string,
condition: Condition,
condition: conditions.condition.Condition,
encryptorSigner: ethers.Signer,
) => {
if (!isInit || !provider) return;
Expand Down
2 changes: 1 addition & 1 deletion examples/taco/webpack-5/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const runExample = async () => {

console.log('Encrypting message...');
const message = toBytes('this is a secret');
const hasPositiveBalance = new conditions.RpcCondition({
const hasPositiveBalance = new conditions.base.rpc.RpcCondition({
chain: 80001,
method: 'eth_getBalance',
parameters: [':userAddress', 'latest'],
Expand Down
18 changes: 9 additions & 9 deletions packages/taco/examples/conditions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { conditions } from '../src';

const ownsNFT = new conditions.predefined.ERC721Ownership({
const ownsNFT = new conditions.predefined.erc721.ERC721Ownership({
contractAddress: '0x1e988ba4692e52Bc50b375bcC8585b95c48AaD77',
parameters: [3591],
chain: 5,
});
console.assert(ownsNFT.requiresSigner(), 'ERC721Ownership requires signer');

const hasAtLeastTwoNFTs = new conditions.predefined.ERC721Balance({
const hasAtLeastTwoNFTs = new conditions.predefined.erc721.ERC721Balance({
contractAddress: '0x1e988ba4692e52Bc50b375bcC8585b95c48AaD77',
chain: 5,
returnValueTest: {
Expand All @@ -20,7 +20,7 @@ console.assert(
'ERC721Balance requires signer',
);

const ownsNFTRaw = new conditions.base.ContractCondition({
const ownsNFTRaw = new conditions.base.contract.ContractCondition({
// Provided by the `predefined.ERC721Balance`
method: 'balanceOf',
parameters: [':userAddress'],
Expand All @@ -38,7 +38,7 @@ console.assert(
'ContractCondition requires a signer',
);

const hasAnyNativeAsset = new conditions.base.RpcCondition({
const hasAnyNativeAsset = new conditions.base.rpc.RpcCondition({
chain: 5,
method: 'eth_getBalance',
parameters: [':userAddress'],
Expand All @@ -52,13 +52,13 @@ console.assert(
'RpcCondition requires signer',
);

const ownsNFTOnChain5 = new conditions.predefined.ERC721Ownership({
const ownsNFTOnChain5 = new conditions.predefined.erc721.ERC721Ownership({
contractAddress: '0x1e988ba4692e52Bc50b375bcC8585b95c48AaD77',
parameters: [3591],
chain: 5, // The first network we target
});

const hasAnyNativeAssetOnChain1 = new conditions.base.RpcCondition({
const hasAnyNativeAssetOnChain1 = new conditions.base.rpc.RpcCondition({
chain: 1, // The second network we target
method: 'eth_getBalance',
parameters: [':userAddress'],
Expand All @@ -68,7 +68,7 @@ const hasAnyNativeAssetOnChain1 = new conditions.base.RpcCondition({
},
});

const multichainCondition = conditions.base.CompoundCondition.and([
const multichainCondition = conditions.compound.CompoundCondition.and([
ownsNFTOnChain5,
hasAnyNativeAssetOnChain1,
]);
Expand All @@ -78,7 +78,7 @@ console.assert(
'CompoundCondition requires signer',
);

const myFunctionAbi: conditions.FunctionAbiProps = {
const myFunctionAbi: conditions.base.contract.FunctionAbiProps = {
name: 'myFunction',
type: 'function',
stateMutability: 'view',
Expand All @@ -103,7 +103,7 @@ const myFunctionAbi: conditions.FunctionAbiProps = {
],
};

const myContractCallCondition = new conditions.base.ContractCondition({
const myContractCallCondition = new conditions.base.contract.ContractCondition({
method: 'myFunctionAbi', // `myMethodAbi.name`
parameters: [':userAddress', ':myCustomParam'], // `myMethodAbi.inputs`
functionAbi: myFunctionAbi,
Expand Down
4 changes: 2 additions & 2 deletions packages/taco/examples/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { conditions } from '../src';
import { CustomContextParam } from '../src/conditions';
import { CustomContextParam } from '../src/conditions/context';

const ownsNFTRaw = new conditions.base.ContractCondition({
const ownsNFTRaw = new conditions.base.contract.ContractCondition({
method: 'balanceOf',
parameters: [':userAddress'],
standardContractType: 'ERC721',
Expand Down
2 changes: 1 addition & 1 deletion packages/taco/examples/encrypt-decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const run = async () => {

// @ts-ignore
const web3Provider = new ethers.providers.Web3Provider(window.ethereum);
const ownsNFT = new conditions.predefined.ERC721Ownership({
const ownsNFT = new conditions.predefined.erc721.ERC721Ownership({
contractAddress: '0x1e988ba4692e52Bc50b375bcC8585b95c48AaD77',
parameters: [3591],
chain: 5,
Expand Down
12 changes: 11 additions & 1 deletion packages/taco/src/conditions/base/contract.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ethers } from 'ethers';
import { z } from 'zod';

import { Condition } from '../condition';
import { ETH_ADDRESS_REGEXP } from '../const';
import { OmitConditionType, paramOrContextParamSchema } from '../shared';

import { rpcConditionSchema } from './rpc';
import { paramOrContextParamSchema } from './shared';

// TODO: Consider replacing with `z.unknown`:
// Since Solidity types are tied to Solidity version, we may not be able to accurately represent them in Zod.
Expand Down Expand Up @@ -96,3 +97,12 @@ export const contractConditionSchema = rpcConditionSchema
);

export type ContractConditionProps = z.infer<typeof contractConditionSchema>;

export class ContractCondition extends Condition {
constructor(value: OmitConditionType<ContractConditionProps>) {
super(contractConditionSchema, {
conditionType: ContractConditionType,
...value,
});
}
}
102 changes: 3 additions & 99 deletions packages/taco/src/conditions/base/index.ts
Original file line number Diff line number Diff line change
@@ -1,102 +1,6 @@
import {
CompoundConditionProps,
compoundConditionSchema,
CompoundConditionType,
} from '../compound-condition';
import { Condition, ConditionProps } from '../condition';

import {
ContractConditionProps,
contractConditionSchema,
ContractConditionType,
} from './contract';
import { RpcConditionProps, rpcConditionSchema, RpcConditionType } from './rpc';
import {
TimeConditionProps,
timeConditionSchema,
TimeConditionType,
} from './time';

type OmitConditionType<T> = Omit<T, 'conditionType'>;

// Exporting classes here instead of their respective schema files to
// avoid circular dependency on Condition class.

type ConditionOrProps = Condition | ConditionProps;

export class CompoundCondition extends Condition {
constructor(value: OmitConditionType<CompoundConditionProps>) {
super(compoundConditionSchema, {
conditionType: CompoundConditionType,
...value,
});
}

private static withOperator(
operands: ConditionOrProps[],
operator: 'or' | 'and' | 'not',
): CompoundCondition {
const asObjects = operands.map((operand) => {
if (operand instanceof Condition) {
return operand.toObj();
}
return operand;
});
return new CompoundCondition({
operator,
operands: asObjects,
});
}

public static or(conditions: ConditionOrProps[]): CompoundCondition {
return CompoundCondition.withOperator(conditions, 'or');
}

public static and(conditions: ConditionOrProps[]): CompoundCondition {
return CompoundCondition.withOperator(conditions, 'and');
}

public static not(condition: ConditionOrProps): CompoundCondition {
return CompoundCondition.withOperator([condition], 'not');
}
}

export class ContractCondition extends Condition {
constructor(value: OmitConditionType<ContractConditionProps>) {
super(contractConditionSchema, {
conditionType: ContractConditionType,
...value,
});
}
}

export class RpcCondition extends Condition {
constructor(value: OmitConditionType<RpcConditionProps>) {
super(rpcConditionSchema, {
conditionType: RpcConditionType,
...value,
});
}
}

export class TimeCondition extends Condition {
constructor(value: OmitConditionType<TimeConditionProps>) {
super(timeConditionSchema, {
conditionType: TimeConditionType,
...value,
});
}
}

export {
ContractConditionType,
FunctionAbiProps,
type ContractConditionProps,
} from './contract';
export { RpcConditionType, type RpcConditionProps } from './rpc';
export { ReturnValueTestProps } from './shared';
export {
TimeConditionMethod,
TimeConditionType,
type TimeConditionProps,
} from './time';
export * as contract from './contract';
export * as rpc from './rpc';
export * as time from './time';
Loading

0 comments on commit 9d75ea2

Please sign in to comment.