Skip to content
This repository was archived by the owner on Aug 20, 2020. It is now read-only.

Commit 0b123cf

Browse files
author
Dan Forbes
authored
Prettier (#33)
1 parent f699dda commit 0b123cf

File tree

43 files changed

+1282
-1007
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1282
-1007
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
name: Build App
22

3-
on:
3+
on:
44
push:
5-
branches:
5+
branches:
66
- master
77

88
jobs:
99
build:
10-
1110
runs-on: ubuntu-latest
1211

1312
steps:
14-
- name: Run a one-line script
15-
uses: peter-evans/repository-dispatch@v1
16-
with:
17-
token: ${{ secrets.ACCESS_TOKEN }}
18-
repository: paritytech/substrate.io
19-
event-type: content-update
20-
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
13+
- name: Run a one-line script
14+
uses: peter-evans/repository-dispatch@v1
15+
with:
16+
token: ${{ secrets.ACCESS_TOKEN }}
17+
repository: paritytech/substrate.io
18+
event-type: content-update
19+
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'

.prettierrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"printWidth": 100,
3+
"proseWrap": "always"
4+
}

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ Feel free to add an issue if there is documentation that you'd like to see. See
1515
[contributing guide](https://github.com/substrate-developer-hub/knowledge-base/blob/master/CONTRIBUTING.md)
1616
for guidance on making PRs.
1717

18+
### Prettier
19+
20+
This repository uses [Prettier](https://prettier.io/) to ensure consistent formatting. Please run
21+
Prettier before submitting any changes to the files in this repository. Prettier ships as an
22+
[NPM](https://www.npmjs.com/) package, so NPM must installed to use it. Prettier can be installed
23+
globally with `npm i -g prettier` in which case you can run `prettier --write .` in the project
24+
root. If you prefer not to install Prettier you can run it on-the-fly with `npx prettier --write .`.
25+
In either case, the `.prettierrc.json` file that ships with repository will be used to ensure
26+
consistent formatting.
27+
1828
## License
1929

2030
All documentation is under the

config.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"current_version": "v2.0.0-alpha.6",
3-
"display_order": [
4-
"create-your-first-substrate-chain",
5-
"build-a-dapp",
6-
"start-a-private-network",
7-
"add-a-pallet",
8-
"pallet-in-own-crate"
9-
]
2+
"current_version": "v2.0.0-alpha.6",
3+
"display_order": [
4+
"create-your-first-substrate-chain",
5+
"build-a-dapp",
6+
"start-a-private-network",
7+
"add-a-pallet",
8+
"pallet-in-own-crate"
9+
]
1010
}

tuts/add-a-pallet/config.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
2-
"slug": "config",
3-
"lang": "en",
4-
"title": "Add a Pallet to your Runtime",
5-
"excerpt": "Add the contracts pallet to your Substrate node template",
6-
"tags": [ "Medium", "2 Hours", "No Prerequisites" ],
7-
"versions": [ "v2.0.0-alpha.6", "v2.0.0-alpha.5" ],
8-
"menu": [
9-
{ "title": "Add a Pallet", "slug": "index" }
10-
]
2+
"slug": "config",
3+
"lang": "en",
4+
"title": "Add a Pallet to your Runtime",
5+
"excerpt": "Add the contracts pallet to your Substrate node template",
6+
"tags": ["Medium", "2 Hours", "No Prerequisites"],
7+
"versions": ["v2.0.0-alpha.6", "v2.0.0-alpha.5"],
8+
"menu": [{ "title": "Add a Pallet", "slug": "index" }]
119
}

tuts/add-a-pallet/v2.0.0-alpha.5/index.md

Lines changed: 139 additions & 56 deletions
Large diffs are not rendered by default.

tuts/add-a-pallet/v2.0.0-alpha.6/index.md

Lines changed: 134 additions & 54 deletions
Large diffs are not rendered by default.

tuts/build-a-dapp/config.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"slug": "config",
3-
"lang": "en",
4-
"title": "Build a PoE Decentralized Application",
5-
"excerpt": "Build a customized Substrate chain with its own user interface.",
6-
"tags": [ "Easy", "< 1 Hour", "Prerequisites" ],
7-
"versions": [ "v2.0.0-alpha.6", "v2.0.0-alpha.5" ],
8-
"menu": [
9-
{ "title": "Introduction", "slug": "index" },
10-
{ "title": "Prepare to build a dApp", "slug": "prepare" },
11-
{ "title": "Building a Custom Pallet", "slug": "pallet" },
12-
{ "title": "Building a Custom Front End", "slug": "front-end" }
13-
]
2+
"slug": "config",
3+
"lang": "en",
4+
"title": "Build a PoE Decentralized Application",
5+
"excerpt": "Build a customized Substrate chain with its own user interface.",
6+
"tags": ["Easy", "< 1 Hour", "Prerequisites"],
7+
"versions": ["v2.0.0-alpha.6", "v2.0.0-alpha.5"],
8+
"menu": [
9+
{ "title": "Introduction", "slug": "index" },
10+
{ "title": "Prepare to build a dApp", "slug": "prepare" },
11+
{ "title": "Building a Custom Pallet", "slug": "pallet" },
12+
{ "title": "Building a Custom Front End", "slug": "front-end" }
13+
]
1414
}

