Skip to content

Commit

Permalink
fix: renamed Spam.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
hrithik73 committed Mar 14, 2024
1 parent d743436 commit 5c4809d
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 91 deletions.
15 changes: 9 additions & 6 deletions src/segments/Spambox.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
// React + Web3 Essentials
import React from "react";
import React from 'react';

// External Packages
import styled from "styled-components";
import styled from 'styled-components';

// Internal components
import SpamBox from "segments/spam";
import SpamBox from 'segments/Spam';

// Create Header
function Spambox(props) {

// Render
return (
<FullWidth>
<SpamBox showFilter={props.showFilter} setShowFilter={props.setShowFilter} search={props.search}
setSearch={props.setSearch} />
<SpamBox
showFilter={props.showFilter}
setShowFilter={props.setShowFilter}
search={props.search}
setSearch={props.setSearch}
/>
</FullWidth>
);
}
Expand Down
170 changes: 85 additions & 85 deletions src/segments/spam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { toast as toaster } from 'react-toastify';
import { useClickAway } from 'react-use';
import { Waypoint } from 'react-waypoint';
import styled, { ThemeProvider, useTheme } from 'styled-components';
import { MdCheckCircle, MdError } from "react-icons/md";
import { MdCheckCircle, MdError } from 'react-icons/md';

// Internal Components
import * as PushAPI from '@pushprotocol/restapi';
Expand All @@ -20,7 +20,7 @@ import {
addPaginatedNotifications,
incrementPage,
setFinishedFetching,
updateTopNotifications
updateTopNotifications,
} from 'redux/slices/spamSlice';
import SearchFilter from '../components/SearchFilter';
import DisplayNotice from '../primaries/DisplayNotice';
Expand All @@ -31,7 +31,7 @@ import { ScrollItem } from './ViewChannels';
import { useAccount } from 'hooks';

// Internal Configs
import { appConfig } from "config";
import { appConfig } from 'config';
import { device } from 'config/Globals';
import { AppContext } from 'contexts/AppContext';

Expand All @@ -43,7 +43,7 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
const dispatch = useDispatch();
const { userPushSDKInstance } = useSelector((state: any) => {
return state.user;
});
});
const modalRef = React.useRef(null);
useClickAway(modalRef, () => showFilter && setShowFilter(false));
const { account, chainId, provider } = useAccount();
Expand All @@ -63,7 +63,7 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
const EPNS_DOMAIN = {
name: 'EPNS COMM V1',
chainId: chainId,
verifyingContract: epnsCommReadProvider?.address
verifyingContract: epnsCommReadProvider?.address,
};
const [allNotif, setNotif] = React.useState([]);
const [loadFilter, setLoadFilter] = React.useState(false);
Expand Down Expand Up @@ -94,7 +94,7 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
ETH_TEST_GOERLI: 5,
ETH_TEST_SEPOLIA: 11155111,
POLYGON_MAINNET: 137,
ETH_MAINNET: 1
ETH_MAINNET: 1,
};

const reset = () => setFilter(false);
Expand All @@ -109,7 +109,7 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
endDate = endDate.getTime() / 1000;
var Filter = {
channels: channels,
date: { lowDate: startDate, highDate: endDate }
date: { lowDate: startDate, highDate: endDate },
};
if (channels.length == 0) delete Filter.channels;

Expand Down Expand Up @@ -149,7 +149,7 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
const results = await userPushSDKInstance.notification.list('SPAM', {
limit: NOTIFICATIONS_PER_PAGE,
page: page,
raw: true
raw: true,
});
let parsedResponse = PushAPI.utils.parseApiResponse(results);
parsedResponse.forEach((each, i) => {
Expand Down Expand Up @@ -191,7 +191,7 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
const results = await userPushSDKInstance.notification.list('SPAM', {
limit: NOTIFICATIONS_PER_PAGE,
page: 1,
raw: true
raw: true,
});
if (!notifications.length) {
dispatch(incrementPage());
Expand Down Expand Up @@ -239,7 +239,7 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
const results = await userPushSDKInstance.notification.list('SPAM', {
limit: 100000,
page: 1,
raw: true
raw: true,
});

if (!notifications.length) {
Expand Down Expand Up @@ -270,7 +270,7 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
dispatch(
updateTopNotifications({
notifs: res,
pageSize: NOTIFICATIONS_PER_PAGE
pageSize: NOTIFICATIONS_PER_PAGE,
})
);
setNotif(res);
Expand All @@ -295,8 +295,6 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
}
}, [epnsCommReadProvider, account]);



//function to query more notifications
const handlePagination = async () => {
loadNotifications();
Expand All @@ -312,43 +310,51 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
if (!channelAddress) return;
let address = channelAddress;



if (!address) return;
console.debug(address);
subscribeToast.showLoaderToast({loaderMessage: "Waiting for Confirmation..."});
subscribeToast.showLoaderToast({ loaderMessage: 'Waiting for Confirmation...' });
console.debug(provider, account);
const _signer = await provider.getSigner(account);
console.debug(_signer);
console.debug({
signer: _signer,
channelAddress: convertAddressToAddrCaip(channelAddress, nameToId[blockchain]), // channel address in CAIP
userAddress: convertAddressToAddrCaip(account, chainId), // user address in CAIP
})
});
await PushAPI.channels.subscribe({
signer: _signer,
channelAddress: convertAddressToAddrCaip(channelAddress, chainId), // channel address in CAIP
userAddress: convertAddressToAddrCaip(account, chainId), // user address in CAIP
onSuccess: () => {
subscribeToast.showMessageToast({
toastTitle:"Success",
toastMessage: "Successfully opted into channel !",
toastType: "SUCCESS",
getToastIcon: (size) => <MdCheckCircle size={size} color="green" />
})
toastTitle: 'Success',
toastMessage: 'Successfully opted into channel !',
toastType: 'SUCCESS',
getToastIcon: (size) => (
<MdCheckCircle
size={size}
color="green"
/>
),
});
dispatch(updateSubscriptionStatus({ channelAddress: channelAddress, status: true }));
},
onError: (err) => {
console.error(err);
subscribeToast.showMessageToast({
toastTitle:"Error",
toastMessage: `There was an error opting into channel`,
toastType: "ERROR",
getToastIcon: (size) => <MdError size={size} color="red" />
})
toastTitle: 'Error',
toastMessage: `There was an error opting into channel`,
toastType: 'ERROR',
getToastIcon: (size) => (
<MdError
size={size}
color="red"
/>
),
});
},
env: appConfig.pushNodesEnv
})
env: appConfig.pushNodesEnv,
});
};

