Skip to content

Commit

Permalink
Merge pull request #135 from gnosis/Update-xdai-to-gnosis_chain
Browse files Browse the repository at this point in the history
Update the publication ID to include `gnosis-chain` instead of `xdai`
  • Loading branch information
auryn-macmillan authored Jul 5, 2022
2 parents f391c5e + 5dd4ccf commit 603ca5a
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 70 deletions.
6 changes: 3 additions & 3 deletions packages/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -28,7 +27,9 @@ const App: React.FC = () => {
const [currentSubgraphClient, setCurrentSubgraphClient] = useState(subgraphClient(chainId))

const updateChainId = (newChainId: number | undefined) => {
setChainId(newChainId)
if (newChainId !== chainId) {
setChainId(newChainId)
}
}

useEffect(() => {
Expand All @@ -49,7 +50,6 @@ const App: React.FC = () => {
<Routes>
<Route path="/" element={<LandingView />} />
<Route path="/wallet" element={<WalletView />} />
<Route path="/select-network" element={<SelectNetwork />} />
<Route path="/pinning" element={<SetupIpfsView />} />
<Route path="/publication/publish" element={<PublishView updateChainId={updateChainId} />} />

Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/components/commons/PostItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ const PostItem: React.FC<PostItemProps> = ({ article, couldUpdate, couldDelete }
id: article.id,
}).then((res) => {
setCurrentArticleId(article.id)
setExecutePollInterval(true)
if (res && res.error) {
setLoading(false)
setExecutePollInterval(false)
} else {
setExecutePollInterval(true)
}
})
}
Expand Down
9 changes: 6 additions & 3 deletions packages/app/src/components/views/publication/ArticleView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ export const ArticleView: React.FC<ArticleViewProps> = ({ updateChainId }) => {
const isValidHash = article && isIPFS.multihash(article.article)
const [articleToShow, setArticleToShow] = useState<string>("")

if (publicationId != null) {
updateChainId(publicationIdToChainId(publicationId))
}
useEffect(() => {
if (publicationId != null) {
updateChainId(publicationIdToChainId(publicationId))
}
}, [publicationId, updateChainId])

useEffect(() => {
if (!article && articleId) {
executeQuery()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Expand Down
28 changes: 13 additions & 15 deletions packages/app/src/components/views/publication/PermissionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ export const PublicationPostView: React.FC<PublicationPostViewProps> = ({ update
? haveActionPermission(permissions, "publicationDelete", account || "")
: false

if (publicationId != null) {
updateChainId(publicationIdToChainId(publicationId))
}
useEffect(() => {
if (publicationId != null) {
updateChainId(publicationIdToChainId(publicationId))
}
}, [publicationId, updateChainId])

useEffect(() => {
if (publicationId) {
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/components/views/publication/PublishView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ export const PublishView: React.FC<PublishViewProps> = ({ updateChainId }) => {
tags,
image: image?.path,
}).then((res) => {
setExecutePollInterval(true)
if (res && res.error) {
setLoading(false)
setExecutePollInterval(false)
} else {
setExecutePollInterval(true)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ export const SettingSection: React.FC<SettingsSectionProps> = ({ couldDelete, co
tags,
image: image?.path,
}).then((res) => {
setUpdateInterval(true)
if (res && res.error) {
setUpdateInterval(false)
setLoading(false)
} else {
setUpdateInterval(true)
}
})
} else {
Expand All @@ -126,10 +126,10 @@ export const SettingSection: React.FC<SettingsSectionProps> = ({ couldDelete, co
action: "publication/delete",
id: publication.id,
}).then((res) => {
setExecutePollInterval(true)
if (res && res.error) {
setExecutePollInterval(false)
setDeleteLoading(false)
} else {
setExecutePollInterval(true)
}
})
} else {
Expand Down
3 changes: 0 additions & 3 deletions packages/app/src/components/views/wallet/SelectNetwork.tsx

This file was deleted.

53 changes: 26 additions & 27 deletions packages/app/src/components/views/wallet/WalletView.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -137,33 +137,32 @@ export const WalletView: React.FC = () => {
</Grid>
<Grid item>
<ModalContentContainer>
<Typography variant="body1" fontWeight={700} color={palette.secondary[1000]}>
{publicationChainId != null ? (
<Typography>
This publication is on {chainToString(publicationChainId)}. Please change your wallet to that
network.
{publicationChainId != null ? (
<Typography variant="body1" fontWeight={700} color={palette.secondary[1000]}>
This publication is on {chainToString(publicationChainId)}. Please change your wallet to that
network.
</Typography>
) : (
<Grid item>
<Typography variant="body1" fontWeight={700} color={palette.secondary[1000]}>
Please, change to one of the supported networks:
</Typography>
) : (
<Grid item>
<Typography>Please, change to one of the supported networks:</Typography>
<Grid container flexDirection="column" gap={1}>
{ALL_SUPPORTED_CHAIN_IDS.map((chainId) => (
<Grid
item
key={chainId}
onClick={() =>
connector != null &&
switchChain(connector, chainId).then(() => handleConnector(connector))
}
style={{ cursor: "pointer" }}
>
<Link>{chainToString(Number(chainId))}</Link>
</Grid>
))}
</Grid>
<Grid container flexDirection="column" gap={1}>
{ALL_SUPPORTED_CHAIN_IDS.map((chainId) => (
<Grid
item
key={chainId}
onClick={() =>
connector != null && switchChain(connector, chainId).then(() => handleConnector(connector))
}
style={{ cursor: "pointer" }}
>
<Link>{chainToString(Number(chainId))}</Link>
</Grid>
))}
</Grid>
)}
</Typography>
</Grid>
)}
</ModalContentContainer>
</Grid>
</Grid>
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/models/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ 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,
}

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]
}
1 change: 0 additions & 1 deletion packages/app/src/services/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion packages/subgraph/src/publication.mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Permission, Publication } from "../generated/schema"
import {
ACTION__ARTICLE,
ACTION__PUBLICATION,
getNetwork,
getPermissionId,
jsonToArrayString,
jsonToString,
Expand All @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions packages/subgraph/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,5 @@ function hasPublicationPermission(publicationId: string, user: Address, actionTy

return false
}

export const getNetwork = (rawNetwork: string): string => (rawNetwork == "xdai" ? "gnosis_chain" : rawNetwork)

0 comments on commit 603ca5a

Please sign in to comment.