Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flipper UI next.js react #8

Merged
merged 15 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ yarn.lock

.vscode
.idea

node_modules/

.next/

target/
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"uniswap-v2/contracts/**",
"farming/contracts/**",
# "flipper/flipper/contracts/*" <- uncomment this if you want to use flipper
]

exclude = [
Expand Down
52 changes: 52 additions & 0 deletions flipper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Flipper: wasm dapp for astar

This is a demo for Simple WASM contract. Contract name is Flipper. Flipper contract has two method. One transaction method `flip` and one query method `get`. Flipper contract is meant to show hello world use case for wasm, swanky and connecting to contract via a react frontend.

`contract` folder contains the contract code `ui` folder contains the UI code. UI is written in next.js and react.

# Requirements

- node.js
- swanky cli https://github.com/AstarNetwork/swanky-cli

# Usage

Install swanky cli https://github.com/AstarNetwork/swanky-cli
- `$ npm install -g @astar-network/swanky-cli`

##### Deploy flipper contract
0. Init \
In the root workspace `Cargo.toml` uncomment the line `"flipper/flipper/contracts/*"` \
In `./flipper` folder run `swanky init flipper` and chose `flipper` as template and as contract name. Chose `Y` when asking to download swanky node.

1. Start the local node

- `cd flipper`
- `swanky node start`

2. Build the contract \

Until this [issue on ink!](https://github.com/paritytech/ink/pull/1439) is not resolved please use [this workaround](https://substrate.stackexchange.com/questions/4785/errore0158-when-testing-default-contract-from-flipper/4847#4847) \
When resolved please use swanky: \
`swanky contract compile flipper`

3. deploy the contract

`swanky contract deploy flipper --account alice -g 100000000000 -a true`

Note down the contract address.

##### Run the UI
Go to ui folder

- `cd ../ui`

Install Dependencies

- `yarn`

Start next.js server

- `yarn dev`

Go to http://localhost:3000 and enter the contract address. Flip button flips the boolean value.
3 changes: 3 additions & 0 deletions flipper/ui/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
37 changes: 37 additions & 0 deletions flipper/ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules/
/.pnp
.pnp.js

# testing
/coverage

# next.js
.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

34 changes: 34 additions & 0 deletions flipper/ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
7 changes: 7 additions & 0 deletions flipper/ui/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
}

module.exports = nextConfig
26 changes: 26 additions & 0 deletions flipper/ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "flipper-dapp",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@polkadot/api": "^9.5.1",
"@polkadot/api-contract": "^9.5.1",
"next": "12.3.1",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "18.8.4",
"@types/react": "18.0.21",
"@types/react-dom": "18.0.6",
"eslint": "8.25.0",
"eslint-config-next": "12.3.1",
"typescript": "4.8.4"
}
}
8 changes: 8 additions & 0 deletions flipper/ui/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import '../styles/globals.css'
import type { AppProps } from 'next/app'

function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}

export default MyApp
110 changes: 110 additions & 0 deletions flipper/ui/pages/abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const abi = {
"source": {
"hash": "0xc6791d00ac69ebfe59fa5cfb7f55a5583ff7357da462a1c53cd8518a9cbee964",
"language": "ink! 3.0.0",
"compiler": "rustc 1.62.0-nightly"
},
"contract": {
"name": "flipper",
"version": "0.1.0",
"authors": [
"Astar"
]
},
"V3": {
"spec": {
"constructors": [
{
"args": [
{
"label": "init_value",
"type": {
"displayName": [
"bool"
],
"type": 0
}
}
],
"docs": [
"Constructor that initializes the `bool` value to the given `init_value`."
],
"label": "new",
"payable": false,
"selector": "0x9bae9d5e"
},
{
"args": [],
"docs": [
"Constructor that initializes the `bool` value to `false`.",
"",
"Constructors can delegate to other constructors."
],
"label": "default",
"payable": false,
"selector": "0xed4b9d1b"
}
],
"docs": [],
"events": [],
"messages": [
{
"args": [],
"docs": [
" A message that can be called on instantiated contracts.",
" This one flips the value of the stored `bool` from `true`",
" to `false` and vice versa."
],
"label": "flip",
"mutates": true,
"payable": false,
"returnType": null,
"selector": "0x633aa551"
},
{
"args": [],
"docs": [
" Simply returns the current value of our `bool`."
],
"label": "get",
"mutates": false,
"payable": false,
"returnType": {
"displayName": [
"bool"
],
"type": 0
},
"selector": "0x2f865bd9"
}
]
},
"storage": {
"struct": {
"fields": [
{
"layout": {
"cell": {
"key": "0x0000000000000000000000000000000000000000000000000000000000000000",
"ty": 0
}
},
"name": "value"
}
]
}
},
"types": [
{
"id": 0,
"type": {
"def": {
"primitive": "bool"
}
}
}
]
}
};

export default abi;
Loading