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(react-components)!: rework network dropdown and network config #109

Merged
merged 2 commits into from
May 6, 2024

Conversation

samsiegart
Copy link
Contributor

@samsiegart samsiegart commented May 3, 2024

fixes #96

Overview

Removes the defaultNetworkConfig prop from AgoricProvider in favor of:

  • agoricNetworkConfigs for specifying the available networks.
  • And, defaultChainName for selecting the default network.

Now, instead of passing in networkConfigs to the network dropdown component, it just reads from agoricNetworkConfigs.

Testing

Built successfully and linked locally with dapp-offer-up, tested the new API and switching between multiple networks.

Copy link

cloudflare-workers-and-pages bot commented May 3, 2024

Deploying ui-kit with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5079d09
Status: ✅  Deploy successful!
Preview URL: https://29ead54a.ui-kit-dwm.pages.dev
Branch Preview URL: https://network-config-api.ui-kit-dwm.pages.dev

View logs

@samsiegart samsiegart requested review from turadg and LuqiPan May 3, 2024 07:12
rpc: ['https://main.rpc.agoric.net'],
},
};

const NetworkSelect = () => {
Copy link
Member

Choose a reason for hiding this comment

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

this example looks a little silly now. Consider making it more realistic

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 just added some props so it's less trivial. I didn't want to show all the agoricNetworkConfigs and AgoricProvider again because this section references agoricNetworkConfigs and the top section mentions this component already.

label,
maxHeight,
size = 'md',
appearance = 'bold',
}: NetworkDropdownProps) => {
const { networkConfig, setNetworkConfig } = useAgoricNetwork();
const { networkConfig, setNetworkConfig, agoricNetworkConfigs } =
Copy link
Member

Choose a reason for hiding this comment

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

why is this component mixing agoricNetwork from chain-registry and this useAgoricNetwork hook? I'd expect useAgoricNetwork to abstract all network selection.

Same for nameForNetwork and iconForNetwork.

Is that reasonable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just for display purposes, because NetworkConfig doesn't require a chain name or icon:

image

I see what you mean, but I'd rather not store all that state in NetworkContext just for displaying in the NetworkDropdown. The data in NetworkConfig is sufficient for selecting and connecting to the network, but the NetworkDropdown needs more data to display the options.

@samsiegart samsiegart merged commit fd71909 into main May 6, 2024
2 checks passed
@samsiegart samsiegart deleted the network-config-api branch May 6, 2024 17:04
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.

Integrate NetworkDropdown and AgoricProvider more closely
2 participants