-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): added isAuthenticated, currentNetwork and localCurrency to…
… the nOS API (#1187) * feat(api): added current network to the nOS API * feat(api): add getLocalCurrency to nOS API * chore(api): added isAuthenticated to api and added unprotected channels
- Loading branch information
Maurice Dalderup
authored
Oct 18, 2019
1 parent
8ff4780
commit 30fd7b3
Showing
11 changed files
with
176 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createActions } from 'spunky'; | ||
|
||
import { DEFAULT_NET } from 'values/networks'; | ||
import { getStorage } from 'shared/lib/storage'; | ||
|
||
import generateDAppActionId from './generateDAppActionId'; | ||
|
||
export const ID = 'currentNetwork'; | ||
|
||
export default function makeCurrentNetworkActions(sessionId, requestId) { | ||
const id = generateDAppActionId(sessionId, `${ID}-${requestId}`); | ||
|
||
return createActions(id, () => async () => { | ||
const currentNetwork = await getStorage(ID); | ||
return typeof currentNetwork === 'string' ? currentNetwork : DEFAULT_NET; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createActions } from 'spunky'; | ||
|
||
import { getStorage } from 'shared/lib/storage'; | ||
import { DEFAULT_CURRENCY } from 'shared/values/currencies'; | ||
|
||
import generateDAppActionId from './generateDAppActionId'; | ||
|
||
export const ID = 'currency'; | ||
|
||
export default function makeCurrentNetworkActions(sessionId, requestId) { | ||
const id = generateDAppActionId(sessionId, `${ID}-${requestId}`); | ||
|
||
return createActions(id, () => async () => { | ||
const currency = await getStorage(ID); | ||
return typeof currency === 'string' ? currency : DEFAULT_CURRENCY; | ||
}); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/renderer/browser/components/RequestsProcessor/CurrentNetwork/CurrentNetwork.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { func, any, objectOf } from 'prop-types'; | ||
|
||
export default class CurrentNetwork extends React.PureComponent { | ||
static propTypes = { | ||
data: objectOf(any).isRequired, | ||
onResolve: func.isRequired | ||
}; | ||
|
||
componentDidMount() { | ||
this.props.onResolve(this.props.data); | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/renderer/browser/components/RequestsProcessor/CurrentNetwork/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { compose } from 'recompose'; | ||
import { withData } from 'spunky'; | ||
|
||
import withInitialCall from 'shared/hocs/withInitialCall'; | ||
|
||
import withClean from '../../../hocs/withClean'; | ||
import withNullLoader from '../../../hocs/withNullLoader'; | ||
|
||
import CurrentNetwork from './CurrentNetwork'; | ||
|
||
const mapCurrentNetworkActionsDataToProps = (data) => ({ data }); | ||
|
||
export default function makeGetCurrentNetwork(currentNetworkActions) { | ||
return compose( | ||
withClean(currentNetworkActions), | ||
withInitialCall(currentNetworkActions), | ||
withNullLoader(currentNetworkActions), | ||
withData(currentNetworkActions, mapCurrentNetworkActionsDataToProps) | ||
)(CurrentNetwork); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/renderer/browser/components/RequestsProcessor/IsAuthenticated/IsAuthenticated.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import { func, bool } from 'prop-types'; | ||
|
||
export default class IsAuthenticated extends React.PureComponent { | ||
static propTypes = { | ||
onResolve: func.isRequired, | ||
authenticated: bool | ||
}; | ||
|
||
static defaultProps = { | ||
authenticated: false | ||
}; | ||
|
||
componentDidMount() { | ||
const { authenticated, onResolve } = this.props; | ||
onResolve(authenticated); | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/renderer/browser/components/RequestsProcessor/IsAuthenticated/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import withAuthState from 'auth/hocs/withAuthState'; | ||
|
||
import IsAuthenticated from './IsAuthenticated'; | ||
|
||
export default function makeIsAuthenticated() { | ||
return withAuthState()(IsAuthenticated); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/renderer/browser/components/RequestsProcessor/LocalCurrency/LocalCurrency.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { func, any, objectOf } from 'prop-types'; | ||
|
||
export default class CurrentNetwork extends React.PureComponent { | ||
static propTypes = { | ||
data: objectOf(any).isRequired, | ||
onResolve: func.isRequired | ||
}; | ||
|
||
componentDidMount() { | ||
this.props.onResolve(this.props.data); | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/renderer/browser/components/RequestsProcessor/LocalCurrency/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { compose } from 'recompose'; | ||
import { withData } from 'spunky'; | ||
|
||
import withInitialCall from 'shared/hocs/withInitialCall'; | ||
|
||
import withClean from '../../../hocs/withClean'; | ||
import withNullLoader from '../../../hocs/withNullLoader'; | ||
|
||
import LocalCurrency from './LocalCurrency'; | ||
|
||
const mapLocalCurrencyActionsDataToProps = (data) => ({ data }); | ||
|
||
export default function makeGetLocalCurrency(localCurrencyActions) { | ||
return compose( | ||
withClean(localCurrencyActions), | ||
withInitialCall(localCurrencyActions), | ||
withNullLoader(localCurrencyActions), | ||
withData(localCurrencyActions, mapLocalCurrencyActionsDataToProps) | ||
)(LocalCurrency); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters