Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes request to version check #1299

Merged
merged 3 commits into from
Jul 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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