Socket
Socket
Sign inDemoInstall

@web3modal/core

Package Overview
Dependencies
Maintainers
11
Versions
374
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web3modal/core - npm Package Compare versions

Comparing version 4.1.3-aw214x.1 to 4.1.3-c46ed093.0

8

dist/esm/src/controllers/AccountController.js

@@ -9,3 +9,4 @@ import { subscribeKey as subKey } from 'valtio/utils';

currentTab: 0,
tokenBalance: []
tokenBalance: [],
smartAccountDeployed: false
});

@@ -64,2 +65,4 @@ export const AccountController = {

state.isConnected = false;
state.smartAccountDeployed = false;
state.currentTab = 0;
state.caipAddress = undefined;

@@ -72,6 +75,5 @@ state.address = undefined;

state.addressExplorerUrl = undefined;
state.smartAccountDeployed = undefined;
state.currentTab = 0;
state.tokenBalance = [];
}
};
//# sourceMappingURL=AccountController.js.map

@@ -107,2 +107,3 @@ import { subscribeKey as subKey } from 'valtio/utils';

page: '1',
chains: NetworkController.state.caipNetwork?.id,
entries: recommendedEntries,

@@ -133,2 +134,3 @@ include: includeWalletIds?.join(','),

entries,
chains: NetworkController.state.caipNetwork?.id,
include: includeWalletIds?.join(','),

@@ -157,2 +159,3 @@ exclude: exclude.join(',')

search,
chains: NetworkController.state.caipNetwork?.id,
include: includeWalletIds?.join(','),

