Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Setup dApp skeleton #7

Closed
wants to merge 23 commits into from
Closed
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
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2.1

executors:
docker-node:
docker:
- image: circleci/node:11

jobs:
test_solidity:
executor: docker-node
steps:
- checkout
- run: npm i
- run: npm run build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this will work. Maybe we should drop the circleci configuration from this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha could you be less specific? Why won't it work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of you could use some details heh. Based on the commit that introduced this, I have no idea what you're trying to achieve. What's the purpose of adding this? That will probably help Kuba understand what is expected to work here.

It certainly doesn't test solidity, which is what your build currently implies 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha could you be less specific? Why won't it work?

Yes, sorry. This will be executed in the root directory, which doesn't contain these commands definition. We should set working_directory for these steps.
We should also add workflows specification at the end of the file.

If we want to configure it all in this PR I can give you a hand with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closed but responding anyways - good catch guys, this was actually because I moved everything into app/ to play well with #8's file layout. ATT of that commit @Shadowfiend, it was correct and simply did a build.

38 changes: 38 additions & 0 deletions PLAN
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
order:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should remove the plan from this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

- request-deposit
- initiate-deposit
- await-deposit-confirm
- prove-deposit
- tbtc-minted


requestADeposit
create action
call Keep to request a deposit
sign the transaction and submit
wait for it to be mined
get the deposit address
now call the deposit contract
and get the btc address
goto next

sendTbtc
onclick "ok I sent it"
now show a waiting dialog, with some sort of smart countdown
wait for the transaction to be received
wait for the transaction to be confirmed
wait a certain number of confirmations on this step
when it's finally sufficiently confirmed, dispatch the txid
goto next

proveDeposit
get the txid
run through the proof generation process
generate a proof
again, call the web3 contract, submitting the proof
wait for the tx to be mined successfully
filter through the contract events to get the transaction id
goto next

tbtcMinted
show the link to the tx
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# tbtc-dapp
# tbtc-dapp

The tBTC dApp.

## Setup

### Prerequisites

- Run Ganache test chain
- Deploy tBTC contracts

### Running the dApp

1. `cd app/``
2. `npm i`
3. `npm run dev` and open [http://localhost:3000](http://localhost:3000)

4 changes: 4 additions & 0 deletions app/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["next/babel"],
"plugins": [["styled-components", { "ssr": true }]]
}
3 changes: 3 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on moving this .gitignore to a project root directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^ let's do it

yarn.lock
.next
23 changes: 23 additions & 0 deletions app/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createActions, handleActions, combineActions } from 'redux-actions';

export const REQUEST_A_DEPOSIT = 'REQUEST_A_DEPOSIT'
export const WAIT_CONFIRMATION = 'WAIT_CONFIRMATION'
export const SUBMIT_DEPOSIT_PROOF = 'SUBMIT_DEPOSIT_PROOF'

export function requestADeposit() {
return {
type: REQUEST_A_DEPOSIT
}
}

export function waitConfirmation() {
return {
type: WAIT_CONFIRMATION
}
}

export function submitProof() {
return {
type: SUBMIT_DEPOSIT_PROOF
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about using object literals w/ strings throughout the app?

I've always followed the pattern you have here, but I'm wondering if its really worth it. Action Creators are great for managing side-effects, but we now have sagas for that, so I'm questioning our assumptions a bit.

With action name constants, I still see value in those: easier to debug if you typo, but I am not convinced thats a mistake made often enough to justify the additional boilerplate.

What you have here is much cleaner/safer than what I'm suggesting, and is what I'm used to - I'm just wondering where your head is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never worked under a frontend senior, so I can't speak for the standard. But I wouldn't say the issue is typos - rather, it's refactors. In which case, using your type system is the right thing to do.

It's also something the official Redux docs recommend:

Encapsulating and centralizing commonly used pieces of code is a key concept in programming. While it is certainly possible to manually create action objects everywhere, and write each type value by hand, defining reusable constants makes maintaining code easier. If you put constants in a separate file, you can check your import statements against typos so you can't accidentally use the wrong string.

55 changes: 55 additions & 0 deletions app/components/AwaitDepositConfirmation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import styled from 'styled-components'
import { PageTemplate } from './PageTemplate'
import { MainBlock } from "./MainBlock";
import Link from 'next/link'
import { IconBlock, ContentBlock, FormStep } from './FormStep';
import { DarkGray } from '../styles';

const QRCode = require('qrcode.react')


const CopyAddressBox = styled.div`
background: #ddd;
border: 1px solid #ddd;
display: inline-block;
padding: 1em;
width: 420px;
color: ${DarkGray};
`

const WaitingForTx = styled.div`
text-align: center;
i {
font-size: 64px;
display: block;
clear: both;
}
`

const AwaitDepositConfirmation = ({ address }) => {
return <PageTemplate>
<MainBlock>
<FormStep>
<IconBlock>
<WaitingForTx>
<img src='/static/waiting.png'/>
</WaitingForTx>
</IconBlock>

<ContentBlock>
<h2>Pay 1 BTC</h2>
<p>Scan the QR code or tap to pay, or copy the address below into your wallet</p>

<CopyAddressBox>
{address}
</CopyAddressBox>

<br/><br/>
<a style={{ color: '#333', textDecoration: 'none' }} href="/prove-deposit">[debug] let's prove our deposit and claim tbtc</a>
</ContentBlock>
</FormStep>
</MainBlock>
</PageTemplate>
}

export { AwaitDepositConfirmation }
24 changes: 24 additions & 0 deletions app/components/Button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import styled from 'styled-components'
import { Blue } from '../styles'

const Button = styled.button`
padding: 1em;
background: ${Blue};
color: white;

