Skip to content

Commit

Permalink
Toggle online/offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenaio committed Jul 15, 2019
1 parent 300210f commit 9f4b515
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
48 changes: 41 additions & 7 deletions renderer/pages/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import useFlips from '../../shared/utils/useFlips'
import {useEpochState} from '../../shared/providers/epoch-context'
import {useNotificationDispatch} from '../../shared/providers/notification-context'
import {nodeSettings} from '../../shared/api/api-client'
import {becomeOnline, becomeOffline} from '../../shared/api'
import {useIdentityState} from '../../shared/providers/identity-context'

const DEFAULT_NODE_URL = 'http://localhost:9009'

Expand All @@ -27,7 +29,8 @@ const inviteDb = global.invitesDb || {}

function Settings() {
const {archiveFlips} = useFlips()
const {addNotification} = useNotificationDispatch()
const {addNotification, addError} = useNotificationDispatch()
const {online} = useIdentityState()

const addrRef = React.createRef()
const [addr, setAddr] = useState()
Expand Down Expand Up @@ -130,15 +133,46 @@ function Settings() {
<Link href="/validation/long">Long</Link>
</Box>
</Box>
<EpochDisplay />
<Box my={rem(theme.spacings.medium32)}>
<SubHeading css={margin(0, 0, theme.spacings.small, 0)}>
Now: {online ? 'online 🔵' : 'offline 🔴'}
</SubHeading>
<Box my={theme.spacings.small}>
<Button
disabled={online}
onClick={async () => {
try {
await becomeOnline()
} catch (error) {
addError({
title: error.message,
})
}
}}
>
Become online
</Button>
</Box>
<Box my={theme.spacings.small}>
<Button
disabled={!online}
onClick={async () => {
try {
await becomeOffline()
} catch (error) {
addError({
title: error.message,
})
}
}}
>
Become offline
</Button>
</Box>
</Box>
</Box>
</Layout>
)
}

function EpochDisplay() {
const epoch = useEpochState()
return <Pre>{JSON.stringify(epoch)}</Pre>
}

export default Settings
19 changes: 19 additions & 0 deletions renderer/shared/api/dna.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function fetchIdentities() {
* @property {string[]} flips
* @property {number} totalQualifiedFlips
* @property {number} totalShortFlipPoints
* @property {boolean} online
*/

/**
Expand Down Expand Up @@ -168,3 +169,21 @@ export async function killIdentity(from) {
})
return data
}

export async function becomeOnline() {
const {data} = await api().post('/', {
method: 'dna_becomeOnline',
params: [],
id: 1,
})
return data
}

export async function becomeOffline() {
const {data} = await api().post('/', {
method: 'dna_becomeOffline',
params: [],
id: 1,
})
return data
}

0 comments on commit 9f4b515

Please sign in to comment.