Skip to content

Commit

Permalink
feat: Generate client config from user defined 'config/' files
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Diaz committed Jan 7, 2021
1 parent c75df26 commit 9aa59f9
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 115 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ build/Release
# production
/client/build
config/minter.mainnet.json
client/src/config.json

# misc
**/.DS_Store
Expand Down
8 changes: 6 additions & 2 deletions client/src/components/App/globalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import React, {
} from 'react';

import { TezosToolkit } from '@taquito/taquito';
import config from '../../config';
import config from '../../config.json';
import mkContracts, { Contracts } from '../../api/contracts';
import { BeaconWallet } from '@taquito/beacon-wallet';
import { mkBetterCallDev, BetterCallDev } from '../../resolvers/betterCallDev';
import { BetterCallDev } from '../../resolvers/betterCallDev';

/* <TODO: Use state reducer with global context to manage actions & application dependencies> */

type GlobalActions =
| {
Expand Down Expand Up @@ -58,6 +60,8 @@ const GlobalContext = createContext<IGlobalContext>({
dispatch: (_action: GlobalActions) => null
});

/* </END TODO> */

type Toolkit = [TezosToolkit, BeaconWallet] | undefined;

const TzToolkitContext = createContext<Toolkit>(undefined);
Expand Down
5 changes: 3 additions & 2 deletions client/src/components/AssetDetailsPage/AssetDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { jsx } from '@emotion/core';
import { Description, ParamName, ParamValue } from './Typography';
import { NonFungibleToken } from '../../generated/graphql_schema';
import { Skeleton } from 'antd';
import config from '../../config';

const TZKT_AVATAR_URL = 'https://services.tzkt.io/v1/avatars2/';

const AssetDescription: FC<{ nft?: NonFungibleToken }> = ({ nft }) => (
<Fragment>
Expand All @@ -31,7 +32,7 @@ const AssetDescription: FC<{ nft?: NonFungibleToken }> = ({ nft }) => (

<ParamValue>
<img
src={url.resolve(config.tzktAvatarUrl, nft.owner)}
src={url.resolve(TZKT_AVATAR_URL, nft.owner)}
css={{ width: '2.5em' }}
alt=""
/>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/AssetsPage/AssetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { NonFungibleToken } from '../../generated/graphql_schema';
import { urlFromCid } from '../../api/ipfsUploader';
import AssetTransfer from './AssetTransfer';
import { useContracts } from '../App/globalContext';
import config from '../../config';
import config from '../../config.json';
import { useLocation } from 'wouter';

const { Paragraph, Text, Link } = Typography;
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/WalletConnector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { message } from 'antd';

import HeaderButton from '../common/HeaderButton';
import { useTzToolkit, useTzToolkitSetter } from '../App/globalContext';
import config from '../../config';
import config from '../../config.json';
import * as beaconWallet from './beaconWallet';

const WalletConnector: FC = () => {
Expand Down
12 changes: 0 additions & 12 deletions client/src/config.ts

This file was deleted.

19 changes: 0 additions & 19 deletions client/src/config/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion client/src/hooks/useContractNamesQuery.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import useAsync from '../utils/useAsync';
import { contractNames } from '../resolvers/contractNames';
import config from '../config';
import config from '../config.json';

export const useContractNamesQuery = (
contractOwnerAddress?: string,
Expand Down
2 changes: 1 addition & 1 deletion client/src/hooks/useNftsQuery.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useWalletAddress } from '../components/App/globalContext';
import useAsync from '../utils/useAsync';
import { nfts } from '../resolvers/nfts';
import config from '../config';
import config from '../config.json';

export const useNftsQuery = (contractAddress?: string) => {
const ownerAddress = useWalletAddress();
Expand Down
2 changes: 1 addition & 1 deletion client/src/utils/waitForConfirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { OperationStatus } from '../generated/graphql_schema';
import { pollUntilTrue, sleep } from './polling';
import { contractOperationStatus } from '../resolvers/contractOperationStatus';
import { indexerStats } from '../resolvers/indexerStats';
import config from '../config';
import config from '../config.json';

export const getContractOperationStatus = async (
contractAddress: string,
Expand Down
3 changes: 3 additions & 0 deletions config/minter.mainnet.example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"rpc": "https://mainnet-tezos.giganode.io",
"bcdApiUrl": "https://api.better-call.dev",
"bcdGuiUrl": "https://better-call.dev",
"bcdNetwork": "mainnet",
"admin": {
"address": "<YOUR_TZ_PUBLIC_ADDRESS_HERE>",
"secret": "<YOUR_TZ_PRIVATE_KEY_HERE>"
Expand Down
5 changes: 4 additions & 1 deletion config/minter.sandbox.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"rpc": "http://localhost:8732",
"bcdApiUrl": "http://bcdapi:14000",
"bcdGuiUrl": "http://localhost:8009",
"bcdNetwork": "sandboxnet",
"admin": {
"address": "tz1YPSCGWXwBdTncK2aCctSZAXWvGsGwVJqU",
"secret": "edsk3RFgDiCt7tWB2oe96w1eRw72iYiiqZPLu9nnEY23MYRp2d8Kkx"
Expand All @@ -8,4 +11,4 @@
"nftFaucet": "KT1Lp5D8P8mvtruemGJZBMNJoWKoTAo4jf3A",
"nftFactory": "KT1LxCuAQ8xPuafkULT82ZgrTNLSmVHPuHap"
}
}
}
3 changes: 3 additions & 0 deletions config/minter.testnet.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"rpc": "https://delphinet-tezos.giganode.io",
"bcdApiUrl": "https://api.better-call.dev",
"bcdGuiUrl": "https://better-call.dev",
"bcdNetwork": "delphinet",
"admin": {
"address": "tz1hs8oA8xjpEfrmqHedJ3Yv7KN355JFL3rW",
"secret": "edsk36qzuACZiucKjW3fXifeqSXPveA8ykR95banDK367vimMAC9ZR"
Expand Down
20 changes: 20 additions & 0 deletions contracts/src/bootstrap-contracts-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ async function main() {
await bootstrapNftFactory(config, toolkit);
//add bootstrapping of other contracts here

genClientConfig(config);

process.exit(0);
} catch (err) {
$log.error(`error while bootstrapping environment ${env}`);
Expand All @@ -28,6 +30,24 @@ async function main() {
}
}

function genClientConfig(mainConfig: Configstore) {
const configPath = path.join(__dirname, `../../client/src/config.json`);
const clientConfig = new Configstore('client', {}, { configPath });

const clientConfigKeys = [
'rpc',
'bcdApiUrl',
'bcdGuiUrl',
'bcdNetwork',
'contracts.nftFaucet',
'contracts.nftFactory'
];

for (let key of clientConfigKeys) {
clientConfig.set(key, mainConfig.get(key));
}
}

function getEnv(): string {
const env = process.env['TZ_NETWORK'];
if (!env) {
Expand Down
1 change: 0 additions & 1 deletion docker-stack/ui-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ services:
tty: true
volumes:
- ${PROJECT_ROOT_DIR}/client/src:/usr/src/app/client/src
- ${PROJECT_ROOT_DIR}/config:/usr/src/app/client/src/config/common
ports:
- 3000:3000
29 changes: 0 additions & 29 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,15 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@taquito/signer": "6.3.4-beta.0",
"@taquito/taquito": "6.3.4-beta.0",
"@types/bcrypt": "3.0.0",
"@types/configstore": "4.0.0",
"@types/cookie-parser": "1.4.2",
"@types/cryptr": "4.0.0",
"@types/express": "4.17.2",
"@types/express-fileupload": "1.1.5",
"@types/express-session": "1.17.0",
"@types/graphql-type-json": "0.3.2",
"@types/lodash": "4.14.149",
"@types/lru-cache": "5.1.0",
"@types/node": "12.12.9",
"@types/ramda": "0.27.27",
"apollo-server-express": "2.19.0",
"axios": "0.21.0",
"axios-retry": "3.1.9",
"bcrypt": "3.0.7",
"bignumber.js": "9.0.0",
"cids": "1.0.0",
"concurrently": "5.0.0",
"configstore": "5.0.1",
"cookie-parser": "1.4.4",
"cryptr": "6.0.1",
"express": "4.17.1",
"express-fileupload": "1.2.0",
"express-session": "1.17.0",
"graphql": "14.5.8",
"graphql-import": "1.0.2",
"graphql-type-json": "0.3.1",
"ipfs-http-client": "47.0.1",
"knex": "0.21.1",
"lodash": "4.17.15",
"lru-cache": "5.1.1",
"pg": "8.2.1",
"ramda": "0.27.1",
"sqlite3": "4.1.1",
"subscriptions-transport-ws": "0.9.16",
"ts-node": "8.5.0",
"typescript": "3.7.2"
},
Expand Down
44 changes: 0 additions & 44 deletions server/scripts/originate_contract.ts

This file was deleted.

0 comments on commit 9aa59f9

Please sign in to comment.