@ton/appkit 0.0.5-alpha.2 → 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +139 -0
- package/dist/cjs/actions/index.d.ts +8 -0
- package/dist/cjs/actions/index.d.ts.map +1 -1
- package/dist/cjs/actions/index.js +18 -2
- package/dist/cjs/actions/jettons/create-transfer-jetton-transaction.d.ts +1 -1
- package/dist/cjs/actions/jettons/create-transfer-jetton-transaction.d.ts.map +1 -1
- package/dist/cjs/actions/jettons/create-transfer-jetton-transaction.js +17 -5
- package/dist/cjs/actions/jettons/get-jetton-balance.d.ts +1 -1
- package/dist/cjs/actions/jettons/get-jetton-balance.d.ts.map +1 -1
- package/dist/cjs/actions/jettons/get-jetton-balance.js +8 -3
- package/dist/cjs/actions/jettons/get-jetton-info.d.ts.map +1 -1
- package/dist/cjs/actions/jettons/get-jetton-info.js +15 -6
- package/dist/cjs/actions/jettons/get-jetton-wallet-address.d.ts +1 -1
- package/dist/cjs/actions/jettons/get-jetton-wallet-address.d.ts.map +1 -1
- package/dist/cjs/actions/jettons/get-jetton-wallet-address.js +15 -4
- package/dist/cjs/actions/nft/get-nft.d.ts +1 -1
- package/dist/cjs/actions/nft/get-nft.d.ts.map +1 -1
- package/dist/cjs/actions/staking/get-staking-provider-metadata.d.ts +19 -0
- package/dist/cjs/actions/staking/get-staking-provider-metadata.d.ts.map +1 -0
- package/dist/cjs/actions/staking/get-staking-provider-metadata.js +18 -0
- package/dist/cjs/actions/staking/get-staking-provider.d.ts +21 -0
- package/dist/cjs/actions/staking/get-staking-provider.d.ts.map +1 -0
- package/dist/cjs/actions/staking/get-staking-provider.js +17 -0
- package/dist/cjs/actions/staking/get-staking-providers.d.ts +3 -2
- package/dist/cjs/actions/staking/get-staking-providers.d.ts.map +1 -1
- package/dist/cjs/actions/staking/get-staking-providers.js +2 -2
- package/dist/cjs/actions/staking/set-default-staking-provider.d.ts +18 -0
- package/dist/cjs/actions/staking/set-default-staking-provider.d.ts.map +1 -0
- package/dist/cjs/actions/staking/set-default-staking-provider.js +18 -0
- package/dist/cjs/actions/staking/watch-staking-providers.d.ts +17 -0
- package/dist/cjs/actions/staking/watch-staking-providers.d.ts.map +1 -0
- package/dist/cjs/actions/staking/watch-staking-providers.js +28 -0
- package/dist/cjs/actions/swap/get-swap-provider.d.ts +15 -0
- package/dist/cjs/actions/swap/get-swap-provider.d.ts.map +1 -0
- package/dist/cjs/actions/swap/get-swap-provider.js +14 -0
- package/dist/cjs/actions/swap/get-swap-providers.d.ts +15 -0
- package/dist/cjs/actions/swap/get-swap-providers.d.ts.map +1 -0
- package/dist/cjs/actions/swap/get-swap-providers.js +17 -0
- package/dist/cjs/actions/swap/get-swap-quote.d.ts.map +1 -1
- package/dist/cjs/actions/swap/get-swap-quote.js +6 -1
- package/dist/cjs/actions/swap/set-default-swap-provider.d.ts +18 -0
- package/dist/cjs/actions/swap/set-default-swap-provider.d.ts.map +1 -0
- package/dist/cjs/actions/swap/set-default-swap-provider.js +18 -0
- package/dist/cjs/actions/swap/watch-swap-providers.d.ts +17 -0
- package/dist/cjs/actions/swap/watch-swap-providers.d.ts.map +1 -0
- package/dist/cjs/actions/swap/watch-swap-providers.js +29 -0
- package/dist/cjs/connectors/tonconnect/connectors/ton-connect-connector.js +2 -2
- package/dist/cjs/core/app-kit/constants/events.d.ts +0 -6
- package/dist/cjs/core/app-kit/constants/events.d.ts.map +1 -1
- package/dist/cjs/core/app-kit/constants/events.js +1 -7
- package/dist/cjs/core/app-kit/index.d.ts +2 -2
- package/dist/cjs/core/app-kit/index.d.ts.map +1 -1
- package/dist/cjs/core/app-kit/index.js +1 -2
- package/dist/cjs/core/app-kit/services/app-kit.d.ts +3 -1
- package/dist/cjs/core/app-kit/services/app-kit.d.ts.map +1 -1
- package/dist/cjs/core/app-kit/services/app-kit.js +4 -2
- package/dist/cjs/core/app-kit/types/config.d.ts +4 -2
- package/dist/cjs/core/app-kit/types/config.d.ts.map +1 -1
- package/dist/cjs/core/app-kit/types/events.d.ts +2 -7
- package/dist/cjs/core/app-kit/types/events.d.ts.map +1 -1
- package/dist/cjs/core/cache/adapters/lru-app-kit-cache.d.ts +20 -0
- package/dist/cjs/core/cache/adapters/lru-app-kit-cache.d.ts.map +1 -0
- package/dist/cjs/core/cache/adapters/lru-app-kit-cache.js +32 -0
- package/dist/cjs/core/cache/adapters/lru-app-kit-cache.test.d.ts +9 -0
- package/dist/cjs/core/cache/adapters/lru-app-kit-cache.test.d.ts.map +1 -0
- package/dist/cjs/core/cache/adapters/lru-app-kit-cache.test.js +68 -0
- package/dist/cjs/core/cache/index.d.ts +11 -0
- package/dist/cjs/core/cache/index.d.ts.map +1 -0
- package/dist/cjs/core/cache/index.js +14 -0
- package/dist/cjs/core/cache/types/app-kit-cache.d.ts +14 -0
- package/dist/cjs/core/cache/types/app-kit-cache.d.ts.map +1 -0
- package/dist/cjs/core/cache/types/app-kit-cache.js +9 -0
- package/dist/cjs/core/cache/utils/get-cache-key.d.ts +9 -0
- package/dist/cjs/core/cache/utils/get-cache-key.d.ts.map +1 -0
- package/dist/cjs/core/cache/utils/get-cache-key.js +12 -0
- package/dist/cjs/core/cache/utils/get-cache-key.test.d.ts +9 -0
- package/dist/cjs/core/cache/utils/get-cache-key.test.d.ts.map +1 -0
- package/dist/cjs/core/cache/utils/get-cache-key.test.js +30 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/queries/balances/get-balance-by-address.d.ts.map +1 -1
- package/dist/cjs/queries/balances/get-balance-by-address.js +9 -3
- package/dist/cjs/queries/index.d.ts +0 -1
- package/dist/cjs/queries/index.d.ts.map +1 -1
- package/dist/cjs/queries/index.js +1 -3
- package/dist/cjs/queries/jettons/get-jetton-balance-by-address.d.ts.map +1 -1
- package/dist/cjs/queries/jettons/get-jetton-balance-by-address.js +11 -11
- package/dist/cjs/queries/jettons/get-jetton-info.d.ts.map +1 -1
- package/dist/cjs/queries/jettons/get-jetton-info.js +5 -1
- package/dist/cjs/queries/jettons/get-jetton-wallet-address.d.ts.map +1 -1
- package/dist/cjs/queries/jettons/get-jetton-wallet-address.js +6 -1
- package/dist/cjs/queries/jettons/get-jettons-by-address.d.ts.map +1 -1
- package/dist/cjs/queries/jettons/get-jettons-by-address.js +9 -3
- package/dist/cjs/queries/nft/get-nft.d.ts +1 -1
- package/dist/cjs/queries/nft/get-nft.d.ts.map +1 -1
- package/dist/cjs/queries/nft/get-nft.js +5 -1
- package/dist/cjs/queries/nft/get-nfts-by-address.d.ts.map +1 -1
- package/dist/cjs/queries/nft/get-nfts-by-address.js +5 -1
- package/dist/cjs/queries/staking/get-staked-balance.d.ts +1 -1
- package/dist/cjs/queries/staking/get-staked-balance.d.ts.map +1 -1
- package/dist/cjs/queries/staking/get-staked-balance.js +7 -1
- package/dist/cjs/queries/staking/get-staking-provider-info.d.ts +1 -1
- package/dist/cjs/queries/staking/get-staking-provider-info.d.ts.map +1 -1
- package/dist/cjs/queries/staking/get-staking-provider-info.js +3 -1
- package/dist/cjs/queries/staking/get-staking-quote.d.ts +1 -1
- package/dist/cjs/queries/staking/get-staking-quote.d.ts.map +1 -1
- package/dist/cjs/queries/staking/get-staking-quote.js +8 -2
- package/dist/cjs/queries/swap/get-swap-quote.d.ts.map +1 -1
- package/dist/cjs/queries/swap/get-swap-quote.js +1 -1
- package/dist/cjs/staking/index.d.ts +2 -2
- package/dist/cjs/staking/index.d.ts.map +1 -1
- package/dist/cjs/staking/index.js +3 -1
- package/dist/cjs/swap/index.d.ts +2 -1
- package/dist/cjs/swap/index.d.ts.map +1 -1
- package/dist/cjs/swap/index.js +6 -0
- package/dist/cjs/types/connector.d.ts +0 -1
- package/dist/cjs/types/connector.d.ts.map +1 -1
- package/dist/cjs/types/primitives.d.ts +1 -1
- package/dist/cjs/types/primitives.d.ts.map +1 -1
- package/dist/cjs/utils/address/is-valid-address.d.ts +11 -0
- package/dist/cjs/utils/address/is-valid-address.d.ts.map +1 -0
- package/dist/cjs/utils/address/is-valid-address.js +38 -0
- package/dist/cjs/utils/address/to-bounceble-address.d.ts +11 -0
- package/dist/cjs/utils/address/to-bounceble-address.d.ts.map +1 -0
- package/dist/cjs/utils/address/to-bounceble-address.js +36 -0
- package/dist/cjs/utils/address/to-non-bounceble-address.d.ts +11 -0
- package/dist/cjs/utils/address/to-non-bounceble-address.d.ts.map +1 -0
- package/dist/cjs/utils/address/to-non-bounceble-address.js +36 -0
- package/dist/cjs/utils/amount/calc-fiat-value.d.ts +13 -0
- package/dist/cjs/utils/amount/calc-fiat-value.d.ts.map +1 -0
- package/dist/cjs/utils/amount/calc-fiat-value.js +22 -0
- package/dist/cjs/utils/amount/calc-fiat-value.test.d.ts +9 -0
- package/dist/cjs/utils/amount/calc-fiat-value.test.d.ts.map +1 -0
- package/dist/cjs/utils/amount/calc-fiat-value.test.js +39 -0
- package/dist/cjs/utils/amount/format-large-value.d.ts +9 -0
- package/dist/cjs/utils/amount/format-large-value.d.ts.map +1 -0
- package/dist/cjs/utils/amount/format-large-value.js +40 -0
- package/dist/cjs/utils/amount/format-large-value.test.d.ts +9 -0
- package/dist/cjs/utils/amount/format-large-value.test.d.ts.map +1 -0
- package/dist/cjs/utils/amount/format-large-value.test.js +43 -0
- package/dist/cjs/utils/amount/truncate-decimals.d.ts +9 -0
- package/dist/cjs/utils/amount/truncate-decimals.d.ts.map +1 -0
- package/dist/cjs/utils/amount/truncate-decimals.js +59 -0
- package/dist/cjs/utils/amount/truncate-decimals.test.d.ts +9 -0
- package/dist/cjs/utils/amount/truncate-decimals.test.d.ts.map +1 -0
- package/dist/cjs/utils/amount/truncate-decimals.test.js +83 -0
- package/dist/cjs/utils/balance/calc-max-spendable.d.ts +33 -0
- package/dist/cjs/utils/balance/calc-max-spendable.d.ts.map +1 -0
- package/dist/cjs/utils/balance/calc-max-spendable.js +29 -0
- package/dist/cjs/utils/balance/calc-max-spendable.test.d.ts +9 -0
- package/dist/cjs/utils/balance/calc-max-spendable.test.d.ts.map +1 -0
- package/dist/cjs/utils/balance/calc-max-spendable.test.js +38 -0
- package/dist/cjs/utils/balance/get-ton-shortfall.d.ts +58 -0
- package/dist/cjs/utils/balance/get-ton-shortfall.d.ts.map +1 -0
- package/dist/cjs/utils/balance/get-ton-shortfall.js +46 -0
- package/dist/cjs/utils/balance/get-ton-shortfall.test.d.ts +9 -0
- package/dist/cjs/utils/balance/get-ton-shortfall.test.d.ts.map +1 -0
- package/dist/cjs/utils/balance/get-ton-shortfall.test.js +133 -0
- package/dist/cjs/utils/functions/debounce.d.ts +80 -0
- package/dist/cjs/utils/functions/debounce.d.ts.map +1 -0
- package/dist/cjs/utils/functions/debounce.js +107 -0
- package/dist/cjs/utils/index.d.ts +10 -0
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +10 -0
- package/dist/cjs/utils/jetton/jetton-info.d.ts +2 -1
- package/dist/cjs/utils/jetton/jetton-info.d.ts.map +1 -1
- package/dist/cjs/utils/jetton/jetton-info.js +11 -1
- package/dist/cjs/utils/jetton/jetton-info.test.d.ts +9 -0
- package/dist/cjs/utils/jetton/jetton-info.test.d.ts.map +1 -0
- package/dist/cjs/utils/jetton/jetton-info.test.js +54 -0
- package/dist/cjs/utils/predicate/is-number.d.ts +9 -0
- package/dist/cjs/utils/predicate/is-number.d.ts.map +1 -0
- package/dist/cjs/utils/predicate/is-number.js +20 -0
- package/dist/cjs/utils/predicate/is-string.d.ts +1 -1
- package/dist/cjs/utils/predicate/is-string.d.ts.map +1 -1
- package/dist/cjs/utils/predicate/is-string.js +4 -3
- package/dist/esm/actions/index.d.ts +8 -0
- package/dist/esm/actions/index.d.ts.map +1 -1
- package/dist/esm/actions/index.js +8 -0
- package/dist/esm/actions/jettons/create-transfer-jetton-transaction.d.ts +1 -1
- package/dist/esm/actions/jettons/create-transfer-jetton-transaction.d.ts.map +1 -1
- package/dist/esm/actions/jettons/create-transfer-jetton-transaction.js +17 -5
- package/dist/esm/actions/jettons/get-jetton-balance.d.ts +1 -1
- package/dist/esm/actions/jettons/get-jetton-balance.d.ts.map +1 -1
- package/dist/esm/actions/jettons/get-jetton-balance.js +7 -2
- package/dist/esm/actions/jettons/get-jetton-info.d.ts.map +1 -1
- package/dist/esm/actions/jettons/get-jetton-info.js +15 -6
- package/dist/esm/actions/jettons/get-jetton-wallet-address.d.ts +1 -1
- package/dist/esm/actions/jettons/get-jetton-wallet-address.d.ts.map +1 -1
- package/dist/esm/actions/jettons/get-jetton-wallet-address.js +15 -4
- package/dist/esm/actions/nft/get-nft.d.ts +1 -1
- package/dist/esm/actions/nft/get-nft.d.ts.map +1 -1
- package/dist/esm/actions/staking/get-staking-provider-metadata.d.ts +19 -0
- package/dist/esm/actions/staking/get-staking-provider-metadata.d.ts.map +1 -0
- package/dist/esm/actions/staking/get-staking-provider-metadata.js +14 -0
- package/dist/esm/actions/staking/get-staking-provider.d.ts +21 -0
- package/dist/esm/actions/staking/get-staking-provider.d.ts.map +1 -0
- package/dist/esm/actions/staking/get-staking-provider.js +13 -0
- package/dist/esm/actions/staking/get-staking-providers.d.ts +3 -2
- package/dist/esm/actions/staking/get-staking-providers.d.ts.map +1 -1
- package/dist/esm/actions/staking/get-staking-providers.js +2 -2
- package/dist/esm/actions/staking/set-default-staking-provider.d.ts +18 -0
- package/dist/esm/actions/staking/set-default-staking-provider.d.ts.map +1 -0
- package/dist/esm/actions/staking/set-default-staking-provider.js +14 -0
- package/dist/esm/actions/staking/watch-staking-providers.d.ts +17 -0
- package/dist/esm/actions/staking/watch-staking-providers.d.ts.map +1 -0
- package/dist/esm/actions/staking/watch-staking-providers.js +24 -0
- package/dist/esm/actions/swap/get-swap-provider.d.ts +15 -0
- package/dist/esm/actions/swap/get-swap-provider.d.ts.map +1 -0
- package/dist/esm/actions/swap/get-swap-provider.js +10 -0
- package/dist/esm/actions/swap/get-swap-providers.d.ts +15 -0
- package/dist/esm/actions/swap/get-swap-providers.d.ts.map +1 -0
- package/dist/esm/actions/swap/get-swap-providers.js +13 -0
- package/dist/esm/actions/swap/get-swap-quote.d.ts.map +1 -1
- package/dist/esm/actions/swap/get-swap-quote.js +6 -1
- package/dist/esm/actions/swap/set-default-swap-provider.d.ts +18 -0
- package/dist/esm/actions/swap/set-default-swap-provider.d.ts.map +1 -0
- package/dist/esm/actions/swap/set-default-swap-provider.js +14 -0
- package/dist/esm/actions/swap/watch-swap-providers.d.ts +17 -0
- package/dist/esm/actions/swap/watch-swap-providers.d.ts.map +1 -0
- package/dist/esm/actions/swap/watch-swap-providers.js +25 -0
- package/dist/esm/connectors/tonconnect/connectors/ton-connect-connector.js +2 -2
- package/dist/esm/core/app-kit/constants/events.d.ts +0 -6
- package/dist/esm/core/app-kit/constants/events.d.ts.map +1 -1
- package/dist/esm/core/app-kit/constants/events.js +0 -6
- package/dist/esm/core/app-kit/index.d.ts +2 -2
- package/dist/esm/core/app-kit/index.d.ts.map +1 -1
- package/dist/esm/core/app-kit/index.js +1 -1
- package/dist/esm/core/app-kit/services/app-kit.d.ts +3 -1
- package/dist/esm/core/app-kit/services/app-kit.d.ts.map +1 -1
- package/dist/esm/core/app-kit/services/app-kit.js +4 -2
- package/dist/esm/core/app-kit/types/config.d.ts +4 -2
- package/dist/esm/core/app-kit/types/config.d.ts.map +1 -1
- package/dist/esm/core/app-kit/types/events.d.ts +2 -7
- package/dist/esm/core/app-kit/types/events.d.ts.map +1 -1
- package/dist/esm/core/cache/adapters/lru-app-kit-cache.d.ts +20 -0
- package/dist/esm/core/cache/adapters/lru-app-kit-cache.d.ts.map +1 -0
- package/dist/esm/core/cache/adapters/lru-app-kit-cache.js +28 -0
- package/dist/esm/core/cache/adapters/lru-app-kit-cache.test.d.ts +9 -0
- package/dist/esm/core/cache/adapters/lru-app-kit-cache.test.d.ts.map +1 -0
- package/dist/esm/core/cache/adapters/lru-app-kit-cache.test.js +66 -0
- package/dist/esm/core/cache/index.d.ts +11 -0
- package/dist/esm/core/cache/index.d.ts.map +1 -0
- package/dist/esm/core/cache/index.js +9 -0
- package/dist/esm/core/cache/types/app-kit-cache.d.ts +14 -0
- package/dist/esm/core/cache/types/app-kit-cache.d.ts.map +1 -0
- package/dist/esm/core/cache/types/app-kit-cache.js +8 -0
- package/dist/esm/core/cache/utils/get-cache-key.d.ts +9 -0
- package/dist/esm/core/cache/utils/get-cache-key.d.ts.map +1 -0
- package/dist/esm/core/cache/utils/get-cache-key.js +8 -0
- package/dist/esm/core/cache/utils/get-cache-key.test.d.ts +9 -0
- package/dist/esm/core/cache/utils/get-cache-key.test.d.ts.map +1 -0
- package/dist/esm/core/cache/utils/get-cache-key.test.js +28 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/queries/balances/get-balance-by-address.d.ts.map +1 -1
- package/dist/esm/queries/balances/get-balance-by-address.js +10 -4
- package/dist/esm/queries/index.d.ts +0 -1
- package/dist/esm/queries/index.d.ts.map +1 -1
- package/dist/esm/queries/index.js +0 -1
- package/dist/esm/queries/jettons/get-jetton-balance-by-address.d.ts.map +1 -1
- package/dist/esm/queries/jettons/get-jetton-balance-by-address.js +12 -12
- package/dist/esm/queries/jettons/get-jetton-info.d.ts.map +1 -1
- package/dist/esm/queries/jettons/get-jetton-info.js +6 -2
- package/dist/esm/queries/jettons/get-jetton-wallet-address.d.ts.map +1 -1
- package/dist/esm/queries/jettons/get-jetton-wallet-address.js +7 -2
- package/dist/esm/queries/jettons/get-jettons-by-address.d.ts.map +1 -1
- package/dist/esm/queries/jettons/get-jettons-by-address.js +10 -4
- package/dist/esm/queries/nft/get-nft.d.ts +1 -1
- package/dist/esm/queries/nft/get-nft.d.ts.map +1 -1
- package/dist/esm/queries/nft/get-nft.js +6 -2
- package/dist/esm/queries/nft/get-nfts-by-address.d.ts.map +1 -1
- package/dist/esm/queries/nft/get-nfts-by-address.js +6 -2
- package/dist/esm/queries/staking/get-staked-balance.d.ts +1 -1
- package/dist/esm/queries/staking/get-staked-balance.d.ts.map +1 -1
- package/dist/esm/queries/staking/get-staked-balance.js +8 -2
- package/dist/esm/queries/staking/get-staking-provider-info.d.ts +1 -1
- package/dist/esm/queries/staking/get-staking-provider-info.d.ts.map +1 -1
- package/dist/esm/queries/staking/get-staking-provider-info.js +4 -2
- package/dist/esm/queries/staking/get-staking-quote.d.ts +1 -1
- package/dist/esm/queries/staking/get-staking-quote.d.ts.map +1 -1
- package/dist/esm/queries/staking/get-staking-quote.js +9 -3
- package/dist/esm/queries/swap/get-swap-quote.d.ts.map +1 -1
- package/dist/esm/queries/swap/get-swap-quote.js +1 -1
- package/dist/esm/staking/index.d.ts +2 -2
- package/dist/esm/staking/index.d.ts.map +1 -1
- package/dist/esm/staking/index.js +1 -1
- package/dist/esm/swap/index.d.ts +2 -1
- package/dist/esm/swap/index.d.ts.map +1 -1
- package/dist/esm/swap/index.js +1 -1
- package/dist/esm/types/connector.d.ts +0 -1
- package/dist/esm/types/connector.d.ts.map +1 -1
- package/dist/esm/types/primitives.d.ts +1 -1
- package/dist/esm/types/primitives.d.ts.map +1 -1
- package/dist/esm/utils/address/is-valid-address.d.ts +11 -0
- package/dist/esm/utils/address/is-valid-address.d.ts.map +1 -0
- package/dist/esm/utils/address/is-valid-address.js +33 -0
- package/dist/esm/utils/address/to-bounceble-address.d.ts +11 -0
- package/dist/esm/utils/address/to-bounceble-address.d.ts.map +1 -0
- package/dist/esm/utils/address/to-bounceble-address.js +31 -0
- package/dist/esm/utils/address/to-non-bounceble-address.d.ts +11 -0
- package/dist/esm/utils/address/to-non-bounceble-address.d.ts.map +1 -0
- package/dist/esm/utils/address/to-non-bounceble-address.js +31 -0
- package/dist/esm/utils/amount/calc-fiat-value.d.ts +13 -0
- package/dist/esm/utils/amount/calc-fiat-value.d.ts.map +1 -0
- package/dist/esm/utils/amount/calc-fiat-value.js +19 -0
- package/dist/esm/utils/amount/calc-fiat-value.test.d.ts +9 -0
- package/dist/esm/utils/amount/calc-fiat-value.test.d.ts.map +1 -0
- package/dist/esm/utils/amount/calc-fiat-value.test.js +37 -0
- package/dist/esm/utils/amount/format-large-value.d.ts +9 -0
- package/dist/esm/utils/amount/format-large-value.d.ts.map +1 -0
- package/dist/esm/utils/amount/format-large-value.js +36 -0
- package/dist/esm/utils/amount/format-large-value.test.d.ts +9 -0
- package/dist/esm/utils/amount/format-large-value.test.d.ts.map +1 -0
- package/dist/esm/utils/amount/format-large-value.test.js +41 -0
- package/dist/esm/utils/amount/truncate-decimals.d.ts +9 -0
- package/dist/esm/utils/amount/truncate-decimals.d.ts.map +1 -0
- package/dist/esm/utils/amount/truncate-decimals.js +55 -0
- package/dist/esm/utils/amount/truncate-decimals.test.d.ts +9 -0
- package/dist/esm/utils/amount/truncate-decimals.test.d.ts.map +1 -0
- package/dist/esm/utils/amount/truncate-decimals.test.js +81 -0
- package/dist/esm/utils/balance/calc-max-spendable.d.ts +33 -0
- package/dist/esm/utils/balance/calc-max-spendable.d.ts.map +1 -0
- package/dist/esm/utils/balance/calc-max-spendable.js +25 -0
- package/dist/esm/utils/balance/calc-max-spendable.test.d.ts +9 -0
- package/dist/esm/utils/balance/calc-max-spendable.test.d.ts.map +1 -0
- package/dist/esm/utils/balance/calc-max-spendable.test.js +36 -0
- package/dist/esm/utils/balance/get-ton-shortfall.d.ts +58 -0
- package/dist/esm/utils/balance/get-ton-shortfall.d.ts.map +1 -0
- package/dist/esm/utils/balance/get-ton-shortfall.js +42 -0
- package/dist/esm/utils/balance/get-ton-shortfall.test.d.ts +9 -0
- package/dist/esm/utils/balance/get-ton-shortfall.test.d.ts.map +1 -0
- package/dist/esm/utils/balance/get-ton-shortfall.test.js +131 -0
- package/dist/esm/utils/functions/debounce.d.ts +80 -0
- package/dist/esm/utils/functions/debounce.d.ts.map +1 -0
- package/dist/esm/utils/functions/debounce.js +103 -0
- package/dist/esm/utils/index.d.ts +10 -0
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +10 -0
- package/dist/esm/utils/jetton/jetton-info.d.ts +2 -1
- package/dist/esm/utils/jetton/jetton-info.d.ts.map +1 -1
- package/dist/esm/utils/jetton/jetton-info.js +9 -0
- package/dist/esm/utils/jetton/jetton-info.test.d.ts +9 -0
- package/dist/esm/utils/jetton/jetton-info.test.d.ts.map +1 -0
- package/dist/esm/utils/jetton/jetton-info.test.js +52 -0
- package/dist/esm/utils/predicate/is-number.d.ts +9 -0
- package/dist/esm/utils/predicate/is-number.d.ts.map +1 -0
- package/dist/esm/utils/predicate/is-number.js +16 -0
- package/dist/esm/utils/predicate/is-string.d.ts +1 -1
- package/dist/esm/utils/predicate/is-string.d.ts.map +1 -1
- package/dist/esm/utils/predicate/is-string.js +2 -2
- package/docs/actions.md +57 -9
- package/docs/swap.md +4 -4
- package/package.json +4 -3
- package/src/actions/index.ts +32 -0
- package/src/actions/jettons/create-transfer-jetton-transaction.ts +22 -6
- package/src/actions/jettons/get-jetton-balance.ts +10 -3
- package/src/actions/jettons/get-jetton-info.ts +18 -6
- package/src/actions/jettons/get-jetton-wallet-address.ts +19 -5
- package/src/actions/nft/get-nft.ts +1 -1
- package/src/actions/staking/get-staking-provider-metadata.ts +32 -0
- package/src/actions/staking/get-staking-provider.ts +30 -0
- package/src/actions/staking/get-staking-providers.ts +5 -3
- package/src/actions/staking/set-default-staking-provider.ts +26 -0
- package/src/actions/staking/watch-staking-providers.ts +39 -0
- package/src/actions/swap/get-swap-provider.ts +21 -0
- package/src/actions/swap/get-swap-providers.ts +20 -0
- package/src/actions/swap/get-swap-quote.ts +7 -1
- package/src/actions/swap/set-default-swap-provider.ts +26 -0
- package/src/actions/swap/watch-swap-providers.ts +38 -0
- package/src/connectors/tonconnect/connectors/ton-connect-connector.ts +2 -2
- package/src/core/app-kit/constants/events.ts +0 -7
- package/src/core/app-kit/index.ts +1 -2
- package/src/core/app-kit/services/app-kit.ts +7 -3
- package/src/core/app-kit/types/config.ts +4 -2
- package/src/core/app-kit/types/events.ts +2 -10
- package/src/core/cache/adapters/lru-app-kit-cache.test.ts +77 -0
- package/src/core/cache/adapters/lru-app-kit-cache.ts +38 -0
- package/src/core/cache/index.ts +12 -0
- package/src/core/cache/types/app-kit-cache.ts +14 -0
- package/src/core/cache/utils/get-cache-key.test.ts +34 -0
- package/src/core/cache/utils/get-cache-key.ts +12 -0
- package/src/index.ts +1 -0
- package/src/queries/balances/get-balance-by-address.ts +11 -4
- package/src/queries/index.ts +0 -6
- package/src/queries/jettons/get-jetton-balance-by-address.ts +13 -12
- package/src/queries/jettons/get-jetton-info.ts +6 -2
- package/src/queries/jettons/get-jetton-wallet-address.ts +7 -2
- package/src/queries/jettons/get-jettons-by-address.ts +18 -4
- package/src/queries/nft/get-nft.ts +7 -3
- package/src/queries/nft/get-nfts-by-address.ts +6 -2
- package/src/queries/staking/get-staked-balance.ts +10 -3
- package/src/queries/staking/get-staking-provider-info.ts +5 -2
- package/src/queries/staking/get-staking-quote.ts +13 -4
- package/src/queries/swap/get-swap-quote.ts +3 -1
- package/src/staking/index.ts +10 -1
- package/src/swap/index.ts +2 -4
- package/src/types/connector.ts +0 -1
- package/src/types/primitives.ts +1 -1
- package/src/utils/address/is-valid-address.ts +40 -0
- package/src/utils/address/to-bounceble-address.ts +35 -0
- package/src/utils/address/to-non-bounceble-address.ts +35 -0
- package/src/utils/amount/calc-fiat-value.test.ts +46 -0
- package/src/utils/amount/calc-fiat-value.ts +18 -0
- package/src/utils/amount/format-large-value.test.ts +50 -0
- package/src/utils/amount/format-large-value.ts +43 -0
- package/src/utils/amount/truncate-decimals.test.ts +97 -0
- package/src/utils/amount/truncate-decimals.ts +56 -0
- package/src/utils/balance/calc-max-spendable.test.ts +46 -0
- package/src/utils/balance/calc-max-spendable.ts +44 -0
- package/src/utils/balance/get-ton-shortfall.test.ts +148 -0
- package/src/utils/balance/get-ton-shortfall.ts +82 -0
- package/src/utils/functions/debounce.ts +169 -0
- package/src/utils/index.ts +10 -0
- package/src/utils/jetton/jetton-info.test.ts +65 -0
- package/src/utils/jetton/jetton-info.ts +12 -1
- package/src/utils/predicate/is-number.ts +19 -0
- package/src/utils/predicate/is-string.ts +2 -2
- package/dist/cjs/queries/staking/get-staking-providers.d.ts +0 -20
- package/dist/cjs/queries/staking/get-staking-providers.d.ts.map +0 -1
- package/dist/cjs/queries/staking/get-staking-providers.js +0 -25
- package/dist/esm/queries/staking/get-staking-providers.d.ts +0 -20
- package/dist/esm/queries/staking/get-staking-providers.d.ts.map +0 -1
- package/dist/esm/queries/staking/get-staking-providers.js +0 -20
- package/src/queries/staking/get-staking-providers.ts +0 -52
package/dist/esm/swap/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export { DefiError, SwapError, SwapProvider, SwapManager } from '@ton/walletkit';
|
|
9
|
+
export type { SwapToken, TokenAmount, SwapParams, SwapAPI, SwapQuote, SwapQuoteParams, DefiManagerAPI, DefiProvider, } from '@ton/walletkit';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/swap/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,YAAY,EACR,SAAS,EACT,WAAW,EACX,UAAU,EACV,OAAO,EACP,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/swap/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEjF,YAAY,EACR,SAAS,EACT,WAAW,EACX,UAAU,EACV,OAAO,EACP,SAAS,EACT,eAAe,EACf,cAAc,EACd,YAAY,GACf,MAAM,gBAAgB,CAAC"}
|
package/dist/esm/swap/index.js
CHANGED
|
@@ -37,7 +37,6 @@ export interface ConnectorMetadata {
|
|
|
37
37
|
export interface ConnectorFactoryContext {
|
|
38
38
|
networkManager: AppKitNetworkManager;
|
|
39
39
|
eventEmitter: AppKitEmitter;
|
|
40
|
-
ssr?: boolean;
|
|
41
40
|
}
|
|
42
41
|
/** Factory function that creates a connector from context */
|
|
43
42
|
export type ConnectorFactory = (ctx: ConnectorFactoryContext) => Connector;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../../src/types/connector.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IAErC,kCAAkC;IAClC,OAAO,IAAI,IAAI,CAAC;IAEhB,uBAAuB;IACvB,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhD,0BAA0B;IAC1B,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAElC,4BAA4B;IAC5B,mBAAmB,IAAI,eAAe,EAAE,CAAC;CAC5C;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACpC,cAAc,EAAE,oBAAoB,CAAC;IACrC,YAAY,EAAE,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../../src/types/connector.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IAErC,kCAAkC;IAClC,OAAO,IAAI,IAAI,CAAC;IAEhB,uBAAuB;IACvB,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhD,0BAA0B;IAC1B,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAElC,4BAA4B;IAC5B,mBAAmB,IAAI,eAAe,EAAE,CAAC;CAC5C;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACpC,cAAc,EAAE,oBAAoB,CAAC;IACrC,YAAY,EAAE,aAAa,CAAC;CAC/B;AAED,6DAA6D;AAC7D,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,uBAAuB,KAAK,SAAS,CAAC;AAE3E,yDAAyD;AACzD,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,gBAAgB,CAAC;AAE1D,oDAAoD;AACpD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAE3E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../../src/types/primitives.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../../src/types/primitives.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { UserFriendlyAddress } from '../../types/primitives';
|
|
9
|
+
export declare const isValidAddress: (address: unknown) => address is string;
|
|
10
|
+
export declare const isFriendlyTonAddress: (address: unknown) => address is UserFriendlyAddress;
|
|
11
|
+
//# sourceMappingURL=is-valid-address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-valid-address.d.ts","sourceRoot":"","sources":["../../../../src/utils/address/is-valid-address.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,eAAO,MAAM,cAAc,GAAI,SAAS,OAAO,KAAG,OAAO,IAAI,MAY5D,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,SAAS,OAAO,KAAG,OAAO,IAAI,mBAYlE,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { Address } from '@ton/core';
|
|
9
|
+
import { isString } from '../predicate/is-string';
|
|
10
|
+
export const isValidAddress = (address) => {
|
|
11
|
+
if (typeof address !== 'string') {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
Address.parse(address);
|
|
16
|
+
}
|
|
17
|
+
catch (_) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
};
|
|
22
|
+
export const isFriendlyTonAddress = (address) => {
|
|
23
|
+
if (!isString(address)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
Address.parseFriendly(address);
|
|
28
|
+
}
|
|
29
|
+
catch (_) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { Address } from '@ton/core';
|
|
9
|
+
export declare const toBounceableAddress: (address?: Address | string | null) => string;
|
|
10
|
+
export declare const tryToBounceableAddress: (address?: Address | string | null) => string | undefined;
|
|
11
|
+
//# sourceMappingURL=to-bounceble-address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-bounceble-address.d.ts","sourceRoot":"","sources":["../../../../src/utils/address/to-bounceble-address.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,mBAAmB,GAAI,UAAU,OAAO,GAAG,MAAM,GAAG,IAAI,KAAG,MAcvE,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,UAAU,OAAO,GAAG,MAAM,GAAG,IAAI,KAAG,MAAM,GAAG,SAMnF,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { Address } from '@ton/core';
|
|
9
|
+
import { getErrorMessage } from '../errors/get-error-message';
|
|
10
|
+
export const toBounceableAddress = (address) => {
|
|
11
|
+
if (!address) {
|
|
12
|
+
throw new Error(`Address is empty`);
|
|
13
|
+
}
|
|
14
|
+
if (address instanceof Address) {
|
|
15
|
+
return address.toString({ bounceable: true });
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
return Address.parse(address).toString({ bounceable: true });
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
throw new Error(`Can not convert to bounceble address from "${address}". Error: ${getErrorMessage(e)}`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export const tryToBounceableAddress = (address) => {
|
|
25
|
+
try {
|
|
26
|
+
return toBounceableAddress(address);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { Address } from '@ton/core';
|
|
9
|
+
export declare const toNonBounceableAddress: (address?: Address | string | null) => string;
|
|
10
|
+
export declare const tryToNonBounceableAddress: (address?: Address | string | null) => string | undefined;
|
|
11
|
+
//# sourceMappingURL=to-non-bounceble-address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-non-bounceble-address.d.ts","sourceRoot":"","sources":["../../../../src/utils/address/to-non-bounceble-address.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,eAAO,MAAM,sBAAsB,GAAI,UAAU,OAAO,GAAG,MAAM,GAAG,IAAI,KAAG,MAc1E,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,UAAU,OAAO,GAAG,MAAM,GAAG,IAAI,KAAG,MAAM,GAAG,SAMtF,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { Address } from '@ton/core';
|
|
9
|
+
import { getErrorMessage } from '../errors/get-error-message';
|
|
10
|
+
export const toNonBounceableAddress = (address) => {
|
|
11
|
+
if (!address) {
|
|
12
|
+
throw new Error(`Address is empty`);
|
|
13
|
+
}
|
|
14
|
+
if (address instanceof Address) {
|
|
15
|
+
return address.toString({ bounceable: false });
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
return Address.parse(address).toString({ bounceable: false });
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
throw new Error(`Can not convert to non-bounceable address from "${address}". Error: ${getErrorMessage(e)}`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export const tryToNonBounceableAddress = (address) => {
|
|
25
|
+
try {
|
|
26
|
+
return toNonBounceableAddress(address);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Calculates the fiat value of a token amount.
|
|
10
|
+
* Returns null when rate is unavailable or amount is zero/invalid.
|
|
11
|
+
*/
|
|
12
|
+
export declare function calcFiatValue(amount: string, rate: string | undefined): string;
|
|
13
|
+
//# sourceMappingURL=calc-fiat-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calc-fiat-value.d.ts","sourceRoot":"","sources":["../../../../src/utils/amount/calc-fiat-value.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAK9E"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Calculates the fiat value of a token amount.
|
|
10
|
+
* Returns null when rate is unavailable or amount is zero/invalid.
|
|
11
|
+
*/
|
|
12
|
+
export function calcFiatValue(amount, rate) {
|
|
13
|
+
if (!rate)
|
|
14
|
+
return '0';
|
|
15
|
+
const num = parseFloat(amount);
|
|
16
|
+
if (!num || num <= 0)
|
|
17
|
+
return '0';
|
|
18
|
+
return Number((num * parseFloat(rate)).toFixed(10)).toString();
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calc-fiat-value.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/amount/calc-fiat-value.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { describe, it, expect } from 'vitest';
|
|
9
|
+
import { calcFiatValue } from './calc-fiat-value';
|
|
10
|
+
describe('calcFiatValue', () => {
|
|
11
|
+
it('should return 0 when rate is undefined', () => {
|
|
12
|
+
expect(calcFiatValue('100', undefined)).toBe('0');
|
|
13
|
+
});
|
|
14
|
+
it('should return 0 when rate is 0', () => {
|
|
15
|
+
expect(calcFiatValue('100', '0')).toBe('0');
|
|
16
|
+
});
|
|
17
|
+
it('should return 0 when amount is 0', () => {
|
|
18
|
+
expect(calcFiatValue('0', '1.5')).toBe('0');
|
|
19
|
+
});
|
|
20
|
+
it('should return 0 when amount is negative', () => {
|
|
21
|
+
expect(calcFiatValue('-10', '1.5')).toBe('0');
|
|
22
|
+
});
|
|
23
|
+
it('should return 0 when amount is not a valid number', () => {
|
|
24
|
+
expect(calcFiatValue('abc', '1.5')).toBe('0');
|
|
25
|
+
expect(calcFiatValue('', '1.5')).toBe('0');
|
|
26
|
+
});
|
|
27
|
+
it('should calculate fiat value without rounding', () => {
|
|
28
|
+
expect(calcFiatValue('100', '1.5')).toBe('150');
|
|
29
|
+
expect(calcFiatValue('1', '0.001')).toBe('0.001');
|
|
30
|
+
expect(calcFiatValue('3', '1.005')).toBe('3.015');
|
|
31
|
+
});
|
|
32
|
+
it('should handle decimal amounts without rounding', () => {
|
|
33
|
+
expect(calcFiatValue('0.5', '2')).toBe('1');
|
|
34
|
+
expect(calcFiatValue('1.23456', '100')).toBe('123.456');
|
|
35
|
+
expect(calcFiatValue('2.996876', '1')).toBe('2.996876');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare const formatLargeValue: (amount: string, decimals?: number, minimumFractionDigits?: number) => string;
|
|
9
|
+
//# sourceMappingURL=format-large-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-large-value.d.ts","sourceRoot":"","sources":["../../../../src/utils/amount/format-large-value.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,EAAE,WAAU,MAAU,EAAE,wBAAuB,MAAU,KAAG,MAkC1G,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export const formatLargeValue = (amount, decimals = 2, minimumFractionDigits = 0) => {
|
|
9
|
+
const cleanAmount = amount.toString().replace(/\s/g, '');
|
|
10
|
+
const intPart = cleanAmount.split('.')[0] || '0';
|
|
11
|
+
// value > 100 000 000 000 000 => 100 T
|
|
12
|
+
if (intPart.length > 12) {
|
|
13
|
+
const value = Number(intPart.slice(0, -10)) / 100;
|
|
14
|
+
return `${value.toLocaleString('en-US')}T`;
|
|
15
|
+
}
|
|
16
|
+
// value > 100 000 000 000 => 100 B
|
|
17
|
+
if (intPart.length > 9) {
|
|
18
|
+
const value = Number(intPart.slice(0, -7)) / 100;
|
|
19
|
+
return `${value.toLocaleString('en-US')}B`;
|
|
20
|
+
}
|
|
21
|
+
// value > 10 000 000 => 10 M
|
|
22
|
+
if (intPart.length > 6) {
|
|
23
|
+
const value = Number(intPart.slice(0, -4)) / 100;
|
|
24
|
+
return `${value.toLocaleString('en-US')}M`;
|
|
25
|
+
}
|
|
26
|
+
const value = parseFloat(cleanAmount);
|
|
27
|
+
if (isNaN(value)) {
|
|
28
|
+
return '0';
|
|
29
|
+
}
|
|
30
|
+
const factor = Math.pow(10, decimals);
|
|
31
|
+
const truncated = Math.floor(value * factor) / factor;
|
|
32
|
+
return truncated.toLocaleString('en-US', {
|
|
33
|
+
minimumFractionDigits,
|
|
34
|
+
maximumFractionDigits: decimals,
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-large-value.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/amount/format-large-value.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { describe, it, expect } from 'vitest';
|
|
9
|
+
import { formatLargeValue } from './format-large-value';
|
|
10
|
+
describe('formatLargeValue', () => {
|
|
11
|
+
it('should format trillion values', () => {
|
|
12
|
+
expect(formatLargeValue('1000000000000')).toBe('1T');
|
|
13
|
+
expect(formatLargeValue('1230000000000')).toBe('1.23T');
|
|
14
|
+
expect(formatLargeValue('12345678901234')).toBe('12.34T');
|
|
15
|
+
});
|
|
16
|
+
it('should format billion values', () => {
|
|
17
|
+
expect(formatLargeValue('1000000000')).toBe('1B');
|
|
18
|
+
expect(formatLargeValue('1230000000')).toBe('1.23B');
|
|
19
|
+
});
|
|
20
|
+
it('should format million values', () => {
|
|
21
|
+
expect(formatLargeValue('1000000')).toBe('1M');
|
|
22
|
+
expect(formatLargeValue('1230000')).toBe('1.23M');
|
|
23
|
+
});
|
|
24
|
+
it('should format smaller values using toLocaleString', () => {
|
|
25
|
+
expect(formatLargeValue('1234.56')).toBe('1,234.56');
|
|
26
|
+
expect(formatLargeValue('100')).toBe('100');
|
|
27
|
+
expect(formatLargeValue('0')).toBe('0');
|
|
28
|
+
});
|
|
29
|
+
it('should handle spaces and formatting', () => {
|
|
30
|
+
expect(formatLargeValue('1 000 000')).toBe('1M');
|
|
31
|
+
});
|
|
32
|
+
it('should respect decimals for small values', () => {
|
|
33
|
+
expect(formatLargeValue('1234.5678', 4)).toBe('1,234.5678');
|
|
34
|
+
expect(formatLargeValue('1234.5678', 2)).toBe('1,234.56');
|
|
35
|
+
});
|
|
36
|
+
it('should round down (floor) fractional values', () => {
|
|
37
|
+
expect(formatLargeValue('2.996848', 2)).toBe('2.99');
|
|
38
|
+
expect(formatLargeValue('2.996848', 6)).toBe('2.996848');
|
|
39
|
+
expect(formatLargeValue('0.9999', 2)).toBe('0.99');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare const truncateDecimals: (value: string | number, maxDecimals: number) => string;
|
|
9
|
+
//# sourceMappingURL=truncate-decimals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncate-decimals.d.ts","sourceRoot":"","sources":["../../../../src/utils/amount/truncate-decimals.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA+BH,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,GAAG,MAAM,EAAE,aAAa,MAAM,KAAG,MAkB9E,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Converts a number to a plain decimal string, expanding scientific notation
|
|
10
|
+
* like "1.23e-9" into "0.00000000123".
|
|
11
|
+
*/
|
|
12
|
+
const toPlainDecimalString = (num) => {
|
|
13
|
+
const str = num.toString();
|
|
14
|
+
if (!str.includes('e') && !str.includes('E'))
|
|
15
|
+
return str;
|
|
16
|
+
const [base = '0', exponent = '0'] = str.split(/[eE]/);
|
|
17
|
+
const exp = Number(exponent);
|
|
18
|
+
const isNegative = base.startsWith('-');
|
|
19
|
+
const absBase = isNegative ? base.slice(1) : base;
|
|
20
|
+
const [intPart, decPart = ''] = absBase.split('.');
|
|
21
|
+
let result;
|
|
22
|
+
if (exp < 0) {
|
|
23
|
+
result = '0.' + '0'.repeat(Math.abs(exp) - 1) + intPart + decPart;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const addZeros = exp - decPart.length;
|
|
27
|
+
if (addZeros >= 0) {
|
|
28
|
+
result = intPart + decPart + '0'.repeat(addZeros);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
result = intPart + decPart.slice(0, exp) + '.' + decPart.slice(exp);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return isNegative ? '-' + result : result;
|
|
35
|
+
};
|
|
36
|
+
export const truncateDecimals = (value, maxDecimals) => {
|
|
37
|
+
let strValue;
|
|
38
|
+
if (typeof value === 'number') {
|
|
39
|
+
strValue = toPlainDecimalString(value);
|
|
40
|
+
}
|
|
41
|
+
else if (value.includes('e') || value.includes('E')) {
|
|
42
|
+
const num = Number(value);
|
|
43
|
+
if (Number.isNaN(num))
|
|
44
|
+
return value;
|
|
45
|
+
strValue = toPlainDecimalString(num);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
strValue = value;
|
|
49
|
+
}
|
|
50
|
+
const dotIndex = strValue.indexOf('.');
|
|
51
|
+
if (dotIndex === -1)
|
|
52
|
+
return strValue;
|
|
53
|
+
const result = strValue.slice(0, dotIndex + 1 + maxDecimals);
|
|
54
|
+
return result.endsWith('.') ? result.slice(0, -1) : result;
|
|
55
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncate-decimals.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/amount/truncate-decimals.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { describe, expect, it } from 'vitest';
|
|
9
|
+
import { truncateDecimals } from './truncate-decimals';
|
|
10
|
+
describe('truncateDecimals', () => {
|
|
11
|
+
it('should return integers unchanged', () => {
|
|
12
|
+
expect(truncateDecimals('123', 2)).toBe('123');
|
|
13
|
+
expect(truncateDecimals('0', 5)).toBe('0');
|
|
14
|
+
});
|
|
15
|
+
it('should truncate decimals exceeding maxDecimals', () => {
|
|
16
|
+
expect(truncateDecimals('1.23456', 2)).toBe('1.23');
|
|
17
|
+
expect(truncateDecimals('1.23456', 4)).toBe('1.2345');
|
|
18
|
+
expect(truncateDecimals('0.123456789', 9)).toBe('0.123456789');
|
|
19
|
+
expect(truncateDecimals('0.1234567890', 9)).toBe('0.123456789');
|
|
20
|
+
});
|
|
21
|
+
it('should return value unchanged when decimals are within limit', () => {
|
|
22
|
+
expect(truncateDecimals('1.23', 5)).toBe('1.23');
|
|
23
|
+
expect(truncateDecimals('1.2', 2)).toBe('1.2');
|
|
24
|
+
expect(truncateDecimals('5.0', 1)).toBe('5.0');
|
|
25
|
+
});
|
|
26
|
+
it('should handle maxDecimals of 0', () => {
|
|
27
|
+
expect(truncateDecimals('1.999', 0)).toBe('1');
|
|
28
|
+
expect(truncateDecimals('42.1', 0)).toBe('42');
|
|
29
|
+
});
|
|
30
|
+
it('should strip trailing dot', () => {
|
|
31
|
+
expect(truncateDecimals('1.', 3)).toBe('1');
|
|
32
|
+
expect(truncateDecimals('1.', 0)).toBe('1');
|
|
33
|
+
});
|
|
34
|
+
it('should handle empty string', () => {
|
|
35
|
+
expect(truncateDecimals('', 2)).toBe('');
|
|
36
|
+
});
|
|
37
|
+
it('should handle number input', () => {
|
|
38
|
+
expect(truncateDecimals(1.23456, 2)).toBe('1.23');
|
|
39
|
+
expect(truncateDecimals(42, 3)).toBe('42');
|
|
40
|
+
expect(truncateDecimals(0.1, 5)).toBe('0.1');
|
|
41
|
+
expect(truncateDecimals(3.14159, 0)).toBe('3');
|
|
42
|
+
});
|
|
43
|
+
it('should handle scientific notation strings', () => {
|
|
44
|
+
expect(truncateDecimals('1.095492908209088e-9', 9)).toBe('0.000000001');
|
|
45
|
+
expect(truncateDecimals('5e-7', 9)).toBe('0.0000005');
|
|
46
|
+
});
|
|
47
|
+
it('should handle numbers that produce scientific notation', () => {
|
|
48
|
+
const tiny = 0.000000001 * 1.095492908209088; // 1.095492908209088e-9
|
|
49
|
+
expect(truncateDecimals(tiny, 9)).toBe('0.000000001');
|
|
50
|
+
});
|
|
51
|
+
it('should handle negative numbers and negative scientific notation', () => {
|
|
52
|
+
expect(truncateDecimals('-1.23456', 2)).toBe('-1.23');
|
|
53
|
+
expect(truncateDecimals('-5e-7', 9)).toBe('-0.0000005');
|
|
54
|
+
expect(truncateDecimals(-0.0000005, 9)).toBe('-0.0000005');
|
|
55
|
+
});
|
|
56
|
+
it('should handle scientific notation with positive exponents', () => {
|
|
57
|
+
expect(truncateDecimals('1.2345e2', 2)).toBe('123.45');
|
|
58
|
+
expect(truncateDecimals('1.2345e+2', 0)).toBe('123');
|
|
59
|
+
expect(truncateDecimals('5.2e9', 0)).toBe('5200000000');
|
|
60
|
+
expect(truncateDecimals('-1.23e+9', 0)).toBe('-1230000000');
|
|
61
|
+
});
|
|
62
|
+
it('should handle extreme scientific exponents', () => {
|
|
63
|
+
expect(truncateDecimals('1e-100', 100)).toBe('0.' + '0'.repeat(99) + '1');
|
|
64
|
+
expect(truncateDecimals('1e21', 0)).toBe('1000000000000000000000');
|
|
65
|
+
});
|
|
66
|
+
it('should handle NaN and Infinity', () => {
|
|
67
|
+
expect(truncateDecimals(NaN, 2)).toBe('NaN');
|
|
68
|
+
expect(truncateDecimals(Infinity, 2)).toBe('Infinity');
|
|
69
|
+
expect(truncateDecimals(-Infinity, 2)).toBe('-Infinity');
|
|
70
|
+
expect(truncateDecimals('NaN', 2)).toBe('NaN');
|
|
71
|
+
expect(truncateDecimals('Infinity', 2)).toBe('Infinity');
|
|
72
|
+
});
|
|
73
|
+
it('should handle native numbers with e (scientific notation)', () => {
|
|
74
|
+
expect(truncateDecimals(1e-10, 10)).toBe('0.0000000001');
|
|
75
|
+
expect(truncateDecimals(1.23e-8, 10)).toBe('0.0000000123');
|
|
76
|
+
expect(truncateDecimals(-5.43e-7, 9)).toBe('-0.000000543');
|
|
77
|
+
expect(truncateDecimals(5.2e9, 0)).toBe('5200000000');
|
|
78
|
+
expect(truncateDecimals(-1.23e9, 0)).toBe('-1230000000');
|
|
79
|
+
expect(truncateDecimals(1e21, 0)).toBe('1000000000000000000000');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Default TON reserve subtracted from balance when computing the max spendable amount
|
|
10
|
+
* for a native TON operation — leaves room for network fees. 0.1 TON.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_TON_FEE_RESERVE_NANOS = 100000000n;
|
|
13
|
+
export interface CalcMaxSpendableParams {
|
|
14
|
+
/** User's balance of `token`, as a decimal string. */
|
|
15
|
+
balance: string;
|
|
16
|
+
/** The token the user is going to spend. */
|
|
17
|
+
token: {
|
|
18
|
+
address: string;
|
|
19
|
+
decimals: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* TON reserve (in nanos) subtracted from balance when the token is native TON.
|
|
23
|
+
* Ignored for jettons. Defaults to {@link DEFAULT_TON_FEE_RESERVE_NANOS}.
|
|
24
|
+
*/
|
|
25
|
+
feeReserveNanos?: bigint;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Compute the max spendable amount a user can place into an input when they click MAX.
|
|
29
|
+
* For native TON — subtracts a fixed reserve so the user still has room for network fees.
|
|
30
|
+
* For jettons — returns the full balance (gas is paid from TON separately).
|
|
31
|
+
*/
|
|
32
|
+
export declare const calcMaxSpendable: ({ balance, token, feeReserveNanos, }: CalcMaxSpendableParams) => string;
|
|
33
|
+
//# sourceMappingURL=calc-max-spendable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calc-max-spendable.d.ts","sourceRoot":"","sources":["../../../../src/utils/balance/calc-max-spendable.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;GAGG;AACH,eAAO,MAAM,6BAA6B,aAAe,CAAC;AAE1D,MAAM,WAAW,sBAAsB;IACnC,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,sCAI9B,sBAAsB,KAAG,MAM3B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { formatUnits, parseUnits } from '@ton/walletkit';
|
|
9
|
+
/**
|
|
10
|
+
* Default TON reserve subtracted from balance when computing the max spendable amount
|
|
11
|
+
* for a native TON operation — leaves room for network fees. 0.1 TON.
|
|
12
|
+
*/
|
|
13
|
+
export const DEFAULT_TON_FEE_RESERVE_NANOS = 100000000n;
|
|
14
|
+
/**
|
|
15
|
+
* Compute the max spendable amount a user can place into an input when they click MAX.
|
|
16
|
+
* For native TON — subtracts a fixed reserve so the user still has room for network fees.
|
|
17
|
+
* For jettons — returns the full balance (gas is paid from TON separately).
|
|
18
|
+
*/
|
|
19
|
+
export const calcMaxSpendable = ({ balance, token, feeReserveNanos = DEFAULT_TON_FEE_RESERVE_NANOS, }) => {
|
|
20
|
+
if (token.address !== 'ton')
|
|
21
|
+
return balance;
|
|
22
|
+
const balanceNanos = parseUnits(balance, token.decimals);
|
|
23
|
+
const reducedNanos = balanceNanos > feeReserveNanos ? balanceNanos - feeReserveNanos : 0n;
|
|
24
|
+
return formatUnits(reducedNanos, token.decimals);
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calc-max-spendable.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/balance/calc-max-spendable.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|