@ledgerhq/live-common 22.2.0 → 22.2.1-nightly.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.
Files changed (126) hide show
  1. package/README.md +12 -0
  2. package/lib/bridge/mockHelpers.d.ts.map +1 -1
  3. package/lib/bridge/mockHelpers.js +2 -0
  4. package/lib/bridge/mockHelpers.js.map +1 -1
  5. package/lib/bridge/useBridgeTransaction.d.ts +3 -0
  6. package/lib/bridge/useBridgeTransaction.d.ts.map +1 -1
  7. package/lib/bridge/useBridgeTransaction.js +18 -1
  8. package/lib/bridge/useBridgeTransaction.js.map +1 -1
  9. package/lib/bridge/useBridgeTransaction.test.d.ts +2 -0
  10. package/lib/bridge/useBridgeTransaction.test.d.ts.map +1 -0
  11. package/lib/bridge/useBridgeTransaction.test.js +145 -0
  12. package/lib/bridge/useBridgeTransaction.test.js.map +1 -0
  13. package/lib/data/icons/react/abi.d.ts +8 -0
  14. package/lib/data/icons/react/abi.d.ts.map +1 -0
  15. package/lib/data/icons/react/abi.js +35 -0
  16. package/lib/data/icons/react/abi.js.map +1 -0
  17. package/lib/data/icons/react/gAbi.d.ts +8 -0
  18. package/lib/data/icons/react/gAbi.d.ts.map +1 -0
  19. package/lib/data/icons/react/gAbi.js +36 -0
  20. package/lib/data/icons/react/gAbi.js.map +1 -0
  21. package/lib/data/icons/react/index.d.ts +3 -0
  22. package/lib/data/icons/react/index.d.ts.map +1 -1
  23. package/lib/data/icons/react/index.js +16 -10
  24. package/lib/data/icons/react/index.js.map +1 -1
  25. package/lib/data/icons/react/sAbi.d.ts +8 -0
  26. package/lib/data/icons/react/sAbi.d.ts.map +1 -0
  27. package/lib/data/icons/react/sAbi.js +35 -0
  28. package/lib/data/icons/react/sAbi.js.map +1 -0
  29. package/lib/data/icons/reactNative/abi.d.ts +8 -0
  30. package/lib/data/icons/reactNative/abi.d.ts.map +1 -0
  31. package/lib/data/icons/reactNative/abi.js +36 -0
  32. package/lib/data/icons/reactNative/abi.js.map +1 -0
  33. package/lib/data/icons/reactNative/gAbi.d.ts +8 -0
  34. package/lib/data/icons/reactNative/gAbi.d.ts.map +1 -0
  35. package/lib/data/icons/reactNative/gAbi.js +37 -0
  36. package/lib/data/icons/reactNative/gAbi.js.map +1 -0
  37. package/lib/data/icons/reactNative/index.d.ts +3 -0
  38. package/lib/data/icons/reactNative/index.d.ts.map +1 -1
  39. package/lib/data/icons/reactNative/index.js +16 -10
  40. package/lib/data/icons/reactNative/index.js.map +1 -1
  41. package/lib/data/icons/reactNative/sAbi.d.ts +8 -0
  42. package/lib/data/icons/reactNative/sAbi.d.ts.map +1 -0
  43. package/lib/data/icons/reactNative/sAbi.js +36 -0
  44. package/lib/data/icons/reactNative/sAbi.js.map +1 -0
  45. package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
  46. package/lib/exchange/swap/getExchangeRates.js +15 -14
  47. package/lib/exchange/swap/getExchangeRates.js.map +1 -1
  48. package/lib/exchange/swap/getExchangeRates.test.d.ts +2 -0
  49. package/lib/exchange/swap/getExchangeRates.test.d.ts.map +1 -0
  50. package/lib/exchange/swap/getExchangeRates.test.js +200 -0
  51. package/lib/exchange/swap/getExchangeRates.test.js.map +1 -0
  52. package/lib/families/bitcoin/bridge/js.d.ts.map +1 -1
  53. package/lib/families/bitcoin/bridge/js.js +2 -0
  54. package/lib/families/bitcoin/bridge/js.js.map +1 -1
  55. package/lib/families/cosmos/specs.d.ts.map +1 -1
  56. package/lib/families/cosmos/specs.js +0 -1
  57. package/lib/families/cosmos/specs.js.map +1 -1
  58. package/lib/families/ethereum/specs.js +2 -2
  59. package/lib/families/ethereum/specs.js.map +1 -1
  60. package/lib/families/polkadot/bridge/js.d.ts.map +1 -1
  61. package/lib/families/polkadot/bridge/js.js +5 -1
  62. package/lib/families/polkadot/bridge/js.js.map +1 -1
  63. package/lib/families/polkadot/js-buildTransaction.d.ts.map +1 -1
  64. package/lib/families/polkadot/js-buildTransaction.js +12 -8
  65. package/lib/families/polkadot/js-buildTransaction.js.map +1 -1
  66. package/lib/families/polkadot/js-estimateMaxSpendable.d.ts.map +1 -1
  67. package/lib/families/polkadot/js-estimateMaxSpendable.js +5 -2
  68. package/lib/families/polkadot/js-estimateMaxSpendable.js.map +1 -1
  69. package/lib/families/polkadot/js-getTransactionStatus.d.ts.map +1 -1
  70. package/lib/families/polkadot/js-getTransactionStatus.js +58 -55
  71. package/lib/families/polkadot/js-getTransactionStatus.js.map +1 -1
  72. package/lib/families/polkadot/js-prepareTransaction.d.ts.map +1 -1
  73. package/lib/families/polkadot/js-prepareTransaction.js +5 -2
  74. package/lib/families/polkadot/js-prepareTransaction.js.map +1 -1
  75. package/lib/families/polkadot/js-synchronisation.d.ts.map +1 -1
  76. package/lib/families/polkadot/js-synchronisation.js +6 -3
  77. package/lib/families/polkadot/js-synchronisation.js.map +1 -1
  78. package/lib/families/polkadot/polkadot-crypto.d.ts +2 -0
  79. package/lib/families/polkadot/polkadot-crypto.d.ts.map +1 -0
  80. package/lib/families/polkadot/polkadot-crypto.js +14 -0
  81. package/lib/families/polkadot/polkadot-crypto.js.map +1 -0
  82. package/lib/families/polkadot/preload.d.ts.map +1 -1
  83. package/lib/families/polkadot/preload.js +16 -12
  84. package/lib/families/polkadot/preload.js.map +1 -1
  85. package/lib/market/api/api.d.ts +1 -1
  86. package/lib/market/api/api.d.ts.map +1 -1
  87. package/lib/market/api/api.js +43 -24
  88. package/lib/market/api/api.js.map +1 -1
  89. package/lib/market/types.d.ts +1 -0
  90. package/lib/market/types.d.ts.map +1 -1
  91. package/lib/reactNative.d.ts +1 -0
  92. package/lib/reactNative.d.ts.map +1 -1
  93. package/lib/reactNative.js +3 -0
  94. package/lib/reactNative.js.map +1 -1
  95. package/package.json +19 -19
  96. package/src/bridge/mockHelpers.ts +5 -2
  97. package/src/bridge/useBridgeTransaction.test.ts +70 -0
  98. package/src/bridge/useBridgeTransaction.ts +22 -1
  99. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +1 -45
  100. package/src/data/icons/react/abi.tsx +14 -0
  101. package/src/data/icons/react/gAbi.tsx +14 -0
  102. package/src/data/icons/react/index.tsx +3 -0
  103. package/src/data/icons/react/sAbi.tsx +14 -0
  104. package/src/data/icons/reactNative/abi.tsx +15 -0
  105. package/src/data/icons/reactNative/gAbi.tsx +15 -0
  106. package/src/data/icons/reactNative/index.tsx +3 -0
  107. package/src/data/icons/reactNative/sAbi.tsx +15 -0
  108. package/src/data/icons/svg/ABI.svg +3 -0
  109. package/src/data/icons/svg/gABI.svg +4 -0
  110. package/src/data/icons/svg/sABI.svg +3 -0
  111. package/src/exchange/swap/getExchangeRates.test.ts +151 -0
  112. package/src/exchange/swap/getExchangeRates.ts +30 -22
  113. package/src/families/bitcoin/bridge/js.ts +2 -0
  114. package/src/families/cosmos/specs.ts +0 -1
  115. package/src/families/ethereum/specs.ts +2 -2
  116. package/src/families/polkadot/bridge/js.ts +2 -0
  117. package/src/families/polkadot/js-buildTransaction.ts +3 -0
  118. package/src/families/polkadot/js-estimateMaxSpendable.ts +2 -0
  119. package/src/families/polkadot/js-getTransactionStatus.ts +3 -0
  120. package/src/families/polkadot/js-prepareTransaction.ts +2 -0
  121. package/src/families/polkadot/js-synchronisation.ts +2 -0
  122. package/src/families/polkadot/polkadot-crypto.ts +10 -0
  123. package/src/families/polkadot/preload.ts +2 -0
  124. package/src/market/api/api.ts +39 -17
  125. package/src/market/types.ts +1 -0
  126. package/src/reactNative.ts +5 -0
