Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebView: Dapp & Connect Wallet #264

Closed
phr85 opened this issue Apr 29, 2020 · 4 comments
Closed

WebView: Dapp & Connect Wallet #264

phr85 opened this issue Apr 29, 2020 · 4 comments

Comments

@phr85
Copy link

phr85 commented Apr 29, 2020

Dear Community

I'm using the Example WKWebView with injected "web3swift".
Our Android Developer using TrustWallet (AlphaWallet) Dapp Component and he can connect his wallet to our custom Dapp widget.

I'm trying the same on iOS, but without luck:
He told me we have to use "signPersonalMessage (web3.eth.personal.sign)" instead of "signMessage (web3.eth.sign)".

Does anyone know how to extend WebView bridge with this function?

Bests & thank you in advance

Philippe

@AntonGrigorevSecurrency
Copy link

AntonGrigorevSecurrency commented Apr 29, 2020

Hi @phr85 . Maybe web3.browserFunctions.personalSign can be useful for you?

@phr85
Copy link
Author

phr85 commented Apr 29, 2020

Hello @AntonGrigorevSecurrency, thank you very much for you answer.

I'm not really sure how I could bind this and what kind of params I will receive inside function:

I play around a lot and I guess it should be something like this:

self.webView.bridge.register({ (parameters, completion) in
            print("personal_sign")
            if parameters == nil {
                completion(.failure(Bridge.JSError(code: 0, description: "No parameters provided")))
                return
            }
            let allAccounts = web3.browserFunctions.getAccounts()
            let payload = parameters!["payload"] as? [String:Any]
            let personalMessage = payload!["data"] as? String
            
            let result = web3.browserFunctions.personalSign(personalMessage!, account: allAccounts?.first ?? "", password: self.walletPassword )
            if result == nil {
                completion(.failure(Bridge.JSError(code: 0, description: "Account or data is invalid")))
                return
            }
            completion(.success(["signedMessage": result as Any]))
        }, for: "eth_browserFunctions_personalSign")

@phr85
Copy link
Author

phr85 commented May 6, 2020

I found out that our Dapp is calling getAccounts, which web3swift in webview returns. Our Dapp try to access "accounts[0]" and stops. I wonder why. I also tried in Safari Inspector to access first account of getAccounts() but I didn't get result.

@phr85
Copy link
Author

phr85 commented May 7, 2020

The issue was in our Dapp and not in the library.

@phr85 phr85 closed this as completed May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants