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

1931 Part 2: 1710 Cross network favorites #1975

Merged

Conversation

Da-Colon
Copy link
Contributor

@Da-Colon Da-Colon commented Jun 3, 2024

Fixes #1710

Kinda a weird one to fit in the middle but wanted this work to be done prior to the Local Storage migration actually is done so that the typing is setup.

This PR handles adding the network prefix to the cached favorite string. It also adds some helper functions to get the network prefix and chain id via the network prefix to allow for the UI around the favorites.

@Da-Colon Da-Colon self-assigned this Jun 3, 2024
Copy link

netlify bot commented Jun 3, 2024

Deploy Preview for decent-interface-dev ready!

Name Link
🔨 Latest commit 348a955
🔍 Latest deploy log https://app.netlify.com/sites/decent-interface-dev/deploys/6668b49754c799000884d876
😎 Deploy Preview https://deploy-preview-1975.app.dev.decentdao.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Da-Colon Da-Colon changed the base branch from develop to issue/1931-local-storage-updates June 3, 2024 16:05
src/utils/url.ts Outdated Show resolved Hide resolved
@Da-Colon Da-Colon marked this pull request as ready for review June 3, 2024 20:19
@Da-Colon Da-Colon changed the title [DRAFT] 1710 Part 2: Cross network favorites 1710 Part 2: Cross network favorites Jun 3, 2024
@Da-Colon Da-Colon changed the title 1710 Part 2: Cross network favorites 1930 Part 2: 1710 Cross network favorites Jun 3, 2024
@Da-Colon Da-Colon changed the title 1930 Part 2: 1710 Cross network favorites 1931 Part 2: 1710 Cross network favorites Jun 3, 2024
@Da-Colon
Copy link
Contributor Author

Da-Colon commented Jun 5, 2024

Found a much better solution. (kinda a duh. moment).

Soo. one thing is missing here. pulling the DAO's name on a different network. I have it almost setup but the last thing is targeting the right registry contract. I tried to find a way to make this work but ultimately I started rubbing up against the updates @adamgall is making in the typechain rework. I need those updates ha! then this will be a piece of cake.