@@ -1,17 +1,21 @@
1
- import type { Exchange, GetExchangeRates } from "./types";
2
- import type { Transaction } from "../../types";
1
+ import { BigNumber } from "bignumber.js";
3
2
  import { getAccountCurrency, getAccountUnit } from "../../account";
4
- import type { Unit, TokenCurrency, CryptoCurrency } from "../../types";
5
3
  import { formatCurrencyUnit } from "../../currencies";
6
- import { mockGetExchangeRates } from "./mock";
7
- import network from "../../network";
8
- import { getSwapAPIError, getSwapAPIBaseURL } from "./";
9
4
  import { getEnv } from "../../env";
10
- import { BigNumber } from "bignumber.js";
11
5
  import {
12
- SwapExchangeRateAmountTooLow,
13
6
  SwapExchangeRateAmountTooHigh,
7
+ SwapExchangeRateAmountTooLow,
14
8
  } from "../../errors";
9
+ import network from "../../network";
10
+ import type {
11
+ CryptoCurrency,
12
+ TokenCurrency,
13
+ Transaction,
14
+ Unit,
15
+ } from "../../types";
16
+ import { getSwapAPIBaseURL, getSwapAPIError } from "./";
17
+ import { mockGetExchangeRates } from "./mock";
18
+ import type { Exchange, GetExchangeRates } from "./types";
15
19
 
