UNPKG

@stokr/components-library

Version:

STOKR - Components Library

184 lines (182 loc) 12.4 kB
"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.getVerifyIdentityChecklist = exports.default = exports.UserChecklist = void 0; var _react = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _ToDoList = _interopRequireWildcard(require("../ToDoList/ToDoList")); var _globalVariables = require("../../constants/globalVariables"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } var UserChecklist = function UserChecklist(props) { var _user$countryObj; var _props$user = props.user, user = _props$user === void 0 ? {} : _props$user, additionalTasks = props.additionalTasks, redirectCookie = props.redirectCookie, getTasksCount = props.getTasksCount, useRelativePath = props.useRelativePath, onTaxIdComplete = props.onTaxIdComplete; var isFromAllowedCountry = (_user$countryObj = user.countryObj) === null || _user$countryObj === void 0 ? void 0 : _user$countryObj.isAllowed; //const isFromAllowedCountry = isFromAllowedCountryFunction(user.country) var _useState = (0, _react.useState)([]), _useState2 = _slicedToArray(_useState, 2), mandatoryTasks = _useState2[0], setmandatoryTasks = _useState2[1]; var _useState3 = (0, _react.useState)(0), _useState4 = _slicedToArray(_useState3, 2), mandatoryTasksCount = _useState4[0], setmandatoryTasksCount = _useState4[1]; var _useState5 = (0, _react.useState)([]), _useState6 = _slicedToArray(_useState5, 2), walletTasks = _useState6[0], setwalletTasks = _useState6[1]; var _useState7 = (0, _react.useState)(0), _useState8 = _slicedToArray(_useState7, 2), walletTasksCount = _useState8[0], setwalletTasksCount = _useState8[1]; var _useState9 = (0, _react.useState)([]), _useState10 = _slicedToArray(_useState9, 2), optionalTasks = _useState10[0], setoptionalTasks = _useState10[1]; (0, _react.useEffect)(function () { generateTodos(user); }, [user]); (0, _react.useEffect)(function () { //calculate mandatory count from tasks if (mandatoryTasks.length > 0) { if (isFromAllowedCountry) { var _mandatoryTasksCount = mandatoryTasks.reduce(function (count, task) { if (task.state === _ToDoList.ToDoTaskState.APPROVED || task.state === _ToDoList.ToDoTaskState.IN_PROGRESS) { return count; } return count + 1; }, 0); setmandatoryTasksCount(_mandatoryTasksCount); } } }, [mandatoryTasks, isFromAllowedCountry]); (0, _react.useEffect)(function () { //calculate wallet count from tasks if (walletTasks.length > 0) { if (isFromAllowedCountry) { var _walletTasksCount = walletTasks.reduce(function (count, task) { if (task.title === 'Liquid Address') { if (task.state === _ToDoList.ToDoTaskState.APPROVED || task.state === _ToDoList.ToDoTaskState.IN_PROGRESS) { return count; } return count + 1; } return count; }, 0); setwalletTasksCount(_walletTasksCount); } } }, [walletTasks, isFromAllowedCountry]); (0, _react.useEffect)(function () { //if you provide function to get tasks count, pass the counter into the function if (getTasksCount) { getTasksCount({ mandatoryTasksCount: mandatoryTasksCount, walletTasksCount: walletTasksCount }); } }, [mandatoryTasksCount, walletTasksCount, getTasksCount]); var generateTodos = function generateTodos(userData) { var country = user.country, user_type = user.user_type, _user$wallets = user.wallets, wallets = _user$wallets === void 0 ? [] : _user$wallets; var liquidWallets = wallets.filter(function (wallet) { return wallet.type === _globalVariables.walletTypes.LIQUID; }) || []; var platformURL = useRelativePath === true ? '' : "https://signup.".concat(_globalVariables.platformDomain); setmandatoryTasks([{ title: user_type === _globalVariables.UserTypes.investor_entity ? 'Country of Entity Registration' : 'Country of Residence', message: !country ? "Please select your country of ".concat(user_type === _globalVariables.UserTypes.investor_entity ? 'entity registration' : 'residence') : !isFromAllowedCountry ? 'STOKR is not yet available where you live' : "Your country of ".concat(user_type === _globalVariables.UserTypes.investor_entity ? 'entity registration' : 'residence', " has been registered"), state: !country ? _ToDoList.ToDoTaskState.SKIPPED : !isFromAllowedCountry ? _ToDoList.ToDoTaskState.DENIED : _ToDoList.ToDoTaskState.APPROVED, link: "".concat(platformURL, "/country-of-residence") }, { title: user_type === _globalVariables.UserTypes.investor_entity ? 'Verify Entity' : 'Verify Identity', message: getVerifyIdentityChecklist(isFromAllowedCountry, user).message, state: getVerifyIdentityChecklist(isFromAllowedCountry, user).state, link: getVerifyIdentityChecklist(isFromAllowedCountry, user).hasLink && "".concat(platformURL, "/verify-identity") }]); setwalletTasks([{ title: 'Liquid Address', message: !isFromAllowedCountry ? 'Sorry, you are living in a country where this is not available' : liquidWallets.length > 0 ? 'Your address is registered' : 'Register a Liquid address where you will receive the securities', state: !isFromAllowedCountry ? _ToDoList.ToDoTaskState.NOT_AVAILABLE : liquidWallets.length > 0 ? _ToDoList.ToDoTaskState.APPROVED : _ToDoList.ToDoTaskState.SKIPPED, link: isFromAllowedCountry && "".concat(platformURL, "/register-liquid-securities") }]); var optionalTasks = [{ title: 'Tax ID', message: !userData.taxId ? 'To invest in certain offerings, you need to provide your tax ID' : userData.taxId && 'You tax ID is submitted', state: !userData.taxId ? _ToDoList.ToDoTaskState.SKIPPED : userData.taxId && _ToDoList.ToDoTaskState.APPROVED, openModal: _ToDoList.ToDoModal.TAX_ID, tooltip: "Some offers require you to provide your Tax ID before being able to invest.\n\nYour tax information will be disclosed to the Luxembourg tax authorities annually for tax compliance purposes required by the Common Reporting Standard implementation." }]; setoptionalTasks(optionalTasks); }; return /*#__PURE__*/_react.default.createElement(_ToDoList.default, _extends({}, props, { mandatoryTasks: mandatoryTasks, walletsTasks: walletTasks, optionalTasks: optionalTasks, additionalTasks: additionalTasks, redirectCookie: redirectCookie, mandatoryTasksCount: mandatoryTasksCount, walletsTasksCount: walletTasksCount, pendingTasksCount: mandatoryTasksCount + walletTasksCount })); }; exports.UserChecklist = UserChecklist; var getVerifyIdentityChecklist = function getVerifyIdentityChecklist(isFromAllowedCountry, user) { var kyc_status = user.kyc_status, user_type = user.user_type; var message; var state; var hasLink = false; if (!isFromAllowedCountry) { message = 'Sorry, you are living in a country where this is not available.'; state = _ToDoList.ToDoTaskState.NOT_AVAILABLE; } else if (!kyc_status || kyc_status.toUpperCase() === 'DRAFT') { message = user_type === _globalVariables.UserTypes.investor_entity ? 'Submit your entity documents for verification.' : 'Submit identity verification for compliance clearance.'; state = _ToDoList.ToDoTaskState.SKIPPED; hasLink = true; } else if (kyc_status.toUpperCase() === 'REJECTED' || kyc_status.toUpperCase() === 'ESCALATED' || kyc_status.toUpperCase() === 'IN PROGRESS' || kyc_status.toUpperCase() === 'INCONCLUSIVE' || kyc_status.toUpperCase() === 'APPROVED' || kyc_status.toUpperCase() === 'DENIED') { message = 'Identity verification is in progress.'; state = _ToDoList.ToDoTaskState.IN_PROGRESS; } else if (kyc_status.toUpperCase() === 'ACCEPTED') { message = user_type === _globalVariables.UserTypes.investor_entity ? 'Entity verification complete.' : 'Identity verification complete.'; state = _ToDoList.ToDoTaskState.APPROVED; } else if (kyc_status.toUpperCase() === 'REAPPLY' || kyc_status.toUpperCase() === 'CANCELLED') { message = user_type === _globalVariables.UserTypes.investor_entity ? 'Please re-verify your entity documentation.' : 'Please re-verify your identity.'; state = _ToDoList.ToDoTaskState.DENIED; hasLink = true; } return { message: message, state: state, hasLink: hasLink }; }; exports.getVerifyIdentityChecklist = getVerifyIdentityChecklist; UserChecklist.propTypes = { user: _propTypes.default.object.isRequired, additionalTasks: _propTypes.default.any, redirectCookie: _propTypes.default.bool, getTasksCount: _propTypes.default.func, useRelativePath: _propTypes.default.bool, onTaxIdComplete: _propTypes.default.func }; var _default = UserChecklist; exports.default = _default;