@ledgerhq/live-common 34.51.0-nightly.1 → 34.51.0-nightly.3

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 (531) hide show
  1. package/lib/bridge/crypto-assets/index.d.ts.map +1 -1
  2. package/lib/bridge/crypto-assets/index.js +0 -2
  3. package/lib/bridge/crypto-assets/index.js.map +1 -1
  4. package/lib/bridge/crypto-assets/index.test.js +0 -4
  5. package/lib/bridge/crypto-assets/index.test.js.map +1 -1
  6. package/lib/bridge/generic-alpaca/accountBridge.d.ts.map +1 -1
  7. package/lib/bridge/generic-alpaca/accountBridge.js +2 -0
  8. package/lib/bridge/generic-alpaca/accountBridge.js.map +1 -1
  9. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +1 -0
  10. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
  11. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js +3 -0
  12. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
  13. package/lib/bridge/generic-alpaca/prepareTransaction.d.ts.map +1 -1
  14. package/lib/bridge/generic-alpaca/prepareTransaction.js +37 -45
  15. package/lib/bridge/generic-alpaca/prepareTransaction.js.map +1 -1
  16. package/lib/bridge/generic-alpaca/signOperation.d.ts.map +1 -1
  17. package/lib/bridge/generic-alpaca/signOperation.js +0 -20
  18. package/lib/bridge/generic-alpaca/signOperation.js.map +1 -1
  19. package/lib/bridge/generic-alpaca/signRawOperation.d.ts +8 -0
  20. package/lib/bridge/generic-alpaca/signRawOperation.d.ts.map +1 -0
  21. package/lib/bridge/generic-alpaca/signRawOperation.js +55 -0
  22. package/lib/bridge/generic-alpaca/signRawOperation.js.map +1 -0
  23. package/lib/bridge/generic-alpaca/tests/getAccountShape.test.js +1 -0
  24. package/lib/bridge/generic-alpaca/tests/getAccountShape.test.js.map +1 -1
  25. package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.js +186 -88
  26. package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.js.map +1 -1
  27. package/lib/bridge/generic-alpaca/utils.d.ts.map +1 -1
  28. package/lib/bridge/generic-alpaca/utils.js +1 -0
  29. package/lib/bridge/generic-alpaca/utils.js.map +1 -1
  30. package/lib/bridge/mockHelpers.d.ts +1 -0
  31. package/lib/bridge/mockHelpers.d.ts.map +1 -1
  32. package/lib/bridge/mockHelpers.js +53 -1
  33. package/lib/bridge/mockHelpers.js.map +1 -1
  34. package/lib/bridge/react/BridgeSync.d.ts +1 -0
  35. package/lib/bridge/react/BridgeSync.d.ts.map +1 -1
  36. package/lib/bridge/react/BridgeSync.js +19 -16
  37. package/lib/bridge/react/BridgeSync.js.map +1 -1
  38. package/lib/bridge/react/BridgeSync.test.js +403 -66
  39. package/lib/bridge/react/BridgeSync.test.js.map +1 -1
  40. package/lib/currencies/index.d.ts +1 -1
  41. package/lib/currencies/index.d.ts.map +1 -1
  42. package/lib/currencies/index.js +2 -3
  43. package/lib/currencies/index.js.map +1 -1
  44. package/lib/currencies/sortByMarketcap.test.js +1 -3
  45. package/lib/currencies/sortByMarketcap.test.js.map +1 -1
  46. package/lib/dada-client/entities/index.d.ts +1 -1
  47. package/lib/dada-client/entities/index.d.ts.map +1 -1
  48. package/lib/e2e/enum/Account.d.ts +4 -0
  49. package/lib/e2e/enum/Account.d.ts.map +1 -1
  50. package/lib/e2e/enum/Account.js +4 -0
  51. package/lib/e2e/enum/Account.js.map +1 -1
  52. package/lib/e2e/enum/AppInfos.d.ts +1 -0
  53. package/lib/e2e/enum/AppInfos.d.ts.map +1 -1
  54. package/lib/e2e/enum/AppInfos.js +1 -0
  55. package/lib/e2e/enum/AppInfos.js.map +1 -1
  56. package/lib/e2e/enum/Currency.d.ts +2 -0
  57. package/lib/e2e/enum/Currency.d.ts.map +1 -1
  58. package/lib/e2e/enum/Currency.js +2 -0
  59. package/lib/e2e/enum/Currency.js.map +1 -1
  60. package/lib/e2e/enum/Network.d.ts +2 -1
  61. package/lib/e2e/enum/Network.d.ts.map +1 -1
  62. package/lib/e2e/enum/Network.js +1 -0
  63. package/lib/e2e/enum/Network.js.map +1 -1
  64. package/lib/e2e/enum/TokenType.d.ts +2 -1
  65. package/lib/e2e/enum/TokenType.d.ts.map +1 -1
  66. package/lib/e2e/enum/TokenType.js +1 -0
  67. package/lib/e2e/enum/TokenType.js.map +1 -1
  68. package/lib/e2e/enum/TransactionStatus.d.ts +4 -1
  69. package/lib/e2e/enum/TransactionStatus.d.ts.map +1 -1
  70. package/lib/e2e/enum/TransactionStatus.js +3 -0
  71. package/lib/e2e/enum/TransactionStatus.js.map +1 -1
  72. package/lib/e2e/families/sui.d.ts +2 -0
  73. package/lib/e2e/families/sui.d.ts.map +1 -0
  74. package/lib/e2e/families/sui.js +11 -0
  75. package/lib/e2e/families/sui.js.map +1 -0
  76. package/lib/e2e/index.d.ts +11 -0
  77. package/lib/e2e/index.d.ts.map +1 -1
  78. package/lib/e2e/speculos.d.ts +1 -0
  79. package/lib/e2e/speculos.d.ts.map +1 -1
  80. package/lib/e2e/speculos.js +23 -1
  81. package/lib/e2e/speculos.js.map +1 -1
  82. package/lib/env.react.d.ts +1 -1
  83. package/lib/env.react.d.ts.map +1 -1
  84. package/lib/exchange/providers/swap.js +4 -4
  85. package/lib/exchange/providers/swap.js.map +1 -1
  86. package/lib/exchange/swap/api/v5/__mocks__/fetchRates.mocks.d.ts.map +1 -1
  87. package/lib/exchange/swap/api/v5/__mocks__/fetchRates.mocks.js +1 -1
  88. package/lib/exchange/swap/api/v5/__mocks__/fetchRates.mocks.js.map +1 -1
  89. package/lib/exchange/swap/mock.js +1 -1
  90. package/lib/exchange/swap/mock.js.map +1 -1
  91. package/lib/families/algorand/bridge/mock.d.ts.map +1 -1
  92. package/lib/families/algorand/bridge/mock.js +1 -0
  93. package/lib/families/algorand/bridge/mock.js.map +1 -1
  94. package/lib/families/bitcoin/bridge/mock.d.ts.map +1 -1
  95. package/lib/families/bitcoin/bridge/mock.js +1 -0
  96. package/lib/families/bitcoin/bridge/mock.js.map +1 -1
  97. package/lib/families/canton/bridge/mock.d.ts.map +1 -1
  98. package/lib/families/canton/bridge/mock.js +3 -0
  99. package/lib/families/canton/bridge/mock.js.map +1 -1
  100. package/lib/families/cardano/bridge/mock.d.ts.map +1 -1
  101. package/lib/families/cardano/bridge/mock.js +1 -0
  102. package/lib/families/cardano/bridge/mock.js.map +1 -1
  103. package/lib/families/casper/bridge/mock.d.ts.map +1 -1
  104. package/lib/families/casper/bridge/mock.js +1 -0
  105. package/lib/families/casper/bridge/mock.js.map +1 -1
  106. package/lib/families/cosmos/bridge/mock.d.ts.map +1 -1
  107. package/lib/families/cosmos/bridge/mock.js +1 -0
  108. package/lib/families/cosmos/bridge/mock.js.map +1 -1
  109. package/lib/families/evm/bridge/mock.d.ts.map +1 -1
  110. package/lib/families/evm/bridge/mock.js +1 -0
  111. package/lib/families/evm/bridge/mock.js.map +1 -1
  112. package/lib/families/icon/bridge/mock.d.ts.map +1 -1
  113. package/lib/families/icon/bridge/mock.js +1 -0
  114. package/lib/families/icon/bridge/mock.js.map +1 -1
  115. package/lib/families/multiversx/bridge/mock.d.ts.map +1 -1
  116. package/lib/families/multiversx/bridge/mock.js +1 -0
  117. package/lib/families/multiversx/bridge/mock.js.map +1 -1
  118. package/lib/families/polkadot/bridge/mock.d.ts.map +1 -1
  119. package/lib/families/polkadot/bridge/mock.js +1 -0
  120. package/lib/families/polkadot/bridge/mock.js.map +1 -1
  121. package/lib/families/polkadot/config.d.ts.map +1 -1
  122. package/lib/families/polkadot/config.js +84 -0
  123. package/lib/families/polkadot/config.js.map +1 -1
  124. package/lib/families/polkadot/setup.d.ts.map +1 -1
  125. package/lib/families/polkadot/setup.js +5 -4
  126. package/lib/families/polkadot/setup.js.map +1 -1
  127. package/lib/families/solana/bridge/mock.d.ts +1 -0
  128. package/lib/families/solana/bridge/mock.d.ts.map +1 -1
  129. package/lib/families/stellar/bridge/mock.d.ts.map +1 -1
  130. package/lib/families/stellar/bridge/mock.js +1 -0
  131. package/lib/families/stellar/bridge/mock.js.map +1 -1
  132. package/lib/families/tezos/bridge/mock.d.ts.map +1 -1
  133. package/lib/families/tezos/bridge/mock.js +1 -0
  134. package/lib/families/tezos/bridge/mock.js.map +1 -1
  135. package/lib/families/tron/bridge/mock.d.ts.map +1 -1
  136. package/lib/families/tron/bridge/mock.js +1 -0
  137. package/lib/families/tron/bridge/mock.js.map +1 -1
  138. package/lib/families/xrp/bridge/mock.d.ts.map +1 -1
  139. package/lib/families/xrp/bridge/mock.js +1 -0
  140. package/lib/families/xrp/bridge/mock.js.map +1 -1
  141. package/lib/featureFlags/defaultFeatures.d.ts +3 -0
  142. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  143. package/lib/featureFlags/defaultFeatures.js +14 -1
  144. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  145. package/lib/featureFlags/useFeature.d.ts +1 -1
  146. package/lib/featureFlags/useFeature.d.ts.map +1 -1
  147. package/lib/generated/bridge/mock.d.ts +1 -0
  148. package/lib/generated/bridge/mock.d.ts.map +1 -1
  149. package/lib/hooks/useManifestWithSessionId.d.ts +12 -0
  150. package/lib/hooks/useManifestWithSessionId.d.ts.map +1 -0
  151. package/lib/hooks/useManifestWithSessionId.js +67 -0
  152. package/lib/hooks/useManifestWithSessionId.js.map +1 -0
  153. package/lib/hooks/useManifestWithSessionId.test.d.ts +2 -0
  154. package/lib/hooks/useManifestWithSessionId.test.d.ts.map +1 -0
  155. package/lib/hooks/useManifestWithSessionId.test.js +71 -0
  156. package/lib/hooks/useManifestWithSessionId.test.js.map +1 -0
  157. package/lib/hw/actions/rawTransaction.d.ts +37 -0
  158. package/lib/hw/actions/rawTransaction.d.ts.map +1 -0
  159. package/lib/hw/actions/rawTransaction.js +107 -0
  160. package/lib/hw/actions/rawTransaction.js.map +1 -0
  161. package/lib/market/utils/index.d.ts +1 -0
  162. package/lib/market/utils/index.d.ts.map +1 -1
  163. package/lib/market/utils/index.js +16 -0
  164. package/lib/market/utils/index.js.map +1 -1
  165. package/lib/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.d.ts +2 -0
  166. package/lib/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.d.ts.map +1 -0
  167. package/lib/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.js +350 -0
  168. package/lib/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.js.map +1 -0
  169. package/lib/modularDrawer/hooks/index.d.ts +2 -0
  170. package/lib/modularDrawer/hooks/index.d.ts.map +1 -0
  171. package/lib/modularDrawer/hooks/index.js +6 -0
  172. package/lib/modularDrawer/hooks/index.js.map +1 -0
  173. package/lib/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.d.ts.map +1 -1
  174. package/lib/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.js +9 -0
  175. package/lib/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.js.map +1 -1
  176. package/lib/modularDrawer/hooks/useDetailedAccountsCore.d.ts +14 -0
  177. package/lib/modularDrawer/hooks/useDetailedAccountsCore.d.ts.map +1 -0
  178. package/lib/modularDrawer/hooks/useDetailedAccountsCore.js +119 -0
  179. package/lib/modularDrawer/hooks/useDetailedAccountsCore.js.map +1 -0
  180. package/lib/modularDrawer/hooks/useRightBalanceAsset.d.ts.map +1 -1
  181. package/lib/modularDrawer/hooks/useRightBalanceAsset.js +9 -1
  182. package/lib/modularDrawer/hooks/useRightBalanceAsset.js.map +1 -1
  183. package/lib/modularDrawer/hooks/useRightBalanceNetwork.d.ts +6 -1
  184. package/lib/modularDrawer/hooks/useRightBalanceNetwork.d.ts.map +1 -1
  185. package/lib/modularDrawer/hooks/useRightBalanceNetwork.js +12 -4
  186. package/lib/modularDrawer/hooks/useRightBalanceNetwork.js.map +1 -1
  187. package/lib/modularDrawer/index.d.ts +4 -0
  188. package/lib/modularDrawer/index.d.ts.map +1 -0
  189. package/lib/modularDrawer/index.js +20 -0
  190. package/lib/modularDrawer/index.js.map +1 -0
  191. package/lib/modularDrawer/types/detailedAccount.d.ts +46 -0
  192. package/lib/modularDrawer/types/detailedAccount.d.ts.map +1 -0
  193. package/lib/modularDrawer/types/detailedAccount.js +3 -0
  194. package/lib/modularDrawer/types/detailedAccount.js.map +1 -0
  195. package/lib/modularDrawer/types/index.d.ts +2 -0
  196. package/lib/modularDrawer/types/index.d.ts.map +1 -0
  197. package/lib/modularDrawer/types/index.js +18 -0
  198. package/lib/modularDrawer/types/index.js.map +1 -0
  199. package/lib/modularDrawer/utils/__tests__/sortAccountsByFiatValue.test.d.ts +2 -0
  200. package/lib/modularDrawer/utils/__tests__/sortAccountsByFiatValue.test.d.ts.map +1 -0
  201. package/lib/modularDrawer/utils/__tests__/sortAccountsByFiatValue.test.js +106 -0
  202. package/lib/modularDrawer/utils/__tests__/sortAccountsByFiatValue.test.js.map +1 -0
  203. package/lib/modularDrawer/utils/getBalanceAndFiatValueByAssets.d.ts +3 -4
  204. package/lib/modularDrawer/utils/getBalanceAndFiatValueByAssets.d.ts.map +1 -1
  205. package/lib/modularDrawer/utils/getBalanceAndFiatValueByAssets.js +7 -0
  206. package/lib/modularDrawer/utils/getBalanceAndFiatValueByAssets.js.map +1 -1
  207. package/lib/modularDrawer/utils/index.d.ts +1 -0
  208. package/lib/modularDrawer/utils/index.d.ts.map +1 -1
  209. package/lib/modularDrawer/utils/index.js +3 -1
  210. package/lib/modularDrawer/utils/index.js.map +1 -1
  211. package/lib/modularDrawer/utils/sortAccountsByFiatValue.d.ts +8 -0
  212. package/lib/modularDrawer/utils/sortAccountsByFiatValue.d.ts.map +1 -0
  213. package/lib/modularDrawer/utils/sortAccountsByFiatValue.js +17 -0
  214. package/lib/modularDrawer/utils/sortAccountsByFiatValue.js.map +1 -0
  215. package/lib/modularDrawer/utils/type.d.ts +2 -2
  216. package/lib/modularDrawer/utils/type.d.ts.map +1 -1
  217. package/lib/platform/providers/RemoteLiveAppProvider/api/mock.json +3 -3
  218. package/lib/wallet-api/logic.d.ts +1 -0
  219. package/lib/wallet-api/logic.d.ts.map +1 -1
  220. package/lib/wallet-api/logic.js +21 -1
  221. package/lib/wallet-api/logic.js.map +1 -1
  222. package/lib/wallet-api/react.d.ts +9 -1
  223. package/lib/wallet-api/react.d.ts.map +1 -1
  224. package/lib/wallet-api/react.js +60 -2
  225. package/lib/wallet-api/react.js.map +1 -1
  226. package/lib/wallet-api/tracking.d.ts +3 -0
  227. package/lib/wallet-api/tracking.d.ts.map +1 -1
  228. package/lib/wallet-api/tracking.js +12 -0
  229. package/lib/wallet-api/tracking.js.map +1 -1
  230. package/lib/wallet-api/useDappLogic.js +1 -1
  231. package/lib/wallet-api/useDappLogic.js.map +1 -1
  232. package/lib-es/bridge/crypto-assets/index.d.ts.map +1 -1
  233. package/lib-es/bridge/crypto-assets/index.js +0 -2
  234. package/lib-es/bridge/crypto-assets/index.js.map +1 -1
  235. package/lib-es/bridge/crypto-assets/index.test.js +0 -4
  236. package/lib-es/bridge/crypto-assets/index.test.js.map +1 -1
  237. package/lib-es/bridge/generic-alpaca/accountBridge.d.ts.map +1 -1
  238. package/lib-es/bridge/generic-alpaca/accountBridge.js +2 -0
  239. package/lib-es/bridge/generic-alpaca/accountBridge.js.map +1 -1
  240. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +1 -0
  241. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +1 -1
  242. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js +3 -0
  243. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +1 -1
  244. package/lib-es/bridge/generic-alpaca/prepareTransaction.d.ts.map +1 -1
  245. package/lib-es/bridge/generic-alpaca/prepareTransaction.js +37 -45
  246. package/lib-es/bridge/generic-alpaca/prepareTransaction.js.map +1 -1
  247. package/lib-es/bridge/generic-alpaca/signOperation.d.ts.map +1 -1
  248. package/lib-es/bridge/generic-alpaca/signOperation.js +0 -17
  249. package/lib-es/bridge/generic-alpaca/signOperation.js.map +1 -1
  250. package/lib-es/bridge/generic-alpaca/signRawOperation.d.ts +8 -0
  251. package/lib-es/bridge/generic-alpaca/signRawOperation.d.ts.map +1 -0
  252. package/lib-es/bridge/generic-alpaca/signRawOperation.js +48 -0
  253. package/lib-es/bridge/generic-alpaca/signRawOperation.js.map +1 -0
  254. package/lib-es/bridge/generic-alpaca/tests/getAccountShape.test.js +1 -0
  255. package/lib-es/bridge/generic-alpaca/tests/getAccountShape.test.js.map +1 -1
  256. package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.js +163 -88
  257. package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.js.map +1 -1
  258. package/lib-es/bridge/generic-alpaca/utils.d.ts.map +1 -1
  259. package/lib-es/bridge/generic-alpaca/utils.js +1 -0
  260. package/lib-es/bridge/generic-alpaca/utils.js.map +1 -1
  261. package/lib-es/bridge/mockHelpers.d.ts +1 -0
  262. package/lib-es/bridge/mockHelpers.d.ts.map +1 -1
  263. package/lib-es/bridge/mockHelpers.js +51 -0
  264. package/lib-es/bridge/mockHelpers.js.map +1 -1
  265. package/lib-es/bridge/react/BridgeSync.d.ts +1 -0
  266. package/lib-es/bridge/react/BridgeSync.d.ts.map +1 -1
  267. package/lib-es/bridge/react/BridgeSync.js +17 -15
  268. package/lib-es/bridge/react/BridgeSync.js.map +1 -1
  269. package/lib-es/bridge/react/BridgeSync.test.js +382 -65
  270. package/lib-es/bridge/react/BridgeSync.test.js.map +1 -1
  271. package/lib-es/currencies/index.d.ts +1 -1
  272. package/lib-es/currencies/index.d.ts.map +1 -1
  273. package/lib-es/currencies/index.js +1 -1
  274. package/lib-es/currencies/index.js.map +1 -1
  275. package/lib-es/currencies/sortByMarketcap.test.js +1 -3
  276. package/lib-es/currencies/sortByMarketcap.test.js.map +1 -1
  277. package/lib-es/dada-client/entities/index.d.ts +1 -1
  278. package/lib-es/dada-client/entities/index.d.ts.map +1 -1
  279. package/lib-es/e2e/enum/Account.d.ts +4 -0
  280. package/lib-es/e2e/enum/Account.d.ts.map +1 -1
  281. package/lib-es/e2e/enum/Account.js +4 -0
  282. package/lib-es/e2e/enum/Account.js.map +1 -1
  283. package/lib-es/e2e/enum/AppInfos.d.ts +1 -0
  284. package/lib-es/e2e/enum/AppInfos.d.ts.map +1 -1
  285. package/lib-es/e2e/enum/AppInfos.js +1 -0
  286. package/lib-es/e2e/enum/AppInfos.js.map +1 -1
  287. package/lib-es/e2e/enum/Currency.d.ts +2 -0
  288. package/lib-es/e2e/enum/Currency.d.ts.map +1 -1
  289. package/lib-es/e2e/enum/Currency.js +2 -0
  290. package/lib-es/e2e/enum/Currency.js.map +1 -1
  291. package/lib-es/e2e/enum/Network.d.ts +2 -1
  292. package/lib-es/e2e/enum/Network.d.ts.map +1 -1
  293. package/lib-es/e2e/enum/Network.js +1 -0
  294. package/lib-es/e2e/enum/Network.js.map +1 -1
  295. package/lib-es/e2e/enum/TokenType.d.ts +2 -1
  296. package/lib-es/e2e/enum/TokenType.d.ts.map +1 -1
  297. package/lib-es/e2e/enum/TokenType.js +1 -0
  298. package/lib-es/e2e/enum/TokenType.js.map +1 -1
  299. package/lib-es/e2e/enum/TransactionStatus.d.ts +4 -1
  300. package/lib-es/e2e/enum/TransactionStatus.d.ts.map +1 -1
  301. package/lib-es/e2e/enum/TransactionStatus.js +3 -0
  302. package/lib-es/e2e/enum/TransactionStatus.js.map +1 -1
  303. package/lib-es/e2e/families/sui.d.ts +2 -0
  304. package/lib-es/e2e/families/sui.d.ts.map +1 -0
  305. package/lib-es/e2e/families/sui.js +7 -0
  306. package/lib-es/e2e/families/sui.js.map +1 -0
  307. package/lib-es/e2e/index.d.ts +11 -0
  308. package/lib-es/e2e/index.d.ts.map +1 -1
  309. package/lib-es/e2e/speculos.d.ts +1 -0
  310. package/lib-es/e2e/speculos.d.ts.map +1 -1
  311. package/lib-es/e2e/speculos.js +21 -0
  312. package/lib-es/e2e/speculos.js.map +1 -1
  313. package/lib-es/env.react.d.ts +1 -1
  314. package/lib-es/env.react.d.ts.map +1 -1
  315. package/lib-es/exchange/providers/swap.js +4 -4
  316. package/lib-es/exchange/providers/swap.js.map +1 -1
  317. package/lib-es/exchange/swap/api/v5/__mocks__/fetchRates.mocks.d.ts.map +1 -1
  318. package/lib-es/exchange/swap/api/v5/__mocks__/fetchRates.mocks.js +1 -1
  319. package/lib-es/exchange/swap/api/v5/__mocks__/fetchRates.mocks.js.map +1 -1
  320. package/lib-es/exchange/swap/mock.js +1 -1
  321. package/lib-es/exchange/swap/mock.js.map +1 -1
  322. package/lib-es/families/algorand/bridge/mock.d.ts.map +1 -1
  323. package/lib-es/families/algorand/bridge/mock.js +2 -1
  324. package/lib-es/families/algorand/bridge/mock.js.map +1 -1
  325. package/lib-es/families/bitcoin/bridge/mock.d.ts.map +1 -1
  326. package/lib-es/families/bitcoin/bridge/mock.js +2 -1
  327. package/lib-es/families/bitcoin/bridge/mock.js.map +1 -1
  328. package/lib-es/families/canton/bridge/mock.d.ts.map +1 -1
  329. package/lib-es/families/canton/bridge/mock.js +3 -0
  330. package/lib-es/families/canton/bridge/mock.js.map +1 -1
  331. package/lib-es/families/cardano/bridge/mock.d.ts.map +1 -1
  332. package/lib-es/families/cardano/bridge/mock.js +2 -1
  333. package/lib-es/families/cardano/bridge/mock.js.map +1 -1
  334. package/lib-es/families/casper/bridge/mock.d.ts.map +1 -1
  335. package/lib-es/families/casper/bridge/mock.js +2 -1
  336. package/lib-es/families/casper/bridge/mock.js.map +1 -1
  337. package/lib-es/families/cosmos/bridge/mock.d.ts.map +1 -1
  338. package/lib-es/families/cosmos/bridge/mock.js +2 -1
  339. package/lib-es/families/cosmos/bridge/mock.js.map +1 -1
  340. package/lib-es/families/evm/bridge/mock.d.ts.map +1 -1
  341. package/lib-es/families/evm/bridge/mock.js +2 -1
  342. package/lib-es/families/evm/bridge/mock.js.map +1 -1
  343. package/lib-es/families/icon/bridge/mock.d.ts.map +1 -1
  344. package/lib-es/families/icon/bridge/mock.js +2 -1
  345. package/lib-es/families/icon/bridge/mock.js.map +1 -1
  346. package/lib-es/families/multiversx/bridge/mock.d.ts.map +1 -1
  347. package/lib-es/families/multiversx/bridge/mock.js +2 -1
  348. package/lib-es/families/multiversx/bridge/mock.js.map +1 -1
  349. package/lib-es/families/polkadot/bridge/mock.d.ts.map +1 -1
  350. package/lib-es/families/polkadot/bridge/mock.js +2 -1
  351. package/lib-es/families/polkadot/bridge/mock.js.map +1 -1
  352. package/lib-es/families/polkadot/config.d.ts.map +1 -1
  353. package/lib-es/families/polkadot/config.js +84 -0
  354. package/lib-es/families/polkadot/config.js.map +1 -1
  355. package/lib-es/families/polkadot/setup.d.ts.map +1 -1
  356. package/lib-es/families/polkadot/setup.js +5 -4
  357. package/lib-es/families/polkadot/setup.js.map +1 -1
  358. package/lib-es/families/solana/bridge/mock.d.ts +1 -0
  359. package/lib-es/families/solana/bridge/mock.d.ts.map +1 -1
  360. package/lib-es/families/stellar/bridge/mock.d.ts.map +1 -1
  361. package/lib-es/families/stellar/bridge/mock.js +2 -1
  362. package/lib-es/families/stellar/bridge/mock.js.map +1 -1
  363. package/lib-es/families/tezos/bridge/mock.d.ts.map +1 -1
  364. package/lib-es/families/tezos/bridge/mock.js +2 -1
  365. package/lib-es/families/tezos/bridge/mock.js.map +1 -1
  366. package/lib-es/families/tron/bridge/mock.d.ts.map +1 -1
  367. package/lib-es/families/tron/bridge/mock.js +2 -1
  368. package/lib-es/families/tron/bridge/mock.js.map +1 -1
  369. package/lib-es/families/xrp/bridge/mock.d.ts.map +1 -1
  370. package/lib-es/families/xrp/bridge/mock.js +2 -1
  371. package/lib-es/families/xrp/bridge/mock.js.map +1 -1
  372. package/lib-es/featureFlags/defaultFeatures.d.ts +3 -0
  373. package/lib-es/featureFlags/defaultFeatures.d.ts.map +1 -1
  374. package/lib-es/featureFlags/defaultFeatures.js +14 -1
  375. package/lib-es/featureFlags/defaultFeatures.js.map +1 -1
  376. package/lib-es/featureFlags/useFeature.d.ts +1 -1
  377. package/lib-es/featureFlags/useFeature.d.ts.map +1 -1
  378. package/lib-es/generated/bridge/mock.d.ts +1 -0
  379. package/lib-es/generated/bridge/mock.d.ts.map +1 -1
  380. package/lib-es/hooks/useManifestWithSessionId.d.ts +12 -0
  381. package/lib-es/hooks/useManifestWithSessionId.d.ts.map +1 -0
  382. package/lib-es/hooks/useManifestWithSessionId.js +60 -0
  383. package/lib-es/hooks/useManifestWithSessionId.js.map +1 -0
  384. package/lib-es/hooks/useManifestWithSessionId.test.d.ts +2 -0
  385. package/lib-es/hooks/useManifestWithSessionId.test.d.ts.map +1 -0
  386. package/lib-es/hooks/useManifestWithSessionId.test.js +69 -0
  387. package/lib-es/hooks/useManifestWithSessionId.test.js.map +1 -0
  388. package/lib-es/hw/actions/rawTransaction.d.ts +37 -0
  389. package/lib-es/hw/actions/rawTransaction.d.ts.map +1 -0
  390. package/lib-es/hw/actions/rawTransaction.js +103 -0
  391. package/lib-es/hw/actions/rawTransaction.js.map +1 -0
  392. package/lib-es/market/utils/index.d.ts +1 -0
  393. package/lib-es/market/utils/index.d.ts.map +1 -1
  394. package/lib-es/market/utils/index.js +2 -0
  395. package/lib-es/market/utils/index.js.map +1 -1
  396. package/lib-es/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.d.ts +2 -0
  397. package/lib-es/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.d.ts.map +1 -0
  398. package/lib-es/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.js +345 -0
  399. package/lib-es/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.js.map +1 -0
  400. package/lib-es/modularDrawer/hooks/index.d.ts +2 -0
  401. package/lib-es/modularDrawer/hooks/index.d.ts.map +1 -0
  402. package/lib-es/modularDrawer/hooks/index.js +2 -0
  403. package/lib-es/modularDrawer/hooks/index.js.map +1 -0
  404. package/lib-es/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.d.ts.map +1 -1
  405. package/lib-es/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.js +9 -0
  406. package/lib-es/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.js.map +1 -1
  407. package/lib-es/modularDrawer/hooks/useDetailedAccountsCore.d.ts +14 -0
  408. package/lib-es/modularDrawer/hooks/useDetailedAccountsCore.d.ts.map +1 -0
  409. package/lib-es/modularDrawer/hooks/useDetailedAccountsCore.js +115 -0
  410. package/lib-es/modularDrawer/hooks/useDetailedAccountsCore.js.map +1 -0
  411. package/lib-es/modularDrawer/hooks/useRightBalanceAsset.d.ts.map +1 -1
  412. package/lib-es/modularDrawer/hooks/useRightBalanceAsset.js +6 -1
  413. package/lib-es/modularDrawer/hooks/useRightBalanceAsset.js.map +1 -1
  414. package/lib-es/modularDrawer/hooks/useRightBalanceNetwork.d.ts +6 -1
  415. package/lib-es/modularDrawer/hooks/useRightBalanceNetwork.d.ts.map +1 -1
  416. package/lib-es/modularDrawer/hooks/useRightBalanceNetwork.js +9 -4
  417. package/lib-es/modularDrawer/hooks/useRightBalanceNetwork.js.map +1 -1
  418. package/lib-es/modularDrawer/index.d.ts +4 -0
  419. package/lib-es/modularDrawer/index.d.ts.map +1 -0
  420. package/lib-es/modularDrawer/index.js +4 -0
  421. package/lib-es/modularDrawer/index.js.map +1 -0
  422. package/lib-es/modularDrawer/types/detailedAccount.d.ts +46 -0
  423. package/lib-es/modularDrawer/types/detailedAccount.d.ts.map +1 -0
  424. package/lib-es/modularDrawer/types/detailedAccount.js +2 -0
  425. package/lib-es/modularDrawer/types/detailedAccount.js.map +1 -0
  426. package/lib-es/modularDrawer/types/index.d.ts +2 -0
  427. package/lib-es/modularDrawer/types/index.d.ts.map +1 -0
  428. package/lib-es/modularDrawer/types/index.js +2 -0
  429. package/lib-es/modularDrawer/types/index.js.map +1 -0
  430. package/lib-es/modularDrawer/utils/__tests__/sortAccountsByFiatValue.test.d.ts +2 -0
  431. package/lib-es/modularDrawer/utils/__tests__/sortAccountsByFiatValue.test.d.ts.map +1 -0
  432. package/lib-es/modularDrawer/utils/__tests__/sortAccountsByFiatValue.test.js +101 -0
  433. package/lib-es/modularDrawer/utils/__tests__/sortAccountsByFiatValue.test.js.map +1 -0
  434. package/lib-es/modularDrawer/utils/getBalanceAndFiatValueByAssets.d.ts +3 -4
  435. package/lib-es/modularDrawer/utils/getBalanceAndFiatValueByAssets.d.ts.map +1 -1
  436. package/lib-es/modularDrawer/utils/getBalanceAndFiatValueByAssets.js +4 -0
  437. package/lib-es/modularDrawer/utils/getBalanceAndFiatValueByAssets.js.map +1 -1
  438. package/lib-es/modularDrawer/utils/index.d.ts +1 -0
  439. package/lib-es/modularDrawer/utils/index.d.ts.map +1 -1
  440. package/lib-es/modularDrawer/utils/index.js +1 -0
  441. package/lib-es/modularDrawer/utils/index.js.map +1 -1
  442. package/lib-es/modularDrawer/utils/sortAccountsByFiatValue.d.ts +8 -0
  443. package/lib-es/modularDrawer/utils/sortAccountsByFiatValue.d.ts.map +1 -0
  444. package/lib-es/modularDrawer/utils/sortAccountsByFiatValue.js +13 -0
  445. package/lib-es/modularDrawer/utils/sortAccountsByFiatValue.js.map +1 -0
  446. package/lib-es/modularDrawer/utils/type.d.ts +2 -2
  447. package/lib-es/modularDrawer/utils/type.d.ts.map +1 -1
  448. package/lib-es/platform/providers/RemoteLiveAppProvider/api/mock.json +3 -3
  449. package/lib-es/wallet-api/logic.d.ts +1 -0
  450. package/lib-es/wallet-api/logic.d.ts.map +1 -1
  451. package/lib-es/wallet-api/logic.js +19 -0
  452. package/lib-es/wallet-api/logic.js.map +1 -1
  453. package/lib-es/wallet-api/react.d.ts +9 -1
  454. package/lib-es/wallet-api/react.d.ts.map +1 -1
  455. package/lib-es/wallet-api/react.js +61 -3
  456. package/lib-es/wallet-api/react.js.map +1 -1
  457. package/lib-es/wallet-api/tracking.d.ts +3 -0
  458. package/lib-es/wallet-api/tracking.d.ts.map +1 -1
  459. package/lib-es/wallet-api/tracking.js +12 -0
  460. package/lib-es/wallet-api/tracking.js.map +1 -1
  461. package/lib-es/wallet-api/useDappLogic.js +2 -2
  462. package/lib-es/wallet-api/useDappLogic.js.map +1 -1
  463. package/package.json +59 -59
  464. package/src/bridge/crypto-assets/index.test.ts +0 -4
  465. package/src/bridge/crypto-assets/index.ts +0 -2
  466. package/src/bridge/generic-alpaca/accountBridge.ts +2 -0
  467. package/src/bridge/generic-alpaca/alpaca/network/network-alpaca.ts +8 -0
  468. package/src/bridge/generic-alpaca/prepareTransaction.ts +46 -69
  469. package/src/bridge/generic-alpaca/signOperation.ts +0 -20
  470. package/src/bridge/generic-alpaca/signRawOperation.ts +86 -0
  471. package/src/bridge/generic-alpaca/tests/getAccountShape.test.ts +1 -0
  472. package/src/bridge/generic-alpaca/tests/prepareTransaction.test.ts +191 -109
  473. package/src/bridge/generic-alpaca/utils.ts +1 -0
  474. package/src/bridge/mockHelpers.ts +57 -0
  475. package/src/bridge/react/BridgeSync.test.tsx +513 -82
  476. package/src/bridge/react/BridgeSync.tsx +18 -17
  477. package/src/currencies/index.ts +1 -2
  478. package/src/currencies/sortByMarketcap.test.ts +1 -3
  479. package/src/dada-client/MIGRATION_GUIDE.md +215 -0
  480. package/src/dada-client/entities/index.ts +1 -1
  481. package/src/e2e/enum/Account.ts +31 -0
  482. package/src/e2e/enum/AppInfos.ts +2 -0
  483. package/src/e2e/enum/Currency.ts +11 -0
  484. package/src/e2e/enum/Network.ts +1 -0
  485. package/src/e2e/enum/TokenType.ts +1 -0
  486. package/src/e2e/enum/TransactionStatus.ts +3 -0
  487. package/src/e2e/families/sui.ts +7 -0
  488. package/src/e2e/speculos.ts +23 -0
  489. package/src/exchange/providers/swap.ts +4 -4
  490. package/src/exchange/swap/api/v5/__mocks__/fetchRates.mocks.ts +1 -2
  491. package/src/exchange/swap/mock.ts +1 -1
  492. package/src/families/algorand/bridge/mock.ts +2 -0
  493. package/src/families/bitcoin/bridge/mock.ts +2 -0
  494. package/src/families/canton/bridge/mock.ts +3 -0
  495. package/src/families/cardano/bridge/mock.ts +2 -0
  496. package/src/families/casper/bridge/mock.ts +2 -0
  497. package/src/families/cosmos/bridge/mock.ts +2 -0
  498. package/src/families/evm/bridge/mock.ts +2 -0
  499. package/src/families/icon/bridge/mock.ts +2 -0
  500. package/src/families/multiversx/bridge/mock.ts +2 -0
  501. package/src/families/polkadot/bridge/mock.ts +2 -0
  502. package/src/families/polkadot/config.ts +84 -0
  503. package/src/families/polkadot/setup.ts +6 -4
  504. package/src/families/stellar/bridge/mock.ts +2 -0
  505. package/src/families/tezos/bridge/mock.ts +2 -0
  506. package/src/families/tron/bridge/mock.ts +2 -0
  507. package/src/families/xrp/bridge/mock.ts +2 -0
  508. package/src/featureFlags/defaultFeatures.ts +15 -1
  509. package/src/hooks/useManifestWithSessionId.test.ts +105 -0
  510. package/src/hooks/useManifestWithSessionId.ts +83 -0
  511. package/src/hw/actions/rawTransaction.ts +190 -0
  512. package/src/market/utils/index.ts +3 -0
  513. package/src/modularDrawer/hooks/__tests__/useDetailedAccountsCore.test.ts +472 -0
  514. package/src/modularDrawer/hooks/index.ts +1 -0
  515. package/src/modularDrawer/hooks/useCurrenciesUnderFeatureFlag.ts +9 -0
  516. package/src/modularDrawer/hooks/useDetailedAccountsCore.ts +146 -0
  517. package/src/modularDrawer/hooks/useRightBalanceAsset.tsx +5 -1
  518. package/src/modularDrawer/hooks/useRightBalanceNetwork.tsx +10 -4
  519. package/src/modularDrawer/index.ts +3 -0
  520. package/src/modularDrawer/types/detailedAccount.ts +49 -0
  521. package/src/modularDrawer/types/index.ts +1 -0
  522. package/src/modularDrawer/utils/__tests__/sortAccountsByFiatValue.test.ts +117 -0
  523. package/src/modularDrawer/utils/getBalanceAndFiatValueByAssets.ts +6 -3
  524. package/src/modularDrawer/utils/index.ts +1 -0
  525. package/src/modularDrawer/utils/sortAccountsByFiatValue.ts +14 -0
  526. package/src/modularDrawer/utils/type.ts +3 -2
  527. package/src/platform/providers/RemoteLiveAppProvider/api/mock.json +3 -3
  528. package/src/wallet-api/logic.ts +35 -0
  529. package/src/wallet-api/react.ts +87 -1
  530. package/src/wallet-api/tracking.ts +15 -0
  531. package/src/wallet-api/useDappLogic.ts +3 -3
