web3-onboard icon indicating copy to clipboard operation
web3-onboard copied to clipboard

connectWallet does not throw error

Open YaminZheng opened this issue 1 year ago • 4 comments

Current Behavior

try { await connectWallet({ label: 'a error label', disableModels: true }) } catch (err) { // No error, it's always connecting }

Expected Behavior

When I cancel, or pass in an unknown wallet, an error should be thrown so the code can handle it!

Steps To Reproduce

import { useOnboard } from "@web3-onboard/vue";

const { connectWallet } = useOnboard();

const onClickConnect = async () => { try { await connectWallet({ label: 'a error label', disableModels: true }) } catch (err) { alert('Unknown wallet or other error') } }

What package is effected by this issue?

@web3-onboard/vue

Is this a build or a runtime issue?

Runtime

Package Version

2.7.11

Node Version

v18.16.1

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

Anything else?

No response

Sanity Check

  • [X] If this is a build issue, I have included my build config. If this is a runtime issue, I have included reproduction steps and/or a Minimal, Reproducible Example.

YaminZheng avatar Sep 20 '23 08:09 YaminZheng

Hello @YaminZheng 👋 If I am understanding correctly you want to use the connectWallet function to autoselect a wallet but there are cases where the label that you pass in, is a wallet that doesn't exist? And therefore you need a way to detect this state and react to it? We will discuss internally whether adding an error is the appropriate response in this case. However, what you can do and what might be a better approach is to check to see if a wallet was connected after trying to auto select the wallet:

import { useOnboard } from "@web3-onboard/vue";

const { connectWallet, connectedWallet } = useOnboard();

const onClickConnect = async () => {
  try {
    await connectWallet({ label: 'a error label', disableModels: true });
    // Here you can add logic if the wallet you wanted to autoSelect wasn't selected
    if(!connectedWallet) {
      console.log('Could not find wallet to auto connect')
    }
  } catch (err) {
    alert('Unknown wallet or other error');
  }
};

taylorjdawson avatar Sep 21 '23 17:09 taylorjdawson

Sorry, my English is not good, I mean 你不能给每个错误做相同的事情 比如已经打开了一个 metamask 窗口,报错提示应该是去检查你的钱包 如果是用户取消了这个操作,可以不提示任何错误 如果是钱包出了问题,我应该提示他重新下载或刷新页面去操作。 我不知道为何要把这个 catch 在内部处理掉而不给我反馈的任何理由。把错误正确提示来对于用户来说,很值得去做

YaminZheng avatar Sep 22 '23 04:09 YaminZheng

Sorry, my English is not good, I mean 你不能给每个错误做相同的事情 比如已经打开了一个 metamask 窗口,报错提示应该是去检查你的钱包 如果是用户取消了这个操作,可以不提示任何错误 如果是钱包出了问题,我应该提示他重新下载或刷新页面去操作。 我不知道为何要把这个 catch 在内部处理掉而不给我反馈的任何理由。把错误正确提示来对于用户来说,很值得去做

@YaminZheng adding this translation for context: "You can't do the same thing for every error. For example, if a MetaMask window is already open, the error message should be to check your wallet. If the user cancels the operation, you don't need to display any error. If there's a problem with the wallet, I should prompt them to re-download or refresh the page to proceed. I don't know why you would handle this catch internally without giving me any feedback. Providing the correct error message for the user is worth doing."

Are you saying that you are not able to get the provider thrown error? i.e. if metamask throws an error you want to see and be able to catch that error?

taylorjdawson avatar Sep 22 '23 18:09 taylorjdawson

抱歉,我的英语不好,我的意思是你不能给每个错误做相同的事情比如已经打开了一个元掩码窗口,报错提示应该是检查你的钱包如果是用户取消了这个操作,可以不提示任何错误如果是钱包产生的问题,我应该提示他重新下载或刷新页面操作。我不知道为什么要把这个捕获放在内部处理中而不给我反馈任何理由。为用户提供正确的错误提示,很值得付出

@YaminZheng添加上下文翻译: “你不能对每个错误都做同样的事情。例如,如果 MetaMask 窗口已经打开,错误消息应该是检查你的钱包。如果用户取消操作,你就不会”不需要显示任何错误。如果钱包有问题,我应该提示他们重新下载或刷新页面才能继续。我不知道为什么你会在内部处理这个捕获而不给我任何反馈。提供为用户纠正错误消息是值得做的。”

您是说您无法让提供者抛出错误吗?即,如果元掩码抛出一个错误,您希望看到并能够捕获该错误?

Yes, not just metamask, but any other errors if they exist

YaminZheng avatar Sep 25 '23 02:09 YaminZheng