Skip to content

Commit

Permalink
deprecate contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
alissacrane-cb committed Nov 20, 2024
1 parent ec43e35 commit 382a062
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 7 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"clsx": "^2.1.1",
"graphql": "^14 || ^15 || ^16",
"graphql-request": "^6.1.0",
"permissionless": "^0.2.10",
"tailwind-merge": "^2.3.0",
"viem": "^2.21.33",
"wagmi": "^2.12.24"
Expand Down
Binary file modified playground/nextjs-app-router/bun.lockb
Binary file not shown.
1 change: 0 additions & 1 deletion playground/nextjs-app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"graphql-request": "^6.1.0",
"lucide-react": "^0.416.0",
"next": "^14.2.5",
"permissionless": "^0.2.10",
"react": "^18",
"react-dom": "^18",
"tailwind-merge": "^2.4.0",
Expand Down
2 changes: 2 additions & 0 deletions src/transaction/components/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function Transaction({
chainId,
className,
children,
contracts,
isSponsored,
onError,
onStatus,
Expand All @@ -34,6 +35,7 @@ export function Transaction({
calls={calls}
capabilities={capabilities}
chainId={accountChainId}
contracts={contracts}
isSponsored={isSponsored}
onError={onError}
onStatus={onStatus}
Expand Down
16 changes: 15 additions & 1 deletion src/transaction/components/TransactionProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,21 @@ describe('TransactionProvider', () => {
</TransactionProvider>,
);
}).toThrowError(
'Transaction: calls must be provided as a prop to the Transaction component.',
'Transaction: calls or contracts must be provided as a prop to the Transaction component.',
);
restore();
});

it('should throw an error when both contracts and calls are provided', async () => {
const restore = silenceError();
expect(() => {
render(
<TransactionProvider contracts={[{}]} calls={[{}]}>
<div>Test</div>
</TransactionProvider>,
);
}).toThrowError(
'Transaction: Only one of contracts or calls can be provided as a prop to the Transaction component.',
);
restore();
});
Expand Down
14 changes: 11 additions & 3 deletions src/transaction/components/TransactionProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function TransactionProvider({
capabilities: transactionCapabilities,
chainId,
children,
contracts,
isSponsored,
onError,
onStatus,
Expand All @@ -74,7 +75,7 @@ export function TransactionProvider({
number | undefined
>();
const [transactionHashList, setTransactionHashList] = useState<Address[]>([]);
const transactions = calls;
const transactions = calls || contracts;

// Retrieve wallet capabilities
const walletCapabilities = useCapabilitiesSafe({
Expand All @@ -84,9 +85,16 @@ export function TransactionProvider({
const { switchChainAsync } = useSwitchChain();

// Validate `calls` props
if (!calls) {
if (!calls && !contracts) {
throw new Error(
'Transaction: calls must be provided as a prop to the Transaction component.',
'Transaction: calls or contracts must be provided as a prop to the Transaction component.',
);
}

// Validate `calls` and `contracts` props
if (calls && contracts) {
throw new Error(
'Transaction: Only one of contracts or calls can be provided as a prop to the Transaction component.',
);
}

Expand Down
8 changes: 8 additions & 0 deletions src/transaction/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ export type TransactionProviderReact = {
capabilities?: WalletCapabilities; // Capabilities that a wallet supports (e.g. paymasters, session keys, etc).
chainId: number; // The chainId for the transaction.
children: ReactNode; // The child components to be rendered within the provider component.
/**
* @deprecated Use `calls` instead.
*/
contracts?: Calls | Contracts | (Call | ContractFunctionParameters)[]; // An array of calls to be made in the transaction.
isSponsored?: boolean; // Whether the transactions are sponsored (default: false)
onError?: (e: TransactionError) => void; // An optional callback function that handles errors within the provider.
onStatus?: (lifecycleStatus: LifecycleStatus) => void; // An optional callback function that exposes the component lifecycle state
Expand All @@ -167,6 +171,10 @@ export type TransactionReact = {
chainId?: number; // The chainId for the transaction.
children: ReactNode; // The child components to be rendered within the transaction component.
className?: string; // An optional CSS class name for styling the component.
/**
* @deprecated Use `calls` instead.
*/
contracts?: Calls | Contracts | (Call | ContractFunctionParameters)[]; // An array of calls to be made in the transaction.
isSponsored?: boolean; // Whether the transactions are sponsored (default: false)
onError?: (e: TransactionError) => void; // An optional callback function that handles transaction errors.
onStatus?: (lifecycleStatus: LifecycleStatus) => void; // An optional callback function that exposes the component lifecycle state
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/utils/isWalletACoinbaseSmartWallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UserOperation } from 'permissionless';
import type { UserOperation } from 'viem/_types/account-abstraction';
import type { PublicClient } from 'viem';
import { type Mock, describe, expect, it, vi } from 'vitest';
import {
Expand Down

0 comments on commit 382a062

Please sign in to comment.