Comment on lines +17 to +19
* @todo Should switch to object for props
*/
const useDisplayName = (account?: string | null, truncate?: boolean) => {
const useDisplayName = (account?: string | null, truncate?: boolean, chainId?: number) => {
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 would prefer these args be an object but didn't want to fill up this review with this change to all the other files

Copy link
Member

@adamgall adamgall left a comment

Choose a reason for hiding this comment

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

Nice work here, I have a couple of questions n comments

src/components/ui/icons/FavoriteIcon.tsx Outdated Show resolved Hide resolved
src/components/ui/menus/SafesMenu/SafesList.tsx Outdated Show resolved Hide resolved
src/components/ui/menus/SafesMenu/SafeMenuItem.tsx Outdated Show resolved Hide resolved
src/pages/home/SafeDisplayRow.tsx Outdated Show resolved Hide resolved
Comment on lines +90 to +92
<Image src={getNetworkIcon(network)} />
<Show above="md">
<Text>{networkConfig.chain.name}</Text>
<Text>{getChainName(network)}</Text>
Copy link
Member

Choose a reason for hiding this comment

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

What happens when these throw?

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like these (and getChainIdFromPrefix usage above) could be wrapped a useMemo, where we could gracefully handle exceptions and return some acceptable default/error data.

src/utils/url.ts Outdated Show resolved Hide resolved
src/utils/url.ts Outdated Show resolved Hide resolved
src/utils/url.ts Outdated Show resolved Hide resolved
src/utils/url.ts Outdated Show resolved Hide resolved
src/utils/address.ts Outdated Show resolved Hide resolved
src/pages/home/AllSafesDrawer.tsx Outdated Show resolved Hide resolved
Comment on lines 3 to 13
export const decodePrefixedAddress = (address: string) => {
const [prefix, addressWithoutPrefix] = address.split(':');
return {
network: prefix,
address: addressWithoutPrefix,
};
};

export const encodePrefixedAddress = (address: Address, network: string) => {
return `${network}:${address}`;
};
Copy link
Member

Choose a reason for hiding this comment

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

Ok yes! This is a great start, but I also wanted to see some validation in here.

Like, addressWithoutPrefix will be undefined if address doesn't contain a ":".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah I see. wanted a clean return instead of undefined but I can do that.

Copy link
Member

Choose a reason for hiding this comment

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

I think if you throw it doesn't add undefined to the return type

@Da-Colon
Copy link
Contributor Author

Da-Colon commented Jun 5, 2024

As far as the throw errors. I don't believe it will EVER hit here. Unsupported networks are caught way up the food chain. I did this more or less so I didn't have to type our a null or undefined. Since these settings come from hardcoded settings it shouldn't ever throw

@adamgall
Copy link
Member

adamgall commented Jun 5, 2024

As far as the throw errors. I don't believe it will EVER hit here. Unsupported networks are caught way up the food chain. I did this more or less so I didn't have to type our a null or undefined. Since these settings come from hardcoded settings it shouldn't ever throw

Which comment was this in reference to?

@Da-Colon
Copy link
Contributor Author

Da-Colon commented Jun 5, 2024

As far as the throw errors. I don't believe it will EVER hit here. Unsupported networks are caught way up the food chain. I did this more or less so I didn't have to type our a null or undefined. Since these settings come from hardcoded settings it shouldn't ever throw

Which comment was this in reference to?

image

these comments

Copy link
Contributor

@DarksightKellar DarksightKellar left a comment

Choose a reason for hiding this comment

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

Looking good here too! Had a couple thoughts in the review, if you could check 'em out

src/components/ui/icons/FavoriteIcon.tsx Outdated Show resolved Hide resolved
src/utils/address.ts Show resolved Hide resolved
Comment on lines +90 to +92
<Image src={getNetworkIcon(network)} />
<Show above="md">
<Text>{networkConfig.chain.name}</Text>
<Text>{getChainName(network)}</Text>
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like these (and getChainIdFromPrefix usage above) could be wrapped a useMemo, where we could gracefully handle exceptions and return some acceptable default/error data.

@Da-Colon
Copy link
Contributor Author

Da-Colon commented Jun 10, 2024

I feel like these (and getChainIdFromPrefix usage above) could be wrapped a useMemo, where we could gracefully handle exceptions and return some acceptable default/error data.

So similar to my answer to @adamgall is this should never throw here. As the app won't let you connect to a network that isn't supported and since we are directly using the same configuration files.

So IMO, its not needed. But if yall (@adamgall had similar thoughts) are not satisfied with my answe, then I can figure out the changes needed to make this happen, Though hard to test since the app itself won't let you switch to an unsupported network.

image

@adamgall
Copy link
Member

I feel like these (and getChainIdFromPrefix usage above) could be wrapped a useMemo, where we could gracefully handle exceptions and return some acceptable default/error data.

So similar to my answer to @adamgall is this should never throw here. As the app won't let you connect to a network that isn't supported and since we are directly using the same configuration files.

So IMO, its not needed. But if yall (@adamgall had similar thoughts) are not satisfied with my answe, then I can figure out the changes needed to make this happen, Though hard to test since the app itself won't let you switch to an unsupported network.

image

Try/catching errors like this (ones that we know "should never happen") are precisely the point.

I'd like us to get into the habit of building more bulletproof code.

If there's a possibility for a line of code to throw (when evaluating it without any extra context) (and there is in this instance) let's catch it and bubble it up.

@adamgall
Copy link
Member

@Da-Colon j/w, do you plan on doing anything more with this PR? https://decentdao.slack.com/archives/C06QZ68L5SA/p1718121588983869

@Da-Colon
Copy link
Contributor Author

Da-Colon commented Jun 11, 2024

@adamgall Yessir. I'm creating a

Placing an error Boundary with a Fallback UI, around Where this might fail.

localhost_3005_(Desktop)

@Da-Colon
Copy link
Contributor Author

@adamgall Yessir. I'm creating a

Placing an error Boundary with a Fallback UI, around Where this might fail.

localhost_3005_(Desktop)

@decentdao/product @decentdao/design Yall good with the look and copy?

@Da-Colon
Copy link
Contributor Author

Da-Colon commented Jun 11, 2024

@DarksightKellar I didn't add the useMemo as suggested with the error boundary this handles this error as is, wdyt?

Copy link
Contributor

@DarksightKellar DarksightKellar left a comment

Choose a reason for hiding this comment

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

@DarksightKellar I didn't add the useMemo as suggested with the error boundary this handles this error as is, wdyt?

@Da-Colon Yhup, me likey.

@Da-Colon Da-Colon merged commit 0d78c31 into issue/1931-local-storage-updates Jun 12, 2024
7 checks passed
@Da-Colon Da-Colon deleted the issue/1710-cross-network-favorites branch June 12, 2024 14:44
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.

Cross network favorites
3 participants