@leather.io/utils
Advanced tools
| // A minus sign is a wider character than a hyphen, and should be used in | ||
| // numerical contexts | ||
| export const minusSign = '−'; |
| import { describe, expect, test } from 'vitest'; | ||
| import { minusSign } from './special-char'; | ||
| describe('minusSign', () => { | ||
| test('should be the Unicode minus sign character (U+2212)', () => { | ||
| expect(minusSign).toBe('−'); | ||
| expect(minusSign.charCodeAt(0)).toBe(0x2212); | ||
| expect(minusSign).not.toBe('-'); | ||
| }); | ||
| }); |
+14
| import BigNumber from 'bignumber.js'; | ||
| import type { Money } from '@leather.io/models'; | ||
| import { createMoney } from './money'; | ||
| export function calculateMinToReceiveAmount(quoteAmount: Money, slippage: number): Money { | ||
| const minReceiveAmount = quoteAmount.amount.times(BigNumber(1).minus(slippage)); | ||
| return createMoney( | ||
| minReceiveAmount.integerValue(BigNumber.ROUND_DOWN), | ||
| quoteAmount.symbol, | ||
| quoteAmount.decimals | ||
| ); | ||
| } |
| > @leather.io/utils@0.48.3 build /home/runner/work/mono/mono/packages/utils | ||
| > @leather.io/utils@0.49.0 build /home/runner/work/mono/mono/packages/utils | ||
| > tsup | ||
@@ -11,7 +11,7 @@ | ||
| [34mESM[39m Build start | ||
| [32mESM[39m [1mdist/index.js [22m[32m73.59 KB[39m | ||
| [32mESM[39m [1mdist/index.js.map [22m[32m139.33 KB[39m | ||
| [32mESM[39m ⚡️ Build success in 41ms | ||
| [32mESM[39m [1mdist/index.js [22m[32m73.66 KB[39m | ||
| [32mESM[39m [1mdist/index.js.map [22m[32m139.51 KB[39m | ||
| [32mESM[39m ⚡️ Build success in 86ms | ||
| [34mDTS[39m Build start | ||
| [32mDTS[39m ⚡️ Build success in 2258ms | ||
| [32mDTS[39m [1mdist/index.d.ts [22m[32m14.78 KB[39m | ||
| [32mDTS[39m ⚡️ Build success in 3207ms | ||
| [32mDTS[39m [1mdist/index.d.ts [22m[32m15.02 KB[39m |
+48
-0
@@ -371,2 +371,50 @@ # Changelog | ||
| ## [0.49.0](https://github.com/leather-io/mono/compare/@leather.io/utils-v0.48.3...@leather.io/utils-v0.49.0) (2025-11-19) | ||
| ### Features | ||
| * add alex swap provider ([152fd3a](https://github.com/leather-io/mono/commit/152fd3a6d015aace7bd682819a7d3d6112a64730)) | ||
| * add descriptors to get addresses rpc ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * add portfolio table ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * portfolio activity ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * portfolio ui hover, borders, token count ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** add empty state ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** add hover events ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** add portfolio modal ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** add stacked bar chart ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** add stacks to portfolio list ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** add tooltip ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** adjust hover events ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** bitcoin balance for portfolio ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** breakdown by allocation ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** scaffold portfolio page ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** sip10 avatar icons web ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** sip10 balances and assets ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** stacks portfolio balance ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| ### Bug Fixes | ||
| * **mobile:** ensure translations updated ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **mobile:** name is now defined for all models used ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * responsive portfolio ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** a few style fixes ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** add loading spinner to asset list ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** add loading state to bar ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** ensure stacks renders in list ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** improve hover events and styles ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** invisible hover overlay ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** layout as per designs ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** remove unused ui ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| * **web:** remove unused var ([0e664a7](https://github.com/leather-io/mono/commit/0e664a7066a31776ac7e5ec60fa5a0ad893b96ff)) | ||
| ### Dependencies | ||
| * The following workspace dependencies were updated | ||
| * dependencies | ||
| * @leather.io/constants bumped to 0.28.0 | ||
| * @leather.io/models bumped to 0.49.0 | ||
| ## [0.48.3](https://github.com/leather-io/mono/compare/@leather.io/utils-v0.48.2...@leather.io/utils-v0.48.3) (2025-11-17) | ||
@@ -373,0 +421,0 @@ |
+8
-1
@@ -105,2 +105,7 @@ import BigNumber, { BigNumber as BigNumber$1 } from 'bignumber.js'; | ||
| declare function createSip9AssetId(asset: Sip9Asset): CryptoAssetId; | ||
| declare function formatSip9IdField(asset: Sip9Asset): string; | ||
| declare function parseSip9IdField(id: string): { | ||
| assetId: string; | ||
| tokenId: number; | ||
| }; | ||
| type SerializedCryptoAssetId = `${string}|${string}`; | ||
@@ -210,2 +215,4 @@ declare function serializeAssetId(assetId: CryptoAssetId): SerializedCryptoAssetId; | ||
| declare const minusSign = "\u2212"; | ||
| interface SpamFilterArgs { | ||
@@ -289,2 +296,2 @@ input: string; | ||
| export { type CreateInscriptionData, type FormatAmountOptions, type SerializedCryptoAssetId, aggregateBaseCryptoAssetBalances, aggregateBtcBalances, aggregateStxBalances, assertExistence, assertIsTruthy, assertUnreachable, baseCurrencyAmountInQuote, baseCurrencyAmountInQuoteWithFallback, btcToSat, calculateMeanAverage, capitalize, convertAmountToBaseUnit, convertAmountToFractionalUnit, convertToMoneyTypeWithDefaultOfZero, countDecimals, createAccountAddresses, createBaseCryptoAssetBalance, createBtcBalance, createCounter, createCurrencyFormatter, createInscriptionAsset, createMoney, createMoneyFromDecimal, createNullArrayOfLength, createNumArrayOfRange, createSip9AssetId, createStxBalance, dateToUnixTimestamp, daysInMs, daysInSec, defaultWalletKeyId, delay, deserializeAssetId, ensureArray, extractPhraseFromString, fibonacciGenerator, fiveMinInMs, flattenObject, getAssetDisplayName, getAssetId, getTicker, hasBitcoinAddress, hasStacksAddress, hexToNumber, hoursInMs, hoursInSec, increaseValueByOneMicroStx, initBigNumber, invertExchangeRate, isBigInt, isBoolean, isDefined, isEmpty, isEmptyArray, isEmptyString, isError, isEven, isFiatCurrencyCode, isFulfilled, isFunction, isHexString, isMoney, isMoneyGreaterThanZero, isNumber, isNumberOrNumberList, isObject, isRejected, isSameAsset, isSameAssetId, isString, isTypedArray, isUndefined, makeNumberRange, makeStacksTxExplorerLink, mapObject, matchesAssetId, maxMoney, microStxToStx, migratePositiveAssetBalancesToTop, minMoney, minutesInMs, minutesInSec, moneyToBaseUnit, noop, oneDayInMs, oneMinInMs, oneWeekInMs, propIfDefined, pxStringToNumber, quoteCurrencyAmountToBase, rebaseMarketData, removeTrailingNullCharacters, reverseBytes, safelyFormatHexTxid, sanitizeContent, satToBtc, scaleValue, secondsInMs, serializeAssetId, sortAssetsByName, spamFilter, stxToMicroStx, subtractMoney, sumMoney, sumNumbers, toHexString, truncateMiddle, undefinedIfLengthZero, uniqueArray, unitToFractionalUnit, weeksInMs, weeksInSec, whenInscriptionMimeType, whenNetwork }; | ||
| export { type CreateInscriptionData, type FormatAmountOptions, type SerializedCryptoAssetId, aggregateBaseCryptoAssetBalances, aggregateBtcBalances, aggregateStxBalances, assertExistence, assertIsTruthy, assertUnreachable, baseCurrencyAmountInQuote, baseCurrencyAmountInQuoteWithFallback, btcToSat, calculateMeanAverage, capitalize, convertAmountToBaseUnit, convertAmountToFractionalUnit, convertToMoneyTypeWithDefaultOfZero, countDecimals, createAccountAddresses, createBaseCryptoAssetBalance, createBtcBalance, createCounter, createCurrencyFormatter, createInscriptionAsset, createMoney, createMoneyFromDecimal, createNullArrayOfLength, createNumArrayOfRange, createSip9AssetId, createStxBalance, dateToUnixTimestamp, daysInMs, daysInSec, defaultWalletKeyId, delay, deserializeAssetId, ensureArray, extractPhraseFromString, fibonacciGenerator, fiveMinInMs, flattenObject, formatSip9IdField, getAssetDisplayName, getAssetId, getTicker, hasBitcoinAddress, hasStacksAddress, hexToNumber, hoursInMs, hoursInSec, increaseValueByOneMicroStx, initBigNumber, invertExchangeRate, isBigInt, isBoolean, isDefined, isEmpty, isEmptyArray, isEmptyString, isError, isEven, isFiatCurrencyCode, isFulfilled, isFunction, isHexString, isMoney, isMoneyGreaterThanZero, isNumber, isNumberOrNumberList, isObject, isRejected, isSameAsset, isSameAssetId, isString, isTypedArray, isUndefined, makeNumberRange, makeStacksTxExplorerLink, mapObject, matchesAssetId, maxMoney, microStxToStx, migratePositiveAssetBalancesToTop, minMoney, minusSign, minutesInMs, minutesInSec, moneyToBaseUnit, noop, oneDayInMs, oneMinInMs, oneWeekInMs, parseSip9IdField, propIfDefined, pxStringToNumber, quoteCurrencyAmountToBase, rebaseMarketData, removeTrailingNullCharacters, reverseBytes, safelyFormatHexTxid, sanitizeContent, satToBtc, scaleValue, secondsInMs, serializeAssetId, sortAssetsByName, spamFilter, stxToMicroStx, subtractMoney, sumMoney, sumNumbers, toHexString, truncateMiddle, undefinedIfLengthZero, uniqueArray, unitToFractionalUnit, weeksInMs, weeksInSec, whenInscriptionMimeType, whenNetwork }; |
+3
-3
@@ -5,3 +5,3 @@ { | ||
| "description": "Shared bitcoin utilities", | ||
| "version": "0.48.3", | ||
| "version": "0.49.0", | ||
| "license": "MIT", | ||
@@ -23,4 +23,4 @@ "homepage": "https://github.com/leather-io/mono/tree/dev/packages/utils", | ||
| "dompurify": "3.2.4", | ||
| "@leather.io/constants": "0.27.5", | ||
| "@leather.io/models": "0.48.0" | ||
| "@leather.io/constants": "0.28.0", | ||
| "@leather.io/models": "0.49.0" | ||
| }, | ||
@@ -27,0 +27,0 @@ "devDependencies": { |
+14
-14
@@ -7,3 +7,2 @@ import { | ||
| Sip9Asset, | ||
| isSip9Asset, | ||
| } from '@leather.io/models'; | ||
@@ -14,12 +13,4 @@ | ||
| export function matchesAssetId(asset: CryptoAsset, assetId: CryptoAssetId) { | ||
| const protocol = getAssetId(asset).protocol; | ||
| const id = getAssetId(asset).id; | ||
| if (isSip9Asset(asset)) { | ||
| return ( | ||
| protocol === assetId.protocol && | ||
| assetId.id === asset.assetId && | ||
| assetId.tokenId === asset.tokenId | ||
| ); | ||
| } | ||
| return protocol === assetId.protocol && id === assetId.id; | ||
| const assetIdentifier = getAssetId(asset); | ||
| return isSameAssetId(assetIdentifier, assetId); | ||
| } | ||
@@ -92,6 +83,15 @@ | ||
| protocol: asset.protocol, | ||
| id: `${asset.assetId}|${asset.tokenId}`, | ||
| id: formatSip9IdField(asset), | ||
| }; | ||
| } | ||
| export function formatSip9IdField(asset: Sip9Asset) { | ||
| return `${asset.assetId}|${asset.tokenId}`; | ||
| } | ||
| export function parseSip9IdField(id: string) { | ||
| const [assetId, tokenId] = id.split('|'); | ||
| return { assetId, tokenId: Number(tokenId) }; | ||
| } | ||
| export type SerializedCryptoAssetId = `${string}|${string}`; | ||
@@ -104,3 +104,4 @@ | ||
| export function deserializeAssetId(serializedAssetId: SerializedCryptoAssetId): CryptoAssetId { | ||
| const [protocol, id, tokenId] = serializedAssetId.split('|'); | ||
| const [protocol, ...idParts] = serializedAssetId.split('|'); | ||
| const id = idParts.join('|'); | ||
| if (!Object.keys(CryptoAssetProtocols).includes(protocol)) { | ||
@@ -113,4 +114,3 @@ throw new Error(`Unrecognized Asset Protocol: ${protocol}`); | ||
| id, | ||
| tokenId: tokenId ? parseInt(tokenId, 10) : undefined, | ||
| }; | ||
| } |
+1
-0
@@ -20,2 +20,3 @@ import { BigNumber } from 'bignumber.js'; | ||
| export * from './flatten-object'; | ||
| export * from './special-char'; | ||
@@ -22,0 +23,0 @@ export { spamFilter } from './spam-filter/spam-filter'; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
427783
1.34%62
5.08%9256
0.38%+ Added
+ Added
- Removed
- Removed
Updated
Updated