lifinance/widget

vue3 walletManagement error

vic-x opened this issue · 10 comments

vic-x commented

Vue3 configures walletManagement. When clicking 'swap', the chain selected by the wallet is different from the chain selected by the current exchange. Switch the chain first, and an error will be reported after the operation is successful.

image

walletManagement: {
connect: async () => {
connectWallet()
},
disconnect: disconnect,
switchChain: async chainId => {
await SwitchNetwork({
chainId: chainId
})
},
addToken: addToken,
addChain: addChain,
signer: Signer
}

@vic-x could you please provide a reproducible example/screen recording/more detailed steps to reproduce?

vic-x commented

@vic-x您能否提供可重现的示例/屏幕录像/更详细的重现步骤?

cf176f6e764a080c8e9bb26c8e39e872_0_1682585552.mp4

Vue3 configures walletManagement. When clicking 'swap', the chain selected by the wallet is different from the chain selected by the current exchange. Switch the chain first, and an error will be reported after the operation is successful.

image

walletManagement: { connect: async () => { connectWallet() }, disconnect: disconnect, switchChain: async chainId => { await SwitchNetwork({ chainId: chainId }) }, addToken: addToken, addChain: addChain, signer: Signer }

@vic-x thanks for the video! Closely reviewing your code example I noticed you don't return Signer object from switchChain function. If you take a look at the types it's required to return Promise<Signer>:

export interface WidgetWalletManagement {
  connect(): Promise<Signer>;
  disconnect(): Promise<void>;
  switchChain?(chainId: number): Promise<Signer>;
  addToken?(token: StaticToken, chainId: number): Promise<void>;
  addChain?(chainId: number): Promise<boolean>;
  signer?: Signer;
}

Try changing your code example to:

walletManagement: {
  connect: async () => {
    return connectWallet()
  },
  disconnect: disconnect,
  switchChain: async chainId => {
    return SwitchNetwork({
      chainId: chainId
    })
  },
  addToken: addToken,
  addChain: addChain,
  signer: Signer
}
vic-x commented

Vue3 配置钱包管理。点击“切换”时,钱包选择的链与当前交易所选择的链不同。先切换链,运行成功后会报错。
图像
walletManagement: { connect: async () => { connectWallet() }, disconnect: 断开连接, switchChain: async chainId => { await SwitchNetwork({ chainId: chainId }) }, addToken: addToken, addChain: addChain, signer: Signer }

@vic-x感谢视频!仔细查看您的代码示例,我注意到您没有Signer从函数返回对象switchChain。如果您查看需要返回的类型Promise<Signer>

export interface WidgetWalletManagement {
  connect(): Promise<Signer>;
  disconnect(): Promise<void>;
  switchChain?(chainId: number): Promise<Signer>;
  addToken?(token: StaticToken, chainId: number): Promise<void>;
  addChain?(chainId: number): Promise<boolean>;
  signer?: Signer;
}

尝试将您的代码示例更改为:

walletManagement: {
  connect: async () => {
    return connectWallet()
  },
  disconnect: disconnect,
  switchChain: async chainId => {
    return SwitchNetwork({
      chainId: chainId
    })
  },
  addToken: addToken,
  addChain: addChain,
  signer: Signer
}

@chybisov Thank you for your reply, but I still have problems after I modified it. I use @wagmi/core to link wallets, switch chains, and get Signer;

The following is the modified code

walletManagement: {
connect: async () => {
connectWallet(connector, chainId.value)
const Signer = await fetchSigner()
return markRaw(Signer)
},
disconnect: disconnect,
switchChain: async chainId => {
await SwitchNetwork({
chainId: chainId
})
const Signer = await fetchSigner({ chainId: chainId })
return markRaw(Signer)
},
addToken: addToken,
addChain: addChain,
signer: markRaw(Signer)
},

@vic-x hard to say from this code example what went wrong, it looks fine. Can you please share a reproducible example so I can debug it?

vic-x commented

@vic-x hard to say from this code example what went wrong, it looks fine. Can you please share a reproducible example so I can debug it?

@chybisov
I wrote a demo, you can view it at https://github.com/vic-x/lifi-demo

@vic-x thank you for the demo. We will investigate it and come back to you 🙂

@vic-x It took a while to figure out, but the fix is released in v2.0.0-beta.10.

vic-x commented

@chybisov Thank you so much for taking care of this for me。I have updated to the latest installation package and the problem has been solved。 🙏