font-size: 16px;
font-weight: 500;
font-style: normal;
font-stretch: normal;
line-height: 1;
letter-spacing: normal;
color: #ffffff;

:hover {
cursor: pointer;
opacity: 0.8;
color: white;
}
`

export { Button }
26 changes: 26 additions & 0 deletions app/components/FormStep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import styled from 'styled-components'

export const FormStep = styled.div`
display: flex;
flex-direction: row;
width: 850px;
margin: 0 auto;
padding-top: 2em;
`

export const IconBlock = styled.div`
width: 200px;
max-height: 256px;
align-items: center;
display: flex;
justify-content: center;
margin-right: 2em;
img {
height: 100%;
width: 100%;
}
`

export const ContentBlock = styled.div`
flex: 1;
`
45 changes: 45 additions & 0 deletions app/components/InitiateDeposit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import styled from 'styled-components'
const QRCode = require('qrcode.react')
import Link from 'next/link'
import { Button } from '../components/Button'
import { PageTemplate } from '../components/PageTemplate'
import { MainBlock } from "../components/MainBlock"
import { IconBlock, FormStep, ContentBlock } from '../components/FormStep';

const CopyAddressBox = styled.div`
background: white;
border: 1px solid #ddd;
display: inline-block;
padding: 1em;
margin-bottom: 1em;
width: 420px;
`

const InitiateDeposit = ({ address }) => {
return <PageTemplate>
<MainBlock>
<FormStep>
<IconBlock>
<QRCode size={160} value={address || ''}/>
</IconBlock>

<ContentBlock>
<h2>Pay 1 BTC</h2>
<p>Scan the QR code or tap to pay, or copy the address below into your wallet</p>

<CopyAddressBox>
{address}
</CopyAddressBox>

<br/>
<Link href="/await-deposit-confirm">
<Button>Ok, I sent it!</Button>
</Link>
</ContentBlock>

</FormStep>
</MainBlock>
</PageTemplate>
}

export { InitiateDeposit }
14 changes: 14 additions & 0 deletions app/components/MainBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import styled from 'styled-components'

import { LightBlue } from '../styles'

const MainBlock = styled.div`
flex: 1;
align-items: start;
display: flex;
flex-direction: column;
padding: 0em 4em;
background: ${LightBlue};
`

export { MainBlock }
80 changes: 80 additions & 0 deletions app/components/PageTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { Button } from "../components/Button";
import styled from 'styled-components'
import Link from 'next/link'

import { DarkBlue } from '../styles'

export const PageWrapper = styled.div`
min-height: 100vh;

display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: stretch;
align-content: stretch;

h1,
h2,
h3,
h4 {
font-weight: 300;
color: ${DarkBlue};
}

p {
color: ${DarkBlue};
}

`

export const PageContainer = styled.div`

display: flex;
justify-content: space-around;
flex-direction: column;
flex: 1;
`

export const HeaderBlock = styled.div`
flex: 0 1;
padding: 0em 0;
margin: 2em 4em;
`

export const MainBlock = styled.div`
flex: 1;
align-items: center;
display: flex;
flex-direction: row;
margin: 0em 4em;
`

export const TBTCTitle = styled.div`
font-size: 1.6em;
color: ${DarkBlue};

:hover {
cursor: pointer;
}
`


const PageTemplate = ({ children }) => {
return <PageWrapper>
<PageContainer>

<HeaderBlock>
<Link href="/">
<TBTCTitle>tbtc</TBTCTitle>
</Link>
</HeaderBlock>

{children}

</PageContainer>
</PageWrapper>

}

export { PageTemplate }
Loading