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

Settings safe integration #327

Merged
merged 16 commits into from
Jan 3, 2025

Conversation

pheuberger
Copy link
Member

@pheuberger pheuberger commented Dec 17, 2024

This PR introduces a set of features to enable Safe multisig support to make changes to the profile name and avatar image in /settings.

  1. A selector modal that enables the user to select between their EOA and all the Safes the user is an owner of for the currently selected chain.
  2. Display a pending update message when an update was initiated and is still to be signed by the other members of the Safe
  3. Let's the user cancel the pending update request in case there are typos or the new data isn't in agreement with the other signers

In a fast-follow, I'll implement an affordance to allow the user to refresh the pending request to see if the threshold of the Safe was met and commit the change to the database

Copy link

vercel bot commented Dec 17, 2024

@pheuberger is attempting to deploy a commit to the Hypercerts Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@pheuberger pheuberger force-pushed the settings-safe-integration branch from da34af3 to e5290c6 Compare December 18, 2024 14:32
Copy link

vercel bot commented Dec 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hypercerts-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2025 2:51am

@pheuberger pheuberger force-pushed the settings-safe-integration branch from e5290c6 to e8908ee Compare December 18, 2024 14:42
@pheuberger pheuberger marked this pull request as ready for review December 18, 2024 14:44
Copy link
Contributor

@bitbeckers bitbeckers left a comment

Choose a reason for hiding this comment

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

Thanks! Mostly reviewed the business logic and changes in the code. As the build doesn't succeed, we'll need another pass when that's resolved.

import { truncateEthereumAddress } from "@/lib/utils";

interface AccountItemProps {
type: "personal" | "safe";
Copy link
Contributor

Choose a reason for hiding this comment

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

to stick with the evm lingo, it's an 'eoa' not 'personal'

hooks/useAccountDetails.ts Outdated Show resolved Hide resolved
components/settings/settings-form.tsx Show resolved Hide resolved
users/hooks.ts Outdated Show resolved Hide resolved
hooks/useSignAPIMessage.ts Outdated Show resolved Hide resolved
lib/sign-api-message.ts Show resolved Hide resolved
This patch adds API Kit which unfortunately overrides viem's Address
type and thus introduces build errors around code that was and still is
fine. Please read this GitHub issue for more details:

safe-global/safe-core-sdk#1087

To get the app to build again I needed to assert address to be of type
`0x${string}` in a few places. We know it's the correct type, it's just
that the TypeScript compiler doesn't, so this is safe to do.
The motivation for the account selector is to enable users of the
Hypercerts app to execute certain transactions via a Safe. Currently
only the connected wallet can issue transactions.

The modal will fetch the Safe accounts that the currently connected
wallet is a member of and display them alongside the currently connected
wallet. Any selection made will just visually change the currently
connected wallet, but will have no impact on the behavior of the app
when sending transactions just yet.

Future commits will fully implement this feature.
The chain display component emits the following warning:

  Image with src "/chain-icons/ethereum_sepolia.png" has "fill" but is
  missing "sizes" prop. Please add it to improve page performance.

This patch adds the sizes prop to both image tags.
The component was emitting two warnings:

  Image with src "/avatar-default.jpg" has "fill" but is missing "sizes"
  prop. Please add it to improve page performance.

  Image with src "/avatar-default.jpg" has "fill" and parent element
  with invalid "position". Provided "static" should be one of
  absolute,fixed,relative.

This patch adds the sizes prop and makes the parent AvatarFallback
relative.
This is to silence the lint warnings.
This addresses this lint warning:

