Skip to content

Commit c06fb07

Browse files
author
MattDHill
committed
getBalance and getUtxos working. update packages
1 parent a0756ef commit c06fb07

File tree

14 files changed

+2894
-1906
lines changed

14 files changed

+2894
-1906
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ config.ts
1616
.env.development.local
1717
.env.test.local
1818
.env.production.local
19+
.vscode
1920

2021
npm-debug.log*
2122
yarn-debug.log*

Diff for: package-lock.json

+2,800-1,832
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+31-25
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
{
22
"name": "borker-app",
33
"version": "0.1.0",
4-
"private": true,
4+
"description": "GUI for censorship-resistant news sharing on Dogecoin",
5+
"author": "MattDHill",
6+
"license": "MIT",
7+
"repository": {
8+
"type": "git",
9+
"url": "[email protected]:MattDHill/borker-app.git"
10+
},
511
"dependencies": {
6-
"@fortawesome/fontawesome-svg-core": "^1.2.12",
7-
"@fortawesome/free-regular-svg-icons": "^5.6.3",
8-
"@fortawesome/free-solid-svg-icons": "^5.6.3",
9-
"@fortawesome/react-fontawesome": "^0.1.3",
10-
"bignumber.js": "^8.0.1",
12+
"@fortawesome/fontawesome-svg-core": "^1.2.18",
13+
"@fortawesome/free-regular-svg-icons": "^5.8.2",
14+
"@fortawesome/free-solid-svg-icons": "^5.8.2",
15+
"@fortawesome/react-fontawesome": "^0.1.4",
16+
"bignumber.js": "^8.1.1",
1117
"borker-rs": "^0.1.6",
1218
"crypto-js": "^3.1.9-1",
13-
"idb-keyval": "^3.1.0",
14-
"lighthouse": "^4.0.0-alpha.2-3.2.1",
15-
"moment": "^2.22.2",
16-
"qrcode.react": "^0.9.1",
17-
"react": "^16.7.0",
19+
"idb-keyval": "^3.2.0",
20+
"lighthouse": "^5.0.0",
21+
"moment": "^2.24.0",
22+
"qrcode.react": "^0.9.3",
23+
"react": "^16.8.6",
1824
"react-copy-to-clipboard": "^5.0.1",
19-
"react-dom": "^16.7.0",
25+
"react-dom": "^16.8.6",
2026
"react-modal": "^3.8.1",
2127
"react-router-dom": "^4.3.1",
2228
"react-scripts": "2.1.1",
2329
"react-sidebar": "^3.0.2",
24-
"react-tabs": "^2.3.0",
30+
"react-tabs": "^3.0.0",
2531
"request": "^2.88.0",
26-
"request-promise": "^4.2.2",
32+
"request-promise": "^4.2.4",
2733
"wasm-loader": "^1.3.0"
2834
},
2935
"scripts": {
@@ -43,19 +49,19 @@
4349
],
4450
"devDependencies": {
4551
"@types/crypto-js": "^3.1.43",
46-
"@types/jest": "^23.3.10",
47-
"@types/node": "^10.12.18",
48-
"@types/qrcode.react": "^0.8.1",
49-
"@types/react": "^16.7.18",
52+
"@types/jest": "^24.0.13",
53+
"@types/node": "^12.0.2",
54+
"@types/qrcode.react": "^0.8.2",
55+
"@types/react": "^16.8.17",
5056
"@types/react-copy-to-clipboard": "^4.2.6",
51-
"@types/react-dom": "^16.0.11",
52-
"@types/react-modal": "^3.6.0",
53-
"@types/react-router-dom": "^4.3.1",
57+
"@types/react-dom": "^16.8.4",
58+
"@types/react-modal": "^3.8.2",
59+
"@types/react-router-dom": "^4.3.3",
5460
"@types/react-sidebar": "^3.0.0",
55-
"@types/react-tabs": "^2.3.0",
56-
"@types/request-promise": "^4.1.42",
57-
"node-sass": "^4.10.0",
61+
"@types/react-tabs": "^2.3.1",
62+
"@types/request-promise": "^4.1.43",
63+
"node-sass": "^4.12.0",
5864
"react-app-rewired": "^1.6.2",
59-
"typescript": "^3.1.6"
65+
"typescript": "^3.4.5"
6066
}
6167
}

