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

Feature/fix-version-check #1307

Merged
merged 2 commits into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 11 additions & 7 deletions __tests__/modules/metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,27 @@ 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()
done()
})

test("it shows a warning when the versions don't match", async done => {
test('it shows a warning when the versions dont match', async done => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo - should be don't

const spy = jest.spyOn(notifications, 'showWarningNotification')

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

Expand Down
15 changes: 5 additions & 10 deletions app/modules/metadata.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
// @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 =>
dispatch(
const showError = message => dispatch(
showWarningNotification({
message,
autoDismiss: 0,
Expand All @@ -33,11 +28,11 @@ export const checkVersion = () => async (
)

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

if (shouldUpdate) {
showError(
Expand Down