16
20
  const getExchangeRates: GetExchangeRates = async (
17
21
  exchange: Exchange,
@@ -66,30 +70,34 @@ const getExchangeRates: GetExchangeRates = async (
66
70
  };
67
71
  }
68
72
 
69
- // NB Allows us to simply multiply satoshi values from/to
70
- const magnitudeAwareRate = (
71
- tradeMethod === "fixed"
72
- ? new BigNumber(maybeRate)
73
- : new BigNumber(amountTo).div(amountFrom)
74
- ).div(new BigNumber(10).pow(unitFrom.magnitude - unitTo.magnitude));
73
+ const payoutNetworkFees = new BigNumber(maybePayoutNetworkFees || 0);
75
74
 
76
- const payoutNetworkFees = new BigNumber(maybePayoutNetworkFees || 0).times(
75
+ const magnitudeAwarePayoutNetworkFees = payoutNetworkFees.times(
77
76
  new BigNumber(10).pow(unitTo.magnitude)
78
77
  );
79
78
 
80
- const toAmount = new BigNumber(amountTo)
81
- .times(new BigNumber(10).pow(unitTo.magnitude))
82
- .minus(payoutNetworkFees); // Nb no longer need to break it down on UI
79
+ const rate = maybeRate
80
+ ? new BigNumber(maybeRate)
81
+ : new BigNumber(amountTo).minus(payoutNetworkFees).div(amountFrom);
82
+
83
+ // NB Allows us to simply multiply satoshi values from/to
84
+ const magnitudeAwareRate = rate.div(
85
+ new BigNumber(10).pow(unitFrom.magnitude - unitTo.magnitude)
86
+ );
87
+
88
+ const toAmount = new BigNumber(amountTo).minus(payoutNetworkFees);
83
89
 
84
- const rate =
85
- maybeRate || new BigNumber(amountTo).div(new BigNumber(amountFrom));
90
+ const magnitudeAwareToAmount = toAmount.times(
91
+ new BigNumber(10).pow(unitTo.magnitude)
92
+ );
93
+ // Nb no longer need to break it down on UI
86
94
 
87
95
  const out = {
88
96
  magnitudeAwareRate,
89
97
  provider,
90
98
  rate,
91
99
  rateId,
92
- toAmount,
100
+ toAmount: magnitudeAwareToAmount,
93
101
  tradeMethod,
94
102
  };
95
103
 
@@ -98,7 +106,7 @@ const getExchangeRates: GetExchangeRates = async (
98
106
  } else {
99
107
  return {
100
108
  ...out,
101
- payoutNetworkFees,
109
+ payoutNetworkFees: magnitudeAwarePayoutNetworkFees,
102
110
  };
103
111
  }
104
112
  });
