Skip to content

Commit 2b0d694

Browse files
yoanslvymathieulrl
andauthored
Develop (#85)
* rebase * fix: typings * fix: multichain * Fix/bitwarden (#68) * fix: bitwarden * up: version * u: version * Feat/capabilities (#70) * feat: EIP1193 Provider * restrict policies to sudo & contract-call * connect provider to sdk actions * add test of requests in viem-demo * PR reviews * clean: test in front * lint: modified files in sdk * add: distinct example for capabilities features * modify: grantPermissions return * add: EIP1193Parameters type * lint sdk * remove biome-ignore in examples * update: nonce * fix: recovery * feat/sdk-lite (#75) * feat/sdk-lite-init-commit * add: example for sdk lite * update: contractParams passed by user * remove: api key in example sdk lite * refacto: remove unused code * clean: lightening sdk * add: default safe contract config * fix: counter number in example * remove contractParams in example * update: doc comments * delete: sessionKey and importSafe pages in example * remove eip5792 & erc7715 actions in sdk lite * update Readme * clean * update Readme * clean: remove unnessary code * update: store account address in local storage in example * clean: unused dependencies in package.json * fix: typings * update: naming --------- Co-authored-by: yoanslvy <97676023+yoanslvy@users.noreply.github.com> * Develop (#80) * feat/sdk-lite (#75) * feat/sdk-lite-init-commit * add: example for sdk lite * update: contractParams passed by user * remove: api key in example sdk lite * refacto: remove unused code * clean: lightening sdk * add: default safe contract config * fix: counter number in example * remove contractParams in example * update: doc comments * delete: sessionKey and importSafe pages in example * remove eip5792 & erc7715 actions in sdk lite * update Readme * clean * update Readme * clean: remove unnessary code * update: store account address in local storage in example * clean: unused dependencies in package.json * fix: typings * update: naming --------- Co-authored-by: yoanslvy <97676023+yoanslvy@users.noreply.github.com> * fix: typo * Sdk core/new features (#77) * feat/ add capabilities & safeOwner actions * add: eip1193Actions in createClient * update: capabilities example with sdk core * add: safeOwner tests in sdk core demo * update: viem version * update: sdk version * feat/session-keys sdk (#76) * feat/session-keys sdk * lint * make session-keys sdk agnostic to any safe smart account client * feat: toSmartSessionsAccount * add: session keys example * update: bun.lock * fix: typings errors * export type SafeSigner * update: use permissionless in example * fix: typing error in applyDefaults * update: smartAccountClient type in toSessionsSigner * WIP: fix type error in example * add: addSafe7579Module function * add: SmartSessionsAccountClient type * update: example session keys * update: package version * remove: bun.lock file * update: viem version * update: readme --------- Co-authored-by: Mathieu LARUELLE <95310781+mathieulrl@users.noreply.github.com> * feat/sdk-lite (#75) * feat/sdk-lite-init-commit * add: example for sdk lite * update: contractParams passed by user * remove: api key in example sdk lite * refacto: remove unused code * clean: lightening sdk * add: default safe contract config * fix: counter number in example * remove contractParams in example * update: doc comments * delete: sessionKey and importSafe pages in example * remove eip5792 & erc7715 actions in sdk lite * update Readme * clean * update Readme * clean: remove unnessary code * update: store account address in local storage in example * clean: unused dependencies in package.json * fix: typings * update: naming --------- Co-authored-by: yoanslvy <97676023+yoanslvy@users.noreply.github.com> * fix: typo * Sdk core/new features (#77) * feat/ add capabilities & safeOwner actions * add: eip1193Actions in createClient * update: capabilities example with sdk core * add: safeOwner tests in sdk core demo * update: viem version * update: sdk version * feat/session-keys sdk (#76) * feat/session-keys sdk * lint * make session-keys sdk agnostic to any safe smart account client * feat: toSmartSessionsAccount * add: session keys example * update: bun.lock * fix: typings errors * export type SafeSigner * update: use permissionless in example * fix: typing error in applyDefaults * update: smartAccountClient type in toSessionsSigner * WIP: fix type error in example * add: addSafe7579Module function * add: SmartSessionsAccountClient type * update: example session keys * update: package version * remove: bun.lock file * update: viem version * update: readme * update: support safe 1.1 * fix: merge errors * update: viem * update: rebase * update: remove sessionkey (#87) --------- Co-authored-by: mathieuLARUELLE <math.laruelle@gmail.com> Co-authored-by: Mathieu LARUELLE <95310781+mathieulrl@users.noreply.github.com>
1 parent 8e05250 commit 2b0d694

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2233
-2040
lines changed

bun.lockb

14.9 KB
Binary file not shown.

examples/react-hooks-demo/src/app/components/Transaction.tsx

Lines changed: 142 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { PlusIcon } from "@radix-ui/react-icons";
44
import type React from "react";
55
import { useEffect, useState } from "react";
66
import {
7-
http,
8-
type Address,
9-
createPublicClient,
10-
encodeFunctionData,
11-
getContract,
7+
http,
8+
type Address,
9+
createPublicClient,
10+
encodeFunctionData,
11+
getContract,
1212
} from "viem";
1313
import { arbitrumSepolia } from "viem/chains";
1414
import countContractAbi from "../contract/counterABI.json";
@@ -18,154 +18,156 @@ import Alert from "../lib/ui/components/Alert";
1818
const COUNTER_CONTRACT_ADDRESS = "0x4FbF9EE4B2AF774D4617eAb027ac2901a41a7b5F";
1919

2020
const publicClient = createPublicClient({
21-
chain: arbitrumSepolia,
22-
transport: http(),
23-
cacheTime: 60_000,
24-
batch: {
25-
multicall: { wait: 50 },
26-
},
21+
chain: arbitrumSepolia,
22+
transport: http(),
23+
cacheTime: 60_000,
24+
batch: {
25+
multicall: { wait: 50 },
26+
},
2727
});
2828

2929
const counterContract = getContract({
30-
address: COUNTER_CONTRACT_ADDRESS,
31-
abi: countContractAbi,
32-
client: publicClient,
30+
address: COUNTER_CONTRACT_ADDRESS,
31+
abi: countContractAbi,
32+
client: publicClient,
3333
});
3434

3535
interface TransactionProps {
36-
hash: string | null;
37-
sendTransaction: any;
38-
address: Address;
39-
transactionSuccess: boolean;
40-
setTransactionSuccess: React.Dispatch<React.SetStateAction<boolean>>;
36+
hash: string | null;
37+
sendTransaction: any;
38+
address: Address;
39+
transactionSuccess: boolean;
40+
setTransactionSuccess: React.Dispatch<React.SetStateAction<boolean>>;
4141
}
4242

4343
function Transaction({
44-
sendTransaction,
45-
address,
46-
transactionSuccess,
47-
setTransactionSuccess,
44+
sendTransaction,
45+
address,
46+
transactionSuccess,
47+
setTransactionSuccess,
4848
}: TransactionProps) {
49-
const [isTransactionLoading, setIsTransactionLoading] =
50-
useState<boolean>(false);
51-
const [transactionSended, setTransactionSended] = useState<any | null>(null);
52-
const [transactionResponse, setTransactionResponse] = useState<any | null>(
53-
null
54-
);
55-
const [transactionFailure, setTransactionFailure] = useState(false);
56-
const [nftBalance, setNftBalance] = useState<number>(0);
57-
58-
function TransactionButton({
59-
sendTestTransaction,
60-
isTransactionLoading,
61-
label,
62-
}: {
63-
sendTestTransaction: () => Promise<void>;
64-
isTransactionLoading: boolean;
65-
label: string;
66-
}) {
67-
return (
68-
<button
69-
className="flex h-11 py-2 px-4 gap-2 flex-none items-center justify-center rounded-lg bg-gray-100 hover:bg-gray-200"
70-
onClick={sendTestTransaction}
71-
>
72-
{isTransactionLoading ? (
73-
<Icons.spinner className="h-4 w-4 animate-spin" />
74-
) : (
75-
<>
76-
<PlusIcon width={16} height={16} />
77-
</>
78-
)}
79-
{label}
80-
</button>
49+
const [isTransactionLoading, setIsTransactionLoading] =
50+
useState<boolean>(false);
51+
const [transactionSended, setTransactionSended] = useState<any | null>(
52+
null
8153
);
82-
}
83-
84-
useEffect(() => {
85-
if (address) {
86-
(async () => {
87-
const balance = await counterContract.read.counters([address]);
88-
setNftBalance(Number(balance));
89-
})();
90-
}
91-
}, []);
92-
93-
const sendTestTransaction = async () => {
94-
setTransactionSended(null);
95-
setTransactionResponse(null);
96-
setTransactionFailure(false);
97-
setTransactionSuccess(false);
98-
99-
setIsTransactionLoading(true);
100-
try {
101-
if (!address) throw new Error("No wallet instance");
102-
103-
const calldata = encodeFunctionData({
104-
abi: countContractAbi,
105-
functionName: "count",
106-
});
107-
108-
const txHash = await sendTransaction({
109-
calls: {
110-
to: COUNTER_CONTRACT_ADDRESS,
111-
value: 0,
112-
data: calldata,
113-
},
114-
});
115-
116-
setTransactionSended(txHash);
117-
118-
const txResponse = await publicClient.waitForTransactionReceipt({
119-
hash: txHash,
120-
});
121-
122-
setTransactionResponse(txResponse);
123-
124-
const balance = await counterContract.read.counters([address]);
125-
setNftBalance(Number(balance));
126-
127-
setTransactionSuccess(true);
128-
} catch (e) {
129-
console.log("Error:", e);
130-
setTransactionFailure(true);
54+
const [transactionResponse, setTransactionResponse] = useState<any | null>(
55+
null
56+
);
57+
const [transactionFailure, setTransactionFailure] = useState(false);
58+
const [nftBalance, setNftBalance] = useState<number>(0);
59+
60+
function TransactionButton({
61+
sendTestTransaction,
62+
isTransactionLoading,
63+
label,
64+
}: {
65+
sendTestTransaction: () => Promise<void>;
66+
isTransactionLoading: boolean;
67+
label: string;
68+
}) {
69+
return (
70+
<button
71+
className="flex h-11 py-2 px-4 gap-2 flex-none items-center justify-center rounded-lg bg-gray-100 hover:bg-gray-200"
72+
onClick={sendTestTransaction}
73+
>
74+
{isTransactionLoading ? (
75+
<Icons.spinner className="h-4 w-4 animate-spin" />
76+
) : (
77+
<>
78+
<PlusIcon width={16} height={16} />
79+
</>
80+
)}
81+
{label}
82+
</button>
83+
);
13184
}
13285

133-
setIsTransactionLoading(false);
134-
};
135-
136-
return (
137-
<main>
138-
<div className="p-4">
139-
<div className="relative flex items-center gap-x-6 rounded-lg p-4">
140-
<TransactionButton
141-
sendTestTransaction={() => sendTestTransaction()}
142-
isTransactionLoading={isTransactionLoading}
143-
label="Increment Counter"
144-
/>
145-
<p className=" text-gray-600">{nftBalance}</p>
146-
</div>
147-
</div>
148-
{transactionSended && !transactionResponse && (
149-
<Alert
150-
state="information"
151-
content="Transaction in progress.. (est. time 10 sec)"
152-
/>
153-
)}
154-
{transactionSuccess && (
155-
<Alert
156-
state="success"
157-
content="Transaction confirmed !"
158-
link={{
159-
content: "Go see your transaction",
160-
url: `${process.env.NEXT_PUBLIC_SCAN_URL}tx/${transactionResponse?.transactionHash}`,
161-
}}
162-
/>
163-
)}
164-
{transactionFailure && (
165-
<Alert state="error" content="Transaction Failed !" />
166-
)}
167-
</main>
168-
);
86+
useEffect(() => {
87+
if (address) {
88+
(async () => {
89+
const balance = await counterContract.read.counters([address]);
90+
setNftBalance(Number(balance));
91+
})();
92+
}
93+
}, []);
94+
95+
const sendTestTransaction = async () => {
96+
setTransactionSended(null);
97+
setTransactionResponse(null);
98+
setTransactionFailure(false);
99+
setTransactionSuccess(false);
100+
101+
setIsTransactionLoading(true);
102+
try {
103+
if (!address) throw new Error("No wallet instance");
104+
105+
const calldata = encodeFunctionData({
106+
abi: countContractAbi,
107+
functionName: "count",
108+
});
109+
110+
const txHash = await sendTransaction({
111+
calls: {
112+
to: COUNTER_CONTRACT_ADDRESS,
113+
value: 0,
114+
data: calldata,
115+
},
116+
});
117+
118+
setTransactionSended(txHash);
119+
120+
const txResponse = await publicClient.waitForTransactionReceipt({
121+
hash: txHash,
122+
});
123+
124+
setTransactionResponse(txResponse);
125+
126+
const balance = await counterContract.read.counters([address]);
127+
setNftBalance(Number(balance));
128+
129+
setTransactionSuccess(true);
130+
} catch (e) {
131+
console.log("Error:", e);
132+
setTransactionFailure(true);
133+
}
134+
135+
setIsTransactionLoading(false);
136+
};
137+
138+
return (
139+
<main>
140+
<div className="p-4">
141+
<div className="relative flex items-center gap-x-6 rounded-lg p-4">
142+
<TransactionButton
143+
sendTestTransaction={() => sendTestTransaction()}
144+
isTransactionLoading={isTransactionLoading}
145+
label="Increment Counter"
146+
/>
147+
<p className=" text-gray-600">{nftBalance}</p>
148+
</div>
149+
</div>
150+
{transactionSended && !transactionResponse && (
151+
<Alert
152+
state="information"
153+
content="Transaction in progress.. (est. time 10 sec)"
154+
/>
155+
)}
156+
{transactionSuccess && (
157+
<Alert
158+
state="success"
159+
content="Transaction confirmed !"
160+
link={{
161+
content: "Go see your transaction",
162+
url: `${process.env.NEXT_PUBLIC_SCAN_URL}tx/${transactionResponse?.transactionHash}`,
163+
}}
164+
/>
165+
)}
166+
{transactionFailure && (
167+
<Alert state="error" content="Transaction Failed !" />
168+
)}
169+
</main>
170+
);
169171
}
170172

171173
export default Transaction;

0 commit comments

Comments
 (0)