labscommunity / arweave-wallet-kit

A React library for interaction with different Arweave wallets
https://docs.arweavekit.com/wallets/wallet-kit
MIT License
16 stars 9 forks source link

fix: this.callWindowApi is not a function error with useApi hook #3

Closed pawanpaudel93 closed 1 year ago

pawanpaudel93 commented 1 year ago

Bug fixed

Here, https://github.com/labscommunity/arweave-wallet-kit/blob/549ed58d06792bed4738d33b13f030d2d7b08876/src/hooks/strategy.ts#L46 Object destructuring is used to extract methods from the strategy instance but the methods lose their original this binding. So when any of the methods are used with the useApi hook, it gives this.callWindowApi is not a function error. So to fix this error, arrow functions are used for the extracted methods.

pawanpaudel93 commented 1 year ago

@martonlederer

martonlederer commented 1 year ago

Hey, the currently published version appears to work fine with object destructuring. Are you sure this is an issue? Can you upload some screenshots so I can see this error?

pawanpaudel93 commented 1 year ago

@martonlederer image

This is the error I get when using any methods from the useApi hook.

pawanpaudel93 commented 1 year ago

@martonlederer Check the deployed app which shows the above error. It uses the useApi hook to get the active address.

https://arweave-wallet-kit-demo.vercel.app/ https://github.com/pawanpaudel93/arweave-wallet-kit-demo

martonlederer commented 1 year ago

In #2, I've moved the callWindowApi function in its own utility file. We'll be merging that soon and we'll see if there are any other issues that this PR would solve, after that change. I'm going to keep this open till then, thank you 😄

martonlederer commented 1 year ago

@pawanpaudel93 I've just released a beta version of #2 and tested it out in your demo repo and it seems like it works. Would you also be able to test it? The version is 1.0.1-beta.0. Thanks!

pawanpaudel93 commented 1 year ago

Thanks, @martonlederer it works now.