From 4f1d065c65c59a258dc793bbe9c0cd82c46b4dd8 Mon Sep 17 00:00:00 2001 From: Nilesh Gupta Date: Wed, 27 Mar 2024 15:25:48 +0530 Subject: [PATCH 01/12] Enabled browser notif feature again --- src/App.tsx | 3 + src/api/index.js | 38 +++-- src/config/config-dev.js | 153 +++++++++--------- src/config/config-prod.js | 100 ++++++------ src/config/config-staging.js | 151 ++++++++--------- src/firebase.js | 42 +++-- src/helpers/CaipHelper.ts | 13 +- src/helpers/RoutesHelper.ts | 25 +-- src/hooks/useBrowserNotification.ts | 61 ++++--- src/services/deliveryNode/index.ts | 1 + .../deliveryNode/registerDeviceToken.ts | 26 +++ src/services/index.ts | 11 +- 12 files changed, 335 insertions(+), 289 deletions(-) create mode 100644 src/services/deliveryNode/index.ts create mode 100644 src/services/deliveryNode/registerDeviceToken.ts diff --git a/src/App.tsx b/src/App.tsx index 37e02c7b06..66c8aabb1e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -30,6 +30,7 @@ import AppLogin from './AppLogin'; import { SectionV2 } from './components/reusables/SharedStylingV2'; import { ErrorContext } from './contexts/ErrorContext'; import { setIndex, setRun, setWelcomeNotifsEmpty } from './redux/slices/userJourneySlice'; +import { useBrowserNotification } from 'hooks/useBrowserNotification'; // Internal Configs import { appConfig } from 'config'; @@ -145,6 +146,8 @@ export default function App() { setcurrentTime(now); }, []); + useBrowserNotification(); + useEffect(() => { if (!account) return; dispatch(resetSpamSlice()); diff --git a/src/api/index.js b/src/api/index.js index 6d911e1092..99c3c1f361 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -1,12 +1,13 @@ // External Packages -import axios from "axios"; +import axios from 'axios'; // Internal Configs -import { appConfig } from "config"; +import { appConfig } from 'config'; // Constants -const BASE_URL = appConfig.apiUrl -const TOOLING_BASE_URL = appConfig.toolingApiUrl +const BASE_URL = appConfig.apiUrl; +const TOOLING_BASE_URL = appConfig.toolingApiUrl; +const DELIVERY_NODE_BASE_URL = appConfig.deliveryNodeApiUrl; /** * A function used to make get requests throughout the entire application @@ -14,13 +15,13 @@ const TOOLING_BASE_URL = appConfig.toolingApiUrl * @returns {Promise} */ export const getReq = async (path) => { - try { - const response = await axios.get(BASE_URL + path); - return response; - } catch (error) { - throw error; - } - }; + try { + const response = await axios.get(BASE_URL + path); + return response; + } catch (error) { + throw error; + } +}; /** * A function used to make post requests to the backend @@ -55,5 +56,18 @@ export const toolingPostReq = async (path, obj) => { } }; -export * from './ipfs'; +export const deliveryNodePostReq = async (path, obj) => { + try { + const response = await axios.post(DELIVERY_NODE_BASE_URL + path, obj, { + headers: { + 'Content-Type': 'application/json', + }, + }); + return response; + } catch (error) { + console.error(error.response.data); + throw error.response.data; + } +}; +export * from './ipfs'; diff --git a/src/config/config-dev.js b/src/config/config-dev.js index b7be278a0b..898b1f0be0 100644 --- a/src/config/config-dev.js +++ b/src/config/config-dev.js @@ -1,11 +1,11 @@ // environmental configurations for the dapp for different environments export const config = { - /** + /** * Push Nodes Environment - can be dev, staging or prod - important to keep one on one connection */ pushNodesEnv: 'dev', - - /** + + /** * API Calls Related */ appEnv: 'dev', @@ -14,11 +14,12 @@ export const config = { apiUrl: 'https://backend-dev.epns.io/apis', w2wApiUrl: 'https://backend-dev.epns.io/apis', toolingApiUrl: 'https://tooling.epns.io/apis', + deliveryNodeApiUrl: 'https://delivery-dev.epns.io/apis', ipfsInfuraAPIKey: process.env.REACT_APP_IPFS_INFURA_API_KEY || '22rfiNb1J645FdehoqbKMpLbF6V', ipfsInfuraAPISecret: process.env.REACT_APP_IPFS_INFURA_API_SECRET || 'a757597f020425c3ae532e6be84de552', - /** + /** * Allowed Networks */ allowedNetworks: [ @@ -29,26 +30,26 @@ export const config = { 420, // optimism goerli testnet 1442, // polygon zkevm testnet 421613, // arbitrum testnet - 123 // fuse testnet + 123, // fuse testnet ], - /** + /** * Core Network Related Data */ coreContractChain: 11155111, //the chain id of the network which the core contract relies on - coreRPC: 'https://sepolia.infura.io/v3/5524d420b29f4f7a8d8d2f582a0d43f7', - mainnetCoreRPC: "https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a", + coreRPC: 'https://sepolia.infura.io/v3/fffaf09bf68e4c4e8f8c5dcfc9383295', + mainnetCoreRPC: 'https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a', mainnetCoreContractChain: 1, aliasRPC: { - 80001: "https://polygon-mumbai.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9", - 97: "https://data-seed-prebsc-1-s1.binance.org:8545", - 420: "https://opt-goerli.g.alchemy.com/v2/98vFj7OCg4vbGKvCDpj6pOAMSBVC7rzm", - 1442: "https://rpc.public.zkevm-test.net", - 421613: "https://goerli-rollup.arbitrum.io/rpc" + 80001: 'https://polygon-mumbai.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9', + 97: 'https://data-seed-prebsc-1-s1.binance.org:8545', + 420: 'https://opt-goerli.g.alchemy.com/v2/98vFj7OCg4vbGKvCDpj6pOAMSBVC7rzm', + 1442: 'https://rpc.public.zkevm-test.net', + 421613: 'https://goerli-rollup.arbitrum.io/rpc', }, infuraApiUrl: 'https:/infura-ipfs.io/ipfs/', - /** + /** * Analaytics + Firebase */ googleAnalyticsId: 'UA-165415629-5', @@ -64,7 +65,7 @@ export const config = { measurementId: 'G-ZJH2T7R9S1', }, - /** + /** * External links */ links: { @@ -73,109 +74,105 @@ export const config = { extension: 'https://chrome.google.com/webstore/detail/epns-staging-protocol-alp/bjiennpmhdcandkpigcploafccldlakj', howto: 'https://push.org/docs', }, -} +}; /** * Smart Contract Related */ export const addresses = { - ceaErc20: "0xc1C0472c0C80bCcDC7F5D01A376Bd97a734B8815", - epnscore: "0x5AB1520E2bd519BDab2e1347EEe81C00a77f4946", - epnsEthComm: "0x9dDCD7ed7151afab43044E4D694FA064742C428c", - epnsPolyComm: "0xAf55BE8e6b0d6107891bA76eADeEa032ef8A4504", // the ploygon comm contract - pushToken: "0x37c779a1564DCc0e3914aB130e0e787d93e21804", //address for push token - pushChannelAdmin: "0xfA47d7EaEC85eE8db2cBFF7d18AC407d1A556Dc2", - aDai: "0x31f30d9A5627eAfeC4433Ae2886Cf6cc3D25E772", - epnsToken: "0x37c779a1564DCc0e3914aB130e0e787d93e21804", - epnsLPToken: "0x1f094Bd8c260D0C3fC79157096015990885af4d2", - rockstar: "0x3f8C2152b79276b78315CAF66cCF951780580A8a", - batchMintNFT: "0xCf733D547B9f7F87c1B1f63f45c197C007F8eedf", - NFTRewards: "0xc4708BB6EC3B797344f123126171302e4e3E68E2", - distributor: "0x5B548D33874DeABaC2F683A6E1864795E09932F0", - rockstarV2: "0xA2b885e7065EA59a3251489715ca80DE5Ff642f8", //mainnet address - NFTRewardsV2: "0xdc66567a990B7fa10730459537620857c9e03287", //mainnet address + ceaErc20: '0xc1C0472c0C80bCcDC7F5D01A376Bd97a734B8815', + epnscore: '0x5AB1520E2bd519BDab2e1347EEe81C00a77f4946', + epnsEthComm: '0x9dDCD7ed7151afab43044E4D694FA064742C428c', + epnsPolyComm: '0xAf55BE8e6b0d6107891bA76eADeEa032ef8A4504', // the ploygon comm contract + pushToken: '0x37c779a1564DCc0e3914aB130e0e787d93e21804', //address for push token + pushChannelAdmin: '0xfA47d7EaEC85eE8db2cBFF7d18AC407d1A556Dc2', + aDai: '0x31f30d9A5627eAfeC4433Ae2886Cf6cc3D25E772', + epnsToken: '0x37c779a1564DCc0e3914aB130e0e787d93e21804', + epnsLPToken: '0x1f094Bd8c260D0C3fC79157096015990885af4d2', + rockstar: '0x3f8C2152b79276b78315CAF66cCF951780580A8a', + batchMintNFT: '0xCf733D547B9f7F87c1B1f63f45c197C007F8eedf', + NFTRewards: '0xc4708BB6EC3B797344f123126171302e4e3E68E2', + distributor: '0x5B548D33874DeABaC2F683A6E1864795E09932F0', + rockstarV2: '0xA2b885e7065EA59a3251489715ca80DE5Ff642f8', //mainnet address + NFTRewardsV2: '0xdc66567a990B7fa10730459537620857c9e03287', //mainnet address //For Yield Farm V1(Deprecated) - staking: "0xAECb9074e222e8F06f8034140A3F86610E4d3c3E", // deprecated staking addresses - depYieldFarmPUSH: "0x6EA019f7FE2640A55154DdC36Bfd21275De388BD", // deprecated YieldFarm Push address - depYieldFarmLP:"0xc2886D0e7DAd16cc92b1156Dc9A0b0D3F047FD15", + staking: '0xAECb9074e222e8F06f8034140A3F86610E4d3c3E', // deprecated staking addresses + depYieldFarmPUSH: '0x6EA019f7FE2640A55154DdC36Bfd21275De388BD', // deprecated YieldFarm Push address + depYieldFarmLP: '0xc2886D0e7DAd16cc92b1156Dc9A0b0D3F047FD15', - pushToken: "0x37c779a1564DCc0e3914aB130e0e787d93e21804", + pushToken: '0x37c779a1564DCc0e3914aB130e0e787d93e21804', // For Sepolia - pushToken: "0x37c779a1564DCc0e3914aB130e0e787d93e21804", + pushToken: '0x37c779a1564DCc0e3914aB130e0e787d93e21804', // pushCoreV2: "0x8a965286c0752DFE821868312025091f60BD902A", // 15 min epoch - pushCoreV2: "0x5AB1520E2bd519BDab2e1347EEe81C00a77f4946", //21 days epoch - uniV2LPToken: "0x2333609Cc527a9309Cdad16E0742a3C6DC1C551b", - uniswapV2Router02: "0xC532a74256D3Db42D0Bf7a0400fEFDbad7694008", - WETHAddress: "0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9", - USDTAddress: "0x7169D38820dfd117C3FA1f22a697dBA58d90BA06", + pushCoreV2: '0x5AB1520E2bd519BDab2e1347EEe81C00a77f4946', //21 days epoch + uniV2LPToken: '0x2333609Cc527a9309Cdad16E0742a3C6DC1C551b', + uniswapV2Router02: '0xC532a74256D3Db42D0Bf7a0400fEFDbad7694008', + WETHAddress: '0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9', + USDTAddress: '0x7169D38820dfd117C3FA1f22a697dBA58d90BA06', //For 30 mins epoch // stakingV2: "0xCa02F3FdF3794aF08CADb98b0E4504261cB8c302", // yieldFarmLP: "0x22C1dBC8975c23De9e2219C0fC3E03b404577512", //For 21 days Epoch - stakingV2: "0xFf13FBc1dE7FBF300059FE56495c82bBa2F986c6", - yieldFarmLP: "0xAB531bD9D39c492a05de65Eee85F6C712c05ea0b", - - - - alphaAccessNft: "0x39f77Db4d5d3e85c213233D5Af02C46a85Cf1Db4" + stakingV2: '0xFf13FBc1dE7FBF300059FE56495c82bBa2F986c6', + yieldFarmLP: '0xAB531bD9D39c492a05de65Eee85F6C712c05ea0b', - -} + alphaAccessNft: '0x39f77Db4d5d3e85c213233D5Af02C46a85Cf1Db4', +}; export const CHAIN_DETAILS = { 11155111: { - label: "Ethereum Sepolia", - name: "ETH_TEST_SEPOLIA", + label: 'Ethereum Sepolia', + name: 'ETH_TEST_SEPOLIA', chainId: 11155111, - rpcUrl: "https://sepolia.infura.io/v3/5524d420b29f4f7a8d8d2f582a0d43f7", - commAddress: "0x28709649Dfda9baDEbb61dBF7a8D199cfC8EcF2e", - network: "sepolia", - }, + rpcUrl: 'https://sepolia.infura.io/v3/5524d420b29f4f7a8d8d2f582a0d43f7', + commAddress: '0x28709649Dfda9baDEbb61dBF7a8D199cfC8EcF2e', + network: 'sepolia', + }, 80001: { - label: "Polygon Mumbai", - name: "POLYGON_TEST_MUMBAI", + label: 'Polygon Mumbai', + name: 'POLYGON_TEST_MUMBAI', chainId: 80001, - rpcUrl: "https://polygon-mumbai.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9", - commAddress: "0xAf55BE8e6b0d6107891bA76eADeEa032ef8A4504", - network: "polygon-mumbai", + rpcUrl: 'https://polygon-mumbai.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9', + commAddress: '0xAf55BE8e6b0d6107891bA76eADeEa032ef8A4504', + network: 'polygon-mumbai', }, 97: { - label: "BNB Testnet", - name: "BNB_TESTNET", + label: 'BNB Testnet', + name: 'BNB_TESTNET', chainId: 97, - rpcUrl: "https://data-seed-prebsc-1-s1.binance.org:8545", - commAddress: "0x4132061E3349ff36cFfCadA460E10Bd4f31F7ea8" + rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545', + commAddress: '0x4132061E3349ff36cFfCadA460E10Bd4f31F7ea8', }, 420: { - label: "Optimism Goerli", - name: "OPTIMISM_TESTNET", + label: 'Optimism Goerli', + name: 'OPTIMISM_TESTNET', chainId: 420, rpcUrl: 'https://opt-goerli.g.alchemy.com/v2/98vFj7OCg4vbGKvCDpj6pOAMSBVC7rzm', - commAddress: '0x4305D572F2bf38Fc2AE8D0172055b1EFd18F57a6' + commAddress: '0x4305D572F2bf38Fc2AE8D0172055b1EFd18F57a6', }, 1442: { - label: "Polygon zkEVM Testnet", - name: "POLYGON_ZK_EVM_TESTNET", + label: 'Polygon zkEVM Testnet', + name: 'POLYGON_ZK_EVM_TESTNET', chainId: 1442, rpcUrl: 'https://rpc.public.zkevm-test.net', - commAddress: '0x630b152e4185c63D7177c656b56b26f878C61572' + commAddress: '0x630b152e4185c63D7177c656b56b26f878C61572', }, 421613: { - label: "Arbitrum Testnet", - name: "ARBITRUM_TESTNET", + label: 'Arbitrum Testnet', + name: 'ARBITRUM_TESTNET', chainId: 421613, rpcUrl: '', - commAddress: '0x2f6aE0907116A2c50D712e78b48D874fadeB6850' + commAddress: '0x2f6aE0907116A2c50D712e78b48D874fadeB6850', }, 123: { - label: "Fuse Testnet", - name: "FUSE_TESTNET", + label: 'Fuse Testnet', + name: 'FUSE_TESTNET', chainId: 123, rpcUrl: 'https://rpc.fusespark.io', - commAddress: '0x7eBb54D86CF928115965DB596a3E600404dD8039' - } -} \ No newline at end of file + commAddress: '0x7eBb54D86CF928115965DB596a3E600404dD8039', + }, +}; diff --git a/src/config/config-prod.js b/src/config/config-prod.js index 7f3e885b32..caf8031f1d 100644 --- a/src/config/config-prod.js +++ b/src/config/config-prod.js @@ -14,6 +14,7 @@ export const config = { apiUrl: 'https://backend.epns.io/apis', w2wApiUrl: 'https://backend.epns.io/apis', toolingApiUrl: 'https://tooling.epns.io/apis', + deliveryNodeApiUrl: 'https://delivery-prod.epns.io/apis', ipfsInfuraAPIKey: process.env.REACT_APP_IPFS_INFURA_API_KEY || '22rfiNb1J645FdehoqbKMpLbF6V', ipfsInfuraAPISecret: process.env.REACT_APP_IPFS_INFURA_API_SECRET || 'a757597f020425c3ae532e6be84de552', @@ -39,10 +40,10 @@ export const config = { mainnetCoreRPC: 'https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a', mainnetCoreContractChain: 1, aliasRPC: { - 137: "https://polygon-mainnet.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9", - 56: "https://bsc-dataseed.binance.org/", - 10: "https://opt-mainnet.g.alchemy.com/v2/JYW0UaSC5Zd0hrI6vE2K9VN1wJupoY5B", - 42161: "https://arb1.arbitrum.io/rpc", + 137: 'https://polygon-mainnet.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9', + 56: 'https://bsc-dataseed.binance.org/', + 10: 'https://opt-mainnet.g.alchemy.com/v2/JYW0UaSC5Zd0hrI6vE2K9VN1wJupoY5B', + 42161: 'https://arb1.arbitrum.io/rpc', 1101: 'https://rpc.polygon-zkevm.gateway.fm', }, infuraApiUrl: 'https:/infura-ipfs.io/ipfs/', @@ -53,14 +54,14 @@ export const config = { googleAnalyticsId: 'UA-165415629-1', vapidKey: 'BFRmmAEEXOhk31FIsooph5CxlXKh6N0_NocUWHzvtpoUEvqQTwLXu6XtwkrH7ckyr2CvVz1ll-8q4oo6-ZqFJPY', firebaseConfig: { - apiKey: 'AIzaSyClOk4qP0ttFW-BPnXy7WT920xfdXSbFu8', - authDomain: 'epns-internal.firebaseapp.com', - databaseURL: 'https://epns-internal.firebaseio.com', - projectId: 'epns-internal', - storageBucket: 'epns-internal.appspot.com', - messagingSenderId: '755180533582', - appId: '1:755180533582:web:752ff8db31905506b7d01f', - measurementId: 'G-ZJH2T7R9S1', + apiKey: 'AIzaSyBrzkFPyNmVDFzGY7dKz2HocUO4m-ni-Fc', + authDomain: 'epns-ethereum-push-service.firebaseapp.com', + databaseURL: 'https://epns-ethereum-push-service.firebaseio.com', + projectId: 'epns-ethereum-push-service', + storageBucket: 'epns-ethereum-push-service.appspot.com', + messagingSenderId: '915758146133', + appId: '1:915758146133:web:2de388356233f5c22f2adc', + measurementId: 'G-X1L5P2E4EP', }, /** @@ -83,7 +84,7 @@ export const addresses = { epnsEthComm: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', // mainnet address eth comm epnsPolyComm: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', // mainnet address polygon comm pushToken: '0xf418588522d5dd018b425E472991E52EBBeEEEEE', // mainnet address - pushChannelAdmin: "0x65193c896eC400f731712D4f71046CeDd11Bff27", // mainnet push core admin + pushChannelAdmin: '0x65193c896eC400f731712D4f71046CeDd11Bff27', // mainnet push core admin aDai: '0xcB1Fe6F440c49E9290c3eb7f158534c2dC374201', // mainnet address staking: '0xB72ff1e675117beDefF05a7D0a472c3844cfec85', // mainnet address yieldFarmPUSH: '0x6019B84E2eE9EB62BC42E32AB6375A7095886366', // mainnet address @@ -101,70 +102,69 @@ export const addresses = { NFTRewardsV2: '0xdc66567a990B7fa10730459537620857c9e03287', //mainnet address //For Yield Farm V1(Deprecated) - staking: "0xB72ff1e675117beDefF05a7D0a472c3844cfec85", // deprecated staking mainnet addresses - depYieldFarmPUSH: "0x6019B84E2eE9EB62BC42E32AB6375A7095886366", // deprecated YieldFarmPUSH mainnet address - depYieldFarmLP:"0xbB2A70e67770D0A7F5f42d883C5BBE9b85e0DcD6",// deprecated YieldFarmLP mainnet addresses + staking: '0xB72ff1e675117beDefF05a7D0a472c3844cfec85', // deprecated staking mainnet addresses + depYieldFarmPUSH: '0x6019B84E2eE9EB62BC42E32AB6375A7095886366', // deprecated YieldFarmPUSH mainnet address + depYieldFarmLP: '0xbB2A70e67770D0A7F5f42d883C5BBE9b85e0DcD6', // deprecated YieldFarmLP mainnet addresses //For Yield Farm V2 - stakingV2:"0x9D2513F5b539DC774C66b28ACEc94e4bD00105C2",//mainnet address - yieldFarmLP: "0x9af118D9fA1eFEa5b5a792847554960217DEdb04",//mainnet address - uniV2LPToken: "0xaf31fd9c3b0350424bf96e551d2d1264d8466205",//same as epnsLPToken - pushCoreV2: "0x66329Fdd4042928BfCAB60b179e1538D56eeeeeE",//not upgraded - - alphaAccessNft: "0x87d34d40EFaF2d594A7eD9B1126F15Cb3fc721ef" + stakingV2: '0x9D2513F5b539DC774C66b28ACEc94e4bD00105C2', //mainnet address + yieldFarmLP: '0x9af118D9fA1eFEa5b5a792847554960217DEdb04', //mainnet address + uniV2LPToken: '0xaf31fd9c3b0350424bf96e551d2d1264d8466205', //same as epnsLPToken + pushCoreV2: '0x66329Fdd4042928BfCAB60b179e1538D56eeeeeE', //not upgraded + alphaAccessNft: '0x87d34d40EFaF2d594A7eD9B1126F15Cb3fc721ef', }; export const CHAIN_DETAILS = { 1: { - label: "Ethereum Mainnet", - name: "ETH_MAINNET", + label: 'Ethereum Mainnet', + name: 'ETH_MAINNET', chainId: 1, - rpcUrl: "https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a", - commAddress: "0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa", - network: "mainnet", - }, + rpcUrl: 'https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a', + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', + network: 'mainnet', + }, 137: { - label: "Polygon Mainnet", - name: "POLYGON_MAINNET", + label: 'Polygon Mainnet', + name: 'POLYGON_MAINNET', chainId: 137, - rpcUrl: "https://polygon-mainnet.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9", - commAddress: "0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa", - network: "polygon-mainnet", + rpcUrl: 'https://polygon-mainnet.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9', + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', + network: 'polygon-mainnet', }, 56: { - label: "BNB Mainnet", - name: "BNB_MAINNET", + label: 'BNB Mainnet', + name: 'BNB_MAINNET', chainId: 56, - rpcUrl: "https://bsc-dataseed.binance.org/", - commAddress: "0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa" + rpcUrl: 'https://bsc-dataseed.binance.org/', + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, 10: { - label: "Optimism Mainnet", - name: "OPTIMISM_MAINNET", + label: 'Optimism Mainnet', + name: 'OPTIMISM_MAINNET', chainId: 10, rpcUrl: 'https://opt-mainnet.g.alchemy.com/v2/JYW0UaSC5Zd0hrI6vE2K9VN1wJupoY5B', - commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa' + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, 1101: { - label: "Polygon zkEVM Mainnet", - name: "POLYGON_ZK_EVM_MAINNET", + label: 'Polygon zkEVM Mainnet', + name: 'POLYGON_ZK_EVM_MAINNET', chainId: 1101, rpcUrl: 'https://rpc.polygon-zkevm.gateway.fm', - commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa' + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, 42161: { - label: "Arbitrum Mainnet", - name: "ARBITRUMONE_MAINNET", + label: 'Arbitrum Mainnet', + name: 'ARBITRUMONE_MAINNET', chainId: 42161, rpcUrl: 'https://arb1.arbitrum.io/rpc', - commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa' + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, 122: { - label: "Fuse Mainnet", - name: "FUSE_MAINNET", + label: 'Fuse Mainnet', + name: 'FUSE_MAINNET', chainId: 122, rpcUrl: 'https://rpc.fuse.io', - commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa' + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, -} \ No newline at end of file +}; diff --git a/src/config/config-staging.js b/src/config/config-staging.js index d9b3f57b60..09bda73c34 100644 --- a/src/config/config-staging.js +++ b/src/config/config-staging.js @@ -1,24 +1,25 @@ // environmental configurations for the dapp for different environments export const config = { - /** + /** * Push Nodes Environment - can be dev, staging or prod - important to keep one on one connection */ pushNodesEnv: 'staging', - - /** + + /** * API Calls Related */ appEnv: 'staging', // helps in deciding some text, links, etc, DO NOT CHANGE - + pushNodeApiVersion: 1, apiUrl: 'https://backend-staging.epns.io/apis', w2wApiUrl: 'https://backend-staging.epns.io/apis', toolingApiUrl: 'https://staging-tooling.epns.io/apis', + deliveryNodeApiUrl: 'https://delivery-staging.epns.io/apis', ipfsInfuraAPIKey: process.env.REACT_APP_IPFS_INFURA_API_KEY || '22rfiNb1J645FdehoqbKMpLbF6V', ipfsInfuraAPISecret: process.env.REACT_APP_IPFS_INFURA_API_SECRET || 'a757597f020425c3ae532e6be84de552', - /** + /** * Allowed Networks */ allowedNetworks: [ @@ -30,26 +31,26 @@ export const config = { 420, // optimism goerli testnet 1442, // polygon zkevm testnet 421613, // arbitrum testnet - 123 // fuse testnet + 123, // fuse testnet ], - /** + /** * Core Network Related Data */ coreContractChain: 11155111, //the chain id of the network which the core contract relies on - coreRPC: 'https://sepolia.infura.io/v3/49f638cc25a94ddb86b7aefd612f11ab', - mainnetCoreRPC: "https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a", + coreRPC: 'https://sepolia.infura.io/v3/5524d420b29f4f7a8d8d2f582a0d43f7', + mainnetCoreRPC: 'https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a', mainnetCoreContractChain: 1, aliasRPC: { - 80001: "https://polygon-mumbai.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9", - 97: "https://data-seed-prebsc-1-s1.binance.org:8545", - 420: "https://opt-goerli.g.alchemy.com/v2/98vFj7OCg4vbGKvCDpj6pOAMSBVC7rzm", - 1442: "https://rpc.public.zkevm-test.net", - 421613: "https://goerli-rollup.arbitrum.io/rpc" + 80001: 'https://polygon-mumbai.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9', + 97: 'https://data-seed-prebsc-1-s1.binance.org:8545', + 420: 'https://opt-goerli.g.alchemy.com/v2/98vFj7OCg4vbGKvCDpj6pOAMSBVC7rzm', + 1442: 'https://rpc.public.zkevm-test.net', + 421613: 'https://goerli-rollup.arbitrum.io/rpc', }, infuraApiUrl: 'https:/infura-ipfs.io/ipfs/', - /** + /** * Analaytics + Firebase */ googleAnalyticsId: 'UA-165415629-5', @@ -65,7 +66,7 @@ export const config = { measurementId: 'G-ZJH2T7R9S1', }, - /** + /** * External links */ links: { @@ -74,100 +75,100 @@ export const config = { extension: 'https://chrome.google.com/webstore/detail/epns-staging-protocol-alp/bjiennpmhdcandkpigcploafccldlakj', howto: 'https://push.org/docs', }, -} +}; /** * Smart Contract Related */ export const addresses = { - ceaErc20: "0xc1C0472c0C80bCcDC7F5D01A376Bd97a734B8815", - epnscore: "0x9d65129223451fbd58fc299c635cd919baf2564c", - epnsEthComm: "0x0c34d54a09cfe75bccd878a469206ae77e0fe6e7", // the core contract - epnsPolyComm: "0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa", // the ploygon comm contract - pushToken: "0x37c779a1564DCc0e3914aB130e0e787d93e21804", //address for push token - aDai: "0x31f30d9A5627eAfeC4433Ae2886Cf6cc3D25E772", - pushChannelAdmin: "0x0c97B7B7D14FBBfe726bF85c992db02E8E7D0fC6", + ceaErc20: '0xc1C0472c0C80bCcDC7F5D01A376Bd97a734B8815', + epnscore: '0x9d65129223451fbd58fc299c635cd919baf2564c', + epnsEthComm: '0x0c34d54a09cfe75bccd878a469206ae77e0fe6e7', // the core contract + epnsPolyComm: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', // the ploygon comm contract + pushToken: '0x37c779a1564DCc0e3914aB130e0e787d93e21804', //address for push token + aDai: '0x31f30d9A5627eAfeC4433Ae2886Cf6cc3D25E772', + pushChannelAdmin: '0x0c97B7B7D14FBBfe726bF85c992db02E8E7D0fC6', // staking: "0xAECb9074e222e8F06f8034140A3F86610E4d3c3E", // deprecated staking addresses // yieldFarmPUSH: "0xb41cd6760d3b1d0d216851f63fda9573b04dd46e", // yieldFarmLP: "0x604f629A6b5E85805D57f39493BBC2856cE8A540", - epnsToken: "0x37c779a1564DCc0e3914aB130e0e787d93e21804", - epnsLPToken: "0x1f094Bd8c260D0C3fC79157096015990885af4d2", - uniV2LPToken:"0x698839247E5b83572fFF6ccdcf386CC37e60bEf5",// for new staking V2 Contract on staging - rockstar: "0x3f8C2152b79276b78315CAF66cCF951780580A8a", - batchMintNFT: "0xCf733D547B9f7F87c1B1f63f45c197C007F8eedf", - NFTRewards: "0xc4708BB6EC3B797344f123126171302e4e3E68E2", - distributor: "0x5B548D33874DeABaC2F683A6E1864795E09932F0", - uniswapV2Router02: "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D", - WETHAddress: "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6", - USDTAddress: "0x11fe4b6ae13d2a6055c8d9cf65c55bac32b5d844", - rockstarV2:"0xA2b885e7065EA59a3251489715ca80DE5Ff642f8",//mainnet address - NFTRewardsV2: "0xdc66567a990B7fa10730459537620857c9e03287", //mainnet address + epnsToken: '0x37c779a1564DCc0e3914aB130e0e787d93e21804', + epnsLPToken: '0x1f094Bd8c260D0C3fC79157096015990885af4d2', + uniV2LPToken: '0x698839247E5b83572fFF6ccdcf386CC37e60bEf5', // for new staking V2 Contract on staging + rockstar: '0x3f8C2152b79276b78315CAF66cCF951780580A8a', + batchMintNFT: '0xCf733D547B9f7F87c1B1f63f45c197C007F8eedf', + NFTRewards: '0xc4708BB6EC3B797344f123126171302e4e3E68E2', + distributor: '0x5B548D33874DeABaC2F683A6E1864795E09932F0', + uniswapV2Router02: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D', + WETHAddress: '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', + USDTAddress: '0x11fe4b6ae13d2a6055c8d9cf65c55bac32b5d844', + rockstarV2: '0xA2b885e7065EA59a3251489715ca80DE5Ff642f8', //mainnet address + NFTRewardsV2: '0xdc66567a990B7fa10730459537620857c9e03287', //mainnet address //For Yield Farm v1(deprecated) - staking: "0xAECb9074e222e8F06f8034140A3F86610E4d3c3E", // deprecated staking addresses - depYieldFarmPUSH: "0x6EA019f7FE2640A55154DdC36Bfd21275De388BD", // deprecated YieldFarm Push address - depYieldFarmLP:"0xc2886D0e7DAd16cc92b1156Dc9A0b0D3F047FD15", // deprecated YieldFarm LP address + staking: '0xAECb9074e222e8F06f8034140A3F86610E4d3c3E', // deprecated staking addresses + depYieldFarmPUSH: '0x6EA019f7FE2640A55154DdC36Bfd21275De388BD', // deprecated YieldFarm Push address + depYieldFarmLP: '0xc2886D0e7DAd16cc92b1156Dc9A0b0D3F047FD15', // deprecated YieldFarm LP address //For Yield Farm V2 - stakingV2:"0xA99dE35dce05f59fF87ae393a7576B8Ce5881416", - yieldFarmLP: "0xeE543C5bC1b6EB647CfC23fe95D3C5877945Ad21", - pushCoreV2: "0x9d65129223451fbd58fc299c635cd919baf2564c",//not upgraded - uniV2LPToken: "0x698839247E5b83572fFF6ccdcf386CC37e60bEf5", - pushToken: "0x37c779a1564DCc0e3914aB130e0e787d93e21804", + stakingV2: '0xA99dE35dce05f59fF87ae393a7576B8Ce5881416', + yieldFarmLP: '0xeE543C5bC1b6EB647CfC23fe95D3C5877945Ad21', + pushCoreV2: '0x9d65129223451fbd58fc299c635cd919baf2564c', //not upgraded + uniV2LPToken: '0x698839247E5b83572fFF6ccdcf386CC37e60bEf5', + pushToken: '0x37c779a1564DCc0e3914aB130e0e787d93e21804', - alphaAccessNft: "0x39f77Db4d5d3e85c213233D5Af02C46a85Cf1Db4" -} + alphaAccessNft: '0x39f77Db4d5d3e85c213233D5Af02C46a85Cf1Db4', +}; export const CHAIN_DETAILS = { 11155111: { - label: "Ethereum Sepolia", - name: "ETH_TEST_SEPOLIA", + label: 'Ethereum Sepolia', + name: 'ETH_TEST_SEPOLIA', chainId: 11155111, - rpcUrl: "https://sepolia.infura.io/v3/5524d420b29f4f7a8d8d2f582a0d43f7", - commAddress: "0x0c34d54a09cfe75bccd878a469206ae77e0fe6e7", - network: "sepolia", - }, + rpcUrl: 'https://sepolia.infura.io/v3/5524d420b29f4f7a8d8d2f582a0d43f7', + commAddress: '0x0c34d54a09cfe75bccd878a469206ae77e0fe6e7', + network: 'sepolia', + }, 80001: { - label: "Polygon Mumbai", - name: "POLYGON_TEST_MUMBAI", + label: 'Polygon Mumbai', + name: 'POLYGON_TEST_MUMBAI', chainId: 80001, - rpcUrl: "https://polygon-mumbai.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9", - commAddress: "0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa", - network: "polygon-mumbai", + rpcUrl: 'https://polygon-mumbai.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9', + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', + network: 'polygon-mumbai', }, 97: { - label: "BNB Testnet", - name: "BNB_TESTNET", + label: 'BNB Testnet', + name: 'BNB_TESTNET', chainId: 97, - rpcUrl: "https://data-seed-prebsc-1-s1.binance.org:8545", - commAddress: "0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa" + rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545', + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, 420: { - label: "Optimism Goerli", - name: "OPTIMISM_TESTNET", + label: 'Optimism Goerli', + name: 'OPTIMISM_TESTNET', chainId: 420, rpcUrl: 'https://opt-goerli.g.alchemy.com/v2/98vFj7OCg4vbGKvCDpj6pOAMSBVC7rzm', - commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa' + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, 1442: { - label: "Polygon zkEVM Testnet", - name: "POLYGON_ZK_EVM_TESTNET", + label: 'Polygon zkEVM Testnet', + name: 'POLYGON_ZK_EVM_TESTNET', chainId: 1442, rpcUrl: 'https://rpc.public.zkevm-test.net', - commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa' + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, 421613: { - label: "Arbitrum Testnet", - name: "ARBITRUM_TESTNET", + label: 'Arbitrum Testnet', + name: 'ARBITRUM_TESTNET', chainId: 421613, rpcUrl: '', - commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa' + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, 123: { - label: "Fuse Testnet", - name: "FUSE_TESTNET", + label: 'Fuse Testnet', + name: 'FUSE_TESTNET', chainId: 123, rpcUrl: 'https://rpc.fusespark.io', - commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa' - } -} \ No newline at end of file + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', + }, +}; diff --git a/src/firebase.js b/src/firebase.js index 67f350de4b..3beb51405e 100644 --- a/src/firebase.js +++ b/src/firebase.js @@ -1,17 +1,17 @@ // External Packages -import { initializeApp } from "@firebase/app"; -import { getMessaging, getToken, onMessage } from "@firebase/messaging"; +import { initializeApp } from '@firebase/app'; +import { getMessaging, getToken, onMessage } from '@firebase/messaging'; // Internal Components -import { postReq } from "api"; +import { registerDeviceToken } from './services'; // Internal Configs -import { appConfig } from "config"; +import { appConfig } from 'config'; // Initialize the Firebase app in the service worker by passing the generated config var firebaseConfig = { ...appConfig.firebaseConfig }; -const TOKEN_KEY = "EPNS_BASE_PUSH_TOKEN"; -const CACHEPREFIX = "PUSH_TOKEN_"; +const TOKEN_KEY = 'EPNS_BASE_PUSH_TOKEN'; +const CACHEPREFIX = 'PUSH_TOKEN_'; const firebaseApp = initializeApp(firebaseConfig); const messaging = getMessaging(firebaseApp); @@ -22,7 +22,7 @@ const setLocalToken = (token) => localStorage.setItem(TOKEN_KEY, token); export const getPushToken = async () => { try { let token = getLocalToken(TOKEN_KEY); - if(!token){ + if (!token) { token = await getToken(messaging, { vapidKey: appConfig.vapidKey, }); @@ -30,9 +30,7 @@ export const getPushToken = async () => { } return token; } catch (err) { - console.log('\n\n\n\n') - console.error("An error occurred while retrieving token. ", err); - console.log('\n\n\n\n') + console.error('An error occurred while retrieving token. ', err); } }; @@ -41,25 +39,23 @@ export const onMessageListener = () => onMessage(messaging, (payload) => { resolve(payload); }); -}); + }); -export const browserFunction = async(account)=>{ - try{ +export const browserFunction = async (account) => { + try { const tokenKey = `${CACHEPREFIX}${account}`; const tokenExists = localStorage.getItem(tokenKey) || localStorage.getItem(CACHEPREFIX); //temp to prevent more than 1 account to register if (!tokenExists) { const response = await getPushToken(); - const object = { - op: 'register', - wallet: account.toLowerCase(), - device_token: response, - platform: 'dapp', - }; - await postReq('/pushtokens/_register_no_auth', object); + + await registerDeviceToken({ + token: response, + account: account, + }); localStorage.setItem(tokenKey, response); localStorage.setItem(CACHEPREFIX, 'response'); //temp to prevent more than 1 account to register } - }catch(e){ - console.error("Error setting up the browser notification",e); + } catch (e) { + console.error('Error setting up the browser notification', e); } -} +}; diff --git a/src/helpers/CaipHelper.ts b/src/helpers/CaipHelper.ts index 3f177da32e..d50632201d 100644 --- a/src/helpers/CaipHelper.ts +++ b/src/helpers/CaipHelper.ts @@ -1,7 +1,9 @@ // Internal Configs import { appConfig } from '../config'; -export const Eip155EnabledIds: Array = [1, 56, 137, 10, 1101, 42161, 11155111, 97, 80001, 420, 1442, 421613, 122, 123]; +export const Eip155EnabledIds: Array = [ + 1, 56, 137, 10, 1101, 42161, 11155111, 97, 80001, 420, 1442, 421613, 122, 123, +]; // Types type CAIPProps = { @@ -32,13 +34,14 @@ export const getCAIP = (chainId: number): string | null => { } }; -export const convertAddressToAddrCaip = ( - userAddress: string, - chainId: number -): string => { +export const convertAddressToAddrCaip = (userAddress: string, chainId: number): string => { return `eip155:${chainId}:${userAddress}`; }; +export const convertAddressToPartialCaip = (userAddress: string): string => { + return `eip155:${userAddress}`; +}; + export const convertAddrCaipToAddress = (addressInCaip: string): string => { const caipArr: string[] = addressInCaip.split(':'); if (caipArr.length == 3 && caipArr[0] == 'eip155') { diff --git a/src/helpers/RoutesHelper.ts b/src/helpers/RoutesHelper.ts index 8511838dfa..8b93386b9c 100644 --- a/src/helpers/RoutesHelper.ts +++ b/src/helpers/RoutesHelper.ts @@ -1,23 +1,28 @@ // Internal Configs -import { appConfig } from "../config"; +import { appConfig } from '../config'; // Constants const apiVersion: number = appConfig.pushNodeApiVersion; const channelsRoute: string = `/v${apiVersion}/channels`; const usersRoute: string = `/v${apiVersion}/users`; const ipfsRoute: string = `/v${apiVersion}/ipfs`; +const deliveryNodeRoute: string = `/v${apiVersion}`; export const usersServiceEndpoints = { - userSubscriptions: (userAddressInCAIP: string):string => `${usersRoute}/${userAddressInCAIP}/subscriptions`, - userDelegations: (userAddressInCAIP: string):string => `${usersRoute}/${userAddressInCAIP}/delegations` -} + userSubscriptions: (userAddressInCAIP: string): string => `${usersRoute}/${userAddressInCAIP}/subscriptions`, + userDelegations: (userAddressInCAIP: string): string => `${usersRoute}/${userAddressInCAIP}/delegations`, +}; export const channelsServiceEndpoints = { - channelsInfo: (queryParams?: string):string => `${channelsRoute}?${queryParams}`, - channelsSearch: (queryParams: string):string => `${channelsRoute}/search?${queryParams}`, - channelDelegates: (channelAddressInCAIP: string):string => `${channelsRoute}/${channelAddressInCAIP}/delegates` -} + channelsInfo: (queryParams?: string): string => `${channelsRoute}?${queryParams}`, + channelsSearch: (queryParams: string): string => `${channelsRoute}/search?${queryParams}`, + channelDelegates: (channelAddressInCAIP: string): string => `${channelsRoute}/${channelAddressInCAIP}/delegates`, +}; export const ipfsServiceEndpoints = { - ipfsUpload: ():string => `${ipfsRoute}/upload` -} \ No newline at end of file + ipfsUpload: (): string => `${ipfsRoute}/upload`, +}; + +export const deliveryNodeServiceEndpoints = { + registerDeviceToken: (): string => `${deliveryNodeRoute}/pushtokens/register`, +}; diff --git a/src/hooks/useBrowserNotification.ts b/src/hooks/useBrowserNotification.ts index b37c524e56..96dbb98707 100644 --- a/src/hooks/useBrowserNotification.ts +++ b/src/hooks/useBrowserNotification.ts @@ -1,35 +1,33 @@ // React + Web3 Essentials -import { useEffect, useState } from 'react'; +import { useContext, useEffect, useState } from 'react'; // External Packages -import { toast } from "react-toastify"; +import { useAccount } from './useAccount'; +import { GlobalContext } from 'contexts/GlobalContext'; -export function useBrowserNotification(account){ - const [triggerNotification, setTriggerNotification] = useState(false); - - useEffect(() => { - if (!("serviceWorker" in navigator)) return - if (!account) return; - (async function () { - const {browserFunction} = require('firebase') - await browserFunction(account); - })(); - }, [account]); - - useEffect(() => { - if (!("serviceWorker" in navigator)) return - const {onMessageListener} = require("firebase") - onMessageListener().then(payload => { - if (!("Notification" in window)) { - toast.dark(`${payload.notification.body} from: ${payload.notification.title}`, { - type: toast.TYPE.DARK, - autoClose: 5000, - position: "top-right" - }); +export function useBrowserNotification() { + const { account } = useAccount(); + const { readOnlyWallet } = useContext(GlobalContext); + const [triggerNotification, setTriggerNotification] = useState(false); + + useEffect(() => { + if (!('serviceWorker' in navigator)) return; + if (!account || account == readOnlyWallet) return; + (async function () { + const { browserFunction } = require('firebase'); + await browserFunction(account); + })(); + }, [account]); + + useEffect(() => { + if (!('serviceWorker' in navigator)) return; + const { onMessageListener } = require('firebase'); + onMessageListener() + .then((payload) => { + if (!('Notification' in window)) { + // useStream handles this case of showing in page notif (if showing notifs is not allowed) } else { - console.info('\n\n\n\n\n') - console.info("revieced push notification") - console.info('\n\n\n\n\n') + console.info('received push notification'); const notificationTitle = payload.notification.title; const notificationOptions = { title: payload.data.app, @@ -42,7 +40,8 @@ export function useBrowserNotification(account){ }; var notification = new Notification(notificationTitle, notificationOptions); } - }).catch(err => console.error('failed: ', err)) - .finally(() => setTriggerNotification(!triggerNotification)); //retrigger the listener after it has been used once - }, [triggerNotification]); - } \ No newline at end of file + }) + .catch((err) => console.error('failed: ', err)) + .finally(() => setTriggerNotification(!triggerNotification)); //retrigger the listener after it has been used once + }, [triggerNotification]); +} diff --git a/src/services/deliveryNode/index.ts b/src/services/deliveryNode/index.ts new file mode 100644 index 0000000000..20d88dba38 --- /dev/null +++ b/src/services/deliveryNode/index.ts @@ -0,0 +1 @@ +export * from './registerDeviceToken'; diff --git a/src/services/deliveryNode/registerDeviceToken.ts b/src/services/deliveryNode/registerDeviceToken.ts new file mode 100644 index 0000000000..449b686932 --- /dev/null +++ b/src/services/deliveryNode/registerDeviceToken.ts @@ -0,0 +1,26 @@ +// Internal Components +import { deliveryNodePostReq } from 'api'; +import { convertAddressToPartialCaip } from 'helpers/CaipHelper'; +import { deliveryNodeServiceEndpoints } from 'helpers/RoutesHelper'; + +// Types +type Props = { + token: string; + account: string; +}; + +export const registerDeviceToken = async ({ token, account }: Props) => { + const reqEndpoint = deliveryNodeServiceEndpoints.registerDeviceToken(); + console.log(reqEndpoint); + try { + const data = { + wallet: convertAddressToPartialCaip(account.toLowerCase()), + device_token: token, + platform: 'web', + }; + const response = await deliveryNodePostReq(reqEndpoint, data); + } catch (err) { + console.error(err); + throw new Error(err.message); + } +}; diff --git a/src/services/index.ts b/src/services/index.ts index 735e68702d..942e78d437 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,5 +1,6 @@ -export * from "./channels"; -export * from "./chats"; -export * from "./ipfs"; -export * from "./users"; -export * from "./alias"; \ No newline at end of file +export * from './channels'; +export * from './chats'; +export * from './ipfs'; +export * from './users'; +export * from './alias'; +export * from './deliveryNode'; From 994c88ef26be38f5c7b140373c9b10e32fdaec0c Mon Sep 17 00:00:00 2001 From: Nilesh Gupta Date: Thu, 28 Mar 2024 16:18:54 +0530 Subject: [PATCH 02/12] Updated firebase project details --- src/config/config-dev.js | 17 ++++++++--------- src/config/config-prod.js | 2 +- src/config/config-staging.js | 2 +- src/firebase.js | 1 + 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/config/config-dev.js b/src/config/config-dev.js index 898b1f0be0..91cf6a700a 100644 --- a/src/config/config-dev.js +++ b/src/config/config-dev.js @@ -53,16 +53,15 @@ export const config = { * Analaytics + Firebase */ googleAnalyticsId: 'UA-165415629-5', - vapidKey: 'BFRmmAEEXOhk31FIsooph5CxlXKh6N0_NocUWHzvtpoUEvqQTwLXu6XtwkrH7ckyr2CvVz1ll-8q4oo6-ZqFJPY', + vapidKey: 'BJYsH1MYRqzfuzduyHLNaUfZCYdAahcJXsdWzdTqleWox0vOLaycyVPdy_J9XWzSIKvRu0xkwxo75mhDiVJhNnw', firebaseConfig: { - apiKey: 'AIzaSyClOk4qP0ttFW-BPnXy7WT920xfdXSbFu8', - authDomain: 'epns-internal.firebaseapp.com', - databaseURL: 'https://epns-internal.firebaseio.com', - projectId: 'epns-internal', - storageBucket: 'epns-internal.appspot.com', - messagingSenderId: '755180533582', - appId: '1:755180533582:web:752ff8db31905506b7d01f', - measurementId: 'G-ZJH2T7R9S1', + apiKey: 'AIzaSyB4aXx2pJ9T5sw0Q1bba3jI1EAGp0Z5kBI', + authDomain: 'push-dev-a6a63.firebaseapp.com', + projectId: 'push-dev-a6a63', + storageBucket: 'push-dev-a6a63.appspot.com', + messagingSenderId: '974364469170', + appId: '1:974364469170:web:47fd6304c6cf36b5bfe6ab', + measurementId: 'G-5YR8N35DY4', }, /** diff --git a/src/config/config-prod.js b/src/config/config-prod.js index caf8031f1d..0e97cac3a0 100644 --- a/src/config/config-prod.js +++ b/src/config/config-prod.js @@ -52,7 +52,7 @@ export const config = { * Analaytics + Firebase */ googleAnalyticsId: 'UA-165415629-1', - vapidKey: 'BFRmmAEEXOhk31FIsooph5CxlXKh6N0_NocUWHzvtpoUEvqQTwLXu6XtwkrH7ckyr2CvVz1ll-8q4oo6-ZqFJPY', + vapidKey: 'BOMOB--KihZkwM8SQ_OrPEsuu8UcSYiRB9AvMjsWil3WJDmxBEcDex8g4d5rFGgA8U-7esfRM5pvR98jaE1nX0M', firebaseConfig: { apiKey: 'AIzaSyBrzkFPyNmVDFzGY7dKz2HocUO4m-ni-Fc', authDomain: 'epns-ethereum-push-service.firebaseapp.com', diff --git a/src/config/config-staging.js b/src/config/config-staging.js index 09bda73c34..a9427e6373 100644 --- a/src/config/config-staging.js +++ b/src/config/config-staging.js @@ -54,7 +54,7 @@ export const config = { * Analaytics + Firebase */ googleAnalyticsId: 'UA-165415629-5', - vapidKey: 'BFRmmAEEXOhk31FIsooph5CxlXKh6N0_NocUWHzvtpoUEvqQTwLXu6XtwkrH7ckyr2CvVz1ll-8q4oo6-ZqFJPY', + vapidKey: 'BO-oYHtENkaP1nRQMmXAmjbkyWz_4sms1Z5OzE8B7h5gmuXiePvLmbXRiJNA233WtzzEo83yWZAVX1blsJQkNFg', firebaseConfig: { apiKey: 'AIzaSyClOk4qP0ttFW-BPnXy7WT920xfdXSbFu8', authDomain: 'epns-internal.firebaseapp.com', diff --git a/src/firebase.js b/src/firebase.js index 3beb51405e..7b46878467 100644 --- a/src/firebase.js +++ b/src/firebase.js @@ -31,6 +31,7 @@ export const getPushToken = async () => { return token; } catch (err) { console.error('An error occurred while retrieving token. ', err); + throw err; } }; From abaf3544c72ab3041146b5823599812b934ba4f2 Mon Sep 17 00:00:00 2001 From: Hritik Singh Date: Mon, 1 Apr 2024 19:00:21 +0530 Subject: [PATCH 03/12] fix: undefined values and removed logs --- src/hooks/useBrowserNotification.ts | 7 +++---- src/services/deliveryNode/registerDeviceToken.ts | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/hooks/useBrowserNotification.ts b/src/hooks/useBrowserNotification.ts index 96dbb98707..daeb17e723 100644 --- a/src/hooks/useBrowserNotification.ts +++ b/src/hooks/useBrowserNotification.ts @@ -27,12 +27,11 @@ export function useBrowserNotification() { if (!('Notification' in window)) { // useStream handles this case of showing in page notif (if showing notifs is not allowed) } else { - console.info('received push notification'); const notificationTitle = payload.notification.title; const notificationOptions = { - title: payload.data.app, - body: payload.notification.body, - image: payload.data.aimg, + title: payload?.notification?.title, + body: payload?.notification?.body, + image: payload?.data?.aimg, icon: payload?.data?.icon, data: { url: payload?.data?.acta || payload?.data?.url, diff --git a/src/services/deliveryNode/registerDeviceToken.ts b/src/services/deliveryNode/registerDeviceToken.ts index 449b686932..53b1a413be 100644 --- a/src/services/deliveryNode/registerDeviceToken.ts +++ b/src/services/deliveryNode/registerDeviceToken.ts @@ -11,7 +11,6 @@ type Props = { export const registerDeviceToken = async ({ token, account }: Props) => { const reqEndpoint = deliveryNodeServiceEndpoints.registerDeviceToken(); - console.log(reqEndpoint); try { const data = { wallet: convertAddressToPartialCaip(account.toLowerCase()), From 023d8d7365abbaf44ab71406dd17f39d73119349 Mon Sep 17 00:00:00 2001 From: harshrajat Date: Wed, 3 Apr 2024 02:12:05 +0400 Subject: [PATCH 04/12] added config for alpha and localhost --- src/config/config-alpha.js | 84 +++++++++++++------------ src/config/config-localhost.js | 109 +++++++++++++++++---------------- 2 files changed, 96 insertions(+), 97 deletions(-) diff --git a/src/config/config-alpha.js b/src/config/config-alpha.js index c278d73804..aac904178c 100644 --- a/src/config/config-alpha.js +++ b/src/config/config-alpha.js @@ -14,6 +14,7 @@ export const config = { apiUrl: 'https://backend.epns.io/apis', w2wApiUrl: 'https://backend.epns.io/apis', toolingApiUrl: 'https://tooling.epns.io/apis', + deliveryNodeApiUrl: 'https://delivery-prod.epns.io/apis', ipfsInfuraAPIKey: process.env.REACT_APP_IPFS_INFURA_API_KEY || '22rfiNb1J645FdehoqbKMpLbF6V', ipfsInfuraAPISecret: process.env.REACT_APP_IPFS_INFURA_API_SECRET || 'a757597f020425c3ae532e6be84de552', @@ -39,10 +40,10 @@ export const config = { mainnetCoreRPC: 'https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a', mainnetCoreContractChain: 1, aliasRPC: { - 137: "https://polygon-mainnet.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9", - 56: "https://bsc-dataseed.binance.org/", - 10: "https://opt-mainnet.g.alchemy.com/v2/JYW0UaSC5Zd0hrI6vE2K9VN1wJupoY5B", - 42161: "https://arb1.arbitrum.io/rpc", + 137: 'https://polygon-mainnet.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9', + 56: 'https://bsc-dataseed.binance.org/', + 10: 'https://opt-mainnet.g.alchemy.com/v2/JYW0UaSC5Zd0hrI6vE2K9VN1wJupoY5B', + 42161: 'https://arb1.arbitrum.io/rpc', 1101: 'https://rpc.polygon-zkevm.gateway.fm', }, infuraApiUrl: 'https:/infura-ipfs.io/ipfs/', @@ -83,7 +84,7 @@ export const addresses = { epnsEthComm: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', // mainnet address eth comm epnsPolyComm: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', // mainnet address polygon comm pushToken: '0xf418588522d5dd018b425E472991E52EBBeEEEEE', // mainnet address - pushChannelAdmin: "0x65193c896eC400f731712D4f71046CeDd11Bff27", // mainnet push core admin + pushChannelAdmin: '0x65193c896eC400f731712D4f71046CeDd11Bff27', // mainnet push core admin aDai: '0xcB1Fe6F440c49E9290c3eb7f158534c2dC374201', // mainnet address staking: '0xB72ff1e675117beDefF05a7D0a472c3844cfec85', // mainnet address yieldFarmPUSH: '0x6019B84E2eE9EB62BC42E32AB6375A7095886366', // mainnet address @@ -101,70 +102,67 @@ export const addresses = { NFTRewardsV2: '0xdc66567a990B7fa10730459537620857c9e03287', //mainnet address //For Yield Farm V1(Deprecated) - staking: "0xB72ff1e675117beDefF05a7D0a472c3844cfec85", // deprecated staking mainnet addresses - depYieldFarmPUSH: "0x6019B84E2eE9EB62BC42E32AB6375A7095886366", // deprecated YieldFarmPUSH mainnet address - depYieldFarmLP:"0xbB2A70e67770D0A7F5f42d883C5BBE9b85e0DcD6",// deprecated YieldFarmLP mainnet addresses + staking: '0xB72ff1e675117beDefF05a7D0a472c3844cfec85', // deprecated staking mainnet addresses + depYieldFarmPUSH: '0x6019B84E2eE9EB62BC42E32AB6375A7095886366', // deprecated YieldFarmPUSH mainnet address + depYieldFarmLP: '0xbB2A70e67770D0A7F5f42d883C5BBE9b85e0DcD6', // deprecated YieldFarmLP mainnet addresses //For Yield Farm V2 - stakingV2:"0x9D2513F5b539DC774C66b28ACEc94e4bD00105C2",//mainnet address - yieldFarmLP: "0x9af118D9fA1eFEa5b5a792847554960217DEdb04",//mainnet address - uniV2LPToken: "0xaf31fd9c3b0350424bf96e551d2d1264d8466205",//same as epnsLPToken - pushCoreV2: "0x66329Fdd4042928BfCAB60b179e1538D56eeeeeE",//not upgraded - - - + stakingV2: '0x9D2513F5b539DC774C66b28ACEc94e4bD00105C2', //mainnet address + yieldFarmLP: '0x9af118D9fA1eFEa5b5a792847554960217DEdb04', //mainnet address + uniV2LPToken: '0xaf31fd9c3b0350424bf96e551d2d1264d8466205', //same as epnsLPToken + pushCoreV2: '0x66329Fdd4042928BfCAB60b179e1538D56eeeeeE', //not upgraded }; export const CHAIN_DETAILS = { 1: { - label: "Ethereum Mainnet", - name: "ETH_MAINNET", + label: 'Ethereum Mainnet', + name: 'ETH_MAINNET', chainId: 1, - rpcUrl: "https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a", - commAddress: "0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa", - network: "mainnet", - }, + rpcUrl: 'https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a', + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', + network: 'mainnet', + }, 137: { - label: "Polygon Mainnet", - name: "POLYGON_MAINNET", + label: 'Polygon Mainnet', + name: 'POLYGON_MAINNET', chainId: 137, - rpcUrl: "https://polygon-mainnet.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9", - commAddress: "0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa", - network: "polygon-mainnet", + rpcUrl: 'https://polygon-mainnet.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9', + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', + network: 'polygon-mainnet', }, 56: { - label: "BNB Mainnet", - name: "BNB_MAINNET", + label: 'BNB Mainnet', + name: 'BNB_MAINNET', chainId: 56, - rpcUrl: "https://bsc-dataseed.binance.org/", - commAddress: "0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa" + rpcUrl: 'https://bsc-dataseed.binance.org/', + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, 10: { - label: "Optimism Mainnet", - name: "OPTIMISM_MAINNET", + label: 'Optimism Mainnet', + name: 'OPTIMISM_MAINNET', chainId: 10, rpcUrl: 'https://opt-mainnet.g.alchemy.com/v2/JYW0UaSC5Zd0hrI6vE2K9VN1wJupoY5B', - commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa' + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, 1101: { - label: "Polygon zkEVM Mainnet", - name: "POLYGON_ZK_EVM_MAINNET", + label: 'Polygon zkEVM Mainnet', + name: 'POLYGON_ZK_EVM_MAINNET', chainId: 1101, rpcUrl: 'https://rpc.polygon-zkevm.gateway.fm', - commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa' + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, 42161: { - label: "Arbitrum Mainnet", - name: "ARBITRUMONE_MAINNET", + label: 'Arbitrum Mainnet', + name: 'ARBITRUMONE_MAINNET', chainId: 42161, rpcUrl: 'https://arb1.arbitrum.io/rpc', - commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa' + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, 122: { - label: "Fuse Mainnet", - name: "FUSE_MAINNET", + label: 'Fuse Mainnet', + name: 'FUSE_MAINNET', chainId: 122, rpcUrl: 'https://rpc.fuse.io', - commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa' + commAddress: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa', }, -} \ No newline at end of file +}; diff --git a/src/config/config-localhost.js b/src/config/config-localhost.js index 6e92ccbc76..a58037f2b2 100644 --- a/src/config/config-localhost.js +++ b/src/config/config-localhost.js @@ -14,6 +14,7 @@ export const config = { apiUrl: 'http://localhost:4000/apis', w2wApiUrl: 'http://localhost:4000/apis', toolingApiUrl: 'https://tooling.epns.io/apis', + deliveryNodeApiUrl: 'https://delivery-dev.epns.io/apis', ipfsInfuraAPIKey: process.env.REACT_APP_IPFS_INFURA_API_KEY || '22rfiNb1J645FdehoqbKMpLbF6V', ipfsInfuraAPISecret: process.env.REACT_APP_IPFS_INFURA_API_SECRET || 'a757597f020425c3ae532e6be84de552', @@ -21,26 +22,26 @@ export const config = { /** * Allowed Networks */ - allowedNetworks: [ + allowedNetworks: [ 5, // for eth goerli 80001, //for mumbai polygon 97, // bnb testnet - 420 // optimism goerli testnet + 420, // optimism goerli testnet ], /** * Core Network Related Data */ - coreContractChain: 5, //the chain id of the network which the core contract relies on - coreRPC: 'https://goerli.infura.io/v3/4ff53a5254144d988a8318210b56f47a', - mainnetCoreRPC: "https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a", - mainnetCoreContractChain: 1, - aliasRPC: { - 80001: "https://polygon-mumbai.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9", - 97: "https://data-seed-prebsc-1-s1.binance.org:8545", - 420: "https://opt-goerli.g.alchemy.com/v2/98vFj7OCg4vbGKvCDpj6pOAMSBVC7rzm" - }, - infuraApiUrl: 'https:/infura-ipfs.io/ipfs/', + coreContractChain: 5, //the chain id of the network which the core contract relies on + coreRPC: 'https://goerli.infura.io/v3/4ff53a5254144d988a8318210b56f47a', + mainnetCoreRPC: 'https://mainnet.infura.io/v3/4ff53a5254144d988a8318210b56f47a', + mainnetCoreContractChain: 1, + aliasRPC: { + 80001: 'https://polygon-mumbai.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9', + 97: 'https://data-seed-prebsc-1-s1.binance.org:8545', + 420: 'https://opt-goerli.g.alchemy.com/v2/98vFj7OCg4vbGKvCDpj6pOAMSBVC7rzm', + }, + infuraApiUrl: 'https:/infura-ipfs.io/ipfs/', /** * Analaytics + Firebase @@ -72,58 +73,58 @@ export const config = { /** * Smart Contract Related */ - export const addresses = { - ceaErc20: "0xc1C0472c0C80bCcDC7F5D01A376Bd97a734B8815", - epnscore: "0x23346b732d56d34ec4e890419fbfb8548216a799", - epnsEthComm: "0xc064F30bac07e84500c97A04D21a9d1bfFC72Ec0", - epnsPolyComm: "0xAf55BE8e6b0d6107891bA76eADeEa032ef8A4504", // the ploygon comm contract - pushToken: "0x2b9bE9259a4F5Ba6344c1b1c07911539642a2D33", //address for push token - aDai: "0x31f30d9A5627eAfeC4433Ae2886Cf6cc3D25E772", - staking: "0x8e129EF695F8761922F1AA38588292f8d8817bA5", - yieldFarmPUSH: "0xb41cd6760d3b1d0d216851f63fda9573b04dd46e", - yieldFarmLP: "0x604f629A6b5E85805D57f39493BBC2856cE8A540", - epnsToken: "0x2b9bE9259a4F5Ba6344c1b1c07911539642a2D33", - epnsLPToken: "0x1f094Bd8c260D0C3fC79157096015990885af4d2", - rockstar: "0x3f8C2152b79276b78315CAF66cCF951780580A8a", - batchMintNFT: "0xCf733D547B9f7F87c1B1f63f45c197C007F8eedf", - NFTRewards: "0xc4708BB6EC3B797344f123126171302e4e3E68E2", - distributor: "0x5B548D33874DeABaC2F683A6E1864795E09932F0", - uniswapV2Router02: "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D", //n - WETHAddress: "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6", // mainnet address //n - USDTAddress: "0x13512979ade267ab5100878e2e0f485b568328a4", // mainnet address //n - rockstarV2: "0xA2b885e7065EA59a3251489715ca80DE5Ff642f8", //mainnet address - NFTRewardsV2: "0xdc66567a990B7fa10730459537620857c9e03287", //mainnet address -} +export const addresses = { + ceaErc20: '0xc1C0472c0C80bCcDC7F5D01A376Bd97a734B8815', + epnscore: '0x23346b732d56d34ec4e890419fbfb8548216a799', + epnsEthComm: '0xc064F30bac07e84500c97A04D21a9d1bfFC72Ec0', + epnsPolyComm: '0xAf55BE8e6b0d6107891bA76eADeEa032ef8A4504', // the ploygon comm contract + pushToken: '0x2b9bE9259a4F5Ba6344c1b1c07911539642a2D33', //address for push token + aDai: '0x31f30d9A5627eAfeC4433Ae2886Cf6cc3D25E772', + staking: '0x8e129EF695F8761922F1AA38588292f8d8817bA5', + yieldFarmPUSH: '0xb41cd6760d3b1d0d216851f63fda9573b04dd46e', + yieldFarmLP: '0x604f629A6b5E85805D57f39493BBC2856cE8A540', + epnsToken: '0x2b9bE9259a4F5Ba6344c1b1c07911539642a2D33', + epnsLPToken: '0x1f094Bd8c260D0C3fC79157096015990885af4d2', + rockstar: '0x3f8C2152b79276b78315CAF66cCF951780580A8a', + batchMintNFT: '0xCf733D547B9f7F87c1B1f63f45c197C007F8eedf', + NFTRewards: '0xc4708BB6EC3B797344f123126171302e4e3E68E2', + distributor: '0x5B548D33874DeABaC2F683A6E1864795E09932F0', + uniswapV2Router02: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D', //n + WETHAddress: '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', // mainnet address //n + USDTAddress: '0x13512979ade267ab5100878e2e0f485b568328a4', // mainnet address //n + rockstarV2: '0xA2b885e7065EA59a3251489715ca80DE5Ff642f8', //mainnet address + NFTRewardsV2: '0xdc66567a990B7fa10730459537620857c9e03287', //mainnet address +}; export const CHAIN_DETAILS = { 5: { - label: "Ethereum Goerli", - name: "ETH_TEST_GOERLI", + label: 'Ethereum Goerli', + name: 'ETH_TEST_GOERLI', chainId: 5, - rpcUrl: "https://goerli.infura.io/v3/4ff53a5254144d988a8318210b56f47a", - commAddress: "0xc064F30bac07e84500c97A04D21a9d1bfFC72Ec0", - network: "goerli", - }, + rpcUrl: 'https://goerli.infura.io/v3/4ff53a5254144d988a8318210b56f47a', + commAddress: '0xc064F30bac07e84500c97A04D21a9d1bfFC72Ec0', + network: 'goerli', + }, 80001: { - label: "Polygon Mumbai", - name: "POLYGON_TEST_MUMBAI", + label: 'Polygon Mumbai', + name: 'POLYGON_TEST_MUMBAI', chainId: 80001, - rpcUrl: "https://polygon-mumbai.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9", - commAddress: "0xAf55BE8e6b0d6107891bA76eADeEa032ef8A4504", - network: "polygon-mumbai", + rpcUrl: 'https://polygon-mumbai.infura.io/v3/150f25623ae64d08ab7ec7dd0c6b6ee9', + commAddress: '0xAf55BE8e6b0d6107891bA76eADeEa032ef8A4504', + network: 'polygon-mumbai', }, 97: { - label: "BNB Testnet", - name: "BNB_TESTNET", + label: 'BNB Testnet', + name: 'BNB_TESTNET', chainId: 97, - rpcUrl: "https://data-seed-prebsc-1-s1.binance.org:8545", - commAddress: "0x4132061E3349ff36cFfCadA460E10Bd4f31F7ea8" + rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545', + commAddress: '0x4132061E3349ff36cFfCadA460E10Bd4f31F7ea8', }, 420: { - label: "Optimism Goerli", - name: "OPTIMISM_TESTNET", + label: 'Optimism Goerli', + name: 'OPTIMISM_TESTNET', chainId: 420, rpcUrl: 'https://opt-goerli.g.alchemy.com/v2/98vFj7OCg4vbGKvCDpj6pOAMSBVC7rzm', - commAddress: '0x4305D572F2bf38Fc2AE8D0172055b1EFd18F57a6' - } -} + commAddress: '0x4305D572F2bf38Fc2AE8D0172055b1EFd18F57a6', + }, +}; From c6ea1709349e38ad6222549d2069d61434a7fd3f Mon Sep 17 00:00:00 2001 From: Monalisha Mishra Date: Wed, 8 May 2024 18:15:34 +0530 Subject: [PATCH 05/12] started building it --- .../channel/AllowNotificationModal.tsx | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/components/channel/AllowNotificationModal.tsx diff --git a/src/components/channel/AllowNotificationModal.tsx b/src/components/channel/AllowNotificationModal.tsx new file mode 100644 index 0000000000..799a97b362 --- /dev/null +++ b/src/components/channel/AllowNotificationModal.tsx @@ -0,0 +1,32 @@ +import { SpanV2 } from 'components/reusables/SharedStylingV2'; +import { device } from 'config/Globals'; +import styled, { useTheme } from 'styled-components'; + +const AllowNotificationModal = () => { + const theme = useTheme(); + return ( + + Allow Notifications + + We recommend enabling notifications for receiving updates from subscribed channels for a seamless experience. + + + ); +}; + +export default AllowNotificationModal; + +const ModalContainer = styled.div` + display: flex; + flex-direction: column; + border-radius: 24px; + background: ${(props) => props.theme.modalContentBackground}; + border-radius: 24px; + padding: 24px; + @media (${device.laptop}) { + width: 50vw; + } + @media (${device.mobileL}) { + width: 95vw; + } +`; From f5923c89d8ca3f714f0a28e9be6c04470864d356 Mon Sep 17 00:00:00 2001 From: Monalisha Mishra Date: Fri, 10 May 2024 14:02:00 +0530 Subject: [PATCH 06/12] added allow notif modal --- src/components/ViewChannelItem.jsx | 123 ++++++++++------ .../channel/AllowNotificationModal.tsx | 92 ++++++++++-- .../dropdowns/OptinNotifSettingDropdown.tsx | 1 + src/config/Themization.js | 2 + src/helpers/channel/allowNotification.ts | 22 +++ src/helpers/channel/types.ts | 134 +++++++++--------- 6 files changed, 249 insertions(+), 125 deletions(-) create mode 100644 src/helpers/channel/allowNotification.ts diff --git a/src/components/ViewChannelItem.jsx b/src/components/ViewChannelItem.jsx index 77b93e453d..4a831836c8 100644 --- a/src/components/ViewChannelItem.jsx +++ b/src/components/ViewChannelItem.jsx @@ -18,6 +18,7 @@ import styled, { css, useTheme } from 'styled-components'; // Internal Compoonents import * as PushAPI from '@pushprotocol/restapi'; import { Device } from 'assets/Device'; +import AllowNotificationModal from './channel/AllowNotificationModal'; import MetaInfoDisplayer from 'components/MetaInfoDisplayer'; import LoaderSpinner, { LOADER_TYPE } from 'components/reusables/loaders/LoaderSpinner'; import { ButtonV2 } from 'components/reusables/SharedStylingV2'; @@ -43,6 +44,8 @@ import VerifiedTooltipContent from './VerifiedTooltipContent'; import APP_PATHS from 'config/AppPaths'; import { addresses, appConfig, CHAIN_DETAILS } from 'config/index.js'; import { IPFSGateway } from 'helpers/IpfsHelper'; +import { checkPermission } from 'helpers/channel/allowNotification'; +import { NOTIF_PERMISSION_STATUS } from 'helpers/channel/types'; // Create Header function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, profileType }) { @@ -85,6 +88,9 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p const [channelObjectFromHash, setChannelObjectFromHash] = React.useState({}); const [channelObjectStartBlock, setChannelObjectStartBlock] = React.useState({}); const [showChannelChangedWarning, setShowChannelChangedWarning] = React.useState(false); + const [showAllowNotification, setShowAllowNotification] = useState(false); + + const isVerified = channelObject.verified_status; const isBlocked = channelObject.blocked; const isMobile = useDeviceWidthCheck(600); @@ -103,6 +109,13 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p setSubscribed(subscriptionStatus[channelObject.channel]); }, [subscriptionStatus]); + useEffect(() => { + if (showAllowNotification) + setTimeout(() => { + setShowAllowNotification(false); + }, 10000); + }, [showAllowNotification]); + useEffect(() => { setIsPushAdmin(pushAdminAddress == account); }, [pushAdminAddress, account]); @@ -399,6 +412,20 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p setToolTipheight(containerHeight?.top); }; + const onAllowModalOpen = () => { + if (checkPermission() === NOTIF_PERMISSION_STATUS.PENDING) { + const lastTime = localStorage.getItem('allow_notif_modal'); + let today = new Date().getTime() + (1 * 24 * 60 * 60 * 1000); + if (lastTime && lastTime >= today) { + setShowAllowNotification(true); + } + else { + localStorage.setItem('allow_notif_modal', today); + } + } + + } + // render return ( Polygon { - setSubscribed(true); - setSubscriberCount((prevSubscriberCount) => prevSubscriberCount + 1); + onAllowModalOpen(); }} > {}} + onClick={() => { }} disabled={txInProgress} className="optin" > @@ -988,7 +1013,7 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p }} > {}} + onClick={() => { }} disabled={txInProgress} > {txInProgress && ( @@ -1021,6 +1046,10 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p clearToast={clearToast} /> )} + {/* modal to allow notification */} + {showAllowNotification && + setShowAllowNotification(false)} /> + } ); } diff --git a/src/components/channel/AllowNotificationModal.tsx b/src/components/channel/AllowNotificationModal.tsx index 799a97b362..59231cc8e1 100644 --- a/src/components/channel/AllowNotificationModal.tsx +++ b/src/components/channel/AllowNotificationModal.tsx @@ -1,15 +1,76 @@ -import { SpanV2 } from 'components/reusables/SharedStylingV2'; -import { device } from 'config/Globals'; +// External Packages import styled, { useTheme } from 'styled-components'; -const AllowNotificationModal = () => { +// Internal Components +import { ButtonV2, ItemHV2, ItemVV2, SpanV2 } from 'components/reusables/SharedStylingV2'; + +// Internal Configs +import { device } from 'config/Globals'; +import { handleBrowserNotification } from 'helpers/channel/allowNotification'; + +interface AllowNotificationModalProps { + onModalClose: () => {}; +} + +const AllowNotificationModal: React.FC = ({ + onModalClose, +}: AllowNotificationModalProps) => { const theme = useTheme(); + return ( - Allow Notifications - - We recommend enabling notifications for receiving updates from subscribed channels for a seamless experience. - + + + + Allow Notifications + + + We recommend enabling notifications for receiving updates from subscribed channels for a seamless + experience. + + + + { + handleBrowserNotification(onModalClose); + }} + > + Allow + + onModalClose()} + > + Skip + + + ); }; @@ -19,14 +80,17 @@ export default AllowNotificationModal; const ModalContainer = styled.div` display: flex; flex-direction: column; - border-radius: 24px; + right: 20px; + bottom: 20px; + position: fixed; + z-index: 99999999999; + width: 340px; + border-radius: 12px; + border: 1px solid rgba(0, 0, 0, 0.1); background: ${(props) => props.theme.modalContentBackground}; - border-radius: 24px; - padding: 24px; - @media (${device.laptop}) { - width: 50vw; - } + padding: 16px 20px; + @media (${device.mobileL}) { - width: 95vw; + width: calc(100% - 80px); } `; diff --git a/src/components/dropdowns/OptinNotifSettingDropdown.tsx b/src/components/dropdowns/OptinNotifSettingDropdown.tsx index 39e36ce649..9d894df960 100644 --- a/src/components/dropdowns/OptinNotifSettingDropdown.tsx +++ b/src/components/dropdowns/OptinNotifSettingDropdown.tsx @@ -252,6 +252,7 @@ const OptinNotifSettingDropdown: React.FC = (opt settings: userSettingsFromDefaultChannelSetting({ channelSetting: channelSettings }), }) ); + onSuccessOptin(); subscribeToast.showMessageToast({ toastTitle: 'Success', diff --git a/src/config/Themization.js b/src/config/Themization.js index 03f1eb33ff..67856306ca 100644 --- a/src/config/Themization.js +++ b/src/config/Themization.js @@ -9,6 +9,7 @@ const themeLight = { border: '#E5E8F6', color: '#000', secondaryColor: '#657795', + descriptionTextColor: '#000', hover: '#F3F3FF', borderColor: '#dfdee9', primaryPushThemeTextColor: '#cf1c84', @@ -313,6 +314,7 @@ const themeDark = { color: '#FFF', secondaryColor: '#B6BCD6', hover: '#00000033', + descriptionTextColor: '#B6BCD6', borderColor: '#4A4F67', primaryPushThemeTextColor: '#cf1c84', }, diff --git a/src/helpers/channel/allowNotification.ts b/src/helpers/channel/allowNotification.ts new file mode 100644 index 0000000000..391c987208 --- /dev/null +++ b/src/helpers/channel/allowNotification.ts @@ -0,0 +1,22 @@ +import { NOTIF_PERMISSION_STATUS } from './types'; + +export const handleBrowserNotification = (onSuccess?: () => void) => { + if (!('Notification' in window)) { + alert('This browser does not support desktop notification'); + } else if (checkPermission() === NOTIF_PERMISSION_STATUS.PENDING) { + Notification.requestPermission().then(() => { + onSuccess ? onSuccess() : null; + }); + } +}; + +export const checkPermission = () => { + if (!('Notification' in window)) { + alert('This browser does not support desktop notification'); + } else if (Notification.permission === 'granted') { + return NOTIF_PERMISSION_STATUS.GRANTED; + } else if (Notification.permission !== 'denied') { + return NOTIF_PERMISSION_STATUS.PENDING; + } + return NOTIF_PERMISSION_STATUS.DENIED; +}; diff --git a/src/helpers/channel/types.ts b/src/helpers/channel/types.ts index 93a5936a48..9265b05fa9 100644 --- a/src/helpers/channel/types.ts +++ b/src/helpers/channel/types.ts @@ -1,67 +1,73 @@ export type ChannelSetting = -| { - type: 1; // Boolean - default: boolean; - description: string; - index: number; - } -| { - type: 2; // Range - default: number; - enabled: boolean; - description: string; - index: number; - lowerLimit: number; - upperLimit: number; - ticker: number; - } -| { - type: 3; // Range - default: { - lower: number; - upper: number; - }; - enabled: boolean; - description: string; - index: number; - lowerLimit: number; - upperLimit: number; - ticker: number; -}; + | { + type: 1; // Boolean + default: boolean; + description: string; + index: number; + } + | { + type: 2; // Range + default: number; + enabled: boolean; + description: string; + index: number; + lowerLimit: number; + upperLimit: number; + ticker: number; + } + | { + type: 3; // Range + default: { + lower: number; + upper: number; + }; + enabled: boolean; + description: string; + index: number; + lowerLimit: number; + upperLimit: number; + ticker: number; + }; export type UserSetting = -| { - type: 1; // Boolean - default: boolean; - description: string; - index: number; - user: boolean; - } -| { - type: 2; // Range - default: number; - enabled: boolean; - description: string; - index: number; - lowerLimit: number; - upperLimit: number; - user: number; - ticker: number; - } -| { - type: 3; // Range - default: { - lower: number; - upper: number; - }; - enabled: boolean; - description: string; - index: number; - lowerLimit: number; - upperLimit: number; - user: { - lower: number; - upper: number; - }; - ticker: number; -}; + | { + type: 1; // Boolean + default: boolean; + description: string; + index: number; + user: boolean; + } + | { + type: 2; // Range + default: number; + enabled: boolean; + description: string; + index: number; + lowerLimit: number; + upperLimit: number; + user: number; + ticker: number; + } + | { + type: 3; // Range + default: { + lower: number; + upper: number; + }; + enabled: boolean; + description: string; + index: number; + lowerLimit: number; + upperLimit: number; + user: { + lower: number; + upper: number; + }; + ticker: number; + }; + +export enum NOTIF_PERMISSION_STATUS { + 'GRANTED' = 'granted', + 'DENIED' = 'denied', + 'PENDING' = 'pending', +} From 18550366d3431490ef4e2be14fb6afce11774829 Mon Sep 17 00:00:00 2001 From: Monalisha Mishra Date: Tue, 14 May 2024 13:29:12 +0530 Subject: [PATCH 07/12] fixed the review comments issues --- src/components/ViewChannelItem.jsx | 22 +++++++++++++++------- src/config/index.js | 2 ++ src/helpers/channel/allowNotification.ts | 18 +++++++++--------- src/helpers/channel/types.ts | 6 +----- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/components/ViewChannelItem.jsx b/src/components/ViewChannelItem.jsx index 4a831836c8..80aac7e6d1 100644 --- a/src/components/ViewChannelItem.jsx +++ b/src/components/ViewChannelItem.jsx @@ -42,10 +42,9 @@ import VerifiedTooltipContent from './VerifiedTooltipContent'; // Internal Configs import APP_PATHS from 'config/AppPaths'; -import { addresses, appConfig, CHAIN_DETAILS } from 'config/index.js'; +import { addresses, appConfig, CHAIN_DETAILS, ALLOW_NOTIF_MODAL } from 'config/index.js'; import { IPFSGateway } from 'helpers/IpfsHelper'; import { checkPermission } from 'helpers/channel/allowNotification'; -import { NOTIF_PERMISSION_STATUS } from 'helpers/channel/types'; // Create Header function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, profileType }) { @@ -413,15 +412,24 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p }; const onAllowModalOpen = () => { - if (checkPermission() === NOTIF_PERMISSION_STATUS.PENDING) { - const lastTime = localStorage.getItem('allow_notif_modal'); + /* checks if the user doesnot have + permission set, then opens the modal only if + the modal was last opened 24 hours before + */ + if (checkPermission() === 'pending') { + let lastTime = localStorage.getItem(ALLOW_NOTIF_MODAL); let today = new Date().getTime() + (1 * 24 * 60 * 60 * 1000); - if (lastTime && lastTime >= today) { - setShowAllowNotification(true); + if (lastTime) { + lastTime = parseInt(lastTime); + if (lastTime >= today) { + setShowAllowNotification(true); + } } else { - localStorage.setItem('allow_notif_modal', today); + setShowAllowNotification(true); } + //sets the recent opened time in localstorage. + localStorage.setItem(ALLOW_NOTIF_MODAL, today); } } diff --git a/src/config/index.js b/src/config/index.js index 978ab7f18e..9a6cb9b0ab 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -39,3 +39,5 @@ const appConfig = { ...dynamicConfig, ...generalConfig }; export { CHAIN_DETAILS, abis, addresses, appConfig }; export const defaultSnapOrigin = 'npm:@pushprotocol/snap'; + +export const ALLOW_NOTIF_MODAL = 'ALLOW_NOTIF_MODAL'; diff --git a/src/helpers/channel/allowNotification.ts b/src/helpers/channel/allowNotification.ts index 391c987208..34ab0d620c 100644 --- a/src/helpers/channel/allowNotification.ts +++ b/src/helpers/channel/allowNotification.ts @@ -1,22 +1,22 @@ -import { NOTIF_PERMISSION_STATUS } from './types'; +import { NotificationPermissionStatus } from './types'; export const handleBrowserNotification = (onSuccess?: () => void) => { - if (!('Notification' in window)) { - alert('This browser does not support desktop notification'); - } else if (checkPermission() === NOTIF_PERMISSION_STATUS.PENDING) { + const status = checkPermission(); + if (status === 'notValid') alert('This browser does not support desktop notification'); + else if (status === 'pending') { Notification.requestPermission().then(() => { onSuccess ? onSuccess() : null; }); } }; -export const checkPermission = () => { +export const checkPermission = (): NotificationPermissionStatus => { if (!('Notification' in window)) { - alert('This browser does not support desktop notification'); + return 'notValid'; } else if (Notification.permission === 'granted') { - return NOTIF_PERMISSION_STATUS.GRANTED; + return 'granted'; } else if (Notification.permission !== 'denied') { - return NOTIF_PERMISSION_STATUS.PENDING; + return 'pending'; } - return NOTIF_PERMISSION_STATUS.DENIED; + return 'denied'; }; diff --git a/src/helpers/channel/types.ts b/src/helpers/channel/types.ts index 9265b05fa9..064ab62f73 100644 --- a/src/helpers/channel/types.ts +++ b/src/helpers/channel/types.ts @@ -66,8 +66,4 @@ export type UserSetting = ticker: number; }; -export enum NOTIF_PERMISSION_STATUS { - 'GRANTED' = 'granted', - 'DENIED' = 'denied', - 'PENDING' = 'pending', -} +export type NotificationPermissionStatus = 'granted' | 'denied' | 'pending' | 'notValid'; From de123fcd8822bf70fa04cb7f5d6cab2e4d195fd7 Mon Sep 17 00:00:00 2001 From: Monalisha Mishra Date: Wed, 22 May 2024 12:44:37 +0530 Subject: [PATCH 08/12] added redux --- src/components/ViewChannelItem.jsx | 26 +++++++++++++---------- src/config/index.js | 2 +- src/redux/slices/modalSlice.ts | 29 +++++++++++++++++++++++++ src/redux/store.js | 34 ++++++++++++++++-------------- 4 files changed, 63 insertions(+), 28 deletions(-) create mode 100644 src/redux/slices/modalSlice.ts diff --git a/src/components/ViewChannelItem.jsx b/src/components/ViewChannelItem.jsx index 80aac7e6d1..36f1697d81 100644 --- a/src/components/ViewChannelItem.jsx +++ b/src/components/ViewChannelItem.jsx @@ -39,10 +39,11 @@ import { ImageV2 } from './reusables/SharedStylingV2'; import Tooltip from './reusables/tooltip/Tooltip'; import UpdateChannelTooltipContent from './UpdateChannelTooltipContent'; import VerifiedTooltipContent from './VerifiedTooltipContent'; +import { setAllowNotifModalVisibility } from 'redux/slices/modalSlice'; // Internal Configs import APP_PATHS from 'config/AppPaths'; -import { addresses, appConfig, CHAIN_DETAILS, ALLOW_NOTIF_MODAL } from 'config/index.js'; +import { addresses, appConfig, CHAIN_DETAILS, ALLOW_NOTIF_MODAL_LAST_TIMESTAMP } from 'config/index.js'; import { IPFSGateway } from 'helpers/IpfsHelper'; import { checkPermission } from 'helpers/channel/allowNotification'; @@ -60,6 +61,7 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p (state) => state.contracts ); const { canVerify, channelDetails, coreChannelAdmin } = useSelector((state) => state.admin); + const { isAllowNotifModalVisible } = useSelector((state) => state.modal); const { channelsCache, CHANNEL_BLACKLIST, @@ -87,7 +89,7 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p const [channelObjectFromHash, setChannelObjectFromHash] = React.useState({}); const [channelObjectStartBlock, setChannelObjectStartBlock] = React.useState({}); const [showChannelChangedWarning, setShowChannelChangedWarning] = React.useState(false); - const [showAllowNotification, setShowAllowNotification] = useState(false); + // const [isAllowNotifModalVisible, setAllowNotifModalVisibility] = useState(false); const isVerified = channelObject.verified_status; @@ -109,11 +111,11 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p }, [subscriptionStatus]); useEffect(() => { - if (showAllowNotification) + if (isAllowNotifModalVisible) setTimeout(() => { - setShowAllowNotification(false); + dispatch(setAllowNotifModalVisibility({ flag: false })); }, 10000); - }, [showAllowNotification]); + }, [isAllowNotifModalVisible]); useEffect(() => { setIsPushAdmin(pushAdminAddress == account); @@ -417,19 +419,19 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p the modal was last opened 24 hours before */ if (checkPermission() === 'pending') { - let lastTime = localStorage.getItem(ALLOW_NOTIF_MODAL); + let lastTime = localStorage.getItem(ALLOW_NOTIF_MODAL_LAST_TIMESTAMP); let today = new Date().getTime() + (1 * 24 * 60 * 60 * 1000); if (lastTime) { lastTime = parseInt(lastTime); if (lastTime >= today) { - setShowAllowNotification(true); + dispatch(setAllowNotifModalVisibility({ flag: true })); } } else { - setShowAllowNotification(true); + dispatch(setAllowNotifModalVisibility({ flag: true })); } //sets the recent opened time in localstorage. - localStorage.setItem(ALLOW_NOTIF_MODAL, today); + localStorage.setItem(ALLOW_NOTIF_MODAL_LAST_TIMESTAMP, today); } } @@ -1055,8 +1057,10 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p /> )} {/* modal to allow notification */} - {showAllowNotification && - setShowAllowNotification(false)} /> + {isAllowNotifModalVisible && + + dispatch(setAllowNotifModalVisibility({ flag: false }))} + /> } ); diff --git a/src/config/index.js b/src/config/index.js index 9a6cb9b0ab..258ac2380a 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -40,4 +40,4 @@ export { CHAIN_DETAILS, abis, addresses, appConfig }; export const defaultSnapOrigin = 'npm:@pushprotocol/snap'; -export const ALLOW_NOTIF_MODAL = 'ALLOW_NOTIF_MODAL'; +export const ALLOW_NOTIF_MODAL_LAST_TIMESTAMP = 'ALLOW_NOTIF_MODAL_LAST_TIMESTAMP'; diff --git a/src/redux/slices/modalSlice.ts b/src/redux/slices/modalSlice.ts new file mode 100644 index 0000000000..b2db75c019 --- /dev/null +++ b/src/redux/slices/modalSlice.ts @@ -0,0 +1,29 @@ +/** + * This file helps us maintain the modal visiblity state so that the modal state is not changed when there are re renders. + */ + +// External Packages +import { createSlice } from '@reduxjs/toolkit'; + +export interface IModalSliceState { + isAllowNotifModalVisible: boolean; +} + +const initialState: IModalSliceState = { + isAllowNotifModalVisible: false, //the current page +}; + +export const modalSlice = createSlice({ + name: 'modal', + initialState, + reducers: { + resetModalSlice: () => initialState, + setAllowNotifModalVisibility: (state, action) => { + state.isAllowNotifModalVisible = action.payload.flag; + }, + }, +}); + +export const { resetModalSlice, setAllowNotifModalVisibility } = modalSlice.actions; + +export default modalSlice.reducer; diff --git a/src/redux/store.js b/src/redux/store.js index bf6096bf37..ddccaeee0c 100644 --- a/src/redux/store.js +++ b/src/redux/store.js @@ -7,29 +7,31 @@ import channelCreationReducer from './slices/channelCreationSlice'; import channelReducer from './slices/channelSlice'; import contractReducer from './slices/contractSlice'; import notificationReducer from './slices/notificationSlice'; -import canSendNotification from "./slices/sendNotificationSlice"; +import canSendNotification from './slices/sendNotificationSlice'; import spamReducer from './slices/spamSlice'; import userJourneyReducer from './slices/userJourneySlice'; -import userReducer from "./slices/userSlice"; +import userReducer from './slices/userSlice'; +import modalReducer from './slices/modalSlice'; const rootReducer = combineReducers({ - contracts: contractReducer, - channels: channelReducer, - channelCreation: channelCreationReducer, - admin: adminReducer, - notifications: notificationReducer, - spam: spamReducer, - userJourney: userJourneyReducer, - canSend:canSendNotification, - user: userReducer + contracts: contractReducer, + channels: channelReducer, + channelCreation: channelCreationReducer, + admin: adminReducer, + notifications: notificationReducer, + spam: spamReducer, + userJourney: userJourneyReducer, + canSend: canSendNotification, + user: userReducer, + modal: modalReducer, }); const store = configureStore({ - reducer: rootReducer, - middleware: getDefaultMiddleware({ - serializableCheck: false, - immutableCheck: false - }) + reducer: rootReducer, + middleware: getDefaultMiddleware({ + serializableCheck: false, + immutableCheck: false, + }), }); export default store; From 33610ebe426af6b6d76a36f908a0d451ede8a184 Mon Sep 17 00:00:00 2001 From: Monalisha Mishra Date: Wed, 5 Jun 2024 17:37:31 +0530 Subject: [PATCH 09/12] fixed getToken --- src/App.tsx | 3 ++- src/components/channel/AllowNotificationModal.tsx | 8 ++++++-- src/config/config-staging.js | 2 +- src/firebase.js | 4 +++- src/helpers/channel/allowNotification.ts | 4 ++-- src/hooks/useBrowserNotification.ts | 1 + yarn.lock | 6 +++--- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 5caaf1f10b..e1336cf786 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -14,6 +14,7 @@ import { createGlobalStyle } from 'styled-components'; // Internal Compoonents import InitState from 'components/InitState'; +import { useBrowserNotification } from 'hooks/useBrowserNotification'; import AppContextProvider, { AppContext } from 'contexts/AppContext'; import NavigationContextProvider from 'contexts/NavigationContext'; import { useAccount, useInactiveListener, useSDKSocket } from 'hooks'; @@ -192,7 +193,7 @@ export default function App() { // // This will run when the page first loads and whenever the title changes // document.title = title; // }, [title]); - + useBrowserNotification(); React.useEffect(() => { const now = Date.now() / 1000; setcurrentTime(now); diff --git a/src/components/channel/AllowNotificationModal.tsx b/src/components/channel/AllowNotificationModal.tsx index 59231cc8e1..48eed0a3cb 100644 --- a/src/components/channel/AllowNotificationModal.tsx +++ b/src/components/channel/AllowNotificationModal.tsx @@ -1,8 +1,12 @@ +import { useContext } from 'react'; + // External Packages import styled, { useTheme } from 'styled-components'; // Internal Components import { ButtonV2, ItemHV2, ItemVV2, SpanV2 } from 'components/reusables/SharedStylingV2'; +import { useAccount } from 'hooks'; +import GlobalContext from 'contexts/GlobalContext'; // Internal Configs import { device } from 'config/Globals'; @@ -16,7 +20,7 @@ const AllowNotificationModal: React.FC = ({ onModalClose, }: AllowNotificationModalProps) => { const theme = useTheme(); - + const { account } = useAccount(); return ( @@ -53,7 +57,7 @@ const AllowNotificationModal: React.FC = ({ color="#fff" borderRadius="8px" onClick={() => { - handleBrowserNotification(onModalClose); + handleBrowserNotification(account, onModalClose); }} > Allow diff --git a/src/config/config-staging.js b/src/config/config-staging.js index f393883487..929d847839 100644 --- a/src/config/config-staging.js +++ b/src/config/config-staging.js @@ -55,7 +55,7 @@ export const config = { * Analaytics + Firebase */ googleAnalyticsId: 'UA-165415629-5', - vapidKey: 'BO-oYHtENkaP1nRQMmXAmjbkyWz_4sms1Z5OzE8B7h5gmuXiePvLmbXRiJNA233WtzzEo83yWZAVX1blsJQkNFg', + vapidKey: 'BFRmmAEEXOhk31FIsooph5CxlXKh6N0_NocUWHzvtpoUEvqQTwLXu6XtwkrH7ckyr2CvVz1ll-8q4oo6-ZqFJPY', firebaseConfig: { apiKey: 'AIzaSyClOk4qP0ttFW-BPnXy7WT920xfdXSbFu8', authDomain: 'epns-internal.firebaseapp.com', diff --git a/src/firebase.js b/src/firebase.js index ee8b18832b..b0cf1bf6b1 100644 --- a/src/firebase.js +++ b/src/firebase.js @@ -21,6 +21,8 @@ const setLocalToken = (token) => localStorage.setItem(TOKEN_KEY, token); export const getPushToken = async () => { try { let token = getLocalToken(TOKEN_KEY); + console.debug(token, 'token'); + console.debug(appConfig.vapidKey, 'vapidkey'); if (!token) { token = await getToken(messaging, { vapidKey: appConfig.vapidKey, @@ -47,7 +49,7 @@ export const browserFunction = async (account) => { const tokenExists = localStorage.getItem(tokenKey) || localStorage.getItem(CACHEPREFIX); //temp to prevent more than 1 account to register if (!tokenExists) { const response = await getPushToken(); - + console.debug(account, 'account'); await registerDeviceToken({ token: response, account: account, diff --git a/src/helpers/channel/allowNotification.ts b/src/helpers/channel/allowNotification.ts index 90be30295e..3fb89224be 100644 --- a/src/helpers/channel/allowNotification.ts +++ b/src/helpers/channel/allowNotification.ts @@ -1,9 +1,9 @@ import { NotificationPermissionStatus } from './types'; import { browserFunction } from 'firebase'; -export const handleBrowserNotification = (account: string, readOnlyWallet: string, onSuccess?: () => void) => { +export const handleBrowserNotification = (account: string, onSuccess?: () => void) => { if (!('serviceWorker' in navigator)) return; - if (!account || account == readOnlyWallet) return; + if (!account) return; const status = checkPermission(); if (status === 'notValid') alert('This browser does not support desktop notification'); else if (status === 'pending') { diff --git a/src/hooks/useBrowserNotification.ts b/src/hooks/useBrowserNotification.ts index 6dcc075297..0c4cdfc914 100644 --- a/src/hooks/useBrowserNotification.ts +++ b/src/hooks/useBrowserNotification.ts @@ -25,6 +25,7 @@ export function useBrowserNotification() { // const { onMessageListener } = require('firebase'); onMessageListener() .then((payload) => { + console.debug('payload', payload); if (!('Notification' in window)) { // useStream handles this case of showing in page notif (if showing notifs is not allowed) } else { diff --git a/yarn.lock b/yarn.lock index a72d4b2e01..ebce00e278 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6689,11 +6689,11 @@ __metadata: linkType: hard "@types/node@npm:>=12.12.47": - version: 20.14.1 - resolution: "@types/node@npm:20.14.1" + version: 20.14.2 + resolution: "@types/node@npm:20.14.2" dependencies: undici-types: "npm:~5.26.4" - checksum: 10/1417d9768dccca9491fb5fc41ef0ee9044cef4c86eef413608dd983c30af19d5f0930b356791dde3aec238a6a47bbea42c47b69929b5fe822cf09cd543f6c52f + checksum: 10/c38e47b190fa0a8bdfde24b036dddcf9401551f2fb170a90ff33625c7d6f218907e81c74e0fa6e394804a32623c24c60c50e249badc951007830f0d02c48ee0f languageName: node linkType: hard From 18ab9fea6eb5dbc13d0c9aa16c9afaca87248856 Mon Sep 17 00:00:00 2001 From: Monalisha Mishra Date: Mon, 24 Jun 2024 21:11:05 +0530 Subject: [PATCH 10/12] fixed firebase --- src/config/config-alpha.js | 2 +- src/config/config-dev.js | 2 +- src/config/config-localhost.js | 2 +- src/config/config-prod.js | 2 +- src/config/config-staging.js | 2 +- src/firebase.js | 5 +++-- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/config/config-alpha.js b/src/config/config-alpha.js index b17a8620a6..3a56d47a6a 100644 --- a/src/config/config-alpha.js +++ b/src/config/config-alpha.js @@ -52,7 +52,7 @@ export const config = { * Analaytics + Firebase */ googleAnalyticsId: 'UA-165415629-1', - vapidKey: 'BFRmmAEEXOhk31FIsooph5CxlXKh6N0_NocUWHzvtpoUEvqQTwLXu6XtwkrH7ckyr2CvVz1ll-8q4oo6-ZqFJPY', + vapidKey: 'BO-oYHtENkaP1nRQMmXAmjbkyWz_4sms1Z5OzE8B7h5gmuXiePvLmbXRiJNA233WtzzEo83yWZAVX1blsJQkNFg', firebaseConfig: { apiKey: 'AIzaSyClOk4qP0ttFW-BPnXy7WT920xfdXSbFu8', authDomain: 'epns-internal.firebaseapp.com', diff --git a/src/config/config-dev.js b/src/config/config-dev.js index d6e03ce97c..46257beedc 100644 --- a/src/config/config-dev.js +++ b/src/config/config-dev.js @@ -54,7 +54,7 @@ export const config = { * Analaytics + Firebase */ googleAnalyticsId: 'UA-165415629-5', - vapidKey: 'BJYsH1MYRqzfuzduyHLNaUfZCYdAahcJXsdWzdTqleWox0vOLaycyVPdy_J9XWzSIKvRu0xkwxo75mhDiVJhNnw', + vapidKey: 'BO-oYHtENkaP1nRQMmXAmjbkyWz_4sms1Z5OzE8B7h5gmuXiePvLmbXRiJNA233WtzzEo83yWZAVX1blsJQkNFg', firebaseConfig: { apiKey: 'AIzaSyB4aXx2pJ9T5sw0Q1bba3jI1EAGp0Z5kBI', authDomain: 'push-dev-a6a63.firebaseapp.com', diff --git a/src/config/config-localhost.js b/src/config/config-localhost.js index d3b6549076..a93b6f9983 100644 --- a/src/config/config-localhost.js +++ b/src/config/config-localhost.js @@ -47,7 +47,7 @@ export const config = { * Analaytics + Firebase */ googleAnalyticsId: 'UA-165415629-5', - vapidKey: 'BFRmmAEEXOhk31FIsooph5CxlXKh6N0_NocUWHzvtpoUEvqQTwLXu6XtwkrH7ckyr2CvVz1ll-8q4oo6-ZqFJPY', + vapidKey: 'BO-oYHtENkaP1nRQMmXAmjbkyWz_4sms1Z5OzE8B7h5gmuXiePvLmbXRiJNA233WtzzEo83yWZAVX1blsJQkNFg', firebaseConfig: { apiKey: 'AIzaSyClOk4qP0ttFW-BPnXy7WT920xfdXSbFu8', authDomain: 'epns-internal.firebaseapp.com', diff --git a/src/config/config-prod.js b/src/config/config-prod.js index aaf6ccca42..7e86932a36 100644 --- a/src/config/config-prod.js +++ b/src/config/config-prod.js @@ -53,7 +53,7 @@ export const config = { * Analaytics + Firebase */ googleAnalyticsId: 'UA-165415629-1', - vapidKey: 'BOMOB--KihZkwM8SQ_OrPEsuu8UcSYiRB9AvMjsWil3WJDmxBEcDex8g4d5rFGgA8U-7esfRM5pvR98jaE1nX0M', + vapidKey: 'BO-oYHtENkaP1nRQMmXAmjbkyWz_4sms1Z5OzE8B7h5gmuXiePvLmbXRiJNA233WtzzEo83yWZAVX1blsJQkNFg', firebaseConfig: { apiKey: 'AIzaSyBrzkFPyNmVDFzGY7dKz2HocUO4m-ni-Fc', authDomain: 'epns-ethereum-push-service.firebaseapp.com', diff --git a/src/config/config-staging.js b/src/config/config-staging.js index 929d847839..f393883487 100644 --- a/src/config/config-staging.js +++ b/src/config/config-staging.js @@ -55,7 +55,7 @@ export const config = { * Analaytics + Firebase */ googleAnalyticsId: 'UA-165415629-5', - vapidKey: 'BFRmmAEEXOhk31FIsooph5CxlXKh6N0_NocUWHzvtpoUEvqQTwLXu6XtwkrH7ckyr2CvVz1ll-8q4oo6-ZqFJPY', + vapidKey: 'BO-oYHtENkaP1nRQMmXAmjbkyWz_4sms1Z5OzE8B7h5gmuXiePvLmbXRiJNA233WtzzEo83yWZAVX1blsJQkNFg', firebaseConfig: { apiKey: 'AIzaSyClOk4qP0ttFW-BPnXy7WT920xfdXSbFu8', authDomain: 'epns-internal.firebaseapp.com', diff --git a/src/firebase.js b/src/firebase.js index b0cf1bf6b1..514f34b524 100644 --- a/src/firebase.js +++ b/src/firebase.js @@ -8,7 +8,7 @@ import { registerDeviceToken } from './services'; // Internal Configs import { appConfig } from 'config'; // Initialize the Firebase app in the service worker by passing the generated config -var firebaseConfig = { ...appConfig.firebaseConfig }; +var firebaseConfig = { ...appConfig.firebaseConfig, vapidKey: appConfig.vapidKey }; const TOKEN_KEY = 'EPNS_BASE_PUSH_TOKEN'; const CACHEPREFIX = 'PUSH_TOKEN_'; @@ -21,11 +21,12 @@ const setLocalToken = (token) => localStorage.setItem(TOKEN_KEY, token); export const getPushToken = async () => { try { let token = getLocalToken(TOKEN_KEY); - console.debug(token, 'token'); + console.debug(token, 'serviceWorker' in navigator, 'token'); console.debug(appConfig.vapidKey, 'vapidkey'); if (!token) { token = await getToken(messaging, { vapidKey: appConfig.vapidKey, + serviceWorkerRegistration: await navigator.serviceWorker.ready, // Ensure the service worker is ready }); setLocalToken(token); } From 7d4355bcab97d5533f3e77de8a3702ec7205488d Mon Sep 17 00:00:00 2001 From: Monalisha Mishra Date: Wed, 26 Jun 2024 14:19:34 +0530 Subject: [PATCH 11/12] debugging the change --- public/index.html | 1 + src/firebase.js | 20 +++++++++++++++----- src/hooks/useBrowserNotification.ts | 5 +++-- src/index.tsx | 15 +++++++++++++-- src/serviceWorker.js | 13 +++++++++---- 5 files changed, 41 insertions(+), 13 deletions(-) diff --git a/public/index.html b/public/index.html index 96e6b15efe..985cefece0 100644 --- a/public/index.html +++ b/public/index.html @@ -132,6 +132,7 @@ +