Skip to content

Commit

Permalink
Merge pull request #2505 from near/add-new-project-validator
Browse files Browse the repository at this point in the history
chore: add new project validator factory to regex
  • Loading branch information
esaminu authored Feb 25, 2022
2 parents e83ecc0 + 416c39d commit 4ca20af
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions packages/frontend/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ export const ValidatorVersion = {

export const MAINNET = 'mainnet';
export const TESTNET = 'testnet';
export const PROJECT_VALIDATOR_PREFIX_MAINNET = '.pool.near';
export const VALIDATOR_PREFIX_MAINNET = '.poolv1.near';
export const PROJECT_VALIDATOR_PREFIX_TESTNET = '.factory01.littlefarm.testnet';
export const VALIDATOR_PREFIX_TESTNET = '.m0';
export const PROJECT_VALIDATOR_PREFIXES_MAINNET = ['.pool.near'];
export const VALIDATOR_PREFIXES_MAINNET = ['.poolv1.near'];
export const PROJECT_VALIDATOR_PREFIXES_TESTNET = ['.factory01.littlefarm.testnet','.factory.colorpalette.testnet'];
export const VALIDATOR_PREFIXES_TESTNET = ['.m0'];

export const PROJECT_VALIDATOR_REGEXP_TESTNET = new RegExp(`.*(${PROJECT_VALIDATOR_PREFIX_TESTNET}|${VALIDATOR_PREFIX_TESTNET})`);
export const PROJECT_VALIDATOR_REGEXP_MAINNET = new RegExp(`.*(${PROJECT_VALIDATOR_PREFIX_MAINNET}|${VALIDATOR_PREFIX_MAINNET})`);
export const PROJECT_VALIDATOR_REGEXP_TESTNET = new RegExp(`.*(${PROJECT_VALIDATOR_PREFIXES_TESTNET.join('|')}|${VALIDATOR_PREFIXES_TESTNET.join('|')})`);
export const PROJECT_VALIDATOR_REGEXP_MAINNET = new RegExp(`.*(${PROJECT_VALIDATOR_PREFIXES_MAINNET.join('|')}|${VALIDATOR_PREFIXES_MAINNET.join('|')})`);

export const getProjectValidatorPrefix = (networkId) => {
export const getFarmingValidatorPrefixes = (networkId) => {
switch (networkId) {
case (MAINNET): {
return PROJECT_VALIDATOR_PREFIX_MAINNET;
return PROJECT_VALIDATOR_PREFIXES_MAINNET;
}
case (TESTNET): {
return PROJECT_VALIDATOR_PREFIX_TESTNET;
return PROJECT_VALIDATOR_PREFIXES_TESTNET;
}
default: {
return PROJECT_VALIDATOR_PREFIX_TESTNET;
return PROJECT_VALIDATOR_PREFIXES_TESTNET;
}
}
};
Expand All @@ -45,20 +45,20 @@ export const getValidatorRegExp = (networkId) => {
};

export const getValidationVersion = (networkId, accountId) => {
const prefix = getValidationNetworkPrefix(networkId);
return accountId.indexOf(prefix) === -1 ? VALIDATOR_VERSION : PROJECT_VALIDATOR_VERSION;
const prefixes = getValidationNetworkPrefixes(networkId);
return prefixes.some((prefix) => accountId.indexOf(prefix) !== -1) ? PROJECT_VALIDATOR_VERSION : VALIDATOR_VERSION;
};

export const getValidationNetworkPrefix = (networkId) => {
export const getValidationNetworkPrefixes = (networkId) => {
switch (networkId) {
case (MAINNET): {
return PROJECT_VALIDATOR_PREFIX_MAINNET;
return PROJECT_VALIDATOR_PREFIXES_MAINNET;
}
case (TESTNET): {
return PROJECT_VALIDATOR_PREFIX_TESTNET;
return PROJECT_VALIDATOR_PREFIXES_TESTNET;
}
default: {
return PROJECT_VALIDATOR_PREFIX_TESTNET;
return PROJECT_VALIDATOR_PREFIXES_TESTNET;
}
}
};

0 comments on commit 4ca20af

Please sign in to comment.