@ledgerhq/live-common 21.5.1-btcjs.0 → 21.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (328) hide show
  1. package/lib/account/addAccounts.d.ts.map +1 -1
  2. package/lib/account/addAccounts.js +1 -2
  3. package/lib/account/addAccounts.js.map +1 -1
  4. package/lib/account/support.d.ts.map +1 -1
  5. package/lib/account/support.js +1 -24
  6. package/lib/account/support.js.map +1 -1
  7. package/lib/api/explorerConfig/index.js +15 -15
  8. package/lib/bot/index.d.ts +1 -2
  9. package/lib/bot/index.d.ts.map +1 -1
  10. package/lib/bot/index.js +15 -19
  11. package/lib/bot/index.js.map +1 -1
  12. package/lib/bot/test.bot.js +1 -4
  13. package/lib/bot/test.bot.js.map +1 -1
  14. package/lib/bridge/jsHelpers.d.ts +1 -6
  15. package/lib/bridge/jsHelpers.d.ts.map +1 -1
  16. package/lib/bridge/jsHelpers.js +3 -11
  17. package/lib/bridge/jsHelpers.js.map +1 -1
  18. package/lib/env.js +1 -1
  19. package/lib/env.js.map +1 -1
  20. package/lib/exchange/swap/getExchangeRates.d.ts.map +1 -1
  21. package/lib/exchange/swap/getExchangeRates.js +9 -8
  22. package/lib/exchange/swap/getExchangeRates.js.map +1 -1
  23. package/lib/exchange/swap/hooks/index.d.ts +11 -0
  24. package/lib/exchange/swap/hooks/index.d.ts.map +1 -0
  25. package/lib/exchange/swap/hooks/index.js +23 -0
  26. package/lib/exchange/swap/hooks/index.js.map +1 -0
  27. package/lib/exchange/swap/hooks/useFromState.d.ts +15 -0
  28. package/lib/exchange/swap/hooks/useFromState.d.ts.map +1 -0
  29. package/lib/exchange/swap/hooks/useFromState.js +67 -0
  30. package/lib/exchange/swap/hooks/useFromState.js.map +1 -0
  31. package/lib/exchange/swap/hooks/useFromState.test.d.ts +2 -0
  32. package/lib/exchange/swap/hooks/useFromState.test.d.ts.map +1 -0
  33. package/lib/exchange/swap/hooks/useFromState.test.js +141 -0
  34. package/lib/exchange/swap/hooks/useFromState.test.js.map +1 -0
  35. package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts +5 -0
  36. package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts.map +1 -0
  37. package/lib/exchange/swap/hooks/usePickDefaultAccount.js +37 -0
  38. package/lib/exchange/swap/hooks/usePickDefaultAccount.js.map +1 -0
  39. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts +2 -0
  40. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.d.ts.map +1 -0
  41. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js +185 -0
  42. package/lib/exchange/swap/hooks/usePickDefaultAccount.test.js.map +1 -0
  43. package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts +3 -0
  44. package/lib/exchange/swap/hooks/usePickDefaultCurrency.d.ts.map +1 -0
  45. package/lib/exchange/swap/hooks/usePickDefaultCurrency.js +17 -0
  46. package/lib/exchange/swap/hooks/usePickDefaultCurrency.js.map +1 -0
  47. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts +2 -0
  48. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.d.ts.map +1 -0
  49. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js +73 -0
  50. package/lib/exchange/swap/hooks/usePickDefaultCurrency.test.js.map +1 -0
  51. package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts +12 -0
  52. package/lib/exchange/swap/hooks/usePollKYCStatus.d.ts.map +1 -0
  53. package/lib/exchange/swap/hooks/usePollKYCStatus.js +105 -0
  54. package/lib/exchange/swap/hooks/usePollKYCStatus.js.map +1 -0
  55. package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts +2 -0
  56. package/lib/exchange/swap/hooks/usePollKYCStatus.test.d.ts.map +1 -0
  57. package/lib/exchange/swap/hooks/usePollKYCStatus.test.js +78 -0
  58. package/lib/exchange/swap/hooks/usePollKYCStatus.test.js.map +1 -0
  59. package/lib/exchange/swap/hooks/useProviderRates.d.ts +20 -0
  60. package/lib/exchange/swap/hooks/useProviderRates.d.ts.map +1 -0
  61. package/lib/exchange/swap/hooks/useProviderRates.js +174 -0
  62. package/lib/exchange/swap/hooks/useProviderRates.js.map +1 -0
  63. package/lib/exchange/swap/hooks/useProviderRates.test.d.ts +2 -0
  64. package/lib/exchange/swap/hooks/useProviderRates.test.d.ts.map +1 -0
  65. package/lib/exchange/swap/hooks/useProviderRates.test.js +261 -0
  66. package/lib/exchange/swap/hooks/useProviderRates.test.js.map +1 -0
  67. package/lib/exchange/swap/hooks/useReverseAccounts.d.ts +15 -0
  68. package/lib/exchange/swap/hooks/useReverseAccounts.d.ts.map +1 -0
  69. package/lib/exchange/swap/hooks/useReverseAccounts.js +35 -0
  70. package/lib/exchange/swap/hooks/useReverseAccounts.js.map +1 -0
  71. package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts +2 -0
  72. package/lib/exchange/swap/hooks/useReverseAccounts.test.d.ts.map +1 -0
  73. package/lib/exchange/swap/hooks/useReverseAccounts.test.js +79 -0
  74. package/lib/exchange/swap/hooks/useReverseAccounts.test.js.map +1 -0
  75. package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts +5 -0
  76. package/lib/exchange/swap/hooks/useSelectableCurrencies.d.ts.map +1 -0
  77. package/lib/exchange/swap/hooks/useSelectableCurrencies.js +43 -0
  78. package/lib/exchange/swap/hooks/useSelectableCurrencies.js.map +1 -0
  79. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts +2 -0
  80. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.d.ts.map +1 -0
  81. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js +32 -0
  82. package/lib/exchange/swap/hooks/useSelectableCurrencies.test.js.map +1 -0
  83. package/lib/exchange/swap/hooks/useSwapProviders.d.ts +14 -0
  84. package/lib/exchange/swap/hooks/useSwapProviders.d.ts.map +1 -0
  85. package/lib/exchange/swap/hooks/useSwapProviders.js +104 -0
  86. package/lib/exchange/swap/hooks/useSwapProviders.js.map +1 -0
  87. package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts +2 -0
  88. package/lib/exchange/swap/hooks/useSwapProviders.test.d.ts.map +1 -0
  89. package/lib/exchange/swap/hooks/useSwapProviders.test.js +174 -0
  90. package/lib/exchange/swap/hooks/useSwapProviders.test.js.map +1 -0
  91. package/lib/exchange/swap/hooks/useSwapTransaction.d.ts +53 -0
  92. package/lib/exchange/swap/hooks/useSwapTransaction.d.ts.map +1 -0
  93. package/lib/exchange/swap/hooks/useSwapTransaction.js +109 -0
  94. package/lib/exchange/swap/hooks/useSwapTransaction.js.map +1 -0
  95. package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts +2 -0
  96. package/lib/exchange/swap/hooks/useSwapTransaction.test.d.ts.map +1 -0
  97. package/lib/exchange/swap/hooks/useSwapTransaction.test.js +50 -0
  98. package/lib/exchange/swap/hooks/useSwapTransaction.test.js.map +1 -0
  99. package/lib/exchange/swap/hooks/useToState.d.ts +12 -0
  100. package/lib/exchange/swap/hooks/useToState.d.ts.map +1 -0
  101. package/lib/exchange/swap/hooks/useToState.js +73 -0
  102. package/lib/exchange/swap/hooks/useToState.js.map +1 -0
  103. package/lib/exchange/swap/hooks/useToState.test.d.ts +2 -0
  104. package/lib/exchange/swap/hooks/useToState.test.d.ts.map +1 -0
  105. package/lib/exchange/swap/hooks/useToState.test.js +107 -0
  106. package/lib/exchange/swap/hooks/useToState.test.js.map +1 -0
  107. package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts +15 -0
  108. package/lib/exchange/swap/hooks/useUpdateMaxAmount.d.ts.map +1 -0
  109. package/lib/{families/bitcoin/getAccountNetworkInfo.js → exchange/swap/hooks/useUpdateMaxAmount.js} +47 -65
  110. package/lib/exchange/swap/hooks/useUpdateMaxAmount.js.map +1 -0
  111. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts +2 -0
  112. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.d.ts.map +1 -0
  113. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js +217 -0
  114. package/lib/exchange/swap/hooks/useUpdateMaxAmount.test.js.map +1 -0
  115. package/lib/exchange/swap/mock.d.ts +6 -2
  116. package/lib/exchange/swap/mock.d.ts.map +1 -1
  117. package/lib/exchange/swap/mock.js +21 -6
  118. package/lib/exchange/swap/mock.js.map +1 -1
  119. package/lib/exchange/swap/types.d.ts +1 -1
  120. package/lib/exchange/swap/types.d.ts.map +1 -1
  121. package/lib/exchange/swap/utils/index.d.ts +16 -0
  122. package/lib/exchange/swap/utils/index.d.ts.map +1 -0
  123. package/lib/exchange/swap/utils/index.js +49 -0
  124. package/lib/exchange/swap/utils/index.js.map +1 -0
  125. package/lib/exchange/swap/utils/index.test.d.ts +2 -0
  126. package/lib/exchange/swap/utils/index.test.d.ts.map +1 -0
  127. package/lib/exchange/swap/utils/index.test.js +238 -0
  128. package/lib/exchange/swap/utils/index.test.js.map +1 -0
  129. package/lib/families/bitcoin/account.d.ts.map +1 -1
  130. package/lib/families/bitcoin/account.js +2 -3
  131. package/lib/families/bitcoin/account.js.map +1 -1
  132. package/lib/families/bitcoin/datasets/bitcoin.js +6 -6
  133. package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
  134. package/lib/families/bitcoin/datasets/litecoin.js +3 -3
  135. package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
  136. package/lib/families/bitcoin/serialization.d.ts +2 -2
  137. package/lib/families/bitcoin/serialization.d.ts.map +1 -1
  138. package/lib/families/bitcoin/serialization.js +4 -8
  139. package/lib/families/bitcoin/serialization.js.map +1 -1
  140. package/lib/families/bitcoin/specs.d.ts +1 -0
  141. package/lib/families/bitcoin/specs.d.ts.map +1 -1
  142. package/lib/families/bitcoin/specs.js +17 -8
  143. package/lib/families/bitcoin/specs.js.map +1 -1
  144. package/lib/families/bitcoin/speculos-deviceActions.js +2 -2
  145. package/lib/families/bitcoin/speculos-deviceActions.js.map +1 -1
  146. package/lib/families/bitcoin/test-dataset.js +1 -1
  147. package/lib/families/bitcoin/test-dataset.js.map +1 -1
  148. package/lib/families/bitcoin/transaction.d.ts +3 -3
  149. package/lib/families/bitcoin/transaction.d.ts.map +1 -1
  150. package/lib/families/bitcoin/transaction.js +61 -64
  151. package/lib/families/bitcoin/transaction.js.map +1 -1
  152. package/lib/families/bitcoin/types.d.ts +36 -66
  153. package/lib/families/bitcoin/types.d.ts.map +1 -1
  154. package/lib/families/bitcoin/types.js +1 -16
  155. package/lib/families/bitcoin/types.js.map +1 -1
  156. package/lib/families/crypto_org/datasets/croeseid.d.ts.map +1 -1
  157. package/lib/families/crypto_org/datasets/croeseid.js +2 -6
  158. package/lib/families/crypto_org/datasets/croeseid.js.map +1 -1
  159. package/lib/families/elrond/api/apiCalls.d.ts +0 -4
  160. package/lib/families/elrond/api/apiCalls.d.ts.map +1 -1
  161. package/lib/families/elrond/api/apiCalls.js +3 -37
  162. package/lib/families/elrond/api/apiCalls.js.map +1 -1
  163. package/lib/families/elrond/api/sdk.js +2 -2
  164. package/lib/families/elrond/api/sdk.js.map +1 -1
  165. package/lib/families/elrond/js-transaction.d.ts +2 -0
  166. package/lib/families/elrond/js-transaction.d.ts.map +1 -1
  167. package/lib/families/elrond/types.d.ts +2 -0
  168. package/lib/families/elrond/types.d.ts.map +1 -1
  169. package/lib/families/elrond/types.js.map +1 -1
  170. package/lib/families/tezos/bridge/js.js.map +1 -1
  171. package/lib/generated/bridge/js.d.ts +0 -4
  172. package/lib/generated/bridge/js.d.ts.map +1 -1
  173. package/lib/generated/bridge/js.js +18 -20
  174. package/lib/generated/bridge/js.js.map +1 -1
  175. package/lib/generated/specs.d.ts +1 -0
  176. package/lib/generated/specs.d.ts.map +1 -1
  177. package/lib/migrations/accounts-dataset.d.ts.map +1 -1
  178. package/lib/migrations/accounts-dataset.js +2 -4
  179. package/lib/migrations/accounts-dataset.js.map +1 -1
  180. package/lib/migrations/accounts.d.ts.map +1 -1
  181. package/lib/migrations/accounts.js +0 -17
  182. package/lib/migrations/accounts.js.map +1 -1
  183. package/lib/mock/account.d.ts +2 -1
  184. package/lib/mock/account.d.ts.map +1 -1
  185. package/lib/mock/account.js +5 -4
  186. package/lib/mock/account.js.map +1 -1
  187. package/package.json +12 -13
  188. package/src/.DS_Store +0 -0
  189. package/src/__tests__/.DS_Store +0 -0
  190. package/src/__tests__/__snapshots__/.DS_Store +0 -0
  191. package/src/__tests__/__snapshots__/all.libcore.ts.snap +10 -10
  192. package/src/account/addAccounts.ts +1 -2
  193. package/src/account/support.ts +1 -24
  194. package/src/api/explorerConfig/index.ts +15 -15
  195. package/src/bot/index.ts +3 -8
  196. package/src/bot/test.bot.ts +1 -6
  197. package/src/bridge/jsHelpers.ts +2 -22
  198. package/src/env.ts +1 -1
  199. package/src/exchange/swap/getExchangeRates.ts +8 -5
  200. package/src/exchange/swap/hooks/index.ts +10 -0
  201. package/src/exchange/swap/hooks/useFromState.test.ts +134 -0
  202. package/src/exchange/swap/hooks/useFromState.ts +84 -0
  203. package/src/exchange/swap/hooks/usePickDefaultAccount.test.ts +167 -0
  204. package/src/exchange/swap/hooks/usePickDefaultAccount.ts +47 -0
  205. package/src/exchange/swap/hooks/usePickDefaultCurrency.test.ts +107 -0
  206. package/src/exchange/swap/hooks/usePickDefaultCurrency.ts +20 -0
  207. package/src/exchange/swap/hooks/usePollKYCStatus.test.ts +89 -0
  208. package/src/exchange/swap/hooks/usePollKYCStatus.ts +43 -0
  209. package/src/exchange/swap/hooks/useProviderRates.test.ts +200 -0
  210. package/src/exchange/swap/hooks/useProviderRates.ts +130 -0
  211. package/src/exchange/swap/hooks/useReverseAccounts.test.ts +83 -0
  212. package/src/exchange/swap/hooks/useReverseAccounts.ts +56 -0
  213. package/src/exchange/swap/hooks/useSelectableCurrencies.test.ts +39 -0
  214. package/src/exchange/swap/hooks/useSelectableCurrencies.ts +26 -0
  215. package/src/exchange/swap/hooks/useSwapProviders.test.ts +113 -0
  216. package/src/exchange/swap/hooks/useSwapProviders.ts +57 -0
  217. package/src/exchange/swap/hooks/useSwapTransaction.test.ts +54 -0
  218. package/src/exchange/swap/hooks/useSwapTransaction.ts +170 -0
  219. package/src/exchange/swap/hooks/useToState.test.ts +53 -0
  220. package/src/exchange/swap/hooks/useToState.ts +86 -0
  221. package/src/exchange/swap/hooks/useUpdateMaxAmount.test.ts +132 -0
  222. package/src/exchange/swap/hooks/useUpdateMaxAmount.ts +67 -0
  223. package/src/exchange/swap/mock.ts +22 -3
  224. package/src/exchange/swap/types.ts +2 -1
  225. package/src/exchange/swap/utils/index.test.ts +224 -0
  226. package/src/exchange/swap/utils/index.ts +67 -0
  227. package/src/families/bitcoin/account.ts +1 -2
  228. package/src/families/bitcoin/datasets/bitcoin.ts +6 -6
  229. package/src/families/bitcoin/datasets/litecoin.ts +6 -6
  230. package/src/families/bitcoin/serialization.ts +0 -6
  231. package/src/families/bitcoin/specs.ts +14 -5
  232. package/src/families/bitcoin/speculos-deviceActions.ts +1 -1
  233. package/src/families/bitcoin/test-dataset.ts +1 -1
  234. package/src/families/bitcoin/transaction.ts +93 -98
  235. package/src/families/bitcoin/types.ts +37 -95
  236. package/src/families/crypto_org/datasets/croeseid.ts +7 -9
  237. package/src/families/elrond/api/apiCalls.ts +3 -31
  238. package/src/families/elrond/api/sdk.ts +2 -2
  239. package/src/families/elrond/types.ts +2 -0
  240. package/src/families/tezos/bridge/js.ts +1 -1
  241. package/src/generated/bridge/js.ts +0 -3
  242. package/src/migrations/accounts-dataset.ts +0 -3
  243. package/src/migrations/accounts.ts +0 -18
  244. package/src/mock/account.ts +2 -4
  245. package/lib/__tests__/families/bitcoin/logic.d.ts +0 -2
  246. package/lib/__tests__/families/bitcoin/logic.d.ts.map +0 -1
  247. package/lib/__tests__/families/bitcoin/logic.js +0 -39
  248. package/lib/__tests__/families/bitcoin/logic.js.map +0 -1
  249. package/lib/families/bitcoin/bridge/js.d.ts +0 -8
  250. package/lib/families/bitcoin/bridge/js.d.ts.map +0 -1
  251. package/lib/families/bitcoin/bridge/js.js +0 -149
  252. package/lib/families/bitcoin/bridge/js.js.map +0 -1
  253. package/lib/families/bitcoin/cache.d.ts +0 -28
  254. package/lib/families/bitcoin/cache.d.ts.map +0 -1
  255. package/lib/families/bitcoin/cache.js +0 -109
  256. package/lib/families/bitcoin/cache.js.map +0 -1
  257. package/lib/families/bitcoin/getAccountNetworkInfo.d.ts +0 -6
  258. package/lib/families/bitcoin/getAccountNetworkInfo.d.ts.map +0 -1
  259. package/lib/families/bitcoin/getAccountNetworkInfo.js.map +0 -1
  260. package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts +0 -2
  261. package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts.map +0 -1
  262. package/lib/families/bitcoin/getAccountNetworkInfo.test.js +0 -71
  263. package/lib/families/bitcoin/getAccountNetworkInfo.test.js.map +0 -1
  264. package/lib/families/bitcoin/js-broadcast.d.ts +0 -11
  265. package/lib/families/bitcoin/js-broadcast.d.ts.map +0 -1
  266. package/lib/families/bitcoin/js-broadcast.js +0 -80
  267. package/lib/families/bitcoin/js-broadcast.js.map +0 -1
  268. package/lib/families/bitcoin/js-buildTransaction.d.ts +0 -5
  269. package/lib/families/bitcoin/js-buildTransaction.d.ts.map +0 -1
  270. package/lib/families/bitcoin/js-buildTransaction.js +0 -106
  271. package/lib/families/bitcoin/js-buildTransaction.js.map +0 -1
  272. package/lib/families/bitcoin/js-createTransaction.d.ts +0 -9
  273. package/lib/families/bitcoin/js-createTransaction.d.ts.map +0 -1
  274. package/lib/families/bitcoin/js-createTransaction.js +0 -27
  275. package/lib/families/bitcoin/js-createTransaction.js.map +0 -1
  276. package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts +0 -15
  277. package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts.map +0 -1
  278. package/lib/families/bitcoin/js-estimateMaxSpendable.js +0 -95
  279. package/lib/families/bitcoin/js-estimateMaxSpendable.js.map +0 -1
  280. package/lib/families/bitcoin/js-getFeesForTransaction.d.ts +0 -26
  281. package/lib/families/bitcoin/js-getFeesForTransaction.d.ts.map +0 -1
  282. package/lib/families/bitcoin/js-getFeesForTransaction.js +0 -100
  283. package/lib/families/bitcoin/js-getFeesForTransaction.js.map +0 -1
  284. package/lib/families/bitcoin/js-getTransactionStatus.d.ts +0 -5
  285. package/lib/families/bitcoin/js-getTransactionStatus.d.ts.map +0 -1
  286. package/lib/families/bitcoin/js-getTransactionStatus.js +0 -131
  287. package/lib/families/bitcoin/js-getTransactionStatus.js.map +0 -1
  288. package/lib/families/bitcoin/js-prepareTransaction.d.ts +0 -5
  289. package/lib/families/bitcoin/js-prepareTransaction.d.ts.map +0 -1
  290. package/lib/families/bitcoin/js-prepareTransaction.js +0 -80
  291. package/lib/families/bitcoin/js-prepareTransaction.js.map +0 -1
  292. package/lib/families/bitcoin/js-signOperation.d.ts +0 -10
  293. package/lib/families/bitcoin/js-signOperation.d.ts.map +0 -1
  294. package/lib/families/bitcoin/js-signOperation.js +0 -212
  295. package/lib/families/bitcoin/js-signOperation.js.map +0 -1
  296. package/lib/families/bitcoin/js-synchronisation.d.ts +0 -10
  297. package/lib/families/bitcoin/js-synchronisation.d.ts.map +0 -1
  298. package/lib/families/bitcoin/js-synchronisation.js +0 -411
  299. package/lib/families/bitcoin/js-synchronisation.js.map +0 -1
  300. package/lib/families/bitcoin/logic.d.ts +0 -34
  301. package/lib/families/bitcoin/logic.d.ts.map +0 -1
  302. package/lib/families/bitcoin/logic.js +0 -292
  303. package/lib/families/bitcoin/logic.js.map +0 -1
  304. package/lib/families/bitcoin/networks.d.ts +0 -3
  305. package/lib/families/bitcoin/networks.d.ts.map +0 -1
  306. package/lib/families/bitcoin/networks.js +0 -379
  307. package/lib/families/bitcoin/networks.js.map +0 -1
  308. package/lib/families/bitcoin/wallet.d.ts +0 -6
  309. package/lib/families/bitcoin/wallet.d.ts.map +0 -1
  310. package/lib/families/bitcoin/wallet.js +0 -66
  311. package/lib/families/bitcoin/wallet.js.map +0 -1
  312. package/src/__tests__/families/bitcoin/logic.ts +0 -40
  313. package/src/families/bitcoin/bridge/js.ts +0 -76
  314. package/src/families/bitcoin/cache.ts +0 -76
  315. package/src/families/bitcoin/getAccountNetworkInfo.test.ts +0 -27
  316. package/src/families/bitcoin/getAccountNetworkInfo.ts +0 -61
  317. package/src/families/bitcoin/js-broadcast.ts +0 -30
  318. package/src/families/bitcoin/js-buildTransaction.ts +0 -57
  319. package/src/families/bitcoin/js-createTransaction.ts +0 -27
  320. package/src/families/bitcoin/js-estimateMaxSpendable.ts +0 -36
  321. package/src/families/bitcoin/js-getFeesForTransaction.ts +0 -59
  322. package/src/families/bitcoin/js-getTransactionStatus.ts +0 -118
  323. package/src/families/bitcoin/js-prepareTransaction.ts +0 -35
  324. package/src/families/bitcoin/js-signOperation.ts +0 -164
  325. package/src/families/bitcoin/js-synchronisation.ts +0 -362
  326. package/src/families/bitcoin/logic.ts +0 -253
  327. package/src/families/bitcoin/networks.ts +0 -360
  328. package/src/families/bitcoin/wallet.ts +0 -21
