-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathTravel.ts
44 lines (41 loc) · 1.49 KB
/
Travel.ts
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
40
41
42
43
44
import type {OnyxUpdate} from 'react-native-onyx';
import * as API from '@libs/API';
import {SIDE_EFFECT_REQUEST_COMMANDS} from '@libs/API/types';
import asyncOpenURL from '@libs/asyncOpenURL';
import ONYXKEYS from '@src/ONYXKEYS';
import {buildTravelDotURL} from './Link';
/**
* Accept Spotnana terms and conditions to receive a proper token used for authenticating further actions
*/
function acceptSpotnanaTerms() {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: 'merge',
key: ONYXKEYS.NVP_TRAVEL_SETTINGS,
value: {
hasAcceptedTerms: true,
},
},
];
const error = new Error('Failed to generate spotnana token.');
return new Promise((_, reject) => {
asyncOpenURL(
// eslint-disable-next-line rulesdir/no-api-side-effects-method
API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.ACCEPT_SPOTNANA_TERMS, null, {optimisticData})
.then((response) => {
if (!response?.spotnanaToken) {
reject(error);
throw error;
}
return buildTravelDotURL(response.spotnanaToken);
})
.catch(() => {
reject(error);
throw error;
}),
(travelDotURL) => travelDotURL ?? '',
);
});
}
// eslint-disable-next-line import/prefer-default-export
export {acceptSpotnanaTerms};