@ledgerhq/live-common 21.28.0 → 21.31.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 (324) hide show
  1. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.synced.unit.test.js +1 -1
  2. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.synced.unit.test.js.map +1 -1
  3. package/lib/__tests__/test-helpers/bridge.js +1 -1
  4. package/lib/__tests__/test-helpers/bridge.js.map +1 -1
  5. package/lib/__tests__/test-helpers/setup.js +1 -0
  6. package/lib/__tests__/test-helpers/setup.js.map +1 -1
  7. package/lib/account/support.d.ts.map +1 -1
  8. package/lib/account/support.js.map +1 -1
  9. package/lib/apps/hw.d.ts.map +1 -1
  10. package/lib/apps/hw.js +8 -3
  11. package/lib/apps/hw.js.map +1 -1
  12. package/lib/bot/engine.js +1 -1
  13. package/lib/bot/engine.js.map +1 -1
  14. package/lib/bridge/jsHelpers.js +1 -1
  15. package/lib/data/icons/react/celo.d.ts +8 -0
  16. package/lib/data/icons/react/celo.d.ts.map +1 -0
  17. package/lib/data/icons/react/celo.js +32 -0
  18. package/lib/data/icons/react/celo.js.map +1 -0
  19. package/lib/data/icons/react/index.d.ts +1 -0
  20. package/lib/data/icons/react/index.d.ts.map +1 -1
  21. package/lib/data/icons/react/index.js +11 -8
  22. package/lib/data/icons/react/index.js.map +1 -1
  23. package/lib/data/icons/reactNative/celo.d.ts +8 -0
  24. package/lib/data/icons/reactNative/celo.d.ts.map +1 -0
  25. package/lib/data/icons/reactNative/celo.js +33 -0
  26. package/lib/data/icons/reactNative/celo.js.map +1 -0
  27. package/lib/data/icons/reactNative/index.d.ts +1 -0
  28. package/lib/data/icons/reactNative/index.d.ts.map +1 -1
  29. package/lib/data/icons/reactNative/index.js +11 -8
  30. package/lib/data/icons/reactNative/index.js.map +1 -1
  31. package/lib/env.d.ts +20 -5
  32. package/lib/env.d.ts.map +1 -1
  33. package/lib/env.js +15 -0
  34. package/lib/env.js.map +1 -1
  35. package/lib/env.react.d.ts +1 -1
  36. package/lib/env.react.d.ts.map +1 -1
  37. package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts.map +1 -1
  38. package/lib/exchange/swap/hooks/usePickDefaultAccount.js +4 -9
  39. package/lib/exchange/swap/hooks/usePickDefaultAccount.js.map +1 -1
  40. package/lib/exchange/swap/utils/index.d.ts +6 -1
  41. package/lib/exchange/swap/utils/index.d.ts.map +1 -1
  42. package/lib/exchange/swap/utils/index.js +8 -1
  43. package/lib/exchange/swap/utils/index.js.map +1 -1
  44. package/lib/exchange/swap/utils/index.test.js +27 -0
  45. package/lib/exchange/swap/utils/index.test.js.map +1 -1
  46. package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
  47. package/lib/families/bitcoin/wallet-btc/crypto/base.js +19 -20
  48. package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
  49. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.d.ts.map +1 -1
  50. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js +4 -5
  51. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js.map +1 -1
  52. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
  53. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +3 -4
  54. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
  55. package/lib/families/bitcoin/wallet-btc/crypto/decred.d.ts.map +1 -1
  56. package/lib/families/bitcoin/wallet-btc/crypto/decred.js +3 -4
  57. package/lib/families/bitcoin/wallet-btc/crypto/decred.js.map +1 -1
  58. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts.map +1 -1
  59. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js +3 -4
  60. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js.map +1 -1
  61. package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
  62. package/lib/families/bitcoin/wallet-btc/crypto/zec.js +3 -4
  63. package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
  64. package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
  65. package/lib/families/bitcoin/wallet-btc/crypto/zen.js +3 -4
  66. package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
  67. package/lib/families/bitcoin/wallet-btc/xpub.js +1 -1
  68. package/lib/families/bitcoin/wallet-btc/xpub.js.map +1 -1
  69. package/lib/families/celo/api/hubble.d.ts +8 -0
  70. package/lib/families/celo/api/hubble.d.ts.map +1 -0
  71. package/lib/families/celo/api/hubble.js +144 -0
  72. package/lib/families/celo/api/hubble.js.map +1 -0
  73. package/lib/families/celo/api/index.d.ts +2 -0
  74. package/lib/families/celo/api/index.d.ts.map +1 -0
  75. package/lib/families/celo/api/index.js +13 -0
  76. package/lib/families/celo/api/index.js.map +1 -0
  77. package/lib/families/celo/api/sdk.d.ts +3 -0
  78. package/lib/families/celo/api/sdk.d.ts.map +1 -0
  79. package/lib/families/celo/api/sdk.js +13 -0
  80. package/lib/families/celo/api/sdk.js.map +1 -0
  81. package/lib/families/celo/bridge/js.d.ts +8 -0
  82. package/lib/families/celo/bridge/js.d.ts.map +1 -0
  83. package/lib/families/celo/bridge/js.js +87 -0
  84. package/lib/families/celo/bridge/js.js.map +1 -0
  85. package/lib/families/celo/cli-transaction.d.ts +14 -0
  86. package/lib/families/celo/cli-transaction.d.ts.map +1 -0
  87. package/lib/families/celo/cli-transaction.js +37 -0
  88. package/lib/families/celo/cli-transaction.js.map +1 -0
  89. package/lib/families/celo/datasets/celo.scanAccounts.1.d.ts +5 -0
  90. package/lib/families/celo/datasets/celo.scanAccounts.1.d.ts.map +1 -0
  91. package/lib/families/celo/datasets/celo.scanAccounts.1.js +12 -0
  92. package/lib/families/celo/datasets/celo.scanAccounts.1.js.map +1 -0
  93. package/lib/families/celo/deviceTransactionConfig.d.ts +4 -0
  94. package/lib/families/celo/deviceTransactionConfig.d.ts.map +1 -0
  95. package/lib/families/celo/deviceTransactionConfig.js +16 -0
  96. package/lib/families/celo/deviceTransactionConfig.js.map +1 -0
  97. package/lib/families/celo/hw-app-celo.d.ts +19 -0
  98. package/lib/families/celo/hw-app-celo.d.ts.map +1 -0
  99. package/lib/families/celo/hw-app-celo.js +147 -0
  100. package/lib/families/celo/hw-app-celo.js.map +1 -0
  101. package/lib/families/celo/hw-getAddress.d.ts +2 -0
  102. package/lib/families/celo/hw-getAddress.d.ts.map +1 -0
  103. package/lib/families/celo/hw-getAddress.js +13 -0
  104. package/lib/families/celo/hw-getAddress.js.map +1 -0
  105. package/lib/families/celo/js-broadcast.d.ts +8 -0
  106. package/lib/families/celo/js-broadcast.d.ts.map +1 -0
  107. package/lib/families/celo/js-broadcast.js +58 -0
  108. package/lib/families/celo/js-broadcast.js.map +1 -0
  109. package/lib/families/celo/js-buildTransaction.d.ts +6 -0
  110. package/lib/families/celo/js-buildTransaction.d.ts.map +1 -0
  111. package/lib/families/celo/js-buildTransaction.js +89 -0
  112. package/lib/families/celo/js-buildTransaction.js.map +1 -0
  113. package/lib/families/celo/js-createTransaction.d.ts +4 -0
  114. package/lib/families/celo/js-createTransaction.d.ts.map +1 -0
  115. package/lib/families/celo/js-createTransaction.js +12 -0
  116. package/lib/families/celo/js-createTransaction.js.map +1 -0
  117. package/lib/families/celo/js-estimateMaxSpendable.d.ts +10 -0
  118. package/lib/families/celo/js-estimateMaxSpendable.d.ts.map +1 -0
  119. package/lib/families/celo/js-estimateMaxSpendable.js +77 -0
  120. package/lib/families/celo/js-estimateMaxSpendable.js.map +1 -0
  121. package/lib/families/celo/js-getFeesForTransaction.d.ts +8 -0
  122. package/lib/families/celo/js-getFeesForTransaction.d.ts.map +1 -0
  123. package/lib/families/celo/js-getFeesForTransaction.js +76 -0
  124. package/lib/families/celo/js-getFeesForTransaction.js.map +1 -0
  125. package/lib/families/celo/js-getTransactionStatus.d.ts +5 -0
  126. package/lib/families/celo/js-getTransactionStatus.d.ts.map +1 -0
  127. package/lib/families/celo/js-getTransactionStatus.js +86 -0
  128. package/lib/families/celo/js-getTransactionStatus.js.map +1 -0
  129. package/lib/families/celo/js-prepareTransaction.d.ts +5 -0
  130. package/lib/families/celo/js-prepareTransaction.d.ts.map +1 -0
  131. package/lib/families/celo/js-prepareTransaction.js +76 -0
  132. package/lib/families/celo/js-prepareTransaction.js.map +1 -0
  133. package/lib/families/celo/js-signOperation.d.ts +13 -0
  134. package/lib/families/celo/js-signOperation.d.ts.map +1 -0
  135. package/lib/families/celo/js-signOperation.js +150 -0
  136. package/lib/families/celo/js-signOperation.js.map +1 -0
  137. package/lib/families/celo/js-synchronisation.d.ts +10 -0
  138. package/lib/families/celo/js-synchronisation.d.ts.map +1 -0
  139. package/lib/families/celo/js-synchronisation.js +88 -0
  140. package/lib/families/celo/js-synchronisation.js.map +1 -0
  141. package/lib/families/celo/specs.d.ts +7 -0
  142. package/lib/families/celo/specs.d.ts.map +1 -0
  143. package/lib/families/celo/specs.js +56 -0
  144. package/lib/families/celo/specs.js.map +1 -0
  145. package/lib/families/celo/speculos-deviceActions.d.ts +7 -0
  146. package/lib/families/celo/speculos-deviceActions.d.ts.map +1 -0
  147. package/lib/families/celo/speculos-deviceActions.js +53 -0
  148. package/lib/families/celo/speculos-deviceActions.js.map +1 -0
  149. package/lib/families/celo/transaction.d.ts +11 -0
  150. package/lib/families/celo/transaction.d.ts.map +1 -0
  151. package/lib/families/celo/transaction.js +39 -0
  152. package/lib/families/celo/transaction.js.map +1 -0
  153. package/lib/families/celo/types.d.ts +16 -0
  154. package/lib/families/celo/types.d.ts.map +1 -0
  155. package/lib/families/celo/types.js +6 -0
  156. package/lib/families/celo/types.js.map +1 -0
  157. package/lib/families/ethereum/datasets/ethereum.scanAccounts.1.d.ts +1 -0
  158. package/lib/families/ethereum/datasets/ethereum.scanAccounts.1.d.ts.map +1 -1
  159. package/lib/families/ethereum/datasets/ethereum.scanAccounts.1.js +1 -0
  160. package/lib/families/ethereum/datasets/ethereum.scanAccounts.1.js.map +1 -1
  161. package/lib/families/ethereum/modules/erc1155.d.ts.map +1 -1
  162. package/lib/families/ethereum/modules/erc1155.js +8 -2
  163. package/lib/families/ethereum/modules/erc1155.js.map +1 -1
  164. package/lib/families/polkadot/cache.d.ts +1 -1
  165. package/lib/families/polkadot/cache.js +1 -1
  166. package/lib/families/solana/api/chain/index.d.ts +2 -2
  167. package/lib/families/solana/api/chain/index.d.ts.map +1 -1
  168. package/lib/families/solana/api/chain/index.js +4 -4
  169. package/lib/families/solana/api/chain/index.js.map +1 -1
  170. package/lib/families/solana/bridge/bridge.js +5 -5
  171. package/lib/families/solana/bridge/bridge.js.map +1 -1
  172. package/lib/families/solana/bridge/js.js +3 -3
  173. package/lib/families/solana/bridge/js.js.map +1 -1
  174. package/lib/families/solana/bridge/mock.js +1 -1
  175. package/lib/families/solana/bridge/mock.js.map +1 -1
  176. package/lib/families/solana/test-dataset.d.ts.map +1 -1
  177. package/lib/families/solana/test-dataset.js +211 -209
  178. package/lib/families/solana/test-dataset.js.map +1 -1
  179. package/lib/families/solana/utils.d.ts +1 -2
  180. package/lib/families/solana/utils.d.ts.map +1 -1
  181. package/lib/families/solana/utils.js +11 -9
  182. package/lib/families/solana/utils.js.map +1 -1
  183. package/lib/families/tezos/datasets/tezos.scanAccounts.1.js +1 -1
  184. package/lib/families/tezos/datasets/tezos.scanAccounts.1.js.map +1 -1
  185. package/lib/featureFlags/FeatureToggle.d.ts +10 -0
  186. package/lib/featureFlags/FeatureToggle.d.ts.map +1 -0
  187. package/lib/featureFlags/FeatureToggle.js +17 -0
  188. package/lib/featureFlags/FeatureToggle.js.map +1 -0
  189. package/lib/featureFlags/defaultFeatures.d.ts +3 -0
  190. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -0
  191. package/lib/featureFlags/defaultFeatures.js +9 -0
  192. package/lib/featureFlags/defaultFeatures.js.map +1 -0
  193. package/lib/featureFlags/index.d.ts +5 -0
  194. package/lib/featureFlags/index.d.ts.map +1 -0
  195. package/lib/featureFlags/index.js +17 -0
  196. package/lib/featureFlags/index.js.map +1 -0
  197. package/lib/featureFlags/provider.d.ts +13 -0
  198. package/lib/featureFlags/provider.d.ts.map +1 -0
  199. package/lib/featureFlags/provider.js +68 -0
  200. package/lib/featureFlags/provider.js.map +1 -0
  201. package/lib/featureFlags/types.d.ts +8 -0
  202. package/lib/featureFlags/types.d.ts.map +1 -0
  203. package/lib/featureFlags/types.js +3 -0
  204. package/lib/featureFlags/types.js.map +1 -0
  205. package/lib/featureFlags/useFeature.d.ts +3 -0
  206. package/lib/featureFlags/useFeature.d.ts.map +1 -0
  207. package/lib/featureFlags/useFeature.js +9 -0
  208. package/lib/featureFlags/useFeature.js.map +1 -0
  209. package/lib/generated/bridge/js.d.ts +4 -0
  210. package/lib/generated/bridge/js.d.ts.map +1 -1
  211. package/lib/generated/bridge/js.js +24 -22
  212. package/lib/generated/bridge/js.js.map +1 -1
  213. package/lib/generated/cli-transaction.d.ts +9 -0
  214. package/lib/generated/cli-transaction.d.ts.map +1 -1
  215. package/lib/generated/cli-transaction.js +24 -22
  216. package/lib/generated/cli-transaction.js.map +1 -1
  217. package/lib/generated/deviceTransactionConfig.d.ts +2 -0
  218. package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
  219. package/lib/generated/deviceTransactionConfig.js +22 -20
  220. package/lib/generated/deviceTransactionConfig.js.map +1 -1
  221. package/lib/generated/hw-getAddress.d.ts +1 -0
  222. package/lib/generated/hw-getAddress.d.ts.map +1 -1
  223. package/lib/generated/hw-getAddress.js +26 -24
  224. package/lib/generated/hw-getAddress.js.map +1 -1
  225. package/lib/generated/specs.d.ts +3 -0
  226. package/lib/generated/specs.d.ts.map +1 -1
  227. package/lib/generated/specs.js +24 -22
  228. package/lib/generated/specs.js.map +1 -1
  229. package/lib/generated/speculos-deviceActions.d.ts +3 -0
  230. package/lib/generated/speculos-deviceActions.d.ts.map +1 -1
  231. package/lib/generated/speculos-deviceActions.js +24 -22
  232. package/lib/generated/speculos-deviceActions.js.map +1 -1
  233. package/lib/generated/transaction.d.ts +5 -0
  234. package/lib/generated/transaction.d.ts.map +1 -1
  235. package/lib/generated/transaction.js +26 -24
  236. package/lib/generated/transaction.js.map +1 -1
  237. package/lib/generated/types.d.ts +12 -6
  238. package/lib/generated/types.d.ts.map +1 -1
  239. package/lib/generated/types.js +14 -12
  240. package/lib/generated/types.js.map +1 -1
  241. package/lib/types/index.d.ts +1 -0
  242. package/lib/types/index.d.ts.map +1 -1
  243. package/lib/types/index.js +1 -0
  244. package/lib/types/index.js.map +1 -1
  245. package/lib/types/manager.d.ts +7 -0
  246. package/lib/types/manager.d.ts.map +1 -1
  247. package/lib/types/manager.js +7 -0
  248. package/lib/types/manager.js.map +1 -1
  249. package/package.json +12 -9
  250. package/src/.DS_Store +0 -0
  251. package/src/__tests__/.DS_Store +0 -0
  252. package/src/__tests__/__snapshots__/all.libcore.ts.snap +0 -33226
  253. package/src/__tests__/families/bitcoin/wallet-btc/xpub.synced.unit.test.ts +1 -1
  254. package/src/__tests__/test-helpers/bridge.ts +1 -1
  255. package/src/__tests__/test-helpers/setup.ts +1 -0
  256. package/src/account/support.ts +1 -0
  257. package/src/apps/hw.ts +7 -0
  258. package/src/bot/engine.ts +1 -1
  259. package/src/bridge/jsHelpers.ts +1 -1
  260. package/src/data/icons/react/celo.tsx +12 -0
  261. package/src/data/icons/react/index.tsx +1 -0
  262. package/src/data/icons/reactNative/celo.tsx +13 -0
  263. package/src/data/icons/reactNative/index.tsx +1 -0
  264. package/src/data/icons/svg/CELO.svg +5 -0
  265. package/src/env.ts +15 -0
  266. package/src/exchange/swap/hooks/usePickDefaultAccount.ts +4 -9
  267. package/src/exchange/swap/utils/index.test.ts +44 -1
  268. package/src/exchange/swap/utils/index.ts +12 -1
  269. package/src/families/bitcoin/wallet-btc/crypto/base.ts +41 -20
  270. package/src/families/bitcoin/wallet-btc/crypto/bitcoin.ts +12 -5
  271. package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +11 -4
  272. package/src/families/bitcoin/wallet-btc/crypto/decred.ts +11 -4
  273. package/src/families/bitcoin/wallet-btc/crypto/litecoin.ts +11 -4
  274. package/src/families/bitcoin/wallet-btc/crypto/zec.ts +11 -4
  275. package/src/families/bitcoin/wallet-btc/crypto/zen.ts +11 -4
  276. package/src/families/bitcoin/wallet-btc/xpub.ts +1 -1
  277. package/src/families/celo/api/hubble.ts +93 -0
  278. package/src/families/celo/api/index.ts +1 -0
  279. package/src/families/celo/api/sdk.ts +8 -0
  280. package/src/families/celo/bridge/js.ts +38 -0
  281. package/src/families/celo/cli-transaction.ts +41 -0
  282. package/src/families/celo/datasets/celo.scanAccounts.1.ts +20 -0
  283. package/src/families/celo/deviceTransactionConfig.ts +19 -0
  284. package/src/families/celo/hw-app-celo.ts +108 -0
  285. package/src/families/celo/hw-getAddress.ts +1 -0
  286. package/src/families/celo/js-broadcast.ts +12 -0
  287. package/src/families/celo/js-buildTransaction.ts +32 -0
  288. package/src/families/celo/js-createTransaction.ts +12 -0
  289. package/src/families/celo/js-estimateMaxSpendable.ts +28 -0
  290. package/src/families/celo/js-getFeesForTransaction.ts +38 -0
  291. package/src/families/celo/js-getTransactionStatus.ts +67 -0
  292. package/src/families/celo/js-prepareTransaction.ts +28 -0
  293. package/src/families/celo/js-signOperation.ts +149 -0
  294. package/src/families/celo/js-synchronisation.ts +40 -0
  295. package/src/families/celo/specs.ts +53 -0
  296. package/src/families/celo/speculos-deviceActions.ts +51 -0
  297. package/src/families/celo/transaction.ts +39 -0
  298. package/src/families/celo/types.ts +20 -0
  299. package/src/families/ethereum/datasets/ethereum.scanAccounts.1.ts +1 -0
  300. package/src/families/ethereum/modules/erc1155.ts +9 -0
  301. package/src/families/polkadot/cache.ts +1 -1
  302. package/src/families/solana/api/chain/index.ts +8 -7
  303. package/src/families/solana/bridge/bridge.ts +11 -11
  304. package/src/families/solana/bridge/js.ts +3 -3
  305. package/src/families/solana/bridge/mock.ts +1 -1
  306. package/src/families/solana/test-dataset.ts +340 -337
  307. package/src/families/solana/utils.ts +9 -8
  308. package/src/families/tezos/datasets/tezos.scanAccounts.1.ts +39 -39
  309. package/src/featureFlags/FeatureToggle.tsx +24 -0
  310. package/src/featureFlags/defaultFeatures.ts +7 -0
  311. package/src/featureFlags/index.ts +4 -0
  312. package/src/featureFlags/provider.tsx +48 -0
  313. package/src/featureFlags/types.ts +9 -0
  314. package/src/featureFlags/useFeature.ts +8 -0
  315. package/src/generated/bridge/js.ts +3 -0
  316. package/src/generated/cli-transaction.ts +3 -0
  317. package/src/generated/deviceTransactionConfig.ts +3 -0
  318. package/src/generated/hw-getAddress.ts +3 -0
  319. package/src/generated/specs.ts +3 -0
  320. package/src/generated/speculos-deviceActions.ts +3 -0
  321. package/src/generated/transaction.ts +3 -0
  322. package/src/generated/types.ts +14 -0
  323. package/src/types/index.ts +1 -0
  324. package/src/types/manager.ts +7 -0