  Using `<img>` could result in slower LCP and higher bandwidth.
  Consider using `<Image />` from `next/image` to automatically optimize
  images. This may incur additional usage or cost from your provider.
Without this patch, when the user pastes an invalid URL or wants to type
one out themselves the app crashes.

This patch adds a check if the avatar url is valid and only then renders
the avatar preview.
The dialog steps were fairly complicated strings that were repeated
multiple times. It's easy to introduce a typo into these strings, so
they were replaced with constants.
This is in preparation to enabling smart account message signing via
Safes. That way we can abstract the selection of EOA or smart account
into this hook.

Another advantage is that we don't need to construct the domain on every
signature request.
@pheuberger pheuberger force-pushed the settings-safe-integration branch from 0313a2f to bc93fdf Compare December 24, 2024 15:38
This patch adds support for the currently selected account to initiate a
change of user data (display name and image uri).

The message is written out the Safe Transaction Service where users can
facilitate the signature flow. Then the safe message hash is sent to the
Hypercerts API which keeps track of the signature request.

Since this flow is so different to the EOA signing, it can't reuse the
EOA signing flow and at the end of the transaction it can't make the
change to the user data right away, which makes this a 1-step flow.
Without this patch the user doesn't know that a multisig user settings
update is waiting to be signed.

This displays a message below the form and informs the user of the new
name and image url.
This patch adds a way for users to cancel a pending signature request.
This is so that they don't have to commit a change to the database if it
contains a mistake or was made in error.
Managing loading state is scattered all throughout this component and
thus hard to follow. Some terms (pending) were clashing, so this patch
does away with isPending in favor isLoading while still keeping the
finer grained loading flags.
This patch adds a refresh button to the pending signature card that,
when pressed, will refresh the cached GraphQL data to see if the pending
request was executed and apply the name and avatar changes to the form.

This patch extracts the pending update card into its own component so as
to not overload the settings form too much.
Without this patch submitting the user settings changes will not
re-trigger a GraphQL fetch of the user data. This is important, however,
as we need the message hash of the Safe message in the case a multisig
is being used for this data change.

As it turns out, revalidatePathServerAction() isn't needed for this and
on its own won't work. The most straight forward approach is invoking
refetch() from useQuery().
When using a Safe to sign a user data change, the submission of the
request will display a pending data card. Given the data is pending and
explicitly shown, we need to display the original data that's still the
de facto correct data until the pending data change is executed.

Also invert the if statement to remove one level of nesting.
@pheuberger pheuberger force-pushed the settings-safe-integration branch from bc93fdf to ace376b Compare December 24, 2024 15:52
@pheuberger
Copy link
Member Author

pheuberger commented Dec 24, 2024

@bitbeckers I implemented the changes and fixed the bug I was facing. Everything builds locally and I re-deployed the Vercel preview. I hope the PR will recognize that.

Seems as though Vercel doesn't pick up my force-pushed changes, so when I redeploy it will redeploy the previously failing commit. I might have to create a new PR. Unless you have a better idea?

@bitbeckers
Copy link
Contributor

@bitbeckers I implemented the changes and fixed the bug I was facing. Everything builds locally and I re-deployed the Vercel preview. I hope the PR will recognize that.

Seems as though Vercel doesn't pick up my force-pushed changes, so when I redeploy it will redeploy the previously failing commit. I might have to create a new PR. Unless you have a better idea?

Just kicked the Vercel deployment from my end. If it indeed doesn't work, it'd need a new PR yeah

@pheuberger
Copy link
Member Author

@bitbeckers I implemented the changes and fixed the bug I was facing. Everything builds locally and I re-deployed the Vercel preview. I hope the PR will recognize that.
Seems as though Vercel doesn't pick up my force-pushed changes, so when I redeploy it will redeploy the previously failing commit. I might have to create a new PR. Unless you have a better idea?

Just kicked the Vercel deployment from my end. If it indeed doesn't work, it'd need a new PR yeah

It seems the build completed successfully. Feel free to merge any time :)

@bitbeckers bitbeckers merged commit 52f82bc into hypercerts-org:dev Jan 3, 2025
2 checks passed
@pheuberger pheuberger deleted the settings-safe-integration branch January 13, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants