Hi,
ethpress only deals with login, and after you log in, there’s a cookie set and your page reloads, thus there’s no trace of what happened before, and the walletconnect connection has been lost.
Until some integration with https://developer.ww.wp.xz.cn/rest-api/using-the-rest-api/authentication/#authentication-plugins REST-API authentication plugins is created, I’d say that that’s not possible.
EDIT:
So I said that “the connection is lost”, but actually walletconnect sets something in javascript localstorage, so you might be able to salvage things. Use your web3 library of choice (ethpress doesn’t use one), and the walletconnect web3 provider, and try things from there.
I don’t know if that’ll work well or not, but it’s worth a shot, I guess.
-
This reply was modified 6 years, 2 months ago by
lynn999.
Thread Starter
DAM
(@damland)
I can specify the web3 instance using web3js but how can I know if current user is using metamask or walletconnect?
just to know how do you sign the message without a web3 library?
Thanks!
There’s no definitive way of knowing now, I suppose. You can check window.ethereum.isMetaMask to know if a user has it installed, or check localStorage.walletconnect (or whatever that one is) is set. Obviously that can go wrong if both are set.
The library used for walletconnect signing is this one:
https://www.npmjs.com/package/@walletconnect/browser
and it actually does have transactions support as well. I guess it might have a part of web3 lib in it, but I don’t really care to know.
Thread Starter
DAM
(@damland)
Can you save somewhere if the user has used matemask or walletconnect to login to let me keep using the same wallet for that user?
And for metamask what library have you used?
Thanks
Yes, that needs to be added.
And for metamask what library have you used?
I’m using the Ethereum provider that MetaMask itself injects, there is no library being used for that. Docs here: https://docs.metamask.io/guide/ethereum-provider.html
I have uploaded a new development version: https://ww.wp.xz.cn/plugins/ethpress/advanced/ .
The hook ethpress_login now has 2 arguments (instead of 1): $user, $provider, where $provider == 'metamask' || $provider == 'trust' || $provider == 'walletconnect'.
Then you can hook to that, and do something, like set a cookie. Ex.
add_action( 'ethpress_login', function( $user, $provider = 'unknown' ) {
if ( ! is_wp_error( $user ) ) {
setcookie( 'web3_provider_used', sanitize_key( $provider ) );
}
}, 10, 2 );
The new version also has a PHP version for verifying Ethereum signatures, which is used if you have php-gmp or php-bcmath.
Oh, and I’ll add it a new version soon, probably in a couple of days, to give myself some time to think up errors it might have.
-
This reply was modified 6 years, 1 month ago by
lynn999.
Version 0.6.0 was published yesterday.
Let me know if you need something else/more than the hook.
Meanwhile, closing.