diff --git a/package.json b/package.json index 7857dbbb1cf..3c0c03f2276 100644 --- a/package.json +++ b/package.json @@ -135,10 +135,10 @@ "@dlc-link/dlc-tools": "1.1.1", "@fungible-systems/zone-file": "2.0.0", "@hirosystems/token-metadata-api-client": "1.2.0", - "@leather-wallet/models": "0.6.5", - "@leather-wallet/query": "0.6.7", - "@leather-wallet/tokens": "0.4.0", - "@leather-wallet/utils": "0.6.5", + "@leather-wallet/models": "0.6.6", + "@leather-wallet/query": "0.6.8", + "@leather-wallet/tokens": "0.5.0", + "@leather-wallet/utils": "0.6.6", "@ledgerhq/hw-transport-webusb": "6.27.19", "@noble/hashes": "1.3.2", "@noble/secp256k1": "2.0.0", @@ -254,7 +254,7 @@ "@btckit/types": "0.0.19", "@chromatic-com/storybook": "1.2.23", "@leather-wallet/prettier-config": "0.4.0", - "@leather-wallet/rpc": "0.3.9", + "@leather-wallet/rpc": "0.3.10", "@leather-wallet/panda-preset": "0.0.5", "@ls-lint/ls-lint": "2.2.3", "@mdx-js/loader": "3.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6a9e0abd0e3..f689003082c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,17 +31,17 @@ dependencies: specifier: 1.2.0 version: 1.2.0 '@leather-wallet/models': - specifier: 0.6.5 - version: 0.6.5 + specifier: 0.6.6 + version: 0.6.6 '@leather-wallet/query': - specifier: 0.6.7 - version: 0.6.7(react-dom@18.3.1)(react@18.3.1) + specifier: 0.6.8 + version: 0.6.8(react-dom@18.3.1)(react@18.3.1) '@leather-wallet/tokens': - specifier: 0.4.0 - version: 0.4.0 + specifier: 0.5.0 + version: 0.5.0 '@leather-wallet/utils': - specifier: 0.6.5 - version: 0.6.5 + specifier: 0.6.6 + version: 0.6.6 '@ledgerhq/hw-transport-webusb': specifier: 6.27.19 version: 6.27.19 @@ -387,8 +387,8 @@ devDependencies: specifier: 0.4.0 version: 0.4.0 '@leather-wallet/rpc': - specifier: 0.3.9 - version: 0.3.9 + specifier: 0.3.10 + version: 0.3.10 '@ls-lint/ls-lint': specifier: 2.2.3 version: 2.2.3 @@ -4027,13 +4027,13 @@ packages: '@jridgewell/sourcemap-codec': 1.4.15 dev: true - /@leather-wallet/bitcoin@0.6.5: - resolution: {integrity: sha512-zJPLe4qCjex/qnyyi1mR1D3Dza3eec6p+VRQ5l/CJq6vwVmpQ86ISYZ6EKQW9BSoXy5l7RWsXXOx4LPZr1OGwA==} + /@leather-wallet/bitcoin@0.6.6: + resolution: {integrity: sha512-YH3Vt5VXuzmj3vK85G6VIxTjx7FYwmBZDFeuLuPexvYTMfU7JVPXsb4BMO6C4AFXTC0TpFQa6qSTGrEAJfxCqQ==} dependencies: '@bitcoinerlab/secp256k1': 1.0.2 '@leather-wallet/constants': 0.6.1 - '@leather-wallet/models': 0.6.5 - '@leather-wallet/utils': 0.6.5 + '@leather-wallet/models': 0.6.6 + '@leather-wallet/utils': 0.6.6 '@noble/hashes': 1.3.3 '@noble/secp256k1': 2.0.0 '@scure/base': 1.1.3 @@ -4054,8 +4054,8 @@ packages: resolution: {integrity: sha512-hchHbLTEDueM1vFe1xmYeJLx2hj4cQaDQX5DmgDZ/W1haBqfQ1meWxkX1FPXk8af9Dtm0ZfF957LkUWbkXnSTg==} dev: false - /@leather-wallet/models@0.6.5: - resolution: {integrity: sha512-9ULJLp9PgxEF13/V9avNyibIEqlAXlnPOXSmdhoJ0Tupa7zwEkG8RZhtuhdxV1dHm3HELPJYfJo8z2DqM+YjHQ==} + /@leather-wallet/models@0.6.6: + resolution: {integrity: sha512-RRQ2rk7zB8bTIDCO4nTwBowJ/rcBRYn/5MfDEKDPOEYW7BsmgKZH5PHxhAYrutW0WW8XqOUTOSXvwvoGKu1oXw==} dependencies: bignumber.js: 9.1.2 @@ -4078,16 +4078,16 @@ packages: - supports-color dev: true - /@leather-wallet/query@0.6.7(react-dom@18.3.1)(react@18.3.1): - resolution: {integrity: sha512-f/5xH3kqeAmzl+3UB0T/n6u4xKCsU5p4qWhUz/+CqVLpsFnN5ecuZeR//DJ6QSt0c7+jNL725CcB3tsa8wy2aQ==} + /@leather-wallet/query@0.6.8(react-dom@18.3.1)(react@18.3.1): + resolution: {integrity: sha512-uqQztPXC17kfSjgzTVsWF5wNOO3tQhy2/LEQGIo+i37HbUf3RE01I2l/V/KjwmuVR6Cu9YjpJcNQ2L4v0eYT7A==} peerDependencies: react: '*' dependencies: - '@leather-wallet/bitcoin': 0.6.5 + '@leather-wallet/bitcoin': 0.6.6 '@leather-wallet/constants': 0.6.1 - '@leather-wallet/models': 0.6.5 - '@leather-wallet/rpc': 0.3.9 - '@leather-wallet/utils': 0.6.5 + '@leather-wallet/models': 0.6.6 + '@leather-wallet/rpc': 0.3.10 + '@leather-wallet/utils': 0.6.6 '@noble/hashes': 1.3.3 '@scure/base': 1.1.3 '@scure/bip32': 1.3.3 @@ -4114,21 +4114,21 @@ packages: - react-native dev: false - /@leather-wallet/rpc@0.3.9: - resolution: {integrity: sha512-q0uKPqrSLv9/hj5gairpEm5hG1JdJ9sFOa6fapL9a4EsQzGbbNS6bOF7pNknMo/7cRGzTfDJmFlxLreLsGB1Gg==} + /@leather-wallet/rpc@0.3.10: + resolution: {integrity: sha512-H0Iz8fjGeYDJcBlzUEkthmLcLaXQvX4m3kp8tA4Tyx6ntdji3PA49cFEwUDUEGIHmOFYy0IEvO34cAmKufs5xw==} dependencies: - '@leather-wallet/models': 0.6.5 + '@leather-wallet/models': 0.6.6 - /@leather-wallet/tokens@0.4.0: - resolution: {integrity: sha512-3b2EjGGYVsJYsYN3OlZB6t5RNMN1VFrza5KDrs1RxFfuVNXcOhiTnXbnStJeNCwremV5S77vUnKZVW6bb/wIUQ==} + /@leather-wallet/tokens@0.5.0: + resolution: {integrity: sha512-i7eXEZpZUKHKchhwxlzewbeLPh8zBuxTcg+FInl89kT+zZRL/vt9pOHBeS2SL5i7TTyBjlnkFBIhCXqQjFacQQ==} dev: false - /@leather-wallet/utils@0.6.5: - resolution: {integrity: sha512-fVVpuqcfW8k5kvp7pQZiYC3HQ6GSmjk+M3PB/FGYVRBUrzHYDaSxiQi/L1d7g/dGGuspz0nD7kG3fMhli6iNyA==} + /@leather-wallet/utils@0.6.6: + resolution: {integrity: sha512-X1fS08b0znP6DkMWff2EaMtR2tdU/szQrNq4p16M7tw0BR8IRWcGtGtsqLl71zo28/qKrEe8PqZxv02hzvd2gA==} dependencies: '@leather-wallet/constants': 0.6.1 - '@leather-wallet/models': 0.6.5 - '@leather-wallet/rpc': 0.3.9 + '@leather-wallet/models': 0.6.6 + '@leather-wallet/rpc': 0.3.10 bignumber.js: 9.1.2 dev: false diff --git a/src/app/common/asset-utils.ts b/src/app/common/asset-utils.ts index b8a857c668e..13b3ba2be65 100644 --- a/src/app/common/asset-utils.ts +++ b/src/app/common/asset-utils.ts @@ -1,10 +1,9 @@ -import type { Money } from '@leather-wallet/models'; - -import type { MarketData } from '@shared/models/market.model'; - -import { baseCurrencyAmountInQuote } from './money/calculate-money'; -import { i18nFormatCurrency } from './money/format-money'; -import { isMoneyGreaterThanZero } from './money/money.utils'; +import type { MarketData, Money } from '@leather-wallet/models'; +import { + baseCurrencyAmountInQuote, + i18nFormatCurrency, + isMoneyGreaterThanZero, +} from '@leather-wallet/utils'; export function sortAssetsByName(assets: T) { return assets diff --git a/src/app/common/hooks/balance/use-total-balance.tsx b/src/app/common/hooks/balance/use-total-balance.tsx index a02bdcf01d3..9b490830990 100644 --- a/src/app/common/hooks/balance/use-total-balance.tsx +++ b/src/app/common/hooks/balance/use-total-balance.tsx @@ -1,10 +1,8 @@ import { useMemo } from 'react'; import { useCryptoCurrencyMarketDataMeanAverage } from '@leather-wallet/query'; -import { createMoney } from '@leather-wallet/utils'; +import { baseCurrencyAmountInQuote, createMoney, i18nFormatCurrency } from '@leather-wallet/utils'; -import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; -import { i18nFormatCurrency } from '@app/common/money/format-money'; import { useBtcCryptoAssetBalanceNativeSegwit } from '@app/query/bitcoin/balance/btc-balance-native-segwit.hooks'; import { useStxCryptoAssetBalance } from '@app/query/stacks/balance/account-balance.hooks'; diff --git a/src/app/common/hooks/use-bitcoin-contracts.ts b/src/app/common/hooks/use-bitcoin-contracts.ts index 972892df648..d883428b9b2 100644 --- a/src/app/common/hooks/use-bitcoin-contracts.ts +++ b/src/app/common/hooks/use-bitcoin-contracts.ts @@ -8,7 +8,7 @@ import { useCalculateBitcoinFiatValue, useCryptoCurrencyMarketDataMeanAverage, } from '@leather-wallet/query'; -import { createMoneyFromDecimal, satToBtc } from '@leather-wallet/utils'; +import { createMoneyFromDecimal, i18nFormatCurrency, satToBtc } from '@leather-wallet/utils'; import { bytesToHex } from '@stacks/common'; import { @@ -27,7 +27,6 @@ import { import { useCurrentNetwork } from '@app/store/networks/networks.selectors'; import { initialSearchParams } from '../initial-search-params'; -import { i18nFormatCurrency } from '../money/format-money'; import { useDefaultRequestParams } from './use-default-request-search-params'; export interface SimplifiedBitcoinContract { diff --git a/src/app/common/hooks/use-convert-to-fiat-amount.ts b/src/app/common/hooks/use-convert-to-fiat-amount.ts index e15e9954f13..56eefe7098b 100644 --- a/src/app/common/hooks/use-convert-to-fiat-amount.ts +++ b/src/app/common/hooks/use-convert-to-fiat-amount.ts @@ -2,11 +2,10 @@ import { useCallback } from 'react'; import type { Money } from '@leather-wallet/models'; import { useCryptoCurrencyMarketDataMeanAverage } from '@leather-wallet/query'; +import { baseCurrencyAmountInQuote } from '@leather-wallet/utils'; import { CryptoCurrencies } from '@shared/models/currencies.model'; -import { baseCurrencyAmountInQuote } from '../money/calculate-money'; - export function useConvertCryptoCurrencyToFiatAmount(currency: CryptoCurrencies) { // TODO: unsafe type assumption const cryptoCurrencyMarketData = useCryptoCurrencyMarketDataMeanAverage( diff --git a/src/app/common/money/calculate-money.spec.ts b/src/app/common/money/calculate-money.spec.ts deleted file mode 100644 index 3b613c93e57..00000000000 --- a/src/app/common/money/calculate-money.spec.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { createMoney, createMoneyFromDecimal } from '@leather-wallet/utils'; -import BigNumber from 'bignumber.js'; - -import { MarketData, createMarketData, createMarketPair } from '@shared/models/market.model'; - -import { - baseCurrencyAmountInQuote, - convertAmountToFractionalUnit, - subtractMoney, - sumMoney, -} from './calculate-money'; - -const tenMicroStx = createMoney(10, 'STX'); -const tenStx = createMoneyFromDecimal(10, 'STX'); - -const tenBtc = createMoneyFromDecimal(10, 'BTC'); - -const mockWrongMarketData = { - pair: createMarketPair('BTC' as any, 'USD'), - price: createMoneyFromDecimal(1, 'EUR' as any, 2), -} as MarketData; - -const mockAccurateStxMarketData = createMarketData( - createMarketPair('STX', 'USD'), - createMoneyFromDecimal(0.3, 'USD') -); - -describe(baseCurrencyAmountInQuote.name, () => { - test('it throw when passed mismatching currencies', () => - expect(() => baseCurrencyAmountInQuote(tenMicroStx, mockWrongMarketData)).toThrowError()); - - test('it converts currency small amounts accurately', () => { - const result = baseCurrencyAmountInQuote(tenMicroStx, mockAccurateStxMarketData); - expect(result.amount.toString()).toEqual('0.0003'); - }); - - test('it converts currency amounts accurately', () => { - const result = baseCurrencyAmountInQuote(tenStx, mockAccurateStxMarketData); - expect(result.amount.toString()).toEqual('300'); - }); -}); - -describe(convertAmountToFractionalUnit.name, () => { - test('it converts a small decimal amount to a fractional unit', () => - expect(convertAmountToFractionalUnit(new BigNumber(1), 2).toNumber()).toEqual(100)); - - test('it converts 99 as decimal amount to a fractional unit', () => - expect(convertAmountToFractionalUnit(new BigNumber(99), 6).toNumber()).toEqual(99000000)); -}); - -describe(sumMoney.name, () => { - test('it sums two money objects', () => { - const result = sumMoney([tenMicroStx, tenMicroStx]); - expect(result.amount.toString()).toEqual('20'); - expect(result.symbol).toEqual(tenMicroStx.symbol); - }); - test('it throws error when summing different currencies', () => { - expect(() => sumMoney([tenMicroStx, tenBtc])).toThrowError(); - }); -}); - -describe(subtractMoney.name, () => { - test('it subtracts two money objects', () => { - const result = subtractMoney(tenMicroStx, tenMicroStx); - expect(result.amount.toString()).toEqual('0'); - expect(result.symbol).toEqual(tenMicroStx.symbol); - }); - test('it throws error when subtracting different currencies', () => { - expect(() => subtractMoney(tenMicroStx, tenBtc)).toThrowError(); - }); -}); diff --git a/src/app/common/money/calculate-money.ts b/src/app/common/money/calculate-money.ts deleted file mode 100644 index b8afc81bf08..00000000000 --- a/src/app/common/money/calculate-money.ts +++ /dev/null @@ -1,58 +0,0 @@ -import type { Money, NumType } from '@leather-wallet/models'; -import { createMoney, initBigNumber, isNumber, sumNumbers } from '@leather-wallet/utils'; -import { BigNumber } from 'bignumber.js'; - -import { MarketData, formatMarketPair } from '@shared/models/market.model'; - -import { formatMoney } from './format-money'; -import { isMoney } from './money.utils'; - -export function baseCurrencyAmountInQuote(quantity: Money, { pair, price }: MarketData) { - if (quantity.symbol.toLowerCase() !== pair.base.toLowerCase()) - throw new Error( - `Cannot calculate value of ${formatMoney(quantity)} with market pair of ${formatMarketPair( - pair - )}` - ); - - return createMoney( - convertAmountToFractionalUnit( - convertAmountToBaseUnit(quantity).times(convertAmountToBaseUnit(price)), - price.decimals - ), - pair.quote - ); -} - -export function convertAmountToFractionalUnit(num: Money | BigNumber, decimals?: number) { - if (isMoney(num)) return num.amount.shiftedBy(num.decimals); - if (!isNumber(decimals)) throw new Error('Must define decimal of given currency'); - return num.shiftedBy(decimals); -} - -export function convertToMoneyTypeWithDefaultOfZero( - symbol: string, - num?: NumType, - decimals?: number -) { - return createMoney(initBigNumber(num ?? 0), symbol.toUpperCase(), decimals); -} - -export function convertAmountToBaseUnit(num: Money | BigNumber, decimals?: number) { - if (isMoney(num)) return num.amount.shiftedBy(-num.decimals); - if (!isNumber(decimals)) throw new Error('Must define decimal of given currency'); - return num.shiftedBy(-decimals); -} - -export function subtractMoney(xAmount: Money, yAmount: Money) { - if (xAmount.symbol !== yAmount.symbol) throw new Error('Cannot subtract different currencies'); - return createMoney(xAmount.amount.minus(yAmount.amount), xAmount.symbol, xAmount.decimals); -} - -export function sumMoney(moneysArr: Money[]) { - if (moneysArr.some(item => item.symbol !== moneysArr[0].symbol)) - throw new Error('Cannot sum different currencies'); - - const sum = sumNumbers(moneysArr.map(item => item.amount.toNumber())); - return createMoney(sum, moneysArr[0].symbol, moneysArr[0].decimals); -} diff --git a/src/app/common/money/format-money.ts b/src/app/common/money/format-money.ts deleted file mode 100644 index 4f64fe565fa..00000000000 --- a/src/app/common/money/format-money.ts +++ /dev/null @@ -1,37 +0,0 @@ -import type { Money } from '@leather-wallet/models'; - -const thinSpace = ' '; - -export function formatMoney({ amount, symbol, decimals }: Money) { - return `${amount.shiftedBy(-decimals).toString()} ${symbol}`; -} - -export function formatMoneyWithoutSymbol({ amount, decimals }: Money) { - return `${amount.shiftedBy(-decimals).toString()}`; -} - -export function formatMoneyPadded({ amount, symbol, decimals }: Money) { - return `${amount.shiftedBy(-decimals).toFormat(decimals)} ${symbol}`; -} - -export function i18nFormatCurrency(quantity: Money, decimals: number = 2) { - if (quantity.symbol !== 'USD') throw new Error('Cannot format non-USD amounts'); - const currencyFormatter = new Intl.NumberFormat('en-US', { - style: 'currency', - currency: 'USD', - maximumFractionDigits: decimals, - }); - - const formatted = currencyFormatter.format( - quantity.amount.shiftedBy(-quantity.decimals).toNumber() - ); - - if (quantity.amount.isGreaterThan(0) && formatted === '$0.00') - return '<' + thinSpace + formatted.replace('0.00', '0.01'); - - return formatted; -} - -export function formatDustUsdAmounts(value: string) { - return value.endsWith('0.00') ? '<' + thinSpace + value.replace('0.00', '0.01') : value; -} diff --git a/src/app/common/money/money.utils.ts b/src/app/common/money/money.utils.ts deleted file mode 100644 index 9bdaf9d8f14..00000000000 --- a/src/app/common/money/money.utils.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { Money } from '@leather-wallet/models'; -import { isObject } from '@leather-wallet/utils'; -import BigNumber from 'bignumber.js'; - -export function isMoney(val: unknown): val is Money { - if (!isObject(val)) return false; - return 'amount' in val && 'symbol' in val && 'decimals' in val; -} - -export function isMoneyGreaterThanZero(money: Money) { - if (!BigNumber.isBigNumber(money.amount)) return; - return !(money.amount.isNaN() || money.amount.isZero()); -} diff --git a/src/app/common/transactions/bitcoin/coinselect/local-coin-selection.ts b/src/app/common/transactions/bitcoin/coinselect/local-coin-selection.ts index eb44eaa7e10..797f9b0114c 100644 --- a/src/app/common/transactions/bitcoin/coinselect/local-coin-selection.ts +++ b/src/app/common/transactions/bitcoin/coinselect/local-coin-selection.ts @@ -1,12 +1,10 @@ import type { UtxoResponseItem } from '@leather-wallet/query'; -import { sumNumbers } from '@leather-wallet/utils'; +import { sumMoney, sumNumbers } from '@leather-wallet/utils'; import BigNumber from 'bignumber.js'; import { validate } from 'bitcoin-address-validation'; import type { TransferRecipient } from '@shared/models/form.model'; -import { sumMoney } from '@app/common/money/calculate-money'; - import { filterUneconomicalUtxos, getSizeInfo } from '../utils'; export class InsufficientFundsError extends Error { diff --git a/src/app/common/validation/forms/amount-validators.ts b/src/app/common/validation/forms/amount-validators.ts index a5db5e7a0a8..ef0a5f46a98 100644 --- a/src/app/common/validation/forms/amount-validators.ts +++ b/src/app/common/validation/forms/amount-validators.ts @@ -2,6 +2,7 @@ import type { Money } from '@leather-wallet/models'; import type { UtxoResponseItem } from '@leather-wallet/query'; import { btcToSat, + convertAmountToBaseUnit, countDecimals, isNumber, microStxToStx, @@ -13,8 +14,6 @@ import * as yup from 'yup'; import { analytics } from '@shared/utils/analytics'; -import { convertAmountToBaseUnit } from '@app/common/money/calculate-money'; - import { FormErrorMessages } from '../../../../shared/error-messages'; import { formatInsufficientBalanceError, formatPrecisionError } from '../../error-formatters'; import { currencyAmountValidator, stxAmountPrecisionValidator } from './currency-validators'; diff --git a/src/app/components/balance/btc-balance.tsx b/src/app/components/balance/btc-balance.tsx index f6fad708482..61830a36f89 100644 --- a/src/app/components/balance/btc-balance.tsx +++ b/src/app/components/balance/btc-balance.tsx @@ -1,4 +1,5 @@ -import { formatMoney } from '@app/common/money/format-money'; +import { formatMoney } from '@leather-wallet/utils'; + import { Caption } from '@app/ui/components/typography/caption'; import { BitcoinNativeSegwitAccountLoader } from '../loaders/bitcoin-account-loader'; diff --git a/src/app/components/bitcoin-custom-fee/hooks/use-bitcoin-custom-fee.tsx b/src/app/components/bitcoin-custom-fee/hooks/use-bitcoin-custom-fee.tsx index 1eae4d741ca..daee80a640b 100644 --- a/src/app/components/bitcoin-custom-fee/hooks/use-bitcoin-custom-fee.tsx +++ b/src/app/components/bitcoin-custom-fee/hooks/use-bitcoin-custom-fee.tsx @@ -2,12 +2,10 @@ import { useCallback } from 'react'; import type { Money } from '@leather-wallet/models'; import { useCryptoCurrencyMarketDataMeanAverage } from '@leather-wallet/query'; -import { createMoney } from '@leather-wallet/utils'; +import { baseCurrencyAmountInQuote, createMoney, i18nFormatCurrency } from '@leather-wallet/utils'; import type { TransferRecipient } from '@shared/models/form.model'; -import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; -import { i18nFormatCurrency } from '@app/common/money/format-money'; import { determineUtxosForSpend, determineUtxosForSpendAll, diff --git a/src/app/components/bitcoin-fees-list/use-bitcoin-fees-list-multiple-recipients.ts b/src/app/components/bitcoin-fees-list/use-bitcoin-fees-list-multiple-recipients.ts index 6003e99adf0..b49c2f4be77 100644 --- a/src/app/components/bitcoin-fees-list/use-bitcoin-fees-list-multiple-recipients.ts +++ b/src/app/components/bitcoin-fees-list/use-bitcoin-fees-list-multiple-recipients.ts @@ -6,13 +6,16 @@ import { useAverageBitcoinFeeRates, useCryptoCurrencyMarketDataMeanAverage, } from '@leather-wallet/query'; -import { createMoney } from '@leather-wallet/utils'; +import { + baseCurrencyAmountInQuote, + createMoney, + formatMoneyPadded, + i18nFormatCurrency, +} from '@leather-wallet/utils'; import { BtcFeeType, btcTxTimeMap } from '@shared/models/fees/bitcoin-fees.model'; import type { TransferRecipient } from '@shared/models/form.model'; -import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; -import { formatMoneyPadded, i18nFormatCurrency } from '@app/common/money/format-money'; import { type DetermineUtxosForSpendArgs, determineUtxosForSpend, diff --git a/src/app/components/bitcoin-fees-list/use-bitcoin-fees-list.ts b/src/app/components/bitcoin-fees-list/use-bitcoin-fees-list.ts index eff79b6bb9b..03ca38468a0 100644 --- a/src/app/components/bitcoin-fees-list/use-bitcoin-fees-list.ts +++ b/src/app/components/bitcoin-fees-list/use-bitcoin-fees-list.ts @@ -6,12 +6,15 @@ import { useAverageBitcoinFeeRates, useCryptoCurrencyMarketDataMeanAverage, } from '@leather-wallet/query'; -import { createMoney } from '@leather-wallet/utils'; +import { + baseCurrencyAmountInQuote, + createMoney, + formatMoneyPadded, + i18nFormatCurrency, +} from '@leather-wallet/utils'; import { BtcFeeType, btcTxTimeMap } from '@shared/models/fees/bitcoin-fees.model'; -import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; -import { formatMoneyPadded, i18nFormatCurrency } from '@app/common/money/format-money'; import { DetermineUtxosForSpendArgs, determineUtxosForSpend, diff --git a/src/app/components/crypto-asset-item/crypto-asset-item.layout.utils.ts b/src/app/components/crypto-asset-item/crypto-asset-item.layout.utils.ts index db931eda58f..dddf73121b9 100644 --- a/src/app/components/crypto-asset-item/crypto-asset-item.layout.utils.ts +++ b/src/app/components/crypto-asset-item/crypto-asset-item.layout.utils.ts @@ -1,8 +1,8 @@ import type { Money } from '@leather-wallet/models'; +import { formatMoneyWithoutSymbol } from '@leather-wallet/utils'; import { CryptoAssetSelectors } from '@tests/selectors/crypto-asset.selectors'; import { formatBalance } from '@app/common/format-balance'; -import { formatMoneyWithoutSymbol } from '@app/common/money/format-money'; export function parseCryptoAssetBalance(availableBalance: Money) { const availableBalanceString = formatMoneyWithoutSymbol(availableBalance); diff --git a/src/app/components/fees-row/components/transaction-fee.tsx b/src/app/components/fees-row/components/transaction-fee.tsx index b91ac284a4e..8879adbb889 100644 --- a/src/app/components/fees-row/components/transaction-fee.tsx +++ b/src/app/components/fees-row/components/transaction-fee.tsx @@ -1,10 +1,10 @@ import type { Money } from '@leather-wallet/models'; +import { formatDustUsdAmounts, i18nFormatCurrency } from '@leather-wallet/utils'; import { SharedComponentsSelectors } from '@tests/selectors/shared-component.selectors'; import { styled } from 'leather-styles/jsx'; import { CryptoCurrencies } from '@shared/models/currencies.model'; -import { formatDustUsdAmounts, i18nFormatCurrency } from '@app/common/money/format-money'; import { BasicTooltip } from '@app/ui/components/tooltip/basic-tooltip'; interface TransactionFeeProps { diff --git a/src/app/components/fees-row/fees-row.tsx b/src/app/components/fees-row/fees-row.tsx index fb93b9849e2..6bd6bf47284 100644 --- a/src/app/components/fees-row/fees-row.tsx +++ b/src/app/components/fees-row/fees-row.tsx @@ -1,6 +1,6 @@ import { useCallback, useEffect, useMemo, useState } from 'react'; -import { createMoney, isNumber, isString } from '@leather-wallet/utils'; +import { convertAmountToBaseUnit, createMoney, isNumber, isString } from '@leather-wallet/utils'; import { SharedComponentsSelectors } from '@tests/selectors/shared-component.selectors'; import BigNumber from 'bignumber.js'; import { useField } from 'formik'; @@ -10,7 +10,6 @@ import { STX_DECIMALS } from '@shared/constants'; import { FeeTypes, Fees } from '@shared/models/fees/fees.model'; import { useConvertCryptoCurrencyToFiatAmount } from '@app/common/hooks/use-convert-to-fiat-amount'; -import { convertAmountToBaseUnit } from '@app/common/money/calculate-money'; import { LoadingRectangle } from '@app/components/loading-rectangle'; import { CustomFeeField } from './components/custom-fee-field'; diff --git a/src/app/features/asset-list/bitcoin/btc-crypto-asset-item/btc-crypto-asset-item.tsx b/src/app/features/asset-list/bitcoin/btc-crypto-asset-item/btc-crypto-asset-item.tsx index ce4f519ee47..e963d8b9069 100644 --- a/src/app/features/asset-list/bitcoin/btc-crypto-asset-item/btc-crypto-asset-item.tsx +++ b/src/app/features/asset-list/bitcoin/btc-crypto-asset-item/btc-crypto-asset-item.tsx @@ -1,8 +1,7 @@ import type { BtcCryptoAssetBalance } from '@leather-wallet/models'; import { useCryptoCurrencyMarketDataMeanAverage } from '@leather-wallet/query'; +import { baseCurrencyAmountInQuote, i18nFormatCurrency } from '@leather-wallet/utils'; -import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; -import { i18nFormatCurrency } from '@app/common/money/format-money'; import { CryptoAssetItemLayout } from '@app/components/crypto-asset-item/crypto-asset-item.layout'; import { BtcAvatarIcon } from '@app/ui/components/avatar/btc-avatar-icon'; diff --git a/src/app/features/asset-list/stacks/stx-crypo-asset-item/stx-crypto-asset-item.tsx b/src/app/features/asset-list/stacks/stx-crypo-asset-item/stx-crypto-asset-item.tsx index 51d42bd9e6c..e261cbe54fe 100644 --- a/src/app/features/asset-list/stacks/stx-crypo-asset-item/stx-crypto-asset-item.tsx +++ b/src/app/features/asset-list/stacks/stx-crypo-asset-item/stx-crypto-asset-item.tsx @@ -1,9 +1,12 @@ import type { StxCryptoAssetBalance } from '@leather-wallet/models'; import { useCryptoCurrencyMarketDataMeanAverage } from '@leather-wallet/query'; +import { + baseCurrencyAmountInQuote, + formatMoneyWithoutSymbol, + i18nFormatCurrency, +} from '@leather-wallet/utils'; import { styled } from 'leather-styles/jsx'; -import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; -import { formatMoneyWithoutSymbol, i18nFormatCurrency } from '@app/common/money/format-money'; import { CryptoAssetItemLayout } from '@app/components/crypto-asset-item/crypto-asset-item.layout'; import { StxAvatarIcon } from '@app/ui/components/avatar/stx-avatar-icon'; import { Caption } from '@app/ui/components/typography/caption'; diff --git a/src/app/features/bitcoin-choose-fee/bitcoin-choose-fee.tsx b/src/app/features/bitcoin-choose-fee/bitcoin-choose-fee.tsx index 5a2bc21c7b6..67ae4c29015 100644 --- a/src/app/features/bitcoin-choose-fee/bitcoin-choose-fee.tsx +++ b/src/app/features/bitcoin-choose-fee/bitcoin-choose-fee.tsx @@ -1,12 +1,12 @@ import { useState } from 'react'; import type { Money } from '@leather-wallet/models'; +import { formatMoney } from '@leather-wallet/utils'; import { Box, FlexProps, Stack, styled } from 'leather-styles/jsx'; import { BtcFeeType } from '@shared/models/fees/bitcoin-fees.model'; import type { TransferRecipient } from '@shared/models/form.model'; -import { formatMoney } from '@app/common/money/format-money'; import { BitcoinCustomFee } from '@app/components/bitcoin-custom-fee/bitcoin-custom-fee'; import { MAX_FEE_RATE_MULTIPLIER } from '@app/components/bitcoin-custom-fee/hooks/use-bitcoin-custom-fee'; import { OnChooseFeeArgs } from '@app/components/bitcoin-fees-list/bitcoin-fees-list'; diff --git a/src/app/features/bitcoin-choose-fee/hooks/use-validate-bitcoin-spend.ts b/src/app/features/bitcoin-choose-fee/hooks/use-validate-bitcoin-spend.ts index a069b3d902a..5055843e24f 100644 --- a/src/app/features/bitcoin-choose-fee/hooks/use-validate-bitcoin-spend.ts +++ b/src/app/features/bitcoin-choose-fee/hooks/use-validate-bitcoin-spend.ts @@ -1,9 +1,8 @@ import { useState } from 'react'; import type { Money } from '@leather-wallet/models'; -import { createMoney } from '@leather-wallet/utils'; +import { createMoney, subtractMoney, sumMoney } from '@leather-wallet/utils'; -import { subtractMoney, sumMoney } from '@app/common/money/calculate-money'; import { useCurrentBtcCryptoAssetBalanceNativeSegwit } from '@app/query/bitcoin/balance/btc-balance-native-segwit.hooks'; export function useValidateBitcoinSpend(amount?: Money, isSendingMax?: boolean) { diff --git a/src/app/features/collectibles/components/taproot-balance-displayer.tsx b/src/app/features/collectibles/components/taproot-balance-displayer.tsx index 941678f1af5..7ebf853c6bf 100644 --- a/src/app/features/collectibles/components/taproot-balance-displayer.tsx +++ b/src/app/features/collectibles/components/taproot-balance-displayer.tsx @@ -1,6 +1,6 @@ import { useCurrentTaprootAccountBalance } from '@leather-wallet/query'; +import { formatMoney } from '@leather-wallet/utils'; -import { formatMoney } from '@app/common/money/format-money'; import { useRecoverUninscribedTaprootUtxosFeatureEnabled } from '@app/query/common/remote-config/remote-config.query'; import { useCurrentAccountIndex } from '@app/store/accounts/account'; import { useCurrentAccountNativeSegwitIndexZeroSigner } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks'; diff --git a/src/app/features/dialogs/increase-fee-dialog/increase-btc-fee-dialog.tsx b/src/app/features/dialogs/increase-fee-dialog/increase-btc-fee-dialog.tsx index 22896787ecf..425087eac4c 100644 --- a/src/app/features/dialogs/increase-fee-dialog/increase-btc-fee-dialog.tsx +++ b/src/app/features/dialogs/increase-fee-dialog/increase-btc-fee-dialog.tsx @@ -1,7 +1,7 @@ import { Suspense } from 'react'; import { Outlet, useLocation, useNavigate } from 'react-router-dom'; -import { btcToSat, createMoney } from '@leather-wallet/utils'; +import { btcToSat, createMoney, formatMoney } from '@leather-wallet/utils'; import { Formik } from 'formik'; import { Flex, Stack } from 'leather-styles/jsx'; @@ -9,7 +9,6 @@ import { BitcoinTx } from '@shared/models/transactions/bitcoin-transaction.model import { RouteUrls } from '@shared/route-urls'; import { useLocationStateWithCache } from '@app/common/hooks/use-location-state'; -import { formatMoney } from '@app/common/money/format-money'; import { getBitcoinTxValue } from '@app/common/transactions/bitcoin/utils'; import { BitcoinCustomFeeInput } from '@app/components/bitcoin-custom-fee/bitcoin-custom-fee-input'; import { BitcoinTransactionItem } from '@app/components/bitcoin-transaction-item/bitcoin-transaction-item'; diff --git a/src/app/features/psbt-signer/components/psbt-inputs-and-outputs/components/psbt-input-list/components/psbt-input-item.tsx b/src/app/features/psbt-signer/components/psbt-inputs-and-outputs/components/psbt-input-list/components/psbt-input-item.tsx index e8e2efa73ce..cf91d01bb20 100644 --- a/src/app/features/psbt-signer/components/psbt-inputs-and-outputs/components/psbt-input-list/components/psbt-input-item.tsx +++ b/src/app/features/psbt-signer/components/psbt-inputs-and-outputs/components/psbt-input-list/components/psbt-input-item.tsx @@ -1,6 +1,5 @@ -import { createMoney, truncateMiddle } from '@leather-wallet/utils'; +import { createMoney, formatMoney, truncateMiddle } from '@leather-wallet/utils'; -import { formatMoney } from '@app/common/money/format-money'; import { PsbtInput } from '@app/features/psbt-signer/hooks/use-parsed-inputs'; import { TagWithTooltip } from '@app/ui/components/tag/tag-with-tooltip'; diff --git a/src/app/features/psbt-signer/components/psbt-inputs-and-outputs/components/psbt-output-list/components/psbt-output-item.tsx b/src/app/features/psbt-signer/components/psbt-inputs-and-outputs/components/psbt-output-list/components/psbt-output-item.tsx index 4f0ef140e74..243130b4624 100644 --- a/src/app/features/psbt-signer/components/psbt-inputs-and-outputs/components/psbt-output-list/components/psbt-output-item.tsx +++ b/src/app/features/psbt-signer/components/psbt-inputs-and-outputs/components/psbt-output-list/components/psbt-output-item.tsx @@ -1,6 +1,5 @@ -import { createMoney, truncateMiddle } from '@leather-wallet/utils'; +import { createMoney, formatMoney, truncateMiddle } from '@leather-wallet/utils'; -import { formatMoney } from '@app/common/money/format-money'; import { PsbtOutput } from '@app/features/psbt-signer/hooks/use-parsed-outputs'; import { TagWithTooltip } from '@app/ui/components/tag/tag-with-tooltip'; diff --git a/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-receive-totals.tsx b/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-receive-totals.tsx index fd4b3ca79d8..b17cbde1c60 100644 --- a/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-receive-totals.tsx +++ b/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-receive-totals.tsx @@ -1,7 +1,6 @@ import { useCalculateBitcoinFiatValue } from '@leather-wallet/query'; -import { truncateMiddle } from '@leather-wallet/utils'; +import { formatMoney, i18nFormatCurrency, truncateMiddle } from '@leather-wallet/utils'; -import { formatMoney, i18nFormatCurrency } from '@app/common/money/format-money'; import { removeMinusSign } from '@app/common/utils'; import { usePsbtSignerContext } from '@app/features/psbt-signer/psbt-signer.context'; diff --git a/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-transfer-totals.tsx b/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-transfer-totals.tsx index 0ac24344867..26ce4949bde 100644 --- a/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-transfer-totals.tsx +++ b/src/app/features/psbt-signer/components/psbt-inputs-outputs-totals/components/psbt-address-transfer-totals.tsx @@ -1,7 +1,6 @@ import { useCalculateBitcoinFiatValue } from '@leather-wallet/query'; -import { truncateMiddle } from '@leather-wallet/utils'; +import { formatMoney, i18nFormatCurrency, truncateMiddle } from '@leather-wallet/utils'; -import { formatMoney, i18nFormatCurrency } from '@app/common/money/format-money'; import { usePsbtSignerContext } from '@app/features/psbt-signer/psbt-signer.context'; import { PsbtAddressTotalItem } from './psbt-address-total-item'; diff --git a/src/app/features/psbt-signer/components/psbt-request-fee.tsx b/src/app/features/psbt-signer/components/psbt-request-fee.tsx index 9765df998a0..ce49902c3bf 100644 --- a/src/app/features/psbt-signer/components/psbt-request-fee.tsx +++ b/src/app/features/psbt-signer/components/psbt-request-fee.tsx @@ -1,9 +1,8 @@ import type { Money } from '@leather-wallet/models'; import { useCalculateBitcoinFiatValue } from '@leather-wallet/query'; +import { formatMoney, i18nFormatCurrency } from '@leather-wallet/utils'; import { HStack, Stack, styled } from 'leather-styles/jsx'; -import { formatMoney, i18nFormatCurrency } from '@app/common/money/format-money'; - import { PsbtRequestDetailsSectionLayout } from './psbt-request-details-section.layout'; export function PsbtRequestFee(props: { fee: Money }) { diff --git a/src/app/features/psbt-signer/hooks/use-psbt-details.tsx b/src/app/features/psbt-signer/hooks/use-psbt-details.tsx index 9cfbddfbb2b..2800382735b 100644 --- a/src/app/features/psbt-signer/hooks/use-psbt-details.tsx +++ b/src/app/features/psbt-signer/hooks/use-psbt-details.tsx @@ -1,9 +1,8 @@ import { useCallback, useMemo } from 'react'; -import { createMoney } from '@leather-wallet/utils'; +import { createMoney, subtractMoney } from '@leather-wallet/utils'; import * as btc from '@scure/btc-signer'; -import { subtractMoney } from '@app/common/money/calculate-money'; import { useCurrentAccountNativeSegwitIndexZeroSigner } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks'; import { useCurrentAccountTaprootIndexZeroSigner } from '@app/store/accounts/blockchain/bitcoin/taproot-account.hooks'; import { useCurrentNetwork } from '@app/store/networks/networks.selectors'; diff --git a/src/app/features/retrieve-taproot-to-native-segwit/retrieve-taproot-to-native-segwit.tsx b/src/app/features/retrieve-taproot-to-native-segwit/retrieve-taproot-to-native-segwit.tsx index 86eb01b182d..89615e84b9a 100644 --- a/src/app/features/retrieve-taproot-to-native-segwit/retrieve-taproot-to-native-segwit.tsx +++ b/src/app/features/retrieve-taproot-to-native-segwit/retrieve-taproot-to-native-segwit.tsx @@ -5,13 +5,12 @@ import { useCurrentTaprootAccountBalance, useCurrentTaprootAccountUninscribedUtxos, } from '@leather-wallet/query'; -import { delay, truncateMiddle } from '@leather-wallet/utils'; +import { delay, formatMoneyPadded, truncateMiddle } from '@leather-wallet/utils'; import { Stack } from 'leather-styles/jsx'; import { RouteUrls } from '@shared/route-urls'; import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; -import { formatMoneyPadded } from '@app/common/money/format-money'; import { FormAddressDisplayer } from '@app/components/address-displayer/form-address-displayer'; import { InfoCardRow, InfoCardSeparator } from '@app/components/info-card/info-card'; import { useToast } from '@app/features/toasts/use-toast'; diff --git a/src/app/features/stacks-transaction-request/hooks/use-stacks-transaction-summary.ts b/src/app/features/stacks-transaction-request/hooks/use-stacks-transaction-summary.ts index 2cbe4a9f7a4..4b161b7854f 100644 --- a/src/app/features/stacks-transaction-request/hooks/use-stacks-transaction-summary.ts +++ b/src/app/features/stacks-transaction-request/hooks/use-stacks-transaction-summary.ts @@ -1,5 +1,13 @@ import { useCryptoCurrencyMarketDataMeanAverage } from '@leather-wallet/query'; -import { createMoney, isDefined, microStxToStx } from '@leather-wallet/utils'; +import { + baseCurrencyAmountInQuote, + convertToMoneyTypeWithDefaultOfZero, + createMoney, + formatMoney, + i18nFormatCurrency, + isDefined, + microStxToStx, +} from '@leather-wallet/utils'; import { bytesToUtf8 } from '@stacks/common'; import { ClarityType, @@ -15,11 +23,6 @@ import BigNumber from 'bignumber.js'; import { CryptoCurrencies } from '@shared/models/currencies.model'; -import { - baseCurrencyAmountInQuote, - convertToMoneyTypeWithDefaultOfZero, -} from '@app/common/money/calculate-money'; -import { formatMoney, i18nFormatCurrency } from '@app/common/money/format-money'; import { getEstimatedConfirmationTime } from '@app/common/transactions/stacks/transaction.utils'; import { removeTrailingNullCharacters } from '@app/common/utils'; import { useStacksBlockTime } from '@app/query/stacks/info/info.hooks'; diff --git a/src/app/pages/bitcoin-contract-list/components/bitcoin-contract-list-item-layout.tsx b/src/app/pages/bitcoin-contract-list/components/bitcoin-contract-list-item-layout.tsx index d8998780280..863d6f7f183 100644 --- a/src/app/pages/bitcoin-contract-list/components/bitcoin-contract-list-item-layout.tsx +++ b/src/app/pages/bitcoin-contract-list/components/bitcoin-contract-list-item-layout.tsx @@ -1,12 +1,15 @@ import { useCallback } from 'react'; import { useCryptoCurrencyMarketDataMeanAverage } from '@leather-wallet/query'; -import { createMoneyFromDecimal, satToBtc } from '@leather-wallet/utils'; +import { + baseCurrencyAmountInQuote, + createMoneyFromDecimal, + i18nFormatCurrency, + satToBtc, +} from '@leather-wallet/utils'; import { Flex, HStack, styled } from 'leather-styles/jsx'; import { useBitcoinExplorerLink } from '@app/common/hooks/use-bitcoin-explorer-link'; -import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; -import { i18nFormatCurrency } from '@app/common/money/format-money'; import { Flag } from '@app/ui/components/flag/flag'; import { Caption } from '@app/ui/components/typography/caption'; import { BitcoinContractIcon } from '@app/ui/icons/bitcoin-contract-icon'; diff --git a/src/app/pages/bitcoin-contract-request/components/bitcoin-contract-offer/bitcoin-contract-offer-input.tsx b/src/app/pages/bitcoin-contract-request/components/bitcoin-contract-offer/bitcoin-contract-offer-input.tsx index f994ded76e4..d476b425e56 100644 --- a/src/app/pages/bitcoin-contract-request/components/bitcoin-contract-offer/bitcoin-contract-offer-input.tsx +++ b/src/app/pages/bitcoin-contract-request/components/bitcoin-contract-offer/bitcoin-contract-offer-input.tsx @@ -1,9 +1,14 @@ import { useCalculateBitcoinFiatValue } from '@leather-wallet/query'; -import { createMoneyFromDecimal, satToBtc, truncateMiddle } from '@leather-wallet/utils'; +import { + createMoneyFromDecimal, + formatMoney, + i18nFormatCurrency, + satToBtc, + truncateMiddle, +} from '@leather-wallet/utils'; import { Stack, styled } from 'leather-styles/jsx'; import { SimplifiedBitcoinContract } from '@app/common/hooks/use-bitcoin-contracts'; -import { formatMoney, i18nFormatCurrency } from '@app/common/money/format-money'; import { BitcoinContractLockAmount } from './bitcoin-contract-lock-amount'; diff --git a/src/app/pages/rpc-send-transfer/components/send-transfer-confirmation-details.tsx b/src/app/pages/rpc-send-transfer/components/send-transfer-confirmation-details.tsx index f7598ee0865..beb109c2367 100644 --- a/src/app/pages/rpc-send-transfer/components/send-transfer-confirmation-details.tsx +++ b/src/app/pages/rpc-send-transfer/components/send-transfer-confirmation-details.tsx @@ -1,8 +1,7 @@ import type { Money } from '@leather-wallet/models'; +import { formatMoney } from '@leather-wallet/utils'; import { HStack, Stack, styled } from 'leather-styles/jsx'; -import { formatMoney } from '@app/common/money/format-money'; - interface SendTransferConfirmationDetailsProps { currentAddress: string; recipient: string; diff --git a/src/app/pages/rpc-send-transfer/components/send-transfer-details.tsx b/src/app/pages/rpc-send-transfer/components/send-transfer-details.tsx index 1a7b4f4a430..1117dbf7cfd 100644 --- a/src/app/pages/rpc-send-transfer/components/send-transfer-details.tsx +++ b/src/app/pages/rpc-send-transfer/components/send-transfer-details.tsx @@ -1,10 +1,8 @@ -import { truncateMiddle } from '@leather-wallet/utils'; +import { formatMoney, truncateMiddle } from '@leather-wallet/utils'; import { HStack, Stack, styled } from 'leather-styles/jsx'; import type { TransferRecipient } from '@shared/models/form.model'; -import { formatMoney } from '@app/common/money/format-money'; - interface SendTransferDetailsProps { recipients: TransferRecipient[]; currentAddress: string; diff --git a/src/app/pages/rpc-send-transfer/rpc-send-transfer-confirmation.tsx b/src/app/pages/rpc-send-transfer/rpc-send-transfer-confirmation.tsx index f7f6cfecc3b..2e8c9f983fb 100644 --- a/src/app/pages/rpc-send-transfer/rpc-send-transfer-confirmation.tsx +++ b/src/app/pages/rpc-send-transfer/rpc-send-transfer-confirmation.tsx @@ -4,7 +4,16 @@ import { useBitcoinBroadcastTransaction, useCryptoCurrencyMarketDataMeanAverage, } from '@leather-wallet/query'; -import { createMoney, truncateMiddle } from '@leather-wallet/utils'; +import { + baseCurrencyAmountInQuote, + createMoney, + formatMoney, + formatMoneyPadded, + formatMoneyWithoutSymbol, + i18nFormatCurrency, + sumMoney, + truncateMiddle, +} from '@leather-wallet/utils'; import { HStack, Stack, styled } from 'leather-styles/jsx'; import get from 'lodash.get'; @@ -16,13 +25,6 @@ import { RouteUrls } from '@shared/route-urls'; import { makeRpcSuccessResponse } from '@shared/rpc/rpc-methods'; import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; -import { baseCurrencyAmountInQuote, sumMoney } from '@app/common/money/calculate-money'; -import { - formatMoney, - formatMoneyPadded, - formatMoneyWithoutSymbol, - i18nFormatCurrency, -} from '@app/common/money/format-money'; import { InfoCardFooter } from '@app/components/info-card/info-card'; import { useCurrentNativeSegwitUtxos } from '@app/query/bitcoin/address/utxos-by-address.hooks'; import { useCurrentAccountNativeSegwitAddressIndexZero } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks'; diff --git a/src/app/pages/rpc-send-transfer/rpc-send-transfer.tsx b/src/app/pages/rpc-send-transfer/rpc-send-transfer.tsx index 4604eddbced..658e9fdf43a 100644 --- a/src/app/pages/rpc-send-transfer/rpc-send-transfer.tsx +++ b/src/app/pages/rpc-send-transfer/rpc-send-transfer.tsx @@ -1,7 +1,6 @@ -import { createMoney } from '@leather-wallet/utils'; +import { createMoney, formatMoneyPadded } from '@leather-wallet/utils'; import BigNumber from 'bignumber.js'; -import { formatMoneyPadded } from '@app/common/money/format-money'; import { InfoCardFooter } from '@app/components/info-card/info-card'; import { useBreakOnNonCompliantEntity } from '@app/query/common/compliance-checker/compliance-checker.query'; import { useCurrentAccountNativeSegwitIndexZeroSigner } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks'; diff --git a/src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx b/src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx index 374a65ebd81..276763810df 100644 --- a/src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx +++ b/src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx @@ -7,7 +7,13 @@ import { useCalculateBitcoinFiatValue, useCryptoCurrencyMarketDataMeanAverage, } from '@leather-wallet/query'; -import { isError } from '@leather-wallet/utils'; +import { + formatMoney, + formatMoneyPadded, + i18nFormatCurrency, + isError, + sumMoney, +} from '@leather-wallet/utils'; import { hexToBytes } from '@noble/hashes/utils'; import { bytesToHex } from '@stacks/common'; @@ -16,8 +22,6 @@ import { makeRpcErrorResponse, makeRpcSuccessResponse } from '@shared/rpc/rpc-me import { closeWindow } from '@shared/utils'; import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; -import { sumMoney } from '@app/common/money/calculate-money'; -import { formatMoney, formatMoneyPadded, i18nFormatCurrency } from '@app/common/money/format-money'; import { SignPsbtArgs } from '@app/common/psbt/requests'; import { useRpcSignPsbtParams } from '@app/common/psbt/use-psbt-request-params'; import { usePsbtSigner } from '@app/features/psbt-signer/hooks/use-psbt-signer'; diff --git a/src/app/pages/send/ordinal-inscription/hooks/use-send-inscription-fees-list.ts b/src/app/pages/send/ordinal-inscription/hooks/use-send-inscription-fees-list.ts index 430212bb9d1..cc12720e843 100644 --- a/src/app/pages/send/ordinal-inscription/hooks/use-send-inscription-fees-list.ts +++ b/src/app/pages/send/ordinal-inscription/hooks/use-send-inscription-fees-list.ts @@ -6,12 +6,15 @@ import { useAverageBitcoinFeeRates, useCryptoCurrencyMarketDataMeanAverage, } from '@leather-wallet/query'; -import { createMoney } from '@leather-wallet/utils'; +import { + baseCurrencyAmountInQuote, + createMoney, + formatMoneyPadded, + i18nFormatCurrency, +} from '@leather-wallet/utils'; import { BtcFeeType, btcTxTimeMap } from '@shared/models/fees/bitcoin-fees.model'; -import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; -import { formatMoneyPadded, i18nFormatCurrency } from '@app/common/money/format-money'; import { FeesListItem } from '@app/components/bitcoin-fees-list/bitcoin-fees-list'; import { useCurrentNativeSegwitUtxos } from '@app/query/bitcoin/address/utxos-by-address.hooks'; import { useCurrentAccountNativeSegwitSigner } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks'; diff --git a/src/app/pages/send/send-crypto-asset-form/components/send-fiat-value.tsx b/src/app/pages/send/send-crypto-asset-form/components/send-fiat-value.tsx index 9e29bdd048d..8aeed8a5dc1 100644 --- a/src/app/pages/send/send-crypto-asset-form/components/send-fiat-value.tsx +++ b/src/app/pages/send/send-crypto-asset-form/components/send-fiat-value.tsx @@ -1,15 +1,15 @@ import { useEffect, useState } from 'react'; -import type { Money } from '@leather-wallet/models'; -import { createMoneyFromDecimal, isNumber } from '@leather-wallet/utils'; +import type { MarketData, Money } from '@leather-wallet/models'; +import { + baseCurrencyAmountInQuote, + createMoneyFromDecimal, + i18nFormatCurrency, + isNumber, +} from '@leather-wallet/utils'; import { useField } from 'formik'; import { styled } from 'leather-styles/jsx'; -import { MarketData } from '@shared/models/market.model'; - -import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; -import { i18nFormatCurrency } from '@app/common/money/format-money'; - interface SendFiatInputProps { marketData: MarketData; assetSymbol?: string; diff --git a/src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx b/src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx index 1d46bf8c47a..43f5f26abe2 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form-confirmation.tsx @@ -1,7 +1,7 @@ import { useLocation, useNavigate } from 'react-router-dom'; import { useBitcoinBroadcastTransaction } from '@leather-wallet/query'; -import { createMoney } from '@leather-wallet/utils'; +import { createMoney, formatMoney, formatMoneyPadded, sumMoney } from '@leather-wallet/utils'; import { SendCryptoAssetSelectors } from '@tests/selectors/send.selectors'; import { Stack } from 'leather-styles/jsx'; import get from 'lodash.get'; @@ -10,8 +10,6 @@ import { decodeBitcoinTx } from '@shared/crypto/bitcoin/bitcoin.utils'; import { RouteUrls } from '@shared/route-urls'; import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; -import { sumMoney } from '@app/common/money/calculate-money'; -import { formatMoney, formatMoneyPadded } from '@app/common/money/format-money'; import { InfoCardAssetValue, InfoCardRow, diff --git a/src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form.tsx b/src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form.tsx index 91a2bcbe461..42a8e95a49e 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/brc20/brc20-send-form.tsx @@ -1,15 +1,12 @@ import { Outlet, useLocation } from 'react-router-dom'; -import type { Money } from '@leather-wallet/models'; +import type { MarketData, Money } from '@leather-wallet/models'; +import { convertAmountToBaseUnit, formatMoney } from '@leather-wallet/utils'; import { SendCryptoAssetSelectors } from '@tests/selectors/send.selectors'; import { Form, Formik } from 'formik'; import { Box, styled } from 'leather-styles/jsx'; import get from 'lodash.get'; -import type { MarketData } from '@shared/models/market.model'; - -import { convertAmountToBaseUnit } from '@app/common/money/calculate-money'; -import { formatMoney } from '@app/common/money/format-money'; import { openInNewTab } from '@app/common/utils/open-in-new-tab'; import { Brc20AvatarIcon } from '@app/ui/components/avatar/brc20-avatar-icon'; import { Button } from '@app/ui/components/button/button'; diff --git a/src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx b/src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx index 6a0cca1f69e..3b29f7f5dd1 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form-confirmation.tsx @@ -5,7 +5,14 @@ import { useBitcoinBroadcastTransaction, useCryptoCurrencyMarketDataMeanAverage, } from '@leather-wallet/query'; -import { createMoney, createMoneyFromDecimal, satToBtc } from '@leather-wallet/utils'; +import { + baseCurrencyAmountInQuote, + createMoney, + createMoneyFromDecimal, + formatMoneyPadded, + i18nFormatCurrency, + satToBtc, +} from '@leather-wallet/utils'; import { hexToBytes } from '@noble/hashes/utils'; import * as btc from '@scure/btc-signer'; import { SendCryptoAssetSelectors } from '@tests/selectors/send.selectors'; @@ -18,8 +25,6 @@ import { CryptoCurrencies } from '@shared/models/currencies.model'; import { RouteUrls } from '@shared/route-urls'; import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; -import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; -import { formatMoneyPadded, i18nFormatCurrency } from '@app/common/money/format-money'; import { queryClient } from '@app/common/persistence'; import { FormAddressDisplayer } from '@app/components/address-displayer/form-address-displayer'; import { diff --git a/src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form.tsx b/src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form.tsx index 456c1055be2..96fd1cfe83a 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/btc/btc-send-form.tsx @@ -2,13 +2,13 @@ import { Outlet } from 'react-router-dom'; import type { CryptoCurrencies } from '@leather-wallet/models'; import { useCryptoCurrencyMarketDataMeanAverage } from '@leather-wallet/query'; +import { formatMoney } from '@leather-wallet/utils'; import { SendCryptoAssetSelectors } from '@tests/selectors/send.selectors'; import { Form, Formik } from 'formik'; import { Box } from 'leather-styles/jsx'; import { HIGH_FEE_WARNING_LEARN_MORE_URL_BTC } from '@shared/constants'; -import { formatMoney } from '@app/common/money/format-money'; import { HighFeeDialog } from '@app/features/dialogs/high-fee-dialog/high-fee-dialog'; import { BtcAvatarIcon } from '@app/ui/components/avatar/btc-avatar-icon'; import { Button } from '@app/ui/components/button/button'; diff --git a/src/app/pages/send/send-crypto-asset-form/form/sip10/use-sip10-send-form.tsx b/src/app/pages/send/send-crypto-asset-form/form/sip10/use-sip10-send-form.tsx index 4176cbfc2d7..6e80e52b9cf 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/sip10/use-sip10-send-form.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/sip10/use-sip10-send-form.tsx @@ -1,13 +1,13 @@ import { useMemo } from 'react'; import type { CryptoAssetBalance, Sip10CryptoAssetInfo } from '@leather-wallet/models'; +import { convertAmountToBaseUnit } from '@leather-wallet/utils'; import { FormikHelpers } from 'formik'; import * as yup from 'yup'; import { logger } from '@shared/logger'; import { StacksSendFormValues } from '@shared/models/form.model'; -import { convertAmountToBaseUnit } from '@app/common/money/calculate-money'; import { getSafeImageCanonicalUri } from '@app/common/stacks-utils'; import { stacksFungibleTokenAmountValidator } from '@app/common/validation/forms/amount-validators'; import { useCalculateStacksTxFees } from '@app/query/stacks/fees/fees.hooks'; diff --git a/src/app/pages/send/send-crypto-asset-form/form/stacks/stacks-common-send-form.tsx b/src/app/pages/send/send-crypto-asset-form/form/stacks/stacks-common-send-form.tsx index 193f27ed14c..759a6155152 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/stacks/stacks-common-send-form.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/stacks/stacks-common-send-form.tsx @@ -1,6 +1,7 @@ import { Outlet, useNavigate } from 'react-router-dom'; import type { Money } from '@leather-wallet/models'; +import { formatMoney } from '@leather-wallet/utils'; import { SendCryptoAssetSelectors } from '@tests/selectors/send.selectors'; import BigNumber from 'bignumber.js'; import { Form, Formik, FormikHelpers } from 'formik'; @@ -12,7 +13,6 @@ import { Fees } from '@shared/models/fees/fees.model'; import { StacksSendFormValues } from '@shared/models/form.model'; import { RouteUrls } from '@shared/route-urls'; -import { formatMoney } from '@app/common/money/format-money'; import { FeesRow } from '@app/components/fees-row/fees-row'; import { NonceSetter } from '@app/components/nonce-setter'; import { HighFeeDialog } from '@app/features/dialogs/high-fee-dialog/high-fee-dialog'; diff --git a/src/app/pages/send/send-crypto-asset-form/form/stx/use-stx-send-form.tsx b/src/app/pages/send/send-crypto-asset-form/form/stx/use-stx-send-form.tsx index d69d206590b..20e0575cb66 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/stx/use-stx-send-form.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/stx/use-stx-send-form.tsx @@ -1,5 +1,6 @@ import { useMemo } from 'react'; +import { convertAmountToBaseUnit } from '@leather-wallet/utils'; import { FormikHelpers } from 'formik'; import * as yup from 'yup'; @@ -7,7 +8,6 @@ import { STX_DECIMALS } from '@shared/constants'; import { logger } from '@shared/logger'; import { StacksSendFormValues } from '@shared/models/form.model'; -import { convertAmountToBaseUnit } from '@app/common/money/calculate-money'; import { stxAmountValidator, stxAvailableBalanceValidator, diff --git a/src/app/pages/send/sent-summary/brc20-sent-summary.tsx b/src/app/pages/send/sent-summary/brc20-sent-summary.tsx index 5c8e73cadb9..6f4e2ab24c1 100644 --- a/src/app/pages/send/sent-summary/brc20-sent-summary.tsx +++ b/src/app/pages/send/sent-summary/brc20-sent-summary.tsx @@ -1,11 +1,10 @@ import { useLocation, useNavigate } from 'react-router-dom'; -import { createMoney } from '@leather-wallet/utils'; +import { createMoney, formatMoney } from '@leather-wallet/utils'; import { HStack, Stack, styled } from 'leather-styles/jsx'; import get from 'lodash.get'; import { HandleOpenStacksTxLinkArgs } from '@app/common/hooks/use-stacks-explorer-link'; -import { formatMoney } from '@app/common/money/format-money'; import { openInNewTab } from '@app/common/utils/open-in-new-tab'; import { InfoCardAssetValue, diff --git a/src/app/pages/swap/components/swap-asset-dialog/components/swap-asset-item.tsx b/src/app/pages/swap/components/swap-asset-dialog/components/swap-asset-item.tsx index 83ccef5e333..82eabeab90b 100644 --- a/src/app/pages/swap/components/swap-asset-dialog/components/swap-asset-item.tsx +++ b/src/app/pages/swap/components/swap-asset-dialog/components/swap-asset-item.tsx @@ -1,7 +1,7 @@ +import { formatMoneyWithoutSymbol } from '@leather-wallet/utils'; import { SwapSelectors } from '@tests/selectors/swap.selectors'; import { convertAssetBalanceToFiat } from '@app/common/asset-utils'; -import { formatMoneyWithoutSymbol } from '@app/common/money/format-money'; import type { SwapAsset } from '@app/query/common/alex-sdk/alex-sdk.hooks'; import { useGetFungibleTokenMetadataQuery } from '@app/query/stacks/token-metadata/fungible-tokens/fungible-token-metadata.query'; import { isFtAsset } from '@app/query/stacks/token-metadata/token-metadata.utils'; diff --git a/src/app/pages/swap/components/swap-asset-dialog/components/swap-asset-list.tsx b/src/app/pages/swap/components/swap-asset-dialog/components/swap-asset-list.tsx index 384db6b427b..5da8af7f76c 100644 --- a/src/app/pages/swap/components/swap-asset-dialog/components/swap-asset-list.tsx +++ b/src/app/pages/swap/components/swap-asset-dialog/components/swap-asset-list.tsx @@ -1,6 +1,11 @@ import { useNavigate, useParams } from 'react-router-dom'; -import { createMoney, isUndefined } from '@leather-wallet/utils'; +import { + convertAmountToFractionalUnit, + createMoney, + formatMoneyWithoutSymbol, + isUndefined, +} from '@leather-wallet/utils'; import { SwapSelectors } from '@tests/selectors/swap.selectors'; import BigNumber from 'bignumber.js'; import { useFormikContext } from 'formik'; @@ -8,8 +13,6 @@ import { Stack } from 'leather-styles/jsx'; import { RouteUrls } from '@shared/route-urls'; -import { convertAmountToFractionalUnit } from '@app/common/money/calculate-money'; -import { formatMoneyWithoutSymbol } from '@app/common/money/format-money'; import { useSwapContext } from '@app/pages/swap/swap.context'; import type { SwapAsset } from '@app/query/common/alex-sdk/alex-sdk.hooks'; diff --git a/src/app/pages/swap/components/swap-asset-select/components/swap-amount-field.tsx b/src/app/pages/swap/components/swap-asset-select/components/swap-amount-field.tsx index 8574f05224e..4572b38b0d3 100644 --- a/src/app/pages/swap/components/swap-asset-select/components/swap-amount-field.tsx +++ b/src/app/pages/swap/components/swap-asset-select/components/swap-amount-field.tsx @@ -1,14 +1,18 @@ import { ChangeEvent } from 'react'; -import { createMoney, isDefined, isUndefined } from '@leather-wallet/utils'; +import { + convertAmountToFractionalUnit, + createMoney, + formatMoneyWithoutSymbol, + isDefined, + isUndefined, +} from '@leather-wallet/utils'; import { SwapSelectors } from '@tests/selectors/swap.selectors'; import BigNumber from 'bignumber.js'; import { useField, useFormikContext } from 'formik'; import { Stack, styled } from 'leather-styles/jsx'; import { useShowFieldError } from '@app/common/form-utils'; -import { convertAmountToFractionalUnit } from '@app/common/money/calculate-money'; -import { formatMoneyWithoutSymbol } from '@app/common/money/format-money'; import { SwapFormValues } from '../../../hooks/use-swap-form'; import { useSwapContext } from '../../../swap.context'; diff --git a/src/app/pages/swap/components/swap-asset-select/swap-asset-select-base.tsx b/src/app/pages/swap/components/swap-asset-select/swap-asset-select-base.tsx index 2382f7013fc..e62bcdd0797 100644 --- a/src/app/pages/swap/components/swap-asset-select/swap-asset-select-base.tsx +++ b/src/app/pages/swap/components/swap-asset-select/swap-asset-select-base.tsx @@ -1,12 +1,17 @@ -import { createMoney, isDefined, isUndefined } from '@leather-wallet/utils'; +import { + convertAmountToFractionalUnit, + createMoney, + formatMoneyWithoutSymbol, + i18nFormatCurrency, + isDefined, + isUndefined, +} from '@leather-wallet/utils'; import BigNumber from 'bignumber.js'; import { useField, useFormikContext } from 'formik'; import { RouteUrls } from '@shared/route-urls'; import { useShowFieldError } from '@app/common/form-utils'; -import { convertAmountToFractionalUnit } from '@app/common/money/calculate-money'; -import { formatMoneyWithoutSymbol, i18nFormatCurrency } from '@app/common/money/format-money'; import { SwapFormValues } from '../../hooks/use-swap-form'; import { useSwapNavigate } from '../../hooks/use-swap-navigate'; diff --git a/src/app/pages/swap/components/swap-asset-select/swap-asset-select-quote.tsx b/src/app/pages/swap/components/swap-asset-select/swap-asset-select-quote.tsx index 88e67b1ae8f..304917005dc 100644 --- a/src/app/pages/swap/components/swap-asset-select/swap-asset-select-quote.tsx +++ b/src/app/pages/swap/components/swap-asset-select/swap-asset-select-quote.tsx @@ -1,9 +1,8 @@ -import { isDefined } from '@leather-wallet/utils'; +import { formatMoneyWithoutSymbol, i18nFormatCurrency, isDefined } from '@leather-wallet/utils'; import { useField } from 'formik'; import { RouteUrls } from '@shared/route-urls'; -import { formatMoneyWithoutSymbol, i18nFormatCurrency } from '@app/common/money/format-money'; import { LoadingSpinner } from '@app/components/loading-spinner'; import { useSwapNavigate } from '../../hooks/use-swap-navigate'; diff --git a/src/app/pages/swap/components/swap-details/swap-details.tsx b/src/app/pages/swap/components/swap-details/swap-details.tsx index c4802703a33..1bfd3b45da9 100644 --- a/src/app/pages/swap/components/swap-details/swap-details.tsx +++ b/src/app/pages/swap/components/swap-details/swap-details.tsx @@ -1,5 +1,6 @@ import { createMoneyFromDecimal, + formatMoneyPadded, isDefined, isUndefined, microStxToStx, @@ -8,7 +9,6 @@ import { SwapSelectors } from '@tests/selectors/swap.selectors'; import BigNumber from 'bignumber.js'; import { HStack, styled } from 'leather-styles/jsx'; -import { formatMoneyPadded } from '@app/common/money/format-money'; import { getEstimatedConfirmationTime } from '@app/common/transactions/stacks/transaction.utils'; import { SwapSubmissionData, useSwapContext } from '@app/pages/swap/swap.context'; import { useStacksBlockTime } from '@app/query/stacks/info/info.hooks'; diff --git a/src/app/pages/swap/hooks/use-swap-form.tsx b/src/app/pages/swap/hooks/use-swap-form.tsx index 15b62711cf5..c34a4d34166 100644 --- a/src/app/pages/swap/hooks/use-swap-form.tsx +++ b/src/app/pages/swap/hooks/use-swap-form.tsx @@ -1,4 +1,4 @@ -import { createMoney } from '@leather-wallet/utils'; +import { convertAmountToFractionalUnit, createMoney } from '@leather-wallet/utils'; import BigNumber from 'bignumber.js'; import * as yup from 'yup'; @@ -6,7 +6,6 @@ import { FormErrorMessages } from '@shared/error-messages'; import { FeeTypes } from '@shared/models/fees/fees.model'; import { StacksTransactionFormValues } from '@shared/models/form.model'; -import { convertAmountToFractionalUnit } from '@app/common/money/calculate-money'; import type { SwapAsset } from '@app/query/common/alex-sdk/alex-sdk.hooks'; import { useNextNonce } from '@app/query/stacks/nonce/account-nonces.hooks'; diff --git a/src/app/pages/swap/swap.utils.ts b/src/app/pages/swap/swap.utils.ts index b7bdbc7d845..99479345d43 100644 --- a/src/app/pages/swap/swap.utils.ts +++ b/src/app/pages/swap/swap.utils.ts @@ -1,10 +1,10 @@ -import type { Money } from '@leather-wallet/models'; -import { createMoney, unitToFractionalUnit } from '@leather-wallet/utils'; - -import type { MarketData } from '@shared/models/market.model'; - -import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; -import { isMoneyGreaterThanZero } from '@app/common/money/money.utils'; +import type { MarketData, Money } from '@leather-wallet/models'; +import { + baseCurrencyAmountInQuote, + createMoney, + isMoneyGreaterThanZero, + unitToFractionalUnit, +} from '@leather-wallet/utils'; export function convertInputAmountValueToFiat(balance: Money, price: MarketData, value: string) { const valueAsMoney = createMoney( diff --git a/src/app/query/bitcoin/balance/bitcoin-contracts-balance.hooks.ts b/src/app/query/bitcoin/balance/bitcoin-contracts-balance.hooks.ts index c05b36dbac9..efc5770d9b8 100644 --- a/src/app/query/bitcoin/balance/bitcoin-contracts-balance.hooks.ts +++ b/src/app/query/bitcoin/balance/bitcoin-contracts-balance.hooks.ts @@ -1,11 +1,9 @@ import { useMemo } from 'react'; import { useCalculateBitcoinFiatValue } from '@leather-wallet/query'; -import { createMoney, isUndefined } from '@leather-wallet/utils'; +import { createMoney, i18nFormatCurrency, isUndefined } from '@leather-wallet/utils'; import BigNumber from 'bignumber.js'; -import { i18nFormatCurrency } from '@app/common/money/format-money'; - import { useBitcoinContractsBalanceQuery } from './bitcoin-contracts-balance.query'; export function useGetBitcoinContractsBalance() { diff --git a/src/app/query/bitcoin/ordinals/brc20/brc20-tokens.hooks.ts b/src/app/query/bitcoin/ordinals/brc20/brc20-tokens.hooks.ts index dd80bb7d153..dcb44e471f9 100644 --- a/src/app/query/bitcoin/ordinals/brc20/brc20-tokens.hooks.ts +++ b/src/app/query/bitcoin/ordinals/brc20/brc20-tokens.hooks.ts @@ -1,4 +1,8 @@ -import type { Brc20CryptoAssetInfo } from '@leather-wallet/models'; +import { + type Brc20CryptoAssetInfo, + createMarketData, + createMarketPair, +} from '@leather-wallet/models'; import { createBrc20TransferInscription, encodeBrc20TransferInscription, @@ -11,8 +15,6 @@ import { import { createMoney, unitToFractionalUnit } from '@leather-wallet/utils'; import BigNumber from 'bignumber.js'; -import { createMarketData, createMarketPair } from '@shared/models/market.model'; - import { createCryptoAssetBalance } from '@app/query/common/models'; import { isFetchedWithSuccess } from '@app/query/query-config'; import { useAppDispatch } from '@app/store'; diff --git a/src/app/query/common/alex-sdk/alex-sdk.hooks.ts b/src/app/query/common/alex-sdk/alex-sdk.hooks.ts index a4ed43795a7..c171502856b 100644 --- a/src/app/query/common/alex-sdk/alex-sdk.hooks.ts +++ b/src/app/query/common/alex-sdk/alex-sdk.hooks.ts @@ -1,15 +1,18 @@ import { useCallback } from 'react'; -import type { Money } from '@leather-wallet/models'; -import { createMoney, isDefined } from '@leather-wallet/utils'; +import { + type MarketData, + type Money, + createMarketData, + createMarketPair, +} from '@leather-wallet/models'; +import { convertAmountToFractionalUnit, createMoney, isDefined } from '@leather-wallet/utils'; import { Currency, type TokenInfo } from 'alex-sdk'; import BigNumber from 'bignumber.js'; import { logger } from '@shared/logger'; -import { type MarketData, createMarketData, createMarketPair } from '@shared/models/market.model'; import { sortAssetsByName } from '@app/common/asset-utils'; -import { convertAmountToFractionalUnit } from '@app/common/money/calculate-money'; import { getPrincipalFromContractId } from '@app/common/utils'; import { useCurrentStxAvailableUnlockedBalance } from '@app/query/stacks/balance/account-balance.hooks'; import { useTransferableSip10Tokens } from '@app/query/stacks/sip10/sip10-tokens.hooks'; diff --git a/src/app/query/stacks/balance/account-balance.hooks.ts b/src/app/query/stacks/balance/account-balance.hooks.ts index 1df67f702fc..0e1783ecdfa 100644 --- a/src/app/query/stacks/balance/account-balance.hooks.ts +++ b/src/app/query/stacks/balance/account-balance.hooks.ts @@ -1,10 +1,9 @@ import type { Money, StxCryptoAssetBalance } from '@leather-wallet/models'; -import { createMoney } from '@leather-wallet/utils'; +import { createMoney, subtractMoney, sumMoney } from '@leather-wallet/utils'; import BigNumber from 'bignumber.js'; import { AccountBalanceStxKeys, type AddressBalanceResponse } from '@shared/models/account.model'; -import { subtractMoney, sumMoney } from '@app/common/money/calculate-money'; import { useCurrentStacksAccountAddress } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks'; import { accountBalanceStxKeys } from '@app/store/accounts/blockchain/stacks/stacks-account.models'; diff --git a/src/shared/constants.ts b/src/shared/constants.ts index c4c6d0fd730..f8ba725704a 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -79,7 +79,7 @@ export const STX20_API_BASE_URL_MAINNET = 'https://api.stx20.com/api/v1'; export const HIRO_EXPLORER_URL = 'https://explorer.hiro.so'; export const HIRO_API_BASE_URL_MAINNET = 'https://api.hiro.so'; -export const HIRO_API_BASE_URL_TESTNET = 'https://api.testnet.hiro.so'; +export const HIRO_API_BASE_URL_TESTNET = 'https://api.old.testnet.hiro.so'; export const HIRO_API_BASE_URL_NAKAMOTO_TESTNET = 'https://api.nakamoto.testnet.hiro.so'; export const BITCOIN_API_BASE_URL_MAINNET = 'https://blockstream.info/api'; diff --git a/src/shared/models/currencies.model.ts b/src/shared/models/currencies.model.ts index e49b7ad0ff7..4c93e3c56e5 100644 --- a/src/shared/models/currencies.model.ts +++ b/src/shared/models/currencies.model.ts @@ -1,5 +1,3 @@ import type { LiteralUnion } from 'leather-styles/types'; export type CryptoCurrencies = LiteralUnion<'BTC' | 'STX', string>; - -export type FiatCurrencies = 'USD' | string; diff --git a/src/shared/models/market.model.ts b/src/shared/models/market.model.ts deleted file mode 100644 index fc8102257ac..00000000000 --- a/src/shared/models/market.model.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { Money } from '@leather-wallet/models'; - -import { CryptoCurrencies, FiatCurrencies } from './currencies.model'; - -interface MarketPair { - readonly base: CryptoCurrencies; - readonly quote: FiatCurrencies; -} - -export function createMarketPair(base: CryptoCurrencies, quote: FiatCurrencies): MarketPair { - return Object.freeze({ base, quote }); -} - -export function formatMarketPair({ base, quote }: MarketPair) { - return `${base}/${quote}`; -} - -export interface MarketData { - readonly pair: MarketPair; - readonly price: Money; -} - -export function createMarketData(pair: MarketPair, price: Money): MarketData { - if (pair.quote !== price.symbol) - throw new Error('Cannot create market data when price does not match quote'); - return Object.freeze({ pair, price }); -}