Skip to content

Commit

Permalink
chore: update save setting to api call
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashshah committed Oct 19, 2023
1 parent f7b6ece commit 508c7a4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@mui/lab": "^5.0.0-alpha.72",
"@mui/material": "^5.5.0",
"@pushprotocol/ledgerlive": "latest",
"@pushprotocol/restapi": "0.0.1-alpha.50",
"@pushprotocol/restapi": "1.4.27",
"@pushprotocol/socket": "latest",
"@pushprotocol/uiweb": "0.0.1-alpha.21",
"@reduxjs/toolkit": "^1.7.1",
Expand Down
55 changes: 28 additions & 27 deletions src/components/channel/NotificationSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// React + Web3 Essentials
import React, { useEffect, useMemo } from 'react';
import { ethers } from 'ethers';
import React, { useContext, useEffect, useMemo } from 'react';

// External Packages
import 'react-dropdown/style.css';
Expand All @@ -19,13 +18,15 @@ import { AddSettingButton } from './ChannelButtons';
import ChannelInfoList from './ChannelInfoList';
import DepositFeeFooter from './DepositFeeFooter';
import { useAccount } from 'hooks';
import { AppContext } from 'contexts/AppContext';

// Internal Configs
import { appConfig } from 'config';
import useModalBlur, { MODAL_POSITION } from 'hooks/useModalBlur';
import { ChannelSetting } from 'helpers/channel/types';
import { getChannel } from 'services';
import { updateChannelSetting } from 'redux/slices/channelSlice';
import { NotificationSetting } from '@pushprotocol/restapi/src/lib/pushNotification/PushNotificationTypes';

// Constants
const CORE_CHAIN_ID = appConfig.coreContractChain;
Expand All @@ -47,6 +48,8 @@ function NotificationSettings() {
const [isLoading, setIsLoading] = React.useState(false);
const [isLoadingSettings, setIsLoadingSettings] = React.useState(true);

const { userPushSDKInstance } = useContext(AppContext);

const {
isModalOpen: isAddSettingModalOpen,
showModal: showAddSettingModal,
Expand Down Expand Up @@ -128,36 +131,31 @@ function NotificationSettings() {
try {
setIsLoading(true);

const feesRequiredForEdit = 50;
const parsedFees = ethers.utils.parseUnits(feesRequiredForEdit.toString(), 18);

notificationToast.showLoaderToast({ loaderMessage: 'Waiting for Confirmation...' });
const notifOptions = settings.length;
let _notifSettings = '';
let _notifDescription = '';
settings.forEach((setting) => {
if (_notifSettings !== '') _notifSettings += '+';
if (_notifDescription !== '') _notifDescription += '+';
const settingData: NotificationSetting[] = settings.map((setting) => {
if (setting.type === 1) {
_notifSettings += `${setting.type}-${setting.default ? '1' : '0'}`;
} else if (setting.type === 2) {
_notifSettings += `${setting.type}-${setting.enabled ? '1' : '0'}-${setting.default}-${setting.lowerLimit}-${
setting.upperLimit
}-${setting.ticker}`;
return {
type: setting.type,
description: setting.description,
default: setting.default ? 1 : 0,
};
}
if (setting.type === 2) {
return {
type: setting.type,
description: setting.description,
default: setting.default,
data: {
lower: setting.lowerLimit,
upper: setting.upperLimit,
ticker: setting.ticker,
enabled: setting.enabled,
},
};
}
_notifDescription += setting.description;
});
await userPushSDKInstance.channel.setting(settingData);

const tx = await epnsWriteProvider.createChannelSettings(
notifOptions,
_notifSettings,
_notifDescription,
parsedFees,
{ gasLimit: 1000000 }
);

console.log(tx);
await tx.wait();
dispatch(updateChannelSetting({ channelAddress, settings }));
setIsLoading(false);

Expand All @@ -172,6 +170,9 @@ function NotificationSettings() {
/>
),
});

// Go back to channel dashboard
setTimeout(() => goBack(), 2000);
} catch (err) {
setIsLoading(false);
if (err.code == 'ACTION_REJECTED') {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5423,7 +5423,7 @@ __metadata:
"@mui/lab": ^5.0.0-alpha.72
"@mui/material": ^5.5.0
"@pushprotocol/ledgerlive": latest
"@pushprotocol/restapi": 0.0.1-alpha.50
"@pushprotocol/restapi": 1.4.27
"@pushprotocol/socket": latest
"@pushprotocol/uiweb": 0.0.1-alpha.21
"@reduxjs/toolkit": ^1.7.1
Expand Down Expand Up @@ -5625,9 +5625,9 @@ __metadata:
languageName: node
linkType: hard

"@pushprotocol/restapi@npm:0.0.1-alpha.50":
version: 0.0.1-alpha.50
resolution: "@pushprotocol/restapi@npm:0.0.1-alpha.50"
"@pushprotocol/restapi@npm:1.4.27":
version: 1.4.27
resolution: "@pushprotocol/restapi@npm:1.4.27"
dependencies:
"@ambire/signature-validator": ^1.3.1
"@metamask/eth-sig-util": ^5.0.2
Expand All @@ -5648,7 +5648,7 @@ __metadata:
viem: ^1.3.0
peerDependencies:
ethers: ^5.6.8
checksum: 47d5edc46102cbc33b2873ed603be55fe834b19474e63ce7d68b1e7a0980d32bba0c06bf0dfcfbf7eca74bef85e8479213e59bfe87cbe05099d7f775dc3c7540
checksum: 5f171e9ecaad780684fbae1cf624bfb7f464c0979a070ed102113ab26053d3780f5e36b59a6a99d661c251f8a71ede44132dbb45b8a2fe6191a48b8a164629d0
languageName: node
linkType: hard

Expand Down

0 comments on commit 508c7a4

Please sign in to comment.