/ src / lib / utils / wave / profile.ts
profile.ts
 1  import { authenticatedCall } from './call';
 2  import { newsletterSubscriptionStatusDtoSchema, waveOwnProfileUserDataSchema } from './types/user';
 3  import parseRes from './utils/parse-res';
 4  
 5  export async function patchProfile(
 6    f = fetch,
 7    profileData: {
 8      payoutAddresses: {
 9        stellar: string | null;
10      };
11    },
12  ) {
13    return parseRes(
14      waveOwnProfileUserDataSchema,
15      await authenticatedCall(f, `/api/user`, {
16        method: 'PATCH',
17        body: JSON.stringify(profileData),
18      }),
19    );
20  }
21  
22  export async function getNewsletterSubscriptionStatus(f = fetch) {
23    return parseRes(
24      newsletterSubscriptionStatusDtoSchema,
25      await authenticatedCall(f, '/api/user/newsletter/status'),
26    );
27  }
28  
29  export async function setNewsletterSubscription(isSubscribed: boolean) {
30    if (isSubscribed) {
31      return authenticatedCall(undefined, '/api/user/newsletter/subscribe', {
32        method: 'POST',
33      });
34    } else {
35      return authenticatedCall(undefined, '/api/user/newsletter/unsubscribe', {
36        method: 'POST',
37      });
38    }
39  }