const isSubscribedFn = (channel: string) => {
Expand Down Expand Up @@ -384,7 +390,7 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined
progress: undefined,
});
} else if (error.code === -32601) {
console.error(error);
Expand All @@ -396,7 +402,7 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined
progress: undefined,
});
} else {
console.error(error);
Expand All @@ -408,7 +414,7 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined
progress: undefined,
});
}
}
Expand All @@ -432,59 +438,53 @@ const SpamBox = ({ showFilter, setShowFilter, search, setSearch }) => {
/>
</div>
<ScrollItem>
{notifications && (
<Items id="scrollstyle-secondary">
{bgUpdateLoading && (
<Item padding="10px 20px">
<LoaderSpinner type={LOADER_TYPE.SEAMLESS} />
</Item>
)}
{(filter && !run ? filteredNotifications : allNotif).map((oneNotification, index) => {
const {
cta,
title,
message,
app,
icon,
image,
secret,
notification,
channel,
blockchain,
url
} = oneNotification;
// render the notification item
return (
<NotifsOuter key={index}>
{showWayPoint(index) && !loading && <Waypoint onEnter={handlePagination} />}
<NotificationItem
notificationTitle={title}
notificationBody={message}
cta={cta}
app={app}
icon={icon}
image={image}
theme={themes.scheme}
subscribeFn={() => onSubscribeToChannel(channel, blockchain)}
isSpam
isSubscribedFn={async () => isSubscribedFn(channel)}
isSecret={secret != ''}
decryptFn={() => onDecrypt({ secret, title, message, image, cta })}
chainName={blockchain}
url={url}
/>
</NotifsOuter>
);
})}
{loading && !bgUpdateLoading && <LoaderSpinner type={LOADER_TYPE.SEAMLESS} />}
</Items>
)}
{(!notifications.length || (filter && !filteredNotifications.length)) && !loading && (
<CenteredContainerInfo>
<DisplayNotice title="You currently have no spam notifications." />
</CenteredContainerInfo>
)}
{toast && <NotificationToast notification={toast} clearToast={clearToast} />}
{notifications && (
<Items id="scrollstyle-secondary">
{bgUpdateLoading && (
<Item padding="10px 20px">
<LoaderSpinner type={LOADER_TYPE.SEAMLESS} />
</Item>
)}
{(filter && !run ? filteredNotifications : allNotif).map((oneNotification, index) => {
const { cta, title, message, app, icon, image, secret, notification, channel, blockchain, url } =
oneNotification;
// render the notification item
return (
<NotifsOuter key={index}>
{showWayPoint(index) && !loading && <Waypoint onEnter={handlePagination} />}
<NotificationItem
notificationTitle={title}
notificationBody={message}
cta={cta}
app={app}
icon={icon}
image={image}
theme={themes.scheme}
subscribeFn={() => onSubscribeToChannel(channel, blockchain)}
isSpam
isSubscribedFn={async () => isSubscribedFn(channel)}
isSecret={secret != ''}
decryptFn={() => onDecrypt({ secret, title, message, image, cta })}
chainName={blockchain}
url={url}
/>
</NotifsOuter>
);
})}
{loading && !bgUpdateLoading && <LoaderSpinner type={LOADER_TYPE.SEAMLESS} />}
</Items>
)}
{(!notifications.length || (filter && !filteredNotifications.length)) && !loading && (
<CenteredContainerInfo>
<DisplayNotice title="You currently have no spam notifications." />
</CenteredContainerInfo>
)}
{toast && (
<NotificationToast
notification={toast}
clearToast={clearToast}
/>
)}
</ScrollItem>
</Container>
</ThemeProvider>
Expand Down

0 comments on commit 5c4809d

Please sign in to comment.