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

[TS migration] Migrate 'generateDeviceID' lib to TypeScript #27706

Closed
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import DeviceInfo from 'react-native-device-info';
import Str from 'expensify-common/lib/str';
import GenerateDeviceID from './types';

const deviceID = DeviceInfo.getDeviceId();
const uniqueID = Str.guid(deviceID);
Expand All @@ -22,11 +23,7 @@ const uniqueID = Str.guid(deviceID);
*
* Furthermore, the deviceID prefix is not unique to a specific device, but is likely to change from one type of device to another.
* Including this prefix will tell us with a reasonable degree of confidence if the user just uninstalled and reinstalled the app, or if they got a new device.
*
* @returns {Promise<String>}
*/
function generateDeviceID() {
return Promise.resolve(uniqueID);
}
const generateDeviceID: GenerateDeviceID = () => Promise.resolve(uniqueID);

export default generateDeviceID;
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import ELECTRON_EVENTS from '../../../../../desktop/ELECTRON_EVENTS';
import GenerateDeviceID from './types';

/**
* Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app.
*
* @returns {Promise<String>}
*/
function generateDeviceID() {
return window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID);
}
const generateDeviceID: GenerateDeviceID = () => window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID);

export default generateDeviceID;
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import DeviceInfo from 'react-native-device-info';
import GenerateDeviceID from './types';

const deviceID = DeviceInfo.getDeviceId();

/**
* Get the unique ID of the current device. This should remain the same even if the user uninstalls and reinstalls the app.
*
* @returns {Promise<String>}
*/
function generateDeviceID() {
return DeviceInfo.getUniqueId().then((uniqueID) => `${deviceID}_${uniqueID}`);
}
const generateDeviceID: GenerateDeviceID = () => DeviceInfo.getUniqueId().then((uniqueID) => `${deviceID}_${uniqueID}`);

export default generateDeviceID;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Str from 'expensify-common/lib/str';
import GenerateDeviceID from './types';

const uniqueID = Str.guid();

Expand All @@ -13,11 +14,7 @@ const uniqueID = Str.guid();
*
* While this isn't perfect, it's just as good as any other obvious web solution, such as this one https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/deviceId
* which is also different/reset under the same circumstances
*
* @returns {Promise<String>}
*/
function generateDeviceID() {
return Promise.resolve(uniqueID);
}
const generateDeviceID: GenerateDeviceID = () => Promise.resolve(uniqueID);

export default generateDeviceID;
3 changes: 3 additions & 0 deletions src/libs/actions/Device/generateDeviceID/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type GenerateDeviceID = () => Promise<string>;

export default GenerateDeviceID;