-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the ability both to notify the webui of when a wallet is created and the ability for the webui to call a function to create wallets too
- Loading branch information
Showing
13 changed files
with
310 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const types = require('../constants/rewards_types') | ||
|
||
export const createWalletRequested = () => ({ | ||
type: types.CREATE_WALLET_REQUESTED | ||
}) | ||
|
||
export const walletCreated = () => ({ | ||
type: types.WALLET_CREATED | ||
}) | ||
|
||
export const walletCreateFailed = () => ({ | ||
type: types.WALLET_CREATE_FAILED | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
console.log('brave_rewards.js loaded') | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const React = require('react') | ||
const { render } = require('react-dom') | ||
const { Provider } = require('react-redux') | ||
const App = require('./components/app') | ||
const { bindActionCreators } = require('redux') | ||
|
||
window.cr.define('brave_rewards', function () { | ||
'use strict' | ||
|
||
function initialize () { | ||
const store = require('./store') | ||
render( | ||
<Provider store={store}> | ||
<App /> | ||
</Provider>, | ||
document.getElementById('root')) | ||
window.i18nTemplate.process(window.document, window.loadTimeData) | ||
} | ||
|
||
function getActions () { | ||
const store = require('./store') | ||
const rewardsActions = require('./actions/rewards_actions') | ||
return bindActionCreators(rewardsActions, store.dispatch.bind(store)) | ||
} | ||
|
||
function walletCreated () { | ||
getActions().walletCreated() | ||
} | ||
|
||
function walletCreateFailed () { | ||
getActions().walletCreateFailed() | ||
} | ||
|
||
return { | ||
initialize, | ||
walletCreated, | ||
walletCreateFailed | ||
} | ||
}) | ||
|
||
document.addEventListener('DOMContentLoaded', window.brave_rewards.initialize) | ||
|
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,59 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const React = require('react') | ||
const { bindActionCreators } = require('redux') | ||
const { connect } = require('react-redux') | ||
const rewardsActions = require('../actions/rewards_actions') | ||
|
||
const CreateWalletLink = (props) => | ||
<div> | ||
<a href='#' onClick={props.createWalletClicked}>Create Wallet</a> | ||
</div> | ||
|
||
class RewardsPage extends React.Component { | ||
constructor (props) { | ||
super(props) | ||
this.onCreateWalletClicked = this.onCreateWalletClicked.bind(this) | ||
} | ||
|
||
onCreateWalletClicked() { | ||
this.actions.createWalletRequested() | ||
} | ||
|
||
get actions () { | ||
return this.props.actions | ||
} | ||
|
||
render () { | ||
const { rewardsData } = this.props | ||
return ( | ||
<div> | ||
<CreateWalletLink createWalletClicked={this.onCreateWalletClicked} /> | ||
{ | ||
rewardsData.walletCreated | ||
? <div>Wallet Created!</div> | ||
: null | ||
} | ||
{ | ||
rewardsData.walletCreateFailed | ||
? <div>Wallet Create Failed!</div> | ||
: null | ||
} | ||
</div>) | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
rewardsData: state.rewardsData | ||
}) | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
actions: bindActionCreators(rewardsActions, dispatch) | ||
}) | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(RewardsPage) |
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 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
export const CREATE_WALLET_REQUESTED = 'CREATE_WALLET_REQUESTED' | ||
export const WALLET_CREATED = 'WALLET_CREATED' | ||
export const WALLET_CREATE_FAILED = 'WALLET_CREATE_FAILED' |
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,12 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { combineReducers } from 'redux' | ||
import rewardsReducer from './rewards_reducer' | ||
|
||
const combinedReducer = combineReducers({ | ||
rewardsData: rewardsReducer | ||
}) | ||
|
||
export default combinedReducer |
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,37 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
/* global chrome */ | ||
|
||
const types = require('../constants/rewards_types') | ||
const storage = require('../storage') | ||
|
||
const rewardsReducer = (state, action) => { | ||
if (state === undefined) { | ||
state = storage.load() || {} | ||
state = Object.assign(storage.getInitialState(), state) | ||
} | ||
const startingState = state | ||
switch (action.type) { | ||
case types.CREATE_WALLET_REQUESTED: | ||
chrome.send('createWalletRequested', []); | ||
break | ||
case types.WALLET_CREATED: | ||
state = {... state} | ||
state.walletCreated = true | ||
break | ||
case types.WALLET_CREATE_FAILED: | ||
state = {... state} | ||
state.walletCreateFailed = true | ||
break | ||
} | ||
|
||
if (state !== startingState) { | ||
storage.debouncedSave(state) | ||
} | ||
|
||
return state | ||
} | ||
|
||
export default rewardsReducer |
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,30 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const debounce = require('../common/debounce') | ||
|
||
const keyName = 'rewards-data' | ||
|
||
const cleanData = (state) => ({}) | ||
|
||
module.exports.getInitialState = () => cleanData({}) | ||
|
||
module.exports.load = () => { | ||
const data = window.localStorage.getItem(keyName) | ||
let state | ||
if (data) { | ||
try { | ||
state = JSON.parse(data) | ||
} catch (e) { | ||
console.error('Could not parse local storage data: ', e) | ||
} | ||
} | ||
return cleanData(state) | ||
} | ||
|
||
module.exports.debouncedSave = debounce((data) => { | ||
if (data) { | ||
window.localStorage.setItem(keyName, JSON.stringify(cleanData(data))) | ||
} | ||
}, 50) |
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,9 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { createStore } from 'redux' | ||
import reducers from './reducers' | ||
|
||
const store = createStore(reducers) | ||
module.exports = store |
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