@web3-onboard/wagmi
Advanced tools
Comparing version 2.0.0-wagmi.4 to 2.0.0
@@ -1,2 +0,2 @@ | ||
import { createConfig, createConnector } from '@wagmi/core'; | ||
import { createConfig, createConnector, getConnectors } from '@wagmi/core'; | ||
import { createWagmiChains, createWalletId } from './utils'; | ||
@@ -27,3 +27,4 @@ import { connect as wagmiConnect } from '@wagmi/core'; | ||
wagmiConnect, | ||
wagmiDisconnectWallet | ||
wagmiDisconnectWallet, | ||
getWagmiConnector | ||
}; | ||
@@ -99,2 +100,13 @@ } | ||
} | ||
function getWagmiConnector(label) { | ||
try { | ||
const wagmiConnectors = getConnectors(wagmiConfig); | ||
if (!(wagmiConnectors === null || wagmiConnectors === void 0 ? void 0 : wagmiConnectors.length)) | ||
return undefined; | ||
return wagmiConnectors.find(connector => connector.name === label); | ||
} | ||
catch (e) { | ||
console.error('error disconnecting wallet from wagmi', e); | ||
} | ||
} | ||
const convertW3OToWagmiWallet = (label, provider, coreProviderMethods) => { | ||
@@ -101,0 +113,0 @@ if (!coreProviderMethods || typeof coreProviderMethods === undefined) { |
@@ -1,2 +0,2 @@ | ||
import type { Config, ConnectReturnType, CreateConnectorFn } from '@wagmi/core'; | ||
import type { Config, ConnectReturnType, Connector, CreateConnectorFn } from '@wagmi/core'; | ||
import type { Chain, EIP1193Provider, ProviderAccounts } from '@web3-onboard/common'; | ||
@@ -23,2 +23,3 @@ import type { ConnectParameters } from '@wagmi/core'; | ||
wagmiDisconnectWallet: (label: string) => Promise<Config | undefined>; | ||
getWagmiConnector: (label: string) => Connector | undefined; | ||
}; |
{ | ||
"name": "@web3-onboard/wagmi", | ||
"version": "2.0.0-wagmi.4", | ||
"version": "2.0.0", | ||
"description": "Module to configure, connect and return web3-onboard wallets as wagmi wallets and wagmi-config to be used with wagmi-core methods", | ||
@@ -64,8 +64,8 @@ "keywords": [ | ||
"dependencies": { | ||
"@web3-onboard/common": "^2.4.0-wagmi.2", | ||
"@web3-onboard/common": "^2.4.0", | ||
"joi": "17.9.1", | ||
"viem": "2.12.0", | ||
"@wagmi/core": "2.10.3", | ||
"@wagmi/core": "2.10.4", | ||
"eventemitter3": "^4.0.7" | ||
} | ||
} |
@@ -18,2 +18,7 @@ # @web3-onboard/wagmi | ||
### `wagmiConnector` and Connectors | ||
`wagmiConnector` is a property returned as part of the wallet state object and can be used to interact with | ||
the WAGMI API returned from this module or an external WAGMI instance. Please see examples below... | ||
```ts | ||
@@ -23,3 +28,2 @@ import Onboard from '@web3-onboard/core' | ||
import wagmi from '@web3-onboard/wagmi' | ||
import { parseEther } from 'viem' | ||
import { | ||
@@ -36,2 +40,3 @@ sendTransaction as wagmiSendTransaction, | ||
const onboard = Onboard({ | ||
// This javascript object is unordered meaning props do not require a certain order | ||
wagmi, | ||
@@ -52,3 +57,4 @@ wallets: [injected], | ||
// current primary wallet - as multiple wallets can connect this value is the currently active | ||
const [currentPrimaryWallet] = onboard.state.get().wallets | ||
const [activeWallet] = onboard.state.get().wallets | ||
const { wagmiConnector } = activeWallet | ||
const wagmiConfig = onboard.state.get().wagmiConfig | ||
@@ -58,3 +64,3 @@ const result = await wagmiSendTransaction(wagmiConfig, { | ||
// desired connector to send txn from | ||
account: currentPrimaryWallet.accounts[0], | ||
connector: wagmiConnector, | ||
value: parseEther('0.001') | ||
@@ -65,13 +71,10 @@ }) | ||
async function switchWagmiChain(chainId) { | ||
let chainAsNumber | ||
if (isHex(chainId)) { | ||
chainAsNumber = fromHex(chainId, 'number') | ||
} else if (!isHex(chainId) && typeof chainId === 'number') { | ||
chainAsNumber = chainId | ||
} else { | ||
throw new Error('Invalid chainId') | ||
} | ||
async function signMessage(chainId) { | ||
// current primary wallet - as multiple wallets can connect this value is the currently active | ||
const [activeWallet] = onboard.state.get().wallets | ||
const wagmiConfig = onboard.state.get().wagmiConfig | ||
await switchChain(wagmiConfig, { chainId: chainAsNumber }) | ||
await wagmiSignMessage(wagmiConfig, { | ||
message: 'This is my message to you', | ||
connector: activeWallet.wagmiConnector | ||
}) | ||
} | ||
@@ -81,7 +84,6 @@ | ||
const wagmiConfig = onboard.state.get().wagmiConfig | ||
const disconnectThisWallet = getConnectors(wagmiConfig).find( | ||
connector => connector.name === label | ||
) | ||
disconnect(wagmiConfig, { connector: disconnectThisWallet }) | ||
const [activeWallet] = onboard.state.get().wallets | ||
const { wagmiConnector } = activeWallet | ||
disconnect(wagmiConfig, { connector: wagmiConnector }) | ||
} | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15370
268
0
83
+ Added@wagmi/core@2.10.4(transitive)
- Removed@wagmi/core@2.10.3(transitive)
Updated@wagmi/core@2.10.4
Updated@web3-onboard/common@^2.4.0