Skip to content
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
19 changes: 2 additions & 17 deletions src/InstallationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,10 @@
*/

import Storage from './Storage';
const uuidv4 = require('uuid/v4');

let iidCache = null;

function hexOctet() {
return Math.floor(
(1 + Math.random()) * 0x10000
).toString(16).substring(1);
}

function generateId() {
return (
hexOctet() + hexOctet() + '-' +
hexOctet() + '-' +
hexOctet() + '-' +
hexOctet() + '-' +
hexOctet() + hexOctet() + hexOctet()
);
}

const InstallationController = {
currentInstallationId(): Promise<string> {
if (typeof iidCache === 'string') {
Expand All @@ -37,7 +22,7 @@ const InstallationController = {
const path = Storage.generatePath('installationId');
return Storage.getItemAsync(path).then((iid) => {
if (!iid) {
iid = generateId();
iid = uuidv4();
return Storage.setItemAsync(path, iid).then(() => {
iidCache = iid;
return iid;
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/InstallationController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jest.dontMock('../CoreManager');
jest.dontMock('../InstallationController');
jest.dontMock('../Storage');
jest.dontMock('../StorageController.default');
jest.mock('uuid/v4', () => {
let value = 0;
return () => value++ + '';
});

const CoreManager = require('../CoreManager');
const InstallationController = require('../InstallationController');
Expand Down