From c2b2771e053e826169e77cb93c82893ecfa2f400 Mon Sep 17 00:00:00 2001 From: Asgeir Date: Tue, 5 Jul 2022 10:53:07 +0200 Subject: [PATCH 1/4] Update the publication ID to include `gnosis-chain` instead of `xdai` - the subgraph converts old xdai name to gnosis_chain (The Graph still uses xdai) --- packages/app/src/models/publication.ts | 6 +++--- packages/subgraph/src/publication.mapping.ts | 3 ++- packages/subgraph/src/utils.ts | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/app/src/models/publication.ts b/packages/app/src/models/publication.ts index 8839a43c..29d67e59 100644 --- a/packages/app/src/models/publication.ts +++ b/packages/app/src/models/publication.ts @@ -54,8 +54,8 @@ export interface Article { } } -const THE_GRAPH_NAME_TO_CHAINID: { [name: string]: number } = { - xdai: 100, +const CHAINNAME_TO_CHAINID: { [name: string]: number } = { + gnosis_chain: 100, mainnet: 1, rinkeby: 4, } @@ -63,5 +63,5 @@ const THE_GRAPH_NAME_TO_CHAINID: { [name: string]: number } = { export const publicationIdToChainId = (id: string): number => { // The Graph network names (see: `packages/subgraph/network_configs/`) const chainName = id.split(":")[0] - return THE_GRAPH_NAME_TO_CHAINID[chainName] + return CHAINNAME_TO_CHAINID[chainName] } diff --git a/packages/subgraph/src/publication.mapping.ts b/packages/subgraph/src/publication.mapping.ts index 3155d5fb..5702f2ab 100644 --- a/packages/subgraph/src/publication.mapping.ts +++ b/packages/subgraph/src/publication.mapping.ts @@ -4,6 +4,7 @@ import { Permission, Publication } from "../generated/schema" import { ACTION__ARTICLE, ACTION__PUBLICATION, + getNetwork, getPermissionId, jsonToArrayString, jsonToString, @@ -15,7 +16,7 @@ import { import { store } from "@graphprotocol/graph-ts" export const getPublicationId = (event: NewPost): string => - dataSource.network() + ":P-" + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + getNetwork(dataSource.network()) + ":P-" + event.transaction.hash.toHex() + "-" + event.logIndex.toString() const PUBLICATION_ENTITY_TYPE = "Publication" const ARTICLE_ENTITY_TYPE = "Article" const PERMISSION_ENTITY_TYPE = "Permission" diff --git a/packages/subgraph/src/utils.ts b/packages/subgraph/src/utils.ts index 4b889351..9c3ef712 100644 --- a/packages/subgraph/src/utils.ts +++ b/packages/subgraph/src/utils.ts @@ -159,3 +159,5 @@ function hasPublicationPermission(publicationId: string, user: Address, actionTy return false } + +export const getNetwork = (rawNetwork: string): string => (rawNetwork == "xdai" ? "gnosis_chain" : rawNetwork) From 76c60e1151bd79b8ce203742608ff363fd3945b0 Mon Sep 17 00:00:00 2001 From: Asgeir Date: Tue, 5 Jul 2022 11:49:18 +0200 Subject: [PATCH 2/4] Fix notification bugs --- .../app/src/components/commons/PostItem.tsx | 4 +-- .../views/publication/CreatePostView.tsx | 4 +-- .../views/publication/PermissionView.tsx | 28 +++++++++---------- .../views/publication/PreviewPostView.tsx | 5 +++- .../views/publication/PublishView.tsx | 4 +-- .../publication/components/SettingSection.tsx | 8 +++--- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/packages/app/src/components/commons/PostItem.tsx b/packages/app/src/components/commons/PostItem.tsx index fe347c46..afd41055 100644 --- a/packages/app/src/components/commons/PostItem.tsx +++ b/packages/app/src/components/commons/PostItem.tsx @@ -81,10 +81,10 @@ const PostItem: React.FC = ({ article, couldUpdate, couldDelete } id: article.id, }).then((res) => { setCurrentArticleId(article.id) - setExecutePollInterval(true) if (res && res.error) { setLoading(false) - setExecutePollInterval(false) + } else { + setExecutePollInterval(true) } }) } diff --git a/packages/app/src/components/views/publication/CreatePostView.tsx b/packages/app/src/components/views/publication/CreatePostView.tsx index 617d0545..08c17d80 100644 --- a/packages/app/src/components/views/publication/CreatePostView.tsx +++ b/packages/app/src/components/views/publication/CreatePostView.tsx @@ -95,10 +95,10 @@ export const CreatePostView: React.FC = () => { action: "article/delete", id: article.id, }).then((res) => { - setExecutePollInterval(true) if (res && res.error) { - setExecutePollInterval(false) setLoading(false) + } else { + setExecutePollInterval(true) } }) } diff --git a/packages/app/src/components/views/publication/PermissionView.tsx b/packages/app/src/components/views/publication/PermissionView.tsx index 32a32e60..b8fe981f 100644 --- a/packages/app/src/components/views/publication/PermissionView.tsx +++ b/packages/app/src/components/views/publication/PermissionView.tsx @@ -206,24 +206,22 @@ export const PermissionView: React.FC = () => { "publication/permissions": data.publicationPermissions, }, }).then((res) => { - if (type === "delete") { - deleteInterval(true) - } - if (type === "new") { - newPermissionInterval(true) - } - if (type === "edit") { - updateInterval(true) - if (publication && publication.permissions) { - updateCurrentUser(publication.permissions) - } - } if (res && res.error) { setDeleteLoading(false) setLoading(false) - deleteInterval(false) - updateInterval(false) - newPermissionInterval(false) + } else { + if (type === "delete") { + deleteInterval(true) + } + if (type === "new") { + newPermissionInterval(true) + } + if (type === "edit") { + updateInterval(true) + if (publication && publication.permissions) { + updateCurrentUser(publication.permissions) + } + } } }) } diff --git a/packages/app/src/components/views/publication/PreviewPostView.tsx b/packages/app/src/components/views/publication/PreviewPostView.tsx index d4f61046..a94ff3b1 100644 --- a/packages/app/src/components/views/publication/PreviewPostView.tsx +++ b/packages/app/src/components/views/publication/PreviewPostView.tsx @@ -122,7 +122,10 @@ export const PreviewPostView: React.FC = () => { if (res && res.error) { setLoading(false) - updatePoll(false) + } else if (article && article.lastUpdated) { + setArticleId(article.id) + setCurrentTimestamp(parseInt(article.lastUpdated)) + updatePoll(true) } }) } diff --git a/packages/app/src/components/views/publication/PublishView.tsx b/packages/app/src/components/views/publication/PublishView.tsx index 4abce8e2..661c4860 100644 --- a/packages/app/src/components/views/publication/PublishView.tsx +++ b/packages/app/src/components/views/publication/PublishView.tsx @@ -150,10 +150,10 @@ export const PublishView: React.FC = ({ updateChainId }) => { tags, image: image?.path, }).then((res) => { - setExecutePollInterval(true) if (res && res.error) { setLoading(false) - setExecutePollInterval(false) + } else { + setExecutePollInterval(true) } }) } diff --git a/packages/app/src/components/views/publication/components/SettingSection.tsx b/packages/app/src/components/views/publication/components/SettingSection.tsx index 32be8884..1eaad5f2 100644 --- a/packages/app/src/components/views/publication/components/SettingSection.tsx +++ b/packages/app/src/components/views/publication/components/SettingSection.tsx @@ -107,10 +107,10 @@ export const SettingSection: React.FC = ({ couldDelete, co tags, image: image?.path, }).then((res) => { - setUpdateInterval(true) if (res && res.error) { - setUpdateInterval(false) setLoading(false) + } else { + setUpdateInterval(true) } }) } else { @@ -126,10 +126,10 @@ export const SettingSection: React.FC = ({ couldDelete, co action: "publication/delete", id: publication.id, }).then((res) => { - setExecutePollInterval(true) if (res && res.error) { - setExecutePollInterval(false) setDeleteLoading(false) + } else { + setExecutePollInterval(true) } }) } else { From ea703632c3dd0ff47fcf56e3c7c531847dfe4382 Mon Sep 17 00:00:00 2001 From: Asgeir Date: Tue, 5 Jul 2022 15:28:08 +0200 Subject: [PATCH 3/4] Fix bug: directly using setState (without `useEffect` hook) "Warning: Cannot update a component (`App`) while rendering a different component ..." --- packages/app/src/App.tsx | 4 +++- .../app/src/components/views/publication/ArticleView.tsx | 9 ++++++--- .../components/views/publication/PublicationPostView.tsx | 8 +++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index 72c65b97..a6c7ee64 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -28,7 +28,9 @@ const App: React.FC = () => { const [currentSubgraphClient, setCurrentSubgraphClient] = useState(subgraphClient(chainId)) const updateChainId = (newChainId: number | undefined) => { - setChainId(newChainId) + if (newChainId !== chainId) { + setChainId(newChainId) + } } useEffect(() => { diff --git a/packages/app/src/components/views/publication/ArticleView.tsx b/packages/app/src/components/views/publication/ArticleView.tsx index c93d3dfa..39b5bda6 100644 --- a/packages/app/src/components/views/publication/ArticleView.tsx +++ b/packages/app/src/components/views/publication/ArticleView.tsx @@ -26,9 +26,12 @@ export const ArticleView: React.FC = ({ updateChainId }) => { const isValidHash = article && isIPFS.multihash(article.article) const [articleToShow, setArticleToShow] = useState("") - if (publicationId != null) { - updateChainId(publicationIdToChainId(publicationId)) - } + useEffect(() => { + if (publicationId != null) { + updateChainId(publicationIdToChainId(publicationId)) + } + }, [publicationId, updateChainId]) + useEffect(() => { if (!article && articleId) { executeQuery() diff --git a/packages/app/src/components/views/publication/PublicationPostView.tsx b/packages/app/src/components/views/publication/PublicationPostView.tsx index d8394a64..71128fb4 100644 --- a/packages/app/src/components/views/publication/PublicationPostView.tsx +++ b/packages/app/src/components/views/publication/PublicationPostView.tsx @@ -46,9 +46,11 @@ export const PublicationPostView: React.FC = ({ update ? haveActionPermission(permissions, "publicationDelete", account || "") : false - if (publicationId != null) { - updateChainId(publicationIdToChainId(publicationId)) - } + useEffect(() => { + if (publicationId != null) { + updateChainId(publicationIdToChainId(publicationId)) + } + }, [publicationId, updateChainId]) useEffect(() => { if (publicationId) { From 5dd4ccf7499f8c469f0e236602d03e07a29a0f1f Mon Sep 17 00:00:00 2001 From: Asgeir Date: Tue, 5 Jul 2022 16:35:48 +0200 Subject: [PATCH 4/4] Remove logging + Unused component + Fix nested `Typography` components --- packages/app/src/App.tsx | 2 - .../components/views/wallet/SelectNetwork.tsx | 3 -- .../components/views/wallet/WalletView.tsx | 53 +++++++++---------- packages/app/src/services/graphql.ts | 1 - 4 files changed, 26 insertions(+), 33 deletions(-) delete mode 100644 packages/app/src/components/views/wallet/SelectNetwork.tsx diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index a6c7ee64..313d4be7 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -16,7 +16,6 @@ import { subgraphClient } from "./services/graphql" import { PermissionView } from "./components/views/publication/PermissionView" import SetupIpfsView from "./components/views/pinning/SetupIpfsView" import { useWeb3React } from "@web3-react/core" -import { SelectNetwork } from "./components/views/wallet/SelectNetwork" import { PosterProvider } from "./services/poster/context" import { WalletProvider } from "./connectors/WalletProvider" @@ -51,7 +50,6 @@ const App: React.FC = () => { } /> } /> - } /> } /> } /> diff --git a/packages/app/src/components/views/wallet/SelectNetwork.tsx b/packages/app/src/components/views/wallet/SelectNetwork.tsx deleted file mode 100644 index 5e2a7e53..00000000 --- a/packages/app/src/components/views/wallet/SelectNetwork.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import React from "react" - -export const SelectNetwork: React.FC = () =>

Select a supported network here

diff --git a/packages/app/src/components/views/wallet/WalletView.tsx b/packages/app/src/components/views/wallet/WalletView.tsx index b56093ac..76657446 100644 --- a/packages/app/src/components/views/wallet/WalletView.tsx +++ b/packages/app/src/components/views/wallet/WalletView.tsx @@ -1,5 +1,5 @@ import { Box, Grid, Link, Modal, styled, Typography } from "@mui/material" -import React, { useEffect, useRef, useState } from "react" +import React, { useEffect, useState, useRef } from "react" import { palette, typography } from "../../../theme" import CloseIcon from "@mui/icons-material/Close" import { useLocation, useNavigate } from "react-router-dom" @@ -84,7 +84,7 @@ export const WalletView: React.FC = () => { } await activate(connector, undefined, true).catch((error) => { if (error instanceof UnsupportedChainIdError && connector) { - console.error(error) + console.warn(error.message) setShowModal(true) } }) @@ -137,33 +137,32 @@ export const WalletView: React.FC = () => { - - {publicationChainId != null ? ( - - This publication is on {chainToString(publicationChainId)}. Please change your wallet to that - network. + {publicationChainId != null ? ( + + This publication is on {chainToString(publicationChainId)}. Please change your wallet to that + network. + + ) : ( + + + Please, change to one of the supported networks: - ) : ( - - Please, change to one of the supported networks: - - {ALL_SUPPORTED_CHAIN_IDS.map((chainId) => ( - - connector != null && - switchChain(connector, chainId).then(() => handleConnector(connector)) - } - style={{ cursor: "pointer" }} - > - {chainToString(Number(chainId))} - - ))} - + + {ALL_SUPPORTED_CHAIN_IDS.map((chainId) => ( + + connector != null && switchChain(connector, chainId).then(() => handleConnector(connector)) + } + style={{ cursor: "pointer" }} + > + {chainToString(Number(chainId))} + + ))} - )} - + + )} diff --git a/packages/app/src/services/graphql.ts b/packages/app/src/services/graphql.ts index 927992fb..3a460e0b 100644 --- a/packages/app/src/services/graphql.ts +++ b/packages/app/src/services/graphql.ts @@ -20,7 +20,6 @@ const SUBGRAPH_RINKEBY = process.env.REACT_APP_SUBGRAPH_RINKEBY const SUBGRAPH_MAINNET = process.env.REACT_APP_SUBGRAPH_MAINNET const getUrl = (chainId?: number) => { - console.log(`Chain Id is: ${chainId}`) if (chainId === SupportedChainId.MAINNET) { return BASE_SUBGRAPH_URL + SUBGRAPH_MAINNET }