Skip to content

Commit

Permalink
fixes request to version check (#1299)
Browse files Browse the repository at this point in the history
* fixes request to version check

* removes console log

* fixes broken tests
  • Loading branch information
comountainclimber authored and dvdschwrtz committed Jul 8, 2018
1 parent 726b5f1 commit 1e0f4ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
12 changes: 6 additions & 6 deletions __tests__/modules/metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ describe('metadata module tests', () => {
test('it does not show a warning when the versions match', async (done) => {
const spy = jest.spyOn(notifications, 'showWarningNotification')

nock('http://testnet-api.wallet.cityofzion.io')
.get('/v2/version')
.reply(200, { version }, { 'Access-Control-Allow-Origin': '*' })
nock('https://api.github.com/repos/CityOfZion/neon-wallet')
.get('/releases/latest')
.reply(200, { tag_name: version }, { 'Access-Control-Allow-Origin': '*' })

await checkVersion()(dispatch, getState)
expect(spy).not.toHaveBeenCalled()
Expand All @@ -31,9 +31,9 @@ describe('metadata module tests', () => {
test("it shows a warning when the versions don't match", async (done) => {
const spy = jest.spyOn(notifications, 'showWarningNotification')

nock('http://testnet-api.wallet.cityofzion.io')
.get('/v2/version')
.reply(200, { version: generateNewerVersion(version) }, { 'Access-Control-Allow-Origin': '*' })
nock('https://api.github.com/repos/CityOfZion/neon-wallet')
.get('/releases/latest')
.reply(200, { tag_name: generateNewerVersion(version) }, { 'Access-Control-Allow-Origin': '*' })

await checkVersion()(dispatch, getState)
expect(spy).toHaveBeenCalled()
Expand Down
12 changes: 4 additions & 8 deletions app/modules/metadata.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
// @flow
import axios from 'axios'
import { api } from 'neon-js'
import compareVersions from 'compare-versions'

import { showWarningNotification } from './notifications'
import { getNetwork } from '../core/deprecated'
import { NEON_WALLET_RELEASE_LINK, NOTIFICATION_POSITIONS } from '../core/constants'
import { version } from '../../package.json'

const DOWNLOAD_LINK = `<a href='${NEON_WALLET_RELEASE_LINK}' target='_blank' class="notification-link">${NEON_WALLET_RELEASE_LINK}</a>`
const CURRENT_RELEASE_URL =
'https://api.github.com/repos/CityOfZion/neon-wallet/releases/latest'

// Actions
export const checkVersion = () => async (dispatch: DispatchType, getState: GetStateType) => {
const state = getState()
const net = getNetwork(state)
const apiEndpoint = api.neonDB.getAPIEndpoint(net)

const showError = (message) => {
return dispatch(showWarningNotification({
message,
Expand All @@ -26,8 +22,8 @@ export const checkVersion = () => async (dispatch: DispatchType, getState: GetSt
}

try {
const response = await axios.get(`${apiEndpoint}/v2/version`)
const shouldUpdate = response && response.data && compareVersions(version, response.data.version) === -1
const response = await axios.get(CURRENT_RELEASE_URL)
const shouldUpdate = response && response.data && compareVersions(version, response.data.tag_name) === -1

if (shouldUpdate) {
showError(`Your wallet is out of date! Please download the latest version from ${DOWNLOAD_LINK}`)
Expand Down

0 comments on commit 1e0f4ff

Please sign in to comment.