-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27709 from fvlvte/24877-migrate-device-lib-to-ts
[TS migration] Migrate 'Device' lib to TypeScript
- Loading branch information
Showing
22 changed files
with
105 additions
and
118 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ | |
"date-fns-tz": "^2.0.0", | ||
"dom-serializer": "^0.2.2", | ||
"domhandler": "^4.3.0", | ||
"expensify-common": "git+ssh://[email protected]/Expensify/expensify-common.git#a055da6a339383da825f353d5c0da72a26285007", | ||
"expensify-common": "git+ssh://[email protected]/Expensify/expensify-common.git#886f90cbd5e83218fdfd7784d8356c308ef05791", | ||
"fbjs": "^3.0.2", | ||
"htmlparser2": "^7.2.0", | ||
"idb-keyval": "^6.2.1", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
.../Device/generateDeviceID/index.desktop.js → .../Device/generateDeviceID/index.desktop.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
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) as Promise<string>; | ||
|
||
export default generateDeviceID; |
7 changes: 2 additions & 5 deletions
7
...ions/Device/generateDeviceID/index.ios.js → ...ions/Device/generateDeviceID/index.ios.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: string) => `${deviceID}_${uniqueID}`); | ||
|
||
export default generateDeviceID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type GenerateDeviceID = () => Promise<string>; | ||
|
||
export default GenerateDeviceID; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import packageConfig from '../../../../../package.json'; | ||
import {GetBaseInfo} from './types'; | ||
|
||
const getBaseInfo: GetBaseInfo = () => ({ | ||
appVersion: packageConfig.version, | ||
timestamp: new Date().toISOString().slice(0, 19), | ||
}); | ||
|
||
export default getBaseInfo; |
10 changes: 3 additions & 7 deletions
10
src/libs/actions/Device/getDeviceInfo/getOSAndName/index.native.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 2 additions & 10 deletions
12
src/libs/actions/Device/getDeviceInfo/getOSAndName/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,4 @@ | ||
import {getOSAndName as libGetOSAndName} from 'expensify-common/lib/Device'; | ||
import GetOSAndName from './types'; | ||
// Don't import this file with '* as Device'. It's known to make VSCode IntelliSense crash. | ||
import {getOSAndName} from 'expensify-common/lib/Device'; | ||
|
||
const getOSAndName: GetOSAndName = () => { | ||
// Parameter names are predefined and we don't choose it here | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const {device_name, os_version} = libGetOSAndName(); | ||
// Parameter names are predefined and we don't choose it here | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
return {device_name, os_version}; | ||
}; | ||
export default getOSAndName; |
11 changes: 7 additions & 4 deletions
11
src/libs/actions/Device/getDeviceInfo/getOSAndName/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
// Parameter names are predefined and we don't choose it here | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
type GetOSAndName = () => {device_name: string | undefined; os_version: string | undefined}; | ||
export default GetOSAndName; | ||
type GetOSAndName = () => OSAndName; | ||
type OSAndName = { | ||
deviceName?: string; | ||
osVersion?: string; | ||
}; | ||
|
||
export type {GetOSAndName, OSAndName}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import getBaseInfo from './getBaseInfo'; | ||
import getOSAndName from './getOSAndName/index'; | ||
import {GetDeviceInfo} from './types'; | ||
|
||
const getDeviceInfo: GetDeviceInfo = () => ({ | ||
...getBaseInfo(), | ||
...getOSAndName(), | ||
os: 'Android', | ||
}); | ||
|
||
export default getDeviceInfo; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import getBaseInfo from './getBaseInfo'; | ||
import getOSAndName from './getOSAndName/index'; | ||
import {GetDeviceInfo} from './types'; | ||
|
||
const getDeviceInfo: GetDeviceInfo = () => ({ | ||
...getBaseInfo(), | ||
...getOSAndName(), | ||
deviceName: 'Desktop', | ||
}); | ||
|
||
export default getDeviceInfo; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import getBaseInfo from './getBaseInfo'; | ||
import getOSAndName from './getOSAndName/index'; | ||
import {GetDeviceInfo} from './types'; | ||
|
||
const getDeviceInfo: GetDeviceInfo = () => ({ | ||
...getBaseInfo(), | ||
...getOSAndName(), | ||
os: 'iOS', | ||
}); | ||
|
||
export default getDeviceInfo; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import getBaseInfo from './getBaseInfo'; | ||
import getOSAndName from './getOSAndName/index'; | ||
import {GetDeviceInfo} from './types'; | ||
|
||
const getDeviceInfo: GetDeviceInfo = () => ({ | ||
...getBaseInfo(), | ||
...getOSAndName(), | ||
}); | ||
|
||
export default getDeviceInfo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {OSAndName} from './getOSAndName/types'; | ||
|
||
type BaseInfo = { | ||
appVersion: string; | ||
timestamp: string; | ||
}; | ||
|
||
type GetDeviceInfo = () => DeviceInfo; | ||
type DeviceInfo = BaseInfo & OSAndName & {os?: string; deviceName?: string; deviceVersion?: string}; | ||
type GetBaseInfo = () => BaseInfo; | ||
|
||
export type {GetDeviceInfo, DeviceInfo, GetBaseInfo, BaseInfo}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters