@ledgerhq/coin-framework 0.0.2
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/lib/account/accountId.d.ts +16 -0
- package/lib/account/accountId.d.ts.map +1 -0
- package/lib/account/accountId.js +85 -0
- package/lib/account/accountId.js.map +1 -0
- package/lib/account/accountName.d.ts +14 -0
- package/lib/account/accountName.d.ts.map +1 -0
- package/lib/account/accountName.js +17 -0
- package/lib/account/accountName.js.map +1 -0
- package/lib/account/addAccounts.d.ts +35 -0
- package/lib/account/addAccounts.d.ts.map +1 -0
- package/lib/account/addAccounts.js +209 -0
- package/lib/account/addAccounts.js.map +1 -0
- package/lib/account/balanceHistoryCache.d.ts +25 -0
- package/lib/account/balanceHistoryCache.d.ts.map +1 -0
- package/lib/account/balanceHistoryCache.js +115 -0
- package/lib/account/balanceHistoryCache.js.map +1 -0
- package/lib/account/groupOperations.d.ts +17 -0
- package/lib/account/groupOperations.d.ts.map +1 -0
- package/lib/account/groupOperations.js +127 -0
- package/lib/account/groupOperations.js.map +1 -0
- package/lib/account/helpers.d.ts +44 -0
- package/lib/account/helpers.d.ts.map +1 -0
- package/lib/account/helpers.js +333 -0
- package/lib/account/helpers.js.map +1 -0
- package/lib/account/helpers.test.d.ts +2 -0
- package/lib/account/helpers.test.d.ts.map +1 -0
- package/lib/account/helpers.test.js +366 -0
- package/lib/account/helpers.test.js.map +1 -0
- package/lib/account/index.d.ts +11 -0
- package/lib/account/index.d.ts.map +1 -0
- package/lib/account/index.js +27 -0
- package/lib/account/index.js.map +1 -0
- package/lib/account/ordering.d.ts +10 -0
- package/lib/account/ordering.d.ts.map +1 -0
- package/lib/account/ordering.js +110 -0
- package/lib/account/ordering.js.map +1 -0
- package/lib/account/pending.d.ts +33 -0
- package/lib/account/pending.d.ts.map +1 -0
- package/lib/account/pending.js +64 -0
- package/lib/account/pending.js.map +1 -0
- package/lib/account/serialization.d.ts +6 -0
- package/lib/account/serialization.d.ts.map +1 -0
- package/lib/account/serialization.js +118 -0
- package/lib/account/serialization.js.map +1 -0
- package/lib/account/support.d.ts +9 -0
- package/lib/account/support.d.ts.map +1 -0
- package/lib/account/support.js +72 -0
- package/lib/account/support.js.map +1 -0
- package/lib/account.test.d.ts +2 -0
- package/lib/account.test.d.ts.map +1 -0
- package/lib/account.test.js +257 -0
- package/lib/account.test.js.map +1 -0
- package/lib/bot/bot-test-context.d.ts +3 -0
- package/lib/bot/bot-test-context.d.ts.map +1 -0
- package/lib/bot/bot-test-context.js +26 -0
- package/lib/bot/bot-test-context.js.map +1 -0
- package/lib/bot/bot-test-context.test.d.ts +2 -0
- package/lib/bot/bot-test-context.test.d.ts.map +1 -0
- package/lib/bot/bot-test-context.test.js +41 -0
- package/lib/bot/bot-test-context.test.js.map +1 -0
- package/lib/bot/formatters.d.ts +2 -0
- package/lib/bot/formatters.d.ts.map +1 -0
- package/lib/bot/formatters.js +31 -0
- package/lib/bot/formatters.js.map +1 -0
- package/lib/bot/specs.d.ts +50 -0
- package/lib/bot/specs.d.ts.map +1 -0
- package/lib/bot/specs.js +204 -0
- package/lib/bot/specs.js.map +1 -0
- package/lib/bot/types.d.ts +178 -0
- package/lib/bot/types.d.ts.map +1 -0
- package/lib/bot/types.js +3 -0
- package/lib/bot/types.js.map +1 -0
- package/lib/bridge/getAddressWrapper.d.ts +6 -0
- package/lib/bridge/getAddressWrapper.d.ts.map +1 -0
- package/lib/bridge/getAddressWrapper.js +27 -0
- package/lib/bridge/getAddressWrapper.js.map +1 -0
- package/lib/bridge/jsHelpers.d.ts +63 -0
- package/lib/bridge/jsHelpers.d.ts.map +1 -0
- package/lib/bridge/jsHelpers.js +574 -0
- package/lib/bridge/jsHelpers.js.map +1 -0
- package/lib/cache.d.ts +10 -0
- package/lib/cache.d.ts.map +1 -0
- package/lib/cache.js +100 -0
- package/lib/cache.js.map +1 -0
- package/lib/cross.d.ts +42 -0
- package/lib/cross.d.ts.map +1 -0
- package/lib/cross.js +254 -0
- package/lib/cross.js.map +1 -0
- package/lib/cross.test.d.ts +2 -0
- package/lib/cross.test.d.ts.map +1 -0
- package/lib/cross.test.js +99 -0
- package/lib/cross.test.js.map +1 -0
- package/lib/currencies/BigNumberToLocaleString.d.ts +8 -0
- package/lib/currencies/BigNumberToLocaleString.d.ts.map +1 -0
- package/lib/currencies/BigNumberToLocaleString.js +65 -0
- package/lib/currencies/BigNumberToLocaleString.js.map +1 -0
- package/lib/currencies/BigNumberToLocaleString.test.d.ts +2 -0
- package/lib/currencies/BigNumberToLocaleString.test.d.ts.map +1 -0
- package/lib/currencies/BigNumberToLocaleString.test.js +108 -0
- package/lib/currencies/BigNumberToLocaleString.test.js.map +1 -0
- package/lib/currencies/CurrencyURIScheme.d.ts +13 -0
- package/lib/currencies/CurrencyURIScheme.d.ts.map +1 -0
- package/lib/currencies/CurrencyURIScheme.js +124 -0
- package/lib/currencies/CurrencyURIScheme.js.map +1 -0
- package/lib/currencies/chopCurrencyUnitDecimals.d.ts +3 -0
- package/lib/currencies/chopCurrencyUnitDecimals.d.ts.map +1 -0
- package/lib/currencies/chopCurrencyUnitDecimals.js +29 -0
- package/lib/currencies/chopCurrencyUnitDecimals.js.map +1 -0
- package/lib/currencies/formatCurrencyUnit.d.ts +33 -0
- package/lib/currencies/formatCurrencyUnit.d.ts.map +1 -0
- package/lib/currencies/formatCurrencyUnit.js +126 -0
- package/lib/currencies/formatCurrencyUnit.js.map +1 -0
- package/lib/currencies/formatShort.d.ts +8 -0
- package/lib/currencies/formatShort.d.ts.map +1 -0
- package/lib/currencies/formatShort.js +27 -0
- package/lib/currencies/formatShort.js.map +1 -0
- package/lib/currencies/index.d.ts +13 -0
- package/lib/currencies/index.d.ts.map +1 -0
- package/lib/currencies/index.js +65 -0
- package/lib/currencies/index.js.map +1 -0
- package/lib/currencies/localeUtility.d.ts +8 -0
- package/lib/currencies/localeUtility.d.ts.map +1 -0
- package/lib/currencies/localeUtility.js +49 -0
- package/lib/currencies/localeUtility.js.map +1 -0
- package/lib/currencies/parseCurrencyUnit.d.ts +4 -0
- package/lib/currencies/parseCurrencyUnit.d.ts.map +1 -0
- package/lib/currencies/parseCurrencyUnit.js +18 -0
- package/lib/currencies/parseCurrencyUnit.js.map +1 -0
- package/lib/currencies/sanitizeValueString.d.ts +6 -0
- package/lib/currencies/sanitizeValueString.d.ts.map +1 -0
- package/lib/currencies/sanitizeValueString.js +56 -0
- package/lib/currencies/sanitizeValueString.js.map +1 -0
- package/lib/currencies/support.d.ts +8 -0
- package/lib/currencies/support.d.ts.map +1 -0
- package/lib/currencies/support.js +101 -0
- package/lib/currencies/support.js.map +1 -0
- package/lib/currencies/valueFromUnit.d.ts +9 -0
- package/lib/currencies/valueFromUnit.d.ts.map +1 -0
- package/lib/currencies/valueFromUnit.js +14 -0
- package/lib/currencies/valueFromUnit.js.map +1 -0
- package/lib/derivation.d.ts +232 -0
- package/lib/derivation.d.ts.map +1 -0
- package/lib/derivation.js +501 -0
- package/lib/derivation.js.map +1 -0
- package/lib/env.d.ts +30 -0
- package/lib/env.d.ts.map +1 -0
- package/lib/env.js +773 -0
- package/lib/env.js.map +1 -0
- package/lib/errors.d.ts +7 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +7 -0
- package/lib/errors.js.map +1 -0
- package/lib/errors.test.d.ts +2 -0
- package/lib/errors.test.d.ts.map +1 -0
- package/lib/errors.test.js +20 -0
- package/lib/errors.test.js.map +1 -0
- package/lib/mocks/account.d.ts +25 -0
- package/lib/mocks/account.d.ts.map +1 -0
- package/lib/mocks/account.js +368 -0
- package/lib/mocks/account.js.map +1 -0
- package/lib/mocks/fixtures/nfts.d.ts +27 -0
- package/lib/mocks/fixtures/nfts.d.ts.map +1 -0
- package/lib/mocks/fixtures/nfts.js +398 -0
- package/lib/mocks/fixtures/nfts.js.map +1 -0
- package/lib/mocks/fixtures/nfts.test.d.ts +2 -0
- package/lib/mocks/fixtures/nfts.test.d.ts.map +1 -0
- package/lib/mocks/fixtures/nfts.test.js +20 -0
- package/lib/mocks/fixtures/nfts.test.js.map +1 -0
- package/lib/mocks/helpers.d.ts +15 -0
- package/lib/mocks/helpers.d.ts.map +1 -0
- package/lib/mocks/helpers.js +32 -0
- package/lib/mocks/helpers.js.map +1 -0
- package/lib/network.d.ts +5 -0
- package/lib/network.d.ts.map +1 -0
- package/lib/network.js +125 -0
- package/lib/network.js.map +1 -0
- package/lib/nft/nftId.d.ts +8 -0
- package/lib/nft/nftId.d.ts.map +1 -0
- package/lib/nft/nftId.js +34 -0
- package/lib/nft/nftId.js.map +1 -0
- package/lib/operation.d.ts +24 -0
- package/lib/operation.d.ts.map +1 -0
- package/lib/operation.js +183 -0
- package/lib/operation.js.map +1 -0
- package/lib/promise.d.ts +21 -0
- package/lib/promise.d.ts.map +1 -0
- package/lib/promise.js +187 -0
- package/lib/promise.js.map +1 -0
- package/lib/promise.test.d.ts +2 -0
- package/lib/promise.test.d.ts.map +1 -0
- package/lib/promise.test.js +72 -0
- package/lib/promise.test.js.map +1 -0
- package/lib/rangeDates.d.ts +29 -0
- package/lib/rangeDates.d.ts.map +1 -0
- package/lib/rangeDates.js +94 -0
- package/lib/rangeDates.js.map +1 -0
- package/lib/rangeDates.test.d.ts +2 -0
- package/lib/rangeDates.test.d.ts.map +1 -0
- package/lib/rangeDates.test.js +51 -0
- package/lib/rangeDates.test.js.map +1 -0
- package/lib/test-helpers/staticTime.d.ts +2 -0
- package/lib/test-helpers/staticTime.d.ts.map +1 -0
- package/lib/test-helpers/staticTime.js +10 -0
- package/lib/test-helpers/staticTime.js.map +1 -0
- package/lib/transaction/common.d.ts +26 -0
- package/lib/transaction/common.d.ts.map +1 -0
- package/lib/transaction/common.js +123 -0
- package/lib/transaction/common.js.map +1 -0
- package/lib-es/account/accountId.d.ts +16 -0
- package/lib-es/account/accountId.d.ts.map +1 -0
- package/lib-es/account/accountId.js +74 -0
- package/lib-es/account/accountId.js.map +1 -0
- package/lib-es/account/accountName.d.ts +14 -0
- package/lib-es/account/accountName.d.ts.map +1 -0
- package/lib-es/account/accountName.js +12 -0
- package/lib-es/account/accountName.js.map +1 -0
- package/lib-es/account/addAccounts.d.ts +35 -0
- package/lib-es/account/addAccounts.d.ts.map +1 -0
- package/lib-es/account/addAccounts.js +200 -0
- package/lib-es/account/addAccounts.js.map +1 -0
- package/lib-es/account/balanceHistoryCache.d.ts +25 -0
- package/lib-es/account/balanceHistoryCache.d.ts.map +1 -0
- package/lib-es/account/balanceHistoryCache.js +109 -0
- package/lib-es/account/balanceHistoryCache.js.map +1 -0
- package/lib-es/account/groupOperations.d.ts +17 -0
- package/lib-es/account/groupOperations.d.ts.map +1 -0
- package/lib-es/account/groupOperations.js +122 -0
- package/lib-es/account/groupOperations.js.map +1 -0
- package/lib-es/account/helpers.d.ts +44 -0
- package/lib-es/account/helpers.d.ts.map +1 -0
- package/lib-es/account/helpers.js +303 -0
- package/lib-es/account/helpers.js.map +1 -0
- package/lib-es/account/helpers.test.d.ts +2 -0
- package/lib-es/account/helpers.test.d.ts.map +1 -0
- package/lib-es/account/helpers.test.js +361 -0
- package/lib-es/account/helpers.test.js.map +1 -0
- package/lib-es/account/index.d.ts +11 -0
- package/lib-es/account/index.d.ts.map +1 -0
- package/lib-es/account/index.js +11 -0
- package/lib-es/account/index.js.map +1 -0
- package/lib-es/account/ordering.d.ts +10 -0
- package/lib-es/account/ordering.d.ts.map +1 -0
- package/lib-es/account/ordering.js +103 -0
- package/lib-es/account/ordering.js.map +1 -0
- package/lib-es/account/pending.d.ts +33 -0
- package/lib-es/account/pending.d.ts.map +1 -0
- package/lib-es/account/pending.js +59 -0
- package/lib-es/account/pending.js.map +1 -0
- package/lib-es/account/serialization.d.ts +6 -0
- package/lib-es/account/serialization.d.ts.map +1 -0
- package/lib-es/account/serialization.js +112 -0
- package/lib-es/account/serialization.js.map +1 -0
- package/lib-es/account/support.d.ts +9 -0
- package/lib-es/account/support.d.ts.map +1 -0
- package/lib-es/account/support.js +64 -0
- package/lib-es/account/support.js.map +1 -0
- package/lib-es/account.test.d.ts +2 -0
- package/lib-es/account.test.d.ts.map +1 -0
- package/lib-es/account.test.js +252 -0
- package/lib-es/account.test.js.map +1 -0
- package/lib-es/bot/bot-test-context.d.ts +3 -0
- package/lib-es/bot/bot-test-context.d.ts.map +1 -0
- package/lib-es/bot/bot-test-context.js +21 -0
- package/lib-es/bot/bot-test-context.js.map +1 -0
- package/lib-es/bot/bot-test-context.test.d.ts +2 -0
- package/lib-es/bot/bot-test-context.test.d.ts.map +1 -0
- package/lib-es/bot/bot-test-context.test.js +39 -0
- package/lib-es/bot/bot-test-context.test.js.map +1 -0
- package/lib-es/bot/formatters.d.ts +2 -0
- package/lib-es/bot/formatters.d.ts.map +1 -0
- package/lib-es/bot/formatters.js +27 -0
- package/lib-es/bot/formatters.js.map +1 -0
- package/lib-es/bot/specs.d.ts +50 -0
- package/lib-es/bot/specs.d.ts.map +1 -0
- package/lib-es/bot/specs.js +193 -0
- package/lib-es/bot/specs.js.map +1 -0
- package/lib-es/bot/types.d.ts +178 -0
- package/lib-es/bot/types.d.ts.map +1 -0
- package/lib-es/bot/types.js +2 -0
- package/lib-es/bot/types.js.map +1 -0
- package/lib-es/bridge/getAddressWrapper.d.ts +6 -0
- package/lib-es/bridge/getAddressWrapper.d.ts.map +1 -0
- package/lib-es/bridge/getAddressWrapper.js +25 -0
- package/lib-es/bridge/getAddressWrapper.js.map +1 -0
- package/lib-es/bridge/jsHelpers.d.ts +63 -0
- package/lib-es/bridge/jsHelpers.d.ts.map +1 -0
- package/lib-es/bridge/jsHelpers.js +562 -0
- package/lib-es/bridge/jsHelpers.js.map +1 -0
- package/lib-es/cache.d.ts +10 -0
- package/lib-es/cache.d.ts.map +1 -0
- package/lib-es/cache.js +93 -0
- package/lib-es/cache.js.map +1 -0
- package/lib-es/cross.d.ts +42 -0
- package/lib-es/cross.d.ts.map +1 -0
- package/lib-es/cross.js +244 -0
- package/lib-es/cross.js.map +1 -0
- package/lib-es/cross.test.d.ts +2 -0
- package/lib-es/cross.test.d.ts.map +1 -0
- package/lib-es/cross.test.js +97 -0
- package/lib-es/cross.test.js.map +1 -0
- package/lib-es/currencies/BigNumberToLocaleString.d.ts +8 -0
- package/lib-es/currencies/BigNumberToLocaleString.d.ts.map +1 -0
- package/lib-es/currencies/BigNumberToLocaleString.js +61 -0
- package/lib-es/currencies/BigNumberToLocaleString.js.map +1 -0
- package/lib-es/currencies/BigNumberToLocaleString.test.d.ts +2 -0
- package/lib-es/currencies/BigNumberToLocaleString.test.d.ts.map +1 -0
- package/lib-es/currencies/BigNumberToLocaleString.test.js +106 -0
- package/lib-es/currencies/BigNumberToLocaleString.test.js.map +1 -0
- package/lib-es/currencies/CurrencyURIScheme.d.ts +13 -0
- package/lib-es/currencies/CurrencyURIScheme.d.ts.map +1 -0
- package/lib-es/currencies/CurrencyURIScheme.js +116 -0
- package/lib-es/currencies/CurrencyURIScheme.js.map +1 -0
- package/lib-es/currencies/chopCurrencyUnitDecimals.d.ts +3 -0
- package/lib-es/currencies/chopCurrencyUnitDecimals.d.ts.map +1 -0
- package/lib-es/currencies/chopCurrencyUnitDecimals.js +25 -0
- package/lib-es/currencies/chopCurrencyUnitDecimals.js.map +1 -0
- package/lib-es/currencies/formatCurrencyUnit.d.ts +33 -0
- package/lib-es/currencies/formatCurrencyUnit.d.ts.map +1 -0
- package/lib-es/currencies/formatCurrencyUnit.js +121 -0
- package/lib-es/currencies/formatCurrencyUnit.js.map +1 -0
- package/lib-es/currencies/formatShort.d.ts +8 -0
- package/lib-es/currencies/formatShort.d.ts.map +1 -0
- package/lib-es/currencies/formatShort.js +20 -0
- package/lib-es/currencies/formatShort.js.map +1 -0
- package/lib-es/currencies/index.d.ts +13 -0
- package/lib-es/currencies/index.d.ts.map +1 -0
- package/lib-es/currencies/index.js +16 -0
- package/lib-es/currencies/index.js.map +1 -0
- package/lib-es/currencies/localeUtility.d.ts +8 -0
- package/lib-es/currencies/localeUtility.d.ts.map +1 -0
- package/lib-es/currencies/localeUtility.js +43 -0
- package/lib-es/currencies/localeUtility.js.map +1 -0
- package/lib-es/currencies/parseCurrencyUnit.d.ts +4 -0
- package/lib-es/currencies/parseCurrencyUnit.d.ts.map +1 -0
- package/lib-es/currencies/parseCurrencyUnit.js +14 -0
- package/lib-es/currencies/parseCurrencyUnit.js.map +1 -0
- package/lib-es/currencies/sanitizeValueString.d.ts +6 -0
- package/lib-es/currencies/sanitizeValueString.d.ts.map +1 -0
- package/lib-es/currencies/sanitizeValueString.js +52 -0
- package/lib-es/currencies/sanitizeValueString.js.map +1 -0
- package/lib-es/currencies/support.d.ts +8 -0
- package/lib-es/currencies/support.d.ts.map +1 -0
- package/lib-es/currencies/support.js +92 -0
- package/lib-es/currencies/support.js.map +1 -0
- package/lib-es/currencies/valueFromUnit.d.ts +9 -0
- package/lib-es/currencies/valueFromUnit.d.ts.map +1 -0
- package/lib-es/currencies/valueFromUnit.js +10 -0
- package/lib-es/currencies/valueFromUnit.js.map +1 -0
- package/lib-es/derivation.d.ts +232 -0
- package/lib-es/derivation.d.ts.map +1 -0
- package/lib-es/derivation.js +473 -0
- package/lib-es/derivation.js.map +1 -0
- package/lib-es/env.d.ts +30 -0
- package/lib-es/env.d.ts.map +1 -0
- package/lib-es/env.js +758 -0
- package/lib-es/env.js.map +1 -0
- package/lib-es/errors.d.ts +7 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +4 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/errors.test.d.ts +2 -0
- package/lib-es/errors.test.d.ts.map +1 -0
- package/lib-es/errors.test.js +18 -0
- package/lib-es/errors.test.js.map +1 -0
- package/lib-es/mocks/account.d.ts +25 -0
- package/lib-es/mocks/account.d.ts.map +1 -0
- package/lib-es/mocks/account.js +358 -0
- package/lib-es/mocks/account.js.map +1 -0
- package/lib-es/mocks/fixtures/nfts.d.ts +27 -0
- package/lib-es/mocks/fixtures/nfts.d.ts.map +1 -0
- package/lib-es/mocks/fixtures/nfts.js +390 -0
- package/lib-es/mocks/fixtures/nfts.js.map +1 -0
- package/lib-es/mocks/fixtures/nfts.test.d.ts +2 -0
- package/lib-es/mocks/fixtures/nfts.test.d.ts.map +1 -0
- package/lib-es/mocks/fixtures/nfts.test.js +18 -0
- package/lib-es/mocks/fixtures/nfts.test.js.map +1 -0
- package/lib-es/mocks/helpers.d.ts +15 -0
- package/lib-es/mocks/helpers.d.ts.map +1 -0
- package/lib-es/mocks/helpers.js +26 -0
- package/lib-es/mocks/helpers.js.map +1 -0
- package/lib-es/network.d.ts +5 -0
- package/lib-es/network.d.ts.map +1 -0
- package/lib-es/network.js +118 -0
- package/lib-es/network.js.map +1 -0
- package/lib-es/nft/nftId.d.ts +8 -0
- package/lib-es/nft/nftId.d.ts.map +1 -0
- package/lib-es/nft/nftId.js +29 -0
- package/lib-es/nft/nftId.js.map +1 -0
- package/lib-es/operation.d.ts +24 -0
- package/lib-es/operation.d.ts.map +1 -0
- package/lib-es/operation.js +168 -0
- package/lib-es/operation.js.map +1 -0
- package/lib-es/promise.d.ts +21 -0
- package/lib-es/promise.d.ts.map +1 -0
- package/lib-es/promise.js +179 -0
- package/lib-es/promise.js.map +1 -0
- package/lib-es/promise.test.d.ts +2 -0
- package/lib-es/promise.test.d.ts.map +1 -0
- package/lib-es/promise.test.js +70 -0
- package/lib-es/promise.test.js.map +1 -0
- package/lib-es/rangeDates.d.ts +29 -0
- package/lib-es/rangeDates.d.ts.map +1 -0
- package/lib-es/rangeDates.js +84 -0
- package/lib-es/rangeDates.js.map +1 -0
- package/lib-es/rangeDates.test.d.ts +2 -0
- package/lib-es/rangeDates.test.d.ts.map +1 -0
- package/lib-es/rangeDates.test.js +49 -0
- package/lib-es/rangeDates.test.js.map +1 -0
- package/lib-es/test-helpers/staticTime.d.ts +2 -0
- package/lib-es/test-helpers/staticTime.d.ts.map +1 -0
- package/lib-es/test-helpers/staticTime.js +5 -0
- package/lib-es/test-helpers/staticTime.js.map +1 -0
- package/lib-es/transaction/common.d.ts +26 -0
- package/lib-es/transaction/common.d.ts.map +1 -0
- package/lib-es/transaction/common.js +115 -0
- package/lib-es/transaction/common.js.map +1 -0
- package/package.json +113 -0
- package/src/__snapshots__/account.test.ts.snap +2065 -0
- package/src/__snapshots__/cross.test.ts.snap +57 -0
- package/src/account/accountId.ts +93 -0
- package/src/account/accountName.ts +25 -0
- package/src/account/addAccounts.ts +236 -0
- package/src/account/balanceHistoryCache.ts +146 -0
- package/src/account/groupOperations.ts +164 -0
- package/src/account/helpers.test.ts +441 -0
- package/src/account/helpers.ts +380 -0
- package/src/account/index.ts +10 -0
- package/src/account/ordering.ts +109 -0
- package/src/account/pending.ts +66 -0
- package/src/account/serialization.ts +189 -0
- package/src/account/support.ts +96 -0
- package/src/account.test.ts +237 -0
- package/src/bot/bot-test-context.test.ts +37 -0
- package/src/bot/bot-test-context.ts +24 -0
- package/src/bot/formatters.ts +22 -0
- package/src/bot/specs.ts +275 -0
- package/src/bot/types.ts +224 -0
- package/src/bridge/getAddressWrapper.ts +40 -0
- package/src/bridge/jsHelpers.ts +645 -0
- package/src/cache.ts +65 -0
- package/src/cross.test.ts +112 -0
- package/src/cross.ts +366 -0
- package/src/currencies/BigNumberToLocaleString.test.ts +155 -0
- package/src/currencies/BigNumberToLocaleString.ts +80 -0
- package/src/currencies/CurrencyURIScheme.ts +114 -0
- package/src/currencies/chopCurrencyUnitDecimals.ts +34 -0
- package/src/currencies/formatCurrencyUnit.ts +167 -0
- package/src/currencies/formatShort.ts +24 -0
- package/src/currencies/index.ts +78 -0
- package/src/currencies/localeUtility.ts +50 -0
- package/src/currencies/parseCurrencyUnit.ts +16 -0
- package/src/currencies/sanitizeValueString.ts +58 -0
- package/src/currencies/support.ts +107 -0
- package/src/currencies/valueFromUnit.ts +10 -0
- package/src/derivation.ts +595 -0
- package/src/env.ts +780 -0
- package/src/errors.test.ts +21 -0
- package/src/errors.ts +9 -0
- package/src/mocks/account.ts +476 -0
- package/src/mocks/fixtures/nfts.test.ts +25 -0
- package/src/mocks/fixtures/nfts.ts +432 -0
- package/src/mocks/helpers.ts +38 -0
- package/src/network.ts +135 -0
- package/src/nft/nftId.ts +26 -0
- package/src/operation.ts +212 -0
- package/src/promise.test.ts +20 -0
- package/src/promise.ts +101 -0
- package/src/rangeDates.test.ts +66 -0
- package/src/rangeDates.ts +96 -0
- package/src/test-helpers/staticTime.ts +4 -0
- package/src/transaction/common.ts +157 -0
package/src/operation.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { Account, AccountLike, Operation } from "@ledgerhq/types-live";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
|
|
4
|
+
export function findOperationInAccount(
|
|
5
|
+
{ operations, pendingOperations }: AccountLike,
|
|
6
|
+
operationId: string
|
|
7
|
+
): Operation | null | undefined {
|
|
8
|
+
for (let i = 0; i < operations.length; i++) {
|
|
9
|
+
const op = operations[i];
|
|
10
|
+
if (op.id === operationId) return op;
|
|
11
|
+
|
|
12
|
+
if (op.internalOperations) {
|
|
13
|
+
const internalOps = op.internalOperations;
|
|
14
|
+
|
|
15
|
+
for (let j = 0; j < internalOps.length; j++) {
|
|
16
|
+
const internalOp = internalOps[j];
|
|
17
|
+
if (internalOp.id === operationId) return internalOp;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (op.nftOperations) {
|
|
22
|
+
const nftOps = op.nftOperations;
|
|
23
|
+
|
|
24
|
+
for (let j = 0; j < nftOps.length; j++) {
|
|
25
|
+
const nftOp = nftOps[j];
|
|
26
|
+
|
|
27
|
+
if (nftOp.id === operationId) return nftOp;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (let i = 0; i < pendingOperations.length; i++) {
|
|
33
|
+
const op = pendingOperations[i];
|
|
34
|
+
if (op.id === operationId) return op;
|
|
35
|
+
|
|
36
|
+
if (op.nftOperations) {
|
|
37
|
+
const nftOps = op.nftOperations;
|
|
38
|
+
|
|
39
|
+
for (let j = 0; j < nftOps.length; j++) {
|
|
40
|
+
const nftOp = nftOps[j];
|
|
41
|
+
|
|
42
|
+
if (nftOp.id === operationId) return nftOp;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function encodeOperationId(
|
|
51
|
+
accountId: string,
|
|
52
|
+
hash: string,
|
|
53
|
+
type: string
|
|
54
|
+
): string {
|
|
55
|
+
return `${accountId}-${hash}-${type}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function decodeOperationId(id: string): {
|
|
59
|
+
accountId: string;
|
|
60
|
+
hash: string;
|
|
61
|
+
type: string;
|
|
62
|
+
} {
|
|
63
|
+
const [accountId, hash, type] = id.split("-");
|
|
64
|
+
return {
|
|
65
|
+
accountId,
|
|
66
|
+
hash,
|
|
67
|
+
type,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function encodeSubOperationId(
|
|
72
|
+
accountId: string,
|
|
73
|
+
hash: string,
|
|
74
|
+
type: string,
|
|
75
|
+
index: string | number
|
|
76
|
+
): string {
|
|
77
|
+
return `${accountId}-${hash}-${type}-i${index}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function decodeSubOperationId(id: string): {
|
|
81
|
+
accountId: string;
|
|
82
|
+
hash: string;
|
|
83
|
+
type: string;
|
|
84
|
+
index: number;
|
|
85
|
+
} {
|
|
86
|
+
const [accountId, hash, type, index] = id.split("-");
|
|
87
|
+
return {
|
|
88
|
+
accountId,
|
|
89
|
+
hash,
|
|
90
|
+
type,
|
|
91
|
+
index: Number(index),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function patchOperationWithHash(
|
|
96
|
+
operation: Operation,
|
|
97
|
+
hash: string
|
|
98
|
+
): Operation {
|
|
99
|
+
return {
|
|
100
|
+
...operation,
|
|
101
|
+
hash,
|
|
102
|
+
id: encodeOperationId(operation.accountId, hash, operation.type),
|
|
103
|
+
subOperations:
|
|
104
|
+
operation.subOperations &&
|
|
105
|
+
operation.subOperations.map((op) => ({
|
|
106
|
+
...op,
|
|
107
|
+
hash,
|
|
108
|
+
id: encodeOperationId(op.accountId, hash, op.type),
|
|
109
|
+
})),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function flattenOperationWithInternalsAndNfts(
|
|
114
|
+
op: Operation
|
|
115
|
+
): Operation[] {
|
|
116
|
+
let ops: Operation[] = [];
|
|
117
|
+
|
|
118
|
+
// ops of type NONE does not appear in lists
|
|
119
|
+
if (op.type !== "NONE") {
|
|
120
|
+
ops.push(op);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// all internal operations are expanded after the main op
|
|
124
|
+
if (op.internalOperations) {
|
|
125
|
+
ops = ops.concat(op.internalOperations);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// all nfts operations are expanded after the main op
|
|
129
|
+
if (op.nftOperations) {
|
|
130
|
+
ops = ops.concat(op.nftOperations);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return ops;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function getOperationAmountNumber(op: Operation): BigNumber {
|
|
137
|
+
switch (op.type) {
|
|
138
|
+
case "IN":
|
|
139
|
+
case "REWARD":
|
|
140
|
+
case "REWARD_PAYOUT":
|
|
141
|
+
case "SUPPLY":
|
|
142
|
+
case "WITHDRAW":
|
|
143
|
+
return op.value;
|
|
144
|
+
|
|
145
|
+
case "OUT":
|
|
146
|
+
case "REVEAL":
|
|
147
|
+
case "CREATE":
|
|
148
|
+
case "FEES":
|
|
149
|
+
case "DELEGATE":
|
|
150
|
+
case "REDELEGATE":
|
|
151
|
+
case "UNDELEGATE":
|
|
152
|
+
case "OPT_IN":
|
|
153
|
+
case "OPT_OUT":
|
|
154
|
+
case "REDEEM":
|
|
155
|
+
case "SLASH":
|
|
156
|
+
case "LOCK":
|
|
157
|
+
return op.value.negated();
|
|
158
|
+
|
|
159
|
+
case "FREEZE":
|
|
160
|
+
case "UNFREEZE":
|
|
161
|
+
case "VOTE":
|
|
162
|
+
case "BOND":
|
|
163
|
+
case "UNBOND":
|
|
164
|
+
case "WITHDRAW_UNBONDED":
|
|
165
|
+
case "SET_CONTROLLER":
|
|
166
|
+
case "NOMINATE":
|
|
167
|
+
case "CHILL":
|
|
168
|
+
case "REVOKE":
|
|
169
|
+
case "APPROVE":
|
|
170
|
+
case "ACTIVATE":
|
|
171
|
+
case "UNLOCK":
|
|
172
|
+
case "STAKE":
|
|
173
|
+
case "UNSTAKE":
|
|
174
|
+
case "WITHDRAW_UNSTAKED":
|
|
175
|
+
return op.fee.negated();
|
|
176
|
+
|
|
177
|
+
default:
|
|
178
|
+
return new BigNumber(0);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function getOperationAmountNumberWithInternals(
|
|
183
|
+
op: Operation
|
|
184
|
+
): BigNumber {
|
|
185
|
+
return flattenOperationWithInternalsAndNfts(op).reduce(
|
|
186
|
+
(amount: BigNumber, op) => amount.plus(getOperationAmountNumber(op)),
|
|
187
|
+
new BigNumber(0)
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export const getOperationConfirmationNumber = (
|
|
192
|
+
operation: Operation,
|
|
193
|
+
account: Account
|
|
194
|
+
): number =>
|
|
195
|
+
operation.blockHeight ? account.blockHeight - operation.blockHeight + 1 : 0;
|
|
196
|
+
|
|
197
|
+
export const getOperationConfirmationDisplayableNumber = (
|
|
198
|
+
operation: Operation,
|
|
199
|
+
account: Account
|
|
200
|
+
): string =>
|
|
201
|
+
account.blockHeight && operation.blockHeight && account.currency.blockAvgTime
|
|
202
|
+
? String(account.blockHeight - operation.blockHeight + 1)
|
|
203
|
+
: "";
|
|
204
|
+
|
|
205
|
+
export const isConfirmedOperation = (
|
|
206
|
+
operation: Operation,
|
|
207
|
+
account: Account,
|
|
208
|
+
confirmationsNb: number
|
|
209
|
+
): boolean =>
|
|
210
|
+
operation.blockHeight
|
|
211
|
+
? account.blockHeight - operation.blockHeight + 1 >= confirmationsNb
|
|
212
|
+
: false;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { promiseAllBatched } from "./promise";
|
|
2
|
+
test("promiseAllBatched", async () => {
|
|
3
|
+
const promisifyIdPlusOne = (a: number) => Promise.resolve(a + 1);
|
|
4
|
+
|
|
5
|
+
const p = promiseAllBatched(5, [], promisifyIdPlusOne);
|
|
6
|
+
expect(typeof p.then).toBe("function");
|
|
7
|
+
expect(await p).toEqual([]);
|
|
8
|
+
expect(
|
|
9
|
+
await promiseAllBatched(5, [1, 2, 3, 4, 5, 6, 7, 8], promisifyIdPlusOne)
|
|
10
|
+
).toEqual([2, 3, 4, 5, 6, 7, 8, 9]);
|
|
11
|
+
expect(
|
|
12
|
+
await promiseAllBatched(1, [1, 2, 3, 4, 5, 6, 7, 8], promisifyIdPlusOne)
|
|
13
|
+
).toEqual([2, 3, 4, 5, 6, 7, 8, 9]);
|
|
14
|
+
expect(
|
|
15
|
+
await promiseAllBatched(10, [1, 2, 3, 4, 5, 6, 7, 8], promisifyIdPlusOne)
|
|
16
|
+
).toEqual([2, 3, 4, 5, 6, 7, 8, 9]);
|
|
17
|
+
expect(
|
|
18
|
+
await promiseAllBatched(2, Array(6).fill(0), (_, i) => Promise.resolve(i))
|
|
19
|
+
).toEqual([0, 1, 2, 3, 4, 5]);
|
|
20
|
+
});
|
package/src/promise.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { log } from "@ledgerhq/logs";
|
|
2
|
+
export const delay = (ms: number): Promise<void> =>
|
|
3
|
+
new Promise((f) => setTimeout(f, ms));
|
|
4
|
+
const defaults = {
|
|
5
|
+
maxRetry: 4,
|
|
6
|
+
interval: 300,
|
|
7
|
+
intervalMultiplicator: 1.5,
|
|
8
|
+
context: "",
|
|
9
|
+
};
|
|
10
|
+
export function retry<A>(
|
|
11
|
+
f: () => Promise<A>,
|
|
12
|
+
options?: Partial<typeof defaults>
|
|
13
|
+
): Promise<A> {
|
|
14
|
+
const { maxRetry, interval, intervalMultiplicator, context } = {
|
|
15
|
+
...defaults,
|
|
16
|
+
...options,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function rec(remainingTry: number, i: number): Promise<A> {
|
|
20
|
+
const result = f();
|
|
21
|
+
|
|
22
|
+
if (remainingTry <= 0) {
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// In case of failure, wait the interval, retry the action
|
|
27
|
+
return result.catch((e) => {
|
|
28
|
+
log(
|
|
29
|
+
"promise-retry",
|
|
30
|
+
context + " failed. " + remainingTry + " retry remain. " + String(e)
|
|
31
|
+
);
|
|
32
|
+
return delay(i).then(() =>
|
|
33
|
+
rec(remainingTry - 1, i * intervalMultiplicator)
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return rec(maxRetry, interval);
|
|
39
|
+
}
|
|
40
|
+
type Job<R, A extends Array<any>> = (...args: A) => Promise<R>;
|
|
41
|
+
export const atomicQueue = <R, A extends Array<any>>(
|
|
42
|
+
job: Job<R, A>,
|
|
43
|
+
queueIdentifier: (...args: A) => string = () => ""
|
|
44
|
+
): Job<R, A> => {
|
|
45
|
+
const queues: Record<string, any> = {};
|
|
46
|
+
return (...args) => {
|
|
47
|
+
const id = queueIdentifier(...args);
|
|
48
|
+
const queue = queues[id] || Promise.resolve();
|
|
49
|
+
const p = queue.then(() => job(...args));
|
|
50
|
+
queues[id] = p.catch(() => {});
|
|
51
|
+
return p;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export function execAndWaitAtLeast<A>(
|
|
55
|
+
ms: number,
|
|
56
|
+
cb: () => Promise<A>
|
|
57
|
+
): Promise<A> {
|
|
58
|
+
const startTime = Date.now();
|
|
59
|
+
return cb().then((r) => {
|
|
60
|
+
const remaining = ms - (Date.now() - startTime);
|
|
61
|
+
if (remaining <= 0) return r;
|
|
62
|
+
return delay(remaining).then(() => r);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* promiseAllBatched(n, items, i => f(i))
|
|
68
|
+
* is essentially like
|
|
69
|
+
* Promise.all(items.map(i => f(i)))
|
|
70
|
+
* but with a guarantee that it will not create more than n concurrent call to f
|
|
71
|
+
* where f is a function that returns a promise
|
|
72
|
+
*/
|
|
73
|
+
export async function promiseAllBatched<A, B>(
|
|
74
|
+
batch: number,
|
|
75
|
+
items: Array<A>,
|
|
76
|
+
fn: (arg0: A, arg1: number) => Promise<B>
|
|
77
|
+
): Promise<B[]> {
|
|
78
|
+
const data = Array(items.length);
|
|
79
|
+
const queue = items.map((item, index) => ({
|
|
80
|
+
item,
|
|
81
|
+
index,
|
|
82
|
+
}));
|
|
83
|
+
|
|
84
|
+
async function step() {
|
|
85
|
+
if (queue.length === 0) return;
|
|
86
|
+
const first = queue.shift();
|
|
87
|
+
if (first) {
|
|
88
|
+
const { item, index } = first;
|
|
89
|
+
data[index] = await fn(item, index);
|
|
90
|
+
}
|
|
91
|
+
await step(); // each time an item redeem, we schedule another one
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// initially, we schedule <batch> items in parallel
|
|
95
|
+
await Promise.all(
|
|
96
|
+
Array(Math.min(batch, items.length))
|
|
97
|
+
.fill(() => undefined)
|
|
98
|
+
.map(step)
|
|
99
|
+
);
|
|
100
|
+
return data;
|
|
101
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
startOfHour,
|
|
3
|
+
startOfMonth,
|
|
4
|
+
startOfDay,
|
|
5
|
+
startOfWeek,
|
|
6
|
+
getPortfolioRangeConfig,
|
|
7
|
+
getDates,
|
|
8
|
+
getRanges,
|
|
9
|
+
} from "./rangeDates";
|
|
10
|
+
|
|
11
|
+
describe("startOfHour", () => {
|
|
12
|
+
test("basic test", () => {
|
|
13
|
+
expect(startOfHour(new Date(1655827384305)).toISOString()).toBe(
|
|
14
|
+
"2022-06-21T16:00:00.000Z"
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
describe("startOfDay", () => {
|
|
19
|
+
test("basic test", () => {
|
|
20
|
+
expect(startOfDay(new Date(1655827384305)).toISOString()).toBe(
|
|
21
|
+
"2022-06-21T04:00:00.000Z"
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe("startOfMonth", () => {
|
|
26
|
+
test("basic test", () => {
|
|
27
|
+
expect(startOfMonth(new Date(1655827384305)).toISOString()).toBe(
|
|
28
|
+
"2022-06-01T04:00:00.000Z"
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe("startOfWeek", () => {
|
|
33
|
+
test("basic test", () => {
|
|
34
|
+
expect(startOfWeek(new Date(1655827384305)).toISOString()).toBe(
|
|
35
|
+
"2022-06-19T04:00:00.000Z"
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe("getPortfolioRangeConfig", () => {
|
|
40
|
+
test("returns a value for day", () => {
|
|
41
|
+
expect(getPortfolioRangeConfig("day")).toBeDefined();
|
|
42
|
+
});
|
|
43
|
+
test("returns a value for week", () => {
|
|
44
|
+
expect(getPortfolioRangeConfig("week")).toBeDefined();
|
|
45
|
+
});
|
|
46
|
+
test("returns a value for month", () => {
|
|
47
|
+
expect(getPortfolioRangeConfig("month")).toBeDefined();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe("getDates", () => {
|
|
51
|
+
test("day returns an array of asked size", () => {
|
|
52
|
+
expect(getDates("day", 100).length).toEqual(100);
|
|
53
|
+
});
|
|
54
|
+
test("week returns an array of asked size", () => {
|
|
55
|
+
expect(getDates("week", 100).length).toEqual(100);
|
|
56
|
+
});
|
|
57
|
+
test("month returns an array of asked size", () => {
|
|
58
|
+
expect(getDates("month", 100).length).toEqual(100);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("getRanges", () => {
|
|
63
|
+
test("returns a non empty array", () => {
|
|
64
|
+
expect(getRanges().length).toBeGreaterThan(0);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PortfolioRangeConfig,
|
|
3
|
+
PortfolioRange,
|
|
4
|
+
} from "@ledgerhq/types-live";
|
|
5
|
+
|
|
6
|
+
export const hourIncrement = 60 * 60 * 1000;
|
|
7
|
+
export const dayIncrement = 24 * hourIncrement;
|
|
8
|
+
export const weekIncrement = 7 * dayIncrement;
|
|
9
|
+
|
|
10
|
+
export function startOfHour(t: Date): Date {
|
|
11
|
+
return new Date(t.getFullYear(), t.getMonth(), t.getDate(), t.getHours());
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function startOfMonth(t: Date): Date {
|
|
15
|
+
return new Date(t.getFullYear(), t.getMonth(), 1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function startOfDay(t: Date): Date {
|
|
19
|
+
return new Date(t.getFullYear(), t.getMonth(), t.getDate());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function startOfWeek(t: Date): Date {
|
|
23
|
+
const d = startOfDay(t);
|
|
24
|
+
return new Date(d.getTime() - d.getDay() * dayIncrement);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getPortfolioRangeConfig(
|
|
28
|
+
r: PortfolioRange
|
|
29
|
+
): PortfolioRangeConfig {
|
|
30
|
+
return ranges[r];
|
|
31
|
+
}
|
|
32
|
+
export const granularities = {
|
|
33
|
+
WEEK: {
|
|
34
|
+
increment: weekIncrement,
|
|
35
|
+
startOf: startOfWeek,
|
|
36
|
+
maxDatapoints: 1000, // (essentially no limit)
|
|
37
|
+
},
|
|
38
|
+
DAY: {
|
|
39
|
+
increment: dayIncrement,
|
|
40
|
+
startOf: startOfDay,
|
|
41
|
+
maxDatapoints: 400, // we only need a year
|
|
42
|
+
},
|
|
43
|
+
HOUR: {
|
|
44
|
+
increment: hourIncrement,
|
|
45
|
+
startOf: startOfHour,
|
|
46
|
+
maxDatapoints: 8 * 24, // we only need a week
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
// TODO Protfolio: this would require to introduce Account#olderOperationDate
|
|
50
|
+
const ranges: Record<PortfolioRange, PortfolioRangeConfig> = {
|
|
51
|
+
all: {
|
|
52
|
+
increment: weekIncrement,
|
|
53
|
+
startOf: startOfWeek,
|
|
54
|
+
granularityId: "WEEK",
|
|
55
|
+
},
|
|
56
|
+
year: {
|
|
57
|
+
count: 52,
|
|
58
|
+
increment: weekIncrement,
|
|
59
|
+
startOf: startOfWeek,
|
|
60
|
+
granularityId: "WEEK",
|
|
61
|
+
},
|
|
62
|
+
month: {
|
|
63
|
+
count: 30,
|
|
64
|
+
increment: dayIncrement,
|
|
65
|
+
startOf: startOfDay,
|
|
66
|
+
granularityId: "DAY",
|
|
67
|
+
},
|
|
68
|
+
week: {
|
|
69
|
+
count: 7 * 24,
|
|
70
|
+
increment: hourIncrement,
|
|
71
|
+
startOf: startOfHour,
|
|
72
|
+
granularityId: "HOUR",
|
|
73
|
+
},
|
|
74
|
+
day: {
|
|
75
|
+
count: 24,
|
|
76
|
+
increment: hourIncrement,
|
|
77
|
+
startOf: startOfHour,
|
|
78
|
+
granularityId: "HOUR",
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
export function getDates(r: PortfolioRange, count: number): Date[] {
|
|
82
|
+
const now = new Date(Date.now());
|
|
83
|
+
if (count === 1) return [now];
|
|
84
|
+
const conf = getPortfolioRangeConfig(r);
|
|
85
|
+
const last = new Date((conf.startOf(now) as any) - 1);
|
|
86
|
+
const dates = [now];
|
|
87
|
+
|
|
88
|
+
for (let i = 0; i < count - 1; i++) {
|
|
89
|
+
dates.unshift(new Date((last as any) - conf.increment * i));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return dates;
|
|
93
|
+
}
|
|
94
|
+
export function getRanges(): string[] {
|
|
95
|
+
return Object.keys(ranges);
|
|
96
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { deserializeError, serializeError } from "@ledgerhq/errors";
|
|
2
|
+
import type {
|
|
3
|
+
Account,
|
|
4
|
+
TransactionCommon,
|
|
5
|
+
TransactionCommonRaw,
|
|
6
|
+
TransactionStatusCommon,
|
|
7
|
+
TransactionStatusCommonRaw,
|
|
8
|
+
} from "@ledgerhq/types-live";
|
|
9
|
+
import { BigNumber } from "bignumber.js";
|
|
10
|
+
import { mapValues } from "lodash";
|
|
11
|
+
|
|
12
|
+
import { getAccountUnit } from "../account";
|
|
13
|
+
import { formatCurrencyUnit } from "../currencies";
|
|
14
|
+
|
|
15
|
+
type tooltipArgs = Record<string, string>;
|
|
16
|
+
export type CommonDeviceTransactionField =
|
|
17
|
+
| {
|
|
18
|
+
type: "amount";
|
|
19
|
+
label: string;
|
|
20
|
+
}
|
|
21
|
+
| {
|
|
22
|
+
type: "address";
|
|
23
|
+
label: string;
|
|
24
|
+
address: string;
|
|
25
|
+
}
|
|
26
|
+
| {
|
|
27
|
+
type: "fees";
|
|
28
|
+
label: string;
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
type: "text";
|
|
32
|
+
label: string;
|
|
33
|
+
value: string;
|
|
34
|
+
tooltipI18nKey?: string;
|
|
35
|
+
tooltipI18nArgs?: tooltipArgs;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const fromTransactionCommonRaw = (
|
|
39
|
+
raw: TransactionCommonRaw
|
|
40
|
+
): TransactionCommon => {
|
|
41
|
+
const common: TransactionCommon = {
|
|
42
|
+
amount: new BigNumber(raw.amount),
|
|
43
|
+
recipient: raw.recipient,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
if ("useAllAmount" in raw) {
|
|
47
|
+
common.useAllAmount = raw.useAllAmount;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if ("subAccountId" in raw) {
|
|
51
|
+
common.subAccountId = raw.subAccountId;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return common;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const toTransactionCommonRaw = (
|
|
58
|
+
raw: TransactionCommon
|
|
59
|
+
): TransactionCommonRaw => {
|
|
60
|
+
const common: TransactionCommonRaw = {
|
|
61
|
+
amount: raw.amount.toString(),
|
|
62
|
+
recipient: raw.recipient,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
if ("useAllAmount" in raw) {
|
|
66
|
+
common.useAllAmount = raw.useAllAmount;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if ("subAccountId" in raw) {
|
|
70
|
+
common.subAccountId = raw.subAccountId;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return common;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const fromErrorRaw = (raw: string): Error => {
|
|
77
|
+
return deserializeError(JSON.parse(raw)) || new Error("unknown reason");
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const toErrorRaw = (raw: Error): string =>
|
|
81
|
+
JSON.stringify(serializeError(raw)) || "{}";
|
|
82
|
+
|
|
83
|
+
export const fromTransactionStatusRawCommon = (
|
|
84
|
+
ts: TransactionStatusCommonRaw
|
|
85
|
+
): TransactionStatusCommon => ({
|
|
86
|
+
errors: mapValues(ts.errors, fromErrorRaw),
|
|
87
|
+
warnings: mapValues(ts.warnings, fromErrorRaw),
|
|
88
|
+
estimatedFees: new BigNumber(ts.estimatedFees),
|
|
89
|
+
amount: new BigNumber(ts.amount),
|
|
90
|
+
totalSpent: new BigNumber(ts.totalSpent),
|
|
91
|
+
recipientIsReadOnly: ts.recipientIsReadOnly,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
export const toTransactionStatusRawCommon = (
|
|
95
|
+
ts: TransactionStatusCommon
|
|
96
|
+
): TransactionStatusCommonRaw => ({
|
|
97
|
+
errors: mapValues<Record<string, Error>, string>(ts.errors, toErrorRaw),
|
|
98
|
+
warnings: mapValues<Record<string, Error>, string>(ts.warnings, toErrorRaw),
|
|
99
|
+
estimatedFees: ts.estimatedFees.toString(),
|
|
100
|
+
amount: ts.amount.toString(),
|
|
101
|
+
totalSpent: ts.totalSpent.toString(),
|
|
102
|
+
recipientIsReadOnly: ts.recipientIsReadOnly,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const formatErrorSmall = (e: Error): string =>
|
|
106
|
+
e.name === "Error" ? e.message : e.name;
|
|
107
|
+
|
|
108
|
+
export const formatTransactionStatusCommon = (
|
|
109
|
+
t: TransactionCommon,
|
|
110
|
+
{
|
|
111
|
+
errors,
|
|
112
|
+
warnings,
|
|
113
|
+
estimatedFees,
|
|
114
|
+
amount,
|
|
115
|
+
totalSpent,
|
|
116
|
+
}: TransactionStatusCommon,
|
|
117
|
+
mainAccount: Account
|
|
118
|
+
): string => {
|
|
119
|
+
let str = "";
|
|
120
|
+
const account =
|
|
121
|
+
(t.subAccountId &&
|
|
122
|
+
(mainAccount.subAccounts || []).find((a) => a.id === t.subAccountId)) ||
|
|
123
|
+
mainAccount;
|
|
124
|
+
|
|
125
|
+
str +=
|
|
126
|
+
"\n amount: " +
|
|
127
|
+
formatCurrencyUnit(getAccountUnit(account), amount, {
|
|
128
|
+
showCode: true,
|
|
129
|
+
disableRounding: true,
|
|
130
|
+
});
|
|
131
|
+
str +=
|
|
132
|
+
"\n estimated fees: " +
|
|
133
|
+
formatCurrencyUnit(getAccountUnit(mainAccount), estimatedFees, {
|
|
134
|
+
showCode: true,
|
|
135
|
+
disableRounding: true,
|
|
136
|
+
});
|
|
137
|
+
str +=
|
|
138
|
+
"\n total spent: " +
|
|
139
|
+
formatCurrencyUnit(getAccountUnit(account), totalSpent, {
|
|
140
|
+
showCode: true,
|
|
141
|
+
disableRounding: true,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
str +=
|
|
145
|
+
"\n" +
|
|
146
|
+
`errors: ${Object.entries(errors)
|
|
147
|
+
.map(([key, error]) => `${key} ${formatErrorSmall(error)}`)
|
|
148
|
+
.join(", ")}`;
|
|
149
|
+
|
|
150
|
+
str +=
|
|
151
|
+
"\n" +
|
|
152
|
+
`errors: ${Object.entries(warnings)
|
|
153
|
+
.map(([key, warning]) => `${key} ${formatErrorSmall(warning)}`)
|
|
154
|
+
.join(", ")}`;
|
|
155
|
+
|
|
156
|
+
return str;
|
|
157
|
+
};
|