Open ghost opened 2 years ago
Hi! At first sight I can see that you are passing idlFactory
when it's expecting interfaceFactory
.
Other than that the code seems fine I think. Let me know if this works or not. You can also always drop us a message in the discord channel (should get a quicker answer too!)
public async createActor<T>({
canisterId,
interfaceFactory,
}: CreateActor<T>): Promise<ActorSubclass<T>>
@tomiir thanks so much, this was indeed the problem. After I started passing idlFactory
as interfaceFactory
I indeed could create the agent successfully:
let status = await window.ic.plug.isConnected();
if (status) {
console.log(status, host, canisterId, idlFactory);
const actor = await window.ic.plug.createActor({ host, canisterId, interfaceFactory: idlFactory });
let result = await actor.popular_tags();
}
However now I run into the next problem with this newly created agent. Whenever I call any function on it (eg popular_tags
in the example above) I always get Uncaught (in promise) Error: No Agent could be found.
I asked this question in #plug channel on discord, but didn't get useful hints. Do you have an idea maybe?
Btw, I figured out the issue - my flow reloaded the window after the connection and this destroyed the agent. I'm puzzled right now how to avoid reconnecting on every new app visit, but will consult the docs first. Sorry for the noise!
FYI, I decided to not integrate Plug for now. I managed to get it working, but I don't think the only workflow I found working is user friendly. Let me sketch the issues I encountered so that you can consider improving them in the future.
TypeError: e is not a function
: was caused by me misreading idlFactory
as interfaceFactory
. So it seems that interfaceFactory
is a required parameter of the createActor
constructor. This problem wouldn't be a problem if createActor
would check all required arguments and return an error if one of them is missing.Uncaught (in promise) Error: No Agent could be found.
: it turns out that for some unclear (to me) reason, even if await window.ic.plug.isConnected()
returns true
I still need to call await window.ic.plug.requestConnect({ host, whitelist: [canisterId] })
so that the agent gets initialized. Which effectively means there is no notion of a session and the Plug modal is shown on every single loading of the page. This makes no sense to me.if (process.env.DFX_NETWORK == "local") await window.ic.plug.agent.fetchRootKey();
But it really should be in the docs or even automated.await window.ic.plug.disconnect()
is not working: it just hangs on that await
for quite some time and then eventually I see the error Uncaught (in promise) Error: There was an error when this app/page tried to interact with your wallet in Plug. Please contact this project’s developers
. I guess I could solve this as well somehow, but I decided to deprioritize the ingreation for now.I help it helps during the future development!
Reopening this issue as it contains a lot of valid points and possible improvements.
Hi @TaggrX. Thanks for taking the time to debug and describe these issues so thoroughly and sorry for the late reply :pray: You make very valid points and I'll try to address them individually:
createActor
method should be creating an agent if it's not present. The issue with the agent is that whenever a page refreshes, the inpage script in plug is re-executed, and the provider re-instantiated, causing the agent to be removed. We've had this issue for some time now and part of the reason we are trying to push the createActor
approach (instead of creating actors with ic.plug.agent
) is to ensure the agent is created at the time of execution and thus always available to the user.We'll be scoping and planning these fixes next week and will let you know when they are released. Thanks again for the feedback and feel free to drop a message in our discord anytime! https://discord.gg/pFjDRhms
Thanks so much for addressing my feedback! I should have more time in a couple of weeks and would be very happy to try integrating Plug again!
Hi! @TaggrX wanted to do a follow up on this points
Will keep the issue open till we release 0.6.
Thank you very much for all the feedback :D
Dear team,
I've played with the Plug Wallet and tried to integrate it into my small app, but to no avail. I'm using version
0.4.4
with latest Firefox and here's my code almost without any modifications from your docs:The first 3 lines work as expected and I see a console output with
status
beingtrue
, my canister id and that theidlFunction
is initialized. However, the execution ofcreateAgent
fails with an exception (see the screenshot).Since it's an internal exception and not an error returned from the actor constructor, I am a bit clueless about how to proceed.
Any help is appreciated!