@stokr/components-library
Version:
STOKR - Components Library
235 lines (225 loc) • 8.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.generateCoreChecklistTasks = generateCoreChecklistTasks;
exports.getVerifyIdentityChecklist = void 0;
var _globalVariables = require("../constants/globalVariables");
const websiteUrl = process.env.REACT_APP_WEBSITE_DOMAIN;
// Unified copy for all checklist tasks - same everywhere
const TASK_COPY = {
country: {
title: {
entity: 'Country of Entity Registration',
individual: 'Country of Residence'
},
description: {
missing: {
entity: 'Please select your jurisdiction of incorporation.',
individual: 'Please select your country of residence.'
},
not_available: 'STOKR is not yet available in your country of residence.',
done: {
entity: 'Your jurisdiction of incorporation has been registered.',
individual: 'Your country of residence has been registered.'
}
},
iconCopy: {
missing: 'Missing step',
not_available: 'Not available',
done: 'Registered'
}
},
identity: {
title: {
entity: 'Verify Entity',
individual: 'Verify Identity'
},
description: {
not_available: 'Sorry, you are living in a country where this is not available.',
missing: {
entity: 'Submit your entity documents for verification.',
individual: 'Submit identity verification for compliance clearance.'
},
in_progress: 'Identity verification is in progress.',
done: {
entity: 'Entity verification complete.',
individual: 'Identity verification complete.'
},
reapply: {
entity: 'Please re-verify your entity documentation.',
individual: 'Please re-verify your identity.'
}
},
iconCopy: {
not_available: 'Not available',
missing: 'Missing step',
in_progress: 'Under review',
done: 'Verified'
}
},
wallet: {
title: 'Liquid Address',
description: {
missing: 'Register a Liquid address where you will receive the securities.',
not_available: 'Sorry, you are living in a country where this is not available.',
done: 'Your address is registered.'
},
iconCopy: {
missing: 'Missing step',
not_available: 'Not available',
done: 'Registered'
}
},
taxId: {
title: 'Tax ID',
description: {
missing: 'Certain investment products require tax identification before participation.',
done: 'Tax identification confirmed. You may now access products requiring tax compliance verification.'
},
iconCopy: {
missing: 'Missing step',
done: 'Submitted',
not_available: 'Not available'
},
tooltip: "Some offers require you to provide your Tax ID before being able to invest.\nYour tax information will be disclosed to the Luxembourg tax authorities annually for tax compliance purposes required by the Common Reporting Standard implementation."
}
};
// Identity verification checklist function -
const getVerifyIdentityChecklist = (isFromAllowedCountry, user, isEntity) => {
const {
kyc_status
} = user;
let state;
let hasLink = false;
let message;
if (!isFromAllowedCountry) {
state = 'not_available';
message = TASK_COPY.identity.description.not_available;
} else if (!kyc_status || kyc_status.toUpperCase() === 'DRAFT') {
state = 'missing';
hasLink = true;
message = isEntity ? TASK_COPY.identity.description.missing.entity : TASK_COPY.identity.description.missing.individual;
} 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') {
state = 'in_progress';
message = TASK_COPY.identity.description.in_progress;
} else if (kyc_status.toUpperCase() === 'ACCEPTED') {
state = 'done';
message = isEntity ? TASK_COPY.identity.description.done.entity : TASK_COPY.identity.description.done.individual;
} else if (kyc_status.toUpperCase() === 'REAPPLY' || kyc_status.toUpperCase() === 'CANCELLED') {
state = 'missing';
hasLink = true;
message = isEntity ? TASK_COPY.identity.description.reapply.entity : TASK_COPY.identity.description.reapply.individual;
}
return {
state,
hasLink,
message
};
};
exports.getVerifyIdentityChecklist = getVerifyIdentityChecklist;
function getCountryDescription(user, isFromAllowedCountry) {
const {
country,
user_type
} = user;
const isEntity = user_type === _globalVariables.UserTypes.investor_entity;
if (!country) {
return isEntity ? TASK_COPY.country.description.missing.entity : TASK_COPY.country.description.missing.individual;
}
if (!isFromAllowedCountry) {
return TASK_COPY.country.description.not_available;
}
return isEntity ? TASK_COPY.country.description.done.entity : TASK_COPY.country.description.done.individual;
}
/**
* Generate core checklist tasks (country, identity, wallet, tax ID) with unified copy
* @param {Object} user - User object
* @returns {Object} Core checklist tasks with unified copy, country status, all tasks, and remaining count
*/
function generateCoreChecklistTasks(user) {
if (!user) {
return {
country: null,
identity: null,
wallet: null,
taxId: null,
isFromAllowedCountry: false,
allTasks: [],
remainingCount: 0
};
}
const {
country,
user_type,
wallets = [],
taxId,
countryObj
} = user;
const isFromAllowedCountry = countryObj === null || countryObj === void 0 ? void 0 : countryObj.isAllowed;
const liquidWallets = wallets.filter(wallet => wallet.type === _globalVariables.walletTypes.LIQUID) || [];
const hasWallet = liquidWallets.length > 0;
const isEntity = user_type === _globalVariables.UserTypes.investor_entity;
const platformURL = "https://signup.".concat(websiteUrl);
// Country task
const countryStatus = !country ? 'missing' : !isFromAllowedCountry ? 'not_available' : 'done';
const countryTask = {
key: 'country',
title: isEntity ? TASK_COPY.country.title.entity : TASK_COPY.country.title.individual,
description: getCountryDescription(user, isFromAllowedCountry),
iconState: countryStatus,
iconCopy: TASK_COPY.country.iconCopy[countryStatus],
link: "".concat(platformURL, "/country-of-residence"),
isClickable: countryStatus !== 'done'
};
// Identity task
const verifyIdentityChecklist = getVerifyIdentityChecklist(isFromAllowedCountry, user, isEntity);
const identity = {
key: 'kyc',
title: isEntity ? TASK_COPY.identity.title.entity : TASK_COPY.identity.title.individual,
description: verifyIdentityChecklist.message,
iconState: verifyIdentityChecklist.state,
iconCopy: TASK_COPY.identity.iconCopy[verifyIdentityChecklist.state],
link: "".concat(platformURL, "/verify-identity"),
isClickable: verifyIdentityChecklist.hasLink
};
// Wallet
const walletStatus = hasWallet ? 'done' : 'missing';
const walletDescription = !isFromAllowedCountry ? TASK_COPY.wallet.description.not_available : hasWallet ? TASK_COPY.wallet.description.done : TASK_COPY.wallet.description.missing;
const wallet = {
key: 'wallet',
title: TASK_COPY.wallet.title,
description: walletDescription,
iconState: walletStatus,
iconCopy: TASK_COPY.wallet.iconCopy[walletStatus],
link: "".concat(platformURL, "/register-liquid-securities"),
isClickable: isFromAllowedCountry && walletStatus !== 'done'
};
// Tax ID
const taxStatus = taxId ? 'done' : 'missing';
const taxIdTask = {
key: 'taxId',
title: TASK_COPY.taxId.title,
description: TASK_COPY.taxId.description[taxStatus],
iconState: taxStatus,
iconCopy: TASK_COPY.taxId.iconCopy[taxStatus],
openModal: 'taxId',
tooltip: TASK_COPY.taxId.tooltip,
isClickable: taxStatus !== 'done'
};
// Create all tasks array
const allTasks = [countryTask, identity, wallet, taxIdTask].filter(Boolean);
// Calculate remaining count based on missing items
const remainingCount = allTasks.filter(task => task.iconState === 'missing' || task.iconState === 'not_available').length;
return {
country: countryTask,
identity,
wallet,
taxId: taxIdTask,
isFromAllowedCountry,
allTasks,
remainingCount
};
}
var _default = exports.default = generateCoreChecklistTasks;