@@ -0,0 +1,134 @@
1
+ import { getCryptoCurrencyById, getTokenById } from "@ledgerhq/cryptoassets";
2
+ import { renderHook, act } from "@testing-library/react-hooks";
3
+ import BigNumber from "bignumber.js";
4
+ import { selectorStateDefaultValues } from ".";
5
+ import useBridgeTransaction from "../../../bridge/useBridgeTransaction";
6
+ import { genAccount, genTokenAccount } from "../../../mock/account";
7
+ import { Account } from "../../../types";
8
+ import { useFromState } from "./useFromState";
9
+
10
+ const BTC = getCryptoCurrencyById("bitcoin");
11
+ const ETH = getCryptoCurrencyById("ethereum");
12
+ const USDT = getTokenById("ethereum/erc20/usd_tether__erc20_");
13
+
14
+ const mockedAccounts: Account[] = [
15
+ genAccount("mocked-account-1"),
16
+ genAccount("mocked-account-2", {
17
+ currency: ETH,
18
+ }),
19
+ ];
20
+ const mockedTokenAccount = genTokenAccount(1, mockedAccounts[1], USDT);
21
+ const allAccounts = [...mockedAccounts, mockedTokenAccount] as Account[];
22
+
23
+ describe("useFromState", () => {
24
+ test("call hook without arguments", () => {
25
+ const { result } = renderHook(() => {
26
+ const bridgeTransaction = useBridgeTransaction();
27
+ return useFromState({
28
+ bridgeTransaction,
29
+ });
30
+ });
31
+ expect(result.current).toMatchObject({
32
+ fromState: selectorStateDefaultValues,
33
+ });
34
+ });
35
+
36
+ test("call hook with default currency", () => {
37
+ const defaultCurrency = BTC;
38
+
39
+ const { result } = renderHook(() => {
40
+ const bridgeTransaction = useBridgeTransaction();
41
+ return useFromState({
42
+ defaultCurrency,
43
+ bridgeTransaction,
44
+ });
45
+ });
46
+ expect(result.current).toMatchObject({
47
+ fromState: {
48
+ ...selectorStateDefaultValues,
49
+ currency: defaultCurrency,
50
+ },
51
+ });
52
+ });
53
+
54
+ test("call hook with default accounts", () => {
55
+ const defaultAccount = mockedTokenAccount;
56
+ const defaultParentAccount = mockedAccounts[1];
57
+
58
+ const { result } = renderHook(() => {
59
+ const bridgeTransaction = useBridgeTransaction();
60
+ return useFromState({
61
+ defaultAccount,
62
+ defaultParentAccount,
63
+ bridgeTransaction,
64
+ });
65
+ });
66
+ expect(result.current).toMatchObject({
67
+ fromState: {
68
+ ...selectorStateDefaultValues,
69
+ account: defaultAccount,
70
+ parentAccount: defaultParentAccount,
71
+ },
72
+ });
73
+ });
74
+
75
+ test("call hook and set the account and all the related properties", () => {
76
+ const { result } = renderHook(() => {
77
+ const bridgeTransaction = useBridgeTransaction();
78
+ return {
79
+ ...useFromState({
80
+ accounts: allAccounts,
81
+ bridgeTransaction,
82
+ }),
83
+ bridgeTransaction,
84
+ };
85
+ });
86
+
87
+ expect(result.current).toMatchObject({
88
+ fromState: selectorStateDefaultValues,
89
+ });
90
+
91
+ act(() => {
92
+ result.current.setFromAccount(mockedTokenAccount);
93
+ });
94
+
95
+ expect(result.current).toMatchObject({
96
+ fromState: {
97
+ ...selectorStateDefaultValues,
98
+ account: mockedTokenAccount,
99
+ parentAccount: mockedAccounts[1],
100
+ currency: USDT,
101
+ },
102
+ });
103
+
104
+ expect(result.current.bridgeTransaction).toMatchObject({
105
+ account: mockedTokenAccount,
106
+ parentAccount: mockedAccounts[1],
107
+ });
108
+ });
109
+
110
+ test("call hook and set the amount", () => {
111
+ const { result } = renderHook(() => {
112
+ const bridgeTransaction = useBridgeTransaction();
113
+ return useFromState({
114
+ accounts: allAccounts,
115
+ bridgeTransaction,
116
+ });
117
+ });
118
+
119
+ expect(result.current).toMatchObject({
120
+ fromState: selectorStateDefaultValues,
121
+ });
122
+
123
+ act(() => {
124
+ result.current.setFromAmount(new BigNumber(10));
125
+ });
126
+
127
+ expect(result.current).toMatchObject({
128
+ fromState: {
129
+ ...selectorStateDefaultValues,
130
+ amount: new BigNumber(10),
131
+ },
132
+ });
133
+ });
134
+ });
@@ -0,0 +1,84 @@
1
+ import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets";
2
+ import { useCallback, useState } from "react";
3
+ import {
4
+ selectorStateDefaultValues,
5
+ SwapSelectorStateType,
6
+ SwapTransactionType,
7
+ } from ".";
8
+ import { getAccountCurrency, getMainAccount } from "../../../account";
9
+ import { Account, AccountLike } from "../../../types";
10
+ import { Result as UseBridgeTransactionReturnType } from "../../../bridge/useBridgeTransaction";
11
+
12
+ export const useFromState = ({
13
+ accounts,
14
+ defaultCurrency,
15
+ defaultAccount,
16
+ defaultParentAccount,
17
+ bridgeTransaction,
18
+ }: {
19
+ accounts?: Account[];
20
+ defaultCurrency?: SwapSelectorStateType["currency"];
21
+ defaultAccount?: SwapSelectorStateType["account"];
22
+ defaultParentAccount?: SwapSelectorStateType["parentAccount"];
23
+ bridgeTransaction: UseBridgeTransactionReturnType;
24
+ }): {
25
+ fromState: SwapSelectorStateType;
26
+ setFromAccount: SwapTransactionType["setFromAccount"];
27
+ setFromAmount: SwapTransactionType["setFromAmount"];
28
+ } => {
29
+ const [fromState, setFromState] = useState<SwapSelectorStateType>({
30
+ ...selectorStateDefaultValues,
31
+ currency: defaultCurrency ?? selectorStateDefaultValues.currency,
32
+ account: defaultAccount ?? selectorStateDefaultValues.account,
33
+ parentAccount:
34
+ defaultParentAccount ?? selectorStateDefaultValues.parentAccount,
35
+ });
36
+
37
+ /* UPDATE from account */
38
+ const setFromAccount: SwapTransactionType["setFromAccount"] = useCallback(
39
+ (account) => {
40
+ const parentAccount =
41
+ account?.type !== "Account"
42
+ ? accounts?.find((a) => a.id === account?.parentId)
43
+ : null;
44
+ const currency = getAccountCurrency(account as AccountLike);
45
+
46
+ bridgeTransaction.setAccount(account as AccountLike, parentAccount);
47
+ setFromState({
48
+ ...selectorStateDefaultValues,
49
+ currency,
50
+ account,
51
+ parentAccount,
52
+ });
53
+
54
+ /* @DEV: That populates fake seed. This is required to use Transaction object */
55
+ const mainAccount = getMainAccount(account as AccountLike, parentAccount);
56
+ const mainCurrency = getAccountCurrency(mainAccount);
57
+ const recipient = getAbandonSeedAddress(mainCurrency.id);
58
+ bridgeTransaction.updateTransaction((transaction) => ({
59
+ ...transaction,
60
+ recipient,
61
+ }));
62
+ },
63
+ // eslint-disable-next-line react-hooks/exhaustive-deps
64
+ [accounts, bridgeTransaction.updateTransaction]
65
+ );
66
+
67
+ const setFromAmount: SwapTransactionType["setFromAmount"] = useCallback(
68
+ (amount) => {
69
+ bridgeTransaction.updateTransaction((transaction) => ({
70
+ ...transaction,
71
+ amount,
72
+ }));
73
+ setFromState((previousState) => ({ ...previousState, amount: amount }));
74
+ },
75
+ // eslint-disable-next-line react-hooks/exhaustive-deps
76
+ [bridgeTransaction.updateTransaction]
77
+ );
78
+
79
+ return {
80
+ fromState,
81
+ setFromAccount,
82
+ setFromAmount,
83
+ };
84
+ };
@@ -0,0 +1,167 @@
1
+ import { renderHook } from "@testing-library/react-hooks";
2
+ import BigNumber from "bignumber.js";
3
+
4
+ import { usePickDefaultAccount } from "./usePickDefaultAccount";
5
+ import { genAccount } from "../../../mock/account";
6
+ import type { Account, CryptoCurrency } from "../../../types";
7
+ import { getCryptoCurrencyById } from "../../../currencies";
8
+
9
+ function* accountGenerator(currency: CryptoCurrency): Generator<Account> {
10
+ let id = 0;
11
+ while (true) {
12
+ id += 1;
13
+ // operations are not taken into account by the usePickDefaultAccount hooks
14
+ yield genAccount(`mocked-account-${id}`, { currency, operationsSize: 0 });
15
+ }
16
+ }
17
+
18
+ const getAccountCreator = (currencyId: string) => {
19
+ const generator = accountGenerator(getCryptoCurrencyById(currencyId));
20
+ return () => generator.next().value;
21
+ };
22
+
23
+ describe("usePickDefaultAccount", () => {
24
+ const getEthAccount = getAccountCreator("ethereum");
25
+ const getBtcAccount = getAccountCreator("bitcoin");
26
+ const getPolkadotAccount = getAccountCreator("polkadot");
27
+ const getCosmosAccount = getAccountCreator("cosmos");
28
+ const setFromAccount = jest.fn();
29
+
30
+ beforeEach(() => {
31
+ setFromAccount.mockClear();
32
+ });
33
+
34
+ test("do nothing when fromAccount is not null/undefined", () => {
35
+ const accounts: Account[] = [getEthAccount(), getBtcAccount()];
36
+
37
+ renderHook(() =>
38
+ usePickDefaultAccount(accounts, getEthAccount(), setFromAccount)
39
+ );
40
+
41
+ expect(setFromAccount).toHaveBeenCalledTimes(0);
42
+ });
43
+
44
+ test("do nothing when all passed accounts are disabled", () => {
45
+ const accounts: Account[] = [
46
+ { ...getEthAccount(), disabled: true },
47
+ { ...getBtcAccount(), disabled: true },
48
+ { ...getEthAccount(), disabled: true },
49
+ { ...getEthAccount(), disabled: true },
50
+ ];
51
+
52
+ renderHook(() =>
53
+ usePickDefaultAccount(accounts, undefined, setFromAccount)
54
+ );
55
+
56
+ expect(setFromAccount).toHaveBeenCalledTimes(0);
57
+ });
58
+
59
+ test("returns an ethereum account when it's available", () => {
60
+ const ethAccount = getEthAccount();
61
+
62
+ const accounts: Account[] = [ethAccount, getBtcAccount()];
63
+
64
+ renderHook(() =>
65
+ usePickDefaultAccount(accounts, undefined, setFromAccount)
66
+ );
67
+
68
+ expect(setFromAccount).toHaveBeenCalledTimes(1);
69
+ expect(setFromAccount).toHaveBeenCalledWith(ethAccount);
70
+ });
71
+
72
+ test("returns the first ethereum account when all of the enabled accounts have the same balance", () => {
73
+ const ethAccount = getEthAccount();
74
+
75
+ const accounts: Account[] = [
76
+ ethAccount,
77
+ getBtcAccount(),
78
+ getEthAccount(),
79
+ { ...getEthAccount(), disabled: true },
80
+ ];
81
+
82
+ renderHook(() =>
83
+ usePickDefaultAccount(accounts, undefined, setFromAccount)
84
+ );
85
+
86
+ expect(setFromAccount).toHaveBeenCalledTimes(1);
87
+ expect(setFromAccount).toHaveBeenCalledWith(ethAccount);
88
+ });
89
+
90
+ test("returns the ethereum enabled account with the highest balance", () => {
91
+ const ethAccount = getEthAccount();
92
+ const ethAccount2 = getEthAccount();
93
+
94
+ ethAccount.amount = new BigNumber(1000);
95
+ ethAccount2.amount = new BigNumber(0);
96
+
97
+ const accounts: Account[] = [
98
+ { ...getEthAccount(), disabled: true },
99
+ ethAccount,
100
+ getBtcAccount(),
101
+ ethAccount2,
102
+ ];
103
+
104
+ renderHook(() =>
105
+ usePickDefaultAccount(accounts, undefined, setFromAccount)
106
+ );
107
+
108
+ expect(setFromAccount).toHaveBeenCalledTimes(1);
109
+ expect(setFromAccount).toHaveBeenCalledWith(ethAccount);
110
+ });
111
+
112
+ test("returns the first bitcoin account when no ethereum accounts are passed/enabled and all btc accounts have the same balance", () => {
113
+ const BtcAccount = getBtcAccount();
114
+
115
+ const accounts: Account[] = [
116
+ { ...getEthAccount(), disabled: true },
117
+ BtcAccount,
118
+ getBtcAccount(),
119
+ ];
120
+
121
+ renderHook(() =>
122
+ usePickDefaultAccount(accounts, undefined, setFromAccount)
123
+ );
124
+
125
+ expect(setFromAccount).toHaveBeenCalledTimes(1);
126
+ expect(setFromAccount).toHaveBeenCalledWith(BtcAccount);
127
+ });
128
+
129
+ test("returns the bitcoin enabled account with the highest balance when no ETH accounts are passed", () => {
130
+ const btcAccount = getBtcAccount();
131
+ const btcAccount2 = getBtcAccount();
132
+
133
+ btcAccount.amount = new BigNumber(1000);
134
+ btcAccount2.amount = new BigNumber(0);
135
+
136
+ const accounts: Account[] = [
137
+ { ...getEthAccount(), disabled: true },
138
+ btcAccount,
139
+ btcAccount2,
140
+ ];
141
+
142
+ renderHook(() =>
143
+ usePickDefaultAccount(accounts, undefined, setFromAccount)
144
+ );
145
+
146
+ expect(setFromAccount).toHaveBeenCalledTimes(1);
147
+ expect(setFromAccount).toHaveBeenCalledWith(btcAccount);
148
+ });
149
+
150
+ test("returns the first enabled account when no ethereum/bitcoin accounts are passed", () => {
151
+ const dotAccount = getPolkadotAccount();
152
+
153
+ const accounts: Account[] = [
154
+ { ...getCosmosAccount(), disabled: true },
155
+ dotAccount,
156
+ getPolkadotAccount(),
157
+ getCosmosAccount(),
158
+ ];
159
+
160
+ renderHook(() =>
161
+ usePickDefaultAccount(accounts, undefined, setFromAccount)
162
+ );
163
+
164
+ expect(setFromAccount).toHaveBeenCalledTimes(1);
165
+ expect(setFromAccount).toHaveBeenCalledWith(dotAccount);
166
+ });
167
+ });
@@ -0,0 +1,47 @@
1
+ import { useEffect } from "react";
2
+ import { Account, TokenAccount } from "../../../types";
3
+
4
+ // Pick a default source account if none are selected.
5
+ export const usePickDefaultAccount = (
6
+ accounts: ((Account | TokenAccount) & { disabled?: boolean })[],
7
+ fromAccount: Account | TokenAccount | null | undefined,
8
+ setFromAccount: (account: Account | TokenAccount) => void
9
+ ): void => {
10
+ useEffect(() => {
11
+ if (!fromAccount) {
12
+ const possibleDefaults = accounts.reduce<
13
+ [
14
+ Account | TokenAccount | undefined | null,
15
+ Account | TokenAccount | undefined | null,
16
+ Account | TokenAccount | undefined | null
17
+ ]
18
+ >(
19
+ (acc, account) => {
20
+ if (account.disabled) return acc;
21
+ if (
22
+ // eventually needs a type guard because the "currency" property does not exist in TokenAccount
23
+ account["currency"]?.id === "ethereum" &&
24
+ (acc[0]?.balance ?? -1) < account.balance
25
+ ) {
26
+ acc[0] = account;
27
+ }
28
+ if (
29
+ // eventually needs a type guard because the "currency" property does not exist in TokenAccount
30
+ account["currency"]?.id === "bitcoin" &&
31
+ (acc[1]?.balance ?? -1) < account.balance
32
+ ) {
33
+ acc[1] = account;
34
+ }
35
+ const maxFundsAccount = acc[2];
36
+ if (!maxFundsAccount || maxFundsAccount.balance < account.balance) {
37
+ acc[2] = account;
38
+ }
39
+ return acc;
40
+ },
41
+ [null, null, null]
42
+ );
43
+ const defaultAccount = possibleDefaults.find(Boolean);
44
+ defaultAccount && setFromAccount(defaultAccount);
45
+ }
46
+ }, [accounts, fromAccount, setFromAccount]);
47
+ };
@@ -0,0 +1,107 @@
1
+ import { renderHook } from "@testing-library/react-hooks";
2
+
3
+ import { usePickDefaultCurrency } from "./usePickDefaultCurrency";
4
+ import { getCryptoCurrencyById } from "../../../currencies";
5
+ import { CryptoCurrency, TokenCurrency } from "../../../types";
6
+
7
+ describe("usePickDefaultCurrency", () => {
8
+ const setCurrency = jest.fn();
9
+
10
+ beforeEach(() => {
11
+ setCurrency.mockClear();
12
+ });
13
+
14
+ test("do nothing when the passed currency is valid", () => {
15
+ const currencies: (CryptoCurrency | TokenCurrency)[] = [
16
+ getCryptoCurrencyById("ethereum"),
17
+ getCryptoCurrencyById("bitcoin"),
18
+ getCryptoCurrencyById("bsc"),
19
+ ];
20
+
21
+ renderHook(() =>
22
+ usePickDefaultCurrency(
23
+ currencies,
24
+ getCryptoCurrencyById("ethereum"),
25
+ setCurrency
26
+ )
27
+ );
28
+
29
+ expect(setCurrency).toHaveBeenCalledTimes(0);
30
+ });
31
+
32
+ test("do nothing if the currency is undefined/null and the currencies list don't include eth/btc", () => {
33
+ const currencies: (CryptoCurrency | TokenCurrency)[] = [
34
+ getCryptoCurrencyById("solana"),
35
+ getCryptoCurrencyById("polkadot"),
36
+ getCryptoCurrencyById("bsc"),
37
+ ];
38
+
39
+ renderHook(() =>
40
+ usePickDefaultCurrency(currencies, undefined, setCurrency)
41
+ );
42
+
43
+ expect(setCurrency).toHaveBeenCalledTimes(0);
44
+ });
45
+
46
+ test("do nothing if the currency passed isn't valid in the list and the currencies list don't include eth/btc", () => {
47
+ const currencies: (CryptoCurrency | TokenCurrency)[] = [
48
+ getCryptoCurrencyById("solana"),
49
+ getCryptoCurrencyById("polkadot"),
50
+ getCryptoCurrencyById("bsc"),
51
+ ];
52
+
53
+ renderHook(() =>
54
+ usePickDefaultCurrency(
55
+ currencies,
56
+ getCryptoCurrencyById("stellar"),
57
+ setCurrency
58
+ )
59
+ );
60
+
61
+ expect(setCurrency).toHaveBeenCalledTimes(0);
62
+ });
63
+
64
+ test("returns the ethereum currency if the passed currency isn't valid and ethereum comes before bitcoin in the list", () => {
65
+ const ethereumCurrency = getCryptoCurrencyById("ethereum");
66
+
67
+ const currencies: (CryptoCurrency | TokenCurrency)[] = [
68
+ getCryptoCurrencyById("bsc"),
69
+ ethereumCurrency,
70
+ getCryptoCurrencyById("bitcoin"),
71
+ getCryptoCurrencyById("polkadot"),
72
+ ];
73
+
74
+ renderHook(() =>
75
+ usePickDefaultCurrency(
76
+ currencies,
77
+ getCryptoCurrencyById("stellar"),
78
+ setCurrency
79
+ )
80
+ );
81
+
82
+ expect(setCurrency).toHaveBeenCalledTimes(1);
83
+ expect(setCurrency).toHaveBeenCalledWith(ethereumCurrency);
84
+ });
85
+
86
+ test("returns the bitcoin currency if the passed currency isn't valid and bitcoin comes before ethereum in the list", () => {
87
+ const bitcoinCurrency = getCryptoCurrencyById("bitcoin");
88
+
89
+ const currencies: (CryptoCurrency | TokenCurrency)[] = [
90
+ getCryptoCurrencyById("bsc"),
91
+ bitcoinCurrency,
92
+ getCryptoCurrencyById("ethereum"),
93
+ getCryptoCurrencyById("polkadot"),
94
+ ];
95
+
96
+ renderHook(() =>
97
+ usePickDefaultCurrency(
98
+ currencies,
99
+ getCryptoCurrencyById("stellar"),
100
+ setCurrency
101
+ )
102
+ );
103
+
104
+ expect(setCurrency).toHaveBeenCalledTimes(1);
105
+ expect(setCurrency).toHaveBeenCalledWith(bitcoinCurrency);
106
+ });
107
+ });
@@ -0,0 +1,20 @@
1
+ import { useEffect } from "react";
2
+ import { CryptoCurrency, TokenCurrency } from "../../../types";
3
+
4
+ // Pick a default currency target if none are selected.
5
+ export const usePickDefaultCurrency = (
6
+ currencies: (CryptoCurrency | TokenCurrency)[],
7
+ currency: (CryptoCurrency | TokenCurrency) | null | undefined,
8
+ setCurrency: (currency: CryptoCurrency | TokenCurrency) => void
9
+ ): void => {
10
+ useEffect(() => {
11
+ // Keep the same currency target if it is still valid.
12
+ const isCurrencyValid = currency && currencies.indexOf(currency) >= 0;
13
+ if (!currency || !isCurrencyValid) {
14
+ const defaultCurrency = currencies.find(
15
+ (currency) => currency.id === "ethereum" || currency.id === "bitcoin"
16
+ );
17
+ defaultCurrency && setCurrency(defaultCurrency);
18
+ }
19
+ }, [currency, currencies, setCurrency]);
20
+ };
@@ -0,0 +1,89 @@
1
+ import { renderHook } from "@testing-library/react-hooks";
2
+ import { mocked } from "ts-jest/utils";
3
+
4
+ import {
5
+ usePollKYCStatus,
6
+ KYC_STATUS_POLLING_INTERVAL,
7
+ } from "./usePollKYCStatus";
8
+ import type { UsePollKYCStatusProps } from "./usePollKYCStatus";
9
+ import { KYC_STATUS } from "../utils";
10
+ import { getKYCStatus } from "..";
11
+ import { KYCStatus } from "../types";
12
+
13
+ // mock getKYCStatus
14
+ jest.mock("..");
15
+ const mockedGetKYCStatus = mocked(getKYCStatus, true);
16
+
17
+ describe("usePollKYCStatus", () => {
18
+ const defaultInput: UsePollKYCStatusProps = {
19
+ provider: "changelly",
20
+ kyc: { id: "1", status: KYC_STATUS.pending },
21
+ onChange: () => {},
22
+ };
23
+
24
+ beforeEach(() => {
25
+ mockedGetKYCStatus.mockReset();
26
+ jest.useFakeTimers();
27
+ });
28
+
29
+ afterEach(() => {
30
+ jest.runOnlyPendingTimers();
31
+ jest.useRealTimers();
32
+ });
33
+
34
+ test("KYC status isn't fetched when the local status isn't PENDING", () => {
35
+ Object.values(KYC_STATUS)
36
+ .filter((status) => status !== "pending")
37
+ .forEach((status) => {
38
+ const input = { ...defaultInput, kyc: { id: "1", status } };
39
+ renderHook(() => usePollKYCStatus(input));
40
+ expect(mockedGetKYCStatus).toHaveBeenCalledTimes(0);
41
+ });
42
+ });
43
+
44
+ test("onChange isn't triggered when the local/remote status are equals", () => {
45
+ const onChange = jest.fn();
46
+ const input = { ...defaultInput, onChange };
47
+
48
+ const fetchedValue: KYCStatus = { status: "pending", id: "1" };
49
+ mockedGetKYCStatus.mockResolvedValueOnce(fetchedValue);
50
+
51
+ renderHook(() => usePollKYCStatus(input));
52
+ expect(mockedGetKYCStatus).toHaveBeenCalledTimes(1);
53
+ expect(mockedGetKYCStatus).toHaveBeenCalledWith(
54
+ input.provider,
55
+ input.kyc.id
56
+ );
57
+ expect(onChange).toHaveBeenCalledTimes(0);
58
+ });
59
+
60
+ test("onChange is triggered when the local/remote status are different", () => {
61
+ const onChange = jest.fn();
62
+ const input = { ...defaultInput, onChange };
63
+
64
+ const fetchedValue: KYCStatus = { status: "approved", id: "1" };
65
+ mockedGetKYCStatus.mockResolvedValueOnce(fetchedValue);
66
+
67
+ const { waitFor } = renderHook(() => usePollKYCStatus(input));
68
+ expect(mockedGetKYCStatus).toHaveBeenCalledTimes(1);
69
+ waitFor(() => expect(onChange).toHaveBeenCalledTimes(1));
70
+ });
71
+
72
+ test("setInterval retriggers the updateKYCStatus function", () => {
73
+ const onChange = jest.fn();
74
+ const input = { ...defaultInput, onChange };
75
+
76
+ const fetchedValue: KYCStatus = { status: "approved", id: "1" };
77
+ mockedGetKYCStatus.mockResolvedValue(fetchedValue);
78
+
79
+ const { waitFor } = renderHook(() => usePollKYCStatus(input));
80
+ waitFor(() => expect(onChange).toHaveBeenCalledTimes(1));
81
+ waitFor(() => expect(mockedGetKYCStatus).toHaveBeenCalledTimes(1));
82
+
83
+ // manually trigger the setInterval
84
+ jest.advanceTimersByTime(KYC_STATUS_POLLING_INTERVAL);
85
+
86
+ waitFor(() => expect(onChange).toHaveBeenCalledTimes(2));
87
+ waitFor(() => expect(mockedGetKYCStatus).toHaveBeenCalledTimes(2));
88
+ });
89
+ });
@@ -0,0 +1,43 @@
1
+ import { useEffect } from "react";
2
+ import { KYC_STATUS } from "../utils";
3
+ import { getKYCStatus } from "..";
4
+
5
+ // Poll the server to update the KYC status of a given provider.
6
+ export const KYC_STATUS_POLLING_INTERVAL = 10000;
7
+ export type KYCItem = {
8
+ id: string;
9
+ status: string;
10
+ };
11
+ export type UsePollKYCStatusProps = {
12
+ provider: string;
13
+ kyc: KYCItem;
14
+ onChange: (item: KYCItem) => void;
15
+ };
16
+ export const usePollKYCStatus = (
17
+ { provider, kyc, onChange }: UsePollKYCStatusProps,
18
+ dependencies = []
19
+ ): void => {
20
+ useEffect(
21
+ () => {
22
+ if (kyc?.status !== KYC_STATUS.pending) return;
23
+ let cancelled = false;
24
+ async function updateKYCStatus() {
25
+ if (!kyc?.id) return;
26
+ const res = await getKYCStatus(provider, kyc.id);
27
+ if (cancelled || res?.status === kyc?.status) return;
28
+ onChange(res);
29
+ }
30
+ const intervalId = setInterval(
31
+ updateKYCStatus,
32
+ KYC_STATUS_POLLING_INTERVAL
33
+ );
34
+ updateKYCStatus();
35
+ return () => {
36
+ cancelled = true;
37
+ clearInterval(intervalId);
38
+ };
39
+ },
40
+ // eslint-disable-next-line
41
+ [provider, kyc, ...dependencies]
42
+ );
43
+ };