tuts/build-a-dapp/v2.0.0-alpha.5/front-end.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,28 @@ substrate-front-end-template
4848

4949
Delete the contents of that file, and instead use the following component.
5050

51-
52-
5351
```js
5452
// React and Semantic UI elements.
55-
import React, { useState, useEffect } from 'react';
56-
import { Form, Input, Grid, Message } from 'semantic-ui-react';
53+
import React, { useState, useEffect } from "react";
54+
import { Form, Input, Grid, Message } from "semantic-ui-react";
5755
// Pre-built Substrate front-end utilities for connecting to a node
5856
// and making a transaction.
59-
import { useSubstrate } from './substrate-lib';
60-
import { TxButton } from './substrate-lib/components';
57+
import { useSubstrate } from "./substrate-lib";
58+
import { TxButton } from "./substrate-lib/components";
6159
// Polkadot-JS utilities for hashing data.
62-
import { blake2AsHex } from '@polkadot/util-crypto';
60+
import { blake2AsHex } from "@polkadot/util-crypto";
6361

6462
// Our main Proof Of Existence Component which is exported.
65-
export default function ProofOfExistence (props) {
63+
export default function ProofOfExistence(props) {
6664
// Establish an API to talk to our Substrate node.
6765
const { api } = useSubstrate();
6866
// Get the "selected user" from the `AccountSelector` component.
6967
const { accountPair } = props;
7068
// React hooks for all the state variables we track.
7169
// Learn more at: https://reactjs.org/docs/hooks-intro.html
72-
const [status, setStatus] = useState('');
73-
const [digest, setDigest] = useState('');
74-
const [owner, setOwner] = useState('');
70+
const [status, setStatus] = useState("");
71+
const [digest, setDigest] = useState("");
72+
const [owner, setOwner] = useState("");
7573
const [block, setBlock] = useState(0);
7674

7775
// Our `FileReader()` which is accessible from our functions below.
@@ -81,15 +79,15 @@ export default function ProofOfExistence (props) {
8179
const bufferToDigest = () => {
8280
// Turns the file content to a hexadecimal representation.
8381
const content = Array.from(new Uint8Array(fileReader.result))
84-
.map(b => b.toString(16).padStart(2, '0'))
85-
.join('');
82+
.map((b) => b.toString(16).padStart(2, "0"))
83+
.join("");
8684

8785
const hash = blake2AsHex(content, 256);
8886
setDigest(hash);
8987
};
9088

9189
// Callback function for when a new file is selected.
92-
const handleFileChosen = file => {
90+
const handleFileChosen = (file) => {
9391
fileReader = new FileReader();
9492
fileReader.onloadend = bufferToDigest;
9593
fileReader.readAsArrayBuffer(file);
@@ -103,23 +101,23 @@ export default function ProofOfExistence (props) {
103101
// This is a subscription, so it will always get the latest value,
104102
// even if it changes.
105103
api.query.templateModule
106-
.proofs(digest, result => {
104+
.proofs(digest, (result) => {
107105
// Our storage item returns a tuple, which is represented as an array.
108106
setOwner(result[0].toString());
109107
setBlock(result[1].toNumber());
110108
})
111-
.then(unsub => {
109+
.then((unsub) => {
112110
unsubscribe = unsub;
113111
});
114112

115113
return () => unsubscribe && unsubscribe();
116-
// This tells the React hook to update whenever the file digest changes
117-
// (when a new file is chosen), or when the storage subscription says the
118-
// value of the storage item has updated.
114+
// This tells the React hook to update whenever the file digest changes
115+
// (when a new file is chosen), or when the storage subscription says the
116+
// value of the storage item has updated.
119117
}, [digest, api.query.templateModule]);
120118

121119
// We can say a file digest is claimed if the stored block number is not 0.
122-
function isClaimed () {
120+
function isClaimed() {
123121
return block !== 0;
124122
}
125123

@@ -132,10 +130,10 @@ export default function ProofOfExistence (props) {
132130
<Form.Field>
133131
{/* File selector with a callback to `handleFileChosen`. */}
134132
<Input
135-
type='file'
133+
type="file"
136134
id="file"
137135
label="Your File"
138-
onChange={e => handleFileChosen(e.target.files[0])}
136+
onChange={(e) => handleFileChosen(e.target.files[0])}
139137
/>
140138
{/* Show this message if the file is available to be claimed */}
141139
<Message success header="File Digest Unclaimed" content={digest} />
@@ -152,7 +150,7 @@ export default function ProofOfExistence (props) {
152150
and not already claimed. Updates the `status`. */}
153151
<TxButton
154152
accountPair={accountPair}
155-
label={'Create Claim'}
153+
label={"Create Claim"}
156154
setStatus={setStatus}
157155
type="TRANSACTION"
158156
attrs={{ params: [digest], tx: api.tx.templateModule.createClaim }}
@@ -170,14 +168,13 @@ export default function ProofOfExistence (props) {
170168
/>
171169
</Form.Field>
172170
{/* Status message about the transaction. */}
173-
<div style={{ overflowWrap: 'break-word' }}>{status}</div>
171+
<div style={{ overflowWrap: "break-word" }}>{status}</div>
174172
</Form>
175173
</Grid.Column>
176174
);
177175
}
178176
```
179177