@@ -25,6 +25,8 @@ const receive = makeAccountBridgeReceive({
25
25
  const updateTransaction = (t, patch) => {
26
26
  const updatedT = { ...t, ...patch };
27
27
 
28
+ // We accept case-insensitive addresses as input from user,
29
+ // but segwit addresses need to be converted to lowercase to be valid
28
30
  if (updatedT.recipient.toLowerCase().indexOf("bc1") === 0) {
29
31
  updatedT.recipient = updatedT.recipient.toLowerCase();
30
32
  }
@@ -50,7 +50,6 @@ const cosmos: AppSpec<Transaction> = {
50
50
  currency: getCryptoCurrencyById("cosmos"),
51
51
  appQuery: {
52
52
  model: DeviceModelId.nanoS,
53
- firmware: "2.0.0",
54
53
  appName: "Cosmos",
55
54
  },
56
55
  testTimeout: 2 * 60 * 1000,
@@ -26,10 +26,10 @@ const ethereumBasicMutations = ({ maxAccount }) => [
26
26
  {
27
27
  name: "move 50%",
28
28
  maxRun: 2,
29
- transaction: ({ account, siblings, bridge }) => {
29
+ transaction: ({ account, siblings, bridge, maxSpendable }) => {
30
30
  const sibling = pickSiblings(siblings, maxAccount);
31
31
  const recipient = sibling.freshAddress;
32
- const amount = account.balance.div(2).integerValue();
32
+ const amount = maxSpendable.div(2).integerValue();
33
33
  return {
34
34
  transaction: bridge.createTransaction(account),
35
35
  updates: [
@@ -15,6 +15,7 @@ import prepareTransaction from "../js-prepareTransaction";
15
15
  import getTransactionStatus from "../js-getTransactionStatus";
16
16
  import estimateMaxSpendable from "../js-estimateMaxSpendable";
17
17
  import signOperation from "../js-signOperation";
18
+ import { loadPolkadotCrypto } from "../polkadot-crypto";
18
19
  const receive = makeAccountBridgeReceive();
19
20
 
20
21
  const updateTransaction = (t, patch) => ({ ...t, ...patch });
@@ -28,6 +29,7 @@ const broadcast = async ({
28
29
  }: {
29
30
  signedOperation: SignedOperation;
30
31
  }): Promise<Operation> => {
32
+ await loadPolkadotCrypto();
31
33
  const hash = await submitExtrinsic(signature);
32
34
  return patchOperationWithHash(operation, hash);
33
35
  };
@@ -3,6 +3,7 @@ import type { Transaction } from "./types";
3
3
  import type { Account } from "../../types";
4
4
  import { getRegistry, getTransactionParams } from "./cache";
5
5
  import { isFirstBond, getNonce } from "./logic";
6
+ import { loadPolkadotCrypto } from "./polkadot-crypto";
6
7
  const EXTRINSIC_VERSION = 4;
7
8
  // Default values for tx parameters, if the user doesn't specify any
8
9
  const DEFAULTS = {
@@ -140,6 +141,8 @@ export const buildTransaction = async (
140
141
  t: Transaction,
141
142
  forceLatestParams = false
142
143
  ) => {
144
+ await loadPolkadotCrypto();
145
+
143
146
  const { extrinsics, registry } = await getRegistry();
144
147
  const info = forceLatestParams
145
148
  ? await getTransactionParams.force()
@@ -5,6 +5,7 @@ import type { Transaction } from "./types";
5
5
  import { calculateAmount } from "./logic";
6
6
  import getEstimatedFees from "./js-getFeesForTransaction";
7
7
  import createTransaction from "./js-createTransaction";
8
+ import { loadPolkadotCrypto } from "./polkadot-crypto";
8
9
 
9
10
  /**
10
11
  * Returns the maximum possible amount for transaction
@@ -20,6 +21,7 @@ const estimateMaxSpendable = async ({
20
21
  parentAccount: Account | null | undefined;
21
22
  transaction: Transaction | null | undefined;
22
23
  }): Promise<BigNumber> => {
24
+ await loadPolkadotCrypto();
23
25
  const a = getMainAccount(account, parentAccount);
24
26
  const t = { ...createTransaction(), ...transaction, useAllAmount: true };
25
27
  const fees = await getEstimatedFees({
@@ -41,6 +41,7 @@ import {
41
41
  import { isValidAddress } from "./address";
42
42
  import { getCurrentPolkadotPreloadData } from "./preload";
43
43
  import { isControllerAddress, isNewAccount, isElectionClosed } from "./cache";
44
+ import { loadPolkadotCrypto } from "./polkadot-crypto";
44
45
 
45
46
  // Should try to refacto
46
47
  const getSendTransactionStatus = async (
@@ -135,6 +136,8 @@ const getSendTransactionStatus = async (
135
136
  };
136
137
 
137
138
  const getTransactionStatus = async (a: Account, t: Transaction) => {
139
+ await loadPolkadotCrypto();
140
+
138
141
  const errors: {
139
142
  staking?: Error;
140
143
  amount?: Error;
@@ -1,6 +1,7 @@
1
1
  import type { Account } from "../../types";
2
2
  import type { Transaction } from "./types";
3
3
  import getEstimatedFees from "./js-getFeesForTransaction";
4
+ import { loadPolkadotCrypto } from "./polkadot-crypto";
4
5
 
5
6
  const sameFees = (a, b) => (!a || !b ? a === b : a.eq(b));
6
7
 
@@ -10,6 +11,7 @@ const sameFees = (a, b) => (!a || !b ? a === b : a.eq(b));
10
11
  * @param {Transaction} t
11
12
  */
12
13
  const prepareTransaction = async (a: Account, t: Transaction) => {
14
+ await loadPolkadotCrypto();
13
15
  let fees = t.fees;
14
16
  fees = await getEstimatedFees({
15
17
  a,
@@ -3,8 +3,10 @@ import { encodeAccountId } from "../../account";
3
3
  import type { GetAccountShape } from "../../bridge/jsHelpers";
4
4
  import { makeSync, makeScanAccounts, mergeOps } from "../../bridge/jsHelpers";
5
5
  import { getAccount, getOperations } from "./api";
6
+ import { loadPolkadotCrypto } from "./polkadot-crypto";
6
7
 
7
8
  const getAccountShape: GetAccountShape = async (info) => {
9
+ await loadPolkadotCrypto();
8
10
  const { address, initialAccount, currency, derivationMode } = info;
9
11
  const oldOperations = initialAccount?.operations || [];
10
12
  const startAt = oldOperations.length
@@ -0,0 +1,10 @@
1
+ import { cryptoWaitReady } from "@polkadot/util-crypto";
2
+
3
+ let loadingPromise: null | Promise<boolean>;
4
+
5
+ export function loadPolkadotCrypto(): Promise<boolean> {
6
+ if (loadingPromise) return loadingPromise;
7
+ const p = cryptoWaitReady();
8
+ loadingPromise = p;
9
+ return p;
10
+ }
@@ -6,6 +6,7 @@ import { PRELOAD_MAX_AGE } from "./logic";
6
6
  import { getRegistry, getMinimumBondBalance } from "./cache";
7
7
  import type { PolkadotPreloadData, PolkadotValidator } from "./types";
8
8
  import { getStakingProgress, getValidators } from "./validators";
9
+ import { loadPolkadotCrypto } from "./polkadot-crypto";
9
10
 
10
11
  let currentPolkadotPreloadedData: PolkadotPreloadData = {
11
12
  validators: [],
@@ -105,6 +106,7 @@ const shouldRefreshValidators = (previousState, currentState) => {
105
106
  };
106
107
 
107
108
  export const preload = async (): Promise<PolkadotPreloadData> => {
109
+ await loadPolkadotCrypto();
108
110
  await getRegistry(); // ensure registry is already in cache.
109
111
  const minimumBondBalance = await getMinimumBondBalance();
110
112
  const minimumBondBalanceStr = minimumBondBalance.toString();
@@ -102,29 +102,36 @@ async function listPaginated({
102
102
  search = "",
103
103
  sparkline = true,
104
104
  liveCompatible = false,
105
+ top100 = false,
105
106
  }: MarketListRequestParams): Promise<CurrencyData[]> {
106
107
  let ids = _ids;
107
108
 
108
- if (search) {
109
- ids = SUPPORTED_COINS_LIST.filter(matchSearch(search)).map(({ id }) => id);
110
- if (!ids.length) {
111
- return [];
109
+ if (top100) {
110
+ limit = 100;
111
+ } else {
112
+ if (search) {
113
+ ids = SUPPORTED_COINS_LIST.filter(matchSearch(search)).map(
114
+ ({ id }) => id
115
+ );
116
+ if (!ids.length) {
117
+ return [];
118
+ }
112
119
  }
113
- }
114
120
 
115
- if (liveCompatible) {
116
- if (ids.length > 0) {
117
- ids = LIVE_COINS_LIST.filter((id) => ids.includes(id));
118
- } else {
119
- ids = ids.concat(LIVE_COINS_LIST);
121
+ if (liveCompatible) {
122
+ if (ids.length > 0) {
123
+ ids = LIVE_COINS_LIST.filter((id) => ids.includes(id));
124
+ } else {
125
+ ids = ids.concat(LIVE_COINS_LIST);
126
+ }
120
127
  }
121
- }
122
128
 
123
- if (starred.length > 0) {
124
- if (ids.length > 0) {
125
- ids = starred.filter((id) => ids.includes(id));
126
- } else {
127
- ids = ids.concat(starred);
129
+ if (starred.length > 0) {
130
+ if (ids.length > 0) {
131
+ ids = starred.filter((id) => ids.includes(id));
132
+ } else {
133
+ ids = ids.concat(starred);
134
+ }
128
135
  }
129
136
  }
130
137
 
@@ -137,11 +144,26 @@ async function listPaginated({
137
144
  }&price_change_percentage=${range}` +
138
145
  `${ids.length > 0 ? `&page=1&&ids=${ids.toString()}` : `&page=${page}`}`;
139
146
 
140
- const { data } = await network({
147
+ let { data } = await network({
141
148
  method: "GET",
142
149
  url,
143
150
  });
144
151
 
152
+ if (top100) {
153
+ // Perform a search by the user's input and order the result by change in percentage
154
+ data = data
155
+ .filter((currency) => {
156
+ if (!search) return true;
157
+ const match = `${currency.symbol}|${currency.name}`;
158
+ return match.toLowerCase().includes(search.toLowerCase());
159
+ })
160
+ .sort(
161
+ (a, b) =>
162
+ b[`price_change_percentage_${range}_in_currency`] -
163
+ a[`price_change_percentage_${range}_in_currency`]
164
+ );
165
+ }
166
+
145
167
  return data.map(
146
168
  (currency: {
147
169
  [x: string]: any;
@@ -22,6 +22,7 @@ export type MarketListRequestParams = {
22
22
  lastRequestTime?: Date;
23
23
  sparkline?: boolean;
24
24
  liveCompatible?: boolean;
25
+ top100?: boolean;
25
26
  };
26
27
 
27
28
  export type MarketCurrencyChartDataRequestParams = {
@@ -1,6 +1,11 @@
1
+ // Uses Asm.js version of @polkadot/util-crypto
2
+ // See: https://polkadot.js.org/docs/util-crypto/FAQ/#i-dont-have-wasm-available-in-my-environment
3
+ import "@polkadot/wasm-crypto/initOnlyAsm";
4
+
1
5
  import * as icons from "./data/icons/reactNative";
2
6
  import * as flags from "./data/flags/reactNative";
3
7
  import type { CryptoCurrency, TokenCurrency } from "./types";
8
+
4
9
  type Icon = React.ComponentType<{
5
10
  size: number;
6
11
  color: string;