Skip to content

Commit cab165d

Browse files
chore: send origin to blockchain api, added expo check for user agent
1 parent f83ab59 commit cab165d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

packages/core/src/controllers/BlockchainApiController.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type {
2626
} from '../utils/TypeUtil';
2727
import { OptionsController } from './OptionsController';
2828
import { ConstantsUtil } from '../utils/ConstantsUtil';
29+
import { ApiUtil } from '../utils/ApiUtil';
2930

3031
// -- Helpers ------------------------------------------- //
3132
const baseUrl = CoreHelperUtil.getBlockchainApiUrl();
@@ -36,7 +37,9 @@ const getHeaders = () => {
3637
return {
3738
'Content-Type': 'application/json',
3839
'x-sdk-type': sdkType,
39-
'x-sdk-version': sdkVersion
40+
'x-sdk-version': sdkVersion,
41+
'User-Agent': ApiUtil.getUserAgent(),
42+
'origin': ApiUtil.getOrigin()
4043
};
4144
};
4245

packages/core/src/utils/ApiUtil.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,37 @@ export const ApiUtil = {
1414
].join('.');
1515
},
1616

17+
getEnvironment() {
18+
try {
19+
// Check if Expo is installed
20+
const hasExpoGlobal = !!(global as any).expo;
21+
const hasExpoConstants = hasExpoGlobal && (global as any).expo?.modules?.ExponentConstants;
22+
const environment: string | undefined =
23+
hasExpoConstants && (global as any).expo?.modules?.ExponentConstants?.executionEnvironment;
24+
25+
if (environment === 'standalone' || environment === 'storeClient') {
26+
return 'expo-managed';
27+
} else if (environment === 'bare') {
28+
return 'expo-bare';
29+
}
30+
31+
return 'bare';
32+
} catch {
33+
return 'bare';
34+
}
35+
},
36+
1737
getUserAgent() {
1838
const rnVersion = Platform.select({
1939
ios: this.getReactNativeVersion(),
2040
android: this.getReactNativeVersion(),
2141
default: 'undefined'
2242
});
2343

24-
return `${Platform.OS}-${Platform.Version}@rn-${rnVersion}`;
44+
const envPrefix = this.getEnvironment();
45+
46+
const userAgent = `${Platform.OS}-${Platform.Version}@rn-${rnVersion}@${envPrefix}`;
47+
48+
return userAgent;
2549
}
2650
};

0 commit comments

Comments
 (0)