@ledgerhq/live-common 23.1.0 → 24.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (470) hide show
  1. package/lib/__tests__/mocks/account.js +3 -3
  2. package/lib/__tests__/mocks/account.js.map +1 -1
  3. package/lib/__tests__/test-helpers/bridge.d.ts +1 -4
  4. package/lib/__tests__/test-helpers/bridge.d.ts.map +1 -1
  5. package/lib/__tests__/test-helpers/bridge.js +1 -28
  6. package/lib/__tests__/test-helpers/bridge.js.map +1 -1
  7. package/lib/__tests__/test-helpers/setup.js +51 -0
  8. package/lib/__tests__/test-helpers/setup.js.map +1 -1
  9. package/lib/api/Ripple.d.ts.map +1 -1
  10. package/lib/api/Ripple.js +113 -68
  11. package/lib/api/Ripple.js.map +1 -1
  12. package/lib/apps/support.d.ts.map +1 -1
  13. package/lib/apps/support.js +6 -2
  14. package/lib/apps/support.js.map +1 -1
  15. package/lib/bot/index.d.ts.map +1 -1
  16. package/lib/bot/index.js +13 -19
  17. package/lib/bot/index.js.map +1 -1
  18. package/lib/bot/test.bot.d.ts +1 -1
  19. package/lib/bot/test.bot.d.ts.map +1 -1
  20. package/lib/bot/test.bot.js +1 -2
  21. package/lib/bot/test.bot.js.map +1 -1
  22. package/lib/countervalues/logic.integration.test.d.ts +2 -0
  23. package/lib/countervalues/logic.integration.test.d.ts.map +1 -0
  24. package/lib/countervalues/{logic.test.js → logic.integration.test.js} +1 -1
  25. package/lib/countervalues/logic.integration.test.js.map +1 -0
  26. package/lib/countervalues/react.d.ts +1 -21
  27. package/lib/countervalues/react.d.ts.map +1 -1
  28. package/lib/countervalues/react.js +1 -77
  29. package/lib/countervalues/react.js.map +1 -1
  30. package/lib/derivation.d.ts +1 -0
  31. package/lib/derivation.d.ts.map +1 -1
  32. package/lib/derivation.js +3 -2
  33. package/lib/derivation.js.map +1 -1
  34. package/lib/env.d.ts +16 -6
  35. package/lib/env.d.ts.map +1 -1
  36. package/lib/env.js +11 -1
  37. package/lib/env.js.map +1 -1
  38. package/lib/env.react.d.ts +1 -1
  39. package/lib/env.react.d.ts.map +1 -1
  40. package/lib/errors.d.ts +0 -3
  41. package/lib/errors.d.ts.map +1 -1
  42. package/lib/errors.js +2 -3
  43. package/lib/errors.js.map +1 -1
  44. package/lib/exchange/index.d.ts +5 -0
  45. package/lib/exchange/index.d.ts.map +1 -1
  46. package/lib/exchange/index.js.map +1 -1
  47. package/lib/exchange/swap/checkQuote.d.ts +4 -0
  48. package/lib/exchange/swap/checkQuote.d.ts.map +1 -0
  49. package/lib/{families/tezos/bridge.test.js → exchange/swap/checkQuote.js} +35 -36
  50. package/lib/exchange/swap/checkQuote.js.map +1 -0
  51. package/lib/exchange/swap/checkQuote.test.d.ts +2 -0
  52. package/lib/exchange/swap/checkQuote.test.d.ts.map +1 -0
  53. package/lib/{families/filecoin/bridge.test.js → exchange/swap/checkQuote.test.js} +53 -42
  54. package/lib/exchange/swap/checkQuote.test.js.map +1 -0
  55. package/lib/exchange/swap/completeExchange.d.ts.map +1 -1
  56. package/lib/exchange/swap/completeExchange.js +9 -9
  57. package/lib/exchange/swap/completeExchange.js.map +1 -1
  58. package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
  59. package/lib/exchange/swap/getExchangeRates.js +3 -1
  60. package/lib/exchange/swap/getExchangeRates.js.map +1 -1
  61. package/lib/exchange/swap/getExchangeRates.test.js +1 -2
  62. package/lib/exchange/swap/getExchangeRates.test.js.map +1 -1
  63. package/lib/exchange/swap/getProviders.d.ts.map +1 -1
  64. package/lib/exchange/swap/getProviders.js +10 -4
  65. package/lib/exchange/swap/getProviders.js.map +1 -1
  66. package/lib/exchange/swap/getStatus.d.ts +1 -3
  67. package/lib/exchange/swap/getStatus.d.ts.map +1 -1
  68. package/lib/exchange/swap/getStatus.js +2 -30
  69. package/lib/exchange/swap/getStatus.js.map +1 -1
  70. package/lib/exchange/swap/hooks/usePollKYCStatus.test.js +4 -5
  71. package/lib/exchange/swap/hooks/usePollKYCStatus.test.js.map +1 -1
  72. package/lib/exchange/swap/hooks/useProviderRates.d.ts +3 -4
  73. package/lib/exchange/swap/hooks/useProviderRates.d.ts.map +1 -1
  74. package/lib/exchange/swap/hooks/useProviderRates.js +35 -5
  75. package/lib/exchange/swap/hooks/useProviderRates.js.map +1 -1
  76. package/lib/exchange/swap/hooks/useProviderRates.test.js +107 -3
  77. package/lib/exchange/swap/hooks/useProviderRates.test.js.map +1 -1
  78. package/lib/exchange/swap/hooks/useSwapProviders.test.js +1 -2
  79. package/lib/exchange/swap/hooks/useSwapProviders.test.js.map +1 -1
  80. package/lib/exchange/swap/hooks/useSwapTransaction.d.ts +5 -4
  81. package/lib/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -1
  82. package/lib/exchange/swap/hooks/useSwapTransaction.js +6 -6
  83. package/lib/exchange/swap/hooks/useSwapTransaction.js.map +1 -1
  84. package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts +4 -3
  85. package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts.map +1 -1
  86. package/lib/exchange/swap/hooks/useUpdateMaxAmount.js +8 -5
  87. package/lib/exchange/swap/hooks/useUpdateMaxAmount.js.map +1 -1
  88. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js +37 -7
  89. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -1
  90. package/lib/exchange/swap/index.d.ts +10 -8
  91. package/lib/exchange/swap/index.d.ts.map +1 -1
  92. package/lib/exchange/swap/index.js +43 -18
  93. package/lib/exchange/swap/index.js.map +1 -1
  94. package/lib/exchange/swap/index.test.d.ts +2 -0
  95. package/lib/exchange/swap/index.test.d.ts.map +1 -0
  96. package/lib/exchange/swap/index.test.js +30 -0
  97. package/lib/exchange/swap/index.test.js.map +1 -0
  98. package/lib/exchange/swap/initSwap.d.ts +1 -1
  99. package/lib/exchange/swap/initSwap.d.ts.map +1 -1
  100. package/lib/exchange/swap/initSwap.js +30 -25
  101. package/lib/exchange/swap/initSwap.js.map +1 -1
  102. package/lib/exchange/swap/mock.d.ts +5 -2
  103. package/lib/exchange/swap/mock.d.ts.map +1 -1
  104. package/lib/exchange/swap/mock.js +127 -6
  105. package/lib/exchange/swap/mock.js.map +1 -1
  106. package/lib/exchange/swap/postSwapState.d.ts +4 -0
  107. package/lib/exchange/swap/postSwapState.d.ts.map +1 -0
  108. package/lib/exchange/swap/postSwapState.js +121 -0
  109. package/lib/exchange/swap/postSwapState.js.map +1 -0
  110. package/lib/exchange/swap/types.d.ts +30 -2
  111. package/lib/exchange/swap/types.d.ts.map +1 -1
  112. package/lib/exchange/swap/updateAccountSwapStatus.d.ts.map +1 -1
  113. package/lib/exchange/swap/updateAccountSwapStatus.js +2 -2
  114. package/lib/exchange/swap/updateAccountSwapStatus.js.map +1 -1
  115. package/lib/exchange/swap/utils/index.d.ts +19 -2
  116. package/lib/exchange/swap/utils/index.d.ts.map +1 -1
  117. package/lib/exchange/swap/utils/index.js +96 -20
  118. package/lib/exchange/swap/utils/index.js.map +1 -1
  119. package/lib/exchange/swap/utils/index.test.js +95 -48
  120. package/lib/exchange/swap/utils/index.test.js.map +1 -1
  121. package/lib/families/algorand/bridge.integration.test.d.ts +2 -0
  122. package/lib/families/algorand/bridge.integration.test.d.ts.map +1 -0
  123. package/lib/families/algorand/{test-dataset.js → bridge.integration.test.js} +12 -11
  124. package/lib/families/algorand/bridge.integration.test.js.map +1 -0
  125. package/lib/families/bitcoin/bridge.integration.test.d.ts +2 -0
  126. package/lib/families/bitcoin/bridge.integration.test.d.ts.map +1 -0
  127. package/lib/families/bitcoin/{test-dataset.js → bridge.integration.test.js} +17 -14
  128. package/lib/families/bitcoin/bridge.integration.test.js.map +1 -0
  129. package/lib/families/bitcoin/descriptor.d.ts.map +1 -1
  130. package/lib/families/bitcoin/descriptor.js +2 -1
  131. package/lib/families/bitcoin/descriptor.js.map +1 -1
  132. package/lib/families/bitcoin/satstack.d.ts.map +1 -1
  133. package/lib/families/bitcoin/satstack.js +5 -6
  134. package/lib/families/bitcoin/satstack.js.map +1 -1
  135. package/lib/families/bitcoin/satstack.test.js +4 -1
  136. package/lib/families/bitcoin/satstack.test.js.map +1 -1
  137. package/lib/families/bitcoin/specs.d.ts.map +1 -1
  138. package/lib/families/bitcoin/specs.js +1 -2
  139. package/lib/families/bitcoin/specs.js.map +1 -1
  140. package/lib/families/cardano/bridge.integration.test.d.ts +2 -0
  141. package/lib/families/cardano/bridge.integration.test.d.ts.map +1 -0
  142. package/lib/families/cardano/{test-dataset.js → bridge.integration.test.js} +4 -2
  143. package/lib/families/cardano/bridge.integration.test.js.map +1 -0
  144. package/lib/families/celo/bridge.integration.test.d.ts +2 -0
  145. package/lib/families/celo/bridge.integration.test.d.ts.map +1 -0
  146. package/lib/families/celo/bridge.integration.test.js +16 -0
  147. package/lib/families/celo/bridge.integration.test.js.map +1 -0
  148. package/lib/families/cosmos/bridge.integration.test.d.ts +2 -0
  149. package/lib/families/cosmos/bridge.integration.test.d.ts.map +1 -0
  150. package/lib/families/cosmos/{test-dataset.js → bridge.integration.test.js} +5 -4
  151. package/lib/families/cosmos/bridge.integration.test.js.map +1 -0
  152. package/lib/families/cosmos/speculos-deviceActions.js +2 -2
  153. package/lib/families/crypto_org/bridge.integration.test.d.ts +2 -0
  154. package/lib/families/crypto_org/bridge.integration.test.d.ts.map +1 -0
  155. package/lib/families/crypto_org/bridge.integration.test.js +16 -0
  156. package/lib/families/crypto_org/bridge.integration.test.js.map +1 -0
  157. package/lib/families/elrond/bridge.integration.test.d.ts +2 -0
  158. package/lib/families/elrond/bridge.integration.test.d.ts.map +1 -0
  159. package/lib/families/elrond/{test-dataset.js → bridge.integration.test.js} +5 -5
  160. package/lib/families/elrond/bridge.integration.test.js.map +1 -0
  161. package/lib/families/ethereum/bridge.integration.test.d.ts +2 -0
  162. package/lib/families/ethereum/bridge.integration.test.d.ts.map +1 -0
  163. package/lib/families/ethereum/{test-dataset.js → bridge.integration.test.js} +8 -24
  164. package/lib/families/ethereum/bridge.integration.test.js.map +1 -0
  165. package/lib/families/ethereum/datasets/ethereum1.d.ts +3 -0
  166. package/lib/families/ethereum/datasets/ethereum1.d.ts.map +1 -0
  167. package/lib/families/ethereum/datasets/ethereum1.js +22 -0
  168. package/lib/families/ethereum/datasets/ethereum1.js.map +1 -0
  169. package/lib/families/ethereum/modules/compound.resilience.integration.test.d.ts +2 -0
  170. package/lib/families/ethereum/modules/compound.resilience.integration.test.d.ts.map +1 -0
  171. package/lib/families/ethereum/modules/{compound.resilience.test.js → compound.resilience.integration.test.js} +3 -3
  172. package/lib/families/ethereum/modules/compound.resilience.integration.test.js.map +1 -0
  173. package/lib/families/ethereum/modules/erc1155.d.ts.map +1 -1
  174. package/lib/families/ethereum/modules/erc1155.js +5 -1
  175. package/lib/families/ethereum/modules/erc1155.js.map +1 -1
  176. package/lib/families/ethereum/modules/erc721.d.ts.map +1 -1
  177. package/lib/families/ethereum/modules/erc721.js +5 -0
  178. package/lib/families/ethereum/modules/erc721.js.map +1 -1
  179. package/lib/families/ethereum/nft.unit.test.js +35 -15
  180. package/lib/families/ethereum/nft.unit.test.js.map +1 -1
  181. package/lib/families/ethereum/synchronisation.d.ts.map +1 -1
  182. package/lib/families/ethereum/synchronisation.integration.test.d.ts +2 -0
  183. package/lib/families/ethereum/synchronisation.integration.test.d.ts.map +1 -0
  184. package/lib/families/ethereum/{synchronisation.test.js → synchronisation.integration.test.js} +4 -4
  185. package/lib/families/ethereum/synchronisation.integration.test.js.map +1 -0
  186. package/lib/families/ethereum/synchronisation.js +17 -13
  187. package/lib/families/ethereum/synchronisation.js.map +1 -1
  188. package/lib/families/filecoin/bridge.integration.test.d.ts +2 -0
  189. package/lib/families/filecoin/bridge.integration.test.d.ts.map +1 -0
  190. package/lib/families/filecoin/{test-dataset.js → bridge.integration.test.js} +84 -3
  191. package/lib/families/filecoin/bridge.integration.test.js.map +1 -0
  192. package/lib/families/hedera/bridge.integration.test.d.ts +2 -0
  193. package/lib/families/hedera/bridge.integration.test.d.ts.map +1 -0
  194. package/lib/families/hedera/{test-dataset.js → bridge.integration.test.js} +5 -3
  195. package/lib/families/hedera/bridge.integration.test.js.map +1 -0
  196. package/lib/families/polkadot/bridge.integration.test.d.ts +2 -0
  197. package/lib/families/polkadot/bridge.integration.test.d.ts.map +1 -0
  198. package/lib/families/polkadot/{test-dataset.js → bridge.integration.test.js} +138 -4
  199. package/lib/families/polkadot/bridge.integration.test.js.map +1 -0
  200. package/lib/families/ripple/bridge.integration.test.d.ts +2 -0
  201. package/lib/families/ripple/bridge.integration.test.d.ts.map +1 -0
  202. package/lib/families/ripple/{test-dataset.js → bridge.integration.test.js} +4 -2
  203. package/lib/families/ripple/bridge.integration.test.js.map +1 -0
  204. package/lib/families/solana/api/chain/account/token.d.ts +1 -1
  205. package/lib/families/solana/api/chain/account/vote.d.ts +12 -12
  206. package/lib/families/solana/api/chain/instruction/system/types.d.ts +4 -4
  207. package/lib/families/solana/bridge.integration.test.d.ts +2 -0
  208. package/lib/families/solana/bridge.integration.test.d.ts.map +1 -0
  209. package/lib/families/solana/{test-dataset.js → bridge.integration.test.js} +289 -73
  210. package/lib/families/solana/bridge.integration.test.js.map +1 -0
  211. package/lib/families/stellar/bridge.integration.test.d.ts +2 -0
  212. package/lib/families/stellar/bridge.integration.test.d.ts.map +1 -0
  213. package/lib/families/stellar/{test-dataset.js → bridge.integration.test.js} +9 -8
  214. package/lib/families/stellar/bridge.integration.test.js.map +1 -0
  215. package/lib/families/stellar/js-estimateMaxSpendable.d.ts.map +1 -1
  216. package/lib/families/stellar/js-estimateMaxSpendable.js +2 -2
  217. package/lib/families/stellar/js-estimateMaxSpendable.js.map +1 -1
  218. package/lib/families/tezos/{test-dataset.d.ts → bridge.integration.test.d.ts} +2 -5
  219. package/lib/families/tezos/bridge.integration.test.d.ts.map +1 -0
  220. package/lib/families/tezos/{test-dataset.js → bridge.integration.test.js} +73 -2
  221. package/lib/families/tezos/bridge.integration.test.js.map +1 -0
  222. package/lib/families/tezos/synchronisation.js +2 -2
  223. package/lib/families/tezos/synchronisation.js.map +1 -1
  224. package/lib/families/tron/bridge.integration.test.d.ts +2 -0
  225. package/lib/families/tron/bridge.integration.test.d.ts.map +1 -0
  226. package/lib/families/tron/{test-dataset.js → bridge.integration.test.js} +5 -4
  227. package/lib/families/tron/bridge.integration.test.js.map +1 -0
  228. package/lib/hw/actions/initSwap.d.ts +4 -3
  229. package/lib/hw/actions/initSwap.d.ts.map +1 -1
  230. package/lib/hw/actions/initSwap.js +7 -5
  231. package/lib/hw/actions/initSwap.js.map +1 -1
  232. package/lib/load/speculos.d.ts.map +1 -1
  233. package/lib/load/speculos.js +5 -2
  234. package/lib/load/speculos.js.map +1 -1
  235. package/lib/nft/nftOperationId.d.ts +15 -0
  236. package/lib/nft/nftOperationId.d.ts.map +1 -0
  237. package/lib/nft/nftOperationId.js +50 -0
  238. package/lib/nft/nftOperationId.js.map +1 -0
  239. package/lib/operation.d.ts +1 -1
  240. package/lib/operation.d.ts.map +1 -1
  241. package/lib/operation.js +23 -1
  242. package/lib/operation.js.map +1 -1
  243. package/lib/portfolio/v2/index.d.ts +6 -1
  244. package/lib/portfolio/v2/index.d.ts.map +1 -1
  245. package/lib/portfolio/v2/index.js +7 -3
  246. package/lib/portfolio/v2/index.js.map +1 -1
  247. package/lib/portfolio/v2/range.d.ts +7 -1
  248. package/lib/portfolio/v2/range.d.ts.map +1 -1
  249. package/lib/portfolio/v2/range.js +37 -18
  250. package/lib/portfolio/v2/range.js.map +1 -1
  251. package/lib/portfolio/v2/range.test.d.ts +2 -0
  252. package/lib/portfolio/v2/range.test.d.ts.map +1 -0
  253. package/lib/portfolio/v2/range.test.js +51 -0
  254. package/lib/portfolio/v2/range.test.js.map +1 -0
  255. package/package.json +14 -10
  256. package/src/__tests__/mocks/account.ts +3 -3
  257. package/src/__tests__/test-helpers/bridge.ts +2 -35
  258. package/src/__tests__/test-helpers/setup.ts +39 -0
  259. package/src/api/Ripple.ts +97 -52
  260. package/src/apps/support.ts +6 -2
  261. package/src/bot/index.ts +26 -24
  262. package/src/bot/test.bot.ts +2 -2
  263. package/src/countervalues/{logic.test.ts → logic.integration.test.ts} +0 -0
  264. package/src/countervalues/react.tsx +2 -131
  265. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +15 -1
  266. package/src/derivation.ts +2 -1
  267. package/src/env.ts +12 -2
  268. package/src/errors.ts +0 -1
  269. package/src/exchange/index.ts +7 -0
  270. package/src/exchange/swap/checkQuote.test.ts +53 -0
  271. package/src/exchange/swap/checkQuote.ts +34 -0
  272. package/src/exchange/swap/completeExchange.ts +9 -11
  273. package/src/exchange/swap/getExchangeRates.test.ts +1 -2
  274. package/src/exchange/swap/getExchangeRates.ts +5 -3
  275. package/src/exchange/swap/getProviders.ts +12 -4
  276. package/src/exchange/swap/getStatus.ts +2 -12
  277. package/src/exchange/swap/hooks/usePollKYCStatus.test.ts +1 -3
  278. package/src/exchange/swap/hooks/useProviderRates.test.ts +104 -3
  279. package/src/exchange/swap/hooks/useProviderRates.ts +57 -9
  280. package/src/exchange/swap/hooks/useSwapProviders.test.ts +1 -3
  281. package/src/exchange/swap/hooks/useSwapTransaction.ts +14 -13
  282. package/src/exchange/swap/hooks/useUpdateMaxAmount.test.ts +33 -7
  283. package/src/exchange/swap/hooks/useUpdateMaxAmount.ts +13 -7
  284. package/src/exchange/swap/index.test.ts +36 -0
  285. package/src/exchange/swap/index.ts +51 -30
  286. package/src/exchange/swap/initSwap.ts +54 -40
  287. package/src/exchange/swap/mock.ts +128 -13
  288. package/src/exchange/swap/postSwapState.ts +61 -0
  289. package/src/exchange/swap/types.ts +68 -5
  290. package/src/exchange/swap/updateAccountSwapStatus.ts +4 -4
  291. package/src/exchange/swap/utils/index.test.ts +127 -63
  292. package/src/exchange/swap/utils/index.ts +128 -23
  293. package/src/families/algorand/{test-dataset.ts → bridge.integration.test.ts} +13 -10
  294. package/src/families/bitcoin/__snapshots__/bridge.integration.test.ts.snap +27607 -0
  295. package/src/families/bitcoin/{test-dataset.ts → bridge.integration.test.ts} +18 -13
  296. package/src/families/bitcoin/descriptor.ts +1 -0
  297. package/src/families/bitcoin/satstack.test.ts +4 -1
  298. package/src/families/bitcoin/satstack.ts +9 -5
  299. package/src/families/bitcoin/specs.ts +0 -1
  300. package/src/families/cardano/__snapshots__/{bridge.test.ts.snap → bridge.integration.test.ts.snap} +0 -0
  301. package/src/families/cardano/{test-dataset.ts → bridge.integration.test.ts} +3 -1
  302. package/src/families/celo/bridge.integration.test.ts +14 -0
  303. package/src/families/cosmos/__snapshots__/{bridge.test.ts.snap → bridge.integration.test.ts.snap} +0 -0
  304. package/src/families/cosmos/{test-dataset.ts → bridge.integration.test.ts} +17 -15
  305. package/src/families/cosmos/speculos-deviceActions.ts +2 -2
  306. package/src/families/crypto_org/__snapshots__/bridge.integration.test.ts.snap +2968 -0
  307. package/src/families/crypto_org/bridge.integration.test.ts +14 -0
  308. package/src/families/elrond/__snapshots__/bridge.integration.test.ts.snap +207 -0
  309. package/src/families/elrond/{test-dataset.ts → bridge.integration.test.ts} +6 -4
  310. package/src/families/ethereum/__snapshots__/bridge.integration.test.ts.snap +3263 -0
  311. package/src/families/ethereum/{test-dataset.ts → bridge.integration.test.ts} +6 -19
  312. package/src/families/ethereum/datasets/ethereum1.ts +20 -0
  313. package/src/families/ethereum/modules/{compound.resilience.test.ts → compound.resilience.integration.test.ts} +1 -1
  314. package/src/families/ethereum/modules/erc1155.ts +12 -5
  315. package/src/families/ethereum/modules/erc721.ts +11 -0
  316. package/src/families/ethereum/nft.unit.test.ts +24 -17
  317. package/src/families/ethereum/{synchronisation.test.ts → synchronisation.integration.test.ts} +1 -1
  318. package/src/families/ethereum/synchronisation.ts +22 -18
  319. package/src/families/filecoin/__snapshots__/{bridge.test.ts.snap → bridge.integration.test.ts.snap} +0 -0
  320. package/src/families/filecoin/{test-dataset.ts → bridge.integration.test.ts} +35 -3
  321. package/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap +5 -0
  322. package/src/families/hedera/{test-dataset.ts → bridge.integration.test.ts} +5 -2
  323. package/src/families/polkadot/{test-dataset.ts → bridge.integration.test.ts} +81 -5
  324. package/src/families/ripple/{test-dataset.ts → bridge.integration.test.ts} +5 -1
  325. package/src/families/solana/__snapshots__/{bridge.test.ts.snap → bridge.integration.test.ts.snap} +0 -0
  326. package/src/families/solana/{test-dataset.ts → bridge.integration.test.ts} +170 -5
  327. package/src/families/stellar/__snapshots__/{bridge.test.ts.snap → bridge.integration.test.ts.snap} +0 -0
  328. package/src/families/stellar/{test-dataset.ts → bridge.integration.test.ts} +5 -3
  329. package/src/families/stellar/js-estimateMaxSpendable.ts +3 -1
  330. package/src/families/tezos/{test-dataset.ts → bridge.integration.test.ts} +22 -1
  331. package/src/families/tezos/synchronisation.ts +1 -1
  332. package/src/families/tron/{test-dataset.ts → bridge.integration.test.ts} +6 -5
  333. package/src/hw/actions/initSwap.ts +20 -9
  334. package/src/load/speculos.ts +5 -2
  335. package/src/nft/nftOperationId.ts +47 -0
  336. package/src/operation.ts +50 -1
  337. package/src/portfolio/v2/index.ts +7 -2
  338. package/src/portfolio/v2/range.test.ts +66 -0
  339. package/src/portfolio/v2/range.ts +22 -8
  340. package/lib/__tests__/portfolio.d.ts +0 -2
  341. package/lib/__tests__/portfolio.d.ts.map +0 -1
  342. package/lib/__tests__/portfolio.js +0 -297
  343. package/lib/__tests__/portfolio.js.map +0 -1
  344. package/lib/__tests__/test-helpers/libcore-setup.d.ts +0 -3
  345. package/lib/__tests__/test-helpers/libcore-setup.d.ts.map +0 -1
  346. package/lib/__tests__/test-helpers/libcore-setup.js +0 -68
  347. package/lib/__tests__/test-helpers/libcore-setup.js.map +0 -1
  348. package/lib/__tests__/test-helpers/libcore-setup.native.d.ts +0 -10
  349. package/lib/__tests__/test-helpers/libcore-setup.native.d.ts.map +0 -1
  350. package/lib/__tests__/test-helpers/libcore-setup.native.js +0 -16
  351. package/lib/__tests__/test-helpers/libcore-setup.native.js.map +0 -1
  352. package/lib/countervalues/logic.test.d.ts +0 -2
  353. package/lib/countervalues/logic.test.d.ts.map +0 -1
  354. package/lib/countervalues/logic.test.js.map +0 -1
  355. package/lib/families/algorand/test-dataset.d.ts +0 -5
  356. package/lib/families/algorand/test-dataset.d.ts.map +0 -1
  357. package/lib/families/algorand/test-dataset.js.map +0 -1
  358. package/lib/families/bitcoin/test-dataset.d.ts +0 -5
  359. package/lib/families/bitcoin/test-dataset.d.ts.map +0 -1
  360. package/lib/families/bitcoin/test-dataset.js.map +0 -1
  361. package/lib/families/cardano/bridge.test.d.ts +0 -2
  362. package/lib/families/cardano/bridge.test.d.ts.map +0 -1
  363. package/lib/families/cardano/bridge.test.js +0 -11
  364. package/lib/families/cardano/bridge.test.js.map +0 -1
  365. package/lib/families/cardano/test-dataset.d.ts +0 -5
  366. package/lib/families/cardano/test-dataset.d.ts.map +0 -1
  367. package/lib/families/cardano/test-dataset.js.map +0 -1
  368. package/lib/families/cosmos/bridge.test.d.ts +0 -2
  369. package/lib/families/cosmos/bridge.test.d.ts.map +0 -1
  370. package/lib/families/cosmos/bridge.test.js +0 -11
  371. package/lib/families/cosmos/bridge.test.js.map +0 -1
  372. package/lib/families/cosmos/test-dataset.d.ts +0 -5
  373. package/lib/families/cosmos/test-dataset.d.ts.map +0 -1
  374. package/lib/families/cosmos/test-dataset.js.map +0 -1
  375. package/lib/families/crypto_org/test-dataset.d.ts +0 -5
  376. package/lib/families/crypto_org/test-dataset.d.ts.map +0 -1
  377. package/lib/families/crypto_org/test-dataset.js +0 -12
  378. package/lib/families/crypto_org/test-dataset.js.map +0 -1
  379. package/lib/families/elrond/test-dataset.d.ts +0 -5
  380. package/lib/families/elrond/test-dataset.d.ts.map +0 -1
  381. package/lib/families/elrond/test-dataset.js.map +0 -1
  382. package/lib/families/ethereum/modules/compound.resilience.test.d.ts +0 -2
  383. package/lib/families/ethereum/modules/compound.resilience.test.d.ts.map +0 -1
  384. package/lib/families/ethereum/modules/compound.resilience.test.js.map +0 -1
  385. package/lib/families/ethereum/synchronisation.test.d.ts +0 -2
  386. package/lib/families/ethereum/synchronisation.test.d.ts.map +0 -1
  387. package/lib/families/ethereum/synchronisation.test.js.map +0 -1
  388. package/lib/families/ethereum/test-dataset.d.ts +0 -6
  389. package/lib/families/ethereum/test-dataset.d.ts.map +0 -1
  390. package/lib/families/ethereum/test-dataset.js.map +0 -1
  391. package/lib/families/filecoin/bridge.test.d.ts +0 -2
  392. package/lib/families/filecoin/bridge.test.d.ts.map +0 -1
  393. package/lib/families/filecoin/bridge.test.js.map +0 -1
  394. package/lib/families/filecoin/test-dataset.d.ts +0 -5
  395. package/lib/families/filecoin/test-dataset.d.ts.map +0 -1
  396. package/lib/families/filecoin/test-dataset.js.map +0 -1
  397. package/lib/families/hedera/test-dataset.d.ts +0 -5
  398. package/lib/families/hedera/test-dataset.d.ts.map +0 -1
  399. package/lib/families/hedera/test-dataset.js.map +0 -1
  400. package/lib/families/polkadot/bridge.test.d.ts +0 -2
  401. package/lib/families/polkadot/bridge.test.d.ts.map +0 -1
  402. package/lib/families/polkadot/bridge.test.js +0 -145
  403. package/lib/families/polkadot/bridge.test.js.map +0 -1
  404. package/lib/families/polkadot/test-dataset.d.ts +0 -5
  405. package/lib/families/polkadot/test-dataset.d.ts.map +0 -1
  406. package/lib/families/polkadot/test-dataset.js.map +0 -1
  407. package/lib/families/ripple/bridge.test.d.ts +0 -2
  408. package/lib/families/ripple/bridge.test.d.ts.map +0 -1
  409. package/lib/families/ripple/bridge.test.js +0 -11
  410. package/lib/families/ripple/bridge.test.js.map +0 -1
  411. package/lib/families/ripple/test-dataset.d.ts +0 -5
  412. package/lib/families/ripple/test-dataset.d.ts.map +0 -1
  413. package/lib/families/ripple/test-dataset.js.map +0 -1
  414. package/lib/families/solana/bridge.test.d.ts +0 -2
  415. package/lib/families/solana/bridge.test.d.ts.map +0 -1
  416. package/lib/families/solana/bridge.test.js +0 -11
  417. package/lib/families/solana/bridge.test.js.map +0 -1
  418. package/lib/families/solana/test-dataset.d.ts +0 -23
  419. package/lib/families/solana/test-dataset.d.ts.map +0 -1
  420. package/lib/families/solana/test-dataset.js.map +0 -1
  421. package/lib/families/solana/test-specifics.d.ts +0 -9
  422. package/lib/families/solana/test-specifics.d.ts.map +0 -1
  423. package/lib/families/solana/test-specifics.js +0 -237
  424. package/lib/families/solana/test-specifics.js.map +0 -1
  425. package/lib/families/stellar/bridge.test.d.ts +0 -2
  426. package/lib/families/stellar/bridge.test.d.ts.map +0 -1
  427. package/lib/families/stellar/bridge.test.js +0 -11
  428. package/lib/families/stellar/bridge.test.js.map +0 -1
  429. package/lib/families/stellar/test-dataset.d.ts +0 -7
  430. package/lib/families/stellar/test-dataset.d.ts.map +0 -1
  431. package/lib/families/stellar/test-dataset.js.map +0 -1
  432. package/lib/families/tezos/bridge.test.d.ts +0 -2
  433. package/lib/families/tezos/bridge.test.d.ts.map +0 -1
  434. package/lib/families/tezos/bridge.test.js.map +0 -1
  435. package/lib/families/tezos/test-dataset.d.ts.map +0 -1
  436. package/lib/families/tezos/test-dataset.js.map +0 -1
  437. package/lib/families/tron/test-dataset.d.ts +0 -5
  438. package/lib/families/tron/test-dataset.d.ts.map +0 -1
  439. package/lib/families/tron/test-dataset.js.map +0 -1
  440. package/lib/generated/test-dataset.d.ts +0 -19
  441. package/lib/generated/test-dataset.d.ts.map +0 -1
  442. package/lib/generated/test-dataset.js +0 -38
  443. package/lib/generated/test-dataset.js.map +0 -1
  444. package/lib/portfolio/index.d.ts +0 -30
  445. package/lib/portfolio/index.d.ts.map +0 -1
  446. package/lib/portfolio/index.js +0 -399
  447. package/lib/portfolio/index.js.map +0 -1
  448. package/lib/portfolio/range.d.ts +0 -12
  449. package/lib/portfolio/range.d.ts.map +0 -1
  450. package/lib/portfolio/range.js +0 -73
  451. package/lib/portfolio/range.js.map +0 -1
  452. package/src/__tests__/__snapshots__/portfolio.ts.snap +0 -2770
  453. package/src/__tests__/portfolio.ts +0 -360
  454. package/src/__tests__/test-helpers/libcore-setup.native.ts +0 -19
  455. package/src/__tests__/test-helpers/libcore-setup.ts +0 -51
  456. package/src/families/bitcoin/bridge.test.ts.bak +0 -6
  457. package/src/families/cardano/bridge.test.ts +0 -6
  458. package/src/families/cosmos/bridge.test.ts +0 -6
  459. package/src/families/crypto_org/test-dataset.ts +0 -13
  460. package/src/families/ethereum/bridge.test.ts.bak +0 -8
  461. package/src/families/filecoin/bridge.test.ts +0 -39
  462. package/src/families/polkadot/bridge.test.ts +0 -81
  463. package/src/families/ripple/bridge.test.ts +0 -6
  464. package/src/families/solana/bridge.test.ts +0 -6
  465. package/src/families/solana/test-specifics.ts +0 -170
  466. package/src/families/stellar/bridge.test.ts +0 -6
  467. package/src/families/tezos/bridge.test.ts +0 -24
  468. package/src/generated/test-dataset.ts +0 -48
  469. package/src/portfolio/index.ts +0 -505
  470. package/src/portfolio/range.ts +0 -71
