Closed Taosome closed 11 months ago
vue2.x 中没有 setup
要使用 composition API
另外我计划在下一大版本中取消对vue2.x的支持
好吧,2.7是支持setup了的。 我看你的源码后发现,报上面错误的原因在这里, 通过inject却无法获得provide的值。我正在想办法,让它判断若isVue2时,换个方式取值
最后, 感谢您的回复
你使用 UseWagmiPlugin
了吗?
使用了的。而且我这样手动使用inject是可以注入进来的,很奇怪,引入你的Hook的时候,就会报错呢
额 测试都是在vue3的环境中进行的 这里可能有一些问题 为什么不用vue3呢
比较久的一项目啦,车太重了 不好迁移
---- 回复的原邮件 ---- | 发件人 | Unic @.> | | 日期 | 2023年11月28日 18:05 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [unicape/use-wagmi] bug:
额 测试都是在vue3的环境中进行的 这里可能有一些问题 为什么不用vue3呢
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
方便在StackBlitz上传份代码吗 我抽空修一下
好的 我明天上午传。 感谢
---- 回复的原邮件 ---- | 发件人 | Unic @.> | | 日期 | 2023年11月28日 19:07 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [unicape/use-wagmi] bug:
方便在StackBlitz上传份代码吗 我抽空修一下
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
唉, StackBlitz 上面不能调整node版本, 跑不起来
我抽空去测试吧
好的麻烦了 Node version: v14.21.3 package-json:
{
"name": "b",
"version": "0.0.1",
"license": "MIT",
"scripts": {
"dev": "vue-cli-service serve",
"build": "vue-cli-service build"
},
"dependencies": {
"use-wagmi": "^0.4.6",
"viem": "^1.19.9",
"vue": "^2.7.14",
},
"devDependencies": {
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.3",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-proposal-optional-chaining": "^7.13.12",
"@babel/plugin-transform-runtime": "^7.23.4",
"@babel/preset-env": "^7.23.3",
"@vue/cli-plugin-babel": "^4.5.18",
"@vue/cli-service": "^4.5.18",
"autoprefixer": "^9.5.1",
"core-js": "^3.6.5"
}
}
babel.config.js:
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset',
],
plugins: ["@babel/plugin-proposal-optional-chaining", "@babel/plugin-proposal-nullish-coalescing-operator"]
};
vue.config.js:
module.exports = {
...,
transpileDependencies:['use-wagmi','@wagmi','viem', '@noble', 'abitype', '@walletconnect', 'unstorage']
}
长时间未回复 暂时关闭
抱歉,生病了才回来。 试了你提到的办法,还是不行,报错和一开始issue截图的一致。 我只有用wagmi/core来自己封装了。 最后感谢大佬付出的时间。
@Taosome 你可以创建一个仓库吗? 我去fork一份
I have the same issue and i can't read chinese!! I don't even know what to do. Am i supposed to copy the comments and pasted them in a translation api or i just stare at em until i understand😭😭😭😭
@Taosome 尝试下这样做 @An0nym0usAng3l Try this
// main.js
import { UseWagmiPlugin, configureChains, createConfig } from 'use-wagmi';
import { avalanche, goerli, mainnet, optimism } from 'use-wagmi/chains';
import { CoinbaseWalletConnector } from 'use-wagmi/connectors/coinbaseWallet';
import { InjectedConnector } from 'use-wagmi/connectors/injected';
import { LedgerConnector } from 'use-wagmi/connectors/ledger';
import { MetaMaskConnector } from 'use-wagmi/connectors/metaMask';
import { SafeConnector } from 'use-wagmi/connectors/safe';
import { WalletConnectConnector } from 'use-wagmi/connectors/walletConnect';
import { WalletConnectLegacyConnector } from 'use-wagmi/connectors/walletConnectLegacy';
import { alchemyProvider } from 'use-wagmi/providers/alchemy';
import { infuraProvider } from 'use-wagmi/providers/infura';
import { publicProvider } from 'use-wagmi/providers/public';
import { Buffer } from 'buffer';
window.global = window;
window.Buffer = Buffer;
import { createApp } from 'vue-demi';
import App from './App.vue';
const { chains, publicClient, webSocketPublicClient } = configureChains(
[mainnet, goerli, optimism, avalanche],
[
alchemyProvider({ apiKey: '' }), //TODO: your API Key
infuraProvider({ apiKey: '' }), //TODO: your API Key
publicProvider()
]
);
const config = createConfig({
autoConnect: true,
connectors: [
new MetaMaskConnector({
chains,
options: {
UNSTABLE_shimOnConnectSelectAccount: true
}
}),
new CoinbaseWalletConnector({
chains,
options: {
appName: 'use-wagmi'
}
}),
new WalletConnectConnector({
chains,
options: {
projectId: '' //TODO: your project ID
}
}),
new WalletConnectLegacyConnector({
chains,
options: {
qrcode: true
}
}),
new LedgerConnector({
chains,
options: {
projectId: '' //TODO: your project ID
}
}),
new InjectedConnector({
chains,
options: {
name: detectedName => `Injected (${typeof detectedName === 'string' ? detectedName : detectedName.join(', ')})`,
shimDisconnect: true
}
}),
new SafeConnector({
chains,
options: {
allowedDomains: [/https:\/\/app.safe.global$/],
debug: false
}
})
],
publicClient,
webSocketPublicClient
});
const app = createApp(App);
app.use(UseWagmiPlugin, config);
app.mount('#app');
@Taosome 尝试下这样做 @An0nym0usAng3l Try this
// main.js import { UseWagmiPlugin, configureChains, createConfig } from 'use-wagmi'; import { avalanche, goerli, mainnet, optimism } from 'use-wagmi/chains'; import { CoinbaseWalletConnector } from 'use-wagmi/connectors/coinbaseWallet'; import { InjectedConnector } from 'use-wagmi/connectors/injected'; import { LedgerConnector } from 'use-wagmi/connectors/ledger'; import { MetaMaskConnector } from 'use-wagmi/connectors/metaMask'; import { SafeConnector } from 'use-wagmi/connectors/safe'; import { WalletConnectConnector } from 'use-wagmi/connectors/walletConnect'; import { WalletConnectLegacyConnector } from 'use-wagmi/connectors/walletConnectLegacy'; import { alchemyProvider } from 'use-wagmi/providers/alchemy'; import { infuraProvider } from 'use-wagmi/providers/infura'; import { publicProvider } from 'use-wagmi/providers/public'; import { Buffer } from 'buffer'; window.global = window; window.Buffer = Buffer; import { createApp } from 'vue-demi'; import App from './App.vue'; const { chains, publicClient, webSocketPublicClient } = configureChains( [mainnet, goerli, optimism, avalanche], [ alchemyProvider({ apiKey: '' }), //TODO: your API Key infuraProvider({ apiKey: '' }), //TODO: your API Key publicProvider() ] ); const config = createConfig({ autoConnect: true, connectors: [ new MetaMaskConnector({ chains, options: { UNSTABLE_shimOnConnectSelectAccount: true } }), new CoinbaseWalletConnector({ chains, options: { appName: 'use-wagmi' } }), new WalletConnectConnector({ chains, options: { projectId: '' //TODO: your project ID } }), new WalletConnectLegacyConnector({ chains, options: { qrcode: true } }), new LedgerConnector({ chains, options: { projectId: '' //TODO: your project ID } }), new InjectedConnector({ chains, options: { name: detectedName => `Injected (${typeof detectedName === 'string' ? detectedName : detectedName.join(', ')})`, shimDisconnect: true } }), new SafeConnector({ chains, options: { allowedDomains: [/https:\/\/app.safe.global$/], debug: false } }) ], publicClient, webSocketPublicClient }); const app = createApp(App); app.use(UseWagmiPlugin, config); app.mount('#app');
Thank you! @unicape
@Taosome 尝试下这样做 @An0nym0usAng3l Try this
// main.js import { UseWagmiPlugin, configureChains, createConfig } from 'use-wagmi'; import { avalanche, goerli, mainnet, optimism } from 'use-wagmi/chains'; import { CoinbaseWalletConnector } from 'use-wagmi/connectors/coinbaseWallet'; import { InjectedConnector } from 'use-wagmi/connectors/injected'; import { LedgerConnector } from 'use-wagmi/connectors/ledger'; import { MetaMaskConnector } from 'use-wagmi/connectors/metaMask'; import { SafeConnector } from 'use-wagmi/connectors/safe'; import { WalletConnectConnector } from 'use-wagmi/connectors/walletConnect'; import { WalletConnectLegacyConnector } from 'use-wagmi/connectors/walletConnectLegacy'; import { alchemyProvider } from 'use-wagmi/providers/alchemy'; import { infuraProvider } from 'use-wagmi/providers/infura'; import { publicProvider } from 'use-wagmi/providers/public'; import { Buffer } from 'buffer'; window.global = window; window.Buffer = Buffer; import { createApp } from 'vue-demi'; import App from './App.vue'; const { chains, publicClient, webSocketPublicClient } = configureChains( [mainnet, goerli, optimism, avalanche], [ alchemyProvider({ apiKey: '' }), //TODO: your API Key infuraProvider({ apiKey: '' }), //TODO: your API Key publicProvider() ] ); const config = createConfig({ autoConnect: true, connectors: [ new MetaMaskConnector({ chains, options: { UNSTABLE_shimOnConnectSelectAccount: true } }), new CoinbaseWalletConnector({ chains, options: { appName: 'use-wagmi' } }), new WalletConnectConnector({ chains, options: { projectId: '' //TODO: your project ID } }), new WalletConnectLegacyConnector({ chains, options: { qrcode: true } }), new LedgerConnector({ chains, options: { projectId: '' //TODO: your project ID } }), new InjectedConnector({ chains, options: { name: detectedName => `Injected (${typeof detectedName === 'string' ? detectedName : detectedName.join(', ')})`, shimDisconnect: true } }), new SafeConnector({ chains, options: { allowedDomains: [/https:\/\/app.safe.global$/], debug: false } }) ], publicClient, webSocketPublicClient }); const app = createApp(App); app.use(UseWagmiPlugin, config); app.mount('#app');
Thank you! @unicape
Please tell me the results later. I only went through a simple test and found no errors.
@unicape I am using nuxt for my project so there there was really no way for
const app = createApp(App);
app.use(UseWagmiPlugin, config);
app.mount('#app');
Saw this one on another open issue
// use-wagmi.js
import {
UseWagmiPlugin,
configureChains,
createConfig,
mainnet,
sepolia,
} from "use-wagmi"
import {
arbitrum,
arbitrumGoerli,
avalanche,
polygon,
polygonMumbai,
bscTestnet,
} from "viem/chains"
import { EthereumClient, w3mConnectors, w3mProvider } from "@web3modal/ethereum"
import { Web3Modal } from "@web3modal/html"
export default defineNuxtPlugin((nuxtApp) => {
const config = useRuntimeConfig()
const projectId = config.public.WALLETCONNECT_PROJECT_ID
const chains = [
mainnet,
arbitrum,
arbitrumGoerli,
avalanche,
polygon,
polygonMumbai,
bscTestnet,
]
const { publicClient } = configureChains(chains, [
w3mProvider({ projectId }),
])
const web3config = createConfig({
autoConnect: true,
connectors: w3mConnectors({ projectId, chains }),
publicClient,
})
let web3Modal = null
if (process.client) {
const ethereumClient = new EthereumClient(web3config, chains)
web3Modal = new Web3Modal({ projectId }, ethereumClient)
}
nuxtApp.vueApp.use(UseWagmiPlugin, web3config)
return {
provide: {
web3Modal,
},
}
})
-
// nuxt.config.js
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: ["@use-wagmi/nuxt"],
runtimeConfig: {
public: {
WALLETCONNECT_PROJECT_ID: "kikiki",
},
},
})
@Taosome @An0nym0usAng3l add 2.7 example
@An0nym0usAng3l Here is the access method of nuxt. nuxt2 should have a similar method. nuxt
@An0nym0usAng3l Here is the access method of nuxt. nuxt2 should have a similar method. nuxt
Isn't it better if this is on the documentation? Instead of just the nuxt.config setup, This part should also be added so it'd be clearer. Even the vue2.7 example too.
是vue/cli版本的原因 4.5.18 要报错 换用5.x的可以
@An0nym0usAng3l Good idea, I will document it in the next big version
Is there an existing issue for this?
Package Version
0.4.6
Current Behavior
composition API 测试是正常能用的。但是引入use-wagmi中的hook时控制台就会报错
Expected Behavior
能够正常使用
Steps To Reproduce
Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)
No response
Anything else?