@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
|
@@ -11,7 +11,7 @@ import { getNftsByAddress } from '../../actions/nft/get-nfts-by-address';
|
|
|
11
11
|
import type { GetNftsByAddressOptions } from '../../actions/nft/get-nfts-by-address';
|
|
12
12
|
import type { QueryOptions, QueryParameter } from '../../types/query';
|
|
13
13
|
import type { Compute, ExactPartial } from '../../types/utils';
|
|
14
|
-
import { filterQueryOptions, resolveNetwork } from '../../utils';
|
|
14
|
+
import { filterQueryOptions, resolveNetwork, tryToBounceableAddress } from '../../utils';
|
|
15
15
|
import type { GetNftsByAddressReturnType } from '../../actions/nft/get-nfts-by-address';
|
|
16
16
|
|
|
17
17
|
export type GetNFTsErrorType = Error;
|
|
@@ -28,7 +28,11 @@ export const getNFTsByAddressQueryOptions = <selectData = GetNFTsByAddressData>(
|
|
|
28
28
|
initialOptions: GetNFTsByAddressQueryConfig<selectData> = {},
|
|
29
29
|
): GetNFTsByAddressQueryOptions<selectData> => {
|
|
30
30
|
const network = resolveNetwork(appKit, initialOptions.network);
|
|
31
|
-
const options = {
|
|
31
|
+
const options = {
|
|
32
|
+
...initialOptions,
|
|
33
|
+
network,
|
|
34
|
+
address: tryToBounceableAddress(initialOptions.address) ?? initialOptions.address,
|
|
35
|
+
};
|
|
32
36
|
|
|
33
37
|
return {
|
|
34
38
|
...options.query,
|
|
@@ -12,7 +12,7 @@ import type { GetStakedBalanceReturnType } from '../../actions/staking/get-stake
|
|
|
12
12
|
import type { AppKit } from '../../core/app-kit';
|
|
13
13
|
import type { QueryOptions, QueryParameter } from '../../types/query';
|
|
14
14
|
import type { Compute, ExactPartial } from '../../types/utils';
|
|
15
|
-
import { filterQueryOptions } from '../../utils';
|
|
15
|
+
import { filterQueryOptions, resolveNetwork, tryToBounceableAddress } from '../../utils';
|
|
16
16
|
|
|
17
17
|
export type GetStakedBalanceErrorType = Error;
|
|
18
18
|
|
|
@@ -23,8 +23,15 @@ export type GetStakedBalanceQueryConfig<selectData = GetStakedBalanceData> = Com
|
|
|
23
23
|
|
|
24
24
|
export const getStakedBalanceQueryOptions = <selectData = GetStakedBalanceData>(
|
|
25
25
|
appKit: AppKit,
|
|
26
|
-
|
|
26
|
+
initialOptions: GetStakedBalanceQueryConfig<selectData> = {},
|
|
27
27
|
): GetStakedBalanceQueryOptions<selectData> => {
|
|
28
|
+
const network = resolveNetwork(appKit, initialOptions.network);
|
|
29
|
+
const options = {
|
|
30
|
+
...initialOptions,
|
|
31
|
+
network,
|
|
32
|
+
userAddress: tryToBounceableAddress(initialOptions.userAddress) ?? initialOptions.userAddress,
|
|
33
|
+
};
|
|
34
|
+
|
|
28
35
|
return {
|
|
29
36
|
...options.query,
|
|
30
37
|
enabled: Boolean(options.userAddress && (options.query?.enabled ?? true)),
|
|
@@ -47,7 +54,7 @@ export type GetStakedBalanceData = GetStakedBalanceQueryFnData;
|
|
|
47
54
|
export const getStakedBalanceQueryKey = (
|
|
48
55
|
options: Compute<ExactPartial<GetStakedBalanceOptions>> = {},
|
|
49
56
|
): GetStakedBalanceQueryKey => {
|
|
50
|
-
return ['stakedBalance', filterQueryOptions(options
|
|
57
|
+
return ['stakedBalance', filterQueryOptions(options)] as const;
|
|
51
58
|
};
|
|
52
59
|
|
|
53
60
|
export type GetStakedBalanceQueryKey = readonly ['stakedBalance', Compute<ExactPartial<GetStakedBalanceOptions>>];
|
|
@@ -12,7 +12,7 @@ import type { GetStakingProviderInfoReturnType } from '../../actions/staking/get
|
|
|
12
12
|
import type { AppKit } from '../../core/app-kit';
|
|
13
13
|
import type { QueryOptions, QueryParameter } from '../../types/query';
|
|
14
14
|
import type { Compute, ExactPartial } from '../../types/utils';
|
|
15
|
-
import { filterQueryOptions } from '../../utils';
|
|
15
|
+
import { filterQueryOptions, resolveNetwork } from '../../utils';
|
|
16
16
|
|
|
17
17
|
export type GetStakingProviderInfoErrorType = Error;
|
|
18
18
|
|
|
@@ -28,8 +28,11 @@ export type GetStakingProviderInfoQueryConfig<selectData = GetStakingProviderInf
|
|
|
28
28
|
|
|
29
29
|
export const getStakingProviderInfoQueryOptions = <selectData = GetStakingProviderInfoData>(
|
|
30
30
|
appKit: AppKit,
|
|
31
|
-
|
|
31
|
+
initialOptions: GetStakingProviderInfoQueryConfig<selectData> = {},
|
|
32
32
|
): GetStakingProviderInfoQueryOptions<selectData> => {
|
|
33
|
+
const network = resolveNetwork(appKit, initialOptions.network);
|
|
34
|
+
const options = { ...initialOptions, network };
|
|
35
|
+
|
|
33
36
|
return {
|
|
34
37
|
...options.query,
|
|
35
38
|
queryFn: async (context) => {
|
|
@@ -12,7 +12,7 @@ import type { GetStakingQuoteReturnType } from '../../actions/staking/get-stakin
|
|
|
12
12
|
import type { AppKit } from '../../core/app-kit';
|
|
13
13
|
import type { QueryOptions, QueryParameter } from '../../types/query';
|
|
14
14
|
import type { Compute, ExactPartial } from '../../types/utils';
|
|
15
|
-
import { filterQueryOptions } from '../../utils';
|
|
15
|
+
import { filterQueryOptions, resolveNetwork, tryToBounceableAddress } from '../../utils';
|
|
16
16
|
|
|
17
17
|
export type GetStakingQuoteErrorType = Error;
|
|
18
18
|
|
|
@@ -23,11 +23,20 @@ export type GetStakingQuoteQueryConfig<selectData = GetStakingQuoteData> = Compu
|
|
|
23
23
|
|
|
24
24
|
export const getStakingQuoteQueryOptions = <selectData = GetStakingQuoteData>(
|
|
25
25
|
appKit: AppKit,
|
|
26
|
-
|
|
26
|
+
initialOptions: GetStakingQuoteQueryConfig<selectData> = {},
|
|
27
27
|
): GetStakingQuoteQueryOptions<selectData> => {
|
|
28
|
+
const network = resolveNetwork(appKit, initialOptions.network);
|
|
29
|
+
const options = {
|
|
30
|
+
...initialOptions,
|
|
31
|
+
network,
|
|
32
|
+
userAddress: tryToBounceableAddress(initialOptions.userAddress) ?? initialOptions.userAddress,
|
|
33
|
+
};
|
|
34
|
+
|
|
28
35
|
return {
|
|
29
36
|
...options.query,
|
|
30
|
-
enabled: Boolean(
|
|
37
|
+
enabled: Boolean(
|
|
38
|
+
options.amount && options.amount !== '0' && options.direction && (options.query?.enabled ?? true),
|
|
39
|
+
),
|
|
31
40
|
queryFn: async (context) => {
|
|
32
41
|
const [, parameters] = context.queryKey as [string, GetStakingQuoteOptions];
|
|
33
42
|
if (!parameters.amount || !parameters.direction) {
|
|
@@ -47,7 +56,7 @@ export type GetStakingQuoteData = GetStakingQuoteQueryFnData;
|
|
|
47
56
|
export const getStakingQuoteQueryKey = (
|
|
48
57
|
options: Compute<ExactPartial<GetStakingQuoteOptions>> = {},
|
|
49
58
|
): GetStakingQuoteQueryKey => {
|
|
50
|
-
return ['stakingQuote', filterQueryOptions(options
|
|
59
|
+
return ['stakingQuote', filterQueryOptions(options)] as const;
|
|
51
60
|
};
|
|
52
61
|
|
|
53
62
|
export type GetStakingQuoteQueryKey = readonly ['stakingQuote', Compute<ExactPartial<GetStakingQuoteOptions>>];
|
|
@@ -28,7 +28,9 @@ export const getSwapQuoteQueryOptions = <selectData = GetSwapQuoteData>(
|
|
|
28
28
|
|
|
29
29
|
return {
|
|
30
30
|
...options.query,
|
|
31
|
-
enabled: Boolean(
|
|
31
|
+
enabled: Boolean(
|
|
32
|
+
options.amount && options.amount !== '0' && options.from && options.to && (options.query?.enabled ?? true),
|
|
33
|
+
),
|
|
32
34
|
queryFn: async (context) => {
|
|
33
35
|
const [, parameters] = context.queryKey as [string, GetSwapQuoteOptions];
|
|
34
36
|
if (!parameters.amount || !parameters.from || !parameters.to) {
|
package/src/staking/index.ts
CHANGED
|
@@ -6,7 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
DefiError,
|
|
11
|
+
StakingProvider,
|
|
12
|
+
UnstakeMode,
|
|
13
|
+
StakingError,
|
|
14
|
+
StakingErrorCode,
|
|
15
|
+
StakingManager,
|
|
16
|
+
} from '@ton/walletkit';
|
|
10
17
|
|
|
11
18
|
export type {
|
|
12
19
|
UnstakeModes,
|
|
@@ -18,4 +25,6 @@ export type {
|
|
|
18
25
|
StakingProviderInfo,
|
|
19
26
|
StakingProviderInterface,
|
|
20
27
|
StakingQuoteDirection,
|
|
28
|
+
StakingProviderMetadata,
|
|
29
|
+
StakingTokenInfo,
|
|
21
30
|
} from '@ton/walletkit';
|
package/src/swap/index.ts
CHANGED
|
@@ -6,17 +6,15 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
export { DefiError, SwapError, SwapProvider, SwapManager } from '@ton/walletkit';
|
|
10
|
+
|
|
9
11
|
export type {
|
|
10
12
|
SwapToken,
|
|
11
13
|
TokenAmount,
|
|
12
14
|
SwapParams,
|
|
13
15
|
SwapAPI,
|
|
14
|
-
SwapFee,
|
|
15
16
|
SwapQuote,
|
|
16
17
|
SwapQuoteParams,
|
|
17
18
|
DefiManagerAPI,
|
|
18
19
|
DefiProvider,
|
|
19
|
-
SwapProvider,
|
|
20
|
-
SwapError,
|
|
21
|
-
SwapManager,
|
|
22
20
|
} from '@ton/walletkit';
|
package/src/types/connector.ts
CHANGED
package/src/types/primitives.ts
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
import { Address } from '@ton/core';
|
|
10
|
+
|
|
11
|
+
import type { UserFriendlyAddress } from '../../types/primitives';
|
|
12
|
+
import { isString } from '../predicate/is-string';
|
|
13
|
+
|
|
14
|
+
export const isValidAddress = (address: unknown): address is string => {
|
|
15
|
+
if (typeof address !== 'string') {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
Address.parse(address);
|
|
21
|
+
} catch (_) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const isFriendlyTonAddress = (address: unknown): address is UserFriendlyAddress => {
|
|
29
|
+
if (!isString(address)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
Address.parseFriendly(address);
|
|
35
|
+
} catch (_) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return true;
|
|
40
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
import { Address } from '@ton/core';
|
|
10
|
+
|
|
11
|
+
import { getErrorMessage } from '../errors/get-error-message';
|
|
12
|
+
|
|
13
|
+
export const toBounceableAddress = (address?: Address | string | null): string => {
|
|
14
|
+
if (!address) {
|
|
15
|
+
throw new Error(`Address is empty`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (address instanceof Address) {
|
|
19
|
+
return address.toString({ bounceable: true });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
return Address.parse(address).toString({ bounceable: true });
|
|
24
|
+
} catch (e) {
|
|
25
|
+
throw new Error(`Can not convert to bounceble address from "${address}". Error: ${getErrorMessage(e)}`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const tryToBounceableAddress = (address?: Address | string | null): string | undefined => {
|
|
30
|
+
try {
|
|
31
|
+
return toBounceableAddress(address);
|
|
32
|
+
} catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
import { Address } from '@ton/core';
|
|
10
|
+
|
|
11
|
+
import { getErrorMessage } from '../errors/get-error-message';
|
|
12
|
+
|
|
13
|
+
export const toNonBounceableAddress = (address?: Address | string | null): string => {
|
|
14
|
+
if (!address) {
|
|
15
|
+
throw new Error(`Address is empty`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (address instanceof Address) {
|
|
19
|
+
return address.toString({ bounceable: false });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
return Address.parse(address).toString({ bounceable: false });
|
|
24
|
+
} catch (e) {
|
|
25
|
+
throw new Error(`Can not convert to non-bounceable address from "${address}". Error: ${getErrorMessage(e)}`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const tryToNonBounceableAddress = (address?: Address | string | null): string | undefined => {
|
|
30
|
+
try {
|
|
31
|
+
return toNonBounceableAddress(address);
|
|
32
|
+
} catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
import { describe, it, expect } from 'vitest';
|
|
10
|
+
|
|
11
|
+
import { calcFiatValue } from './calc-fiat-value';
|
|
12
|
+
|
|
13
|
+
describe('calcFiatValue', () => {
|
|
14
|
+
it('should return 0 when rate is undefined', () => {
|
|
15
|
+
expect(calcFiatValue('100', undefined)).toBe('0');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should return 0 when rate is 0', () => {
|
|
19
|
+
expect(calcFiatValue('100', '0')).toBe('0');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should return 0 when amount is 0', () => {
|
|
23
|
+
expect(calcFiatValue('0', '1.5')).toBe('0');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should return 0 when amount is negative', () => {
|
|
27
|
+
expect(calcFiatValue('-10', '1.5')).toBe('0');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should return 0 when amount is not a valid number', () => {
|
|
31
|
+
expect(calcFiatValue('abc', '1.5')).toBe('0');
|
|
32
|
+
expect(calcFiatValue('', '1.5')).toBe('0');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should calculate fiat value without rounding', () => {
|
|
36
|
+
expect(calcFiatValue('100', '1.5')).toBe('150');
|
|
37
|
+
expect(calcFiatValue('1', '0.001')).toBe('0.001');
|
|
38
|
+
expect(calcFiatValue('3', '1.005')).toBe('3.015');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should handle decimal amounts without rounding', () => {
|
|
42
|
+
expect(calcFiatValue('0.5', '2')).toBe('1');
|
|
43
|
+
expect(calcFiatValue('1.23456', '100')).toBe('123.456');
|
|
44
|
+
expect(calcFiatValue('2.996876', '1')).toBe('2.996876');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* Calculates the fiat value of a token amount.
|
|
11
|
+
* Returns null when rate is unavailable or amount is zero/invalid.
|
|
12
|
+
*/
|
|
13
|
+
export function calcFiatValue(amount: string, rate: string | undefined): string {
|
|
14
|
+
if (!rate) return '0';
|
|
15
|
+
const num = parseFloat(amount);
|
|
16
|
+
if (!num || num <= 0) return '0';
|
|
17
|
+
return Number((num * parseFloat(rate)).toFixed(10)).toString();
|
|
18
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
import { describe, it, expect } from 'vitest';
|
|
10
|
+
|
|
11
|
+
import { formatLargeValue } from './format-large-value';
|
|
12
|
+
|
|
13
|
+
describe('formatLargeValue', () => {
|
|
14
|
+
it('should format trillion values', () => {
|
|
15
|
+
expect(formatLargeValue('1000000000000')).toBe('1T');
|
|
16
|
+
expect(formatLargeValue('1230000000000')).toBe('1.23T');
|
|
17
|
+
expect(formatLargeValue('12345678901234')).toBe('12.34T');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should format billion values', () => {
|
|
21
|
+
expect(formatLargeValue('1000000000')).toBe('1B');
|
|
22
|
+
expect(formatLargeValue('1230000000')).toBe('1.23B');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should format million values', () => {
|
|
26
|
+
expect(formatLargeValue('1000000')).toBe('1M');
|
|
27
|
+
expect(formatLargeValue('1230000')).toBe('1.23M');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should format smaller values using toLocaleString', () => {
|
|
31
|
+
expect(formatLargeValue('1234.56')).toBe('1,234.56');
|
|
32
|
+
expect(formatLargeValue('100')).toBe('100');
|
|
33
|
+
expect(formatLargeValue('0')).toBe('0');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should handle spaces and formatting', () => {
|
|
37
|
+
expect(formatLargeValue('1 000 000')).toBe('1M');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should respect decimals for small values', () => {
|
|
41
|
+
expect(formatLargeValue('1234.5678', 4)).toBe('1,234.5678');
|
|
42
|
+
expect(formatLargeValue('1234.5678', 2)).toBe('1,234.56');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should round down (floor) fractional values', () => {
|
|
46
|
+
expect(formatLargeValue('2.996848', 2)).toBe('2.99');
|
|
47
|
+
expect(formatLargeValue('2.996848', 6)).toBe('2.996848');
|
|
48
|
+
expect(formatLargeValue('0.9999', 2)).toBe('0.99');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
export const formatLargeValue = (amount: string, decimals: number = 2, minimumFractionDigits: number = 0): string => {
|
|
10
|
+
const cleanAmount = amount.toString().replace(/\s/g, '');
|
|
11
|
+
const intPart = cleanAmount.split('.')[0] || '0';
|
|
12
|
+
|
|
13
|
+
// value > 100 000 000 000 000 => 100 T
|
|
14
|
+
if (intPart.length > 12) {
|
|
15
|
+
const value = Number(intPart.slice(0, -10)) / 100;
|
|
16
|
+
return `${value.toLocaleString('en-US')}T`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// value > 100 000 000 000 => 100 B
|
|
20
|
+
if (intPart.length > 9) {
|
|
21
|
+
const value = Number(intPart.slice(0, -7)) / 100;
|
|
22
|
+
return `${value.toLocaleString('en-US')}B`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// value > 10 000 000 => 10 M
|
|
26
|
+
if (intPart.length > 6) {
|
|
27
|
+
const value = Number(intPart.slice(0, -4)) / 100;
|
|
28
|
+
return `${value.toLocaleString('en-US')}M`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const value = parseFloat(cleanAmount);
|
|
32
|
+
if (isNaN(value)) {
|
|
33
|
+
return '0';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const factor = Math.pow(10, decimals);
|
|
37
|
+
const truncated = Math.floor(value * factor) / factor;
|
|
38
|
+
|
|
39
|
+
return truncated.toLocaleString('en-US', {
|
|
40
|
+
minimumFractionDigits,
|
|
41
|
+
maximumFractionDigits: decimals,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
import { describe, expect, it } from 'vitest';
|
|
10
|
+
|
|
11
|
+
import { truncateDecimals } from './truncate-decimals';
|
|
12
|
+
|
|
13
|
+
describe('truncateDecimals', () => {
|
|
14
|
+
it('should return integers unchanged', () => {
|
|
15
|
+
expect(truncateDecimals('123', 2)).toBe('123');
|
|
16
|
+
expect(truncateDecimals('0', 5)).toBe('0');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should truncate decimals exceeding maxDecimals', () => {
|
|
20
|
+
expect(truncateDecimals('1.23456', 2)).toBe('1.23');
|
|
21
|
+
expect(truncateDecimals('1.23456', 4)).toBe('1.2345');
|
|
22
|
+
expect(truncateDecimals('0.123456789', 9)).toBe('0.123456789');
|
|
23
|
+
expect(truncateDecimals('0.1234567890', 9)).toBe('0.123456789');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should return value unchanged when decimals are within limit', () => {
|
|
27
|
+
expect(truncateDecimals('1.23', 5)).toBe('1.23');
|
|
28
|
+
expect(truncateDecimals('1.2', 2)).toBe('1.2');
|
|
29
|
+
expect(truncateDecimals('5.0', 1)).toBe('5.0');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should handle maxDecimals of 0', () => {
|
|
33
|
+
expect(truncateDecimals('1.999', 0)).toBe('1');
|
|
34
|
+
expect(truncateDecimals('42.1', 0)).toBe('42');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should strip trailing dot', () => {
|
|
38
|
+
expect(truncateDecimals('1.', 3)).toBe('1');
|
|
39
|
+
expect(truncateDecimals('1.', 0)).toBe('1');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should handle empty string', () => {
|
|
43
|
+
expect(truncateDecimals('', 2)).toBe('');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should handle number input', () => {
|
|
47
|
+
expect(truncateDecimals(1.23456, 2)).toBe('1.23');
|
|
48
|
+
expect(truncateDecimals(42, 3)).toBe('42');
|
|
49
|
+
expect(truncateDecimals(0.1, 5)).toBe('0.1');
|
|
50
|
+
expect(truncateDecimals(3.14159, 0)).toBe('3');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should handle scientific notation strings', () => {
|
|
54
|
+
expect(truncateDecimals('1.095492908209088e-9', 9)).toBe('0.000000001');
|
|
55
|
+
expect(truncateDecimals('5e-7', 9)).toBe('0.0000005');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should handle numbers that produce scientific notation', () => {
|
|
59
|
+
const tiny = 0.000000001 * 1.095492908209088; // 1.095492908209088e-9
|
|
60
|
+
expect(truncateDecimals(tiny, 9)).toBe('0.000000001');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should handle negative numbers and negative scientific notation', () => {
|
|
64
|
+
expect(truncateDecimals('-1.23456', 2)).toBe('-1.23');
|
|
65
|
+
expect(truncateDecimals('-5e-7', 9)).toBe('-0.0000005');
|
|
66
|
+
expect(truncateDecimals(-0.0000005, 9)).toBe('-0.0000005');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should handle scientific notation with positive exponents', () => {
|
|
70
|
+
expect(truncateDecimals('1.2345e2', 2)).toBe('123.45');
|
|
71
|
+
expect(truncateDecimals('1.2345e+2', 0)).toBe('123');
|
|
72
|
+
expect(truncateDecimals('5.2e9', 0)).toBe('5200000000');
|
|
73
|
+
expect(truncateDecimals('-1.23e+9', 0)).toBe('-1230000000');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should handle extreme scientific exponents', () => {
|
|
77
|
+
expect(truncateDecimals('1e-100', 100)).toBe('0.' + '0'.repeat(99) + '1');
|
|
78
|
+
expect(truncateDecimals('1e21', 0)).toBe('1000000000000000000000');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should handle NaN and Infinity', () => {
|
|
82
|
+
expect(truncateDecimals(NaN, 2)).toBe('NaN');
|
|
83
|
+
expect(truncateDecimals(Infinity, 2)).toBe('Infinity');
|
|
84
|
+
expect(truncateDecimals(-Infinity, 2)).toBe('-Infinity');
|
|
85
|
+
expect(truncateDecimals('NaN', 2)).toBe('NaN');
|
|
86
|
+
expect(truncateDecimals('Infinity', 2)).toBe('Infinity');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should handle native numbers with e (scientific notation)', () => {
|
|
90
|
+
expect(truncateDecimals(1e-10, 10)).toBe('0.0000000001');
|
|
91
|
+
expect(truncateDecimals(1.23e-8, 10)).toBe('0.0000000123');
|
|
92
|
+
expect(truncateDecimals(-5.43e-7, 9)).toBe('-0.000000543');
|
|
93
|
+
expect(truncateDecimals(5.2e9, 0)).toBe('5200000000');
|
|
94
|
+
expect(truncateDecimals(-1.23e9, 0)).toBe('-1230000000');
|
|
95
|
+
expect(truncateDecimals(1e21, 0)).toBe('1000000000000000000000');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* Converts a number to a plain decimal string, expanding scientific notation
|
|
11
|
+
* like "1.23e-9" into "0.00000000123".
|
|
12
|
+
*/
|
|
13
|
+
const toPlainDecimalString = (num: number): string => {
|
|
14
|
+
const str = num.toString();
|
|
15
|
+
if (!str.includes('e') && !str.includes('E')) return str;
|
|
16
|
+
|
|
17
|
+
const [base = '0', exponent = '0'] = str.split(/[eE]/);
|
|
18
|
+
const exp = Number(exponent);
|
|
19
|
+
const isNegative = base.startsWith('-');
|
|
20
|
+
const absBase = isNegative ? base.slice(1) : base;
|
|
21
|
+
const [intPart, decPart = ''] = absBase.split('.');
|
|
22
|
+
|
|
23
|
+
let result: string;
|
|
24
|
+
if (exp < 0) {
|
|
25
|
+
result = '0.' + '0'.repeat(Math.abs(exp) - 1) + intPart + decPart;
|
|
26
|
+
} else {
|
|
27
|
+
const addZeros = exp - decPart.length;
|
|
28
|
+
if (addZeros >= 0) {
|
|
29
|
+
result = intPart + decPart + '0'.repeat(addZeros);
|
|
30
|
+
} else {
|
|
31
|
+
result = intPart + decPart.slice(0, exp) + '.' + decPart.slice(exp);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return isNegative ? '-' + result : result;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const truncateDecimals = (value: string | number, maxDecimals: number): string => {
|
|
39
|
+
let strValue: string;
|
|
40
|
+
|
|
41
|
+
if (typeof value === 'number') {
|
|
42
|
+
strValue = toPlainDecimalString(value);
|
|
43
|
+
} else if (value.includes('e') || value.includes('E')) {
|
|
44
|
+
const num = Number(value);
|
|
45
|
+
if (Number.isNaN(num)) return value;
|
|
46
|
+
strValue = toPlainDecimalString(num);
|
|
47
|
+
} else {
|
|
48
|
+
strValue = value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const dotIndex = strValue.indexOf('.');
|
|
52
|
+
if (dotIndex === -1) return strValue;
|
|
53
|
+
|
|
54
|
+
const result = strValue.slice(0, dotIndex + 1 + maxDecimals);
|
|
55
|
+
return result.endsWith('.') ? result.slice(0, -1) : result;
|
|
56
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
import { describe, expect, it } from 'vitest';
|
|
10
|
+
|
|
11
|
+
import { calcMaxSpendable, DEFAULT_TON_FEE_RESERVE_NANOS } from './calc-max-spendable';
|
|
12
|
+
|
|
13
|
+
const TON = { address: 'ton', decimals: 9 };
|
|
14
|
+
const JETTON = { address: 'EQA_jetton', decimals: 6 };
|
|
15
|
+
|
|
16
|
+
describe('calcMaxSpendable', () => {
|
|
17
|
+
it('returns balance minus the TON fee reserve for native TON', () => {
|
|
18
|
+
// 1 TON balance, default reserve 0.1 TON → 0.9 TON spendable.
|
|
19
|
+
expect(calcMaxSpendable({ balance: '1', token: TON })).toBe('0.9');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('returns the full balance for a jetton (no reserve)', () => {
|
|
23
|
+
expect(calcMaxSpendable({ balance: '100', token: JETTON })).toBe('100');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('clamps to zero when balance is below the reserve', () => {
|
|
27
|
+
expect(calcMaxSpendable({ balance: '0.05', token: TON })).toBe('0');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('clamps to zero when balance equals the reserve', () => {
|
|
31
|
+
expect(calcMaxSpendable({ balance: '0.1', token: TON })).toBe('0');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('respects a custom feeReserveNanos', () => {
|
|
35
|
+
// 1 TON balance, 0.5 TON reserve → 0.5 TON spendable.
|
|
36
|
+
expect(calcMaxSpendable({ balance: '1', token: TON, feeReserveNanos: 500_000_000n })).toBe('0.5');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('ignores feeReserveNanos for jettons', () => {
|
|
40
|
+
expect(calcMaxSpendable({ balance: '100', token: JETTON, feeReserveNanos: 999_999_999_999n })).toBe('100');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('exports a sane default reserve', () => {
|
|
44
|
+
expect(DEFAULT_TON_FEE_RESERVE_NANOS).toBe(100_000_000n);
|
|
45
|
+
});
|
|
46
|
+
});
|