Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/lib-paywall / src / methods / verifyCreate.js
Size: Mime:
import { store } from '../state/store';
import { setData } from '../state/actions';

import { processType, getUserError, paywallStatus } from '../constants/paywall';

import { getUserDataRequest } from './requests';
import getStatusFromUserData from '../utils/getStatusFromUserData';

export default async ({ token, trackingEventPrefix }) => {
  const { apiHost } = store.getState();
  return new Promise(resolve => {
    getUserDataRequest({ token, apiHost })
      .then(async res => {
        const data = await res.text();

        const { status } = getStatusFromUserData({ data, token, trackingEventPrefix, apiHost });
        if (!status.shouldOpenModal) {
          resolve({
            status: paywallStatus.PASS,
          });
        } else {
          store.dispatch(
            setData({
              trackingEventPostfix: status.trackingEventPostfix,
              modalType: status.modalType,
              isPaywallModalOpen: true,
              resolve,
              process: processType.CREATE,
            })
          );
        }
      })
      .catch(e => {
        resolve({ ...getUserError, message: e.message });
      });
  });
};