In order to work on Pioneer 2 you'll need following tools for development and testing:
- nodejs
v14.x
- yarn classic package manager
v1.22.x
In order to interact with the Joystream ecosystem
- Joystream node optional
- Joystream query-node optional
The Pioneer 2.0 is build using the latest version of React. The React development assumes:
- TypeScript 4.x – using
sctrict:true
- Function components & hooks
- styled components for CSS
Libraries
- Apollo client - to interact with GraphQL
- CKEditor 5 as Markdown editor
- xstate state management for complex flows in modals
- Yup validation (partially)
- date-fns to interact with dates
- React libraries for: routing, pagination, breadcrumbs, dropzone, etc (see package.json)
Note: To read about the Pioneer 2 architecture & key concepts see Pioneer 2 readme
The package.json entries for @polkadot/*
packages must be set to the exact versions in order to match Joystream dependencies. See resolutions
section in package.json for details. Keeping dependencies in sync prevents "duplicated instances" error while using Polkadot.js API.
The build scripts uses webpack directly (no CRA) as it integrates better with custom webpack extensions (build CKEditor, etc.).
As the Storybook uses Babel a shared webpack configuration for both webpack and storybook was introduced.
To build the project in a development mode using webpack dev server:
yarn run start
To build a production ready version:
yarn run build
For code quality & standards we rely on ESLint and Prettier. To run both checks execute inside packages/ui
:
## Run linter
yarn lint
## Run lint & apply automatic fixes
yarn lint:fix
Both - the testnet & local development environment expects that a Joystream node instance is available.
Expected URIs:
- local:
ws://127.0.0.1:9944
- testnet:
wss://olympia-dev.joystream.app
Since the local query-node operates on mocks all of the query-node mocked entities are not present on-chain.
Also, any The second limitation is that any on-chain action is not represented in the query-node mocks.
See mocking on how to work with local mocks for development and tests.
The joystream node should be started in a development mode:
joystream-node --dev --tmp --unsafe-ws-external --unsafe-rpc-external --rpc-cors=all --log runtime
The development version uses well-known accounts to store JOY tokens and where Alice
is a Sudo account. See tips on how to add them to the extension.
To access the archival state of the chain Pioneer 2 fetch such information from the query-node. It is a GraphQL server that allows a convenient API for querying the data.
The following tools are used to consume GraphQL data:
- Apollo Client for accessing GraphQL
To fetch the data from a GraphQL we use code generated by GraphQL Code Generator
To generate scripts run:
yarn run queries:generate
The queries are organized as below:
- The query-node schema is stored under @/common/api/schema.graphql
- GraphQL's queries are stored per every module, inside
@/module/queries/
folder - you only need to modify those. - The
graphq-codegen
will generate React hooks for Apollo Client (plugintypescript-react-apollo
) that will be exposed as@/module/queries
import.
For instance, to query for memberships
:
Create a @/memberships/queries/members.graphql
file:
query GetMembers {
memberships {
id
handle
}
}
Then run the yarn run queries:generate
script.
Use the generated hook in your code:
import { useGetMembersQuery } from '@/memberships/queries'
const { loading, data } = useGetMembersQuery()
Some GraphQL related tools use code generation to scaffold types and react hooks from GraphQL schemas and queries.
After updating packages/ui/src/api
any of *.graphql
files run yarn queries:generated
script in the UI package.
You can use the Polkadot apps wallet to browse the Joystream node state and call all available extrinsic.
In order to use the app with Joystream API types you need to upload the correct type defs.json
from the Joystream repo (using proper branch as well). The full path to file is: /types/augment/all/defs.json
.
For the olympia_dev
branch the defs.json
use this link:
- Copy the contents of the
raw view
. - Paste to the input on Settings > Developer tab
- Switch to a network
Substrate defines well-known accounts for Alice
, Alice_Stash
, Bob
, Bob_Stash
, Charlie
, Dave
, Eve
and Ferdie
.
To add any of the above:
- Open extension and click plus sign
- Select "Import account from pre-existing seed"
- Copy the seed from substrate help page as "existing mnemonic seed"
- Open advanced and type the derivation path:
- For
Alice
,Bob
,Charlie
,Dave
,Eve
&Ferdie
use the name as path, e.g.//Eve
- For
Alice_Stash
andBob_Stash
use//stash
after name, e.g.://Bob//stash
By default, only Alice
, Alice_Stash
, Bob
and Bob_Stash
accounts has any funds.