@@ -34,7 +34,7 @@ describe("synced xpub utilites functions", () => {
34
34
 
35
35
  beforeAll(async () => {
36
36
  await xpub.sync();
37
- }, 60000);
37
+ }, 120000);
38
38
 
39
39
  it("should compute accounts/addresses/balances correctly", async () => {
40
40
  const addresses = await xpub.getXpubAddresses();
@@ -478,7 +478,7 @@ export function testBridge<T extends Transaction>(
478
478
 
479
479
  // existing ops are keeping refs
480
480
  synced.operations.slice(count).forEach((op, i) => {
481
- expect(op).toBe(operations[i]);
481
+ expect(op).toStrictEqual(operations[i]);
482
482
  });
483
483
  }
484
484
  );
@@ -56,4 +56,5 @@ setSupportedCurrencies([
56
56
  "crypto_org",
57
57
  "filecoin",
58
58
  "solana",
59
+ "celo",
59
60
  ]);
@@ -21,6 +21,7 @@ import { getAccountBridge } from "../bridge";
21
21
  import jsBridges from "../generated/bridge/js";
22
22
 
23
23
  const experimentalIntegrations = ["algorand", "tezos"];
24
+
24
25
  export function shouldUseJS(currency: CryptoCurrency) {
25
26
  const jsBridge = jsBridges[currency.family];
26
27
  if (!jsBridge) return false;
package/src/apps/hw.ts CHANGED
@@ -5,6 +5,7 @@ import { concat, of, EMPTY, from, Observable, throwError, defer } from "rxjs";
5
5
  import { mergeMap, map } from "rxjs/operators";
6
6
  import type { Exec, AppOp, ListAppsEvent, ListAppsResult } from "./types";
7
7
  import type { App, DeviceInfo } from "../types/manager";
8
+ import { AppType } from "../types/manager";
8
9
  import manager, { getProviderId } from "../manager";
9
10
  import installApp from "../hw/installApp";
10
11
  import uninstallApp from "../hw/uninstallApp";
@@ -313,6 +314,11 @@ export const listApps = (
313
314
  }
314
315
  }
315
316
 
317
+ const type =
318
+ application.description === AppType.PLUGIN
319
+ ? AppType.PLUGIN
320
+ : AppType.APP;
321
+
316
322
  const app: App = polyfillApp({
317
323
  id: version.id,
318
324
  name: version.name,
@@ -320,6 +326,7 @@ export const listApps = (
320
326
  version: version.version,
321
327
  currencyId,
322
328
  description: version.description,
329
+ type,
323
330
  dateModified: version.date_last_modified,
324
331
  icon: version.icon,
325
332
  authorName: application.authorName,
package/src/bot/engine.ts CHANGED
@@ -401,7 +401,7 @@ export async function runOnAccount<T extends Transaction>({
401
401
  }
402
402
  }
403
403
 
404
- // without recovering mecanism, we simply assume an error is a failure
404
+ // without recovering mechanism, we simply assume an error is a failure
405
405
  if (errors.length) {
406
406
  throw errors[0];
407
407
  }
@@ -97,7 +97,7 @@ Operation[] {
97
97
  newOps.forEach((op) => {
98
98
  newOpsIds[op.id] = op;
99
99
  });
100
- // return existins when there is no real new operations
100
+ // return existing when there is no real new operations
101
101
  if (newOps.length === 0) return existing;
102
102
  // edge case, existing can be empty. return the sorted list.
103
103
  if (existing.length === 0) return Object.values(newOpsIds);
@@ -0,0 +1,12 @@
1
+
2
+ import * as React from "react";
3
+ interface Props {
4
+ size: number;
5
+ color?: string;
6
+ };
7
+
8
+ function celo({size, color = "currentColor"}: Props) {
9
+ return <svg width={size} height={size} viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M10.1053 19.1053C12.9834 19.1053 15.3158 16.7728 15.3158 13.8947C15.3158 11.0166 12.9834 8.68421 10.1053 8.68421C7.22716 8.68421 4.89474 11.0166 4.89474 13.8947C4.89474 16.7728 7.22716 19.1053 10.1053 19.1053ZM10.1053 21C6.18126 21 3 17.8187 3 13.8947C3 9.97074 6.18126 6.78947 10.1053 6.78947C14.0293 6.78947 17.2105 9.97074 17.2105 13.8947C17.2105 17.8187 14.0293 21 10.1053 21Z" fill={color} /><path d="M13.8947 15.3158C16.7728 15.3158 19.1053 12.9834 19.1053 10.1053C19.1053 7.22716 16.7728 4.89474 13.8947 4.89474C11.0166 4.89474 8.68421 7.22716 8.68421 10.1053C8.68421 12.9834 11.0166 15.3158 13.8947 15.3158ZM13.8947 17.2105C9.97074 17.2105 6.78947 14.0293 6.78947 10.1053C6.78947 6.18126 9.97074 3 13.8947 3C17.8187 3 21 6.18126 21 10.1053C21 14.0293 17.8187 17.2105 13.8947 17.2105Z" fill={color} /><path d="M14.1297 17.2105C14.6223 16.6137 14.9747 15.9145 15.1623 15.1623C15.9126 14.9747 16.6118 14.6223 17.2105 14.1297C17.184 14.9994 16.9964 15.8558 16.6573 16.6592C15.8558 16.9964 14.9994 17.184 14.1297 17.2105ZM8.83768 8.83768C8.08737 9.02526 7.38821 9.37768 6.78947 9.87032C6.816 9.00063 7.00358 8.14421 7.34274 7.34274C8.14421 7.00547 9.00253 6.81789 9.87032 6.78947C9.37768 7.38632 9.02526 8.08547 8.83768 8.83768Z" fill={color} /></svg>;
10
+ }
11
+
12
+ export default celo;
@@ -78,6 +78,7 @@ export { default as call } from "./call";
78
78
  export { default as cc } from "./cc";
79
79
  export { default as cdn } from "./cdn";
80
80
  export { default as cdt } from "./cdt";
81
+ export { default as celo } from "./celo";
81
82
  export { default as cenz } from "./cenz";
82
83
  export { default as chain } from "./chain";
83
84
  export { default as chat } from "./chat";
@@ -0,0 +1,13 @@
1
+
2
+ import * as React from "react";
3
+ import Svg, { Path } from "react-native-svg";
4
+ interface Props {
5
+ size: number;
6
+ color: string;
7
+ };
8
+
9
+ function celo({ size, color }: Props) {
10
+ return <Svg width={size} height={size} viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><Path d="M10.1053 19.1053C12.9834 19.1053 15.3158 16.7728 15.3158 13.8947C15.3158 11.0166 12.9834 8.68421 10.1053 8.68421C7.22716 8.68421 4.89474 11.0166 4.89474 13.8947C4.89474 16.7728 7.22716 19.1053 10.1053 19.1053ZM10.1053 21C6.18126 21 3 17.8187 3 13.8947C3 9.97074 6.18126 6.78947 10.1053 6.78947C14.0293 6.78947 17.2105 9.97074 17.2105 13.8947C17.2105 17.8187 14.0293 21 10.1053 21Z" fill={color} /><Path d="M13.8947 15.3158C16.7728 15.3158 19.1053 12.9834 19.1053 10.1053C19.1053 7.22716 16.7728 4.89474 13.8947 4.89474C11.0166 4.89474 8.68421 7.22716 8.68421 10.1053C8.68421 12.9834 11.0166 15.3158 13.8947 15.3158ZM13.8947 17.2105C9.97074 17.2105 6.78947 14.0293 6.78947 10.1053C6.78947 6.18126 9.97074 3 13.8947 3C17.8187 3 21 6.18126 21 10.1053C21 14.0293 17.8187 17.2105 13.8947 17.2105Z" fill={color} /><Path d="M14.1297 17.2105C14.6223 16.6137 14.9747 15.9145 15.1623 15.1623C15.9126 14.9747 16.6118 14.6223 17.2105 14.1297C17.184 14.9994 16.9964 15.8558 16.6573 16.6592C15.8558 16.9964 14.9994 17.184 14.1297 17.2105ZM8.83768 8.83768C8.08737 9.02526 7.38821 9.37768 6.78947 9.87032C6.816 9.00063 7.00358 8.14421 7.34274 7.34274C8.14421 7.00547 9.00253 6.81789 9.87032 6.78947C9.37768 7.38632 9.02526 8.08547 8.83768 8.83768Z" fill={color} /></Svg>;
11
+ }
12
+
13
+ export default celo;
@@ -78,6 +78,7 @@ export { default as call } from "./call";
78
78
  export { default as cc } from "./cc";
79
79
  export { default as cdn } from "./cdn";
80
80
  export { default as cdt } from "./cdt";
81
+ export { default as celo } from "./celo";
81
82
  export { default as cenz } from "./cenz";
82
83
  export { default as chain } from "./chain";
83
84
  export { default as chat } from "./chat";
@@ -0,0 +1,5 @@
1
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M10.1053 19.1053C12.9834 19.1053 15.3158 16.7728 15.3158 13.8947C15.3158 11.0166 12.9834 8.68421 10.1053 8.68421C7.22716 8.68421 4.89474 11.0166 4.89474 13.8947C4.89474 16.7728 7.22716 19.1053 10.1053 19.1053ZM10.1053 21C6.18126 21 3 17.8187 3 13.8947C3 9.97074 6.18126 6.78947 10.1053 6.78947C14.0293 6.78947 17.2105 9.97074 17.2105 13.8947C17.2105 17.8187 14.0293 21 10.1053 21Z" fill="#42D689"/>
3
+ <path d="M13.8947 15.3158C16.7728 15.3158 19.1053 12.9834 19.1053 10.1053C19.1053 7.22716 16.7728 4.89474 13.8947 4.89474C11.0166 4.89474 8.68421 7.22716 8.68421 10.1053C8.68421 12.9834 11.0166 15.3158 13.8947 15.3158ZM13.8947 17.2105C9.97074 17.2105 6.78947 14.0293 6.78947 10.1053C6.78947 6.18126 9.97074 3 13.8947 3C17.8187 3 21 6.18126 21 10.1053C21 14.0293 17.8187 17.2105 13.8947 17.2105Z" fill="#42D689"/>
4
+ <path d="M14.1297 17.2105C14.6223 16.6137 14.9747 15.9145 15.1623 15.1623C15.9126 14.9747 16.6118 14.6223 17.2105 14.1297C17.184 14.9994 16.9964 15.8558 16.6573 16.6592C15.8558 16.9964 14.9994 17.184 14.1297 17.2105ZM8.83768 8.83768C8.08737 9.02526 7.38821 9.37768 6.78947 9.87032C6.816 9.00063 7.00358 8.14421 7.34274 7.34274C8.14421 7.00547 9.00253 6.81789 9.87032 6.78947C9.37768 7.38632 9.02526 8.08547 8.83768 8.83768Z" fill="#42D689"/>
5
+ </svg>
package/src/env.ts CHANGED
@@ -40,6 +40,16 @@ const envDefinitions = {
40
40
  parser: stringParser,
41
41
  desc: "Node API endpoint for algorand",
42
42
  },
43
+ API_CELO_INDEXER: {
44
+ def: "https://celo.coin.ledger.com/indexer/",
45
+ parser: stringParser,
46
+ desc: "Explorer API for celo",
47
+ },
48
+ API_CELO_NODE: {
49
+ def: "https://celo.coin.ledger.com/archive/",
50
+ parser: stringParser,
51
+ desc: "Node endpoint for celo",
52
+ },
43
53
  API_COSMOS_BLOCKCHAIN_EXPLORER_API_ENDPOINT: {
44
54
  def: "https://cosmoshub4.coin.ledger.com/",
45
55
  parser: stringParser,
@@ -120,6 +130,11 @@ const envDefinitions = {
120
130
  def: "https://tron.coin.ledger.com",
121
131
  desc: "proxy url for trongrid API",
122
132
  },
133
+ API_SOLANA_PROXY: {
134
+ parser: stringParser,
135
+ def: "https://solana.coin.ledger.com",
136
+ desc: "proxy url for solana API",
137
+ },
123
138
  BASE_SOCKET_URL: {
124
139
  def: "wss://scriptrunner.api.live.ledger.com/update",
125
140
  parser: stringParser,
@@ -2,7 +2,7 @@ import { useEffect } from "react";
2
2
  import { Account, TokenAccount } from "../../../types";
3
3
  import { useCurrenciesByMarketcap } from "../../../currencies/sortByMarketcap";
4
4
  import { listCryptoCurrencies, listTokens } from "../../../currencies";
5
- import { getAccountCurrency } from "../../../account";
5
+ import { getAvailableAccountsById } from "../utils";
6
6
 
7
7
  // Pick a default source account if none are selected.
8
8
  export const usePickDefaultAccount = (
@@ -17,14 +17,9 @@ export const usePickDefaultAccount = (
17
17
  if (!fromAccount && allCurrencies.length > 0) {
18
18
  const defaultAccount: Account | TokenAccount | undefined = allCurrencies
19
19
  .map(({ id }) =>
20
- accounts
21
- .filter(
22
- (acc) =>
23
- getAccountCurrency(acc)?.id === id &&
24
- acc.balance.gt(0) &&
25
- !acc.disabled
26
- )
27
- .sort((a, b) => b.balance.minus(a.balance).toNumber())
20
+ getAvailableAccountsById(id, accounts).filter((account) =>
21
+ account.balance.gt(0)
22
+ )
28
23
  )
29
24
  .flat(1)
30
25
  .find(Boolean);
@@ -1,6 +1,10 @@
1
1
  import BigNumber from "bignumber.js";
2
2
 
3
- import { pickExchangeRate, getAccountTuplesForCurrency } from "./index";
3
+ import {
4
+ pickExchangeRate,
5
+ getAccountTuplesForCurrency,
6
+ getAvailableAccountsById,
7
+ } from "./index";
4
8
  import { getMockExchangeRate } from "../mock";
5
9
  import { genAccount } from "../../../mock/account";
6
10
  import type {
@@ -222,3 +226,42 @@ describe("swap/utils/getAccountTuplesForCurrency", () => {
222
226
  });
223
227
  });
224
228
  });
229
+
230
+ describe("swap/utils/getAvailableAccountsById", () => {
231
+ const getEthAccount = getAccountCreator("ethereum");
232
+ const getBtcAccount = getAccountCreator("bitcoin");
233
+ const getPolkadotAccount = getAccountCreator("polkadot");
234
+ const getCosmosAccount = getAccountCreator("cosmos");
235
+
236
+ test("return the correct accounts after sorting/filtering them", () => {
237
+ const [
238
+ disabledAccount,
239
+ higherBalanceAccount,
240
+ lowerBalanceAccount,
241
+ ...accounts
242
+ ] = new Array(6).fill(null).map(getEthAccount);
243
+
244
+ // mutate some accounts to test sorting/filtering
245
+ disabledAccount.disabled = true;
246
+ higherBalanceAccount.balance = new BigNumber(10);
247
+ lowerBalanceAccount.balance = new BigNumber(2);
248
+
249
+ const allAccounts: Account[] = [
250
+ getCosmosAccount(),
251
+ disabledAccount,
252
+ higherBalanceAccount,
253
+ lowerBalanceAccount,
254
+ ...accounts,
255
+ getBtcAccount(),
256
+ getPolkadotAccount(),
257
+ ];
258
+
259
+ const results = getAvailableAccountsById("ethereum", allAccounts);
260
+ expect(results).toHaveLength(5);
261
+ expect(results[0].balance.toNumber()).toBeGreaterThan(0);
262
+ expect(results[1].balance.toNumber()).toBeGreaterThan(0);
263
+ expect(results[0].balance.toNumber()).toBeGreaterThan(
264
+ results[1].balance.toNumber()
265
+ );
266
+ });
267
+ });
@@ -1,7 +1,8 @@
1
1
  import { CryptoCurrency, TokenCurrency } from "@ledgerhq/cryptoassets";
2
2
  import { makeEmptyTokenAccount } from "../../../account";
3
- import { Account, SubAccount } from "../../../types";
3
+ import { Account, SubAccount, TokenAccount } from "../../../types";
4
4
  import type { ExchangeRate } from "../types";
5
+ import { getAccountCurrency } from "../../../account";
5
6
 
6
7
  export const KYC_STATUS = {
7
8
  pending: "pending",
@@ -65,3 +66,13 @@ export function getAccountTuplesForCurrency(
65
66
  }))
66
67
  .filter((a) => (hideEmpty ? a.account?.balance.gt(0) : true));
67
68
  }
69
+
70
+ export const getAvailableAccountsById = (
71
+ id: string,
72
+ accounts: ((Account | TokenAccount) & { disabled?: boolean })[]
73
+ ): ((Account | TokenAccount) & {
74
+ disabled?: boolean | undefined;
75
+ })[] =>
76
+ accounts
77
+ .filter((acc) => getAccountCurrency(acc)?.id === id && !acc.disabled)
78
+ .sort((a, b) => b.balance.minus(a.balance).toNumber());
@@ -42,13 +42,13 @@ class Base implements ICrypto {
42
42
  }
43
43
 
44
44
  protected getPubkeyAt(xpub: string, account: number, index: number): Buffer {
45
- if (!Base.bech32Cache[xpub]) {
45
+ if (!Base.bech32Cache[`${this.network.name}-${xpub}`]) {
46
46
  const buffer: Buffer = bs58.decode(xpub);
47
47
  const depth: number = buffer[4];
48
48
  const i: number = buffer.readUInt32BE(9);
49
49
  const chainCode: Buffer = buffer.slice(13, 45);
50
50
  const publicKey: Buffer = buffer.slice(45, 78);
51
- Base.bech32Cache[xpub] = new BIP32(
51
+ Base.bech32Cache[`${this.network.name}-${xpub}`] = new BIP32(
52
52
  publicKey,
53
53
  chainCode,
54
54
  this.network,
@@ -56,20 +56,30 @@ class Base implements ICrypto {
56
56
  i
57
57
  );
58
58
  }
59
- if (Base.publickeyCache[`${xpub}-${account}-${index}`]) {
60
- return Base.publickeyCache[`${xpub}-${account}-${index}`];
59
+ if (
60
+ Base.publickeyCache[`${this.network.name}-${xpub}-${account}-${index}`]
61
+ ) {
62
+ return Base.publickeyCache[
63
+ `${this.network.name}-${xpub}-${account}-${index}`
64
+ ];
61
65
  }
62
- if (Base.publickeyCache[`${xpub}-${account}`]) {
66
+ if (Base.publickeyCache[`${this.network.name}-${xpub}-${account}`]) {
63
67
  const publicKey =
64
- Base.publickeyCache[`${xpub}-${account}`].derive(index).publicKey;
65
- Base.publickeyCache[`${xpub}-${account}-${index}`] = publicKey;
68
+ Base.publickeyCache[`${this.network.name}-${xpub}-${account}`].derive(
69
+ index
70
+ ).publicKey;
71
+ Base.publickeyCache[`${this.network.name}-${xpub}-${account}-${index}`] =
72
+ publicKey;
66
73
  return publicKey;
67
74
  }
68
- Base.publickeyCache[`${xpub}-${account}`] =
69
- Base.bech32Cache[xpub].derive(account);
75
+ Base.publickeyCache[`${this.network.name}-${xpub}-${account}`] =
76
+ Base.bech32Cache[`${this.network.name}-${xpub}`].derive(account);
70
77
  const publicKey =
71
- Base.publickeyCache[`${xpub}-${account}`].derive(index).publicKey;
72
- Base.publickeyCache[`${xpub}-${account}-${index}`] = publicKey;
78
+ Base.publickeyCache[`${this.network.name}-${xpub}-${account}`].derive(
79
+ index
80
+ ).publicKey;
81
+ Base.publickeyCache[`${this.network.name}-${xpub}-${account}-${index}`] =
82
+ publicKey;
73
83
  return publicKey;
74
84
  }
75
85
 
@@ -110,26 +120,37 @@ class Base implements ICrypto {
110
120
  account: number,
111
121
  index: number
112
122
  ): string {
113
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
114
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
123
+ if (
124
+ Base.addressCache[
125
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
126
+ ]
127
+ ) {
128
+ return Base.addressCache[
129
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
130
+ ];
115
131
  }
116
132
  switch (derivationMode) {
117
133
  case DerivationModes.LEGACY:
118
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
119
- this.getLegacyAddress(xpub, account, index);
134
+ Base.addressCache[
135
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
136
+ ] = this.getLegacyAddress(xpub, account, index);
120
137
  break;
121
138
  case DerivationModes.SEGWIT:
122
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
123
- this.getSegWitAddress(xpub, account, index);
139
+ Base.addressCache[
140
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
141
+ ] = this.getSegWitAddress(xpub, account, index);
124
142
  break;
125
143
  case DerivationModes.NATIVE_SEGWIT:
126
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
127
- this.getNativeSegWitAddress(xpub, account, index);
144
+ Base.addressCache[
145
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
146
+ ] = this.getNativeSegWitAddress(xpub, account, index);
128
147
  break;
129
148
  default:
130
149
  throw new Error(`Invalid derivation Mode: ${derivationMode}`);
131
150
  }
132
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
151
+ return Base.addressCache[
152
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
153
+ ];
133
154
  }
134
155
 
135
156
  // infer address type from its syntax
@@ -125,15 +125,22 @@ class Bitcoin extends Base {
125
125
  account: number,
126
126
  index: number
127
127
  ): string {
128
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
129
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
128
+ if (
129
+ Base.addressCache[
130
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
131
+ ]
132
+ ) {
133
+ return Base.addressCache[
134
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
135
+ ];
130
136
  }
131
137
  switch (derivationMode) {
132
138
  case DerivationModes.TAPROOT:
133
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
134
- this.getTaprootAddress(xpub, account, index);
139
+ Base.addressCache[
140
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
141
+ ] = this.getTaprootAddress(xpub, account, index);
135
142
  return Base.addressCache[
136
- `${derivationMode}-${xpub}-${account}-${index}`
143
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
137
144
  ];
138
145
  default:
139
146
  return super.getAddress(derivationMode, xpub, account, index);
@@ -47,12 +47,19 @@ class BitcoinCash implements ICrypto {
47
47
  account: number,
48
48
  index: number
49
49
  ): string {
50
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
51
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
50
+ if (
51
+ Base.addressCache[
52
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
53
+ ]
54
+ ) {
55
+ return Base.addressCache[
56
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
57
+ ];
52
58
  }
53
59
  const address = this.getLegacyBitcoinCashAddress(xpub, account, index);
54
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
55
- address;
60
+ Base.addressCache[
61
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
62
+ ] = address;
56
63
  return address;
57
64
  }
58
65
 
@@ -74,8 +74,14 @@ class Decred extends Base {
74
74
  account: number,
75
75
  index: number
76
76
  ): string {
77
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
78
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
77
+ if (
78
+ Base.addressCache[
79
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
80
+ ]
81
+ ) {
82
+ return Base.addressCache[
83
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
84
+ ];
79
85
  }
80
86
  let buffer: Buffer;
81
87
  try {
@@ -90,8 +96,9 @@ class Decred extends Base {
90
96
  const hd = new BIP32(X, chainCode, this.network, depth, i);
91
97
  const publicKey = hd.derive(account).derive(index).publicKey;
92
98
  const address = Decred.getAddressFromPk(publicKey);
93
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
94
- address;
99
+ Base.addressCache[
100
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
101
+ ] = address;
95
102
  return address;
96
103
  }
97
104
  }
@@ -59,8 +59,14 @@ class Litecoin extends Base implements ICrypto {
59
59
  account: number,
60
60
  index: number
61
61
  ): string {
62
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
63
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
62
+ if (
63
+ Base.addressCache[
64
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
65
+ ]
66
+ ) {
67
+ return Base.addressCache[
68
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
69
+ ];
64
70
  }
65
71
  let address: string;
66
72
  switch (derivationMode) {
@@ -76,8 +82,9 @@ class Litecoin extends Base implements ICrypto {
76
82
  default:
77
83
  throw new Error("Should not be reachable");
78
84
  }
79
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
80
- address;
85
+ Base.addressCache[
86
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
87
+ ] = address;
81
88
  return address;
82
89
  }
83
90
 
@@ -53,12 +53,19 @@ class ZCash implements ICrypto {
53
53
  account: number,
54
54
  index: number
55
55
  ): string {
56
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
57
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
56
+ if (
57
+ Base.addressCache[
58
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
59
+ ]
60
+ ) {
61
+ return Base.addressCache[
62
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
63
+ ];
58
64
  }
59
65
  const address = this.getLegacyAddress(xpub, account, index);
60
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
61
- address;
66
+ Base.addressCache[
67
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
68
+ ] = address;
62
69
  return address;
63
70
  }
64
71
 
@@ -73,12 +73,19 @@ class Zen implements ICrypto {
73
73
  account: number,
74
74
  index: number
75
75
  ): string {
76
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
77
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
76
+ if (
77
+ Base.addressCache[
78
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
79
+ ]
80
+ ) {
81
+ return Base.addressCache[
82
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
83
+ ];
78
84
  }
79
85
  const address = this.getLegacyAddress(xpub, account, index);
80
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
81
- address;
86
+ Base.addressCache[
87
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
88
+ ] = address;
82
89
  return address;
83
90
  }
84
91
 
@@ -67,7 +67,7 @@ class Xpub extends EventEmitter {
67
67
  );
68
68
 
69
69
  this.storage.addAddress(
70
- `${this.derivationMode}-${this.xpub}-${account}-${index}`,
70
+ `${this.crypto.network.name}-${this.derivationMode}-${this.xpub}-${account}-${index}`,
71
71
  address
72
72
  );
73
73
  await this.whenSynced("address", address);
@@ -0,0 +1,93 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import network from "../../../network";
3
+ import { getEnv } from "../../../env";
4
+ import { Operation, OperationType } from "../../../types";
5
+ import { encodeOperationId } from "../../../operation";
6
+
7
+ const DEFAULT_TRANSACTIONS_LIMIT = 200;
8
+ const getUrl = (route): string => `${getEnv("API_CELO_INDEXER")}${route || ""}`;
9
+
10
+ // Indexer returns both account data and transactions in one call.
11
+ // Transactions are just limited, there's no block height offset
12
+ const fetchAccountDetails = async (
13
+ address: string,
14
+ transactionsLimit: number = DEFAULT_TRANSACTIONS_LIMIT
15
+ ) => {
16
+ const { data } = await network({
17
+ method: "GET",
18
+ url: getUrl(`/account_details/${address}?limit=${transactionsLimit}`),
19
+ });
20
+ return data;
21
+ };
22
+
23
+ const fetchStatus = async () => {
24
+ const { data } = await network({
25
+ method: "GET",
26
+ url: getUrl(`/status`),
27
+ });
28
+ return data;
29
+ };
30
+
31
+ const getOperationType = (type: string): OperationType => {
32
+ switch (type) {
33
+ case "InternalTransferSent":
34
+ return "OUT";
35
+ case "InternalTransferReceived":
36
+ return "IN";
37
+ case "AccountSlashed":
38
+ return "SLASH";
39
+ default:
40
+ return "NONE";
41
+ }
42
+ };
43
+
44
+ const transactionToOperation = (
45
+ address: string,
46
+ accountId: string,
47
+ transaction
48
+ ): Operation => {
49
+ const type: OperationType = getOperationType(transaction.kind);
50
+ const hasFailed = transaction.data.success
51
+ ? !transaction.data.success
52
+ : false;
53
+ const senders = transaction.data.from ? [transaction.data.from] : [];
54
+ const recipients = transaction.data.to ? [transaction.data.to] : [];
55
+
56
+ return {
57
+ id: encodeOperationId(accountId, transaction.transaction_hash, type),
58
+ hash: transaction.transaction_hash,
59
+ accountId,
60
+ fee: new BigNumber(0),
61
+ value: new BigNumber(transaction.amount),
62
+ type,
63
+ blockHeight: transaction.height,
64
+ date: new Date(transaction.time),
65
+ senders,
66
+ recipients,
67
+ hasFailed,
68
+ blockHash: null,
69
+ extra: {},
70
+ };
71
+ };
72
+
73
+ export const getAccountDetails = async (address: string, accountId: string) => {
74
+ const accountDetails = await fetchAccountDetails(address);
75
+ const spendableBalance = new BigNumber(accountDetails.gold_balance);
76
+ const lockedBalance = new BigNumber(accountDetails.total_locked_gold);
77
+ const balance = spendableBalance.plus(lockedBalance);
78
+ const indexerStatus = await fetchStatus();
79
+
80
+ const allTransactions = accountDetails.internal_transfers.concat(
81
+ accountDetails.transactions
82
+ );
83
+ const operations = allTransactions.map((transaction) =>
84
+ transactionToOperation(address, accountId, transaction)
85
+ );
86
+
87
+ return {
88
+ blockHeight: indexerStatus.last_indexed_height,
89
+ balance,
90
+ spendableBalance,
91
+ operations,
92
+ };
93
+ };
@@ -0,0 +1 @@
1
+ export { getAccountDetails } from "./hubble";
@@ -0,0 +1,8 @@
1
+ import { ContractKit, newKit } from "@celo/contractkit";
2
+ import { getEnv } from "../../../env";
3
+
4
+ let kit: ContractKit;
5
+ export const celoKit = () => {
6
+ if (!kit) kit = newKit(getEnv("API_CELO_NODE"));
7
+ return kit;
8
+ };