package/src/derivation.ts CHANGED
@@ -157,12 +157,13 @@ const modes = Object.freeze({
157
157
  // glif legacy derivation
158
158
  gliflegacy: {
159
159
  overridesDerivation: "44'/1'/0'/0/<account>",
160
- tag: "legacy",
160
+ tag: "glif-legacy",
161
161
  },
162
162
  // glif normal derivation
163
163
  glif: {
164
164
  overridesDerivation: "44'/461'/0'/0/<account>",
165
165
  startsAt: 1,
166
+ tag: "glif",
166
167
  },
167
168
  solanaMain: {
168
169
  isNonIterable: true,
package/src/env.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { $ElementType } from "utility-types";
1
+ import mapValues from "lodash/mapValues";
2
2
  // set and get environment & config variables
3
3
  import { Subject } from "rxjs";
4
- import mapValues from "lodash/mapValues";
4
+ import { $ElementType } from "utility-types";
5
5
  type EnvDef<V> = {
6
6
  desc: string;
7
7
  def: V;
@@ -400,6 +400,16 @@ const envDefinitions = {
400
400
  parser: stringParser,
401
401
  desc: "mock the server response for the exchange KYC check, options are 'open', 'pending', 'closed' or 'approved'.",
402
402
  },
403
+ MOCK_SWAP_CHECK_QUOTE: {
404
+ def: "",
405
+ parser: stringParser,
406
+ desc: "mock the server response for the exchange check quote, options are 'RATE_VALID', 'KYC_FAILED', 'KYC_PENDING', 'KYC_UNDEFINED', 'KYC_UPGRADE_REQUIRED', 'MFA_REQUIRED', 'OVER_TRADE_LIMIT', 'UNKNOW_USER' or 'UNKNOWN_ERROR'.",
407
+ },
408
+ MOCK_SWAP_WIDGET_BASE_URL: {
409
+ def: "",
410
+ parser: stringParser,
411
+ desc: "mock the FTX swap widget base url",
412
+ },
403
413
  /**
404
414
  * Note: the mocked cryptoassets config and test partner are signed with the
405
415
  * Ledger test private key
package/src/errors.ts CHANGED
@@ -160,7 +160,6 @@ export const SwapSubmitKYCFailed = createCustomErrorClass(
160
160
  "SwapSubmitKYCFailed"
161
161
  );
162
162
 
163
- export const SwapUnknownSwapId = createCustomErrorClass("SwapUnknownSwapId");
164
163
  export const SwapGenericAPIError = createCustomErrorClass(
165
164
  "SwapGenericAPIError"
166
165
  );
@@ -46,6 +46,13 @@ export type ExchangeProviderNameAndSignature = {
46
46
  nameAndPubkey: Buffer;
47
47
  signature: Buffer;
48
48
  };
49
+
50
+ export type SwapProviderConfig = ExchangeProviderNameAndSignature & {
51
+ curve: string;
52
+ needsKYC: boolean;
53
+ needsBearerToken: boolean;
54
+ };
55
+
49
56
  export const isExchangeSupportedByApp = (
50
57
  appName: string,
51
58
  appVersion: string
@@ -0,0 +1,53 @@
1
+ import axios from "axios";
2
+ import checkQuote from "./checkQuote";
3
+
4
+ jest.mock("axios");
5
+ const mockedAxios = jest.mocked(axios);
6
+
7
+ const provider = "changelly";
8
+ const quoteId = "RATE_ID";
9
+ const bearerToken = "BEARER_TOKEN";
10
+
11
+ describe("swap/checkQuote", () => {
12
+ test("should return response in case of valid rate", async () => {
13
+ const data = {
14
+ code: 1,
15
+ codeName: "RATE_VALID",
16
+ description: "KYC check passed",
17
+ };
18
+
19
+ const resp = {
20
+ data,
21
+ status: 200,
22
+ statusText: "",
23
+ headers: {},
24
+ config: {},
25
+ };
26
+
27
+ mockedAxios.mockResolvedValue(Promise.resolve(resp));
28
+ const res = await checkQuote({ provider, quoteId, bearerToken });
29
+
30
+ expect(res).toEqual(data);
31
+ });
32
+
33
+ test("should return response in case of invalid rate", async () => {
34
+ const data = {
35
+ code: 204,
36
+ codeName: "MFA_REQUIRED",
37
+ description: "MFA Required",
38
+ };
39
+
40
+ const resp = {
41
+ data,
42
+ status: 200,
43
+ statusText: "",
44
+ headers: {},
45
+ config: {},
46
+ };
47
+
48
+ mockedAxios.mockResolvedValue(Promise.resolve(resp));
49
+ const res = await checkQuote({ provider, quoteId, bearerToken });
50
+
51
+ expect(res).toEqual(data);
52
+ });
53
+ });
@@ -0,0 +1,34 @@
1
+ import { getEnv } from "../../env";
2
+ import network from "../../network";
3
+ import { getSwapAPIBaseURL } from "./";
4
+ import { mockCheckQuote } from "./mock";
5
+ import type { CheckQuote } from "./types";
6
+
7
+ const checkQuote: CheckQuote = async ({ provider, quoteId, bearerToken }) => {
8
+ if (getEnv("MOCK") || getEnv("MOCK_SWAP_CHECK_QUOTE")) {
9
+ return mockCheckQuote({ provider, quoteId, bearerToken });
10
+ }
11
+
12
+ const request = {
13
+ provider,
14
+ rateId: quoteId,
15
+ };
16
+
17
+ const { data } = await network({
18
+ method: "POST",
19
+ url: `${getSwapAPIBaseURL()}/rate/check`,
20
+ headers: {
21
+ Authorization: `Bearer ${bearerToken}`,
22
+ },
23
+ data: request,
24
+ });
25
+
26
+ /**
27
+ * TODO: we might want to handle various status and error here
28
+ * cf. https://github.com/LedgerHQ/swap/blob/master/modules/model/src/main/scala/co/ledger/swap/model/RateStatus.scala
29
+ */
30
+
31
+ return data;
32
+ };
33
+
34
+ export default checkQuote;
@@ -1,22 +1,20 @@
1
+ import { TransportStatusError, WrongDeviceForAccount } from "@ledgerhq/errors";
1
2
  import { log } from "@ledgerhq/logs";
2
3
  import { from, Observable } from "rxjs";
3
4
  import secp256k1 from "secp256k1";
4
- import { TransportStatusError, WrongDeviceForAccount } from "@ledgerhq/errors";
5
-
6
- import { delay } from "../../promise";
7
- import ExchangeTransport from "../hw-app-exchange/Exchange";
8
- import perFamily from "../../generated/exchange";
5
+ import { getCurrencyExchangeConfig } from "../";
9
6
  import { getAccountCurrency, getMainAccount } from "../../account";
10
7
  import { getAccountBridge } from "../../bridge";
11
8
  import { TransactionRefusedOnDevice } from "../../errors";
9
+ import perFamily from "../../generated/exchange";
12
10
  import { withDevice } from "../../hw/deviceAccess";
13
- import { getProviderNameAndSignature } from "./";
14
- import { getCurrencyExchangeConfig } from "../";
15
-
11
+ import { delay } from "../../promise";
12
+ import ExchangeTransport from "../hw-app-exchange/Exchange";
16
13
  import type {
17
14
  CompleteExchangeInputSwap,
18
15
  CompleteExchangeRequestEvent,
19
16
  } from "../platform/types";
17
+ import { getProviderConfig } from "./";
20
18
 
21
19
  const withDevicePromise = (deviceId, fn) =>
22
20
  withDevice(deviceId)((transport) => from(fn(transport))).toPromise();
@@ -45,7 +43,7 @@ const completeExchange = (
45
43
 
46
44
  const confirmExchange = async () => {
47
45
  await withDevicePromise(deviceId, async (transport) => {
48
- const providerNameAndSignature = getProviderNameAndSignature(provider);
46
+ const providerConfig = getProviderConfig(provider);
49
47
  const exchange = new ExchangeTransport(
50
48
  transport,
51
49
  exchangeType,
@@ -75,10 +73,10 @@ const completeExchange = (
75
73
  const errorsKeys = Object.keys(errors);
76
74
  if (errorsKeys.length > 0) throw errors[errorsKeys[0]]; // throw the first error
77
75
 
78
- await exchange.setPartnerKey(providerNameAndSignature.nameAndPubkey);
76
+ await exchange.setPartnerKey(providerConfig.nameAndPubkey);
79
77
  if (unsubscribed) return;
80
78
 
81
- await exchange.checkPartner(providerNameAndSignature.signature);
79
+ await exchange.checkPartner(providerConfig.signature);
82
80
  if (unsubscribed) return;
83
81
 
84
82
  await exchange.processTransaction(
@@ -1,13 +1,12 @@
1
1
  import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
2
2
  import axios from "axios";
3
3
  import BigNumber from "bignumber.js";
4
- import { mocked } from "ts-jest/utils";
5
4
  import { Account, Transaction } from "../../types";
6
5
  import getExchangeRates from "./getExchangeRates";
7
6
  import { Exchange, ExchangeRate } from "./types";
8
7
 
9
8
  jest.mock("axios");
10
- const mockedAxios = mocked(axios);
9
+ const mockedAxios = jest.mocked(axios);
11
10
 
12
11
  const bitcoinCurrency = getCryptoCurrencyById("bitcoin");
13
12
  const ethereumCurrency = getCryptoCurrencyById("ethereum");
@@ -13,9 +13,9 @@ import type {
13
13
  Transaction,
14
14
  Unit,
15
15
  } from "../../types";
16
- import { getSwapAPIBaseURL, getSwapAPIError } from "./";
16
+ import { getAvailableProviders, getSwapAPIBaseURL, getSwapAPIError } from "./";
17
17
  import { mockGetExchangeRates } from "./mock";
18
- import type { Exchange, GetExchangeRates } from "./types";
18
+ import type { CustomMinOrMaxError, Exchange, GetExchangeRates } from "./types";
19
19
 
20
20
  const getExchangeRates: GetExchangeRates = async (
21
21
  exchange: Exchange,
@@ -40,6 +40,7 @@ const getExchangeRates: GetExchangeRates = async (
40
40
  from,
41
41
  to,
42
42
  amountFrom: apiAmount.toString(),
43
+ providers: usesV3 ? getAvailableProviders() : undefined,
43
44
  };
44
45
  const res = await network({
45
46
  method: "POST",
@@ -122,7 +123,7 @@ const inferError = (
122
123
  errorCode?: number;
123
124
  errorMessage?: string;
124
125
  }
125
- ): Error | undefined => {
126
+ ): Error | CustomMinOrMaxError | undefined => {
126
127
  const tenPowMagnitude = new BigNumber(10).pow(unitFrom.magnitude);
127
128
  const { amountTo, minAmountFrom, maxAmountFrom, errorCode, errorMessage } =
128
129
  responseData;
@@ -157,6 +158,7 @@ const inferError = (
157
158
  showCode: true,
158
159
  }
159
160
  ),
161
+ amount: new BigNumber(amount),
160
162
  });
161
163
  }
162
164
  }
@@ -1,15 +1,23 @@
1
- import type { GetProviders } from "./types";
2
- import network from "../../network";
3
- import { getSwapAPIBaseURL } from "./";
1
+ import qs from "qs";
4
2
  import { getEnv } from "../../env";
5
- import { mockGetProviders } from "./mock";
6
3
  import { SwapNoAvailableProviders } from "../../errors";
4
+ import network from "../../network";
5
+ import { getAvailableProviders, getSwapAPIBaseURL } from "./";
6
+ import { mockGetProviders } from "./mock";
7
+ import type { GetProviders } from "./types";
7
8
 
8
9
  const getProviders: GetProviders = async () => {
9
10
  if (getEnv("MOCK")) return mockGetProviders();
11
+
12
+ // Rely on the api base to determine the version logic
13
+ const usesV3 = getSwapAPIBaseURL().endsWith("v3");
14
+
10
15
  const res = await network({
11
16
  method: "GET",
12
17
  url: `${getSwapAPIBaseURL()}/providers`,
18
+ params: usesV3 ? { whitelist: getAvailableProviders() } : undefined,
19
+ paramsSerializer: (params) =>
20
+ qs.stringify(params, { arrayFormat: "comma" }),
13
21
  });
14
22
 
15
23
  if (!res.data.length) {
@@ -1,18 +1,9 @@
1
+ import { getEnv } from "../../env";
1
2
  import network from "../../network";
2
3
  import { getSwapAPIBaseURL } from "./";
3
- import type { GetMultipleStatus, GetStatus } from "./types";
4
- import { getEnv } from "../../env";
5
4
  import { mockGetStatus } from "./mock";
6
- import { SwapUnknownSwapId } from "../../errors";
7
- export const getStatus: GetStatus = async (status) => {
8
- const updatedStatus = await getMultipleStatus([status]);
5
+ import type { GetMultipleStatus } from "./types";
9
6
 
10
- if (updatedStatus && updatedStatus.length) {
11
- return updatedStatus[0];
12
- }
13
-
14
- throw new SwapUnknownSwapId(undefined, { ...status });
15
- };
16
7
  export const getMultipleStatus: GetMultipleStatus = async (statusList) => {
17
8
  if (getEnv("MOCK")) return mockGetStatus(statusList);
18
9
  const res = await network({
@@ -22,4 +13,3 @@ export const getMultipleStatus: GetMultipleStatus = async (statusList) => {
22
13
  });
23
14
  return res.data;
24
15
  };
25
- export default getStatus;
@@ -1,6 +1,4 @@
1
1
  import { renderHook } from "@testing-library/react-hooks";
2
- import { mocked } from "ts-jest/utils";
3
-
4
2
  import {
5
3
  usePollKYCStatus,
6
4
  KYC_STATUS_POLLING_INTERVAL,
@@ -12,7 +10,7 @@ import { KYCStatus } from "../types";
12
10
 
13
11
  // mock getKYCStatus
14
12
  jest.mock("..");
15
- const mockedGetKYCStatus = mocked(getKYCStatus, true);
13
+ const mockedGetKYCStatus = jest.mocked(getKYCStatus, true);
16
14
 
17
15
  describe("usePollKYCStatus", () => {
18
16
  const defaultInput: UsePollKYCStatusProps = {
@@ -1,9 +1,12 @@
1
- import { renderHook, act } from "@testing-library/react-hooks";
2
1
  import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
2
+ import { act, renderHook } from "@testing-library/react-hooks";
3
3
  import BigNumber from "bignumber.js";
4
- import { mocked } from "ts-jest/utils";
5
4
  import { useProviderRates } from ".";
6
5
  import { getExchangeRates } from "..";
6
+ import {
7
+ SwapExchangeRateAmountTooHigh,
8
+ SwapExchangeRateAmountTooLow,
9
+ } from "../../../errors";
7
10
  import { genAccount } from "../../../mock/account";
8
11
  import { mockGetExchangeRates } from "../mock";
9
12
 
@@ -15,7 +18,7 @@ const fromAccount = genAccount("from-account", {
15
18
  currency: ETH,
16
19
  });
17
20
 
18
- const mockedGetExchangeRates = mocked(getExchangeRates, true);
21
+ const mockedGetExchangeRates = jest.mocked(getExchangeRates, true);
19
22
  const mockedRatesPromise = mockGetExchangeRates(
20
23
  { fromAccount } as any,
21
24
  { amount: new BigNumber(1) } as any,
@@ -185,6 +188,104 @@ describe("useProviderRates", () => {
185
188
  expect(result.current.rates.value).toBeUndefined();
186
189
  });
187
190
 
191
+ it("should sort SwapExchangeRateAmountTooLow based on amount", async () => {
192
+ const swapExchangeRateAmountTooLowError1 = new SwapExchangeRateAmountTooLow(
193
+ undefined,
194
+ {
195
+ amount: new BigNumber(1),
196
+ }
197
+ );
198
+
199
+ const swapExchangeRateAmountTooLowError2 = new SwapExchangeRateAmountTooLow(
200
+ undefined,
201
+ {
202
+ amount: new BigNumber(2),
203
+ }
204
+ );
205
+
206
+ mockedRates[0].error = swapExchangeRateAmountTooLowError2;
207
+ mockedRates[1].error = swapExchangeRateAmountTooLowError1;
208
+
209
+ mockedGetExchangeRates.mockResolvedValue(mockedRates);
210
+ const { result, waitForNextUpdate } = renderHook(useProviderRates, {
211
+ initialProps: baseInitalProps,
212
+ });
213
+ await waitForNextUpdate({ timeout: 1000 });
214
+ expect(result.current.rates.status).toBe("error");
215
+ expect(result.current.rates.error).toBe(swapExchangeRateAmountTooLowError1);
216
+ expect(result.current.rates.value).toBeUndefined();
217
+ });
218
+
219
+ it("should sort SwapExchangeRateAmountTooHigh based on amount", async () => {
220
+ const swapExchangeRateAmountTooHighError1 =
221
+ new SwapExchangeRateAmountTooHigh(undefined, {
222
+ amount: new BigNumber(1),
223
+ });
224
+
225
+ const swapExchangeRateAmountTooHighError2 =
226
+ new SwapExchangeRateAmountTooHigh(undefined, {
227
+ amount: new BigNumber(2),
228
+ });
229
+
230
+ mockedRates[0].error = swapExchangeRateAmountTooHighError1;
231
+ mockedRates[1].error = swapExchangeRateAmountTooHighError2;
232
+
233
+ mockedGetExchangeRates.mockResolvedValue(mockedRates);
234
+ const { result, waitForNextUpdate } = renderHook(useProviderRates, {
235
+ initialProps: baseInitalProps,
236
+ });
237
+ await waitForNextUpdate({ timeout: 1000 });
238
+ expect(result.current.rates.status).toBe("error");
239
+ expect(result.current.rates.error).toBe(
240
+ swapExchangeRateAmountTooHighError2
241
+ );
242
+ expect(result.current.rates.value).toBeUndefined();
243
+ });
244
+
245
+ it("SwapExchangeRateAmountTooLow should take precedence over standard errors", async () => {
246
+ const swapExchangeRateAmountTooLowError = new SwapExchangeRateAmountTooLow(
247
+ undefined,
248
+ {
249
+ amount: new BigNumber(1),
250
+ }
251
+ );
252
+
253
+ const standardError = new Error("Error");
254
+
255
+ mockedRates[0].error = standardError;
256
+ mockedRates[1].error = swapExchangeRateAmountTooLowError;
257
+
258
+ mockedGetExchangeRates.mockResolvedValue(mockedRates);
259
+ const { result, waitForNextUpdate } = renderHook(useProviderRates, {
260
+ initialProps: baseInitalProps,
261
+ });
262
+ await waitForNextUpdate({ timeout: 1000 });
263
+ expect(result.current.rates.status).toBe("error");
264
+ expect(result.current.rates.error).toBe(swapExchangeRateAmountTooLowError);
265
+ expect(result.current.rates.value).toBeUndefined();
266
+ });
267
+
268
+ it("SwapExchangeRateAmountTooHigh should take precedence over standard errors", async () => {
269
+ const SwapExchangeRateAmountTooHighError =
270
+ new SwapExchangeRateAmountTooHigh(undefined, {
271
+ amount: new BigNumber(1),
272
+ });
273
+
274
+ const standardError = new Error("Error");
275
+
276
+ mockedRates[0].error = standardError;
277
+ mockedRates[1].error = SwapExchangeRateAmountTooHighError;
278
+
279
+ mockedGetExchangeRates.mockResolvedValue(mockedRates);
280
+ const { result, waitForNextUpdate } = renderHook(useProviderRates, {
281
+ initialProps: baseInitalProps,
282
+ });
283
+ await waitForNextUpdate({ timeout: 1000 });
284
+ expect(result.current.rates.status).toBe("error");
285
+ expect(result.current.rates.error).toBe(SwapExchangeRateAmountTooHighError);
286
+ expect(result.current.rates.value).toBeUndefined();
287
+ });
288
+
188
289
  it("should call 'onNoRates' if there are no rates returned by the server", async () => {
189
290
  const onNoRates = jest.fn(() => {});
190
291
  mockedGetExchangeRates.mockResolvedValue([]);
@@ -1,13 +1,12 @@
1
1
  import { useCallback, useEffect, useReducer, useState } from "react";
2
+ import { getExchangeRates } from "..";
3
+ import { Transaction } from "../../../generated/types";
4
+ import type { CustomMinOrMaxError, Exchange, ExchangeRate } from "../types";
2
5
  import {
3
6
  OnNoRatesCallback,
4
7
  SetExchangeRateCallback,
5
8
  SwapSelectorStateType,
6
9
  } from "./useSwapTransaction";
7
- import { getExchangeRates } from "..";
8
- import { Exchange, ExchangeRate } from "../types";
9
- import { pickExchangeRate } from "../utils";
10
- import { Transaction } from "../../../generated/types";
11
10
 
12
11
  export type RatesReducerState = {
13
12
  status?: string | null;
@@ -34,14 +33,12 @@ const ratesReducer = (state: RatesReducerState, action): RatesReducerState => {
34
33
  export const useProviderRates = ({
35
34
  fromState,
36
35
  toState,
37
- exchangeRate,
38
36
  transaction,
39
37
  onNoRates,
40
38
  setExchangeRate,
41
39
  }: {
42
40
  fromState: SwapSelectorStateType;
43
41
  toState: SwapSelectorStateType;
44
- exchangeRate?: ExchangeRate | null | undefined;
45
42
  transaction?: Transaction | null | undefined;
46
43
  onNoRates?: OnNoRatesCallback | null | undefined;
47
44
  setExchangeRate?: SetExchangeRateCallback | null | undefined;
@@ -82,23 +79,74 @@ export const useProviderRates = ({
82
79
  undefined,
83
80
  toCurrency
84
81
  );
82
+
85
83
  if (abort) return;
86
84
  if (rates.length === 0) {
87
85
  onNoRates && onNoRates({ fromState, toState });
88
86
  }
87
+
89
88
  // Discard bad provider rates
90
- let rateError: Error | null | undefined = null;
89
+ let rateError: Error | CustomMinOrMaxError | null | undefined = null;
91
90
  rates = rates.reduce<ExchangeRate[]>((acc, rate) => {
92
91
  rateError = rateError ?? rate.error;
92
+
93
+ /**
94
+ * If we have an error linked to the ammount, this error takes
95
+ * precedence over the other (like a "CurrencyNotSupportedError" one
96
+ * for example)
97
+ */
98
+ if (
99
+ rateError?.name !== rate.error?.name &&
100
+ (rate.error?.name === "SwapExchangeRateAmountTooLow" ||
101
+ rate.error?.name === "SwapExchangeRateAmountTooHigh")
102
+ ) {
103
+ rateError = rate.error;
104
+ }
105
+
106
+ if (
107
+ rateError?.name === rate.error?.name &&
108
+ (rate.error?.name === "SwapExchangeRateAmountTooLow" ||
109
+ rate.error?.name === "SwapExchangeRateAmountTooHigh")
110
+ ) {
111
+ /**
112
+ * Comparison pivot, depending on the order in which we want to sort errors
113
+ * If the order is ascending, the pivot is -1, otherwise it's 1
114
+ * Based on returns from https://mikemcl.github.io/bignumber.js/#cmp
115
+ */
116
+ const cmp =
117
+ rateError?.name === "SwapExchangeRateAmountTooLow" ? -1 : 1;
118
+
119
+ /**
120
+ * If the amount is too low, the user should put at least the
121
+ * minimum amount possible
122
+ * If the amount is too high, the user should put at most the
123
+ * maximum amount possible
124
+ */
125
+
126
+ rateError =
127
+ (rateError as CustomMinOrMaxError).amount.comparedTo(
128
+ (rate.error as CustomMinOrMaxError)?.amount
129
+ ) === cmp
130
+ ? rateError
131
+ : rate.error;
132
+ }
133
+
93
134
  return rate.error ? acc : [...acc, rate];
94
135
  }, []);
136
+
95
137
  if (rates.length === 0 && rateError) {
96
138
  // If all the rates are in error
97
139
  dispatchRates({ type: "error", payload: rateError });
98
140
  } else {
99
141
  dispatchRates({ type: "set", payload: rates });
100
- setExchangeRate &&
101
- pickExchangeRate(rates, exchangeRate, setExchangeRate);
142
+
143
+ /**
144
+ * Select the first rate returned by the API. Should be the prefered
145
+ * rate for the user. Rate ordering logic is handeled on backend side
146
+ */
147
+ const rate = rates?.length > 0 ? rates[0] : null;
148
+
149
+ setExchangeRate && setExchangeRate(rate);
102
150
  }
103
151
  } catch (error) {
104
152
  !abort && dispatchRates({ type: "error", payload: error });
@@ -1,12 +1,10 @@
1
1
  import { renderHook } from "@testing-library/react-hooks";
2
- import { mocked } from "ts-jest/utils";
3
-
4
2
  import { useSwapProviders } from "./useSwapProviders";
5
3
  import { getProviders } from "..";
6
4
 
7
5
  jest.mock("..");
8
6
 
9
- const mockedGetProviders = mocked(getProviders);
7
+ const mockedGetProviders = jest.mocked(getProviders);
10
8
 
11
9
  describe("useSwapProviders", () => {
12
10
  const OLD_ENV = process.env;
@@ -1,24 +1,24 @@
1
- import { useMemo } from "react";
1
+ import { AmountRequired } from "@ledgerhq/errors";
2
2
  import { BigNumber } from "bignumber.js";
3
+ import { useMemo } from "react";
4
+ import {
5
+ RatesReducerState,
6
+ useFromState,
7
+ useProviderRates,
8
+ useToState,
9
+ } from ".";
3
10
  import useBridgeTransaction, {
4
11
  Result as UseBridgeTransactionReturnType,
5
12
  } from "../../../bridge/useBridgeTransaction";
6
13
  import type {
7
14
  Account,
15
+ CryptoCurrency,
8
16
  TokenAccount,
9
17
  TokenCurrency,
10
- CryptoCurrency,
11
18
  } from "../../../types";
12
19
  import { ExchangeRate } from "../types";
13
- import { AmountRequired } from "@ledgerhq/errors";
14
- import { useUpdateMaxAmount } from "./useUpdateMaxAmount";
15
- import {
16
- RatesReducerState,
17
- useFromState,
18
- useProviderRates,
19
- useToState,
20
- } from ".";
21
20
  import { useReverseAccounts } from "./useReverseAccounts";
21
+ import { useUpdateMaxAmount } from "./useUpdateMaxAmount";
22
22
 
23
23
  export type SwapSelectorStateType = {
24
24
  currency: null | undefined | TokenCurrency | CryptoCurrency;
@@ -65,6 +65,7 @@ export type OnNoRatesCallback = (arg: {
65
65
  export type SetExchangeRateCallback = (
66
66
  exchangeRate?: ExchangeRate | null
67
67
  ) => void;
68
+ export type SetIsSendMaxLoading = (boolean) => void;
68
69
 
69
70
  export const useFromAmountError = (
70
71
  errors: Record<string, Error | undefined>
@@ -82,16 +83,16 @@ export const useFromAmountError = (
82
83
 
83
84
  export const useSwapTransaction = ({
84
85
  accounts,
85
- exchangeRate,
86
86
  setExchangeRate,
87
+ setIsSendMaxLoading,
87
88
  defaultCurrency = selectorStateDefaultValues.currency,
88
89
  defaultAccount = selectorStateDefaultValues.account,
89
90
  defaultParentAccount = selectorStateDefaultValues.parentAccount,
90
91
  onNoRates,
91
92
  }: {
92
93
  accounts?: Account[];
93
- exchangeRate?: ExchangeRate;
94
94
  setExchangeRate?: SetExchangeRateCallback;
95
+ setIsSendMaxLoading?: SetIsSendMaxLoading;
95
96
  defaultCurrency?: SwapSelectorStateType["currency"];
96
97
  defaultAccount?: SwapSelectorStateType["account"];
97
98
  defaultParentAccount?: SwapSelectorStateType["parentAccount"];
@@ -136,12 +137,12 @@ export const useSwapTransaction = ({
136
137
  parentAccount: fromParentAccount,
137
138
  transaction,
138
139
  feesStrategy: transaction?.feesStrategy,
140
+ setIsSendMaxLoading,
139
141
  });
140
142
 
141
143
  const { rates, refetchRates } = useProviderRates({
142
144
  fromState,
143
145
  toState,
144
- exchangeRate,
145
146
  transaction,
146
147
  onNoRates,
147
148
  setExchangeRate,