Skip to content

Commit 3d2ee26

Browse files
authored
Merge pull request #73 from eonian-core/feature/add-contract-graph-api-mock
Add contract Graph API mock
2 parents 5bb4ebd + 24222aa commit 3d2ee26

25 files changed

+3221
-126
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Check dApp API compatibility
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "packages/web/schema.graphql"
9+
10+
pull_request:
11+
branches:
12+
- main
13+
types:
14+
- opened
15+
- synchronize
16+
paths:
17+
- "packages/web/schema.graphql"
18+
19+
jobs:
20+
check:
21+
name: Check GraphQL schema compatibility
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- uses: actions/checkout@v3
26+
with:
27+
submodules: recursive
28+
29+
- name: Setup NodeJS
30+
uses: actions/setup-node@v2
31+
with:
32+
node-version: "16"
33+
cache: "yarn"
34+
35+
- name: Install dependencies
36+
run: yarn --ignore-scripts
37+
38+
- name: Generate types
39+
run: |-
40+
cd packages/web
41+
yarn gen:gql-types
42+
43+
- name: Build dApp
44+
run: |-
45+
cd packages/web
46+
yarn build
47+

.github/workflows/verify-dapp.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Verify dApp
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "packages/web/**"
9+
10+
pull_request:
11+
branches:
12+
- main
13+
types:
14+
- opened
15+
- synchronize
16+
paths:
17+
- "packages/web/**"
18+
19+
jobs:
20+
# Add linting job after migration to nextjs version with given fix https://github.com/vercel/next.js/issues/44424
21+
22+
test:
23+
name: Test dApp
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- uses: actions/checkout@v3
28+
with:
29+
submodules: recursive
30+
31+
- name: Setup NodeJS
32+
uses: actions/setup-node@v2
33+
with:
34+
node-version: "16"
35+
cache: "yarn"
36+
37+
- name: Install dependencies
38+
run: yarn --ignore-scripts
39+
40+
- name: Run tests
41+
run: |-
42+
cd packages/web
43+
yarn test:ci
44+
45+

.github/workflows/on-pr-for-contracts.yaml renamed to .github/workflows/verify-smart-contracts.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
name: Verify Contracts PR
1+
name: Verify Smart Contracts
22

33
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "packages/contracts/**"
9+
410
pull_request:
511
branches:
612
- main

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Yield Aggregator dApp and protocol for safe and high reward liquidity mining
66

77
This mono-repository contains protocol contracts and dApp code, as well as all related packages.
88

9+
For a list of known development issues related to Lerna monorepo, see [development.md](https://github.com/eonian-core/farm/tree/main/development.md).
10+
911
### Structure
1012

1113
* `packages/contracts` - Protocol contracts.
@@ -43,6 +45,9 @@ yarn
4345
* `yarn test:contracts` - Test only contracts
4446
* `dev:contracts` - Set up a development environment for contracts. Watch file changes and rerun tests.
4547

48+
49+
50+
4651
## Deployment
4752

4853
The deployment process focused on implementing GitOps practices. Basically, it means all master (main) builds go to production directly. For a web application, PRs also deploy to a preview environment.

development.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Known Development Issues
2+
3+
## Installation of dependencies
4+
5+
Fail during installation of dependency in one of the packages.
6+
Example `error An unexpected error occurred: "expected workspace package to exist for \"yargs\"".`
7+
8+
Issue still not fixed by yarn: https://github.com/yarnpkg/yarn/issues/7734.
9+
10+
### Solution
11+
12+
Go to the root directory and run `yarn workspace [package-name] add ...` to add the package. Use `@eonian/web` as the package name for the web package and `@eonian/contracts` for the contracts package.
13+
14+
## Graphql types code generation
15+
16+
Fail during code generation of graphql types.
17+
Example:
18+
19+
```bash
20+
Cannot use GraphQLScalarType "BigDecimal" from another module or realm.
21+
Ensure that there is only one instance of "graphql" in the node_modules
22+
```
23+
24+
Remove `nohoist` from the root `package.json`, delete node_modules in root and all packages, and run `yarn` again. Be aware, removing `nohoist` can cause failures in contracts package.
25+
26+
## Jest is not working properly with ESM modules
27+
28+
Jest is not working properly with ESM modules. It fails to run tests by using the normal `jest` command in the web package.
29+
30+
### Solution
31+
32+
Add a command which enables ESM modules for node and then run jest. For web package it is `yarn jest`

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "root",
2+
"name": "eonian",
33
"private": true,
44
"scripts": {
55
"bootstrap": "lerna bootstrap --use-workspaces",
@@ -20,10 +20,6 @@
2020
"packages/*"
2121
],
2222
"nohoist": [
23-
"**/ts-node",
24-
"**/ts-node/**",
25-
"**/typescript",
26-
"**/typescript/**",
2723
"**/typechain",
2824
"**/typechain/**",
2925
"**/@typechain",
@@ -44,5 +40,9 @@
4440
"generate-lockfile": "^0.0.12",
4541
"lerna": "^5.1.6",
4642
"nx": "^14.3.6"
43+
},
44+
"dependencies": {
45+
"glob": "^8.0.1",
46+
"yargs": "^17.6.2"
4747
}
4848
}

