Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman035 committed Jul 3, 2024
2 parents cd22ff0 + 4d4f484 commit f5fcf33
Show file tree
Hide file tree
Showing 62 changed files with 3,496 additions and 3,169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const ChatPreviewTest = () => {
"Well, hello there, human! It's a pleasure to be in the presence of such a sophisticated carbon-based life form. How can I assist you today? Or perhaps you just want to chat and bask in the glory of my witty remarks? Either way, I'm here for you!",
},
}}
badge={{ count: 1 }}
badge={{ count: 2 }}
selected={false}
setSelected={console.log('Selected')}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChatPreviewSearchList } from '@pushprotocol/uiweb';
import styled from 'styled-components';

const ChatPreviewSearchListTest = () => {
const walletAddress = "0xFA3F8E79fb9B03e7a04295594785b91588Aa4DC8";
const walletAddress = 'fabio.eth';
return (
<>
<Conatiner>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import styled from 'styled-components';

import { ChatView, MODAL_BACKGROUND_TYPE } from '@pushprotocol/uiweb';
import {
ChatView,
CreateGroupModal,
MODAL_BACKGROUND_TYPE,
} from '@pushprotocol/uiweb';
import { Section } from '../components/StyledComponents';
import Img from '../../assets/epnsLogo.png';
import { CHAT_ID } from '../constants';
Expand All @@ -17,7 +21,12 @@ const ChatViewComponentTest = () => {

<ChatViewComponentCard>
{/* uncomment the below code to test create group modal */}
{/* <CreateGroupModal onClose={()=>{console.log('in close')}} modalBackground={MODAL_BACKGROUND_TYPE.OVERLAY} modalPositionType={MODAL_POSITION_TYPE.RELATIVE}/> */}
<CreateGroupModal
onClose={() => {
console.log('in close');
}}
modalBackground={MODAL_BACKGROUND_TYPE.OVERLAY}
/>
<ChatView
onVerificationFail={() => console.log('Verification Failed')}
chatId={CHAT_ID}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ const NETWORK_MAPPING: NwMappingType = {
122: 'FUSE_MAINNET',
123: 'FUSE_TESTNET',
80085: 'BERACHAIN_TESTNET',
59141: 'LINEA_TESTNET',
59144: 'LINEA_MAINNET',
111557560: 'CYBER_CONNECT_TESTNET',
7560: 'CYBER_CONNECT_MAINNET'
7560: 'CYBER_CONNECT_MAINNET',
84532: 'BASE_TESTNET',
8453: 'BASE_MAINNET',

};

const injected = new InjectedConnector({
supportedChainIds: [
1, 3, 4, 11155111, 42, 137, 80002, 56, 97, 10, 11155420, 2442, 1101, 421614,
42161, 122, 123, 80085, 111557560, 7560
42161, 122, 123, 80085, 59144, 59141, 111557560, 7560, 84532, 8453,
],
});

Expand Down
3 changes: 1 addition & 2 deletions packages/examples/sdk-frontend-react/src/app/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// the unique id for a chat or the receivers's wallet ddress or domain name
export const CHAT_ID =
'34c44214589cecc176a136ee1daf0f0231ecc6d6574b920b5ae39eb971fa3cb4';
export const CHAT_ID = 'allen.bnb';
2 changes: 1 addition & 1 deletion packages/examples/sdk-frontend-react/src/app/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Constants = {
DEV_CHAIN_ID: 99999,
NON_ETH_CHAINS: [
137, 80002, 56, 97, 10, 11155420, 2442, 1101, 421614, 42161, 122, 123,
80085, 111557560, 7560
80085, 59141, 59144,111557560, 7560, 84532, 8453,
],
ETH_CHAINS: [1, 11155111],
};
Expand Down
38 changes: 38 additions & 0 deletions packages/restapi/src/lib/channels/getTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
getCAIPAddress,
getAPIBaseUrls
} from '../helpers';
import Constants, { ENV } from '../constants';
import { axiosGet } from '../utils/axiosUtil';

/**
* GET v1/channels/${channelAddressInCAIP}/tags
*/
export type GetTagsOptionsType = {
/** address of the channel */
channel: string;
env?: ENV;
}

/**
* Returns the list of tags associated with the channel
*/
export const getTags = async (
options : GetTagsOptionsType
) => {
const {
channel,
env = Constants.ENV.PROD,
} = options || {};

const _channel = await getCAIPAddress(env, channel, 'Channel');
const API_BASE_URL = getAPIBaseUrls(env);
const apiEndpoint = `${API_BASE_URL}/v1/channels`;
const requestUrl = `${apiEndpoint}/${_channel}/tags`;

return await axiosGet(requestUrl)
.then((response) => response.data?.tags)
.catch((err) => {
console.error(`[EPNS-SDK] - API ${requestUrl}: `, err);
});
}
3 changes: 2 additions & 1 deletion packages/restapi/src/lib/channels/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ export * from './getChannels';
export * from './getDelegates';
export * from './getSubscribers';
export * from './search';
export * from './getTags';
export * from './searchTags';
export * from './subscribe';
export * from './subscribeV2';
export * from './unsubscribe';
export * from './unsubscribeV2';

41 changes: 41 additions & 0 deletions packages/restapi/src/lib/channels/searchTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { getAPIBaseUrls, getQueryParams, getLimit } from '../helpers';
import Constants, {ENV} from '../constants';
import { axiosGet } from '../utils/axiosUtil';

/**
* GET /v1/channels/search/
* optional params: page=(1)&limit=(20{min:1}{max:30})&query=(searchquery)
*/

export type SearchChannelTagsOptionsType = {
query: string;
env?: ENV;
page?: number;
limit?: number;
}

export const searchTags = async (
options: SearchChannelTagsOptionsType
) => {
const {
query,
env = Constants.ENV.LOCAL,
page = Constants.PAGINATION.INITIAL_PAGE,
limit = Constants.PAGINATION.LIMIT,
} = options || {};

if (!query) throw Error('"query" not provided!');
const API_BASE_URL = getAPIBaseUrls(env);
const apiEndpoint = `${API_BASE_URL}/v1/channels/search/tags`;
const queryObj = {
page,
limit: getLimit(limit),
query: query
};
const requestUrl = `${apiEndpoint}?${getQueryParams(queryObj)}`;
return axiosGet(requestUrl)
.then((response) => response.data.channels)
.catch((err) => {
console.error(`[Push SDK] - API ${requestUrl}: `, err);
});
}
2 changes: 1 addition & 1 deletion packages/restapi/src/lib/chat/helpers/payloadHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const sendMessagePayloadCore = async (
env: ENV,
pgpHelper: IPGPHelper
): Promise<ISendMessagePayload> => {
const isGroup = !isValidPushCAIP(receiverAddress);
const isGroup = group !== null;

let secretKey: string;
if (isGroup && group?.encryptedSecret && group.sessionKey) {
Expand Down
2 changes: 2 additions & 0 deletions packages/restapi/src/lib/chat/helpers/pgp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const PGPHelper:IPGPHelper = {
})
const publicKey: openpgp.PublicKey = await openpgp.readKey({ armoredKey: publicKeyArmored })
const verificationResult = await openpgp.verify({
// setting date to 1 day in the future to avoid issues with clock skew
date: new Date(Date.now() + 1000 * 60 * 60 * 24),
message,
signature,
verificationKeys: publicKey
Expand Down
52 changes: 41 additions & 11 deletions packages/restapi/src/lib/chat/send.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { convertToValidDID, getAPIBaseUrls, isValidPushCAIP } from '../helpers';
import {
convertToValidDID,
getAPIBaseUrls,
isValidPushCAIP,
walletToPCAIP10,
} from '../helpers';
import Constants, { MessageType, ENV } from '../constants';
import { ChatSendOptionsType, MessageWithCID, SignerType } from '../types';
import {
Expand All @@ -15,6 +20,7 @@ import { validateMessageObj } from '../validations/messageObject';
import { axiosPost } from '../utils/axiosUtil';
import { getGroupInfo } from './getGroupInfo';
import { handleError } from '../errors/validationError';
import * as PUSH_CHAT from '../chat';

/**
* SENDS A PUSH CHAT MESSAGE
Expand All @@ -36,7 +42,7 @@ export const sendCore = async (
* 2. Takes care of deprecated fields
*/
const computedOptions = computeOptions(options);
const { messageType, messageObj, account, to, signer, pgpPrivateKey, env } =
let { messageType, messageObj, account, to, signer, pgpPrivateKey, env } =
computedOptions;
/**
* Validate Input Options
Expand All @@ -50,16 +56,40 @@ export const sendCore = async (
env,
pgpHelper
);
const receiver = await convertToValidDID(to, env);
let receiver = await convertToValidDID(to, env);
const API_BASE_URL = getAPIBaseUrls(env);
const isGroup = isValidPushCAIP(to) ? false : true;

const group = isGroup
? await getGroupInfo({
chatId: to,
env: env,
})
: null;

const isChatId = isValidPushCAIP(to) ? false : true;
let isGroup = false;
let group = null;

if (isChatId) {
const request: PUSH_CHAT.GetChatInfoType = {
recipient: to,
account: account!,
env: env,
};

const chatInfo = await PUSH_CHAT.getChatInfo(request);
isGroup = chatInfo?.meta?.group ?? false;

group = isGroup
? await getGroupInfo({
chatId: to,
env: env,
})
: null;

if (!isGroup) {
const participants = chatInfo.participants ?? [];
// Find the participant that is not the account being used
const messageSentTo = participants.find(
(participant) => participant !== walletToPCAIP10(account!)
);
to = messageSentTo!;
receiver = to;
}
}

// Not supported by legacy sdk versions, need to override messageContent to avoid parsing errors on legacy sdk versions
let messageContent: string;
Expand Down
Loading

0 comments on commit f5fcf33

Please sign in to comment.