WalletConnect / web3modal-react-native

Web3Modal React-Native SDK
https://web3modal.com
Apache License 2.0
46 stars 15 forks source link

Return address property in useWeb3Modal() #33

Closed meppsilon closed 1 year ago

meppsilon commented 1 year ago

Hello!

I have a bit of a feature request. In my application, I'd like to have the ability to display the user's address to them after they've connected to a wallet. Currently, there isn't a clear way to retrieve the user's wallet address with the tools provided in this sdk.

So I'd like to suggest that we add address as one of the properties in the return object for the useWeb3Modal() hook.

The code could look something like this:

return {
    isOpen: modalState.open,
    open: ModalCtrl.open,
    close: ModalCtrl.close,
    provider: clientState.initialized ? ClientCtrl.provider() : undefined,
    isConnected: accountState.isConnected,
    address: accountState.address, // new code
  };

This request is similar to one I found in Github discussions so I think it is an issue that other developers have run into.

Thanks a lot ahead of time for your help! Let me know if you need me to clarify anything.

ignaciosantise commented 1 year ago

hey @meppsilon 👋 we can do that! I'll reply back when it's done 💪

In the meantime, another way of getting the user address is using a web3Provider instance.

Here you can check how it's initialized: https://github.com/WalletConnect/web3modal-react-native/blob/87b576179ea9876ec11f4c51f269f0fe0ca9b5d3/example/src/components/BlockchainActions.tsx#L27

And then you can do this to get the address:

const signer = web3Provider.getSigner();
const currentAddress = await signer.getAddress();
meppsilon commented 1 year ago

Hey @ignaciosantise,

Thanks for the tip! I will try it out.

Also, thanks for looking into implementing the address in the web3modal hook!

ignaciosantise commented 1 year ago

@meppsilon @web3modal/react-native alpha.5 is now available, and it has the new address prop in useWeb3Modal 💪