Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@web3modal/wagmi

Package Overview
Dependencies
Maintainers
6
Versions
264
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web3modal/wagmi - npm Package Compare versions

Comparing version 3.0.0-23dbc01e to 3.0.0-73ed03f2

dist/esm/exports/index.js

101

dist/esm/src/client.js
import { connect, disconnect, fetchBalance, fetchEnsAvatar, fetchEnsName, getAccount, getNetwork, switchNetwork, watchAccount, watchNetwork } from '@wagmi/core';
import { mainnet } from '@wagmi/core/chains';
import { Web3ModalScaffoldHtml } from '@web3modal/scaffold';
import { ADD_CHAIN_METHOD, INJECTED_ID, NAMESPACE, NAME_MAP, TYPE_MAP, WALLET_CHOICE_KEY, WALLET_CONNECT_ID } from './constants';
export class Web3Modal extends Web3ModalScaffoldHtml {
import { Web3ModalScaffold } from '@web3modal/scaffold';
import { ADD_CHAIN_METHOD, NAMESPACE, VERSION, WALLET_CHOICE_KEY, WALLET_CONNECT_CONNECTOR_ID } from './utils/constants.js';
import { getCaipDefaultChain, getCaipTokens } from './utils/helpers.js';
import { ConnectorExplorerIds, ConnectorImageIds, ConnectorNamesMap, ConnectorTypesMap, NetworkImageIds } from './utils/presets.js';
export class Web3Modal extends Web3ModalScaffold {
constructor(options) {
const { wagmiConfig, projectId, chains } = options;
const { wagmiConfig, chains, defaultChain, _sdkVersion, tokens, ...w3mOptions } = options;
if (!wagmiConfig) {
throw new Error('web3modal:constructor - wagmiConfig is undefined');
}
if (!projectId) {
if (!w3mOptions.projectId) {
throw new Error('web3modal:constructor - projectId is undefined');
}
if (!wagmiConfig.connectors.find(c => c.id === WALLET_CONNECT_ID)) {
if (!wagmiConfig.connectors.find(c => c.id === WALLET_CONNECT_CONNECTOR_ID)) {
throw new Error('web3modal:constructor - WalletConnectConnector is required');

@@ -26,4 +28,4 @@ }

const walletChoice = localStorage.getItem(WALLET_CHOICE_KEY);
if (walletChoice?.includes(WALLET_CONNECT_ID)) {
const connector = wagmiConfig.connectors.find(c => c.id === WALLET_CONNECT_ID);
if (walletChoice?.includes(WALLET_CONNECT_CONNECTOR_ID)) {
const connector = wagmiConfig.connectors.find(c => c.id === WALLET_CONNECT_CONNECTOR_ID);
if (!connector) {

@@ -46,3 +48,3 @@ throw new Error('networkControllerClient:getApprovedCaipNetworks - connector is undefined');

connectWalletConnect: async (onUri) => {
const connector = wagmiConfig.connectors.find(c => c.id === WALLET_CONNECT_ID);
const connector = wagmiConfig.connectors.find(c => c.id === WALLET_CONNECT_CONNECTOR_ID);
if (!connector) {

@@ -68,10 +70,2 @@ throw new Error('connectionControllerClient:getWalletConnectUri - connector is undefined');

},
connectInjected: async () => {
const connector = wagmiConfig.connectors.find(c => c.id === INJECTED_ID);
if (!connector) {
throw new Error('connectionControllerClient:connectInjected - connector is undefined');
}
const chainId = this.caipNetworkIdToNumber(this.getCaipNetwork()?.id);
await connect({ connector, chainId });
},
checkInjectedInstalled(ids) {

@@ -91,9 +85,13 @@ if (!window?.ethereum) {

connectionControllerClient,
projectId
defaultChain: getCaipDefaultChain(defaultChain),
tokens: getCaipTokens(tokens),
_sdkVersion: _sdkVersion ?? `html-wagmi-${VERSION}`,
...w3mOptions
});
this.hasSyncedConnectedAccount = false;
this.options = undefined;
this.options = options;
this.syncRequestedNetworks(chains);
this.syncConnectors(wagmiConfig.connectors);
this.syncAccount();
watchAccount(() => this.syncAccount());
this.syncNetwork();
watchNetwork(() => this.syncNetwork());

@@ -104,3 +102,4 @@ }

id: `${NAMESPACE}:${chain.id}`,
name: chain.name
name: chain.name,
imageId: NetworkImageIds[chain.id]
}));

@@ -114,10 +113,14 @@ this.setRequestedCaipNetworks(requestedCaipNetworks ?? []);

if (isConnected && address && chain) {
this.resetWcConnection();
const caipAddress = `${NAMESPACE}:${chain.id}:${address}`;
this.setIsConnected(isConnected);
this.setCaipAddress(caipAddress);
this.syncNetwork();
await Promise.all([this.syncProfile(address), this.getApprovedCaipNetworksData()]);
await Promise.all([
this.syncProfile(address),
this.syncBalance(address, chain),
this.getApprovedCaipNetworksData()
]);
this.hasSyncedConnectedAccount = true;
}
else if (!isConnected) {
else if (!isConnected && this.hasSyncedConnectedAccount) {
this.resetWcConnection();
this.resetNetwork();

@@ -132,7 +135,13 @@ }

const caipChainId = `${NAMESPACE}:${chainId}`;
this.setCaipNetwork({ id: caipChainId, name: chain.name });
this.setCaipNetwork({ id: caipChainId, name: chain.name, imageId: NetworkImageIds[chain.id] });
if (isConnected && address) {
const caipAddress = `${NAMESPACE}:${chain.id}:${address}`;
this.setCaipAddress(caipAddress);
await this.syncBalance(address, chain);
if (chain.blockExplorers?.default?.url) {
const url = `${chain.blockExplorers.default.url}/address/${address}`;
this.setAddressExplorerUrl(url);
}
if (this.hasSyncedConnectedAccount) {
await this.syncBalance(address, chain);
}
}

@@ -142,8 +151,18 @@ }

async syncProfile(address) {
const profileName = await fetchEnsName({ address, chainId: mainnet.id });
if (profileName) {
this.setProfileName(profileName);
const profileImage = await fetchEnsAvatar({ name: profileName, chainId: mainnet.id });
if (profileImage) {
this.setProfileImage(profileImage);
try {
const { name, avatar } = await this.fetchIdentity({
caipChainId: `${NAMESPACE}:${mainnet.id}`,
address
});
this.setProfileName(name);
this.setProfileImage(avatar);
}
catch {
const profileName = await fetchEnsName({ address, chainId: mainnet.id });
if (profileName) {
this.setProfileName(profileName);
const profileImage = await fetchEnsAvatar({ name: profileName, chainId: mainnet.id });
if (profileImage) {
this.setProfileImage(profileImage);
}
}

@@ -153,10 +172,16 @@ }

async syncBalance(address, chain) {
const balance = await fetchBalance({ address, chainId: chain.id });
const balance = await fetchBalance({
address,
chainId: chain.id,
token: this.options?.tokens?.[chain.id]?.address
});
this.setBalance(balance.formatted, balance.symbol);
}
syncConnectors(connectors) {
const w3mConnectors = connectors.map(connector => ({
id: connector.id,
name: NAME_MAP[connector.id] ?? connector.name,
type: TYPE_MAP[connector.id] ?? 'EXTERNAL'
const w3mConnectors = connectors.map(({ id, name }) => ({
id,
explorerId: ConnectorExplorerIds[id],
imageId: ConnectorImageIds[id],
name: ConnectorNamesMap[id] ?? name,
type: ConnectorTypesMap[id] ?? 'EXTERNAL'
}));

@@ -163,0 +188,0 @@ this.setConnectors(w3mConnectors ?? []);

import type { Chain, Config } from '@wagmi/core';
import type { ProjectId } from '@web3modal/scaffold';
import { Web3ModalScaffoldHtml } from '@web3modal/scaffold';
export interface Web3ModalOptions {
import type { LibraryOptions, Token } from '@web3modal/scaffold';
import { Web3ModalScaffold } from '@web3modal/scaffold';
export interface Web3ModalClientOptions extends Omit<LibraryOptions, 'defaultChain' | 'tokens'> {
wagmiConfig: Config<any, any>;
projectId: ProjectId;
chains?: Chain[];
defaultChain?: Chain;
tokens?: Record<number, Token>;
}
export type Web3ModalOptions = Omit<Web3ModalClientOptions, '_sdkVersion'>;
declare global {

@@ -14,4 +16,6 @@ interface Window {

}
export declare class Web3Modal extends Web3ModalScaffoldHtml {
constructor(options: Web3ModalOptions);
export declare class Web3Modal extends Web3ModalScaffold {
private hasSyncedConnectedAccount;
private options;
constructor(options: Web3ModalClientOptions);
private syncRequestedNetworks;

@@ -18,0 +22,0 @@ private syncAccount;

{
"name": "@web3modal/wagmi",
"version": "3.0.0-23dbc01e",
"version": "3.0.0-73ed03f2",
"type": "module",
"main": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"main": "./dist/esm/exports/index.js",
"types": "./dist/types/exports/index.d.ts",
"files": [

@@ -12,24 +12,35 @@ "dist"

".": {
"import": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts"
"import": "./dist/esm/exports/index.js",
"types": "./dist/types/exports/index.d.ts"
},
"./react": {
"import": "./dist/esm/src/react.js",
"types": "./dist/types/src/react.d.ts"
"import": "./dist/esm/exports/react.js",
"types": "./dist/types/exports/react.d.ts"
},
"./vue": {
"import": "./dist/esm/exports/vue.js",
"types": "./dist/types/exports/vue.d.ts"
}
},
"typesVersions": {
"*": {
"react": [
"./dist/types/exports/react.d.ts"
],
"vue": [
"./dist/types/exports/vue.d.ts"
]
}
},
"scripts": {
"build:clean": "rm -rf dist",
"build:types": "tsc --declaration --emitDeclarationOnly --outDir ./dist/types",
"build:source": "tsc --outDir ./dist/esm",
"build": "npm run build:clean; npm run build:types; npm run build:source",
"typecheck": "tsc --noEmit"
"build": "npm run build:clean; tsc --build",
"watch": "npm run build:clean; tsc --watch",
"typecheck": "tsc --noEmit",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
"@web3modal/scaffold": "3.0.0-23dbc01e"
"@web3modal/polyfills": "3.0.0-73ed03f2",
"@web3modal/scaffold": "3.0.0-73ed03f2"
},
"devDependencies": {
"@wagmi/core": "^1",
"viem": "^1"
},
"peerDependencies": {

@@ -39,3 +50,4 @@ "@wagmi/core": ">=1",

"react-dom": ">=17",
"viem": ">=1"
"viem": ">=1",
"vue": ">=3"
},

@@ -42,0 +54,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc