Skip to content

Commit

Permalink
Merge pull request #264 from rossneilson/release/v3.1.0
Browse files Browse the repository at this point in the history
Release/v3.1.0 - sync with develop
  • Loading branch information
rossneilson authored Mar 7, 2023
2 parents fd21d4c + 81b8b53 commit daf205a
Show file tree
Hide file tree
Showing 40 changed files with 711 additions and 233 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/preview-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,26 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build dapp
run: CI=false pnpm run davi:build-graph-client && pnpm run davi:dev
run: pnpm run davi:build-graph-client && CI=false pnpm run davi:build

- name: Archive artifacts
uses: actions/upload-artifact@v2
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/tests-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,20 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
Expand Down
5 changes: 3 additions & 2 deletions apps/davi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@tiptap/extension-highlight": "^2.0.0-beta.32",
"@tiptap/extension-link": "^2.0.0-beta.209",
"@tiptap/extension-placeholder": "^2.0.0-beta.48",
"@tiptap/pm": "^2.0.0-beta.219",
"@tiptap/react": "^2.0.0-beta.105",
"@tiptap/starter-kit": "^2.0.0-beta.171",
"@types/node": "^16.11.7",
Expand All @@ -90,8 +91,8 @@
"ethers": "^5.7.2",
"git-revision-webpack-plugin": "^3.0.6",
"graphql": "^16.6.0",
"hardhat": "^2.9.1",
"hardhat-dependency-compiler": "^1.1.2",
"hardhat": "^2.12.7",
"hardhat-dependency-compiler": "^1.1.3",
"highlight.js": "^11.6.0",
"i18next": "^21.6.16",
"i18next-browser-languagedetector": "^7.0.1",
Expand Down
1 change: 1 addition & 0 deletions apps/davi/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
"quorum": "Quorum",
"backToOverview": "Back to Overview",
"backToDiscussion": "Back to Discussion",
"originalDiscussion": "Original Discussion",
"seeAllProposals": "See all proposals",
"createdBy": "Created by",
"proposalInfoCard": {
Expand Down
2 changes: 1 addition & 1 deletion apps/davi/src/Modules/Guilds/pages/Proposal/Proposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const ProposalPage: React.FC = () => {
marginTop={'5px;'}
>
<FaChevronLeft style={{ marginRight: '15px' }} />{' '}
{t('proposal.backToDiscussion')}
{t('proposal.originalDiscussion')}
</IconButton>
</StyledLink>
) : (
Expand Down
91 changes: 42 additions & 49 deletions apps/davi/src/clients/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,70 @@ import {
InMemoryCache,
NormalizedCacheObject,
} from '@apollo/client';
import { SupportedSubgraphs } from 'stores/types';
import { SUPPORTED_DAVI_NETWORKS } from 'utils';
import { SupportedSubgraph } from 'stores/types';
import { CHAIN_ID, MAINNET_ID } from 'utils';

// FIX: Add subgraphs URIs here
export const subgraphClientsUris: {
[chainId in SUPPORTED_DAVI_NETWORKS]: {
[supportedSubgraph in SupportedSubgraphs]: string;
};
} = {
[SUPPORTED_DAVI_NETWORKS.MAINNET_ID]: {
Guilds: '',
'Governance1.5': '',
export const subgraphClientsUris: Record<
CHAIN_ID,
Record<SupportedSubgraph, string>
> = {
[CHAIN_ID.MAINNET]: {
[SupportedSubgraph.Guilds]: '',
[SupportedSubgraph.Governance1_5]: '',
},
[SUPPORTED_DAVI_NETWORKS.ARBITRUM_ID]: {
Guilds: '',
'Governance1.5': '',
[CHAIN_ID.ARBITRUM]: {
[SupportedSubgraph.Guilds]: '',
[SupportedSubgraph.Governance1_5]: '',
},
[SUPPORTED_DAVI_NETWORKS.GNOSIS_ID]: {
[CHAIN_ID.GNOSIS]: {
Guilds: process.env.REACT_APP_DXGOV_GUILD_GRAPHQL_ENDPOINT_GNOSIS,
'Governance1.5': process.env.REACT_APP_DXGOV_DAO_GRAPHQL_ENDPOINT_GNOSIS,
},
// testnets
[SUPPORTED_DAVI_NETWORKS.ARBITRUM_TESTNET_ID]: {
Guilds: '',
'Governance1.5': '',
[CHAIN_ID.ARBITRUM_TESTNET]: {
[SupportedSubgraph.Guilds]: '',
[SupportedSubgraph.Governance1_5]: '',
},
[SUPPORTED_DAVI_NETWORKS.GOERLI_ID]: {
Guilds: '',
'Governance1.5': '',
[CHAIN_ID.GOERLI]: {
[SupportedSubgraph.Guilds]: '',
[SupportedSubgraph.Governance1_5]: '',
},
[SUPPORTED_DAVI_NETWORKS.LOCALHOST_ID]: {
[CHAIN_ID.LOCALHOST]: {
Guilds: 'http://127.0.0.1:8000/subgraphs/name/dxdao/guilds',
'Governance1.5': 'http://127.0.0.1:8000/subgraphs/name/dxdao/dao',
},
};

const setupApolloClient = (network: SUPPORTED_DAVI_NETWORKS) => {
const setupApolloClient = (chainId: CHAIN_ID) => {
return {
Guilds: new ApolloClient({
uri: subgraphClientsUris[network]['Guilds'],
[SupportedSubgraph.Guilds]: new ApolloClient({
uri: subgraphClientsUris[chainId][SupportedSubgraph.Guilds],
cache: new InMemoryCache(),
}),
'Governance1.5': new ApolloClient({
uri: subgraphClientsUris[network]['Governance1.5'],
[SupportedSubgraph.Governance1_5]: new ApolloClient({
uri: subgraphClientsUris[chainId][SupportedSubgraph.Governance1_5],
cache: new InMemoryCache(),
}),
};
};

export const apolloClient: {
[chainId in SUPPORTED_DAVI_NETWORKS]: {
[supportedSubgraph in SupportedSubgraphs]: ApolloClient<NormalizedCacheObject>;
};
} = {
[SUPPORTED_DAVI_NETWORKS.MAINNET_ID]: setupApolloClient(
SUPPORTED_DAVI_NETWORKS.MAINNET_ID
),
[SUPPORTED_DAVI_NETWORKS.GNOSIS_ID]: setupApolloClient(
SUPPORTED_DAVI_NETWORKS.GNOSIS_ID
),
[SUPPORTED_DAVI_NETWORKS.ARBITRUM_ID]: setupApolloClient(
SUPPORTED_DAVI_NETWORKS.ARBITRUM_ID
),
export const apolloClient: Record<
CHAIN_ID,
Record<SupportedSubgraph, ApolloClient<NormalizedCacheObject>>
> = {
[CHAIN_ID.MAINNET]: setupApolloClient(CHAIN_ID.MAINNET),
[CHAIN_ID.GNOSIS]: setupApolloClient(CHAIN_ID.GNOSIS),
[CHAIN_ID.ARBITRUM]: setupApolloClient(CHAIN_ID.ARBITRUM),
// testnets
[SUPPORTED_DAVI_NETWORKS.GOERLI_ID]: setupApolloClient(
SUPPORTED_DAVI_NETWORKS.GOERLI_ID
),
[SUPPORTED_DAVI_NETWORKS.ARBITRUM_TESTNET_ID]: setupApolloClient(
SUPPORTED_DAVI_NETWORKS.ARBITRUM_TESTNET_ID
),
[SUPPORTED_DAVI_NETWORKS.LOCALHOST_ID]: setupApolloClient(
SUPPORTED_DAVI_NETWORKS.LOCALHOST_ID
),
[CHAIN_ID.GOERLI]: setupApolloClient(CHAIN_ID.GOERLI),
[CHAIN_ID.ARBITRUM_TESTNET]: setupApolloClient(CHAIN_ID.ARBITRUM_TESTNET),
[CHAIN_ID.LOCALHOST]: setupApolloClient(CHAIN_ID.LOCALHOST),
};

export const getApolloClient = (
subgraph: SupportedSubgraph,
chainId: CHAIN_ID = MAINNET_ID
) => {
return apolloClient?.[chainId]?.[subgraph];
};
12 changes: 6 additions & 6 deletions apps/davi/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import 'react-toastify/dist/ReactToastify.css';
import { useNetwork, WagmiConfig } from 'wagmi';
import EnsureReadOnlyConnection from 'components/Web3Modals/EnsureReadOnlyConnection';
import SyncRouterWithWagmi from 'components/Web3Modals/SyncRouterWithWagmi';
import { useEffect, useMemo } from 'react';
import { useEffect } from 'react';
import { loadFathom } from 'analytics/fathom';
import { SITE_ID } from 'configs';
import { ApolloProvider } from '@apollo/client';
import { apolloClient } from 'clients/apollo';
import { getApolloClient } from 'clients/apollo';
import { wagmiClient } from 'clients/wagmi';
import { DEFAULT_CHAIN_ID } from 'utils';
import { SupportedSubgraph } from 'stores/types';

initializeI18Next();

Expand All @@ -30,8 +30,6 @@ moment.updateLocale('en', {
const Root = () => {
const { chain } = useNetwork();

const chainId = useMemo(() => chain?.id || DEFAULT_CHAIN_ID, [chain]);

useEffect(() => {
loadFathom(SITE_ID)
.then(() => {
Expand All @@ -43,7 +41,9 @@ const Root = () => {
}, []);

return (
<ApolloProvider client={apolloClient[chainId]['Guilds']}>
<ApolloProvider
client={getApolloClient(SupportedSubgraph.Guilds, chain?.id)}
>
<WagmiConfig client={wagmiClient}>
<HashRouter>
<SyncRouterWithWagmi>
Expand Down
4 changes: 2 additions & 2 deletions apps/davi/src/stores/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ export const HookStoreProvider: React.FC<
}, [daoBytecodeHash, dataSource]);

useEffect(() => {
const getDataSourceAvailability = () => {
const getDataSourceAvailability = async () => {
if (governanceType) {
const isDefaultSourceAvailable =
governanceType.checkDataSourceAvailability(chain?.id);
await governanceType.checkDataSourceAvailability(chain?.id);
if (isDefaultSourceAvailable && dataSource !== 'primary') {
setTargetDataSource('primary');
}
Expand Down
50 changes: 47 additions & 3 deletions apps/davi/src/stores/modules/1_5/checkDataSourceAvailability.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
import { subgraphClientsUris } from 'clients/apollo';
import { SupportedSubgraph } from 'stores/types';

// TODO: Check for health of connection if found
export const checkDataSourceAvailability = async chainId => {
try {
if (!!subgraphClientsUris?.[chainId]?.[SupportedSubgraph.Governance1_5]) {
console.debug('No subgraph URL for this chain, using fallback');
return false;
}

export const checkDataSourceAvailability = chainId => {
return !!subgraphClientsUris[chainId]['Governance1.5'];
const query = `{
_meta {
block {
number
timestamp
}
}
}`;

const response = await fetch(
subgraphClientsUris[chainId][SupportedSubgraph.Governance1_5],
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query }),
}
);
const { data, errors } = await response.json();

if (data?._meta?.block?.timestamp < Math.floor(Date.now() / 1000) - 600) {
console.debug('Subgraph out of sync, using fallback');
return false;
}
if (errors) {
console.debug('Error occurred checking source health');
console.error(errors);
return false;
}
if (data) {
console.debug('Subgraph exists and is above 10 minutes in sync');
return true;
} else {
console.debug('No default data source data, using fallback');
return false;
}
} catch {
return false;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ import {
getDaoPermissionsQuery,
} from '.graphclient';
import { useQuery } from '@apollo/client';
import { apolloClient } from 'clients/apollo';
import { getApolloClient } from 'clients/apollo';
import { BigNumber } from 'ethers';
import { useMemo } from 'react';
import { FetcherHooksInterface } from 'stores/types';
import { SUPPORTED_DAVI_NETWORKS } from 'utils';
import { FetcherHooksInterface, SupportedSubgraph } from 'stores/types';
import { useNetwork } from 'wagmi';

type IUseGetAllPermissions = FetcherHooksInterface['useGetAllPermissions'];

export const useGetAllPermissions: IUseGetAllPermissions = daoId => {
const { chain } = useNetwork();
const chainId: SUPPORTED_DAVI_NETWORKS = useMemo(() => chain?.id, [chain]);

const { data, loading, error } = useQuery<getDaoPermissionsQuery>(
getDaoPermissionsDocument,
{
client: apolloClient[chainId]['Governance1.5'],
client: getApolloClient(SupportedSubgraph.Guilds, chain?.id),
variables: { id: daoId?.toLowerCase() },
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { useMemo } from 'react';
import { useQuery } from '@apollo/client';
import { useNetwork } from 'wagmi';
import { FetcherHooksInterface } from 'stores/types';
import { apolloClient } from 'clients/apollo';
import { SUPPORTED_DAVI_NETWORKS } from 'utils';
import { FetcherHooksInterface, SupportedSubgraph } from 'stores/types';
import { getApolloClient } from 'clients/apollo';
import { getMemberList1_5Document, getMemberList1_5Query } from '.graphclient';
import { BigNumber } from 'ethers';

type IUseGetMemberList = FetcherHooksInterface['useGetMemberList'];

export const useGetMemberList: IUseGetMemberList = (daoId: string) => {
const { chain } = useNetwork();
const chainId: SUPPORTED_DAVI_NETWORKS = useMemo(() => chain?.id, [chain]);

const { data, loading, error } = useQuery<getMemberList1_5Query>(
getMemberList1_5Document,
{
client: apolloClient[chainId]['Governance1.5'],
client: getApolloClient(SupportedSubgraph.Guilds, chain?.id),
variables: { id: daoId?.toLowerCase() },
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useMemo } from 'react';
import { BigNumber } from 'ethers';
import { useNetwork } from 'wagmi';
import { useQuery } from '@apollo/client';
Expand All @@ -7,25 +6,23 @@ import {
getDaoNumberOfActiveProposalsDocument,
getDaoNumberOfActiveProposalsQuery,
} from '.graphclient';
import { SUPPORTED_DAVI_NETWORKS } from 'utils';
import { apolloClient } from 'clients/apollo';
import { FetcherHooksInterface } from 'stores/types';
import { getApolloClient } from 'clients/apollo';
import { FetcherHooksInterface, SupportedSubgraph } from 'stores/types';

type IUseGetNumberOfActiveProposals =
FetcherHooksInterface['useGetNumberOfActiveProposals'];

export const useGetNumberOfActiveProposals: IUseGetNumberOfActiveProposals =
daoId => {
const { chain } = useNetwork();
const chainId: SUPPORTED_DAVI_NETWORKS = useMemo(() => chain?.id, [chain]);

// TODO: This query gets all "Submitted" proposals. We should define what an active proposal is, and fetch accordingly

const { data, error, loading } =
useQuery<getDaoNumberOfActiveProposalsQuery>(
getDaoNumberOfActiveProposalsDocument,
{
client: apolloClient[chainId]['Governance1.5'],
client: getApolloClient(SupportedSubgraph.Guilds, chain?.id),
variables: {
id: daoId?.toLowerCase(),
},
Expand Down
Loading

1 comment on commit daf205a

@vercel
Copy link

@vercel vercel bot commented on daf205a Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.