Connect2IC / connect2ic

https://connect2ic.github.io/docs/
MIT License
92 stars 19 forks source link

Is there a hooks could create actor ? #8

Closed sandianyu closed 2 years ago

MioQuispe commented 2 years ago

Do you mean canister? There is: https://connect2ic.github.io/docs/docs/React/hooks#usecanister

It abstracts all details away of how the canister is created, since every wallet does it differently.

sandianyu commented 2 years ago

Do you mean canister? There is: https://connect2ic.github.io/docs/docs/React/hooks#usecanister

It abstracts all details away of how the canister is created, since every wallet does it differently.

Using the canister method should knowing canisterId, but the canisterId may be unknown, maybe store on ic.Therefore, I think export the createActor method just like Plug extension is a better way.

MioQuispe commented 2 years ago

Do you mean canister? There is: https://connect2ic.github.io/docs/docs/React/hooks#usecanister It abstracts all details away of how the canister is created, since every wallet does it differently.

Using the canister method should knowing canisterId, but the canisterId may be unknown, maybe store on ic.Therefore, I think export the createActor method just like Plug extension is a better way.

So you want to use mainnet canisters is that correct? I have an issue open for that https://github.com/Connect2IC/connect2ic/issues/5

It seems like something worth supporting for sure. And yeah would also like to make it able to handle dynamic canisterIds where its not known beforehand. Will have to think about it however what the API should look like. Im not sure exposing the createActor is the way to go. It can look similar to how it is now, but still support your use cases.

sandianyu commented 2 years ago

Yeah, i want to handle the dynamic canisterIds. Thanks for your support, please let me know when you finished it.

MioQuispe commented 2 years ago

Yeah, i want to handle the dynamic canisterIds. Thanks for your support, please let me know when you finished it.

In the meantime, you could do:

const {activeProvider} = useConnect()

const actor = await activeProvider.connector.createActor(canisterId, idlFactory)
sandianyu commented 2 years ago

Yeah, i want to handle the dynamic canisterIds. Thanks for your support, please let me know when you finished it.

In the meantime, you could do:

const {activeProvider} = useConnect()

const actor = await activeProvider.connector.createActor(canisterId, idlFactory)

Thanks.

sandianyu commented 2 years ago

Yeah, i want to handle the dynamic canisterIds. Thanks for your support, please let me know when you finished it.

In the meantime, you could do:

const {activeProvider} = useConnect()

const actor = await activeProvider.connector.createActor(canisterId, idlFactory)

Sorry for reopen it. Is there any way to get this actor by function method, not hooks

neeboo commented 2 years ago

Yeah, i want to handle the dynamic canisterIds. Thanks for your support, please let me know when you finished it.

In the meantime, you could do:

const {activeProvider} = useConnect()

const actor = await activeProvider.connector.createActor(canisterId, idlFactory)

Sorry for reopen it. Is there any way to get this actor by function method, not hooks

I think the best way to use them as function method meanwhile using custom canister, is to wrap the function with connector.


async function createActorFromConnector<T>(connector, canisterId, idlFactory):Promise<ActorSubClass<T>>{
       // ...
}

and return Actor somehow

sandianyu commented 2 years ago

For now, all i know how to get the "connector" is use the useConnect hooks.But it's seems to be hard for me to use hooks, because of the older code's logic

neeboo commented 2 years ago

For now, all i know how to get the "connector" is use the useConnect hooks.But it's seems to be hard for me to use hooks, because of the older code's logic

We can also consider wrapping window API for future version.

MioQuispe commented 2 years ago

For now, all i know how to get the "connector" is use the useConnect hooks.But it's seems to be hard for me to use hooks, because of the older code's logic

Yes I will probably expose the "client" in the future so it can be used outside

MioQuispe commented 2 years ago

For now, all i know how to get the "connector" is use the useConnect hooks.But it's seems to be hard for me to use hooks, because of the older code's logic

Hey there, check out latest version 0.1.0. The client is now exposed So there's no need to use hooks https://connect2ic.github.io/docs/docs/Core/Client