180-
181178
We won't walk you step by step through the creation of this component, but do look over the code
182179
comments to learn what each part is doing.
183180

@@ -195,8 +192,8 @@ pallet, where this digest and the selected user account will be stored on chain.
195192
![Claimed File](../assets/poe-claimed.png)
196193

197194
If all went well, you should see a new `ClaimCreated` event appear in the Events component. The
198-
front-end automatically recognizes that your file is now claimed, and even gives you the option
199-
to revoke the claim if you want.
195+
front-end automatically recognizes that your file is now claimed, and even gives you the option to
196+
revoke the claim if you want.
200197

201198
Remember, only the owner can revoke the claim! If you select another user account at the top, and
202199
you will see that the revoke option is disabled!
@@ -205,22 +202,25 @@ you will see that the revoke option is disabled!
205202

206203
This is the end of our journey into creating a Proof of Existence blockchain.
207204

208-
You have seen first hand how simple it can be to develop a brand new pallet and launch a
209-
custom blockchain using Substrate. Furthermore, we have shown you that the Substrate ecosystem
210-
provides you with the tools to quickly create responsive front-end experiences so users can interact
211-
with your blockchain.
205+
You have seen first hand how simple it can be to develop a brand new pallet and launch a custom
206+
blockchain using Substrate. Furthermore, we have shown you that the Substrate ecosystem provides you
207+
with the tools to quickly create responsive front-end experiences so users can interact with your
208+
blockchain.
212209

213210
This tutorial chose to omit some of the specific details around development in order to keep this
214211
experience short and satisfying. However, we want you to keep learning!
215212

