aurora-is-near / rainbow-bridge-frontend

🌈 Send ERC20 tokens from Ethereum to NEAR
https://rainbowbridge.app
69 stars 31 forks source link

fix(auth): fix provider not found when connecting to imtoken wallet #317

Closed unix closed 3 years ago

unix commented 3 years ago

Issue Description

When opening Rainbow Bridge in the browser inside the imToken wallet, the wallet address will not be retrieved, making it impossible to proceed to the next step.

How to Reproduce

  1. open imToken wallet, redirect to Browser tab.
  2. Type in https://ethereum.bridgetonear.org/ into your internal browser and visit.
  3. Click on the Connect button to observe this issue.

Issue Source

The imToken wallet is injected with the exact same provider as the metamask, so we need to use the metamask linking method.

Changes

PS: Rainbow Bridge is an amazing application, imToken Wallet has a lot of users who are using it. This fix will help all users who are using near in imToken, wait for updated news.

Before

near-imtoken-1

After

near-imtoken-2
paouvrard commented 3 years ago

Thank you @unix ! I've created a deployment on the goerli testnet bridge: https://imtoken.onrender.com for testing. When logging in from imToken mobile browser, there seems to be issues: when both accounts are connected, the page is blank, do you know how to get the error message ? The above url is working ok on MetaMask mobile.

unix commented 3 years ago

@paouvrard According to imToken's documentation, we can access the logs using the debug link (https://imtoken.onrender.com/?___debug=1), but I didn't find any errors.

After debugging I think the problem may be related to this line of code, the main landing is automatically hidden when params are included in the URL.

const params = Object.keys(window.urlParams.get());

if (transfers.length || params.length) {
   window.dom.hide("landing");
} 

When any page is opened within the imToken wallet, the source tracking is automatically added, and the URL is added with additional params:

// visit
http://localhost:2222/

// the real URL of the page in imToken wallet
http://localhost:2222/?locale=zh-CN&utm_source=imtoken

Solutions

To avoid misjudging the params in the URL, we have at least the following ways to solve it. (It is up to you to decide how to change it.)

paouvrard commented 3 years ago

http://localhost:2222/?locale=zh-CN&utm_source=imtoken

I see, this is going to be a problem because the @near-eth library sometimes clears all url params when a NEAR transaction is made which will break imToken, so I will have to adjust it and make a release before this can be merged. In the mean time imToken users can still interact with the bridge via WalletConnect.

paouvrard commented 3 years ago

@unix Could you rebase your PR branch so that I can update the preview and test it ?

unix commented 3 years ago

@paouvrard Resolved. (You can also change my branch at any time if necessary, the main project maintainer has push/force push access to the fork repo)