Diff for: src/app/components/bork-buttons/bork-buttons.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { faRetweet } from '@fortawesome/free-solid-svg-icons'
1010
import { faSkullCrossbones } from '@fortawesome/free-solid-svg-icons'
1111
import CheckoutModal from '../modals/checkout-modal/checkout-modal'
1212
import { withAppContext, AppProps } from '../../contexts/app-context'
13+
import BigNumber from 'bignumber.js'
1314
import '../../App.scss'
1415
import './bork-buttons.scss'
1516

@@ -27,7 +28,7 @@ class BorkButtons extends React.PureComponent<BorkButtonsProps> {
2728
type: BorkType.rebork,
2829
parent: {
2930
txid: this.props.bork.txid,
30-
tip: '10',
31+
tip: new BigNumber(10),
3132
},
3233
}}
3334
/>
@@ -42,7 +43,7 @@ class BorkButtons extends React.PureComponent<BorkButtonsProps> {
4243
type: BorkType.like,
4344
parent: {
4445
txid: this.props.bork.txid,
45-
tip: '10',
46+
tip: new BigNumber(10),
4647
},
4748
}}
4849
/>
@@ -96,7 +97,7 @@ class BorkButtons extends React.PureComponent<BorkButtonsProps> {
9697
<a onClick={this.flag}>
9798
<FontAwesomeIcon
9899
icon={faSkullCrossbones}
99-
style={bork.iFlag ? {color: 'red'} : {} }
100+
style={bork.iFlag ? {color: 'black'} : {} }
100101
/> {showCount && (bork.flagsCount || 0)}
101102
</a>
102103
</td>

Diff for: src/app/components/modals/checkout-modal/checkout-modal.tsx

+15-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react'
2-
import { BorkType, TxData } from '../../../../types/types'
32
import { withAuthContext, AuthProps } from '../../../contexts/auth-context'
43
import BigNumber from 'bignumber.js'
54
import WebService, { ConstructRequest } from '../../../web-service'
@@ -14,7 +13,6 @@ export interface CheckoutModalProps extends AuthProps {
1413
}
1514

1615
export interface CheckoutModalState {
17-
txDatas: TxData[]
1816
fees: BigNumber
1917
tip: BigNumber
2018
totalCost: BigNumber
@@ -27,7 +25,6 @@ class CheckoutModal extends React.Component<CheckoutModalProps, CheckoutModalSta
2725
constructor (props: CheckoutModalProps) {
2826
super(props)
2927
this.state = {
30-
txDatas: [],
3128
fees: new BigNumber(0),
3229
tip: new BigNumber(0),
3330
totalCost: new BigNumber(0),
@@ -37,24 +34,16 @@ class CheckoutModal extends React.Component<CheckoutModalProps, CheckoutModalSta
3734
}
3835

3936
async componentDidMount () {
40-
const txDatas = await this.webService.construct(this.props.data)
37+
const { txCount, parent } = this.props.data
4138

42-
let tip: BigNumber = new BigNumber(0)
43-
if ([BorkType.comment, BorkType.like, BorkType.rebork].includes(this.props.data.type)) {
44-
tip = new BigNumber(txDatas[0].outputs[1].value)
45-
}
46-
47-
const fees = txDatas.reduce((sum, txData) => {
48-
return sum.plus(txData.fee)
49-
}, new BigNumber(0))
39+
const fees = txCount ? new BigNumber(txCount).times(1) : new BigNumber(1)
5040

51-
const totalCost = fees.plus(tip)
41+
const tip = parent ? parent.tip : new BigNumber(0)
5242

5343
this.setState({
54-
txDatas,
55-
tip,
5644
fees,
57-
totalCost,
45+
tip,
46+
totalCost: fees.plus(tip),
5847
})
5948
}
6049

@@ -64,28 +53,29 @@ class CheckoutModal extends React.Component<CheckoutModalProps, CheckoutModalSta
6453

6554
signAndBroadcast = async (e: React.FormEvent<HTMLFormElement>) => {
6655
e.preventDefault()
56+
57+
const utxos = await this.webService.getUtxos(this.state.totalCost.toString())
58+
6759
const encrypted = await Storage.get<string>('wallet')
6860
const wallet = CryptoJS.AES.decrypt(encrypted, this.state.password)
6961

70-
const rawTxs = await Promise.all(this.state.txDatas.map(txData => {
71-
console.log(wallet)
72-
return txData.txHash
73-
}))
62+
const borkerLib = await import('borker-rs')
63+
64+
// const rawTxs = new borkerLib.construct(this.props.data, utxos)
65+
const rawTxs = ['']
7466

7567
this.webService.signAndBroadcastTx(rawTxs)
7668
}
7769

7870
render () {
7971
const { data } = this.props
80-
const { txDatas, tip, totalCost, fees, password } = this.state
72+
const { tip, totalCost, fees, password } = this.state
8173

82-
return !txDatas.length ? (
83-
<p>Loading</p>
84-
) : (
74+
return (
8575
<div className="checkout-modal-content">
8676
<h1>Order Summary</h1>
8777
<p>Transaction Type: <b>{data.type}</b></p>
88-
<p>Total Transactions: {txDatas.length}</p>
78+
<p>Total Transactions: {data.txCount || 1}</p>
8979
<p>Fees: {fees.toString()} DOGE</p>
9080
{tip.isGreaterThan(0) &&
9181
<p>Tip: {tip.toString()} DOGE</p>

Diff for: src/app/components/modals/withdrawal-modal/withdrawal-modal.tsx

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
22
import BigNumber from 'bignumber.js'
33
import './withdrawal-modal.scss'
4+
import WebService from '../../../web-service';
45

56
export interface WithdrawalModalProps {
67
balance: BigNumber
@@ -12,10 +13,15 @@ export interface WithdrawalModalState {
1213
}
1314

1415
class WithdrawalModal extends React.Component<WithdrawalModalProps, WithdrawalModalState> {
15-
16-
state = {
17-
address: '',
18-
amount: '',
16+
public webService: WebService
17+
18+
constructor (props: WithdrawalModalProps) {
19+
super(props)
20+
this.state = {
21+
address: '',
22+
amount: '',
23+
}
24+
this.webService = new WebService()
1925
}
2026

2127
handleAddressChange = (e: React.BaseSyntheticEvent) => {
@@ -26,20 +32,26 @@ class WithdrawalModal extends React.Component<WithdrawalModalProps, WithdrawalMo
2632
this.setState({ amount: e.target.value })
2733
}
2834

35+
withdraw = async (e: React.FormEvent<HTMLFormElement>) => {
36+
e.preventDefault()
37+
const utxos = await this.webService.getUtxos(this.state.amount)
38+
console.log('utxos', utxos)
39+
}
40+
2941
fillMax = () => {
30-
this.setState({ amount: this.props.balance.toFormat(8) })
42+
this.setState({ amount: this.props.balance.dividedBy(100000000).toFixed(8) })
3143
}
3244

3345
render () {
3446
const { address, amount } = this.state
3547
const { balance } = this.props
3648

3749
return (
38-
<form onSubmit={e => { e.preventDefault(); alert('withdrawals coming soon') }} className="withdrawal-form">
50+
<form onSubmit={this.withdraw} className="withdrawal-form">
3951
<h2>Withdrawal</h2>
4052
<input type="text" placeholder="Address" value={address} onChange={this.handleAddressChange} />
4153
<input type="number" placeholder="Amount" value={amount} onChange={this.handleAmountChange} />
42-
<p>Available: <a className={"clickable"} onClick={this.fillMax}>{balance.toFormat(8)}</a></p>
54+
<p>Available: <a className={"clickable"} onClick={this.fillMax}>{balance.dividedBy(100000000).toFormat(8)}</a></p>
4355
<input type="submit" value="Construct Tx" />
4456
</form>
4557
)

Diff for: src/app/pages/auth-routes.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class AuthRoutes extends React.Component<AppProps, AuthRoutesState> {
5959
mql.addListener(this.mediaQueryChanged)
6060

6161
this.setState({
62-
balance: await this.webService.getBalance(this.props.address),
62+
balance: await this.webService.getBalance(),
6363
})
6464
}
6565

Diff for: src/app/pages/borks/bork-new/bork-new.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import CheckoutModal from '../../../components/modals/checkout-modal/checkout-mo
55
import BorkPreviewComponent from '../../../components/bork-preview/bork-preview';
66
import WebService, { ConstructRequest } from '../../../web-service'
77
import { BorkType, Bork } from '../../../../types/types'
8+
import BigNumber from 'bignumber.js'
89
import './bork-new.scss'
910
import '../../../App.scss'
1011

@@ -60,7 +61,7 @@ class NewBorkPage extends React.Component<NewBorkProps, NewBorkState> {
6061
if (parent) {
6162
data.parent = {
6263
txid: parent.txid,
63-
tip: '10',
64+
tip: new BigNumber(10),
6465
}
6566
}
6667

Diff for: src/app/pages/profile/profile-edit/profile-edit.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React from 'react'
22
import { AuthProps, withAuthContext } from '../../../contexts/auth-context'
33
import CheckoutModal from '../../../components/modals/checkout-modal/checkout-modal'
44
import { User, BorkType } from '../../../../types/types'
5+
import { RouteComponentProps } from 'react-router'
56
import './profile-edit.scss'
67
import '../../../App.scss'
7-
import { RouteComponentProps } from 'react-router';
88

99
export interface ProfileEditParams {
1010
type: BorkType.setName | BorkType.setBio | BorkType.setAvatar

Diff for: src/app/pages/profile/profile-routes.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ProfileRoutes extends React.Component<ProfileRoutesProps, ProfileRoutesSta
6060
/>
6161
<Route
6262
exact
63-
path="/profile/:address/edit"
63+
path="/profile/:address/set_*"
6464
render={props => <ProfileEditPage {...props} user={user} />}
6565
/>
6666
<Route

Diff for: src/app/pages/wallet-create/wallet-create.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ class WalletCreatePage extends React.Component<WalletCreateProps, WalletCreateSt
2020

2121
async componentDidMount () {
2222
const borkerLib = await import('borker-rs')
23-
const wallet = new borkerLib.JsWallet(sampleWords)
24-
this.setState({ wallet })
23+
this.setState({
24+
wallet: new borkerLib.JsWallet(sampleWords),
25+
})
2526
}
2627

2728
render () {

Diff for: src/app/pages/wallet/wallet.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class WalletPage extends React.PureComponent<WalletProps> {
2121
<div className="page-content">
2222
<div className="wallet-balance">
2323
<h1>
24-
{balance.toFormat(8)}
24+
{balance.dividedBy(100000000).toFormat(8)}
2525
</h1>
2626
</div>
2727
<table className="wallet-buttons">

Diff for: src/app/web-service.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import rp from 'request-promise'
22
import * as Storage from 'idb-keyval'
33
import BigNumber from 'bignumber.js'
4-
import { BorkType, User, Bork, OrderBy, TxData } from '../types/types'
4+
import { BorkType, User, Bork, OrderBy, TxData, Utxo } from '../types/types'
55
import { FollowsType } from './pages/user-list/user-list'
66
import { BorkerConfig } from './pages/settings/settings'
77

88
class WebService {
99

1010
constructor () {}
1111

12-
async getBalance (address: string): Promise<BigNumber> {
12+
async getBalance (): Promise<BigNumber> {
13+
const address = await Storage.get<string>('address')
14+
1315
const options: rp.Options = {
1416
method: 'GET',
1517
url: `/users/${address}/balance`,
@@ -19,11 +21,13 @@ class WebService {
1921
return new BigNumber(res)
2022
}
2123

22-
async construct (body: ConstructRequest): Promise<TxData[]> {
24+
async getUtxos (amount: string): Promise<Utxo[]> {
25+
const address = await Storage.get<string>('address')
26+
2327
const options: rp.Options = {
24-
method: 'POST',
25-
url: `/transactions/construct`,
26-
body,
28+
method: 'GET',
29+
url: `/users/${address}/utxos`,
30+
qs: { amount },
2731
}
2832

2933
return this.request(options)
@@ -168,9 +172,10 @@ export interface IndexTxParams extends IndexParams {
168172

169173
export interface ConstructRequest {
170174
type: BorkType,
175+
txCount?: number
171176
content?: string
172177
parent?: {
173178
txid: string
174-
tip: string,
179+
tip: BigNumber,
175180
}
176181
}

0 commit comments

Comments
 (0)