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: Add fetchCandid() function to @dfinity/agent #630

Merged
merged 9 commits into from Sep 29, 2022
Merged

Conversation

rvanasa
Copy link
Contributor

@rvanasa rvanasa commented Sep 9, 2022

Description

This PR adds a function to abstract away the implementation details for retrieving the current Candid interface based on canister metadata and the hidden __get_candid_interface_tmp_hack method (for canisters without this metadata).

At the moment, several projects (notably the IC Dashboard and Candid UI) directly call the _tmp_hack method. This fetchCandid() function can be used as a replacement in both of these web applications.

Example usage:

import { fetchCandid, HttpAgent } from '@dfinity/agent';

const agent = new HttpAgent(...);

const candidSource = await fetchCandid(agent, 'ryjl3-tyaaa-aaaaa-aaaba-cai');

How Has This Been Tested?

  • Added a new test case: agent/src/fetch_candid.test.ts
  • Works as expected in a browser environment.

Checklist:

  • My changes follow the guidelines in CONTRIBUTING.md.
  • The title of this PR complies with Conventional Commits.
  • I have edited the CHANGELOG accordingly.
  • I have made corresponding changes to the documentation. (JSDoc)

@rvanasa rvanasa requested a review from a team as a code owner September 9, 2022 21:34
@krpeacock
Copy link
Contributor

krpeacock commented Sep 20, 2022

I think this is more intuitive than CanisterStatus, so it's a good idea! One suggestion - since candid is public metadata, why not move agent to the second position and make it optional, using an anonymous HttpAgent by default?

edit - pinging @rvanasa

@rvanasa
Copy link
Contributor Author

rvanasa commented Sep 29, 2022

Sounds good; updated to use the same anonymous HttpAgent logic from both Candid UI and Motoko Playground.

I also added HttpAgent::isLocal() to simplify the relatively common use case of fetching the root key for local environments. Let me know if there's a better way of approaching this from within the agent-js codebase.

@krpeacock
Copy link
Contributor

We've avoided the concept of local or mainnet for the sake of handling testnets more naturally for NNS dapps, but I don't think I mind introducing this pattern now - it's useful for most use cases

@krpeacock krpeacock merged commit 2dc2127 into main Sep 29, 2022
@krpeacock krpeacock deleted the ryan/fetch-candid branch September 29, 2022 17:50
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.

None yet

3 participants