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

feat: upgrade viem to support heterogeneous calls #1527

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"clsx": "^2.1.1",
"graphql": "^14 || ^15 || ^16",
"graphql-request": "^6.1.0",
"permissionless": "^0.1.29",
"permissionless": "^0.2.10",
"tailwind-merge": "^2.3.0",
"viem": "^2.17.4",
"wagmi": "^2.11.0"
"viem": "^2.21.33",
"wagmi": "^2.12.24"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
Expand Down Expand Up @@ -73,7 +73,7 @@
"graphql-request": "^6.1.0",
"jsdom": "^24.1.0",
"packemon": "3.3.1",
"permissionless": "^0.1.29",
"permissionless": "^0.2.10",
Copy link
Contributor

@alessey alessey Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we still using this dependency after these changes (and under dependencies)?

"react": "^18",
"react-dom": "^18",
"rimraf": "^5.0.5",
Expand Down
Binary file modified playground/nextjs-app-router/bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions playground/nextjs-app-router/components/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export enum TransactionTypes {
ContractsPromise = 'contractsPromise',
CallsCallback = 'callsCallback',
ContractsCallback = 'contractsCallback',
ContractsAndCalls = 'contractsAndCalls',
}

export type Paymaster = {
Expand Down
44 changes: 22 additions & 22 deletions playground/nextjs-app-router/components/demo/Transaction.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { clickCalls, clickContracts } from '@/lib/transactions';
import type { Call } from '@/onchainkit/esm/transaction/types';
import {
clickCalls,
clickContracts,
heterogeneousClickCalls,
} from '@/lib/transactions';
import type { Call, Calls } from '@/onchainkit/esm/transaction/types';
import type { LifecycleStatus } from '@/onchainkit/src/transaction';
import {
Transaction,
Expand Down Expand Up @@ -65,6 +69,12 @@ function TransactionDemo() {
case TransactionTypes.Contracts:
console.log('Playground.Transaction.contracts:', contracts);
break;
case TransactionTypes.ContractsAndCalls:
console.log(
'Playground.Transaction.contractsAndCalls:',
heterogeneousClickCalls,
);
break;
default:
console.log(`Playground.Transaction.${transactionType}`);
break;
Expand All @@ -74,31 +84,21 @@ function TransactionDemo() {
const transactions = useMemo(() => {
switch (transactionType) {
case TransactionTypes.Calls:
return {
calls,
contracts: undefined,
};
return calls;
case TransactionTypes.Contracts:
return {
calls: undefined,
contracts,
};
return contracts;
case TransactionTypes.CallsPromise:
return {
calls: promiseCalls,
contracts: undefined,
};
return promiseCalls;
case TransactionTypes.ContractsPromise:
return {
contracts: promiseContracts,
calls: undefined,
};
return promiseContracts;
case TransactionTypes.CallsCallback:
return { calls: callsCallback, contracts: undefined };
return callsCallback;
case TransactionTypes.ContractsCallback:
return { calls: undefined, contracts: contractsCallback };
return contractsCallback;
case TransactionTypes.ContractsAndCalls:
return heterogeneousClickCalls;
default:
return { calls, contracts: undefined };
return calls;
}
}, [
calls,
Expand All @@ -114,9 +114,9 @@ function TransactionDemo() {
<div className="mx-auto grid w-1/2 gap-8">
<Transaction
chainId={chainId ?? 84532} // something breaks if we don't have default network?
{...transactions}
isSponsored={isSponsored}
onStatus={handleOnStatus}
calls={transactions as Calls}
>
<TransactionButton
text="Click"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export function TransactionOptions() {
<SelectItem value={TransactionTypes.ContractsCallback}>
Contracts Callback
</SelectItem>
<SelectItem value={TransactionTypes.ContractsAndCalls}>
Contracts and Calls
</SelectItem>
</SelectContent>
</Select>
</div>
Expand Down
23 changes: 23 additions & 0 deletions playground/nextjs-app-router/lib/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,26 @@ export const clickCalls = [
to: deployedContracts[85432].click,
},
];

export const heterogeneousClickCalls = [
{
data: encodeFunctionData({
abi: clickAbi,
functionName: 'click',
args: [],
}),
to: deployedContracts[85432].click,
},
{
address: deployedContracts[85432].click,
abi: clickAbi,
functionName: 'click',
args: [],
},
{
address: deployedContracts[85432].click,
abi: clickAbi,
functionName: 'click',
args: [],
},
];
6 changes: 3 additions & 3 deletions playground/nextjs-app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
"graphql-request": "^6.1.0",
"lucide-react": "^0.416.0",
"next": "^14.2.5",
"permissionless": "^0.1.29",
"permissionless": "^0.2.10",
"react": "^18",
"react-dom": "^18",
"tailwind-merge": "^2.4.0",
"tailwindcss-animate": "^1.0.7",
"viem": "^2.17.4",
"wagmi": "^2.11.0"
"viem": "^2.21.33",
"wagmi": "^2.12.24"
},
"devDependencies": {
"@types/node": "^20",
Expand Down
2 changes: 0 additions & 2 deletions src/transaction/components/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function Transaction({
chainId,
className,
children,
contracts,
isSponsored,
onError,
onStatus,
Expand All @@ -35,7 +34,6 @@ export function Transaction({
calls={calls}
capabilities={capabilities}
chainId={accountChainId}
contracts={contracts}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we still support this param and/or deprecate over time by just having anything passed in here be treated the same as the calls param?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm leaning towards just removing it to avoid confusion. i.e devs might think they need to pass calls to calls and contracts to contracts which would cause the order of execution to be unreliable. plus it is a super small change on the developer side (just changing prop name to calls).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you left the calls and contracts error in place we could mark contracts as deprecated for a few releases before removing. it would at least give the devs a heads up over the next few releases before the forcing them to update due to a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious what the rest of the team thinks but personally still leaning towards just removing it since it is such a small change on the dev side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on marking as deprecated for a few releases, then removing. It should be a simple change for the dev but nice to give them a bit of time to switch over

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, reconsidered this. Given it's a simple prop name change, I'd probably lean towards just making the breaking change now

isSponsored={isSponsored}
onError={onError}
onStatus={onStatus}
Expand Down
2 changes: 0 additions & 2 deletions src/transaction/components/TransactionDefault.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function TransactionDefault({
capabilities,
chainId,
className,
contracts,
disabled,
onError,
onStatus,
Expand All @@ -23,7 +22,6 @@ export function TransactionDefault({
capabilities={capabilities}
chainId={chainId}
className={className}
contracts={contracts}
onError={onError}
onStatus={onStatus}
onSuccess={onSuccess}
Expand Down
Loading