216-
To learn much more detail about building on the front-end template, please try the [Front End Tutorial](tutorials/substrate-front-end/index.md). To learn more about building your own pallets, explore the [Substrate Recipes](https://substrate.dev/recipes).
213+
To learn much more detail about building on the front-end template, please try the
214+
[Front End Tutorial](tutorials/substrate-front-end/index.md). To learn more about building your own
215+
pallets, explore the [Substrate Recipes](https://substrate.dev/recipes).
217216

218217
It would also be a good time to call out that your success on the Substrate framework will
219-
ultimately be limited on your ability to program in Rust. The [Rust
220-
Book](https://doc.rust-lang.org/book/) is a great resource for beginning and intermediate rust developers.
218+
ultimately be limited on your ability to program in Rust. The
219+
[Rust Book](https://doc.rust-lang.org/book/) is a great resource for beginning and intermediate rust
220+
developers.
221221

222-
If you experienced any issues with this tutorial or want to provide feedback, feel free to [open a
223-
GitHub
224-
issue](https://github.com/substrate-developer-hub/substrate-developer-hub.github.io/issues/new) or reach out on [Riot](https://riot.im/app/#/room/!HzySYSaIhtyWrwiwEV:matrix.org).
222+
If you experienced any issues with this tutorial or want to provide feedback, feel free to
223+
[open a GitHub issue](https://github.com/substrate-developer-hub/substrate-developer-hub.github.io/issues/new)
224+
or reach out on [Riot](https://riot.im/app/#/room/!HzySYSaIhtyWrwiwEV:matrix.org).
225225

226226
We can't wait to see what you build next!

tuts/build-a-dapp/v2.0.0-alpha.5/index.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,33 @@ lang: en
44
title: Introduction
55
---
66

7-
In this tutorial, you will learn to create a custom ["Proof Of
8-
Existence"](https://en.wikipedia.org/wiki/Proof_of_Existence) dApp using the Substrate
7+
In this tutorial, you will learn to create a custom
8+
["Proof Of Existence"](https://en.wikipedia.org/wiki/Proof_of_Existence) dApp using the Substrate
99
blockchain development framework.
1010

11-
This tutorial should take you about **1 hour** to complete. We will be using the [Rust programming
12-
language](https://www.rust-lang.org/) and [ReactJS](https://reactjs.org/), but you do not need to
13-
know these to be able to complete this guide. We will provide you with working code snippets and
14-
explain what all the code does at a high level.
11+
This tutorial should take you about **1 hour** to complete. We will be using the
12+
[Rust programming language](https://www.rust-lang.org/) and [ReactJS](https://reactjs.org/), but you
13+
do not need to know these to be able to complete this guide. We will provide you with working code
14+
snippets and explain what all the code does at a high level.
1515

1616
We only expect that:
1717

18-
* You are generally familiar with software development, writing code, and running your code.
19-
* You have completed the [Creating Your First Substrate Chain Tutorial](tutorials/creating-your-first-substrate-chain/index.md).
20-
* You are open to learning about the bleeding edge of blockchain development.
18+
- You are generally familiar with software development, writing code, and running your code.
19+
- You have completed the
20+
[Creating Your First Substrate Chain Tutorial](tutorials/creating-your-first-substrate-chain/index.md).
21+
- You are open to learning about the bleeding edge of blockchain development.
2122

22-
If you run into an issue on this tutorial, **we are here to help!** You can [create a new
23-
issue](https://github.com/substrate-developer-hub/substrate-developer-hub.github.io/issues/new) or
24-
contact us on [Riot](https://riot.im/app/#/room/!HzySYSaIhtyWrwiwEV:matrix.org).
23+
If you run into an issue on this tutorial, **we are here to help!** You can
24+
[create a new issue](https://github.com/substrate-developer-hub/substrate-developer-hub.github.io/issues/new)
25+
or contact us on [Riot](https://riot.im/app/#/room/!HzySYSaIhtyWrwiwEV:matrix.org).
2526

2627
## What you will be doing
2728

2829
Before we even get started, let's lay out what we are going to do over the course of this tutorial.
2930
We will:
3031

3132
1. Launch a Substrate blockchain based on a template project.
32-
3. Modify this template project to add our own custom logic.
33-
4. Modify a front-end template to interact with your brand new blockchain.
33+
2. Modify this template project to add our own custom logic.
34+
3. Modify a front-end template to interact with your brand new blockchain.
3435

3536
Sound reasonable? Good, then let's begin!

0 commit comments

Comments
 (0)