From 619ba083e270a1cfdddcb2186cdb4bf3db86b7e8 Mon Sep 17 00:00:00 2001 From: Srujan Gurram Date: Tue, 3 Sep 2024 15:34:38 +0530 Subject: [PATCH] Refactor web3 import structure to use named imports --- .changeset/yellow-carrots-jump.md | 5 +++++ src/lib/integrations/web3-auth-connector.ts | 23 ++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 .changeset/yellow-carrots-jump.md diff --git a/.changeset/yellow-carrots-jump.md b/.changeset/yellow-carrots-jump.md new file mode 100644 index 0000000..af76057 --- /dev/null +++ b/.changeset/yellow-carrots-jump.md @@ -0,0 +1,5 @@ +--- +"@everipedia/iq-login": patch +--- + +reverts web3 import structure diff --git a/src/lib/integrations/web3-auth-connector.ts b/src/lib/integrations/web3-auth-connector.ts index 4be0285..b3242a5 100644 --- a/src/lib/integrations/web3-auth-connector.ts +++ b/src/lib/integrations/web3-auth-connector.ts @@ -1,17 +1,16 @@ import type { Wallet } from "@rainbow-me/rainbowkit"; -import basePackage from "@web3auth/base"; -import ethProviderPackage from "@web3auth/ethereum-provider"; -import modalPackage from "@web3auth/modal"; -import walletServicesPluginPackage from "@web3auth/wallet-services-plugin"; +import { + WALLET_ADAPTERS, + CHAIN_NAMESPACES, + WEB3AUTH_NETWORK, +} from "@web3auth/base"; +import ethereumProvider from "@web3auth/ethereum-provider"; +import { Web3Auth } from "@web3auth/modal"; +import { WalletServicesPlugin } from "@web3auth/wallet-services-plugin"; import { Web3AuthConnector } from "@web3auth/web3auth-wagmi-connector"; import type { Chain } from "viem"; import { createConnector } from "wagmi"; -const { WALLET_ADAPTERS } = basePackage; -const { EthereumPrivateKeyProvider } = ethProviderPackage; -const { Web3Auth } = modalPackage; -const { WalletServicesPlugin } = walletServicesPluginPackage; - if (!process.env.NEXT_PUBLIC_WEB3_AUTH_CLIENT_ID) { throw new Error("NEXT_PUBLIC_WEB3_AUTH_CLIENT_ID is not set"); } @@ -24,7 +23,7 @@ export const rainbowWeb3AuthConnector = ({ const name = "Web3 Auth"; const chainConfig = { - chainNamespace: "eip155" as const, + chainNamespace: CHAIN_NAMESPACES.EIP155, chainId: `0x${chain.id.toString(16)}`, rpcTarget: chain.rpcUrls.default.http[0], displayName: chain.name, @@ -33,7 +32,7 @@ export const rainbowWeb3AuthConnector = ({ blockExplorerUrl: chain.blockExplorers?.default.url[0] as string, }; - const privateKeyProvider = new EthereumPrivateKeyProvider({ + const privateKeyProvider = new ethereumProvider.EthereumPrivateKeyProvider({ config: { chainConfig }, }); @@ -55,7 +54,7 @@ export const rainbowWeb3AuthConnector = ({ onPrimary: "#ffffff", }, }, - web3AuthNetwork: "sapphire_mainnet" as const, + web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET, enableLogging: true, });