forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreferrals.ts
More file actions
39 lines (33 loc) · 1017 Bytes
/
Copy pathreferrals.ts
File metadata and controls
39 lines (33 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { getIdToken } from './firebase';
export type ReferralEnvironment = 'dev' | 'prod';
export interface ReferralClaimResult {
claimed: boolean;
trial_days: number;
}
export function navigateToDesktopDownload(): void {
window.location.assign('https://macos.omi.me');
}
export function parseReferralEnvironment(
value: string | null,
): ReferralEnvironment | null {
return value === 'dev' || value === 'prod' ? value : null;
}
export async function claimReferralTrial(
code: string,
environment: ReferralEnvironment,
): Promise<ReferralClaimResult> {
const token = await getIdToken();
if (!token) throw new Error('Not authenticated');
const response = await fetch('/api/referrals/claim', {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ code, environment }),
});
if (!response.ok) {
throw new Error(`Referral claim failed: ${response.status}`);
}
return response.json();
}