diff --git a/packages/uiweb/src/lib/components/chat/ChatPreview/ChatPreview.tsx b/packages/uiweb/src/lib/components/chat/ChatPreview/ChatPreview.tsx index 721b36653..5d62005d5 100644 --- a/packages/uiweb/src/lib/components/chat/ChatPreview/ChatPreview.tsx +++ b/packages/uiweb/src/lib/components/chat/ChatPreview/ChatPreview.tsx @@ -9,7 +9,6 @@ import { CONSTANTS } from '@pushprotocol/restapi'; import { ethers } from 'ethers'; import { CiImageOn } from 'react-icons/ci'; import { FaFile } from 'react-icons/fa'; -import { CoreContractChainId, InfuraAPIKey } from '../../../config'; import { pushBotAddress } from '../../../config/constants'; import { pCAIP10ToWallet, resolveWeb3Name, shortenText } from '../../../helpers'; import { createBlockie } from '../../../helpers/blockies'; diff --git a/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfile.tsx b/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfile.tsx index 81c00cc9e..9c89d95e9 100644 --- a/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfile.tsx +++ b/packages/uiweb/src/lib/components/chat/ChatProfile/ChatProfile.tsx @@ -28,7 +28,7 @@ import { ProfileContainer } from '../reusables'; import { GroupInfoModal } from './ChatProfileInfoModal'; // Internal Configs -import { CoreContractChainId, InfuraAPIKey, allowedNetworks, device } from '../../../config'; +import { device } from '../../../config'; import { ThemeContext } from '../theme/ThemeProvider'; // Assets diff --git a/packages/uiweb/src/lib/components/chat/UserProfile/UserProfile.tsx b/packages/uiweb/src/lib/components/chat/UserProfile/UserProfile.tsx index 7fa81bc57..8fcea502f 100644 --- a/packages/uiweb/src/lib/components/chat/UserProfile/UserProfile.tsx +++ b/packages/uiweb/src/lib/components/chat/UserProfile/UserProfile.tsx @@ -15,7 +15,7 @@ import { ProfileContainer } from '../reusables'; import { ThemeContext } from '../theme/ThemeProvider'; import { UpdateUserProfileModal } from './UpdateUserProfileModal'; -import { Constants, CoreContractChainId, InfuraAPIKey, ProfilePicture, device } from '../../../config'; +import { device } from '../../../config'; import VerticalEllipsisIcon from '../../../icons/VerticalEllipsis.svg'; import UserProfileIcon from '../../../icons/userCircleGear.svg'; import { MODAL_BACKGROUND_TYPE, MODAL_POSITION_TYPE } from '../../../types'; @@ -33,7 +33,7 @@ export const UserProfile: React.FC = ({ updateUserProfileModalBackground = MODAL_BACKGROUND_TYPE.OVERLAY, updateUserProfileModalPositionType = MODAL_POSITION_TYPE.GLOBAL, onUserProfileUpdateModalOpen, - closeUserProfileModalOnClickAway = false + closeUserProfileModalOnClickAway = false, }) => { const { user } = useChatData(); const [userProfile, setUserProfile] = useState(); @@ -157,7 +157,7 @@ export const UserProfile: React.FC = ({ }; //styles -const Conatiner = styled(Section) ` +const Conatiner = styled(Section)` border: ${(props) => props.theme.border?.userProfile}; box-sizing: border-box; `; diff --git a/packages/uiweb/src/lib/components/chat/helpers/tokenHelpers/chain.ts b/packages/uiweb/src/lib/components/chat/helpers/tokenHelpers/chain.ts index e53db5b32..377d48247 100644 --- a/packages/uiweb/src/lib/components/chat/helpers/tokenHelpers/chain.ts +++ b/packages/uiweb/src/lib/components/chat/helpers/tokenHelpers/chain.ts @@ -1,14 +1,13 @@ -import { InfuraAPIKey } from '../../../../config'; +import { infuraAPIKey } from '../../../../config'; -const getInfuraUrlFor = (network: string, key: string) => - `https://${network}.infura.io/v3/${key}`; +const getInfuraUrlFor = (network: string, key: string) => `https://${network}.infura.io/v3/${key}`; const getRpcURL = (network: string, key: string) => { return getInfuraUrlFor(network, key); }; export const getChainRPC = (chainId: number): string => { - const key = InfuraAPIKey; + const key = infuraAPIKey; switch (chainId) { case 1: diff --git a/packages/uiweb/src/lib/components/supportChat/AddressInfo.tsx b/packages/uiweb/src/lib/components/supportChat/AddressInfo.tsx index 628d5bb8d..86dc2fb26 100644 --- a/packages/uiweb/src/lib/components/supportChat/AddressInfo.tsx +++ b/packages/uiweb/src/lib/components/supportChat/AddressInfo.tsx @@ -6,7 +6,7 @@ import { ethers } from 'ethers'; import { ChatProps } from './Chat'; import { SupportChatPropsContext } from '../../context'; -import { Constants, ENV, InfuraAPIKey, allowedNetworks } from '../../config'; +import { Constants, infuraAPIKey, allowedNetworks } from '../../config'; import { copyToClipboard, pCAIP10ToWallet, resolveWeb3Name } from '../../helpers'; import { CopySvg } from '../../icons/CopySvg'; @@ -19,7 +19,7 @@ export const AddressInfo: React.FC = () => { const [isCopied, setIsCopied] = useState(false); const walletAddress = pCAIP10ToWallet(supportAddress!); const l1ChainId = allowedNetworks[env!]?.includes(1) ? 1 : 5; - const provider = new ethers.providers.InfuraProvider(l1ChainId, InfuraAPIKey); + const provider = new ethers.providers.InfuraProvider(l1ChainId, infuraAPIKey); useEffect(() => { const getUser = async () => { diff --git a/packages/uiweb/src/lib/config/constants.ts b/packages/uiweb/src/lib/config/constants.ts index 9c22f52b6..08edc54b3 100644 --- a/packages/uiweb/src/lib/config/constants.ts +++ b/packages/uiweb/src/lib/config/constants.ts @@ -44,11 +44,16 @@ export const CoreContractChainId = { local: 11155111, }; -export const CoreRPC = { - prod: 'https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a', - dev: 'https://sepolia.infura.io/v3/5524d420b29f4f7a8d8d2f582a0d43f7', - staging: 'https://sepolia.infura.io/v3/49f638cc25a94ddb86b7aefd612f11ab', - local: 'https://sepolia.infura.io/v3/5524d420b29f4f7a8d8d2f582a0d43f7', +export const infuraAPIKey = '100cce93cd9d4626b9cedf707d4dbabc'; + +export const CoreRPC = (env: ENV) => { + const baseinfuraURL = { + prod: 'https://mainnet.infura.io/v3/', + dev: 'https://sepolia.infura.io/v3/', + staging: 'https://sepolia.infura.io/v3/', + local: 'https://sepolia.infura.io/v3/', + }; + return `${baseinfuraURL[env]}${infuraAPIKey}`; }; const TESTNET_NETWORK = { @@ -140,8 +145,6 @@ export const allowedNetworks = { export const BLOCKNATIVE_PROJECT_ID = '64a44a0fb537407bfe97d24330e4109c'; -export const InfuraAPIKey = '150f25623ae64d08ab7ec7dd0c6b6ee9'; - export const PUBLIC_GOOGLE_TOKEN = 'AIzaSyBhUBnCia6zpxY7KcqjghRS1IphinAvKXs'; export const ProfilePicture = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAvklEQVR4AcXBsW2FMBiF0Y8r3GQb6jeBxRauYRpo4yGQkMd4A7kg7Z/GUfSKe8703fKDkTATZsJsrr0RlZSJ9r4RLayMvLmJjnQS1d6IhJkwE2bT13U/DBzp5BN73xgRZsJMmM1HOolqb/yWiWpvjJSUiRZWopIykTATZsJs5g+1N6KSMiO1N/5DmAkzYTa9Lh6MhJkwE2ZzSZlo7xvRwson3txERzqJhJkwE2bT6+JhoKTMJ2pvjAgzYSbMfgDlXixqjH6gRgAAAABJRU5ErkJggg==`; diff --git a/packages/uiweb/src/lib/context/chatContext.ts b/packages/uiweb/src/lib/context/chatContext.ts index 444904949..6313604ff 100644 --- a/packages/uiweb/src/lib/context/chatContext.ts +++ b/packages/uiweb/src/lib/context/chatContext.ts @@ -25,6 +25,7 @@ export interface IChatDataContextValues { isPushChatStreamConnected: boolean; setIsPushChatStreamConnected: React.Dispatch>; toast: any; + infuraAPIKey: string | null; uiConfig: { suppressToast?: boolean; }; @@ -88,6 +89,7 @@ export const initialChatDataContextValues: IChatDataContextValues = { uiConfig: { suppressToast: false, }, + infuraAPIKey: null, chatStream: {}, chatAcceptStream: {}, chatRejectStream: {}, diff --git a/packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx b/packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx index 967de57f0..e5d6d1445 100644 --- a/packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx +++ b/packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx @@ -16,7 +16,7 @@ import usePushUser from '../hooks/usePushUser'; // Internal Configs import { lightChatTheme } from '../components/chat/theme'; import { ThemeContext } from '../components/chat/theme/ThemeProvider'; -import { Constants, ENV, GUEST_MODE_ACCOUNT } from '../config'; +import { Constants, ENV, GUEST_MODE_ACCOUNT, infuraAPIKey as infuraProjectId } from '../config'; // Assets @@ -48,6 +48,7 @@ export interface IChatUIProviderProps { uiConfig?: { suppressToast?: boolean; }; + infuraAPIKey?: string; } // Exported Functions @@ -61,6 +62,7 @@ export const ChatUIProvider = ({ theme, debug = false, uiConfig = {}, + infuraAPIKey = infuraProjectId, }: IChatUIProviderProps) => { // Now destructure with a default value for suppressToast const { suppressToast = false } = uiConfig; @@ -452,6 +454,7 @@ export const ChatUIProvider = ({ setIsPushChatStreamConnected, user: pushUser, setUser: setPushUser, + infuraAPIKey: infuraAPIKey, toast: toastify, uiConfig: uiConfig, chatStream, diff --git a/packages/uiweb/src/lib/dataProviders/Web3OnboardDataProvider.tsx b/packages/uiweb/src/lib/dataProviders/Web3OnboardDataProvider.tsx index 0e1997857..b57892736 100644 --- a/packages/uiweb/src/lib/dataProviders/Web3OnboardDataProvider.tsx +++ b/packages/uiweb/src/lib/dataProviders/Web3OnboardDataProvider.tsx @@ -1,6 +1,6 @@ import coinbaseWalletModule from '@web3-onboard/coinbase'; -import { BLOCKNATIVE_PROJECT_ID, InfuraAPIKey } from '../config'; +import { BLOCKNATIVE_PROJECT_ID, infuraAPIKey } from '../config'; import { Web3OnboardProvider } from '@web3-onboard/react'; import injectedModule, { ProviderLabel } from '@web3-onboard/injected-wallets'; import walletConnectModule from '@web3-onboard/walletconnect'; @@ -30,13 +30,13 @@ const CHAINS: ChainType[] = [ id: '0x1', token: 'ETH', label: 'Ethereum Mainnet', - rpcUrl: `https://mainnet.infura.io/v3/${InfuraAPIKey}`, + rpcUrl: `https://mainnet.infura.io/v3/${infuraAPIKey}`, }, { id: '0xAA36A7', token: 'ETH', label: 'Sepolia', - rpcUrl: `https://sepolia.infura.io/v3/${InfuraAPIKey}`, + rpcUrl: `https://sepolia.infura.io/v3/${infuraAPIKey}`, }, { id: '0x13882', diff --git a/packages/uiweb/src/lib/helpers/address.ts b/packages/uiweb/src/lib/helpers/address.ts index d6c6a2f4f..0b23c82ba 100644 --- a/packages/uiweb/src/lib/helpers/address.ts +++ b/packages/uiweb/src/lib/helpers/address.ts @@ -1,6 +1,6 @@ import { SignerType, CONSTANTS } from '@pushprotocol/restapi'; import { ethers } from 'ethers'; -import { ENV, allowedNetworks } from '../config'; +import { ENV, allowedNetworks, infuraAPIKey } from '../config'; import { createWeb3Name } from '@web3-name-sdk/core'; import { getUdResolverClient } from './udResolver'; diff --git a/packages/uiweb/src/lib/helpers/udResolver.ts b/packages/uiweb/src/lib/helpers/udResolver.ts index cc54d1d57..dda897b1b 100644 --- a/packages/uiweb/src/lib/helpers/udResolver.ts +++ b/packages/uiweb/src/lib/helpers/udResolver.ts @@ -1,7 +1,7 @@ import type { Env } from '@pushprotocol/restapi'; import Resolution from '@unstoppabledomains/resolution'; import { ethers } from 'ethers'; -import { allowedNetworks, InfuraAPIKey, NETWORK_DETAILS } from '../config'; +import { allowedNetworks, infuraAPIKey, NETWORK_DETAILS } from '../config'; export const getUdResolverClient = (env: Env): Resolution | undefined => { try { @@ -14,11 +14,11 @@ export const getUdResolverClient = (env: Env): Resolution | undefined => { locations: { Layer1: { network: 'mainnet', // add config for sepolia once it's supported by UD - provider: new ethers.providers.InfuraProvider(l1ChainId, InfuraAPIKey), + provider: new ethers.providers.InfuraProvider(l1ChainId, infuraAPIKey), }, Layer2: { network: NETWORK_DETAILS[l2ChainId].network, - provider: new ethers.providers.InfuraProvider(l2ChainId, InfuraAPIKey), + provider: new ethers.providers.InfuraProvider(l2ChainId, infuraAPIKey), }, }, }, diff --git a/packages/uiweb/src/lib/hooks/useAccount.ts b/packages/uiweb/src/lib/hooks/useAccount.ts index a37c99647..951aa2c82 100644 --- a/packages/uiweb/src/lib/hooks/useAccount.ts +++ b/packages/uiweb/src/lib/hooks/useAccount.ts @@ -2,12 +2,12 @@ import { Env } from '@pushprotocol/restapi'; import { useConnectWallet, useSetChain } from '@web3-onboard/react'; import { ethers } from 'ethers'; import { useMemo } from 'react'; -import { CoreContractChainId, CoreRPC, GUEST_MODE_ACCOUNT } from '../config'; +import { CoreContractChainId, CoreRPC, ENV, GUEST_MODE_ACCOUNT } from '../config'; interface useAccountParams { - env:Env; + env: Env; } -export const useAccount = ({env}:useAccountParams) => { +export const useAccount = ({ env }: useAccountParams) => { const [{ wallet, connecting }, connect, disconnect, updateBalances, setWalletModules, setPrimaryWallet] = useConnectWallet(); @@ -20,8 +20,17 @@ export const useAccount = ({env}:useAccountParams) => { const switchChain = async (desiredChain: number) => { setChain({ chainId: ethers.utils.hexValue(desiredChain) }); }; + /* + Create a new top level context provider which will hold this provider for the infura calls. + + All the chat specific things will move to top level context. + + All the widget specific things will move to top level context. + */ const provider = useMemo(() => { - return wallet ? new ethers.providers.Web3Provider(wallet.provider, 'any') : new ethers.providers.JsonRpcProvider(CoreRPC[env]); + return wallet + ? new ethers.providers.Web3Provider(wallet.provider, 'any') + : new ethers.providers.JsonRpcProvider(CoreRPC(env)); }, [wallet]); return { @@ -33,7 +42,8 @@ export const useAccount = ({env}:useAccountParams) => { setWalletModules, setPrimaryWallet, provider, - account: wallet && wallet.accounts.length > 0 ? ethers.utils.getAddress(wallet.accounts[0].address) : GUEST_MODE_ACCOUNT, + account: + wallet && wallet.accounts.length > 0 ? ethers.utils.getAddress(wallet.accounts[0].address) : GUEST_MODE_ACCOUNT, chainId: connectedChain ? Number(connectedChain.id) : CoreContractChainId[env], isActive, setChain, @@ -41,4 +51,4 @@ export const useAccount = ({env}:useAccountParams) => { settingChain, chains, }; -}; \ No newline at end of file +}; diff --git a/packages/uiweb/yarn.lock b/packages/uiweb/yarn.lock index 10bc60a3d..9bd0fa00d 100644 --- a/packages/uiweb/yarn.lock +++ b/packages/uiweb/yarn.lock @@ -1,4 +1,3 @@ - # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # yarn lockfile v1 @@ -1862,14 +1861,13 @@ "@walletconnect/window-getters" "^1.0.1" tslib "1.14.1" -"@web3-name-sdk/core@^0.1.15": - version "0.1.18" - resolved "https://registry.yarnpkg.com/@web3-name-sdk/core/-/core-0.1.18.tgz#7155786e5ed2ec4e9f2f220b976bf20d3c6a77b0" - integrity sha512-AmhRf+q9LJI838wClJ6pHAfMYVi4O9FMFvpZubF0bBUE1uMSy5w+p+k2rGTgfVoUbnT5y1d6Negw/omMYiO0lg== +"@web3-name-sdk/core@^0.2.0": + version "0.2.0" + resolved "https://registry.yarnpkg.com/@web3-name-sdk/core/-/core-0.2.0.tgz#4f75731caa275cfda64ec58a485cbcc516fbdb0c" + integrity sha512-A4lqoCTqJwoixTOuPfoX7fR+P/nZ1+aAg3YPa2Y3UxHJnQoAHGc81lBnoCifg0d1TGaR/c701utsT+Od4CQyQQ== dependencies: "@adraffy/ens-normalize" "^1.10.0" "@ensdomains/ens-validation" "^0.1.0" - viem "^1.20" "@web3-onboard/coinbase@^2.2.5": version "2.4.1" @@ -1954,11 +1952,6 @@ resolved "https://registry.yarnpkg.com/@web3-react/types/-/types-6.0.7.tgz#34a6204224467eedc6123abaf55fbb6baeb2809f" integrity sha512-ofGmfDhxmNT1/P/MgVa8IKSkCStFiyvXe+U5tyZurKdrtTDFU+wJ/LxClPDtFerWpczNFPUSrKcuhfPX1sI6+A== -abitype@0.9.8: - version "0.9.8" - resolved "https://registry.yarnpkg.com/abitype/-/abitype-0.9.8.tgz#1f120b6b717459deafd213dfbf3a3dd1bf10ae8c" - integrity sha512-puLifILdm+8sjyss4S+fsUN09obiT1g2YW6CtcQF+QDzxR0euzgEB29MZujC6zMk2a6SVmtttq1fc6+YFA7WYQ== - abitype@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/abitype/-/abitype-1.0.0.tgz#237176dace81d90d018bebf3a45cb42f2a2d9e97" @@ -3033,11 +3026,6 @@ isexe@^2.0.0: resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw== -isows@1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/isows/-/isows-1.0.3.tgz#93c1cf0575daf56e7120bab5c8c448b0809d0d74" - integrity sha512-2cKei4vlmg2cxEjm3wVSqn8pcoRF/LX/wpifuuNquFO4SQmPwarClT+SUCA2lt+l581tTeZIPIZuIDo2jWN1fg== - isows@1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/isows/-/isows-1.0.4.tgz#810cd0d90cc4995c26395d2aa4cfa4037ebdf061" @@ -4466,20 +4454,6 @@ viem@2.12.0: isows "1.0.4" ws "8.13.0" -viem@^1.20: - version "1.21.4" - resolved "https://registry.yarnpkg.com/viem/-/viem-1.21.4.tgz#883760e9222540a5a7e0339809202b45fe6a842d" - integrity sha512-BNVYdSaUjeS2zKQgPs+49e5JKocfo60Ib2yiXOWBT6LuVxY1I/6fFX3waEtpXvL1Xn4qu+BVitVtMh9lyThyhQ== - dependencies: - "@adraffy/ens-normalize" "1.10.0" - "@noble/curves" "1.2.0" - "@noble/hashes" "1.3.2" - "@scure/bip32" "1.3.2" - "@scure/bip39" "1.2.1" - abitype "0.9.8" - isows "1.0.3" - ws "8.13.0" - webidl-conversions@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"