vue3 walletManagement error
vic-x opened this issue · 10 comments
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.
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?
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.
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
}
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 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