Skip to content

Commit

Permalink
fixed plausible & quest chains url
Browse files Browse the repository at this point in the history
  • Loading branch information
dan13ram committed Mar 15, 2023
1 parent 75a3c56 commit 78d851d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
16 changes: 10 additions & 6 deletions lib/mongodb/client.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { Db, MongoClient } from 'mongodb';

import { EnvironmentError } from '@/utils/errors';

if (!process.env.MONGODB_URI) {
throw new Error('Invalid/Missing environment variable: "MONGODB_URI"');
throw new EnvironmentError('MONGODB_URI');
}

const MONGODB_URI = process.env.MONGODB_URI;

if (!process.env.MONGODB_DATABASE) {
throw new Error('Invalid/Missing environment variable: "MONGODB_DATABASE"');
throw new EnvironmentError('MONGODB_DATABASE');
}

const MONGODB_DATABASE = process.env.MONGODB_DATABASE;

declare const global: {
_clientPromise: Promise<Db>;
};

const uri = process.env.MONGODB_URI;
const database = process.env.MONGODB_DATABASE;
const options = {};

let clientPromise: Promise<Db>;
Expand Down Expand Up @@ -42,10 +46,10 @@ export const initIndexes = async (client: Db): Promise<Db> => {
};

const createClientPromise = async (): Promise<Db> => {
const client = new MongoClient(uri, options);
const client = new MongoClient(MONGODB_URI, options);
return client
.connect()
.then((client: MongoClient) => client.db(database))
.then((client: MongoClient) => client.db(MONGODB_DATABASE))
.then(initIndexes);
};

Expand Down
3 changes: 2 additions & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Toaster } from 'react-hot-toast';
import { hotjar } from 'react-hotjar';

import { AppLayout } from '@/components/Layout/AppLayout';
import { PLAUSIBLE_DATA_DOMAIN } from '@/utils/constants';
import { globalStyles, theme } from '@/utils/theme';
import { WalletProvider } from '@/web3';

Expand Down Expand Up @@ -44,7 +45,7 @@ const App = ({ Component, pageProps }: AppProps): JSX.Element => {
<Script
type="text/javascript"
defer
data-domain="questchains.xyz"
data-domain={PLAUSIBLE_DATA_DOMAIN}
data-api="/jjmahtdkrp/api/event"
src="/jjmahtdkrp/js/script.js"
/>
Expand Down
30 changes: 20 additions & 10 deletions utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import { graphql } from '@quest-chains/sdk';

/* eslint-disable @typescript-eslint/no-non-null-assertion */
export const INFURA_ID = process.env.NEXT_PUBLIC_INFURA_ID!;
import { EnvironmentError } from './errors';

export const SUPPORTED_NETWORKS = process.env
.NEXT_PUBLIC_SUPPORTED_NETWORKS!.split(' ')
.filter(n => !!n && !Number.isNaN(Number(n)))
.map(n => `0x${Number(n).toString(16)}`)
.filter(n => graphql.SUPPORTED_NETWORKS.includes(n));
if (!process.env.NEXT_PUBLIC_INFURA_ID)
throw new EnvironmentError('NEXT_PUBLIC_INFURA_ID');

export const INFURA_ID = process.env.NEXT_PUBLIC_INFURA_ID;

if (!process.env.NEXT_PUBLIC_SUPPORTED_NETWORKS)
throw new EnvironmentError('NEXT_PUBLIC_SUPPORTED_NETWORKS');

export const SUPPORTED_NETWORKS =
process.env.NEXT_PUBLIC_SUPPORTED_NETWORKS.split(' ')
.filter(n => !!n && !Number.isNaN(Number(n)))
.map(n => `0x${Number(n).toString(16)}`)
.filter(n => graphql.SUPPORTED_NETWORKS.includes(n));

export const API_URL =
process.env.NEXT_PUBLIC_API_URL || 'https://api.questchains.xyz';

export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

export const QUESTCHAINS_URL =
process.env.NEXT_PUBLIC_QUESTCHAINS_URL || 'https://questchains.xyz';
process.env.NEXT_PUBLIC_QUESTCHAINS_URL || 'https://app.questchains.xyz';

export const PLAUSIBLE_DATA_DOMAIN =
process.env.NEXT_PUBLIC_PLAUSIBLE_DATA_DOMAIN || 'app.questchains.xyz';

export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
7 changes: 7 additions & 0 deletions utils/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class EnvironmentError extends Error {
public errorType = 'EnvironmentError';

constructor(envVar: string) {
super(`Invalid/Missing environment variable: "${envVar}"`);
}
}

0 comments on commit 78d851d

Please sign in to comment.