@@ -169,2 +172,8 @@ exclude: excludeWalletIds?.join(',')

},
async reFetchWallets() {
state.page = 1;
state.wallets = [];
await ApiController.fetchFeaturedWallets();
await ApiController.fetchRecommendedWallets();
},
prefetch() {

@@ -171,0 +180,0 @@ const promises = [

@@ -18,3 +18,3 @@ import { subscribeKey as subKey } from 'valtio/utils';

state.connectors.push(ref(connector));
if (connector.id === 'w3mAuth') {
if (connector.id === 'w3mEmail') {
const emailConnector = connector;

@@ -33,4 +33,4 @@ const optionsState = snapshot(OptionsController.state);

},
getAuthConnector() {
return state.connectors.find(c => c.type === 'AUTH');
getEmailConnector() {
return state.connectors.find(c => c.type === 'EMAIL');
},

@@ -37,0 +37,0 @@ getAnnouncedConnectorRdns() {

@@ -15,3 +15,3 @@ import { proxy, subscribe as sub, snapshot } from 'valtio/vanilla';

try {
const emailConnector = ConnectorController.getAuthConnector();
const emailConnector = ConnectorController.getEmailConnector();
if (emailConnector) {

@@ -30,3 +30,3 @@ emailConnector.provider.syncTheme({

try {
const emailConnector = ConnectorController.getAuthConnector();
const emailConnector = ConnectorController.getEmailConnector();
if (emailConnector) {

@@ -33,0 +33,0 @@ emailConnector.provider.syncTheme({

@@ -58,2 +58,3 @@ import { proxy, subscribe as sub } from 'valtio/vanilla';

state.empty = true;
state.next = undefined;
}

@@ -82,2 +83,5 @@ },

},
clearCursor() {
state.next = undefined;
},
resetTransactions() {

@@ -84,0 +88,0 @@ state.transactions = [];

@@ -10,2 +10,5 @@ import { ConstantsUtil } from './ConstantsUtil.js';

},
checkCaipNetwork(network, networkName = '') {
return network?.id.toLocaleLowerCase().includes(networkName.toLowerCase());
},
isAndroid() {

@@ -12,0 +15,0 @@ const ua = window.navigator.userAgent.toLowerCase();

@@ -8,5 +8,11 @@ import { describe, expect, it } from 'vitest';

const profileImage = 'https://ipfs.com/0x123.png';
const explorerUrl = 'https://some.explorer.com/explore';
describe('AccountController', () => {
it('should have valid default state', () => {
expect(AccountController.state).toEqual({ isConnected: false });
expect(AccountController.state).toEqual({
isConnected: false,
smartAccountDeployed: false,
currentTab: 0,
tokenBalance: []
});
});

@@ -35,7 +41,27 @@ it('should update state correctly on setIsConnected()', () => {

});
it('should update state correctly on setAddressExplorerUrl()', () => {
AccountController.setAddressExplorerUrl(explorerUrl);
expect(AccountController.state.addressExplorerUrl).toEqual(explorerUrl);
});
it('shuold update state correctly on setSmartAccountDeployed()', () => {
AccountController.setSmartAccountDeployed(true);
expect(AccountController.state.smartAccountDeployed).toEqual(true);
});
it('should update state correctly on resetAccount()', () => {
AccountController.resetAccount();
expect(AccountController.state).toEqual({ isConnected: false });
expect(AccountController.state).toEqual({
isConnected: false,
smartAccountDeployed: false,
currentTab: 0,
caipAddress: undefined,
address: undefined,
balance: undefined,
balanceSymbol: undefined,
profileName: undefined,
profileImage: undefined,
addressExplorerUrl: undefined,
tokenBalance: []
});
});
});
//# sourceMappingURL=AccountController.test.js.map

@@ -97,3 +97,3 @@ import { describe, expect, it, vi } from 'vitest';

});
it('should fetch network images', async () => {
it('should only fetch network images for networks with imageIds', async () => {
NetworkController.setRequestedCaipNetworks([

@@ -100,0 +100,0 @@ {

import { describe, expect, it } from 'vitest';
import { AssetController } from '../../index.js';
const walletImage = 'w3mWallet.png';
const walletImage2 = 'w3mWallet2.png';
const networkImage = 'ethereum.png';
const networkImage2 = 'polygon.png';
const connectorImage = 'email-connector.png';
const connectorImage2 = 'metamask-connector.png';
const tokenImage = 'eth.png';
const tokenImage2 = 'usdc.png';
const currencyImage = 'usd.png';
const currencyImage2 = 'eur.png';
const wallet = 'w3m';
const wallet2 = 'w4m';
const network = 'ethereum';
const network2 = 'polygon';
const connector = 'w3m-email';
const connector2 = 'mm-connector';
const token = 'ETH';
const token2 = 'MATIC';
const currency = 'USD';
const currency2 = 'EUR';
describe('AssetController', () => {

@@ -13,3 +33,58 @@ it('should have valid default state', () => {

});
it('should update state properly on setWalletImage()', () => {
AssetController.setWalletImage(wallet, walletImage);
expect(AssetController.state.walletImages).toEqual({ [wallet]: walletImage });
AssetController.setWalletImage(wallet, walletImage2);
expect(AssetController.state.walletImages).toEqual({ [wallet]: walletImage2 });
AssetController.setWalletImage(wallet2, walletImage2);
expect(AssetController.state.walletImages).toEqual({
[wallet]: walletImage2,
[wallet2]: walletImage2
});
});
it('should update state properly on setNetworkImage()', () => {
AssetController.setNetworkImage(network, networkImage);
expect(AssetController.state.networkImages).toEqual({ [network]: networkImage });
AssetController.setNetworkImage(network, networkImage2);
expect(AssetController.state.networkImages).toEqual({ [network]: networkImage2 });
AssetController.setNetworkImage(network2, networkImage2);
expect(AssetController.state.networkImages).toEqual({
[network]: networkImage2,
[network2]: networkImage2
});
});
it('should update state properly on setConnectorImage()', () => {
AssetController.setConnectorImage(connector, connectorImage);
expect(AssetController.state.connectorImages).toEqual({ [connector]: connectorImage });
AssetController.setConnectorImage(connector, connectorImage2);
expect(AssetController.state.connectorImages).toEqual({ [connector]: connectorImage2 });
AssetController.setConnectorImage(connector2, connectorImage2);
expect(AssetController.state.connectorImages).toEqual({
[connector]: connectorImage2,
[connector2]: connectorImage2
});
});
it('should update state properly on setTokenImage()', () => {
AssetController.setTokenImage(token, tokenImage);
expect(AssetController.state.tokenImages).toEqual({ [token]: tokenImage });
AssetController.setTokenImage(token, tokenImage2);
expect(AssetController.state.tokenImages).toEqual({ [token]: tokenImage2 });
AssetController.setTokenImage(token2, tokenImage2);
expect(AssetController.state.tokenImages).toEqual({
[token]: tokenImage2,
[token2]: tokenImage2
});
});
it('should update state properly on setCurrencyImage()', () => {
AssetController.setCurrencyImage(currency, currencyImage);
expect(AssetController.state.currencyImages).toEqual({ [currency]: currencyImage });
AssetController.setCurrencyImage(currency, currencyImage2);
expect(AssetController.state.currencyImages).toEqual({ [currency]: currencyImage2 });
AssetController.setCurrencyImage(currency2, currencyImage2);
expect(AssetController.state.currencyImages).toEqual({
[currency]: currencyImage2,
[currency2]: currencyImage2
});
});
});
//# sourceMappingURL=AssetController.test.js.map

@@ -1,10 +0,11 @@

import { describe, expect, it } from 'vitest';
import { ConnectionController } from '../../index.js';
import { describe, expect, it, vi } from 'vitest';
import { ConnectionController, ConstantsUtil, StorageUtil } from '../../index.js';
const walletConnectUri = 'wc://uri?=123';
const externalId = 'coinbaseWallet';
const type = 'AUTH';
const type = 'EMAIL';
const storageSpy = vi.spyOn(StorageUtil, 'setConnectedConnector');
const client = {
connectWalletConnect: async (onUri) => {
onUri(walletConnectUri);
await Promise.resolve();
await Promise.resolve(walletConnectUri);
},

@@ -16,2 +17,4 @@ disconnect: async () => Promise.resolve(),

};
const clientConnectExternalSpy = vi.spyOn(client, 'connectExternal');
const clientCheckInstalledSpy = vi.spyOn(client, 'checkInstalled');
const partialClient = {

@@ -40,13 +43,27 @@ connectWalletConnect: async () => Promise.resolve(),

});
it('should not throw on connectWalletConnect()', () => {
it('should update state correctly and set wcPromise on connectWalletConnect()', async () => {
const fakeDate = new Date(0);
vi.useFakeTimers();
vi.setSystemTime(fakeDate);
ConnectionController.connectWalletConnect();
expect(ConnectionController.state.wcPromise).toBeDefined();
await ConnectionController.state.wcPromise;
expect(ConnectionController.state.wcUri).toEqual(walletConnectUri);
expect(ConnectionController.state.wcPairingExpiry).toEqual(ConstantsUtil.FOUR_MINUTES_MS);
expect(storageSpy).toHaveBeenCalledWith('WALLET_CONNECT');
vi.useRealTimers();
});
it('should not throw on connectExternal()', async () => {
await ConnectionController.connectExternal({ id: externalId, type });
it('connectExternal() should trigger internal client call and set connector in storage', async () => {
const options = { id: externalId, type };
await ConnectionController.connectExternal(options);
expect(storageSpy).toHaveBeenCalledWith(type);
expect(clientConnectExternalSpy).toHaveBeenCalledWith(options);
});
it('should not throw on checkInstalled()', () => {
it('checkInstalled() should trigger internal client call', () => {
ConnectionController.checkInstalled([externalId]);
expect(clientCheckInstalledSpy).toHaveBeenCalledWith([externalId]);
});
it('should not throw on checkInstalled() without ids', () => {
ConnectionController.checkInstalled();
expect(clientCheckInstalledSpy).toHaveBeenCalledWith(undefined);
});

@@ -57,2 +74,5 @@ it('should not throw when optional methods are undefined', async () => {

ConnectionController.checkInstalled([externalId]);
expect(clientCheckInstalledSpy).toHaveBeenCalledWith([externalId]);
expect(clientCheckInstalledSpy).toHaveBeenCalledWith(undefined);
expect(ConnectionController.state._client).toEqual(partialClient);
});

@@ -59,0 +79,0 @@ it('should update state correctly on resetWcConnection()', () => {

@@ -1,5 +0,31 @@

import { describe, expect, it } from 'vitest';
import { ConnectorController } from '../../index.js';
const walletConnectConnector = { id: 'walletConnect', type: 'WALLET_CONNECT' };
import { describe, expect, it, vi } from 'vitest';
import { ConnectorController, OptionsController } from '../../index.js';
const emailProvider = {
syncDappData: (_args) => Promise.resolve(),
syncTheme: (_args) => Promise.resolve()
};
const walletConnectConnector = {
id: 'walletConnect',
explorerId: 'walletConnect',
type: 'WALLET_CONNECT'
};
const externalConnector = { id: 'external', type: 'EXTERNAL' };
const emailConnector = { id: 'w3mEmail', type: 'EMAIL', provider: emailProvider };
const announcedConnector = {
id: 'announced',
type: 'ANNOUNCED',
info: { rdns: 'announced.io' }
};
const syncDappDataSpy = vi.spyOn(emailProvider, 'syncDappData');
const syncThemeSpy = vi.spyOn(emailProvider, 'syncTheme');
const mockDappData = {
metadata: {
description: 'Desc',
name: 'Name',
url: 'url.com',
icons: ['icon.png']
},
projectId: '1234',
sdkVersion: 'react-wagmi-4.0.13'
};
const metamaskConnector = {

@@ -10,2 +36,6 @@ id: 'metamask',

};
const zerionConnector = {
id: 'ecc4036f814562b41a5268adc86270fba1365471402006302e70169465b7ac18',
type: 'INJECTED'
};
describe('ConnectorController', () => {

@@ -33,7 +63,45 @@ it('should have valid default state', () => {

it('should return the correct connector on getConnector', () => {
expect(ConnectorController.getConnector('walletConnect', '')).toBe(walletConnectConnector);
ConnectorController.addConnector(zerionConnector);
expect(ConnectorController.getConnector('walletConnect', '')).toBe(undefined);
expect(ConnectorController.getConnector('', 'io.metamask.com')).toBe(metamaskConnector);
expect(ConnectorController.getConnector(zerionConnector.id, '')).toBeUndefined();
expect(ConnectorController.getConnector('unknown', '')).toBeUndefined();
});
it('getEmailConnector() should not throw when email connector is not set', () => {
expect(ConnectorController.getEmailConnector()).toEqual(undefined);
});
it('should trigger corresponding sync methods when adding email connector', () => {
OptionsController.setMetadata(mockDappData.metadata);
OptionsController.setSdkVersion(mockDappData.sdkVersion);
OptionsController.setProjectId(mockDappData.projectId);
ConnectorController.addConnector(emailConnector);
expect(ConnectorController.state.connectors).toEqual([
walletConnectConnector,
externalConnector,
metamaskConnector,
emailConnector
]);
expect(syncDappDataSpy).toHaveBeenCalledWith(mockDappData);
expect(syncThemeSpy).toHaveBeenCalledWith({ themeMode: 'dark', themeVariables: {} });
});
it('getEmailConnector() should return emailconnector when already added', () => {
expect(ConnectorController.getEmailConnector()).toEqual(emailConnector);
});
it('getAnnouncedConnectorRdns() should not throw when no announced connector is not set', () => {
expect(ConnectorController.getAnnouncedConnectorRdns()).toEqual([]);
});
it('getAnnouncedConnectorRdns() should return corresponding info array', () => {
ConnectorController.addConnector(announcedConnector);
expect(ConnectorController.getAnnouncedConnectorRdns()).toEqual(['announced.io']);
});
it('getConnnectors() should return all connectors', () => {
expect(ConnectorController.getConnectors()).toEqual([
walletConnectConnector,
externalConnector,
metamaskConnector,
emailConnector,
announcedConnector
]);
});
});
//# sourceMappingURL=ConnectorController.test.js.map

@@ -182,3 +182,23 @@ import { describe, expect, it, vi } from 'vitest';

});
it('should clear cursor correctly', async () => {
const fetchTransactions = vi
.spyOn(BlockchainApiController, 'fetchTransactions')
.mockResolvedValue({
data: [],
next: 'cursor'
});
await TransactionsController.fetchTransactions('0x123');
expect(TransactionsController.state.next).toBe('cursor');
TransactionsController.clearCursor();
expect(TransactionsController.state.next).toBeUndefined();
await TransactionsController.fetchTransactions('0x123');
expect(fetchTransactions).toHaveBeenCalledWith({
account: '0x123',
projectId,
cursor: undefined,
onramp: undefined
});
expect(TransactionsController.state.next).toBe('cursor');
});
});
//# sourceMappingURL=TransactionsController.test.js.map

@@ -35,4 +35,5 @@ import { FetchUtil } from '../utils/FetchUtil.js';

searchWallet({ search }: Pick<ApiGetWalletsRequest, 'search'>): Promise<void>;
reFetchWallets(): Promise<void>;
prefetch(): void;
fetchAnalyticsConfig(): Promise<void>;
};

@@ -1,2 +0,2 @@

import type { Connector, AuthConnector } from '../utils/TypeUtil.js';
import type { Connector, EmailConnector } from '../utils/TypeUtil.js';
export interface ConnectorControllerState {

@@ -10,3 +10,3 @@ connectors: Connector[];

addConnector(connector: Connector): void;
getAuthConnector(): AuthConnector | undefined;
getEmailConnector(): EmailConnector | undefined;
getAnnouncedConnectorRdns(): (string | undefined)[];

@@ -13,0 +13,0 @@ getConnectors(): Connector[];

import type { CaipNetwork, Connector, WcWallet } from '../utils/TypeUtil.js';
export interface RouterControllerState {
view: 'Account' | 'AccountSettings' | 'AllWallets' | 'ApproveTransaction' | 'BuyInProgress' | 'WalletCompatibleNetworks' | 'Connect' | 'ConnectingExternal' | 'ConnectingWalletConnect' | 'ConnectingSiwe' | 'ConnectSocials' | 'ConnectWallets' | 'Downloads' | 'EmailVerifyOtp' | 'EmailVerifyDevice' | 'GetWallet' | 'Networks' | 'OnRampActivity' | 'OnRampFiatSelect' | 'OnRampProviders' | 'OnRampTokenSelect' | 'SwitchNetwork' | 'Transactions' | 'UnsupportedChain' | 'UpdateEmailWallet' | 'UpdateEmailPrimaryOtp' | 'UpdateEmailSecondaryOtp' | 'UpgradeEmailWallet' | 'UpgradeToSmartAccount' | 'WalletReceive' | 'WalletSend' | 'WalletSendPreview' | 'WalletSendSelectToken' | 'WhatIsANetwork' | 'WhatIsAWallet' | 'WhatIsABuy';
view: 'Account' | 'AccountSettings' | 'AllWallets' | 'ApproveTransaction' | 'BuyInProgress' | 'WalletCompatibleNetworks' | 'Connect' | 'ConnectingExternal' | 'ConnectingWalletConnect' | 'ConnectingSiwe' | 'Downloads' | 'EmailVerifyOtp' | 'EmailVerifyDevice' | 'GetWallet' | 'Networks' | 'OnRampActivity' | 'OnRampFiatSelect' | 'OnRampProviders' | 'OnRampTokenSelect' | 'SwitchNetwork' | 'Transactions' | 'UnsupportedChain' | 'UpdateEmailWallet' | 'UpdateEmailPrimaryOtp' | 'UpdateEmailSecondaryOtp' | 'UpgradeEmailWallet' | 'UpgradeToSmartAccount' | 'WalletReceive' | 'WalletSend' | 'WalletSendPreview' | 'WalletSendSelectToken' | 'WhatIsANetwork' | 'WhatIsAWallet' | 'WhatIsABuy';
history: RouterControllerState['view'][];

@@ -5,0 +5,0 @@ data?: {

@@ -18,4 +18,5 @@ import type { Transaction } from '@web3modal/common';

filterSpamTransactions(transactions: Transaction[]): Transaction[];
clearCursor(): void;
resetTransactions(): void;
};
export {};

@@ -5,2 +5,3 @@ import type { Balance } from '@web3modal/common';

isMobile(): boolean;
checkCaipNetwork(network: CaipNetwork | undefined, networkName?: string): boolean | undefined;
isAndroid(): boolean;

@@ -7,0 +8,0 @@ isIos(): boolean;

@@ -18,4 +18,3 @@ import type { W3mFrameProvider } from '@web3modal/wallet';

export type Platform = 'mobile' | 'desktop' | 'browser' | 'web' | 'qrcode' | 'unsupported';
export type ConnectorType = 'EXTERNAL' | 'WALLET_CONNECT' | 'INJECTED' | 'ANNOUNCED' | 'AUTH';
export type SocialProvider = 'google' | 'apple' | 'facebook' | 'x' | 'github' | 'discord' | 'twitch' | 'telegram';
export type ConnectorType = 'EXTERNAL' | 'WALLET_CONNECT' | 'INJECTED' | 'ANNOUNCED' | 'EMAIL';
export type Connector = {

@@ -32,9 +31,5 @@ id: string;

provider?: unknown;
email?: boolean;
socials?: SocialProvider[];
};
export interface AuthConnector extends Connector {
export interface EmailConnector extends Connector {
provider: W3mFrameProvider;
socials?: SocialProvider[];
email?: boolean;
}

@@ -46,3 +41,3 @@ export type CaipNamespaces = Record<string, {

}>;
export type SdkVersion = `${'html' | 'react' | 'vue'}-wagmi-${string}` | `${'html' | 'react' | 'vue'}-ethers5-${string}` | `${'html' | 'react' | 'vue'}-ethers-${string}`;
export type SdkVersion = `${'html' | 'react' | 'vue'}-wagmi-${string}` | `${'html' | 'react' | 'vue'}-ethers5-${string}` | `${'html' | 'react' | 'vue'}-ethers-${string}` | `${'html' | 'react' | 'vue'}-solana-${string}`;
export interface BaseError {

@@ -49,0 +44,0 @@ message?: string;

{
"name": "@web3modal/core",
"version": "4.1.3-aw214x.1",
"version": "4.1.3-c46ed093.0",
"type": "module",

@@ -20,4 +20,4 @@ "main": "./dist/esm/index.js",

"dependencies": {
"@web3modal/common": "4.1.3-aw214x.1",
"@web3modal/wallet": "4.1.3-aw214x.1",
"@web3modal/common": "4.1.3-c46ed093.0",
"@web3modal/wallet": "4.1.3-c46ed093.0",
"valtio": "1.11.2"

@@ -24,0 +24,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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