@ledgerhq/coin-framework 0.0.2-next.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/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 +783 -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 +768 -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 +790 -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
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { genAccount } from "./mocks/account";
|
|
2
|
+
import { getDerivationModesForCurrency } from "./derivation";
|
|
3
|
+
import { listCryptoCurrencies, setSupportedCurrencies } from "./currencies";
|
|
4
|
+
import {
|
|
5
|
+
accountDataToAccount,
|
|
6
|
+
accountToAccountData,
|
|
7
|
+
encode,
|
|
8
|
+
decode,
|
|
9
|
+
} from "./cross";
|
|
10
|
+
import { Account } from "@ledgerhq/types-live";
|
|
11
|
+
|
|
12
|
+
setSupportedCurrencies(["ethereum", "ethereum_classic"]);
|
|
13
|
+
|
|
14
|
+
test("accountDataToAccount / accountToAccountData", () => {
|
|
15
|
+
listCryptoCurrencies().forEach((currency) => {
|
|
16
|
+
getDerivationModesForCurrency(currency).forEach((derivationMode) => {
|
|
17
|
+
const account = genAccount(`${currency.id}_${derivationMode}`, {
|
|
18
|
+
currency,
|
|
19
|
+
});
|
|
20
|
+
const data = accountToAccountData(account);
|
|
21
|
+
expect(accountToAccountData(accountDataToAccount(data))).toMatchObject(
|
|
22
|
+
data
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
test("encode/decode", () => {
|
|
28
|
+
const accounts = listCryptoCurrencies().reduce(
|
|
29
|
+
(acc: Account[], currency) =>
|
|
30
|
+
acc.concat(
|
|
31
|
+
getDerivationModesForCurrency(currency).map((derivationMode) => {
|
|
32
|
+
const account = genAccount(`${currency.id}_${derivationMode}`, {
|
|
33
|
+
currency,
|
|
34
|
+
});
|
|
35
|
+
return account;
|
|
36
|
+
})
|
|
37
|
+
),
|
|
38
|
+
<Account[]>[]
|
|
39
|
+
);
|
|
40
|
+
const data = {
|
|
41
|
+
accounts,
|
|
42
|
+
settings: {
|
|
43
|
+
currenciesSettings: {},
|
|
44
|
+
pairExchanges: {},
|
|
45
|
+
},
|
|
46
|
+
exporterName: "test你好👋",
|
|
47
|
+
exporterVersion: "0.0.0",
|
|
48
|
+
};
|
|
49
|
+
const exp = decode(encode(data));
|
|
50
|
+
expect(exp.meta.exporterName).toEqual(data.exporterName);
|
|
51
|
+
expect(exp.accounts.length).toEqual(data.accounts.length);
|
|
52
|
+
expect(exp.accounts).toMatchObject(data.accounts.map(accountToAccountData));
|
|
53
|
+
});
|
|
54
|
+
test("encode/decode", () => {
|
|
55
|
+
const accounts = Array(3)
|
|
56
|
+
.fill(null)
|
|
57
|
+
.map((_, i) => genAccount("export_" + i));
|
|
58
|
+
const arg = {
|
|
59
|
+
accounts,
|
|
60
|
+
settings: {
|
|
61
|
+
counterValue: "USD",
|
|
62
|
+
pairExchanges: {
|
|
63
|
+
BTC_USD: "KRAKEN",
|
|
64
|
+
},
|
|
65
|
+
currenciesSettings: {
|
|
66
|
+
bitcoin: {
|
|
67
|
+
confirmationsNb: 3,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
blacklistedTokenIds: ["tokenid1", "tokenid2"],
|
|
71
|
+
},
|
|
72
|
+
exporterName: "test",
|
|
73
|
+
exporterVersion: "0.0.0",
|
|
74
|
+
chunkSize: 100,
|
|
75
|
+
};
|
|
76
|
+
const data = encode(arg);
|
|
77
|
+
const res = decode(data);
|
|
78
|
+
expect(res.accounts).toMatchObject(
|
|
79
|
+
accounts.map((a) => ({
|
|
80
|
+
balance: a.balance.toString(),
|
|
81
|
+
currencyId: a.currency.id,
|
|
82
|
+
id: a.id,
|
|
83
|
+
name: a.name,
|
|
84
|
+
index: a.index,
|
|
85
|
+
}))
|
|
86
|
+
);
|
|
87
|
+
expect(res.settings).toMatchObject({
|
|
88
|
+
counterValue: "USD",
|
|
89
|
+
pairExchanges: {
|
|
90
|
+
BTC_USD: "KRAKEN",
|
|
91
|
+
},
|
|
92
|
+
currenciesSettings: {
|
|
93
|
+
bitcoin: {
|
|
94
|
+
confirmationsNb: 3,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
blacklistedTokenIds: ["tokenid1", "tokenid2"],
|
|
98
|
+
});
|
|
99
|
+
expect(res.settings).not.toMatchObject({
|
|
100
|
+
counterValue: "USD",
|
|
101
|
+
pairExchanges: {
|
|
102
|
+
BTC_USD: "KRAKEN",
|
|
103
|
+
},
|
|
104
|
+
currenciesSettings: {
|
|
105
|
+
bitcoin: {
|
|
106
|
+
confirmationsNb: 3,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
blacklistedTokenIds: ["tokenid3"],
|
|
110
|
+
});
|
|
111
|
+
expect(res).toMatchSnapshot();
|
|
112
|
+
});
|
package/src/cross.ts
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
// cross helps dealing with cross-project feature like export/import & cross project conversions
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
import compressjs from "@ledgerhq/compressjs";
|
|
4
|
+
import {
|
|
5
|
+
runDerivationScheme,
|
|
6
|
+
getDerivationScheme,
|
|
7
|
+
asDerivationMode,
|
|
8
|
+
} from "./derivation";
|
|
9
|
+
import { decodeAccountId, emptyHistoryCache } from "./account";
|
|
10
|
+
import { getCryptoCurrencyById } from "./currencies";
|
|
11
|
+
import type { Account, CryptoCurrencyIds } from "@ledgerhq/types-live";
|
|
12
|
+
|
|
13
|
+
export type AccountData = {
|
|
14
|
+
id: string;
|
|
15
|
+
currencyId: string;
|
|
16
|
+
freshAddress?: string;
|
|
17
|
+
seedIdentifier: string;
|
|
18
|
+
derivationMode: string;
|
|
19
|
+
// we are unsafe at this stage, validation is done later
|
|
20
|
+
name: string;
|
|
21
|
+
index: number;
|
|
22
|
+
balance: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type CryptoSettings = {
|
|
26
|
+
confirmationsNb?: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type Settings = {
|
|
30
|
+
counterValue?: string;
|
|
31
|
+
currenciesSettings: Record<CryptoCurrencyIds, CryptoSettings>;
|
|
32
|
+
pairExchanges: Record<string, string | null | undefined>;
|
|
33
|
+
blacklistedTokenIds?: string[];
|
|
34
|
+
hideEmptyTokenAccounts?: boolean;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type DataIn = {
|
|
38
|
+
// accounts to export (filter them to only be the visible ones)
|
|
39
|
+
accounts: Account[];
|
|
40
|
+
// settings
|
|
41
|
+
settings: Settings;
|
|
42
|
+
// the name of the exporter. e.g. "desktop" for the desktop app
|
|
43
|
+
exporterName: string;
|
|
44
|
+
// the version of the exporter. e.g. the desktop app version
|
|
45
|
+
exporterVersion: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type Meta = {
|
|
49
|
+
exporterName: string;
|
|
50
|
+
exporterVersion: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type Result = {
|
|
54
|
+
accounts: AccountData[];
|
|
55
|
+
settings: Settings;
|
|
56
|
+
meta: Meta;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export function encode({
|
|
60
|
+
accounts,
|
|
61
|
+
settings,
|
|
62
|
+
exporterName,
|
|
63
|
+
exporterVersion,
|
|
64
|
+
}: DataIn): string {
|
|
65
|
+
return Buffer.from(
|
|
66
|
+
compressjs.Bzip2.compressFile(
|
|
67
|
+
Buffer.from(
|
|
68
|
+
JSON.stringify({
|
|
69
|
+
meta: {
|
|
70
|
+
exporterName,
|
|
71
|
+
exporterVersion,
|
|
72
|
+
},
|
|
73
|
+
accounts: accounts.map(accountToAccountData),
|
|
74
|
+
settings,
|
|
75
|
+
})
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
).toString("binary");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const asResultMeta = (unsafe: Record<string, any>): Meta => {
|
|
82
|
+
if (typeof unsafe !== "object" || !unsafe) {
|
|
83
|
+
throw new Error("invalid meta data");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const { exporterName, exporterVersion } = unsafe;
|
|
87
|
+
|
|
88
|
+
if (typeof exporterName !== "string") {
|
|
89
|
+
throw new Error("invalid meta.exporterName");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (typeof exporterVersion !== "string") {
|
|
93
|
+
throw new Error("invalid meta.exporterVersion");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
exporterName,
|
|
98
|
+
exporterVersion,
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const asResultAccount = (unsafe: Record<string, any>): AccountData => {
|
|
103
|
+
if (typeof unsafe !== "object" || !unsafe) {
|
|
104
|
+
throw new Error("invalid account data");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const {
|
|
108
|
+
id,
|
|
109
|
+
currencyId,
|
|
110
|
+
freshAddress,
|
|
111
|
+
seedIdentifier,
|
|
112
|
+
derivationMode,
|
|
113
|
+
name,
|
|
114
|
+
index,
|
|
115
|
+
balance,
|
|
116
|
+
} = unsafe;
|
|
117
|
+
|
|
118
|
+
if (typeof id !== "string") {
|
|
119
|
+
throw new Error("invalid account.id");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (typeof currencyId !== "string") {
|
|
123
|
+
throw new Error("invalid account.currencyId");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (typeof seedIdentifier !== "string") {
|
|
127
|
+
throw new Error("invalid account.seedIdentifier");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (typeof derivationMode !== "string") {
|
|
131
|
+
throw new Error("invalid account.derivationMode");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (typeof name !== "string") {
|
|
135
|
+
throw new Error("invalid account.name");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (typeof index !== "number") {
|
|
139
|
+
throw new Error("invalid account.index");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (typeof balance !== "string") {
|
|
143
|
+
throw new Error("invalid account.balance");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const o: AccountData = {
|
|
147
|
+
id,
|
|
148
|
+
currencyId,
|
|
149
|
+
seedIdentifier,
|
|
150
|
+
derivationMode,
|
|
151
|
+
name,
|
|
152
|
+
index,
|
|
153
|
+
balance,
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
if (typeof freshAddress === "string" && freshAddress) {
|
|
157
|
+
o.freshAddress = freshAddress;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return o;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const asResultAccounts = (unsafe: unknown): AccountData[] => {
|
|
164
|
+
if (typeof unsafe !== "object" || !unsafe || !Array.isArray(unsafe)) {
|
|
165
|
+
throw new Error("invalid accounts data");
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return unsafe.map(asResultAccount);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const asCryptoSettings = (unsafe: Record<string, any>): CryptoSettings => {
|
|
172
|
+
if (typeof unsafe !== "object" || !unsafe) {
|
|
173
|
+
throw new Error("invalid currency settings data");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const { confirmationsNb } = unsafe;
|
|
177
|
+
|
|
178
|
+
if (typeof confirmationsNb === "number") {
|
|
179
|
+
return {
|
|
180
|
+
confirmationsNb,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return {};
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const asResultSettings = (unsafe: Record<string, any>): Settings => {
|
|
188
|
+
if (typeof unsafe !== "object" || !unsafe) {
|
|
189
|
+
throw new Error("invalid settings data");
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const {
|
|
193
|
+
counterValue,
|
|
194
|
+
currenciesSettings,
|
|
195
|
+
pairExchanges,
|
|
196
|
+
blacklistedTokenIds,
|
|
197
|
+
hideEmptyTokenAccounts,
|
|
198
|
+
} = unsafe;
|
|
199
|
+
const currenciesSettingsSafe: Record<CryptoCurrencyIds, CryptoSettings> = {};
|
|
200
|
+
|
|
201
|
+
if (currenciesSettings && typeof currenciesSettings === "object") {
|
|
202
|
+
for (const k in currenciesSettings) {
|
|
203
|
+
currenciesSettingsSafe[k] = asCryptoSettings(currenciesSettings[k]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const pairExchangesSafe: Record<string, string> = {};
|
|
208
|
+
|
|
209
|
+
if (pairExchanges && typeof pairExchanges === "object") {
|
|
210
|
+
for (const k in pairExchanges) {
|
|
211
|
+
const v = pairExchanges[k];
|
|
212
|
+
|
|
213
|
+
if (v && typeof v === "string") {
|
|
214
|
+
pairExchangesSafe[k] = v;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const res: Settings = {
|
|
220
|
+
currenciesSettings: currenciesSettingsSafe,
|
|
221
|
+
pairExchanges: pairExchangesSafe,
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
if (counterValue && typeof counterValue === "string") {
|
|
225
|
+
res.counterValue = counterValue;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (hideEmptyTokenAccounts && typeof hideEmptyTokenAccounts === "boolean") {
|
|
229
|
+
res.hideEmptyTokenAccounts = hideEmptyTokenAccounts;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const blacklistedTokenIdsSafe: string[] = [];
|
|
233
|
+
|
|
234
|
+
if (blacklistedTokenIds && Array.isArray(blacklistedTokenIds)) {
|
|
235
|
+
for (const b of blacklistedTokenIds) {
|
|
236
|
+
if (typeof b === "string") {
|
|
237
|
+
blacklistedTokenIdsSafe.push(b);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
res.blacklistedTokenIds = blacklistedTokenIdsSafe;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return res;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
export function decode(bytes: string): Result {
|
|
248
|
+
const unsafe: Record<string, any> = JSON.parse(
|
|
249
|
+
Buffer.from(
|
|
250
|
+
compressjs.Bzip2.decompressFile(Buffer.from(bytes, "binary"))
|
|
251
|
+
).toString()
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
if (typeof unsafe !== "object" || !unsafe) {
|
|
255
|
+
throw new Error("invalid data");
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return {
|
|
259
|
+
meta: asResultMeta(unsafe.meta),
|
|
260
|
+
accounts: asResultAccounts(unsafe.accounts),
|
|
261
|
+
settings: asResultSettings(unsafe.settings),
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
export function accountToAccountData({
|
|
265
|
+
id,
|
|
266
|
+
name,
|
|
267
|
+
seedIdentifier,
|
|
268
|
+
derivationMode,
|
|
269
|
+
freshAddress,
|
|
270
|
+
currency,
|
|
271
|
+
index,
|
|
272
|
+
balance,
|
|
273
|
+
}: Account): AccountData {
|
|
274
|
+
const res: AccountData = {
|
|
275
|
+
id,
|
|
276
|
+
name,
|
|
277
|
+
seedIdentifier,
|
|
278
|
+
derivationMode,
|
|
279
|
+
freshAddress,
|
|
280
|
+
currencyId: currency.id,
|
|
281
|
+
index,
|
|
282
|
+
balance: balance.toString(),
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
return res;
|
|
286
|
+
}
|
|
287
|
+
// reverse the account data to an account.
|
|
288
|
+
// this restore the essential data of an account and the result of the fields
|
|
289
|
+
// are assumed to be restored during first sync
|
|
290
|
+
export const accountDataToAccount = ({
|
|
291
|
+
id,
|
|
292
|
+
currencyId,
|
|
293
|
+
freshAddress: inputFreshAddress,
|
|
294
|
+
name,
|
|
295
|
+
index,
|
|
296
|
+
balance,
|
|
297
|
+
derivationMode: derivationModeStr,
|
|
298
|
+
seedIdentifier,
|
|
299
|
+
}: AccountData): Account => {
|
|
300
|
+
const { xpubOrAddress } = decodeAccountId(id); // TODO rename in AccountId xpubOrAddress
|
|
301
|
+
|
|
302
|
+
const derivationMode = asDerivationMode(derivationModeStr);
|
|
303
|
+
const currency = getCryptoCurrencyById(currencyId);
|
|
304
|
+
let xpub = "";
|
|
305
|
+
let freshAddress = inputFreshAddress || "";
|
|
306
|
+
let freshAddressPath = "";
|
|
307
|
+
|
|
308
|
+
if (
|
|
309
|
+
// FIXME Dirty hack, since we have no way here to know if "xpubOrAddress" is one or the other.
|
|
310
|
+
// Proposed fix: https://ledgerhq.atlassian.net/browse/LL-7437
|
|
311
|
+
currency.family === "bitcoin" ||
|
|
312
|
+
currency.family === "cardano"
|
|
313
|
+
) {
|
|
314
|
+
// In bitcoin implementation, xpubOrAddress field always go in the xpub
|
|
315
|
+
xpub = xpubOrAddress;
|
|
316
|
+
} else {
|
|
317
|
+
if (currency.family === "tezos") {
|
|
318
|
+
xpub = xpubOrAddress;
|
|
319
|
+
} else if (!freshAddress) {
|
|
320
|
+
// otherwise, it's the freshAddress
|
|
321
|
+
freshAddress = xpubOrAddress;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
freshAddressPath = runDerivationScheme(
|
|
325
|
+
getDerivationScheme({
|
|
326
|
+
currency,
|
|
327
|
+
derivationMode,
|
|
328
|
+
}),
|
|
329
|
+
currency,
|
|
330
|
+
{
|
|
331
|
+
account: index,
|
|
332
|
+
}
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const balanceBN = new BigNumber(balance);
|
|
337
|
+
const account: Account = {
|
|
338
|
+
type: "Account",
|
|
339
|
+
id,
|
|
340
|
+
derivationMode,
|
|
341
|
+
seedIdentifier,
|
|
342
|
+
xpub,
|
|
343
|
+
name,
|
|
344
|
+
starred: false,
|
|
345
|
+
used: false,
|
|
346
|
+
currency,
|
|
347
|
+
index,
|
|
348
|
+
freshAddress,
|
|
349
|
+
freshAddressPath,
|
|
350
|
+
swapHistory: [],
|
|
351
|
+
// these fields will be completed as we will sync
|
|
352
|
+
freshAddresses: [],
|
|
353
|
+
blockHeight: 0,
|
|
354
|
+
balance: balanceBN,
|
|
355
|
+
spendableBalance: balanceBN,
|
|
356
|
+
operationsCount: 0,
|
|
357
|
+
operations: [],
|
|
358
|
+
pendingOperations: [],
|
|
359
|
+
unit: currency.units[0],
|
|
360
|
+
lastSyncDate: new Date(0),
|
|
361
|
+
creationDate: new Date(),
|
|
362
|
+
balanceHistoryCache: emptyHistoryCache,
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
return account;
|
|
366
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { toLocaleString } from "./BigNumberToLocaleString";
|
|
3
|
+
test("basic toLocaleString usage", () => {
|
|
4
|
+
expect(toLocaleString(new BigNumber(0))).toBe("0");
|
|
5
|
+
expect(toLocaleString(new BigNumber(8))).toBe("8");
|
|
6
|
+
expect(toLocaleString(new BigNumber(123))).toBe("123");
|
|
7
|
+
expect(toLocaleString(new BigNumber(0.001))).toBe("0.001");
|
|
8
|
+
expect(toLocaleString(new BigNumber(13.1))).toBe("13.1");
|
|
9
|
+
expect(toLocaleString(new BigNumber(123.01))).toBe("123.01");
|
|
10
|
+
expect(toLocaleString(new BigNumber(123.012))).toBe("123.012");
|
|
11
|
+
expect(toLocaleString(new BigNumber(1123))).toBe("1,123");
|
|
12
|
+
expect(toLocaleString(new BigNumber("9999999999999999"))).toBe(
|
|
13
|
+
"9,999,999,999,999,999"
|
|
14
|
+
);
|
|
15
|
+
expect(toLocaleString(new BigNumber("9999999999999.99"))).toBe(
|
|
16
|
+
"9,999,999,999,999.99"
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
test("toLocaleString to default maximumFractionDigits to 3", () => {
|
|
20
|
+
expect(toLocaleString(new BigNumber(4.44444))).toBe("4.444");
|
|
21
|
+
expect(toLocaleString(new BigNumber(444444.444444444))).toBe("444,444.444");
|
|
22
|
+
expect(toLocaleString(new BigNumber(0.444444444))).toBe("0.444");
|
|
23
|
+
expect(toLocaleString(new BigNumber(9.99999))).toBe("9.999");
|
|
24
|
+
expect(toLocaleString(new BigNumber(111111.111111111))).toBe("111,111.111");
|
|
25
|
+
expect(toLocaleString(new BigNumber(0.999999999))).toBe("0.999");
|
|
26
|
+
expect(toLocaleString(new BigNumber(9.5))).toBe("9.5");
|
|
27
|
+
expect(toLocaleString(new BigNumber(9.9))).toBe("9.9");
|
|
28
|
+
expect(toLocaleString(new BigNumber(99.6))).toBe("99.6");
|
|
29
|
+
expect(toLocaleString(new BigNumber(99.8))).toBe("99.8");
|
|
30
|
+
expect(toLocaleString(new BigNumber(999.7))).toBe("999.7");
|
|
31
|
+
expect(toLocaleString(new BigNumber(999.9))).toBe("999.9");
|
|
32
|
+
expect(toLocaleString(new BigNumber(999999.7))).toBe("999,999.7");
|
|
33
|
+
expect(toLocaleString(new BigNumber(999999.9))).toBe("999,999.9");
|
|
34
|
+
});
|
|
35
|
+
test("toLocaleString minimumFractionDigits", () => {
|
|
36
|
+
expect(
|
|
37
|
+
toLocaleString(new BigNumber(0), "en", {
|
|
38
|
+
minimumFractionDigits: 1,
|
|
39
|
+
})
|
|
40
|
+
).toBe("0.0");
|
|
41
|
+
expect(
|
|
42
|
+
toLocaleString(new BigNumber(8), "en", {
|
|
43
|
+
minimumFractionDigits: 1,
|
|
44
|
+
})
|
|
45
|
+
).toBe("8.0");
|
|
46
|
+
expect(
|
|
47
|
+
toLocaleString(new BigNumber(123), "en", {
|
|
48
|
+
minimumFractionDigits: 1,
|
|
49
|
+
})
|
|
50
|
+
).toBe("123.0");
|
|
51
|
+
expect(
|
|
52
|
+
toLocaleString(new BigNumber(0.001), "en", {
|
|
53
|
+
minimumFractionDigits: 1,
|
|
54
|
+
})
|
|
55
|
+
).toBe("0.001");
|
|
56
|
+
expect(
|
|
57
|
+
toLocaleString(new BigNumber(9.5), "en", {
|
|
58
|
+
minimumFractionDigits: 1,
|
|
59
|
+
})
|
|
60
|
+
).toBe("9.5");
|
|
61
|
+
expect(
|
|
62
|
+
toLocaleString(new BigNumber(9.6), "en", {
|
|
63
|
+
minimumFractionDigits: 2,
|
|
64
|
+
})
|
|
65
|
+
).toBe("9.60");
|
|
66
|
+
expect(
|
|
67
|
+
toLocaleString(new BigNumber(13.1), "en", {
|
|
68
|
+
minimumFractionDigits: 3,
|
|
69
|
+
})
|
|
70
|
+
).toBe("13.100");
|
|
71
|
+
expect(
|
|
72
|
+
toLocaleString(new BigNumber(123.01), "en", {
|
|
73
|
+
minimumFractionDigits: 5,
|
|
74
|
+
})
|
|
75
|
+
).toBe("123.01000");
|
|
76
|
+
expect(
|
|
77
|
+
toLocaleString(new BigNumber(123.012), "en", {
|
|
78
|
+
minimumFractionDigits: 10,
|
|
79
|
+
})
|
|
80
|
+
).toBe("123.0120000000");
|
|
81
|
+
expect(
|
|
82
|
+
toLocaleString(new BigNumber(1123), "en", {
|
|
83
|
+
minimumFractionDigits: 1,
|
|
84
|
+
})
|
|
85
|
+
).toBe("1,123.0");
|
|
86
|
+
expect(
|
|
87
|
+
toLocaleString(new BigNumber("9999999999999999"), "en", {
|
|
88
|
+
minimumFractionDigits: 1,
|
|
89
|
+
})
|
|
90
|
+
).toBe("9,999,999,999,999,999.0");
|
|
91
|
+
expect(
|
|
92
|
+
toLocaleString(new BigNumber("9999999999999.999"), "en", {
|
|
93
|
+
minimumFractionDigits: 5,
|
|
94
|
+
})
|
|
95
|
+
).toBe("9,999,999,999,999.99900");
|
|
96
|
+
});
|
|
97
|
+
test("toLocaleString minimumFractionDigits and maximumFractionDigits", () => {
|
|
98
|
+
expect(
|
|
99
|
+
toLocaleString(new BigNumber(1), "en", {
|
|
100
|
+
minimumFractionDigits: 1,
|
|
101
|
+
maximumFractionDigits: 5,
|
|
102
|
+
})
|
|
103
|
+
).toBe("1.0");
|
|
104
|
+
expect(
|
|
105
|
+
toLocaleString(new BigNumber(1.003), "en", {
|
|
106
|
+
minimumFractionDigits: 1,
|
|
107
|
+
maximumFractionDigits: 5,
|
|
108
|
+
})
|
|
109
|
+
).toBe("1.003");
|
|
110
|
+
expect(
|
|
111
|
+
toLocaleString(new BigNumber(1.000003), "en", {
|
|
112
|
+
minimumFractionDigits: 1,
|
|
113
|
+
maximumFractionDigits: 5,
|
|
114
|
+
})
|
|
115
|
+
).toBe("1.0");
|
|
116
|
+
expect(
|
|
117
|
+
toLocaleString(new BigNumber(1.333333333333), "en", {
|
|
118
|
+
minimumFractionDigits: 1,
|
|
119
|
+
maximumFractionDigits: 5,
|
|
120
|
+
})
|
|
121
|
+
).toBe("1.33333");
|
|
122
|
+
expect(
|
|
123
|
+
toLocaleString(new BigNumber(0), "en", {
|
|
124
|
+
minimumFractionDigits: 1,
|
|
125
|
+
maximumFractionDigits: 5,
|
|
126
|
+
})
|
|
127
|
+
).toBe("0.0");
|
|
128
|
+
expect(
|
|
129
|
+
toLocaleString(new BigNumber(0.003), "en", {
|
|
130
|
+
minimumFractionDigits: 1,
|
|
131
|
+
maximumFractionDigits: 5,
|
|
132
|
+
})
|
|
133
|
+
).toBe("0.003");
|
|
134
|
+
expect(
|
|
135
|
+
toLocaleString(new BigNumber(0.000003), "en", {
|
|
136
|
+
minimumFractionDigits: 1,
|
|
137
|
+
maximumFractionDigits: 5,
|
|
138
|
+
})
|
|
139
|
+
).toBe("0.0");
|
|
140
|
+
expect(
|
|
141
|
+
toLocaleString(new BigNumber(9.7), "en", {
|
|
142
|
+
minimumFractionDigits: 1,
|
|
143
|
+
maximumFractionDigits: 1,
|
|
144
|
+
})
|
|
145
|
+
).toBe("9.7");
|
|
146
|
+
expect(
|
|
147
|
+
toLocaleString(
|
|
148
|
+
new BigNumber("4.4444444444444444444411111111111111"),
|
|
149
|
+
"en",
|
|
150
|
+
{
|
|
151
|
+
maximumFractionDigits: 20,
|
|
152
|
+
}
|
|
153
|
+
)
|
|
154
|
+
).toBe("4.44444444444444444444");
|
|
155
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Implement a subset of Number#toLocaleString for BigNumber.js
|
|
2
|
+
// https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Number/toLocaleString
|
|
3
|
+
import { BigNumber } from "bignumber.js";
|
|
4
|
+
import { getSeparators } from "./localeUtility";
|
|
5
|
+
export type SupportedOptions = {
|
|
6
|
+
minimumFractionDigits: number;
|
|
7
|
+
maximumFractionDigits: number;
|
|
8
|
+
useGrouping: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// FIXME later, might want to expose this format!
|
|
12
|
+
const getFormatForLocale = (locale: string) => {
|
|
13
|
+
const { decimal, thousands } = getSeparators(locale);
|
|
14
|
+
const opts = {
|
|
15
|
+
decimalSeparator: ".",
|
|
16
|
+
groupSeparator: ",",
|
|
17
|
+
groupSize: 3,
|
|
18
|
+
secondaryGroupSize: 0,
|
|
19
|
+
fractionGroupSeparator: "\xA0",
|
|
20
|
+
// non-breaking space
|
|
21
|
+
fractionGroupSize: 0,
|
|
22
|
+
};
|
|
23
|
+
if (typeof decimal === "string") opts.decimalSeparator = decimal;
|
|
24
|
+
if (typeof thousands === "string") opts.groupSeparator = thousands;
|
|
25
|
+
return opts;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const toLocaleString = (
|
|
29
|
+
n: BigNumber,
|
|
30
|
+
localeInput?: string,
|
|
31
|
+
options: Partial<SupportedOptions> = {}
|
|
32
|
+
): string => {
|
|
33
|
+
let locale = localeInput;
|
|
34
|
+
if (!locale) locale = "en";
|
|
35
|
+
const minimumFractionDigits: number =
|
|
36
|
+
"minimumFractionDigits" in options
|
|
37
|
+
? (options.minimumFractionDigits as number)
|
|
38
|
+
: 0;
|
|
39
|
+
const maximumFractionDigits: number =
|
|
40
|
+
"maximumFractionDigits" in options
|
|
41
|
+
? (options.maximumFractionDigits as number)
|
|
42
|
+
: Math.max(minimumFractionDigits, 3);
|
|
43
|
+
const useGrouping = "useGrouping" in options ? options.useGrouping : true;
|
|
44
|
+
const format = getFormatForLocale(locale);
|
|
45
|
+
|
|
46
|
+
if (!useGrouping) {
|
|
47
|
+
format.groupSeparator = "";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const BN = BigNumber.clone({
|
|
51
|
+
FORMAT: format,
|
|
52
|
+
});
|
|
53
|
+
const bn = new BN(n);
|
|
54
|
+
const maxDecimals = bn.toFormat(maximumFractionDigits, BigNumber.ROUND_FLOOR);
|
|
55
|
+
|
|
56
|
+
if (maximumFractionDigits !== minimumFractionDigits) {
|
|
57
|
+
const minDecimals = bn.toFormat(
|
|
58
|
+
minimumFractionDigits,
|
|
59
|
+
BigNumber.ROUND_FLOOR
|
|
60
|
+
);
|
|
61
|
+
let i = maxDecimals.length;
|
|
62
|
+
|
|
63
|
+
// cleanup useless '0's from the right until the minimumFractionDigits
|
|
64
|
+
while (i > minDecimals.length) {
|
|
65
|
+
if (maxDecimals[i - 1] !== "0") {
|
|
66
|
+
if (maxDecimals[i - 1] === format.decimalSeparator) {
|
|
67
|
+
i--;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
break; // we reach decimal. stop now.
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
i--;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return maxDecimals.slice(0, i);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return maxDecimals;
|
|
80
|
+
};
|