Skip to content

Commit

Permalink
fix: added support for ens (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
pritipsingh authored Jan 15, 2024
1 parent 3a8218e commit 8e2cec9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ChatSupportTest = () => {
<SupportChat

signer={librarySigner}
supportAddress="0x6269C363695c5E14447a1b3873d7Ae4Ddf6E6eF7"
supportAddress="fabio.eth"
apiKey="tAWEnggQ9Z.UaDBNjrvlJZx3giBTIQDcT8bKQo1O1518uF1Tea7rPwfzXv2ouV5rX9ViwgJUrXm"
env={env}
greetingMsg="How can i help you?"
Expand Down
9 changes: 7 additions & 2 deletions packages/uiweb/src/lib/components/supportChat/AddressInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import React, { useContext, useEffect, useState } from 'react';
import styled from 'styled-components';
import { SupportChatPropsContext } from '../../context';
import { Constants } from '../../config';
import { copyToClipboard, pCAIP10ToWallet } from '../../helpers';
import { Constants, InfuraAPIKey, allowedNetworks } from '../../config';
import { copyToClipboard, pCAIP10ToWallet, resolveNewEns } from '../../helpers';
import { CopySvg } from '../../icons/CopySvg';
import { ethers } from 'ethers';

export const AddressInfo: React.FC = () => {
const { supportAddress, env, theme, pushUser } = useContext<any>(SupportChatPropsContext);
const [ensName, setEnsName] = useState<string>('');
const [user, setUser] = useState<any>({});
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);

useEffect(() => {
const getUser = async () => {
if(pushUser){
const user = await pushUser.info();
const ensNameResult = await resolveNewEns(supportAddress, provider)
setEnsName(ensNameResult!)
setUser(user);
}

Expand Down
20 changes: 17 additions & 3 deletions packages/uiweb/src/lib/components/supportChat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PushAPI } from '@pushprotocol/restapi';
import { ChatIcon } from '../../icons/ChatIcon';
import { Modal } from './Modal';
import styled from 'styled-components';
import { handleOnChatIconClick } from '../../helpers';
import { getAddress, handleOnChatIconClick } from '../../helpers';
import {
SupportChatMainStateContext,
SupportChatPropsContext,
Expand All @@ -16,6 +16,7 @@ import { useSDKSocket } from '../../hooks/useSDKSocket';
import { Div } from '../reusables/sharedStyling';
import { getAddressFromSigner } from '../../helpers';
import { sign } from 'crypto';

export type ChatProps = {
account?: string;
signer: SignerType;
Expand Down Expand Up @@ -50,6 +51,7 @@ export type ButtonStyleProps = {
const [chats, setChats] = useState<IMessageIPFS[]>([]);
const [accountadd, setAccountadd] = useState<string | null>(account)
const [pushUser, setPushUser] = useState<PushAPI | null>(null);
const [resolvedSupportAddress, setResolvedSupportAddress] = useState<string>('');
const setChatsSorted = (chats: IMessageIPFS[]) => {

const chatsWithNumericTimestamps = chats.map(item => ({
Expand All @@ -72,7 +74,7 @@ export type ButtonStyleProps = {
env,
apiKey,
pushUser: pushUser!,
supportAddress,
supportAddress: resolvedSupportAddress,
signer
});

Expand All @@ -81,14 +83,26 @@ export type ButtonStyleProps = {
account : accountadd,
signer,
pushUser,
supportAddress,
supportAddress : resolvedSupportAddress,
greetingMsg,
modalTitle,
theme: { ...lightTheme, ...theme },
apiKey,
env,
};

useEffect(() => {

const getNewSupportAddress = async() => {
if(supportAddress.includes(".")){
const newAddress = await getAddress(supportAddress, env)
setResolvedSupportAddress(newAddress!);
}else{
setResolvedSupportAddress(supportAddress);
}
}
getNewSupportAddress();
},[supportAddress, pushUser, env])


useEffect(() => {
Expand Down

0 comments on commit 8e2cec9

Please sign in to comment.