packages/web/.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
# Feature Flags
2+
13
NEXT_PUBLIC_FEATURE_FAQ_PAGE=true
24
NEXT_PUBLIC_FEATURE_COMMUNITY_PAGE=true
35
NEXT_PUBLIC_FEATURE_MISSION_PAGE=true
46
NEXT_PUBLIC_FEATURE_SECURITY_PAGE=true
7+
8+
# API
9+
NEXT_PUBLIC_GRAPH_URL=http://localhost:4000

packages/web/README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,38 @@ yarn dev
1818

1919
It will start
2020

21-
* NextJS application at [http://localhost:3000](http://localhost:3000) and open page automatically
21+
* NextJS application at [http://localhost:3000](http://localhost:3000) and the open page automatically
2222
* Storybook at [http://localhost:6006](http://localhost:6006) or another port of it is busy
2323

2424
### Storybook
2525

26-
For development of components and independent screens there used Stroybook.
27-
To start it locally use the following command:
26+
For the development of components and independent screens, there used Storybook.
27+
To start it locally, use the following command:
2828

2929
```bash
3030
yarn storybook
3131
```
3232

33+
### GraphQl API
34+
35+
For querying data from the blockchain and other services, there used GraphQL API.
36+
37+
#### Mocking Server
38+
39+
The mocking server allows mocking this API for development purposes. To start it locally, use the following command:
40+
41+
```bash
42+
yarn mock
43+
```
44+
45+
#### Generate Introspection Types
46+
47+
To generate types for the GraphQL API, use the following command:
48+
49+
```bash
50+
yarn gen:gql-types
51+
```
52+
3353
### CDN
3454

3555
* <https://vercel.com/eonian/farm-app> - Web app project in Vercel
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ApolloClient, InMemoryCache, MutationOptions, OperationVariables, QueryOptions } from '@apollo/client';
2+
3+
export const client = new ApolloClient({
4+
uri: process.env.GRAPH_URL || 'http://localhost:4000/',
5+
cache: new InMemoryCache(),
6+
});
7+
8+
export const query = async <T = any, TVariables extends OperationVariables = OperationVariables>(options: QueryOptions<TVariables, T>) =>
9+
client.query<T, TVariables>(options);
10+
11+
export const mutate = async <TData = any, TVariables extends OperationVariables = OperationVariables, TContext extends Record<string, any> = Record<string, any>, TCache extends InMemoryCache = InMemoryCache>(options: MutationOptions<TData, TVariables, TContext>) =>
12+
client.mutate<TData, TVariables, TContext, TCache>(options);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { gql } from '@apollo/client';
2+
import { query } from './apollo.client';
3+
import {GetVaultsQuery} from './gql/graphql';
4+
5+
export const GetVaults = gql`
6+
query GetVaults {
7+
vaults {
8+
underlyingAsset {
9+
address
10+
name
11+
symbol
12+
decimals
13+
}
14+
totalBalance
15+
interestRate
16+
lastHarvestTime
17+
address
18+
name
19+
symbol
20+
decimals
21+
}
22+
}
23+
`;
24+
25+
export type {GetVaultsQuery}
26+
27+
/**
28+
* Get list of Vaults
29+
* @example getVaults().then(console.log)
30+
* */
31+
export const getVaults = () => query<GetVaultsQuery>({ query: GetVaults })

0 commit comments

Comments
 (0)