Skip to content

Commit

Permalink
change files structure and add types.ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Sep 19, 2023
1 parent d731c90 commit 08b00fd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/libs/actions/Device/generateDeviceID/index.android.ts
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 @@ -23,8 +24,6 @@ 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.
*/
function generateDeviceID(): Promise<string> {
return Promise.resolve(uniqueID);
}
const generateDeviceID: GenerateDeviceID = () => Promise.resolve(uniqueID);

export default generateDeviceID;
5 changes: 2 additions & 3 deletions src/libs/actions/Device/generateDeviceID/index.desktop.ts
Original file line number Diff line number Diff line change
@@ -1,10 +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.
*/
function generateDeviceID(): Promise<string> {
return window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID);
}
const generateDeviceID: GenerateDeviceID = () => window.electron.invoke(ELECTRON_EVENTS.REQUEST_DEVICE_ID);

Check failure on line 7 in src/libs/actions/Device/generateDeviceID/index.desktop.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe return of an `any` typed value

Check failure on line 7 in src/libs/actions/Device/generateDeviceID/index.desktop.ts

View workflow job for this annotation

GitHub Actions / typecheck

Property 'electron' does not exist on type 'Window & typeof globalThis'. Did you mean 'Electron'?

export default generateDeviceID;
5 changes: 2 additions & 3 deletions src/libs/actions/Device/generateDeviceID/index.ios.ts
Original file line number Diff line number Diff line change
@@ -1,12 +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.
*/
function generateDeviceID(): Promise<string> {
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 @@ -14,8 +15,6 @@ 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
*/
function generateDeviceID(): Promise<string> {
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;

0 comments on commit 08b00fd

Please sign in to comment.