@@ -2,13 +2,19 @@
2
2
  * @jest-environment jsdom
3
3
  */
4
4
  import "../../__tests__/test-helpers/dom-polyfill";
5
- import React from "react";
5
+ import React, { useEffect } from "react";
6
6
  import { render, screen } from "@testing-library/react";
7
+ import type { Account } from "@ledgerhq/types-live";
8
+ import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
9
+ import { Observable } from "rxjs";
10
+ import type { Observer } from "rxjs";
7
11
  import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
8
12
  import { genAccount } from "../../mock/account";
9
- import { BridgeSync } from "./BridgeSync";
13
+ import { BridgeSync, resetStates } from "./BridgeSync";
10
14
  import { setSupportedCurrencies } from "../../currencies";
11
- import { getAccountBridge } from "..";
15
+ import * as Bridge from "..";
16
+ import { useBridgeSync, useBridgeSyncState } from "./context";
17
+ import type { Sync, BridgeSyncState } from "./types";
12
18
 
13
19
  jest.setTimeout(30000);
14
20
 
@@ -24,96 +30,521 @@ const defaultsBridgeSyncOpts = {
24
30
 
25
31
  setSupportedCurrencies(["bitcoin", "ethereum"]);
26
32
 
33
+ const bitcoin = getCryptoCurrencyById("bitcoin");
34
+ const ethereum = getCryptoCurrencyById("ethereum");
35
+
36
+ const createAccount = (
37
+ id: string,
38
+ currency: CryptoCurrency,
39
+ options: Parameters<typeof genAccount>[1] = {},
40
+ ) => genAccount(id, { ...options, currency });
41
+
42
+ type BridgeSyncRenderProps = Partial<Omit<React.ComponentProps<typeof BridgeSync>, "children">>;
43
+
44
+ const renderBridgeSync = (props: BridgeSyncRenderProps = {}, children: React.ReactNode = null) =>
45
+ render(
46
+ <BridgeSync {...defaultsBridgeSyncOpts} {...props}>
47
+ {children}
48
+ </BridgeSync>,
49
+ );
50
+
51
+ type AccountUpdater = (arg0: Account) => Account;
52
+
53
+ const baseGetAccountBridge = Bridge.getAccountBridge;
54
+
55
+ const withMockedAccountBridge = (
56
+ account: Account,
57
+ syncFactory: () => Observable<AccountUpdater>,
58
+ ) => {
59
+ const originalBridge = baseGetAccountBridge(account);
60
+ const mockBridge = {
61
+ ...originalBridge,
62
+ sync: syncFactory,
63
+ };
64
+ return jest.spyOn(Bridge, "getAccountBridge").mockImplementation(acc => {
65
+ if (acc.id === account.id) {
66
+ return mockBridge;
67
+ }
68
+ return baseGetAccountBridge(acc);
69
+ });
70
+ };
71
+
72
+ const mockBridgeSync = (
73
+ account: Account,
74
+ producer: (observer: Observer<AccountUpdater>) => void | (() => void),
75
+ ) =>
76
+ withMockedAccountBridge(
77
+ account,
78
+ () =>
79
+ new Observable<AccountUpdater>(observer => {
80
+ const cleanup = producer(observer);
81
+ return typeof cleanup === "function" ? cleanup : undefined;
82
+ }),
83
+ );
84
+
27
85
  describe("BridgeSync", () => {
86
+ afterEach(() => {
87
+ jest.restoreAllMocks();
88
+ resetStates();
89
+ });
90
+
28
91
  test("initialize without an error", async () => {
29
- render(<BridgeSync {...defaultsBridgeSyncOpts}>LOADED</BridgeSync>);
92
+ renderBridgeSync({}, "LOADED");
30
93
  expect(screen.getByText("LOADED")).not.toBeNull();
31
94
  });
32
95
 
33
- test("executes a sync at start tracked as reason=initial", async () => {
34
- await new Promise(resolve => {
35
- const BTC = getCryptoCurrencyById("bitcoin");
36
- const account = genAccount("btc1", { currency: BTC });
37
- const futureOpLength = account.operations.length;
38
- // we remove the first operation to feed it back as a broadcasted one, the mock impl will make it go back to operations
39
- const lastOp = account.operations.splice(0, 1)[0];
40
- getAccountBridge(account).broadcast({
41
- account,
42
- signedOperation: {
43
- operation: lastOp,
44
- signature: "",
45
- },
46
- });
47
- const accounts = [account];
48
- expect(accounts[0].operations.length).toBe(futureOpLength - 1);
49
-
50
- function track(type, opts) {
51
- if (type === "SyncSuccess") {
52
- expect(opts).toMatchObject({
53
- reason: "initial",
54
- currencyName: "Bitcoin",
55
- operationsLength: futureOpLength,
56
- });
57
- resolve(null);
58
- }
96
+ test("executes a sync at start tracked as reason=initial", done => {
97
+ const account = createAccount("btc1", bitcoin);
98
+ const futureOpLength = account.operations.length;
99
+ // we remove the first operation to feed it back as a broadcasted one, the mock impl will make it go back to operations
100
+ const lastOp = account.operations.splice(0, 1)[0];
101
+ Bridge.getAccountBridge(account).broadcast({
102
+ account,
103
+ signedOperation: {
104
+ operation: lastOp,
105
+ signature: "",
106
+ },
107
+ });
108
+ const accounts = [account];
109
+ expect(accounts[0].operations.length).toBe(futureOpLength - 1);
110
+
111
+ function track(type, opts) {
112
+ if (type === "SyncSuccess") {
113
+ expect(opts).toMatchObject({
114
+ reason: "initial",
115
+ currencyName: "Bitcoin",
116
+ operationsLength: futureOpLength,
117
+ });
118
+ done();
59
119
  }
60
- render(
61
- <BridgeSync {...defaultsBridgeSyncOpts} accounts={accounts} trackAnalytics={track}>
62
- {null}
63
- </BridgeSync>,
64
- );
120
+ }
121
+ renderBridgeSync({ accounts, trackAnalytics: track });
122
+ });
123
+
124
+ test("sync all accounts in parallel at start tracked as reason=initial", done => {
125
+ const accounts = [
126
+ createAccount("2btc1", bitcoin),
127
+ createAccount("2btc2", bitcoin),
128
+ createAccount("2eth1", ethereum),
129
+ ];
130
+ const synced: Array<Record<string, unknown>> = [];
131
+ let resolveFirst;
132
+ function prepareCurrency() {
133
+ if (!resolveFirst) {
134
+ return new Promise((resolve, reject) => {
135
+ resolveFirst = resolve;
136
+ setTimeout(
137
+ reject,
138
+ 5000,
139
+ new Error("prepareCurrency doesn't seem to be called in parallel"),
140
+ );
141
+ });
142
+ }
143
+ // if we reach here, it means, we managed to have
144
+ // a SECOND sync that need to prepare currency
145
+ // so it's a proof that sync correctly runs in parallel
146
+ // otherwise it would timeout
147
+ resolveFirst();
148
+ return Promise.resolve();
149
+ }
150
+ function track(type, opts) {
151
+ expect(type).not.toEqual("SyncError");
152
+ if (type === "SyncSuccess") {
153
+ synced.push(opts);
154
+ expect(opts).toMatchObject({
155
+ reason: "initial",
156
+ });
157
+ if (synced.length === accounts.length) done();
158
+ }
159
+ }
160
+ renderBridgeSync({
161
+ accounts,
162
+ prepareCurrency,
163
+ trackAnalytics: track,
65
164
  });
66
165
  });
67
166
 
68
- test("sync all accounts in parallel at start tracked as reason=initial", async () => {
69
- await new Promise(resolve => {
70
- const BTC = getCryptoCurrencyById("bitcoin");
71
- const ETH = getCryptoCurrencyById("ethereum");
72
- const accounts = [
73
- genAccount("2btc1", { currency: BTC }),
74
- genAccount("2btc2", { currency: BTC }),
75
- genAccount("2eth1", { currency: ETH }),
76
- ];
77
- const synced: Array<any> = [];
78
- let resolveFirst;
79
- function prepareCurrency() {
80
- if (!resolveFirst) {
81
- return new Promise((resolve, reject) => {
82
- resolveFirst = resolve;
83
- setTimeout(
84
- reject,
85
- 5000,
86
- new Error("prepareCurrency doesn't seem to be called in parallel"),
87
- );
88
- });
167
+ test("provides context values correctly", () => {
168
+ const account = createAccount("btc1", bitcoin);
169
+ const accounts = [account];
170
+
171
+ let syncFunction: Sync | undefined;
172
+ let syncState: BridgeSyncState | undefined;
173
+
174
+ function TestComponent() {
175
+ syncFunction = useBridgeSync();
176
+ syncState = useBridgeSyncState();
177
+ return <div data-testid="test-component">Test</div>;
178
+ }
179
+
180
+ renderBridgeSync({ accounts }, <TestComponent />);
181
+
182
+ expect(syncFunction).toBeDefined();
183
+ expect(typeof syncFunction).toBe("function");
184
+ expect(syncState).toBeDefined();
185
+ expect(typeof syncState).toBe("object");
186
+ });
187
+
188
+ test("handles sync errors with recoverError function", done => {
189
+ const account = createAccount("btc1", bitcoin);
190
+ const accounts = [account];
191
+
192
+ const mockError = new Error("Sync failed");
193
+ const recoverError = jest.fn((error: Error) => {
194
+ expect(error.message).toBe("Sync failed");
195
+ return error; // Return error to treat as actual error
196
+ });
197
+
198
+ // Mock the account bridge to return an Observable that emits an error
199
+ mockBridgeSync(account, observer => {
200
+ const timeout = setTimeout(() => observer.error(mockError), 100);
201
+ return () => clearTimeout(timeout);
202
+ });
203
+
204
+ let syncStateChecked = false;
205
+ let syncStateRef: BridgeSyncState;
206
+ function TestComponent() {
207
+ const syncState = useBridgeSyncState();
208
+ syncStateRef = syncState;
209
+
210
+ // After the error is silenced, the sync state should show no error
211
+ setTimeout(() => {
212
+ if (!syncStateChecked && syncStateRef[account.id]) {
213
+ syncStateChecked = true;
214
+ expect(syncStateRef[account.id].error).toBe(mockError);
215
+ expect(recoverError).toHaveBeenCalledWith(mockError);
216
+ done();
89
217
  }
90
- // if we reach here, it means, we managed to have
91
- // a SECOND sync that need to prepare currency
92
- // so it's a proof that sync correctly runs in parallel
93
- // otherwise it would timeout
94
- resolveFirst();
95
- return Promise.resolve();
96
- }
97
- function track(type, opts) {
98
- expect(type).not.toEqual("SyncError");
99
- if (type === "SyncSuccess") {
100
- synced.push(opts);
101
- expect(opts).toMatchObject({
102
- reason: "initial",
103
- });
104
- if (synced.length === accounts.length) resolve(null);
218
+ }, 200);
219
+
220
+ return <div>Test</div>;
221
+ }
222
+
223
+ renderBridgeSync({ accounts, recoverError }, <TestComponent />);
224
+ });
225
+
226
+ test("silences errors when recoverError returns null", done => {
227
+ const account = createAccount("btc1", bitcoin);
228
+ const accounts = [account];
229
+
230
+ const mockError = new Error("Sync failed but should be silenced");
231
+ const recoverError = jest.fn(() => null); // Return null to silence the error
232
+
233
+ // Mock the account bridge to return an Observable that emits an error
234
+ mockBridgeSync(account, observer => {
235
+ const timeout = setTimeout(() => observer.error(mockError), 100);
236
+ return () => clearTimeout(timeout);
237
+ });
238
+
239
+ let syncStateChecked = false;
240
+ let syncStateRef: BridgeSyncState;
241
+ function TestComponent() {
242
+ const syncState = useBridgeSyncState();
243
+ syncStateRef = syncState;
244
+
245
+ // After the error is silenced, the sync state should show no error
246
+ setTimeout(() => {
247
+ if (!syncStateChecked && syncStateRef[account.id]) {
248
+ syncStateChecked = true;
249
+ expect(syncStateRef[account.id].error).toBeNull();
250
+ expect(recoverError).toHaveBeenCalledWith(mockError);
251
+ done();
105
252
  }
106
- }
107
- render(
108
- <BridgeSync
109
- {...defaultsBridgeSyncOpts}
110
- prepareCurrency={prepareCurrency}
111
- accounts={accounts}
112
- trackAnalytics={track}
113
- >
114
- {null}
115
- </BridgeSync>,
116
- );
253
+ }, 200);
254
+
255
+ return <div>Test</div>;
256
+ }
257
+
258
+ renderBridgeSync({ accounts, recoverError }, <TestComponent />);
259
+ });
260
+
261
+ test("handles blacklisted token IDs in sync config", () => {
262
+ const account = createAccount("btc1", bitcoin);
263
+ const blacklistedTokenIds = ["token1", "token2"];
264
+
265
+ renderBridgeSync({ accounts: [account], blacklistedTokenIds });
266
+
267
+ // Test passes if component renders without errors with blacklisted tokens
268
+ expect(blacklistedTokenIds).toHaveLength(2);
269
+ });
270
+
271
+ test("handles sync actions correctly", () => {
272
+ const account1 = createAccount("btc1", bitcoin);
273
+ const account2 = createAccount("eth1", ethereum);
274
+ const accounts = [account1, account2];
275
+
276
+ let sync: Sync | undefined;
277
+
278
+ function TestComponent() {
279
+ sync = useBridgeSync();
280
+ return <div>Test</div>;
281
+ }
282
+
283
+ renderBridgeSync({ accounts }, <TestComponent />);
284
+
285
+ expect(sync).toBeDefined();
286
+
287
+ // Test different sync actions
288
+ expect(() => {
289
+ sync?.({ type: "SYNC_ALL_ACCOUNTS", priority: 1, reason: "manual" });
290
+ }).not.toThrow();
291
+
292
+ expect(() => {
293
+ sync?.({ type: "SYNC_ONE_ACCOUNT", accountId: account1.id, priority: 1, reason: "manual" });
294
+ }).not.toThrow();
295
+
296
+ expect(() => {
297
+ sync?.({
298
+ type: "SYNC_SOME_ACCOUNTS",
299
+ accountIds: [account1.id],
300
+ priority: 1,
301
+ reason: "manual",
302
+ });
303
+ }).not.toThrow();
304
+
305
+ expect(() => {
306
+ sync?.({ type: "SET_SKIP_UNDER_PRIORITY", priority: 5 });
307
+ }).not.toThrow();
308
+
309
+ expect(() => {
310
+ sync?.({ type: "BACKGROUND_TICK", reason: "background" });
311
+ }).not.toThrow();
312
+ });
313
+
314
+ test("handles pending operations sync", () => {
315
+ const account = createAccount("btc1", bitcoin);
316
+
317
+ // Create account with pending operations
318
+ const accountWithPending = {
319
+ ...account,
320
+ pendingOperations: [
321
+ {
322
+ id: "pending1",
323
+ hash: "hash1",
324
+ type: "OUT" as const,
325
+ value: account.balance,
326
+ fee: account.balance.dividedBy(10),
327
+ blockHash: null,
328
+ blockHeight: null,
329
+ senders: [account.freshAddress],
330
+ recipients: ["recipient1"],
331
+ accountId: account.id,
332
+ date: new Date(),
333
+ extra: {},
334
+ },
335
+ ],
336
+ };
337
+
338
+ const accounts = [accountWithPending];
339
+
340
+ let sync: Sync | undefined;
341
+
342
+ function TestComponent() {
343
+ sync = useBridgeSync();
344
+ return <div>Test</div>;
345
+ }
346
+
347
+ renderBridgeSync({ accounts }, <TestComponent />);
348
+
349
+ expect(sync).toBeDefined();
350
+
351
+ // The component should automatically sync accounts with pending operations
352
+ // This is tested by checking that the component renders without errors
353
+ // and that pending operations are handled properly
354
+ expect(accountWithPending.pendingOperations.length).toBeGreaterThan(0);
355
+ });
356
+
357
+ test("hydrates currencies only once", async () => {
358
+ const account1 = createAccount("btc1", bitcoin);
359
+ const account2 = createAccount("btc2", bitcoin); // Same currency
360
+ const account3 = createAccount("eth1", ethereum);
361
+ const accounts = [account1, account2, account3];
362
+
363
+ const hydrateCurrency = jest.fn(() => Promise.resolve());
364
+
365
+ renderBridgeSync({ accounts, hydrateCurrency });
366
+
367
+ // Wait for hydration to complete
368
+ await new Promise(resolve => setTimeout(resolve, 50));
369
+
370
+ // Should only hydrate each currency once, not once per account
371
+ expect(hydrateCurrency).toHaveBeenCalledTimes(2); // BTC and ETH
372
+ expect(hydrateCurrency).toHaveBeenCalledWith(bitcoin);
373
+ expect(hydrateCurrency).toHaveBeenCalledWith(ethereum);
374
+ });
375
+
376
+ test("handles different sync actions", () => {
377
+ const account = createAccount("btc1", bitcoin);
378
+ const accounts = [account];
379
+
380
+ let sync: Sync | undefined;
381
+
382
+ function TestComponent() {
383
+ sync = useBridgeSync();
384
+ return <div>Test</div>;
385
+ }
386
+
387
+ renderBridgeSync({ accounts }, <TestComponent />);
388
+
389
+ expect(sync).toBeDefined();
390
+
391
+ // Test that sync actions can be called without throwing
392
+ expect(sync).toBeDefined();
393
+ const syncFn = sync!; // Assert non-null since we just checked
394
+
395
+ expect(() =>
396
+ syncFn({ type: "SYNC_ALL_ACCOUNTS", priority: 1, reason: "manual" }),
397
+ ).not.toThrow();
398
+ expect(() =>
399
+ syncFn({ type: "SYNC_ONE_ACCOUNT", accountId: account.id, priority: 1, reason: "manual" }),
400
+ ).not.toThrow();
401
+ expect(() => syncFn({ type: "SET_SKIP_UNDER_PRIORITY", priority: 5 })).not.toThrow();
402
+ expect(() => syncFn({ type: "BACKGROUND_TICK", reason: "background" })).not.toThrow();
403
+ });
404
+
405
+ test("tracks session analytics when all accounts complete", async () => {
406
+ const account1 = createAccount("btc1", bitcoin, { operationsSize: 3 });
407
+ const account2 = createAccount("eth1", ethereum, { operationsSize: 5 });
408
+ const accounts = [account1, account2];
409
+
410
+ const trackAnalytics = jest.fn();
411
+
412
+ renderBridgeSync({ accounts, trackAnalytics });
413
+
414
+ // Wait for potential analytics calls
415
+ await new Promise(resolve => setTimeout(resolve, 100));
416
+
417
+ // The component should not throw when tracking analytics
418
+ expect(accounts).toHaveLength(2);
419
+ });
420
+
421
+ test("handles non-existent account sync gracefully", () => {
422
+ const account = createAccount("btc1", bitcoin);
423
+ const accounts = [account];
424
+
425
+ let sync: Sync | undefined;
426
+
427
+ function TestComponent() {
428
+ sync = useBridgeSync();
429
+ return <div>Test</div>;
430
+ }
431
+
432
+ renderBridgeSync({ accounts }, <TestComponent />);
433
+
434
+ // Try to sync an account that doesn't exist - should not throw
435
+ expect(sync).toBeDefined();
436
+ const syncFn = sync!;
437
+
438
+ expect(() => {
439
+ syncFn({
440
+ type: "SYNC_ONE_ACCOUNT",
441
+ accountId: "non-existent-account",
442
+ priority: 1,
443
+ reason: "manual",
444
+ });
445
+ }).not.toThrow();
446
+ });
447
+
448
+ test("does not send analytics for background sync reason", done => {
449
+ const account = createAccount("btc1", bitcoin);
450
+ const accounts = [account];
451
+
452
+ const trackAnalytics = jest.fn();
453
+
454
+ // Mock the account bridge to complete successfully
455
+ mockBridgeSync(account, observer => {
456
+ observer.next((acc: typeof account) => acc);
457
+ observer.complete();
458
+ });
459
+
460
+ function TestComponent() {
461
+ const sync = useBridgeSync();
462
+
463
+ useEffect(() => {
464
+ // Trigger a background sync
465
+ sync({
466
+ type: "SYNC_ONE_ACCOUNT",
467
+ accountId: account.id,
468
+ priority: 1,
469
+ reason: "background",
470
+ });
471
+ }, [sync]);
472
+ return <div>Test</div>;
473
+ }
474
+
475
+ renderBridgeSync({ accounts, trackAnalytics }, <TestComponent />);
476
+
477
+ // Wait for sync to complete and verify no analytics were sent
478
+ setTimeout(() => {
479
+ // Should not have called trackAnalytics with SyncSuccess for background syncs
480
+ const syncSuccessCalls = trackAnalytics.mock.calls.filter(call => call[0] === "SyncSuccess");
481
+ expect(syncSuccessCalls).toHaveLength(0);
482
+
483
+ // Verify trackAnalytics was not called at all with SyncSuccess
484
+ expect(trackAnalytics).not.toHaveBeenCalledWith("SyncSuccess", expect.anything());
485
+
486
+ done();
487
+ }, 200);
488
+ });
489
+
490
+ test("sends analytics for non-background sync reason", done => {
491
+ const account = createAccount("btc1", bitcoin);
492
+ const accounts = [account];
493
+
494
+ const trackAnalytics = jest.fn();
495
+
496
+ // Mock the account bridge to complete successfully
497
+ mockBridgeSync(account, observer => {
498
+ observer.next((acc: typeof account) => acc);
499
+ observer.complete();
117
500
  });
501
+
502
+ function TestComponent() {
503
+ const sync = useBridgeSync();
504
+
505
+ useEffect(() => {
506
+ // Trigger a manual (non-background) sync
507
+ sync({
508
+ type: "SYNC_ONE_ACCOUNT",
509
+ accountId: account.id,
510
+ priority: 1,
511
+ reason: "manual",
512
+ });
513
+ }, [sync]);
514
+ return <div>Test</div>;
515
+ }
516
+
517
+ renderBridgeSync({ accounts, trackAnalytics }, <TestComponent />);
518
+
519
+ // Wait for sync to complete and verify analytics were sent
520
+ setTimeout(() => {
521
+ // Should have called trackAnalytics with SyncSuccess for manual syncs
522
+ expect(trackAnalytics).toHaveBeenCalledWith(
523
+ "SyncSuccess",
524
+ expect.objectContaining({
525
+ reason: "manual",
526
+ currencyName: account.currency.name,
527
+ }),
528
+ );
529
+
530
+ done();
531
+ }, 400);
532
+ });
533
+
534
+ test("provides sync state context", () => {
535
+ const account = createAccount("btc1", bitcoin);
536
+ const accounts = [account];
537
+
538
+ let syncState: BridgeSyncState | undefined;
539
+
540
+ function TestComponent() {
541
+ syncState = useBridgeSyncState();
542
+ return <div>Test</div>;
543
+ }
544
+
545
+ renderBridgeSync({ accounts }, <TestComponent />);
546
+
547
+ expect(syncState).toBeDefined();
548
+ expect(typeof syncState).toBe("object");
118
549
  });
119
550
  });
@@ -100,13 +100,21 @@ function useHydrate({ accounts, hydrateCurrency }) {
100
100
  }, [accounts, hydrateCurrency]);
101
101
  }
102
102
 
103
- const lastTimeAnalyticsTrackPerAccountId: Record<string, number> = {};
104
- const lastTimeSuccessSyncPerAccountId: Record<string, number> = {};
105
- const nothingState = {
103
+ let lastTimeAnalyticsTrackPerAccountId: Record<string, number> = {};
104
+ let nothingState = {
106
105
  pending: false,
107
106
  error: null,
108
107
  };
109
108
 
109
+ // Only used for tests
110
+ export function resetStates() {
111
+ lastTimeAnalyticsTrackPerAccountId = {};
112
+ nothingState = {
113
+ pending: false,
114
+ error: null,
115
+ };
116
+ }
117
+
110
118
  // useHydrate: returns a sync queue and bridge sync state
111
119
  function useSyncQueue({
112
120
  accounts,
@@ -159,11 +167,10 @@ function useSyncQueue({
159
167
  if (!account) return;
160
168
  const subAccounts: TokenAccount[] = account.subAccounts || [];
161
169
 
162
- // Nb Only emit SyncSuccess/SyncSuccessToken event once per launch
163
- if (lastTimeSuccessSyncPerAccountId[accountId]) {
170
+ if (reason === "background") {
171
+ // don't track background syncs
164
172
  return;
165
173
  }
166
- lastTimeSuccessSyncPerAccountId[accountId] = startSyncTime;
167
174
 
168
175
  trackAnalytics("SyncSuccess", {
169
176
  duration: (Date.now() - startSyncTime) / 1000,
@@ -173,22 +180,16 @@ function useSyncQueue({
173
180
  operationsLength: account.operationsCount,
174
181
  accountsCountForCurrency: accounts.filter(a => a.currency === account.currency).length,
175
182
  tokensLength: subAccounts.length,
176
- votesCount: getVotesCount(account),
177
- reason,
178
- });
179
-
180
- subAccounts.forEach(a => {
181
- const tokenId =
182
- a.type === "TokenAccount" ? getAccountCurrency(a).id : account.currency.name;
183
- trackAnalytics("SyncSuccessToken", {
184
- tokenId,
183
+ tokens: subAccounts.map(a => ({
184
+ tokenId: a.type === "TokenAccount" ? getAccountCurrency(a).id : account.currency.name,
185
185
  tokenTicker: getAccountCurrency(a).ticker,
186
186
  operationsLength: a.operationsCount,
187
187
  parentCurrencyName: account.currency.name,
188
188
  parentDerivationMode: account.derivationMode,
189
189
  votesCount: getVotesCount(a, account),
190
- reason,
191
- });
190
+ })),
191
+ votesCount: getVotesCount(account),
192
+ reason,
192
193
  });
193
194
  };
194
195