diff options
author | kumavis <aaron@kumavis.me> | 2018-06-14 14:30:31 +0800 |
---|---|---|
committer | kumavis <aaron@kumavis.me> | 2018-06-14 14:30:31 +0800 |
commit | 44a8e48a04ea69e1f8e530ae1bacf55890f8df98 (patch) | |
tree | 5c344b5cb746b35504edb4b2903b2e533db527f6 | |
parent | ac8b56a00defff4cb44a6a34251a19d8ab6159b6 (diff) | |
download | tangerine-wallet-browser-44a8e48a04ea69e1f8e530ae1bacf55890f8df98.tar.gz tangerine-wallet-browser-44a8e48a04ea69e1f8e530ae1bacf55890f8df98.tar.zst tangerine-wallet-browser-44a8e48a04ea69e1f8e530ae1bacf55890f8df98.zip |
notices - replace getLatestNotice with getNextNotice
-rw-r--r-- | app/scripts/metamask-controller.js | 3 | ||||
-rw-r--r-- | app/scripts/notice-controller.js | 29 | ||||
-rw-r--r-- | development/states/conf-tx.json | 2 | ||||
-rw-r--r-- | development/states/first-time.json | 2 | ||||
-rw-r--r-- | development/states/notice.json | 2 | ||||
-rw-r--r-- | mascara/src/app/first-time/notice-screen.js | 14 | ||||
-rw-r--r-- | old-ui/app/app.js | 6 | ||||
-rw-r--r-- | test/unit/app/controllers/notice-controller-test.js | 50 | ||||
-rw-r--r-- | ui/app/app.js | 4 | ||||
-rw-r--r-- | ui/app/components/pages/home.js | 8 | ||||
-rw-r--r-- | ui/app/components/pages/notice.js | 12 | ||||
-rw-r--r-- | ui/app/reducers/metamask.js | 4 |
12 files changed, 39 insertions, 97 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index e444180cc..cc02958b5 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -189,9 +189,6 @@ module.exports = class MetamaskController extends EventEmitter { version, firstVersion: initState.firstTimeInfo.version, }) - this.noticeController.updateNoticesList() - // to be uncommented when retrieving notices from a remote server. - // this.noticeController.startPolling() this.shapeshiftController = new ShapeShiftController({ initState: initState.ShapeShiftController, diff --git a/app/scripts/notice-controller.js b/app/scripts/notice-controller.js index 377ef5055..635922104 100644 --- a/app/scripts/notice-controller.js +++ b/app/scripts/notice-controller.js @@ -13,7 +13,7 @@ module.exports = class NoticeController extends EventEmitter { this.firstVersion = opts.firstVersion this.version = opts.version const initState = extend({ - noticesList: [], + noticesList: hardCodedNotices, }, opts.initState) this.store = new ObservableStore(initState) this.memStore = new ObservableStore({}) @@ -29,9 +29,9 @@ module.exports = class NoticeController extends EventEmitter { return notices.filter((notice) => notice.read === false) } - getLatestUnreadNotice () { + getNextUnreadNotice () { const unreadNotices = this.getUnreadNotices() - return unreadNotices[unreadNotices.length - 1] + return unreadNotices[0] } async setNoticesList (noticesList) { @@ -47,7 +47,7 @@ module.exports = class NoticeController extends EventEmitter { notices[index].read = true notices[index].body = '' this.setNoticesList(notices) - const latestNotice = this.getLatestUnreadNotice() + const latestNotice = this.getNextUnreadNotice() cb(null, latestNotice) } catch (err) { cb(err) @@ -64,15 +64,6 @@ module.exports = class NoticeController extends EventEmitter { return result } - startPolling () { - if (this.noticePoller) { - clearInterval(this.noticePoller) - } - this.noticePoller = setInterval(() => { - this.noticeController.updateNoticesList() - }, 300000) - } - _mergeNotices (oldNotices, newNotices) { return uniqBy(oldNotices.concat(newNotices), 'id') } @@ -91,19 +82,15 @@ module.exports = class NoticeController extends EventEmitter { }) } - _mapNoticeIds (notices) { - return notices.map((notice) => notice.id) - } - async _retrieveNoticeData () { // Placeholder for the API. - return hardCodedNotices + return [] } _updateMemstore () { - const lastUnreadNotice = this.getLatestUnreadNotice() - const noActiveNotices = !lastUnreadNotice - this.memStore.updateState({ lastUnreadNotice, noActiveNotices }) + const nextUnreadNotice = this.getNextUnreadNotice() + const noActiveNotices = !nextUnreadNotice + this.memStore.updateState({ nextUnreadNotice, noActiveNotices }) } } diff --git a/development/states/conf-tx.json b/development/states/conf-tx.json index 0f1a13751..57f667cb9 100644 --- a/development/states/conf-tx.json +++ b/development/states/conf-tx.json @@ -52,7 +52,7 @@ "conversionRate": 12.7200827, "conversionDate": 1487363041, "noActiveNotices": true, - "lastUnreadNotice": { + "nextUnreadNotice": { "read": true, "date": "Thu Feb 09 2017", "title": "Terms of Use", diff --git a/development/states/first-time.json b/development/states/first-time.json index fe9188b80..f10eefd35 100644 --- a/development/states/first-time.json +++ b/development/states/first-time.json @@ -12,7 +12,7 @@ "conversionRate": 12.7527416, "conversionDate": 1487624341, "noActiveNotices": false, - "lastUnreadNotice": { + "nextUnreadNotice": { "read": false, "date": "Thu Feb 09 2017", "title": "Terms of Use", diff --git a/development/states/notice.json b/development/states/notice.json index efeffab08..4401393c3 100644 --- a/development/states/notice.json +++ b/development/states/notice.json @@ -13,7 +13,7 @@ "conversionRate": 8.3533002, "conversionDate": 1481671082, "noActiveNotices": false, - "lastUnreadNotice": { + "nextUnreadNotice": { "read": false, "date": "Tue Dec 13 2016", "title": "MultiVault Support", diff --git a/mascara/src/app/first-time/notice-screen.js b/mascara/src/app/first-time/notice-screen.js index a449ccfa9..8cb6f1057 100644 --- a/mascara/src/app/first-time/notice-screen.js +++ b/mascara/src/app/first-time/notice-screen.js @@ -14,7 +14,7 @@ import LoadingScreen from './loading-screen' class NoticeScreen extends Component { static propTypes = { address: PropTypes.string.isRequired, - lastUnreadNotice: PropTypes.shape({ + nextUnreadNotice: PropTypes.shape({ title: PropTypes.string, date: PropTypes.string, body: PropTypes.string, @@ -31,7 +31,7 @@ class NoticeScreen extends Component { }; static defaultProps = { - lastUnreadNotice: {}, + nextUnreadNotice: {}, }; state = { @@ -47,8 +47,8 @@ class NoticeScreen extends Component { } acceptTerms = () => { - const { markNoticeRead, lastUnreadNotice, history } = this.props - markNoticeRead(lastUnreadNotice) + const { markNoticeRead, nextUnreadNotice, history } = this.props + markNoticeRead(nextUnreadNotice) .then(hasActiveNotices => { if (!hasActiveNotices) { history.push(INITIALIZE_BACKUP_PHRASE_ROUTE) @@ -72,7 +72,7 @@ class NoticeScreen extends Component { render () { const { address, - lastUnreadNotice: { title, body }, + nextUnreadNotice: { title, body }, isLoading, } = this.props const { atBottom } = this.state @@ -113,12 +113,12 @@ class NoticeScreen extends Component { } const mapStateToProps = ({ metamask, appState }) => { - const { selectedAddress, lastUnreadNotice, noActiveNotices } = metamask + const { selectedAddress, nextUnreadNotice, noActiveNotices } = metamask const { isLoading } = appState return { address: selectedAddress, - lastUnreadNotice, + nextUnreadNotice, noActiveNotices, isLoading, } diff --git a/old-ui/app/app.js b/old-ui/app/app.js index abeb4f3f9..5c2dccc03 100644 --- a/old-ui/app/app.js +++ b/old-ui/app/app.js @@ -73,7 +73,7 @@ function mapStateToProps (state) { network: state.metamask.network, provider: state.metamask.provider, forgottenPassword: state.appState.forgottenPassword, - lastUnreadNotice: state.metamask.lastUnreadNotice, + nextUnreadNotice: state.metamask.nextUnreadNotice, lostAccounts: state.metamask.lostAccounts, frequentRpcList: state.metamask.frequentRpcList || [], featureFlags, @@ -460,9 +460,9 @@ App.prototype.renderPrimary = function () { }, [ h(NoticeScreen, { - notice: props.lastUnreadNotice, + notice: props.nextUnreadNotice, key: 'NoticeScreen', - onConfirm: () => props.dispatch(actions.markNoticeRead(props.lastUnreadNotice)), + onConfirm: () => props.dispatch(actions.markNoticeRead(props.nextUnreadNotice)), }), !props.isInitialized && h('.flex-row.flex-center.flex-grow', [ diff --git a/test/unit/app/controllers/notice-controller-test.js b/test/unit/app/controllers/notice-controller-test.js index e78b69623..b3ae75080 100644 --- a/test/unit/app/controllers/notice-controller-test.js +++ b/test/unit/app/controllers/notice-controller-test.js @@ -14,18 +14,6 @@ describe('notice-controller', function () { }) describe('notices', function () { - describe('#getNoticesList', function () { - it('should return an empty array when new', function (done) { - // const testList = [{ - // id: 0, - // read: false, - // title: 'Futuristic Notice', - // }] - var result = noticeController.getNoticesList() - assert.equal(result.length, 0) - done() - }) - }) describe('#setNoticesList', function () { it('should set data appropriately', function (done) { @@ -41,36 +29,6 @@ describe('notice-controller', function () { }) }) - describe('#updateNoticeslist', function () { - it('should integrate the latest changes from the source', function (done) { - var testList = [{ - id: 55, - read: false, - title: 'Futuristic Notice', - }] - noticeController.setNoticesList(testList) - noticeController.updateNoticesList().then(() => { - var newList = noticeController.getNoticesList() - assert.ok(newList[0].id === 55) - assert.ok(newList[1]) - done() - }) - }) - it('should not overwrite any existing fields', function (done) { - var testList = [{ - id: 0, - read: false, - title: 'Futuristic Notice', - }] - noticeController.setNoticesList(testList) - var newList = noticeController.getNoticesList() - assert.equal(newList[0].id, 0) - assert.equal(newList[0].title, 'Futuristic Notice') - assert.equal(newList.length, 1) - done() - }) - }) - describe('#markNoticeRead', function () { it('should mark a notice as read', function (done) { var testList = [{ @@ -86,7 +44,7 @@ describe('notice-controller', function () { }) }) - describe('#getLatestUnreadNotice', function () { + describe('#getNextUnreadNotice', function () { it('should retrieve the latest unread notice', function (done) { var testList = [ {id: 0, read: true, title: 'Past Notice'}, @@ -94,8 +52,8 @@ describe('notice-controller', function () { {id: 2, read: false, title: 'Future Notice'}, ] noticeController.setNoticesList(testList) - var latestUnread = noticeController.getLatestUnreadNotice() - assert.equal(latestUnread.id, 2) + var latestUnread = noticeController.getNextUnreadNotice() + assert.equal(latestUnread.id, 1) done() }) it('should return undefined if no unread notices exist.', function (done) { @@ -105,7 +63,7 @@ describe('notice-controller', function () { {id: 2, read: true, title: 'Future Notice'}, ] noticeController.setNoticesList(testList) - var latestUnread = noticeController.getLatestUnreadNotice() + var latestUnread = noticeController.getNextUnreadNotice() assert.ok(!latestUnread) done() }) diff --git a/ui/app/app.js b/ui/app/app.js index ec2329463..d0e48a368 100644 --- a/ui/app/app.js +++ b/ui/app/app.js @@ -314,7 +314,7 @@ function mapStateToProps (state) { noActiveNotices, seedWords, unapprovedTxs, - lastUnreadNotice, + nextUnreadNotice, lostAccounts, unapprovedMsgCount, unapprovedPersonalMsgCount, @@ -348,7 +348,7 @@ function mapStateToProps (state) { network: state.metamask.network, provider: state.metamask.provider, forgottenPassword: state.appState.forgottenPassword, - lastUnreadNotice, + nextUnreadNotice, lostAccounts, frequentRpcList: state.metamask.frequentRpcList || [], currentCurrency: state.metamask.currentCurrency, diff --git a/ui/app/components/pages/home.js b/ui/app/components/pages/home.js index 9110f8202..c53413d3b 100644 --- a/ui/app/components/pages/home.js +++ b/ui/app/components/pages/home.js @@ -86,9 +86,9 @@ class Home extends Component { // if (!props.noActiveNotices) { // log.debug('rendering notice screen for unread notices.') // return h(NoticeScreen, { - // notice: props.lastUnreadNotice, + // notice: props.nextUnreadNotice, // key: 'NoticeScreen', - // onConfirm: () => props.dispatch(actions.markNoticeRead(props.lastUnreadNotice)), + // onConfirm: () => props.dispatch(actions.markNoticeRead(props.nextUnreadNotice)), // }) // } else if (props.lostAccounts && props.lostAccounts.length > 0) { // log.debug('rendering notice screen for lost accounts view.') @@ -279,7 +279,7 @@ function mapStateToProps (state) { noActiveNotices, seedWords, unapprovedTxs, - lastUnreadNotice, + nextUnreadNotice, lostAccounts, unapprovedMsgCount, unapprovedPersonalMsgCount, @@ -313,7 +313,7 @@ function mapStateToProps (state) { network: state.metamask.network, provider: state.metamask.provider, forgottenPassword: state.appState.forgottenPassword, - lastUnreadNotice, + nextUnreadNotice, lostAccounts, frequentRpcList: state.metamask.frequentRpcList || [], currentCurrency: state.metamask.currentCurrency, diff --git a/ui/app/components/pages/notice.js b/ui/app/components/pages/notice.js index 2329a9147..a9077b98b 100644 --- a/ui/app/components/pages/notice.js +++ b/ui/app/components/pages/notice.js @@ -154,11 +154,11 @@ class Notice extends Component { const mapStateToProps = state => { const { metamask } = state - const { noActiveNotices, lastUnreadNotice, lostAccounts } = metamask + const { noActiveNotices, nextUnreadNotice, lostAccounts } = metamask return { noActiveNotices, - lastUnreadNotice, + nextUnreadNotice, lostAccounts, } } @@ -171,21 +171,21 @@ Notice.propTypes = { const mapDispatchToProps = dispatch => { return { - markNoticeRead: lastUnreadNotice => dispatch(actions.markNoticeRead(lastUnreadNotice)), + markNoticeRead: nextUnreadNotice => dispatch(actions.markNoticeRead(nextUnreadNotice)), markAccountsFound: () => dispatch(actions.markAccountsFound()), } } const mergeProps = (stateProps, dispatchProps, ownProps) => { - const { noActiveNotices, lastUnreadNotice, lostAccounts } = stateProps + const { noActiveNotices, nextUnreadNotice, lostAccounts } = stateProps const { markNoticeRead, markAccountsFound } = dispatchProps let notice let onConfirm if (!noActiveNotices) { - notice = lastUnreadNotice - onConfirm = () => markNoticeRead(lastUnreadNotice) + notice = nextUnreadNotice + onConfirm = () => markNoticeRead(nextUnreadNotice) } else if (lostAccounts && lostAccounts.length > 0) { notice = generateLostAccountsNotice(lostAccounts) onConfirm = () => markAccountsFound() diff --git a/ui/app/reducers/metamask.js b/ui/app/reducers/metamask.js index a4d1aece5..6c8ac9ed7 100644 --- a/ui/app/reducers/metamask.js +++ b/ui/app/reducers/metamask.js @@ -21,7 +21,7 @@ function reduceMetamask (state, action) { identities: {}, unapprovedTxs: {}, noActiveNotices: true, - lastUnreadNotice: undefined, + nextUnreadNotice: undefined, frequentRpcList: [], addressBook: [], selectedTokenAddress: null, @@ -65,7 +65,7 @@ function reduceMetamask (state, action) { case actions.SHOW_NOTICE: return extend(metamaskState, { noActiveNotices: false, - lastUnreadNotice: action.value, + nextUnreadNotice: action.value, }) case actions.CLEAR_NOTICES: |