AlphaWallet / alpha-wallet-ios

An advanced Ethereum/EVM mobile wallet
https://www.alphawallet.com
MIT License
597 stars 371 forks source link

bug report - Make TokenScript work on Dapp Browsers (ImToken & TrustWallet) #7109

Open bobjiang opened 5 months ago

bobjiang commented 5 months ago

name: Bug Report about: Using imToken, visit https://viewer.tokenscript.org/, click DAI stablecoin, and click convert to xDAI

this is a blocking issue, without fix it, we cannot list tokenscript viewer on imToken.


Describe the bug blank page after click "convert to xDAI"

Steps to reproduce (REQUIRED)

video attached.

https://github.com/AlphaWallet/alpha-wallet-ios/assets/1224604/2ac41721-38a3-4698-9c0c-a4f51df54115

Expect all pages are open correctly.

Observed 6b. ...

Screenshots If applicable, screenshots (preferred to video) to help explain your problem, a wallet address or transaction hash if applicable/possible

Version or build number number Version number (if app store), build number (if TestFlight)

Additional context (Error Messages, etc.) Add any other context about the problem here.

AW-STJ commented 5 months ago

@abhishes007 - can you please check whether this is an issue in our iOS wallet or not?

abhishes007 commented 5 months ago

The issue is observed only iOS - imToken Wallet

Workflow:

Issue:

Recordings:

iPhone - imToken App Version : 2.14.1.4651

https://github.com/AlphaWallet/alpha-wallet-ios/assets/49184526/9c7d53f5-9839-40ba-b510-9349bc0d3026

Android - imToken App Version: : 2.14.1.4651

https://github.com/AlphaWallet/alpha-wallet-ios/assets/49184526/8dc51121-f9b7-46b7-9fae-a3efce668756

cc: @AW-STJ

bobjiang commented 5 months ago

@abhishes007 this bug should be in Trust Wallet iOS as well.

@micwallace you or others working on this?

micwallace commented 5 months ago

@bobjiang If newer tokenscript are loading (like smartcats) then it's likely some issue with these specific tokenscripts.

@abhishes007 When you get a chance can you confirm smartcats is working in Imtoken on iOS?

abhishes007 commented 5 months ago

@micwallace I tried SmartCat actions and they seems to be stuck and same goes for CatKombat too.

https://github.com/AlphaWallet/alpha-wallet-ios/assets/49184526/ab5937fc-0d7b-4bb3-92fc-ed55859fe6ba

AW-STJ commented 5 months ago

I would say that xDAI TokenScript does not work as expected. It loads up even when there is no xDAI on wallet. And it does not work, hence this issue is flagged by both ImToken and TrustWallet. Its a very old TS that was developed by James Sangalli, we would need to change it and also investigate the behaviour to confirm that it works as expected.

Hence the things to correct:

  1. Make sure that the xDAI and ENS tokenscript are working fine
  2. Make sure that tokenscript is not loaded if there is no token on the wallet, only a demo token is loaded. Make sure that this is loaded on wallets with no wallets.
  3. Make sure that the CatKombat actions are working fine for both ImToken and TrustWallet.

https://www.loom.com/share/6ca4d452facc4f7f9bfffd68ddb3993f?sid=8a6450bf-62a2-4bad-b447-4b7c8c243b0d

micwallace commented 5 months ago

@abhishes007 @bobjiang Maybe this is to do with iframe srcdoc not working in iOS webview. The thing is that I change iframe from base64URL to srcdoc because base64URL did not work in Imtoken Android.

I will push an update to staging that uses base64URL on iOS only, but can't guarantee it will work.

@bobjiang Smartcats did work in iOS previously didn't it? If it did maybe this is something that has recently changed in TS engine

micwallace commented 5 months ago

@abhishes007 Do you know if there's a way to remote debug webviews on iOS? The browser console may have some clues to what is going on.

abhishes007 commented 5 months ago

@micwallace, I am not sure of how we can access the console on iPhone for the browsers, also the browsers in question are inside the wallet (imToken, TrustWallet) apps which makes it more difficult. If you have any specific steps that I can try on my end then I will be happy to help and see if it works.

micwallace commented 5 months ago

@abhishes007 For imToken you can add a parameter to the URL to enable in-browser console: https://imtoken.gitbook.io/developers/products/webview

Although when I tried this on Android it wasn't working

micwallace commented 5 months ago

@abhishes007 If this doesn't work, let me know. I can probably install vconsole in TS viewer directly:
https://developer.trustwallet.com/developer/listing-new-dapps/debugging#id-3.-ios-safari-webview-debugging

abhishes007 commented 5 months ago

@bobjiang I tried it on TrustWallet and for me the SmartCat actions as well as the xDAI TS screens seem to be loading well unless, I am missing something - Recording is attached.

https://github.com/AlphaWallet/alpha-wallet-ios/assets/49184526/c27cdc76-b9c5-482b-b636-cac43f77e9e2

micwallace commented 5 months ago

@bobjiang With help from Abishes we've narrowed down the problem to the browser not being able to load any srcdoc or blob content within the iframe.

It's likely that a setting on the imToken webview disallows loading of this content and we are unable to fix the issue on our end. It was a similar issue to Android but I was able to get around it by using srcdoc instead of blob content (which is a better better anyway). But in the iOS version srcdoc is also disabled.

To demonstrate the issue to imToken team, I've setup a simple page to test the various ways local content can be loaded within an iframe: https://viewer-staging.tokenscript.org/assets/iframe-local-src-test.html

Can you please reach out to imToken and ask them to enable srcdoc for their webview? Tell them it is likely due to WKNavigationActionPolicy or originWhitelist not allowing this

bobjiang commented 5 months ago

@bobjiang With help from Abishes we've narrowed down the problem to the browser not being able to load any srcdoc or blob content within the iframe.

It's likely that a setting on the imToken webview disallows loading of this content and we are unable to fix the issue on our end. It was a similar issue to Android but I was able to get around it by using srcdoc instead of blob content (which is a better better anyway). But in the iOS version srcdoc is also disabled.

To demonstrate the issue to imToken team, I've setup a simple page to test the various ways local content can be loaded within an iframe: https://viewer-staging.tokenscript.org/assets/iframe-local-src-test.html

Can you please reach out to imToken and ask them to enable srcdoc for their webview? Tell them it is likely due to WKNavigationActionPolicy or originWhitelist not allowing this

let me ping the imToken guys.

AW-STJ commented 5 months ago

@bobjiang - any updates from ImToken? Also were you able to reach out to them and move the listing conversations forward.