@ledgerhq/live-common 21.5.1-btcjs.0 → 21.7.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/addAccounts.d.ts.map +1 -1
- package/lib/account/addAccounts.js +1 -2
- package/lib/account/addAccounts.js.map +1 -1
- package/lib/account/support.d.ts.map +1 -1
- package/lib/account/support.js +1 -24
- package/lib/account/support.js.map +1 -1
- package/lib/api/explorerConfig/index.js +15 -15
- package/lib/bot/index.d.ts +1 -2
- package/lib/bot/index.d.ts.map +1 -1
- package/lib/bot/index.js +15 -19
- package/lib/bot/index.js.map +1 -1
- package/lib/bot/test.bot.js +1 -4
- package/lib/bot/test.bot.js.map +1 -1
- package/lib/bridge/jsHelpers.d.ts +1 -6
- package/lib/bridge/jsHelpers.d.ts.map +1 -1
- package/lib/bridge/jsHelpers.js +3 -11
- package/lib/bridge/jsHelpers.js.map +1 -1
- package/lib/env.js +1 -1
- package/lib/env.js.map +1 -1
- package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
- package/lib/exchange/swap/getExchangeRates.js +9 -8
- package/lib/exchange/swap/getExchangeRates.js.map +1 -1
- package/lib/exchange/swap/hooks/index.d.ts +11 -0
- package/lib/exchange/swap/hooks/index.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/index.js +23 -0
- package/lib/exchange/swap/hooks/index.js.map +1 -0
- package/lib/exchange/swap/hooks/useFromState.d.ts +15 -0
- package/lib/exchange/swap/hooks/useFromState.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useFromState.js +67 -0
- package/lib/exchange/swap/hooks/useFromState.js.map +1 -0
- package/lib/exchange/swap/hooks/useFromState.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useFromState.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useFromState.test.js +141 -0
- package/lib/exchange/swap/hooks/useFromState.test.js.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts +5 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.js +37 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.js.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js +185 -0
- package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts +3 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.js +17 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.js.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js +73 -0
- package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js.map +1 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts +12 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.js +105 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.js.map +1 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.js +78 -0
- package/lib/exchange/swap/hooks/usePollKYCStatus.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useProviderRates.d.ts +20 -0
- package/lib/exchange/swap/hooks/useProviderRates.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useProviderRates.js +174 -0
- package/lib/exchange/swap/hooks/useProviderRates.js.map +1 -0
- package/lib/exchange/swap/hooks/useProviderRates.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useProviderRates.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useProviderRates.test.js +261 -0
- package/lib/exchange/swap/hooks/useProviderRates.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.d.ts +15 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.js +35 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.js.map +1 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.test.js +79 -0
- package/lib/exchange/swap/hooks/useReverseAccounts.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts +5 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.js +43 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.js.map +1 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js +32 -0
- package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useSwapProviders.d.ts +14 -0
- package/lib/exchange/swap/hooks/useSwapProviders.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSwapProviders.js +104 -0
- package/lib/exchange/swap/hooks/useSwapProviders.js.map +1 -0
- package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSwapProviders.test.js +174 -0
- package/lib/exchange/swap/hooks/useSwapProviders.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.d.ts +53 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.js +109 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.js.map +1 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.test.js +50 -0
- package/lib/exchange/swap/hooks/useSwapTransaction.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useToState.d.ts +12 -0
- package/lib/exchange/swap/hooks/useToState.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useToState.js +73 -0
- package/lib/exchange/swap/hooks/useToState.js.map +1 -0
- package/lib/exchange/swap/hooks/useToState.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useToState.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useToState.test.js +107 -0
- package/lib/exchange/swap/hooks/useToState.test.js.map +1 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts +15 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts.map +1 -0
- package/lib/{families/bitcoin/getAccountNetworkInfo.js → exchange/swap/hooks/useUpdateMaxAmount.js} +47 -65
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.js.map +1 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts +2 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts.map +1 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js +217 -0
- package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -0
- package/lib/exchange/swap/mock.d.ts +6 -2
- package/lib/exchange/swap/mock.d.ts.map +1 -1
- package/lib/exchange/swap/mock.js +21 -6
- package/lib/exchange/swap/mock.js.map +1 -1
- package/lib/exchange/swap/types.d.ts +1 -1
- package/lib/exchange/swap/types.d.ts.map +1 -1
- package/lib/exchange/swap/utils/index.d.ts +16 -0
- package/lib/exchange/swap/utils/index.d.ts.map +1 -0
- package/lib/exchange/swap/utils/index.js +49 -0
- package/lib/exchange/swap/utils/index.js.map +1 -0
- package/lib/exchange/swap/utils/index.test.d.ts +2 -0
- package/lib/exchange/swap/utils/index.test.d.ts.map +1 -0
- package/lib/exchange/swap/utils/index.test.js +238 -0
- package/lib/exchange/swap/utils/index.test.js.map +1 -0
- package/lib/families/bitcoin/account.d.ts.map +1 -1
- package/lib/families/bitcoin/account.js +2 -3
- package/lib/families/bitcoin/account.js.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin.js +6 -6
- package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/litecoin.js +3 -3
- package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
- package/lib/families/bitcoin/serialization.d.ts +2 -2
- package/lib/families/bitcoin/serialization.d.ts.map +1 -1
- package/lib/families/bitcoin/serialization.js +4 -8
- package/lib/families/bitcoin/serialization.js.map +1 -1
- package/lib/families/bitcoin/specs.d.ts +1 -0
- package/lib/families/bitcoin/specs.d.ts.map +1 -1
- package/lib/families/bitcoin/specs.js +17 -8
- package/lib/families/bitcoin/specs.js.map +1 -1
- package/lib/families/bitcoin/speculos-deviceActions.js +2 -2
- package/lib/families/bitcoin/speculos-deviceActions.js.map +1 -1
- package/lib/families/bitcoin/test-dataset.js +1 -1
- package/lib/families/bitcoin/test-dataset.js.map +1 -1
- package/lib/families/bitcoin/transaction.d.ts +3 -3
- package/lib/families/bitcoin/transaction.d.ts.map +1 -1
- package/lib/families/bitcoin/transaction.js +61 -64
- package/lib/families/bitcoin/transaction.js.map +1 -1
- package/lib/families/bitcoin/types.d.ts +36 -66
- package/lib/families/bitcoin/types.d.ts.map +1 -1
- package/lib/families/bitcoin/types.js +1 -16
- package/lib/families/bitcoin/types.js.map +1 -1
- package/lib/families/crypto_org/datasets/croeseid.d.ts.map +1 -1
- package/lib/families/crypto_org/datasets/croeseid.js +2 -6
- package/lib/families/crypto_org/datasets/croeseid.js.map +1 -1
- package/lib/families/elrond/api/apiCalls.d.ts +0 -4
- package/lib/families/elrond/api/apiCalls.d.ts.map +1 -1
- package/lib/families/elrond/api/apiCalls.js +3 -37
- package/lib/families/elrond/api/apiCalls.js.map +1 -1
- package/lib/families/elrond/api/sdk.js +2 -2
- package/lib/families/elrond/api/sdk.js.map +1 -1
- package/lib/families/elrond/js-transaction.d.ts +2 -0
- package/lib/families/elrond/js-transaction.d.ts.map +1 -1
- package/lib/families/elrond/types.d.ts +2 -0
- package/lib/families/elrond/types.d.ts.map +1 -1
- package/lib/families/elrond/types.js.map +1 -1
- package/lib/families/tezos/bridge/js.js.map +1 -1
- package/lib/generated/bridge/js.d.ts +0 -4
- package/lib/generated/bridge/js.d.ts.map +1 -1
- package/lib/generated/bridge/js.js +18 -20
- package/lib/generated/bridge/js.js.map +1 -1
- package/lib/generated/specs.d.ts +1 -0
- package/lib/generated/specs.d.ts.map +1 -1
- package/lib/migrations/accounts-dataset.d.ts.map +1 -1
- package/lib/migrations/accounts-dataset.js +2 -4
- package/lib/migrations/accounts-dataset.js.map +1 -1
- package/lib/migrations/accounts.d.ts.map +1 -1
- package/lib/migrations/accounts.js +0 -17
- package/lib/migrations/accounts.js.map +1 -1
- package/lib/mock/account.d.ts +2 -1
- package/lib/mock/account.d.ts.map +1 -1
- package/lib/mock/account.js +5 -4
- package/lib/mock/account.js.map +1 -1
- package/package.json +12 -13
- package/src/.DS_Store +0 -0
- package/src/__tests__/.DS_Store +0 -0
- package/src/__tests__/__snapshots__/.DS_Store +0 -0
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +10 -10
- package/src/account/addAccounts.ts +1 -2
- package/src/account/support.ts +1 -24
- package/src/api/explorerConfig/index.ts +15 -15
- package/src/bot/index.ts +3 -8
- package/src/bot/test.bot.ts +1 -6
- package/src/bridge/jsHelpers.ts +2 -22
- package/src/env.ts +1 -1
- package/src/exchange/swap/getExchangeRates.ts +8 -5
- package/src/exchange/swap/hooks/index.ts +10 -0
- package/src/exchange/swap/hooks/useFromState.test.ts +134 -0
- package/src/exchange/swap/hooks/useFromState.ts +84 -0
- package/src/exchange/swap/hooks/usePickDefaultAccount.test.ts +167 -0
- package/src/exchange/swap/hooks/usePickDefaultAccount.ts +47 -0
- package/src/exchange/swap/hooks/usePickDefaultCurrency.test.ts +107 -0
- package/src/exchange/swap/hooks/usePickDefaultCurrency.ts +20 -0
- package/src/exchange/swap/hooks/usePollKYCStatus.test.ts +89 -0
- package/src/exchange/swap/hooks/usePollKYCStatus.ts +43 -0
- package/src/exchange/swap/hooks/useProviderRates.test.ts +200 -0
- package/src/exchange/swap/hooks/useProviderRates.ts +130 -0
- package/src/exchange/swap/hooks/useReverseAccounts.test.ts +83 -0
- package/src/exchange/swap/hooks/useReverseAccounts.ts +56 -0
- package/src/exchange/swap/hooks/useSelectableCurrencies.test.ts +39 -0
- package/src/exchange/swap/hooks/useSelectableCurrencies.ts +26 -0
- package/src/exchange/swap/hooks/useSwapProviders.test.ts +113 -0
- package/src/exchange/swap/hooks/useSwapProviders.ts +57 -0
- package/src/exchange/swap/hooks/useSwapTransaction.test.ts +54 -0
- package/src/exchange/swap/hooks/useSwapTransaction.ts +170 -0
- package/src/exchange/swap/hooks/useToState.test.ts +53 -0
- package/src/exchange/swap/hooks/useToState.ts +86 -0
- package/src/exchange/swap/hooks/useUpdateMaxAmount.test.ts +132 -0
- package/src/exchange/swap/hooks/useUpdateMaxAmount.ts +67 -0
- package/src/exchange/swap/mock.ts +22 -3
- package/src/exchange/swap/types.ts +2 -1
- package/src/exchange/swap/utils/index.test.ts +224 -0
- package/src/exchange/swap/utils/index.ts +67 -0
- package/src/families/bitcoin/account.ts +1 -2
- package/src/families/bitcoin/datasets/bitcoin.ts +6 -6
- package/src/families/bitcoin/datasets/litecoin.ts +6 -6
- package/src/families/bitcoin/serialization.ts +0 -6
- package/src/families/bitcoin/specs.ts +14 -5
- package/src/families/bitcoin/speculos-deviceActions.ts +1 -1
- package/src/families/bitcoin/test-dataset.ts +1 -1
- package/src/families/bitcoin/transaction.ts +93 -98
- package/src/families/bitcoin/types.ts +37 -95
- package/src/families/crypto_org/datasets/croeseid.ts +7 -9
- package/src/families/elrond/api/apiCalls.ts +3 -31
- package/src/families/elrond/api/sdk.ts +2 -2
- package/src/families/elrond/types.ts +2 -0
- package/src/families/tezos/bridge/js.ts +1 -1
- package/src/generated/bridge/js.ts +0 -3
- package/src/migrations/accounts-dataset.ts +0 -3
- package/src/migrations/accounts.ts +0 -18
- package/src/mock/account.ts +2 -4
- package/lib/__tests__/families/bitcoin/logic.d.ts +0 -2
- package/lib/__tests__/families/bitcoin/logic.d.ts.map +0 -1
- package/lib/__tests__/families/bitcoin/logic.js +0 -39
- package/lib/__tests__/families/bitcoin/logic.js.map +0 -1
- package/lib/families/bitcoin/bridge/js.d.ts +0 -8
- package/lib/families/bitcoin/bridge/js.d.ts.map +0 -1
- package/lib/families/bitcoin/bridge/js.js +0 -149
- package/lib/families/bitcoin/bridge/js.js.map +0 -1
- package/lib/families/bitcoin/cache.d.ts +0 -28
- package/lib/families/bitcoin/cache.d.ts.map +0 -1
- package/lib/families/bitcoin/cache.js +0 -109
- package/lib/families/bitcoin/cache.js.map +0 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.d.ts +0 -6
- package/lib/families/bitcoin/getAccountNetworkInfo.d.ts.map +0 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.js.map +0 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts +0 -2
- package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts.map +0 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.test.js +0 -71
- package/lib/families/bitcoin/getAccountNetworkInfo.test.js.map +0 -1
- package/lib/families/bitcoin/js-broadcast.d.ts +0 -11
- package/lib/families/bitcoin/js-broadcast.d.ts.map +0 -1
- package/lib/families/bitcoin/js-broadcast.js +0 -80
- package/lib/families/bitcoin/js-broadcast.js.map +0 -1
- package/lib/families/bitcoin/js-buildTransaction.d.ts +0 -5
- package/lib/families/bitcoin/js-buildTransaction.d.ts.map +0 -1
- package/lib/families/bitcoin/js-buildTransaction.js +0 -106
- package/lib/families/bitcoin/js-buildTransaction.js.map +0 -1
- package/lib/families/bitcoin/js-createTransaction.d.ts +0 -9
- package/lib/families/bitcoin/js-createTransaction.d.ts.map +0 -1
- package/lib/families/bitcoin/js-createTransaction.js +0 -27
- package/lib/families/bitcoin/js-createTransaction.js.map +0 -1
- package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts +0 -15
- package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts.map +0 -1
- package/lib/families/bitcoin/js-estimateMaxSpendable.js +0 -95
- package/lib/families/bitcoin/js-estimateMaxSpendable.js.map +0 -1
- package/lib/families/bitcoin/js-getFeesForTransaction.d.ts +0 -26
- package/lib/families/bitcoin/js-getFeesForTransaction.d.ts.map +0 -1
- package/lib/families/bitcoin/js-getFeesForTransaction.js +0 -100
- package/lib/families/bitcoin/js-getFeesForTransaction.js.map +0 -1
- package/lib/families/bitcoin/js-getTransactionStatus.d.ts +0 -5
- package/lib/families/bitcoin/js-getTransactionStatus.d.ts.map +0 -1
- package/lib/families/bitcoin/js-getTransactionStatus.js +0 -131
- package/lib/families/bitcoin/js-getTransactionStatus.js.map +0 -1
- package/lib/families/bitcoin/js-prepareTransaction.d.ts +0 -5
- package/lib/families/bitcoin/js-prepareTransaction.d.ts.map +0 -1
- package/lib/families/bitcoin/js-prepareTransaction.js +0 -80
- package/lib/families/bitcoin/js-prepareTransaction.js.map +0 -1
- package/lib/families/bitcoin/js-signOperation.d.ts +0 -10
- package/lib/families/bitcoin/js-signOperation.d.ts.map +0 -1
- package/lib/families/bitcoin/js-signOperation.js +0 -212
- package/lib/families/bitcoin/js-signOperation.js.map +0 -1
- package/lib/families/bitcoin/js-synchronisation.d.ts +0 -10
- package/lib/families/bitcoin/js-synchronisation.d.ts.map +0 -1
- package/lib/families/bitcoin/js-synchronisation.js +0 -411
- package/lib/families/bitcoin/js-synchronisation.js.map +0 -1
- package/lib/families/bitcoin/logic.d.ts +0 -34
- package/lib/families/bitcoin/logic.d.ts.map +0 -1
- package/lib/families/bitcoin/logic.js +0 -292
- package/lib/families/bitcoin/logic.js.map +0 -1
- package/lib/families/bitcoin/networks.d.ts +0 -3
- package/lib/families/bitcoin/networks.d.ts.map +0 -1
- package/lib/families/bitcoin/networks.js +0 -379
- package/lib/families/bitcoin/networks.js.map +0 -1
- package/lib/families/bitcoin/wallet.d.ts +0 -6
- package/lib/families/bitcoin/wallet.d.ts.map +0 -1
- package/lib/families/bitcoin/wallet.js +0 -66
- package/lib/families/bitcoin/wallet.js.map +0 -1
- package/src/__tests__/families/bitcoin/logic.ts +0 -40
- package/src/families/bitcoin/bridge/js.ts +0 -76
- package/src/families/bitcoin/cache.ts +0 -76
- package/src/families/bitcoin/getAccountNetworkInfo.test.ts +0 -27
- package/src/families/bitcoin/getAccountNetworkInfo.ts +0 -61
- package/src/families/bitcoin/js-broadcast.ts +0 -30
- package/src/families/bitcoin/js-buildTransaction.ts +0 -57
- package/src/families/bitcoin/js-createTransaction.ts +0 -27
- package/src/families/bitcoin/js-estimateMaxSpendable.ts +0 -36
- package/src/families/bitcoin/js-getFeesForTransaction.ts +0 -59
- package/src/families/bitcoin/js-getTransactionStatus.ts +0 -118
- package/src/families/bitcoin/js-prepareTransaction.ts +0 -35
- package/src/families/bitcoin/js-signOperation.ts +0 -164
- package/src/families/bitcoin/js-synchronisation.ts +0 -362
- package/src/families/bitcoin/logic.ts +0 -253
- package/src/families/bitcoin/networks.ts +0 -360
- package/src/families/bitcoin/wallet.ts +0 -21
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
|
|
3
|
+
import { pickExchangeRate, getAccountTuplesForCurrency } from "./index";
|
|
4
|
+
import { getMockExchangeRate } from "../mock";
|
|
5
|
+
import { genAccount } from "../../../mock/account";
|
|
6
|
+
import type {
|
|
7
|
+
Account,
|
|
8
|
+
CryptoCurrency,
|
|
9
|
+
SubAccount,
|
|
10
|
+
TokenCurrency,
|
|
11
|
+
} from "../../../types";
|
|
12
|
+
import { getCryptoCurrencyById } from "../../../currencies";
|
|
13
|
+
import { getTokenById } from "@ledgerhq/cryptoassets/lib/tokens";
|
|
14
|
+
|
|
15
|
+
describe("swap/utils/pickExchangeRate", () => {
|
|
16
|
+
test("calls the callback function with null when no exchange rates are passed", () => {
|
|
17
|
+
const setExchangeRate = jest.fn();
|
|
18
|
+
pickExchangeRate([], undefined, setExchangeRate);
|
|
19
|
+
|
|
20
|
+
expect(setExchangeRate).toHaveBeenCalledTimes(1);
|
|
21
|
+
expect(setExchangeRate).toHaveBeenCalledWith(null);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("calls the callback function with null when no exchange rates are passed but there is an exchange rate", () => {
|
|
25
|
+
const setExchangeRate = jest.fn();
|
|
26
|
+
const exchangeRate = getMockExchangeRate({ provider: "wyre" });
|
|
27
|
+
pickExchangeRate([], exchangeRate, setExchangeRate);
|
|
28
|
+
|
|
29
|
+
expect(setExchangeRate).toHaveBeenCalledTimes(1);
|
|
30
|
+
expect(setExchangeRate).toHaveBeenCalledWith(null);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("calls the callback function with the first exchange rate when the exchange passed isn't included in the list", () => {
|
|
34
|
+
const setExchangeRate = jest.fn();
|
|
35
|
+
const firstExchangeRate = getMockExchangeRate({
|
|
36
|
+
provider: "changelly",
|
|
37
|
+
tradeMethod: "fixed",
|
|
38
|
+
});
|
|
39
|
+
const exchangeRates = [
|
|
40
|
+
firstExchangeRate,
|
|
41
|
+
getMockExchangeRate({ provider: "changelly", tradeMethod: "float" }),
|
|
42
|
+
];
|
|
43
|
+
const exchangeRate = getMockExchangeRate({ provider: "wyre" });
|
|
44
|
+
|
|
45
|
+
pickExchangeRate(exchangeRates, exchangeRate, setExchangeRate);
|
|
46
|
+
|
|
47
|
+
expect(setExchangeRate).toHaveBeenCalledTimes(1);
|
|
48
|
+
expect(setExchangeRate).toHaveBeenCalledWith(firstExchangeRate);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("calls the callback function with the passed exchange rate when the exchange passed is included in the list", () => {
|
|
52
|
+
const setExchangeRate = jest.fn();
|
|
53
|
+
const exchangeRate = getMockExchangeRate({
|
|
54
|
+
provider: "changelly",
|
|
55
|
+
tradeMethod: "fixed",
|
|
56
|
+
});
|
|
57
|
+
const exchangeRates = [
|
|
58
|
+
getMockExchangeRate({ provider: "changelly", tradeMethod: "float" }),
|
|
59
|
+
exchangeRate,
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
pickExchangeRate(exchangeRates, exchangeRate, setExchangeRate);
|
|
63
|
+
|
|
64
|
+
expect(setExchangeRate).toHaveBeenCalledTimes(1);
|
|
65
|
+
expect(setExchangeRate).toHaveBeenCalledWith(exchangeRate);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/* TODO: Refacto these two function and move them to mock/account.ts if needed */
|
|
70
|
+
function* accountGenerator(currency: CryptoCurrency): Generator<Account> {
|
|
71
|
+
let id = 0;
|
|
72
|
+
while (true) {
|
|
73
|
+
id += 1;
|
|
74
|
+
yield genAccount(`mocked-account-${id}`, { currency, operationsSize: 0 });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const getAccountCreator = (currencyId: string) => {
|
|
78
|
+
const generator = accountGenerator(getCryptoCurrencyById(currencyId));
|
|
79
|
+
return () => generator.next().value;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
describe("swap/utils/getAccountTuplesForCurrency", () => {
|
|
83
|
+
const getEthAccount = getAccountCreator("ethereum");
|
|
84
|
+
const getBtcAccount = getAccountCreator("bitcoin");
|
|
85
|
+
const getPolkadotAccount = getAccountCreator("polkadot");
|
|
86
|
+
const getCosmosAccount = getAccountCreator("cosmos");
|
|
87
|
+
|
|
88
|
+
describe("CryptoCurrency", () => {
|
|
89
|
+
test("returns all accounts associated to the CryptoCurrency", () => {
|
|
90
|
+
const ethCurrency = getCryptoCurrencyById("ethereum");
|
|
91
|
+
const ethAccounts = [getEthAccount(), getEthAccount()];
|
|
92
|
+
const allAccounts: Account[] = [
|
|
93
|
+
getCosmosAccount(),
|
|
94
|
+
...ethAccounts,
|
|
95
|
+
getBtcAccount(),
|
|
96
|
+
getPolkadotAccount(),
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
const results = getAccountTuplesForCurrency(
|
|
100
|
+
ethCurrency,
|
|
101
|
+
allAccounts,
|
|
102
|
+
false
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
expect(results).toHaveLength(2);
|
|
106
|
+
results.forEach((result, index) => {
|
|
107
|
+
expect(result.account).toEqual(ethAccounts[index]);
|
|
108
|
+
expect(result.subAccount).toBeNull();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("returns only associated accounts if they have a balance greater than 0 when the flag is passed", () => {
|
|
113
|
+
const ethCurrency = getCryptoCurrencyById("ethereum");
|
|
114
|
+
const richEthAccounts = [
|
|
115
|
+
{ ...getEthAccount(), balance: new BigNumber(10) },
|
|
116
|
+
{ ...getEthAccount(), balance: new BigNumber(10) },
|
|
117
|
+
];
|
|
118
|
+
const poorEthAccounts = { ...getEthAccount(), balance: new BigNumber(0) };
|
|
119
|
+
|
|
120
|
+
const allAccounts: Account[] = [
|
|
121
|
+
getCosmosAccount(),
|
|
122
|
+
...richEthAccounts,
|
|
123
|
+
poorEthAccounts,
|
|
124
|
+
getBtcAccount(),
|
|
125
|
+
getPolkadotAccount(),
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
const results = getAccountTuplesForCurrency(
|
|
129
|
+
ethCurrency,
|
|
130
|
+
allAccounts,
|
|
131
|
+
true
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
expect(results).toHaveLength(richEthAccounts.length);
|
|
135
|
+
results.forEach((result, index) => {
|
|
136
|
+
expect(result.account).toEqual(richEthAccounts[index]);
|
|
137
|
+
expect(result.subAccount).toBeNull();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("returns an empty array if the CryptoCurrency passed has no associated account", () => {
|
|
142
|
+
const ethCurrency = getCryptoCurrencyById("ethereum");
|
|
143
|
+
const allAccounts: Account[] = [
|
|
144
|
+
getCosmosAccount(),
|
|
145
|
+
getBtcAccount(),
|
|
146
|
+
getPolkadotAccount(),
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
const results = getAccountTuplesForCurrency(
|
|
150
|
+
ethCurrency,
|
|
151
|
+
allAccounts,
|
|
152
|
+
false
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
expect(results).toHaveLength(0);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe("TokenCurrency", () => {
|
|
160
|
+
const aaveToken = Object.freeze(getTokenById("ethereum/erc20/aave"));
|
|
161
|
+
|
|
162
|
+
test("returns correct parent accounts including a new subAccount when a TokenCurrency is provided", () => {
|
|
163
|
+
const ethAccounts = [
|
|
164
|
+
{ ...getEthAccount(), subAccounts: [] },
|
|
165
|
+
{ ...getEthAccount(), subAccounts: [] },
|
|
166
|
+
];
|
|
167
|
+
const allAccounts: Account[] = [
|
|
168
|
+
getCosmosAccount(),
|
|
169
|
+
...ethAccounts,
|
|
170
|
+
getBtcAccount(),
|
|
171
|
+
getPolkadotAccount(),
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
const results = getAccountTuplesForCurrency(
|
|
175
|
+
aaveToken,
|
|
176
|
+
allAccounts,
|
|
177
|
+
false
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
expect(results).toHaveLength(ethAccounts.length);
|
|
181
|
+
results.forEach((result, index) => {
|
|
182
|
+
expect(result.account).toEqual(ethAccounts[index]);
|
|
183
|
+
expect(
|
|
184
|
+
(result.subAccount as SubAccount & { token: TokenCurrency }).token
|
|
185
|
+
).toEqual(aaveToken);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("returns correct parent accounts including already existing subAccounts when a TokenCurrency is provided", () => {
|
|
190
|
+
const ethAccounts = [{ ...getEthAccount(), subAccounts: [aaveToken] }];
|
|
191
|
+
const allAccounts: Account[] = [
|
|
192
|
+
getCosmosAccount(),
|
|
193
|
+
...ethAccounts,
|
|
194
|
+
getBtcAccount(),
|
|
195
|
+
getPolkadotAccount(),
|
|
196
|
+
];
|
|
197
|
+
|
|
198
|
+
const results = getAccountTuplesForCurrency(
|
|
199
|
+
aaveToken,
|
|
200
|
+
allAccounts,
|
|
201
|
+
false
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
expect(results).toHaveLength(ethAccounts.length);
|
|
205
|
+
results.forEach((result, index) => {
|
|
206
|
+
expect(result.account).toEqual(ethAccounts[index]);
|
|
207
|
+
expect(
|
|
208
|
+
(result.subAccount as SubAccount & { token: TokenCurrency }).token
|
|
209
|
+
).toEqual(aaveToken);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("returns an empty array when a TokenCurrency is provided but the accounts list is empty", () => {
|
|
214
|
+
const allAccounts: Account[] = [];
|
|
215
|
+
|
|
216
|
+
const results = getAccountTuplesForCurrency(
|
|
217
|
+
aaveToken,
|
|
218
|
+
allAccounts,
|
|
219
|
+
false
|
|
220
|
+
);
|
|
221
|
+
expect(results).toHaveLength(0);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/cryptoassets";
|
|
2
|
+
import { makeEmptyTokenAccount } from "../../../account";
|
|
3
|
+
import { Account, SubAccount } from "../../../types";
|
|
4
|
+
import type { ExchangeRate } from "../types";
|
|
5
|
+
|
|
6
|
+
export const KYC_STATUS = {
|
|
7
|
+
pending: "pending",
|
|
8
|
+
rejected: "closed",
|
|
9
|
+
approved: "approved",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type KYCStatus = keyof typeof KYC_STATUS;
|
|
13
|
+
|
|
14
|
+
export const pickExchangeRate = (
|
|
15
|
+
exchangeRates: ExchangeRate[],
|
|
16
|
+
exchangeRate: ExchangeRate | null | undefined,
|
|
17
|
+
setExchangeRate: (rate?: ExchangeRate | null) => void
|
|
18
|
+
): void => {
|
|
19
|
+
const hasRates = exchangeRates?.length > 0;
|
|
20
|
+
// If the user picked an exchange rate before, try to select the new one that matches.
|
|
21
|
+
// Otherwise pick the first one.
|
|
22
|
+
const rate =
|
|
23
|
+
hasRates &&
|
|
24
|
+
((exchangeRate &&
|
|
25
|
+
exchangeRates.find(
|
|
26
|
+
({ tradeMethod, provider }) =>
|
|
27
|
+
tradeMethod === exchangeRate.tradeMethod &&
|
|
28
|
+
provider === exchangeRate.provider
|
|
29
|
+
)) ||
|
|
30
|
+
exchangeRates[0]);
|
|
31
|
+
setExchangeRate(rate || null);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type AccountTuple = {
|
|
35
|
+
account: Account | null | undefined;
|
|
36
|
+
subAccount: SubAccount | null | undefined;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function getAccountTuplesForCurrency(
|
|
40
|
+
currency: CryptoCurrency | TokenCurrency,
|
|
41
|
+
allAccounts: Account[],
|
|
42
|
+
hideEmpty?: boolean
|
|
43
|
+
): AccountTuple[] {
|
|
44
|
+
if (currency.type === "TokenCurrency") {
|
|
45
|
+
return allAccounts
|
|
46
|
+
.filter((account) => account.currency.id === currency.parentCurrency.id)
|
|
47
|
+
.map((account) => ({
|
|
48
|
+
account,
|
|
49
|
+
subAccount:
|
|
50
|
+
(account.subAccounts &&
|
|
51
|
+
account.subAccounts.find(
|
|
52
|
+
(subAcc: SubAccount) =>
|
|
53
|
+
subAcc.type === "TokenAccount" &&
|
|
54
|
+
subAcc.token.id === currency.id
|
|
55
|
+
)) ||
|
|
56
|
+
makeEmptyTokenAccount(account, currency),
|
|
57
|
+
}))
|
|
58
|
+
.filter((a) => (hideEmpty ? a.subAccount?.balance.gt(0) : true));
|
|
59
|
+
}
|
|
60
|
+
return allAccounts
|
|
61
|
+
.filter((account) => account.currency.id === currency.id)
|
|
62
|
+
.map((account) => ({
|
|
63
|
+
account,
|
|
64
|
+
subAccount: null,
|
|
65
|
+
}))
|
|
66
|
+
.filter((a) => (hideEmpty ? a.account?.balance.gt(0) : true));
|
|
67
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { Account } from "../../types";
|
|
|
2
2
|
import type { BitcoinOutput, BitcoinInput } from "./types";
|
|
3
3
|
import { formatCurrencyUnit } from "../../currencies";
|
|
4
4
|
import { getEnv } from "../../env";
|
|
5
|
-
import { perCoinLogic } from "./
|
|
5
|
+
import { perCoinLogic } from "./transaction";
|
|
6
6
|
|
|
7
7
|
const sortUTXO = (a, b) => b.value.minus(a.value).toNumber();
|
|
8
8
|
|
|
@@ -31,7 +31,6 @@ export function formatOutput(account: Account, o: BitcoinOutput): string {
|
|
|
31
31
|
}).padEnd(12),
|
|
32
32
|
o.address,
|
|
33
33
|
o.path,
|
|
34
|
-
o.isChange ? "(change)" : "",
|
|
35
34
|
o.rbf ? "rbf" : "",
|
|
36
35
|
o.hash,
|
|
37
36
|
`@${o.outputIndex} (${
|
|
@@ -50,8 +50,8 @@ const dataset: CurrenciesData<Transaction> = {
|
|
|
50
50
|
expectedStatus: {
|
|
51
51
|
amount: new BigNumber("999"),
|
|
52
52
|
// FIXME fee are reloaded?
|
|
53
|
-
// estimatedFees:
|
|
54
|
-
// totalSpent:
|
|
53
|
+
// estimatedFees: BigNumber("250"),
|
|
54
|
+
// totalSpent: BigNumber("1249"),
|
|
55
55
|
errors: {},
|
|
56
56
|
warnings: {
|
|
57
57
|
// feeTooHigh: new FeeTooHigh()
|
|
@@ -76,8 +76,8 @@ const dataset: CurrenciesData<Transaction> = {
|
|
|
76
76
|
expectedStatus: {
|
|
77
77
|
amount: new BigNumber("998"),
|
|
78
78
|
// FIXME fee are reloaded?
|
|
79
|
-
// estimatedFees:
|
|
80
|
-
// totalSpent:
|
|
79
|
+
// estimatedFees: BigNumber("250"),
|
|
80
|
+
// totalSpent: BigNumber("1248"),
|
|
81
81
|
errors: {},
|
|
82
82
|
warnings: {
|
|
83
83
|
// feeTooHigh: new FeeTooHigh()
|
|
@@ -102,8 +102,8 @@ const dataset: CurrenciesData<Transaction> = {
|
|
|
102
102
|
expectedStatus: {
|
|
103
103
|
amount: new BigNumber("997"),
|
|
104
104
|
// FIXME fee are reloaded?
|
|
105
|
-
// estimatedFees:
|
|
106
|
-
// totalSpent:
|
|
105
|
+
// estimatedFees: BigNumber("250"),
|
|
106
|
+
// totalSpent: BigNumber("1247"),
|
|
107
107
|
errors: {},
|
|
108
108
|
warnings: {
|
|
109
109
|
// feeTooHigh: new FeeTooHigh(),
|
|
@@ -50,8 +50,8 @@ const dataset: CurrenciesData<Transaction> = {
|
|
|
50
50
|
expectedStatus: {
|
|
51
51
|
errors: {},
|
|
52
52
|
warnings: {},
|
|
53
|
-
// estimatedFees:
|
|
54
|
-
amount: new BigNumber("200000"), // totalSpent:
|
|
53
|
+
// estimatedFees: BigNumber("5694"),
|
|
54
|
+
amount: new BigNumber("200000"), // totalSpent: BigNumber("205694")
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
57
|
{
|
|
@@ -73,8 +73,8 @@ const dataset: CurrenciesData<Transaction> = {
|
|
|
73
73
|
expectedStatus: {
|
|
74
74
|
errors: {},
|
|
75
75
|
warnings: {},
|
|
76
|
-
// estimatedFees:
|
|
77
|
-
amount: new BigNumber("147200"), // totalSpent:
|
|
76
|
+
// estimatedFees: BigNumber("5694"),
|
|
77
|
+
amount: new BigNumber("147200"), // totalSpent: BigNumber("152894")
|
|
78
78
|
},
|
|
79
79
|
},
|
|
80
80
|
{
|
|
@@ -96,8 +96,8 @@ const dataset: CurrenciesData<Transaction> = {
|
|
|
96
96
|
expectedStatus: {
|
|
97
97
|
errors: {},
|
|
98
98
|
warnings: {},
|
|
99
|
-
// estimatedFees:
|
|
100
|
-
amount: new BigNumber("205273"), // totalSpent:
|
|
99
|
+
// estimatedFees: BigNumber("5694"),
|
|
100
|
+
amount: new BigNumber("205273"), // totalSpent: BigNumber("210967")
|
|
101
101
|
},
|
|
102
102
|
},
|
|
103
103
|
],
|
|
@@ -38,7 +38,6 @@ export function toBitcoinOutputRaw({
|
|
|
38
38
|
outputIndex,
|
|
39
39
|
blockHeight,
|
|
40
40
|
address,
|
|
41
|
-
isChange,
|
|
42
41
|
path,
|
|
43
42
|
value,
|
|
44
43
|
rbf,
|
|
@@ -48,7 +47,6 @@ export function toBitcoinOutputRaw({
|
|
|
48
47
|
outputIndex,
|
|
49
48
|
blockHeight,
|
|
50
49
|
address,
|
|
51
|
-
isChange ? 1 : 0,
|
|
52
50
|
path,
|
|
53
51
|
value.toString(),
|
|
54
52
|
rbf ? 1 : 0,
|
|
@@ -59,7 +57,6 @@ export function fromBitcoinOutputRaw([
|
|
|
59
57
|
outputIndex,
|
|
60
58
|
blockHeight,
|
|
61
59
|
address,
|
|
62
|
-
isChange,
|
|
63
60
|
path,
|
|
64
61
|
value,
|
|
65
62
|
rbf,
|
|
@@ -69,7 +66,6 @@ export function fromBitcoinOutputRaw([
|
|
|
69
66
|
outputIndex,
|
|
70
67
|
blockHeight: blockHeight || undefined,
|
|
71
68
|
address: address || undefined,
|
|
72
|
-
isChange: !!isChange,
|
|
73
69
|
path: path || undefined,
|
|
74
70
|
value: new BigNumber(value),
|
|
75
71
|
rbf: !!rbf,
|
|
@@ -80,7 +76,6 @@ export function toBitcoinResourcesRaw(
|
|
|
80
76
|
): BitcoinResourcesRaw {
|
|
81
77
|
return {
|
|
82
78
|
utxos: r.utxos.map(toBitcoinOutputRaw),
|
|
83
|
-
serializedData: r.serializedData,
|
|
84
79
|
};
|
|
85
80
|
}
|
|
86
81
|
export function fromBitcoinResourcesRaw(
|
|
@@ -88,6 +83,5 @@ export function fromBitcoinResourcesRaw(
|
|
|
88
83
|
): BitcoinResources {
|
|
89
84
|
return {
|
|
90
85
|
utxos: r.utxos.map(fromBitcoinOutputRaw),
|
|
91
|
-
serializedData: r.serializedData,
|
|
92
86
|
};
|
|
93
87
|
}
|
|
@@ -10,7 +10,8 @@ import { pickSiblings } from "../../bot/specs";
|
|
|
10
10
|
import { bitcoinPickingStrategy } from "./types";
|
|
11
11
|
import type { MutationSpec, AppSpec } from "../../bot/types";
|
|
12
12
|
import { LowerThanMinimumRelayFee } from "../../errors";
|
|
13
|
-
import { getMinRelayFee
|
|
13
|
+
import { getMinRelayFee } from "./fees";
|
|
14
|
+
import { isChangeOutput, getUTXOStatus } from "./transaction";
|
|
14
15
|
import { DeviceModelId } from "@ledgerhq/devices";
|
|
15
16
|
type Arg = Partial<{
|
|
16
17
|
minimalAmount: BigNumber;
|
|
@@ -80,11 +81,7 @@ const genericTest = ({
|
|
|
80
81
|
? operation.senders
|
|
81
82
|
: txInputs.map((t) => t.address).filter(Boolean),
|
|
82
83
|
recipients: txOutputs
|
|
83
|
-
// TODO REPLACE >>>>>>>>>>>>>>>>>>
|
|
84
84
|
.filter((o) => !isChangeOutput(o))
|
|
85
|
-
/*/ WITH <<<<<<<<<<<<<<<<<<<<<<<<<
|
|
86
|
-
.filter((o) => !o.isChange)
|
|
87
|
-
//*/
|
|
88
85
|
.map((t) => t.address)
|
|
89
86
|
.filter(Boolean),
|
|
90
87
|
})
|
|
@@ -372,6 +369,17 @@ const stakenet: AppSpec<Transaction> = {
|
|
|
372
369
|
test: genericTest,
|
|
373
370
|
mutations: bitcoinLikeMutations(),
|
|
374
371
|
};
|
|
372
|
+
const stratis: AppSpec<Transaction> = {
|
|
373
|
+
name: "Stratis",
|
|
374
|
+
currency: getCryptoCurrencyById("stratis"),
|
|
375
|
+
dependency: "Bitcoin",
|
|
376
|
+
appQuery: {
|
|
377
|
+
model: DeviceModelId.nanoS,
|
|
378
|
+
appName: "Stratis",
|
|
379
|
+
},
|
|
380
|
+
test: genericTest,
|
|
381
|
+
mutations: bitcoinLikeMutations(),
|
|
382
|
+
};
|
|
375
383
|
const vertcoin: AppSpec<Transaction> = {
|
|
376
384
|
name: "Vertcoin",
|
|
377
385
|
currency: getCryptoCurrencyById("vertcoin"),
|
|
@@ -541,6 +549,7 @@ export default {
|
|
|
541
549
|
qtum,
|
|
542
550
|
stakenet,
|
|
543
551
|
stealthcoin,
|
|
552
|
+
stratis,
|
|
544
553
|
vertcoin,
|
|
545
554
|
viacoin,
|
|
546
555
|
zcash,
|
|
@@ -2,7 +2,7 @@ import type { DeviceAction } from "../../bot/types";
|
|
|
2
2
|
import type { Transaction } from "./types";
|
|
3
3
|
import { formatCurrencyUnit } from "../../currencies";
|
|
4
4
|
import { deviceActionFlow } from "../../bot/specs";
|
|
5
|
-
import { perCoinLogic } from "./
|
|
5
|
+
import { perCoinLogic } from "./transaction";
|
|
6
6
|
const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
7
7
|
steps: [
|
|
8
8
|
{
|
|
@@ -19,7 +19,7 @@ import vertcoin from "./datasets/vertcoin";
|
|
|
19
19
|
import viacoin from "./datasets/viacoin";
|
|
20
20
|
import zcash from "./datasets/zcash";
|
|
21
21
|
const dataset: DatasetTest<Transaction> = {
|
|
22
|
-
implementations: ["
|
|
22
|
+
implementations: ["libcore", "mock"],
|
|
23
23
|
currencies: {
|
|
24
24
|
bitcoin_cash,
|
|
25
25
|
bitcoin_gold,
|
|
@@ -25,102 +25,6 @@ import { formatCurrencyUnit } from "../../currencies";
|
|
|
25
25
|
import type { CryptoCurrencyIds } from "../../types";
|
|
26
26
|
import { libcoreAmountToBigNumber } from "../../libcore/buildBigNumber";
|
|
27
27
|
|
|
28
|
-
const fromFeeItemsRaw = (fir: FeeItemsRaw): FeeItems => ({
|
|
29
|
-
items: fir.items.map((fi) => ({
|
|
30
|
-
key: fi.key,
|
|
31
|
-
speed: fi.speed,
|
|
32
|
-
feePerByte: new BigNumber(fi.feePerByte),
|
|
33
|
-
})),
|
|
34
|
-
defaultFeePerByte: new BigNumber(fir.defaultFeePerByte),
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const toFeeItemsRaw = (fir: FeeItems): FeeItemsRaw => ({
|
|
38
|
-
items: fir.items.map((fi) => ({
|
|
39
|
-
key: fi.key,
|
|
40
|
-
speed: fi.speed,
|
|
41
|
-
feePerByte: fi.feePerByte.toString(),
|
|
42
|
-
})),
|
|
43
|
-
defaultFeePerByte: fir.defaultFeePerByte.toString(),
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
47
|
-
const common = fromTransactionCommonRaw(tr);
|
|
48
|
-
return {
|
|
49
|
-
...common,
|
|
50
|
-
rbf: tr.rbf,
|
|
51
|
-
utxoStrategy: tr.utxoStrategy,
|
|
52
|
-
family: tr.family,
|
|
53
|
-
feePerByte: tr.feePerByte ? new BigNumber(tr.feePerByte) : null,
|
|
54
|
-
networkInfo: tr.networkInfo && {
|
|
55
|
-
family: tr.networkInfo.family,
|
|
56
|
-
feeItems: fromFeeItemsRaw(tr.networkInfo.feeItems),
|
|
57
|
-
},
|
|
58
|
-
feesStrategy: tr.feesStrategy,
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
62
|
-
const common = toTransactionCommonRaw(t);
|
|
63
|
-
return {
|
|
64
|
-
...common,
|
|
65
|
-
rbf: t.rbf,
|
|
66
|
-
utxoStrategy: t.utxoStrategy,
|
|
67
|
-
family: t.family,
|
|
68
|
-
feePerByte: t.feePerByte ? t.feePerByte.toString() : null,
|
|
69
|
-
networkInfo: t.networkInfo && {
|
|
70
|
-
family: t.networkInfo.family,
|
|
71
|
-
feeItems: toFeeItemsRaw(t.networkInfo.feeItems),
|
|
72
|
-
},
|
|
73
|
-
feesStrategy: t.feesStrategy,
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const formatNetworkInfo = (
|
|
78
|
-
networkInfo:
|
|
79
|
-
| {
|
|
80
|
-
feeItems: FeeItems;
|
|
81
|
-
}
|
|
82
|
-
| null
|
|
83
|
-
| undefined
|
|
84
|
-
) => {
|
|
85
|
-
if (!networkInfo) return "network info not loaded";
|
|
86
|
-
return `network fees: ${networkInfo.feeItems.items
|
|
87
|
-
.map((i) => i.key + "=" + i.feePerByte.toString())
|
|
88
|
-
.join(", ")}`;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const formatTransaction = (t: Transaction, account: Account): string => {
|
|
92
|
-
const n = getEnv("DEBUG_UTXO_DISPLAY");
|
|
93
|
-
const { excludeUTXOs, strategy, pickUnconfirmedRBF } = t.utxoStrategy;
|
|
94
|
-
const displayAll = excludeUTXOs.length <= n;
|
|
95
|
-
return `
|
|
96
|
-
SEND ${
|
|
97
|
-
t.useAllAmount
|
|
98
|
-
? "MAX"
|
|
99
|
-
: formatCurrencyUnit(getAccountUnit(account), t.amount, {
|
|
100
|
-
showCode: true,
|
|
101
|
-
disableRounding: true,
|
|
102
|
-
})
|
|
103
|
-
}
|
|
104
|
-
TO ${t.recipient}
|
|
105
|
-
with feePerByte=${
|
|
106
|
-
t.feePerByte ? t.feePerByte.toString() : "?"
|
|
107
|
-
} (${formatNetworkInfo(t.networkInfo)})
|
|
108
|
-
${[
|
|
109
|
-
Object.keys(bitcoinPickingStrategy).find(
|
|
110
|
-
(k) => bitcoinPickingStrategy[k] === strategy
|
|
111
|
-
),
|
|
112
|
-
pickUnconfirmedRBF && "pick-unconfirmed",
|
|
113
|
-
t.rbf && "RBF-enabled",
|
|
114
|
-
]
|
|
115
|
-
.filter(Boolean)
|
|
116
|
-
.join(" ")}${excludeUTXOs
|
|
117
|
-
.slice(0, displayAll ? excludeUTXOs.length : n)
|
|
118
|
-
.map((utxo) => `\nexclude ${utxo.hash} @${utxo.outputIndex}`)
|
|
119
|
-
.join("")}`;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// TODO vvvvv DEPRECATED, TO BE REMOVED vvvvv
|
|
123
|
-
|
|
124
28
|
function bchExplicit(str: string): string {
|
|
125
29
|
const explicit = str.includes(":") ? str : "bitcoincash:" + str;
|
|
126
30
|
|
|
@@ -254,7 +158,6 @@ export async function parseBitcoinOutput(
|
|
|
254
158
|
outputIndex,
|
|
255
159
|
blockHeight,
|
|
256
160
|
address,
|
|
257
|
-
isChange: false,
|
|
258
161
|
path,
|
|
259
162
|
value,
|
|
260
163
|
rbf,
|
|
@@ -298,8 +201,100 @@ export function isChangeOutput(output: BitcoinOutput): boolean {
|
|
|
298
201
|
const p = output.path.split("/");
|
|
299
202
|
return p[p.length - 2] === "1";
|
|
300
203
|
}
|
|
301
|
-
// ==============================================================================
|
|
302
204
|
|
|
205
|
+
const fromFeeItemsRaw = (fir: FeeItemsRaw): FeeItems => ({
|
|
206
|
+
items: fir.items.map((fi) => ({
|
|
207
|
+
key: fi.key,
|
|
208
|
+
speed: fi.speed,
|
|
209
|
+
feePerByte: new BigNumber(fi.feePerByte),
|
|
210
|
+
})),
|
|
211
|
+
defaultFeePerByte: new BigNumber(fir.defaultFeePerByte),
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const toFeeItemsRaw = (fir: FeeItems): FeeItemsRaw => ({
|
|
215
|
+
items: fir.items.map((fi) => ({
|
|
216
|
+
key: fi.key,
|
|
217
|
+
speed: fi.speed,
|
|
218
|
+
feePerByte: fi.feePerByte.toString(),
|
|
219
|
+
})),
|
|
220
|
+
defaultFeePerByte: fir.defaultFeePerByte.toString(),
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
224
|
+
const common = fromTransactionCommonRaw(tr);
|
|
225
|
+
return {
|
|
226
|
+
...common,
|
|
227
|
+
rbf: tr.rbf,
|
|
228
|
+
utxoStrategy: tr.utxoStrategy,
|
|
229
|
+
family: tr.family,
|
|
230
|
+
feePerByte: tr.feePerByte ? new BigNumber(tr.feePerByte) : null,
|
|
231
|
+
networkInfo: tr.networkInfo && {
|
|
232
|
+
family: tr.networkInfo.family,
|
|
233
|
+
feeItems: fromFeeItemsRaw(tr.networkInfo.feeItems),
|
|
234
|
+
},
|
|
235
|
+
feesStrategy: tr.feesStrategy,
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
239
|
+
const common = toTransactionCommonRaw(t);
|
|
240
|
+
return {
|
|
241
|
+
...common,
|
|
242
|
+
rbf: t.rbf,
|
|
243
|
+
utxoStrategy: t.utxoStrategy,
|
|
244
|
+
family: t.family,
|
|
245
|
+
feePerByte: t.feePerByte ? t.feePerByte.toString() : null,
|
|
246
|
+
networkInfo: t.networkInfo && {
|
|
247
|
+
family: t.networkInfo.family,
|
|
248
|
+
feeItems: toFeeItemsRaw(t.networkInfo.feeItems),
|
|
249
|
+
},
|
|
250
|
+
feesStrategy: t.feesStrategy,
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const formatNetworkInfo = (
|
|
255
|
+
networkInfo:
|
|
256
|
+
| {
|
|
257
|
+
feeItems: FeeItems;
|
|
258
|
+
}
|
|
259
|
+
| null
|
|
260
|
+
| undefined
|
|
261
|
+
) => {
|
|
262
|
+
if (!networkInfo) return "network info not loaded";
|
|
263
|
+
return `network fees: ${networkInfo.feeItems.items
|
|
264
|
+
.map((i) => i.key + "=" + i.feePerByte.toString())
|
|
265
|
+
.join(", ")}`;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
export const formatTransaction = (t: Transaction, account: Account): string => {
|
|
269
|
+
const n = getEnv("DEBUG_UTXO_DISPLAY");
|
|
270
|
+
const { excludeUTXOs, strategy, pickUnconfirmedRBF } = t.utxoStrategy;
|
|
271
|
+
const displayAll = excludeUTXOs.length <= n;
|
|
272
|
+
return `
|
|
273
|
+
SEND ${
|
|
274
|
+
t.useAllAmount
|
|
275
|
+
? "MAX"
|
|
276
|
+
: formatCurrencyUnit(getAccountUnit(account), t.amount, {
|
|
277
|
+
showCode: true,
|
|
278
|
+
disableRounding: true,
|
|
279
|
+
})
|
|
280
|
+
}
|
|
281
|
+
TO ${t.recipient}
|
|
282
|
+
with feePerByte=${
|
|
283
|
+
t.feePerByte ? t.feePerByte.toString() : "?"
|
|
284
|
+
} (${formatNetworkInfo(t.networkInfo)})
|
|
285
|
+
${[
|
|
286
|
+
Object.keys(bitcoinPickingStrategy).find(
|
|
287
|
+
(k) => bitcoinPickingStrategy[k] === strategy
|
|
288
|
+
),
|
|
289
|
+
pickUnconfirmedRBF && "pick-unconfirmed",
|
|
290
|
+
t.rbf && "RBF-enabled",
|
|
291
|
+
]
|
|
292
|
+
.filter(Boolean)
|
|
293
|
+
.join(" ")}${excludeUTXOs
|
|
294
|
+
.slice(0, displayAll ? excludeUTXOs.length : n)
|
|
295
|
+
.map((utxo) => `\nexclude ${utxo.hash} @${utxo.outputIndex}`)
|
|
296
|
+
.join("")}`;
|
|
297
|
+
};
|
|
303
298
|
export default {
|
|
304
299
|
fromTransactionRaw,
|
|
305
300
|
toTransactionRaw,
|