Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
noisekit committed Sep 10, 2024
1 parent db76d00 commit 419aaab
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 45 deletions.
43 changes: 12 additions & 31 deletions liquidity/lib/formatters/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,27 @@ export function numberWithCommas(value: string, decimals?: number) {
return decimals ? joinedParts.substring(0, joinedParts.indexOf('.') + decimals + 1) : joinedParts;
}

interface Options extends Intl.NumberFormatOptions {
locales?: string | string[];
}
export const formatNumberToUsd = (val: number | string, options?: Options) => {
const optionsWithDefault = { style: 'currency', currency: 'USD', locales: 'en-EN', ...options };
return new Intl.NumberFormat(optionsWithDefault.locales, optionsWithDefault).format(Number(val));
};

export const formatNumberToCurrencyBasedOnSize = (val: number | string) => {
const num = Number(val);
if (num < 0.0001) {
return formatNumberToUsd(num, { maximumFractionDigits: 8 });
}
if (num < 1) {
return formatNumberToUsd(num, { maximumFractionDigits: 4 });
}
return formatNumberToUsd(num, { maximumFractionDigits: 2 });
export const formatNumberToUsd = (value: number, options?: Intl.NumberFormatOptions) => {
return new Intl.NumberFormat('en-EN', {
style: 'currency',
currency: 'USD',
...options,
}).format(Number(value));
};

export const formatNumber = (value: number | string, options?: Options) => {
const optionsWithDefault = {
export const formatNumber = (value: number, options?: Intl.NumberFormatOptions) => {
return new Intl.NumberFormat('en-EN', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
locales: 'en-EN',
...options,
};
return new Intl.NumberFormat(optionsWithDefault.locales, optionsWithDefault).format(
Number(value)
);
}).format(Number(value));
};

export const formatPercent = (value: number | string, options?: Options) => {
const optionsWithDefault = {
export const formatPercent = (value: number, options?: Intl.NumberFormatOptions) => {
return new Intl.NumberFormat('en-EN', {
minimumFractionDigits: 0,
maximumFractionDigits: 2,
locales: 'en-EN',
style: 'percent',
...options,
};
return new Intl.NumberFormat(optionsWithDefault.locales, optionsWithDefault).format(
Number(value)
);
}).format(Number(value));
};
1 change: 1 addition & 0 deletions liquidity/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"@tanstack/react-query": "^5.8.3",
"@types/humanize-plus": "^1",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.37",
"@types/react-helmet": "^6.1.9",
"babel-loader": "^9.1.3",
"babel-plugin-istanbul": "^6.1.1",
Expand Down
3 changes: 2 additions & 1 deletion liquidity/ui/src/components/Deposit/Deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ export const DepositUi: FC<{
<Alert mb={6} status="error" borderRadius="6px">
<AlertIcon />
<AlertDescription>
Your deposit must be {formatNumber(minDelegation.toString())} {symbol} or higher
Your deposit must be {formatNumber(parseFloat(minDelegation.toString()))} {symbol} or
higher
</AlertDescription>
</Alert>
</Collapse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ export const InitialDepositUi: FC<{
<Alert mb={6} status="error" borderRadius="6px">
<AlertIcon />
<AlertDescription>
Your deposit must be {formatNumber(minDelegation.toString())} {symbol} or higher
Your deposit must be {formatNumber(parseFloat(minDelegation.toString()))} {symbol}{' '}
or higher
</AlertDescription>
</Alert>
</Collapse>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"nyc": "^15.1.0",
"prettier": "^3.1.0",
"svgo": "^3.2.0",
"typescript": "^5.4.5"
"typescript": "^5.6.2"
},
"browserslist": [
"last 1 Chrome version",
Expand Down
2 changes: 1 addition & 1 deletion tools/deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"devDependencies": {
"depcheck": "^1.4.7",
"prettier": "^3.1.0",
"typescript": "^5.4.5"
"typescript": "^5.6.2"
},
"depcheck": {
"ignorePatterns": [],
Expand Down
30 changes: 20 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5205,6 +5205,7 @@ __metadata:
"@tanstack/react-query-devtools": "npm:^5.8.3"
"@types/humanize-plus": "npm:^1"
"@types/react": "npm:^18.2.37"
"@types/react-dom": "npm:^18.2.37"
"@types/react-helmet": "npm:^6.1.9"
"@web3-onboard/coinbase": "npm:^2.4.1"
"@web3-onboard/common": "npm:^2.4.2"
Expand Down Expand Up @@ -6563,7 +6564,7 @@ __metadata:
dependencies:
depcheck: "npm:^1.4.7"
prettier: "npm:^3.1.0"
typescript: "npm:^5.4.5"
typescript: "npm:^5.6.2"
bin:
deps: ./deps.js
deps-circular: ./circular.js
Expand Down Expand Up @@ -7248,6 +7249,15 @@ __metadata:
languageName: node
linkType: hard

"@types/react-dom@npm:^18.2.37":
version: 18.3.0
resolution: "@types/react-dom@npm:18.3.0"
dependencies:
"@types/react": "npm:*"
checksum: 10/6ff53f5a7b7fba952a68e114d3b542ebdc1e87a794234785ebab0bcd9bde7fb4885f21ebaf93d26dc0a1b5b93287f42cad68b78ae04dddf6b20da7aceff0beaf
languageName: node
linkType: hard

"@types/react-helmet@npm:^6.1.9":
version: 6.1.9
resolution: "@types/react-helmet@npm:6.1.9"
Expand Down Expand Up @@ -18198,7 +18208,7 @@ __metadata:
nyc: "npm:^15.1.0"
prettier: "npm:^3.1.0"
svgo: "npm:^3.2.0"
typescript: "npm:^5.4.5"
typescript: "npm:^5.6.2"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -19700,23 +19710,23 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:^5.4.5":
version: 5.4.5
resolution: "typescript@npm:5.4.5"
"typescript@npm:^5.6.2":
version: 5.6.2
resolution: "typescript@npm:5.6.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10/d04a9e27e6d83861f2126665aa8d84847e8ebabcea9125b9ebc30370b98cb38b5dff2508d74e2326a744938191a83a69aa9fddab41f193ffa43eabfdf3f190a5
checksum: 10/f95365d4898f357823e93d334ecda9fcade54f009b397c7d05b7621cd9e865981033cf89ccde0f3e3a7b73b1fdbae18e92bc77db237b43e912f053fef0f9a53b
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A^5.4.5#optional!builtin<compat/typescript>":
version: 5.4.5
resolution: "typescript@patch:typescript@npm%3A5.4.5#optional!builtin<compat/typescript>::version=5.4.5&hash=5adc0c"
"typescript@patch:typescript@npm%3A^5.6.2#optional!builtin<compat/typescript>":
version: 5.6.2
resolution: "typescript@patch:typescript@npm%3A5.6.2#optional!builtin<compat/typescript>::version=5.6.2&hash=8c6c40"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10/760f7d92fb383dbf7dee2443bf902f4365db2117f96f875cf809167f6103d55064de973db9f78fe8f31ec08fff52b2c969aee0d310939c0a3798ec75d0bca2e1
checksum: 10/8bfc7ca0d9feca4c3fcbd6c70741abfcd714197d6448e68225ae71e462447d904d3bfba49759a8fbe4956d87f054e2d346833c8349c222daa594a2626d4e1be8
languageName: node
linkType: hard

Expand Down

0 comments on commit 419aaab

Please sign in to comment.