Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating alpha with main #1413

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
517 changes: 241 additions & 276 deletions packages/restapi/yarn.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { useChatData } from '../../../hooks';
import { Button, Div, Image, Section } from '../../reusables';

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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 27 additions & 3 deletions packages/uiweb/src/lib/components/chat/CreateGroup/AddCriteria.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import PolygonSvg from '../../../icons/polygon.svg';
import ArbitrumSvg from '../../../icons/arbitrum.svg';
import BSCSvg from '../../../icons/bsc.svg';
import FuseSvg from '../../../icons/fuse.svg';
import BaseSvg from '../../../icons/base.svg';
import LineaSvg from '../../../icons/linea.svg';
import CyberConnectSvg from '../../../icons/cyberconnect.svg';

import OptimismSvg from '../../../icons/optimisim.svg';
import { BLOCKCHAIN_NETWORK, ENV, device } from '../../../config';
Expand Down Expand Up @@ -243,14 +246,35 @@ const AddCriteria = ({ handlePrevious, onClose, criteriaStateManager }: ModalHea
icon: FuseSvg,
function: () => setSelectedChainValue(5),
},
{
id: 6,
value: BLOCKCHAIN_NETWORK[env].CYBER_CONNECT,
title: 'Cyber',
icon: CyberConnectSvg,
function: () => setSelectedChainValue(6),
},
{
id: 7,
value: BLOCKCHAIN_NETWORK[env].BASE,
title: 'Base',
icon: BaseSvg,
function: () => setSelectedChainValue(7),
},
{
id: 8,
value: BLOCKCHAIN_NETWORK[env].LINEA,
title: 'Linea',
icon: LineaSvg,
function: () => setSelectedChainValue(8),
},
];
if (env !== ENV.PROD) {
dropdownChainsValues.push({
id: 6,
id: 9,
value: BLOCKCHAIN_NETWORK[env].BERACHAIN,
title: 'Berachain',
icon: BerachainSvg,
function: () => setSelectedChainValue(6),
function: () => setSelectedChainValue(9),
} as DropdownValueType);
}
console.debug(dropdownChainsValues);
Expand Down Expand Up @@ -392,7 +416,7 @@ const AddCriteria = ({ handlePrevious, onClose, criteriaStateManager }: ModalHea
setDecimals,
selectedChainValue,
dropdownChainsValues,
tokenId: Number(tokenId)
tokenId: Number(tokenId),
});
}, 2000);
return () => clearTimeout(getData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -33,7 +33,7 @@ export const UserProfile: React.FC<UserProfileProps> = ({
updateUserProfileModalBackground = MODAL_BACKGROUND_TYPE.OVERLAY,
updateUserProfileModalPositionType = MODAL_POSITION_TYPE.GLOBAL,
onUserProfileUpdateModalOpen,
closeUserProfileModalOnClickAway = false
closeUserProfileModalOnClickAway = false,
}) => {
const { user } = useChatData();
const [userProfile, setUserProfile] = useState<IUser>();
Expand Down Expand Up @@ -157,7 +157,7 @@ export const UserProfile: React.FC<UserProfileProps> = ({
};

//styles
const Conatiner = styled(Section) <IThemeProps>`
const Conatiner = styled(Section)<IThemeProps>`
border: ${(props) => props.theme.border?.userProfile};
box-sizing: border-box;
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions packages/uiweb/src/lib/components/supportChat/AddressInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -19,7 +19,7 @@ export const AddressInfo: React.FC = () => {
const [isCopied, setIsCopied] = useState<boolean>(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 () => {
Expand Down
19 changes: 12 additions & 7 deletions packages/uiweb/src/lib/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -62,6 +67,7 @@ const TESTNET_NETWORK = {
BERACHAIN: 'eip155:80085',
CYBER_CONNECT: 'eip155:111557560',
BASE: 'eip155:84532',
LINEA: 'eip155:59141'
};
const MAINET_NETWORK = {
ETHEREUM: 'eip155:1',
Expand All @@ -73,6 +79,7 @@ const MAINET_NETWORK = {
FUSE: 'eip155:122',
CYBER_CONNECT: 'eip155:7560',
BASE: 'eip155:8453',
LINEA: 'eip155:59144'
};

export const BLOCKCHAIN_NETWORK = {
Expand Down Expand Up @@ -138,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==`;
Expand Down
2 changes: 2 additions & 0 deletions packages/uiweb/src/lib/context/chatContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface IChatDataContextValues {
isPushChatStreamConnected: boolean;
setIsPushChatStreamConnected: React.Dispatch<React.SetStateAction<boolean>>;
toast: any;
infuraAPIKey: string | null;
uiConfig: {
suppressToast?: boolean;
};
Expand Down Expand Up @@ -88,6 +89,7 @@ export const initialChatDataContextValues: IChatDataContextValues = {
uiConfig: {
suppressToast: false,
},
infuraAPIKey: null,
chatStream: {},
chatAcceptStream: {},
chatRejectStream: {},
Expand Down
5 changes: 4 additions & 1 deletion packages/uiweb/src/lib/dataProviders/ChatDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -48,6 +48,7 @@ export interface IChatUIProviderProps {
uiConfig?: {
suppressToast?: boolean;
};
infuraAPIKey?: string;
}

// Exported Functions
Expand All @@ -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;
Expand Down Expand Up @@ -452,6 +454,7 @@ export const ChatUIProvider = ({
setIsPushChatStreamConnected,
user: pushUser,
setUser: setPushUser,
infuraAPIKey: infuraAPIKey,
toast: toastify,
uiConfig: uiConfig,
chatStream,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/uiweb/src/lib/helpers/address.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
6 changes: 3 additions & 3 deletions packages/uiweb/src/lib/helpers/udResolver.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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),
},
},
},
Expand Down
22 changes: 16 additions & 6 deletions packages/uiweb/src/lib/hooks/useAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 {
Expand All @@ -33,12 +42,13 @@ 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,
switchChain,
settingChain,
chains,
};
};
};
Loading
Loading