Skip to content

Commit ce0f572

Browse files
author
MattDHill
committed
defautl borkerip
1 parent 94916c9 commit ce0f572

File tree

6 files changed

+22
-28
lines changed

6 files changed

+22
-28
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# testing
77
/coverage
8-
config.ts
8+
borkerconfig.json
99

1010
# production
1111
/build

src/app/App.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { AppContext } from './contexts/app-context'
77
import './App.scss'
88
import { JsWallet, JsChildWallet } from 'borker-rs-browser'
99
import * as CryptoJS from 'crypto-js'
10+
import * as config from '../borkerconfig.json'
1011

1112
export interface AppState {
1213
isLoading: boolean
@@ -25,6 +26,7 @@ class App extends React.Component<{}, AppState> {
2526
}
2627

2728
async componentDidMount () {
29+
await Storage.set('borkerip', config.borkerip)
2830
this.setState({
2931
address: await Storage.get<string>('address'),
3032
isLoading: false,

src/app/pages/auth-routes.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class AuthRoutes extends React.Component<AppProps, AuthRoutesState> {
8181

8282
getBalance = async () => {
8383
this.setState({
84-
balance: await this.webService.getBalance(),
84+
balance: await this.webService.getBalance(this.props.address),
8585
})
8686
}
8787

src/app/pages/settings/settings.tsx

+10-18
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ import * as Storage from 'idb-keyval'
55
import '../../App.scss'
66
import './settings.scss'
77

8-
export interface BorkerConfig {
9-
externalip: string
10-
}
118

129
export interface SettingsProps extends AuthProps {}
1310

1411
export interface SettingsState {
1512
submitEnabled: boolean
16-
config: BorkerConfig
13+
borkerip: string
1714
}
1815

1916
class SettingsPage extends React.Component<SettingsProps, SettingsState> {
@@ -23,9 +20,7 @@ class SettingsPage extends React.Component<SettingsProps, SettingsState> {
2320
super(props)
2421
this.state = {
2522
submitEnabled: false,
26-
config: {
27-
externalip: '',
28-
},
23+
borkerip: '',
2924
}
3025
this.webService = new WebService()
3126
}
@@ -34,18 +29,15 @@ class SettingsPage extends React.Component<SettingsProps, SettingsState> {
3429
this.props.setShowFab(false)
3530
this.props.setTitle('Settings')
3631

37-
const config = await Storage.get<BorkerConfig>('borkerconfig')
32+
const borkerip = await Storage.get<string>('borkerip')
3833

39-
if (config) { this.setState({ config }) }
34+
if (borkerip) { this.setState({ borkerip }) }
4035
}
4136

4237
handleIpChange = (e: React.BaseSyntheticEvent) => {
4338
this.setState({
4439
submitEnabled: true,
45-
config: {
46-
...this.state.config,
47-
externalip: e.target.value,
48-
},
40+
borkerip: e.target.value,
4941
})
5042
}
5143

@@ -54,25 +46,25 @@ class SettingsPage extends React.Component<SettingsProps, SettingsState> {
5446
this.setState({
5547
submitEnabled: false,
5648
})
57-
await Storage.set('borkerconfig', this.state.config)
58-
if (!this.state.config.externalip) { return }
49+
await Storage.set('bokerip', this.state.borkerip)
50+
if (!this.state.borkerip) { return }
5951
try {
6052
await this.props.getBalance()
6153
alert('Success! Happy Borking')
6254
} catch (err) {
6355
alert('invalid borker IP')
64-
await Storage.set('borkerconfig', { ...this.state.config, externalip: '' })
56+
await Storage.set('borkerip', { borkerip: '' })
6557
}
6658
}
6759

6860
render () {
69-
const { submitEnabled, config } = this.state
61+
const { submitEnabled, borkerip } = this.state
7062

7163
return (
7264
<div className="page-content">
7365
<form onSubmit={this.saveConfig} className="profile-edit-form">
7466
<label>Borker IP Address</label>
75-
<input type="text" value={config.externalip} maxLength={40} onChange={this.handleIpChange} />
67+
<input type="text" value={borkerip} maxLength={40} onChange={this.handleIpChange} />
7668
<input type="submit" value="Save" disabled={!submitEnabled} />
7769
</form>
7870
<br />

src/app/web-service.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ import * as Storage from 'idb-keyval'
33
import BigNumber from 'bignumber.js'
44
import { User, Bork, BorkType, OrderBy, Utxo, Tag } from '../types/types'
55
import { FollowsType } from './pages/user-list/user-list'
6-
import { BorkerConfig } from './pages/settings/settings'
76

87
class WebService {
98

10-
async getBalance (): Promise<BigNumber> {
11-
const address = await Storage.get<string>('address')
12-
9+
async getBalance (address: string): Promise<BigNumber> {
1310
const res = await this.request({
1411
method: 'GET',
1512
url: `/users/${address}/balance`,
@@ -114,19 +111,19 @@ class WebService {
114111

115112
private async request (options: rp.OptionsWithUrl) {
116113

117-
const [config, address] = await Promise.all([
118-
Storage.get<BorkerConfig>('borkerconfig'),
114+
const [borkerip, address] = await Promise.all([
115+
Storage.get<string>('borkerip'),
119116
Storage.get<string>('address'),
120117
])
121118

122-
if (!config || !config.externalip) {
119+
if (!borkerip) {
123120
alert('please go to "Settings" and provide an IP address of a Borker node.')
124121
return
125122
}
126123

127124
Object.assign(options, {
128125
json: true,
129-
url: config.externalip + options.url,
126+
url: borkerip + options.url,
130127
headers: { 'my-address': address },
131128
})
132129

src/borkerconfig-sample.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"borkerip": ""
3+
}

0 commit comments

Comments
 (0)