Skip to content

Commit

Permalink
Merge pull request #3483 from Emurgo/ruslan/removed-validator
Browse files Browse the repository at this point in the history
removed validator package dependency
  • Loading branch information
vsubhuman committed Apr 29, 2024
2 parents 18b844e + 4a2b53c commit fc27d20
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import styles from './DelegationSendForm.scss';
import globalMessages from '../../../i18n/global-messages';
import WarningBox from '../../widgets/WarningBox';
import type { $npm$ReactIntl$IntlFormat, } from 'react-intl';
import isHexadecimal from 'validator/lib/isHexadecimal';
import LocalizableError from '../../../i18n/LocalizableError';
import { bech32, } from 'bech32';
import { isHex } from '@emurgo/yoroi-lib/dist/internals/utils/index';

const messages = defineMessages({
invalidPoolId: {
Expand All @@ -39,7 +39,7 @@ function validateAndSetPool(
if (id.length !== 56) {
return false;
}
return isHexadecimal(id);
return isHex(id);
}
try {
const payload = Buffer.from(
Expand Down
4 changes: 2 additions & 2 deletions packages/yoroi-extension/app/stores/stateless/tokenHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type {
TokenLookupKey, TokenEntry,
} from '../../api/common/lib/MultiToken';
import type { TokenRow, TokenMetadata } from '../../api/ada/lib/storage/database/primitives/tables';
import { isHexadecimal } from 'validator';
import AssetFingerprint from '@emurgo/cip14-js';
import { AssetNameUtils } from '@emurgo/yoroi-lib/dist/internals/utils/assets';
import type { RemoteTokenInfo } from '../../api/ada/lib/state-fetch/types';
import { isHex } from '@emurgo/yoroi-lib/dist/internals/utils/index';

export function getTokenName(
tokenRow: $ReadOnly<{
Expand All @@ -27,7 +27,7 @@ export function getTokenName(
}

function resolveNameProperties(name: ?string): {| name: string, cip67Tag: ?string |} {
if (name == null || name.length === 0 || !isHexadecimal(name)) {
if (name == null || name.length === 0 || !isHex(name)) {
return { name: '', cip67Tag: null };
}
const { asciiName, hexName, cip67Tag } =
Expand Down
11 changes: 4 additions & 7 deletions packages/yoroi-extension/app/utils/validations.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// @flow
import BigNumber from 'bignumber.js';
import isInt from 'validator/lib/isInt';
import { MAX_MEMO_SIZE } from '../config/externalStorageConfig';
import type { $npm$ReactIntl$IntlFormat, } from 'react-intl';
import { defineMessages, } from 'react-intl';
import type { NetworkRow, TokenRow } from '../api/ada/lib/storage/database/primitives/tables';
import { isCardanoHaskell, getCardanoHaskellBaseConfig } from '../api/ada/lib/storage/database/prepackaged/networks';
import { getCardanoHaskellBaseConfig, isCardanoHaskell } from '../api/ada/lib/storage/database/prepackaged/networks';
import { getTokenName } from '../stores/stateless/tokenHelpers';
import { truncateToken } from './formatters';

Expand Down Expand Up @@ -50,12 +49,10 @@ export const isValidMemoOptional: string => boolean = (memo) => (
);

export const isWithinSupply: (string, BigNumber) => boolean = (value, totalSupply) => {
const isNumeric = isInt(value, { allow_leading_zeroes: false });
if (!isNumeric) return false;
const numericValue = new BigNumber(value);
const minValue = new BigNumber(1);
const isValid = numericValue.gte(minValue) && numericValue.lte(totalSupply);
return isValid;
return numericValue.isFinite()
&& numericValue.gte(1)
&& numericValue.lte(totalSupply);
};

export async function validateAmount(
Expand Down
11 changes: 1 addition & 10 deletions packages/yoroi-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/yoroi-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@
"trezor-connect-flow": "Emurgo/trezor-connect-flow#92d6d8c8faef25c0ea1d481aa1ecb4ba77ce539c",
"ua-parser-js": "0.7.24",
"unorm": "1.6.0",
"util": "0.12.5",
"validator": "13.5.2"
"util": "0.12.5"
},
"engineStrict": true,
"engine": {
Expand Down

0 comments on commit fc27d20

Please sign in to comment.