Skip to content

Commit 7217e77

Browse files
authored
update login permissions UI and styling (#6128)
1 parent 5de72c5 commit 7217e77

File tree

2 files changed

+78
-59
lines changed

2 files changed

+78
-59
lines changed

apps/login/src/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function RootLayout({
2727
children: React.ReactNode;
2828
}>) {
2929
return (
30-
<html lang="en" className="h-full w-full">
30+
<html lang="en" className="h-full w-full bg-black text-white">
3131
<body
3232
className={`${sansFont.variable} ${monoFont.variable} h-full w-full font-sans antialiased`}
3333
>

apps/login/src/app/page.tsx

Lines changed: 77 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
"use client";
22

33
import { useSearchParams } from "next/navigation";
4-
import { createThirdwebClient, getContract, sendTransaction } from "thirdweb";
4+
import { createThirdwebClient, getContract } from "thirdweb";
55
import { baseSepolia } from "thirdweb/chains";
66
import { addSessionKey, isActiveSigner } from "thirdweb/extensions/erc4337";
7-
import { ConnectEmbed, useActiveAccount } from "thirdweb/react";
7+
import {
8+
ConnectEmbed,
9+
TransactionButton,
10+
useActiveAccount,
11+
} from "thirdweb/react";
812
import { isContractDeployed } from "thirdweb/utils";
913

1014
const sesionKeySignerAddress = "0x6f700ba0258886411D2536399624EAa7158d1742";
@@ -16,41 +20,6 @@ const client = createThirdwebClient({
1620
export default function Page() {
1721
const account = useActiveAccount();
1822

19-
const onAccept = async () => {
20-
if (!account) {
21-
throw new Error("No account found");
22-
}
23-
const accountContract = getContract({
24-
address: account.address,
25-
// hard coded for now
26-
chain: baseSepolia,
27-
client,
28-
});
29-
let hasSesionKey = false;
30-
// check if already added
31-
const accountDeployed = await isContractDeployed(accountContract);
32-
if (accountDeployed) {
33-
hasSesionKey = await isActiveSigner({
34-
contract: accountContract,
35-
signer: sesionKeySignerAddress,
36-
});
37-
}
38-
// if not added, send tx to add the session key
39-
if (!hasSesionKey) {
40-
const transaction = addSessionKey({
41-
account,
42-
contract: accountContract,
43-
sessionKeyAddress: sesionKeySignerAddress,
44-
// hard coded for now
45-
permissions: { approvedTargets: "*" },
46-
});
47-
await sendTransaction({
48-
account,
49-
transaction,
50-
});
51-
}
52-
};
53-
5423
const searchParams = useSearchParams();
5524
const code = searchParams.get("code");
5625
const clientId = searchParams.get("clientId");
@@ -61,32 +30,82 @@ export default function Page() {
6130
return (
6231
<div className="grid h-full w-full place-items-center">
6332
{account ? (
64-
<div>
65-
<h1>Permissions Screen</h1>
33+
<div className="flex flex-col gap-4 rounded-lg border border-gray-800 p-12">
34+
<h1 className="font-bold text-3xl">Grant Permissions</h1>
35+
<p>
36+
<strong>App.xyz</strong> is asking you to grant it the following
37+
permissions:
38+
</p>
6639
<ul>
67-
<li>perm 1</li>
68-
<li>perm 2</li>
69-
<li>perm 3</li>
40+
<li>✅ Receive your identity information.</li>
41+
<li>
42+
✅ Interact with <strong>all</strong> contracts on{" "}
43+
<strong>Base Sepolia</strong>
44+
</li>
45+
<li>
46+
✅ Spend <strong>all</strong> your funds on{" "}
47+
<strong>Base Sepolia</strong>
48+
</li>
7049
</ul>
71-
<button
72-
type="button"
73-
onClick={() => {
74-
onAccept()
75-
.then(() => {
76-
// redirect back to the app
77-
window.location.href = `${redirect}${encodeHash(
78-
account.address,
79-
sesionKeySignerAddress,
80-
code || "",
81-
)}`;
82-
})
83-
.catch((e) => {
84-
console.error("failed", e);
50+
<p>
51+
By approving below you will grant <strong>App.xyz</strong> these
52+
permissions until <strong>02/02/2025</strong>.
53+
</p>
54+
<TransactionButton
55+
transaction={async () => {
56+
if (!account) {
57+
throw new Error("No account found");
58+
}
59+
const accountContract = getContract({
60+
address: account.address,
61+
// hard coded for now
62+
chain: baseSepolia,
63+
client,
64+
});
65+
let hasSesionKey = false;
66+
// check if already added
67+
const accountDeployed = await isContractDeployed(accountContract);
68+
if (accountDeployed) {
69+
hasSesionKey = await isActiveSigner({
70+
contract: accountContract,
71+
signer: sesionKeySignerAddress,
72+
});
73+
}
74+
// if not added, send tx to add the session key
75+
if (!hasSesionKey) {
76+
return addSessionKey({
77+
account,
78+
contract: accountContract,
79+
sessionKeyAddress: sesionKeySignerAddress,
80+
// hard coded for now
81+
permissions: { approvedTargets: "*" },
8582
});
83+
}
84+
throw "already-added";
85+
}}
86+
onError={(e) => {
87+
if (typeof e === "string" && e === "already-added") {
88+
// redirect back to the app
89+
window.location.href = `${redirect}${encodeHash(
90+
account.address,
91+
sesionKeySignerAddress,
92+
code || "",
93+
)}`;
94+
} else {
95+
console.error(e);
96+
}
97+
}}
98+
onTransactionConfirmed={() => {
99+
// redirect back to the app
100+
window.location.href = `${redirect}${encodeHash(
101+
account.address,
102+
sesionKeySignerAddress,
103+
code || "",
104+
)}`;
86105
}}
87106
>
88-
Accept
89-
</button>
107+
Approve
108+
</TransactionButton>
90109
</div>
91110
) : (
92111
<ConnectEmbed

0 commit comments

Comments
 (0)