@ledgerhq/live-common 25.2.0-next.0 → 25.2.0-next.1

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 (316) hide show
  1. package/lib/__tests__/test-helpers/setup.js +1 -0
  2. package/lib/__tests__/test-helpers/setup.js.map +1 -1
  3. package/lib/account/helpers.d.ts.map +1 -1
  4. package/lib/account/helpers.js +1 -0
  5. package/lib/account/helpers.js.map +1 -1
  6. package/lib/account/serialization.d.ts.map +1 -1
  7. package/lib/account/serialization.js +4 -0
  8. package/lib/account/serialization.js.map +1 -1
  9. package/lib/data/icons/react/index.d.ts +1 -0
  10. package/lib/data/icons/react/index.d.ts.map +1 -1
  11. package/lib/data/icons/react/index.js +7 -5
  12. package/lib/data/icons/react/index.js.map +1 -1
  13. package/lib/data/icons/react/osmo.d.ts +8 -0
  14. package/lib/data/icons/react/osmo.d.ts.map +1 -0
  15. package/lib/data/icons/react/osmo.js +39 -0
  16. package/lib/data/icons/react/osmo.js.map +1 -0
  17. package/lib/data/icons/reactNative/index.d.ts +1 -0
  18. package/lib/data/icons/reactNative/index.d.ts.map +1 -1
  19. package/lib/data/icons/reactNative/index.js +7 -5
  20. package/lib/data/icons/reactNative/index.js.map +1 -1
  21. package/lib/data/icons/reactNative/osmo.d.ts +8 -0
  22. package/lib/data/icons/reactNative/osmo.d.ts.map +1 -0
  23. package/lib/data/icons/reactNative/osmo.js +40 -0
  24. package/lib/data/icons/reactNative/osmo.js.map +1 -0
  25. package/lib/env.d.ts +15 -5
  26. package/lib/env.d.ts.map +1 -1
  27. package/lib/env.js +10 -0
  28. package/lib/env.js.map +1 -1
  29. package/lib/env.react.d.ts +1 -1
  30. package/lib/env.react.d.ts.map +1 -1
  31. package/lib/families/cosmos/CosmosValidatorsManager.d.ts +26 -0
  32. package/lib/families/cosmos/CosmosValidatorsManager.d.ts.map +1 -0
  33. package/lib/families/cosmos/CosmosValidatorsManager.js +365 -0
  34. package/lib/families/cosmos/CosmosValidatorsManager.js.map +1 -0
  35. package/lib/families/cosmos/account.d.ts +2 -2
  36. package/lib/families/cosmos/account.d.ts.map +1 -1
  37. package/lib/families/cosmos/account.js +19 -6
  38. package/lib/families/cosmos/account.js.map +1 -1
  39. package/lib/families/cosmos/api/Cosmos.d.ts +27 -15
  40. package/lib/families/cosmos/api/Cosmos.d.ts.map +1 -1
  41. package/lib/families/cosmos/api/Cosmos.js +418 -410
  42. package/lib/families/cosmos/api/Cosmos.js.map +1 -1
  43. package/lib/families/cosmos/bridge/js.d.ts.map +1 -1
  44. package/lib/families/cosmos/bridge/js.js +5 -5
  45. package/lib/families/cosmos/bridge/js.js.map +1 -1
  46. package/lib/families/cosmos/bridge/mock.js +1 -1
  47. package/lib/families/cosmos/bridge/mock.js.map +1 -1
  48. package/lib/families/cosmos/bridge.integration.test.js +5 -5
  49. package/lib/families/cosmos/bridge.integration.test.js.map +1 -1
  50. package/lib/families/cosmos/cli-transaction.d.ts +3 -3
  51. package/lib/families/cosmos/cli-transaction.d.ts.map +1 -1
  52. package/lib/families/cosmos/cli-transaction.js +4 -5
  53. package/lib/families/cosmos/cli-transaction.js.map +1 -1
  54. package/lib/families/cosmos/js-buildTransaction.js +3 -3
  55. package/lib/families/cosmos/js-buildTransaction.js.map +1 -1
  56. package/lib/families/cosmos/js-createTransaction.js +1 -1
  57. package/lib/families/cosmos/js-createTransaction.js.map +1 -1
  58. package/lib/families/cosmos/js-getTransactionStatus.d.ts +17 -3
  59. package/lib/families/cosmos/js-getTransactionStatus.d.ts.map +1 -1
  60. package/lib/families/cosmos/js-getTransactionStatus.js +224 -176
  61. package/lib/families/cosmos/js-getTransactionStatus.js.map +1 -1
  62. package/lib/families/cosmos/js-prepareTransaction.js +2 -2
  63. package/lib/families/cosmos/js-prepareTransaction.js.map +1 -1
  64. package/lib/families/cosmos/js-signOperation.js +3 -3
  65. package/lib/families/cosmos/js-signOperation.js.map +1 -1
  66. package/lib/families/cosmos/js-synchronisation.js +2 -2
  67. package/lib/families/cosmos/js-synchronisation.js.map +1 -1
  68. package/lib/families/cosmos/logic.js +1 -1
  69. package/lib/families/cosmos/logic.js.map +1 -1
  70. package/lib/families/cosmos/mock.js +1 -1
  71. package/lib/families/cosmos/mock.js.map +1 -1
  72. package/lib/families/cosmos/react.d.ts +4 -4
  73. package/lib/families/cosmos/react.d.ts.map +1 -1
  74. package/lib/families/cosmos/react.js +59 -26
  75. package/lib/families/cosmos/react.js.map +1 -1
  76. package/lib/families/cosmos/react.test.js +17 -15
  77. package/lib/families/cosmos/react.test.js.map +1 -1
  78. package/lib/families/cosmos/specs.js +2 -2
  79. package/lib/families/cosmos/specs.js.map +1 -1
  80. package/lib/families/cosmos/speculos-deviceActions.d.ts.map +1 -1
  81. package/lib/families/cosmos/speculos-deviceActions.js +1 -1
  82. package/lib/families/cosmos/speculos-deviceActions.js.map +1 -1
  83. package/lib/families/cosmos/transaction.d.ts +2 -2
  84. package/lib/families/cosmos/transaction.d.ts.map +1 -1
  85. package/lib/families/cosmos/transaction.js +4 -4
  86. package/lib/families/cosmos/transaction.js.map +1 -1
  87. package/lib/families/cosmos/types.d.ts +31 -13
  88. package/lib/families/cosmos/types.d.ts.map +1 -1
  89. package/lib/families/cosmos/utils.d.ts +1 -0
  90. package/lib/families/cosmos/utils.d.ts.map +1 -1
  91. package/lib/families/cosmos/utils.js +7 -1
  92. package/lib/families/cosmos/utils.js.map +1 -1
  93. package/lib/families/cosmos/validators.d.ts +3 -5
  94. package/lib/families/cosmos/validators.d.ts.map +1 -1
  95. package/lib/families/cosmos/validators.js +4 -317
  96. package/lib/families/cosmos/validators.js.map +1 -1
  97. package/lib/families/osmosis/OsmosisSupplyTypes.d.ts +48 -0
  98. package/lib/families/osmosis/OsmosisSupplyTypes.d.ts.map +1 -0
  99. package/lib/families/osmosis/OsmosisSupplyTypes.js +3 -0
  100. package/lib/families/osmosis/OsmosisSupplyTypes.js.map +1 -0
  101. package/lib/families/osmosis/account.d.ts +14 -0
  102. package/lib/families/osmosis/account.d.ts.map +1 -0
  103. package/lib/families/osmosis/account.js +60 -0
  104. package/lib/families/osmosis/account.js.map +1 -0
  105. package/lib/families/osmosis/api/sdk.d.ts +35 -0
  106. package/lib/families/osmosis/api/sdk.d.ts.map +1 -0
  107. package/lib/families/osmosis/api/sdk.js +478 -0
  108. package/lib/families/osmosis/api/sdk.js.map +1 -0
  109. package/lib/families/osmosis/api/sdk.types.d.ts +57 -0
  110. package/lib/families/osmosis/api/sdk.types.d.ts.map +1 -0
  111. package/lib/families/osmosis/api/sdk.types.js +15 -0
  112. package/lib/families/osmosis/api/sdk.types.js.map +1 -0
  113. package/lib/families/osmosis/api/sdk.unit.test.d.ts +2 -0
  114. package/lib/families/osmosis/api/sdk.unit.test.d.ts.map +1 -0
  115. package/lib/families/osmosis/api/sdk.unit.test.js +50 -0
  116. package/lib/families/osmosis/api/sdk.unit.test.js.map +1 -0
  117. package/lib/families/osmosis/bridge/js.d.ts +8 -0
  118. package/lib/families/osmosis/bridge/js.d.ts.map +1 -0
  119. package/lib/families/osmosis/bridge/js.js +98 -0
  120. package/lib/families/osmosis/bridge/js.js.map +1 -0
  121. package/lib/families/osmosis/bridge.integration.test.d.ts +2 -0
  122. package/lib/families/osmosis/bridge.integration.test.d.ts.map +1 -0
  123. package/lib/families/osmosis/bridge.integration.test.js +383 -0
  124. package/lib/families/osmosis/bridge.integration.test.js.map +1 -0
  125. package/lib/families/osmosis/cli-transaction.d.ts +38 -0
  126. package/lib/families/osmosis/cli-transaction.d.ts.map +1 -0
  127. package/lib/families/osmosis/cli-transaction.js +119 -0
  128. package/lib/families/osmosis/cli-transaction.js.map +1 -0
  129. package/lib/families/osmosis/deviceTransactionConfig.d.ts +25 -0
  130. package/lib/families/osmosis/deviceTransactionConfig.d.ts.map +1 -0
  131. package/lib/families/osmosis/deviceTransactionConfig.js +132 -0
  132. package/lib/families/osmosis/deviceTransactionConfig.js.map +1 -0
  133. package/lib/families/osmosis/errors.d.ts +4 -0
  134. package/lib/families/osmosis/errors.d.ts.map +1 -0
  135. package/lib/families/osmosis/errors.js +8 -0
  136. package/lib/families/osmosis/errors.js.map +1 -0
  137. package/lib/families/osmosis/hw-getAddress.d.ts +4 -0
  138. package/lib/families/osmosis/hw-getAddress.d.ts.map +1 -0
  139. package/lib/families/osmosis/hw-getAddress.js +64 -0
  140. package/lib/families/osmosis/hw-getAddress.js.map +1 -0
  141. package/lib/families/osmosis/js-buildTransaction.d.ts +14 -0
  142. package/lib/families/osmosis/js-buildTransaction.d.ts.map +1 -0
  143. package/lib/families/osmosis/js-buildTransaction.js +303 -0
  144. package/lib/families/osmosis/js-buildTransaction.js.map +1 -0
  145. package/lib/families/osmosis/js-estimateMaxSpendable.d.ts +15 -0
  146. package/lib/families/osmosis/js-estimateMaxSpendable.d.ts.map +1 -0
  147. package/lib/families/osmosis/js-estimateMaxSpendable.js +67 -0
  148. package/lib/families/osmosis/js-estimateMaxSpendable.js.map +1 -0
  149. package/lib/families/osmosis/js-getFeesForTransaction.d.ts +15 -0
  150. package/lib/families/osmosis/js-getFeesForTransaction.d.ts.map +1 -0
  151. package/lib/families/osmosis/js-getFeesForTransaction.js +85 -0
  152. package/lib/families/osmosis/js-getFeesForTransaction.js.map +1 -0
  153. package/lib/families/osmosis/js-getTransactionStatus.d.ts +3 -0
  154. package/lib/families/osmosis/js-getTransactionStatus.d.ts.map +1 -0
  155. package/lib/families/osmosis/js-getTransactionStatus.js +10 -0
  156. package/lib/families/osmosis/js-getTransactionStatus.js.map +1 -0
  157. package/lib/families/osmosis/js-signOperation.d.ts +10 -0
  158. package/lib/families/osmosis/js-signOperation.d.ts.map +1 -0
  159. package/lib/families/osmosis/js-signOperation.js +211 -0
  160. package/lib/families/osmosis/js-signOperation.js.map +1 -0
  161. package/lib/families/osmosis/js-synchronization.d.ts +9 -0
  162. package/lib/families/osmosis/js-synchronization.d.ts.map +1 -0
  163. package/lib/families/osmosis/js-synchronization.js +176 -0
  164. package/lib/families/osmosis/js-synchronization.js.map +1 -0
  165. package/lib/families/osmosis/js-transaction.d.ts +23 -0
  166. package/lib/families/osmosis/js-transaction.d.ts.map +1 -0
  167. package/lib/families/osmosis/js-transaction.js +177 -0
  168. package/lib/families/osmosis/js-transaction.js.map +1 -0
  169. package/lib/families/osmosis/logic.d.ts +5 -0
  170. package/lib/families/osmosis/logic.d.ts.map +1 -0
  171. package/lib/families/osmosis/logic.js +22 -0
  172. package/lib/families/osmosis/logic.js.map +1 -0
  173. package/lib/families/osmosis/preloadedData.d.ts +9 -0
  174. package/lib/families/osmosis/preloadedData.d.ts.map +1 -0
  175. package/lib/families/osmosis/preloadedData.js +32 -0
  176. package/lib/families/osmosis/preloadedData.js.map +1 -0
  177. package/lib/families/osmosis/serialization.d.ts +7 -0
  178. package/lib/families/osmosis/serialization.d.ts.map +1 -0
  179. package/lib/families/osmosis/serialization.js +5 -0
  180. package/lib/families/osmosis/serialization.js.map +1 -0
  181. package/lib/families/osmosis/specs.d.ts +7 -0
  182. package/lib/families/osmosis/specs.d.ts.map +1 -0
  183. package/lib/families/osmosis/specs.js +402 -0
  184. package/lib/families/osmosis/specs.js.map +1 -0
  185. package/lib/families/osmosis/speculos-deviceActions.d.ts +7 -0
  186. package/lib/families/osmosis/speculos-deviceActions.d.ts.map +1 -0
  187. package/lib/families/osmosis/speculos-deviceActions.js +120 -0
  188. package/lib/families/osmosis/speculos-deviceActions.js.map +1 -0
  189. package/lib/families/osmosis/transaction.d.ts +10 -0
  190. package/lib/families/osmosis/transaction.d.ts.map +1 -0
  191. package/lib/families/osmosis/transaction.js +13 -0
  192. package/lib/families/osmosis/transaction.js.map +1 -0
  193. package/lib/families/osmosis/types.d.ts +38 -0
  194. package/lib/families/osmosis/types.d.ts.map +1 -0
  195. package/lib/families/osmosis/types.js +3 -0
  196. package/lib/families/osmosis/types.js.map +1 -0
  197. package/lib/families/osmosis/utils.d.ts +8 -0
  198. package/lib/families/osmosis/utils.d.ts.map +1 -0
  199. package/lib/families/osmosis/utils.js +28 -0
  200. package/lib/families/osmosis/utils.js.map +1 -0
  201. package/lib/families/osmosis/validators.d.ts +4 -0
  202. package/lib/families/osmosis/validators.d.ts.map +1 -0
  203. package/lib/families/osmosis/validators.js +131 -0
  204. package/lib/families/osmosis/validators.js.map +1 -0
  205. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  206. package/lib/featureFlags/defaultFeatures.js +3 -0
  207. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  208. package/lib/generated/account.d.ts +7 -1
  209. package/lib/generated/account.d.ts.map +1 -1
  210. package/lib/generated/account.js +4 -2
  211. package/lib/generated/account.js.map +1 -1
  212. package/lib/generated/bridge/js.d.ts +4 -0
  213. package/lib/generated/bridge/js.d.ts.map +1 -1
  214. package/lib/generated/bridge/js.js +14 -12
  215. package/lib/generated/bridge/js.js.map +1 -1
  216. package/lib/generated/cli-transaction.d.ts +33 -2
  217. package/lib/generated/cli-transaction.d.ts.map +1 -1
  218. package/lib/generated/cli-transaction.js +14 -12
  219. package/lib/generated/cli-transaction.js.map +1 -1
  220. package/lib/generated/deviceTransactionConfig.d.ts +4 -1
  221. package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
  222. package/lib/generated/deviceTransactionConfig.js +14 -12
  223. package/lib/generated/deviceTransactionConfig.js.map +1 -1
  224. package/lib/generated/hw-getAddress.d.ts +1 -0
  225. package/lib/generated/hw-getAddress.d.ts.map +1 -1
  226. package/lib/generated/hw-getAddress.js +14 -12
  227. package/lib/generated/hw-getAddress.js.map +1 -1
  228. package/lib/generated/specs.d.ts +3 -0
  229. package/lib/generated/specs.d.ts.map +1 -1
  230. package/lib/generated/specs.js +14 -12
  231. package/lib/generated/specs.js.map +1 -1
  232. package/lib/generated/speculos-deviceActions.d.ts +3 -0
  233. package/lib/generated/speculos-deviceActions.d.ts.map +1 -1
  234. package/lib/generated/speculos-deviceActions.js +14 -12
  235. package/lib/generated/speculos-deviceActions.js.map +1 -1
  236. package/lib/generated/transaction.d.ts +9 -1
  237. package/lib/generated/transaction.d.ts.map +1 -1
  238. package/lib/generated/transaction.js +14 -12
  239. package/lib/generated/transaction.js.map +1 -1
  240. package/lib/generated/types.d.ts +8 -4
  241. package/lib/generated/types.d.ts.map +1 -1
  242. package/lib/reconciliation.d.ts.map +1 -1
  243. package/lib/reconciliation.js +9 -0
  244. package/lib/reconciliation.js.map +1 -1
  245. package/package.json +8 -3
  246. package/src/__tests__/test-helpers/setup.ts +1 -0
  247. package/src/account/helpers.ts +1 -0
  248. package/src/account/serialization.ts +6 -0
  249. package/src/data/icons/react/index.tsx +1 -0
  250. package/src/data/icons/react/osmo.tsx +14 -0
  251. package/src/data/icons/reactNative/index.tsx +1 -0
  252. package/src/data/icons/reactNative/osmo.tsx +15 -0
  253. package/src/data/icons/svg/OSMO.svg +7 -0
  254. package/src/env.ts +10 -0
  255. package/src/families/cosmos/CosmosValidatorsManager.ts +420 -0
  256. package/src/families/cosmos/account.ts +29 -10
  257. package/src/families/cosmos/api/Cosmos.ts +267 -257
  258. package/src/families/cosmos/bridge/js.ts +6 -7
  259. package/src/families/cosmos/bridge/mock.ts +1 -1
  260. package/src/families/cosmos/bridge.integration.test.ts +5 -5
  261. package/src/families/cosmos/cli-transaction.ts +7 -8
  262. package/src/families/cosmos/js-buildTransaction.ts +4 -4
  263. package/src/families/cosmos/js-createTransaction.ts +1 -1
  264. package/src/families/cosmos/js-getTransactionStatus.ts +276 -226
  265. package/src/families/cosmos/js-prepareTransaction.ts +3 -3
  266. package/src/families/cosmos/js-signOperation.ts +4 -4
  267. package/src/families/cosmos/js-synchronisation.ts +3 -3
  268. package/src/families/cosmos/logic.ts +1 -1
  269. package/src/families/cosmos/mock.ts +1 -1
  270. package/src/families/cosmos/react.test.ts +25 -14
  271. package/src/families/cosmos/react.ts +73 -21
  272. package/src/families/cosmos/specs.ts +2 -2
  273. package/src/families/cosmos/speculos-deviceActions.ts +1 -2
  274. package/src/families/cosmos/transaction.ts +4 -6
  275. package/src/families/cosmos/types.ts +41 -13
  276. package/src/families/cosmos/utils.ts +8 -0
  277. package/src/families/cosmos/validators.ts +5 -363
  278. package/src/families/osmosis/OsmosisSupplyTypes.ts +53 -0
  279. package/src/families/osmosis/__snapshots__/bridge.integration.test.ts.snap +852 -0
  280. package/src/families/osmosis/account.ts +65 -0
  281. package/src/families/osmosis/api/sdk.ts +530 -0
  282. package/src/families/osmosis/api/sdk.types.ts +65 -0
  283. package/src/families/osmosis/api/sdk.unit.test.ts +70 -0
  284. package/src/families/osmosis/bridge/js.ts +64 -0
  285. package/src/families/osmosis/bridge.integration.test.ts +467 -0
  286. package/src/families/osmosis/cli-transaction.ts +145 -0
  287. package/src/families/osmosis/deviceTransactionConfig.ts +174 -0
  288. package/src/families/osmosis/errors.ts +13 -0
  289. package/src/families/osmosis/hw-getAddress.ts +14 -0
  290. package/src/families/osmosis/js-buildTransaction.ts +306 -0
  291. package/src/families/osmosis/js-estimateMaxSpendable.ts +26 -0
  292. package/src/families/osmosis/js-getFeesForTransaction.ts +44 -0
  293. package/src/families/osmosis/js-getTransactionStatus.ts +9 -0
  294. package/src/families/osmosis/js-signOperation.ts +172 -0
  295. package/src/families/osmosis/js-synchronization.ts +122 -0
  296. package/src/families/osmosis/js-transaction.ts +96 -0
  297. package/src/families/osmosis/logic.ts +26 -0
  298. package/src/families/osmosis/preloadedData.ts +32 -0
  299. package/src/families/osmosis/serialization.ts +6 -0
  300. package/src/families/osmosis/specs.ts +393 -0
  301. package/src/families/osmosis/speculos-deviceActions.ts +94 -0
  302. package/src/families/osmosis/transaction.ts +20 -0
  303. package/src/families/osmosis/types.ts +48 -0
  304. package/src/families/osmosis/utils.ts +31 -0
  305. package/src/families/osmosis/validators.ts +79 -0
  306. package/src/featureFlags/defaultFeatures.ts +3 -0
  307. package/src/generated/account.ts +3 -0
  308. package/src/generated/bridge/js.ts +3 -0
  309. package/src/generated/cli-transaction.ts +3 -0
  310. package/src/generated/deviceTransactionConfig.ts +5 -0
  311. package/src/generated/hw-getAddress.ts +3 -0
  312. package/src/generated/specs.ts +3 -0
  313. package/src/generated/speculos-deviceActions.ts +3 -0
  314. package/src/generated/transaction.ts +3 -0
  315. package/src/generated/types.ts +8 -0
  316. package/src/reconciliation.ts +16 -0
@@ -15,9 +15,9 @@ import {
15
15
  NotEnoughDelegationBalance,
16
16
  } from "../../errors";
17
17
  import {
18
- CosmosAccount,
18
+ CosmosLikeTransaction,
19
19
  StatusErrorMap,
20
- Transaction,
20
+ CosmosAccount,
21
21
  TransactionStatus,
22
22
  } from "./types";
23
23
  import { BigNumber } from "bignumber.js";
@@ -28,265 +28,315 @@ import {
28
28
  getMaxEstimatedBalance,
29
29
  } from "./logic";
30
30
  import invariant from "invariant";
31
- import { isValidRecipent } from "./api/Cosmos";
32
-
33
- export const getTransactionStatus = async (
34
- a: CosmosAccount,
35
- t: Transaction
36
- ): Promise<TransactionStatus> => {
37
- if (t.mode === "send") {
38
- // We isolate the send transaction that it's a little bit different from the rest
39
- return await getSendTransactionStatus(a, t);
40
- } else if (t.mode === "delegate") {
41
- return await getDelegateTransactionStatus(a, t);
31
+ import { CosmosAPI, defaultCosmosAPI } from "./api/Cosmos";
32
+ import { OsmosisAPI } from "../osmosis/api/sdk";
33
+
34
+ export class CosmosTransactionStatusManager {
35
+ protected _api: CosmosAPI = defaultCosmosAPI;
36
+ protected _validatorOperatorAddressPrefix = "cosmosvaloper";
37
+
38
+ constructor(options?: {
39
+ api?: CosmosAPI;
40
+ validatorOperatorAddressPrefix?: string;
41
+ }) {
42
+ if (options?.validatorOperatorAddressPrefix) {
43
+ this._validatorOperatorAddressPrefix =
44
+ options.validatorOperatorAddressPrefix;
45
+ }
46
+ if (options?.api) {
47
+ this._api = options.api;
48
+ }
42
49
  }
43
50
 
44
- const errors: StatusErrorMap = {};
45
- const warnings: StatusErrorMap = {};
46
- // here we only treat about all other mode than delegate and send
47
- if (
48
- t.validators.some(
49
- (v) => !v.address || !v.address.includes("cosmosvaloper")
50
- ) ||
51
- t.validators.length === 0
52
- )
53
- errors.recipient = new InvalidAddress(undefined, {
54
- currencyName: a.currency.name,
55
- });
56
-
57
- if (t.mode === "redelegate") {
58
- const redelegationError = redelegationStatusError(a, t);
59
-
60
- if (redelegationError) {
61
- // Note : note sure if I have to put this error on this field
62
- errors.redelegation = redelegationError;
51
+ getTransactionStatus = async (
52
+ a: CosmosAccount,
53
+ t: CosmosLikeTransaction
54
+ ): Promise<TransactionStatus> => {
55
+ if (t.mode === "send") {
56
+ // We isolate the send transaction that it's a little bit different from the rest
57
+ return await this.getSendTransactionStatus(a, t);
58
+ } else if (t.mode === "delegate") {
59
+ return await this.getDelegateTransactionStatus(a, t);
63
60
  }
64
- } else if (t.mode === "undelegate") {
65
- invariant(
66
- a.cosmosResources &&
67
- a.cosmosResources.unbondings.length < COSMOS_MAX_UNBONDINGS,
68
- "unbondings should not have more than 6 entries"
69
- );
70
- if (t.validators.length === 0)
61
+
62
+ const errors: StatusErrorMap = {};
63
+ const warnings: StatusErrorMap = {};
64
+ // here we only treat about all other mode than delegate and send
65
+ if (
66
+ t.validators.some(
67
+ (v) =>
68
+ !v.address ||
69
+ !v.address.includes(this._validatorOperatorAddressPrefix)
70
+ ) ||
71
+ t.validators.length === 0
72
+ )
71
73
  errors.recipient = new InvalidAddress(undefined, {
72
74
  currencyName: a.currency.name,
73
75
  });
74
- const [first] = t.validators;
75
- const unbondingError = first && isDelegable(a, first.address, first.amount);
76
76
 
77
- if (unbondingError) {
78
- errors.unbonding = unbondingError;
77
+ if (t.mode === "redelegate") {
78
+ const redelegationError = this.redelegationStatusError(a, t);
79
+
80
+ if (redelegationError) {
81
+ // Note : note sure if I have to put this error on this field
82
+ errors.redelegation = redelegationError;
83
+ }
84
+ } else if (t.mode === "undelegate") {
85
+ invariant(
86
+ a.cosmosResources &&
87
+ a.cosmosResources.unbondings.length < COSMOS_MAX_UNBONDINGS,
88
+ "unbondings should not have more than 6 entries"
89
+ );
90
+ if (t.validators.length === 0)
91
+ errors.recipient = new InvalidAddress(undefined, {
92
+ currencyName: a.currency.name,
93
+ });
94
+ const [first] = t.validators;
95
+ const unbondingError =
96
+ first && this.isDelegable(a, first.address, first.amount);
97
+
98
+ if (unbondingError) {
99
+ errors.unbonding = unbondingError;
100
+ }
79
101
  }
80
- }
81
-
82
- const validatorAmount = t.validators.reduce(
83
- (old, current) => old.plus(current.amount),
84
- new BigNumber(0)
85
- );
86
102
 
87
- if (t.mode !== "claimReward" && validatorAmount.lte(0)) {
88
- errors.amount = new AmountRequired();
89
- }
103
+ const validatorAmount = t.validators.reduce(
104
+ (old, current) => old.plus(current.amount),
105
+ new BigNumber(0)
106
+ );
90
107
 
91
- const estimatedFees = t.fees || new BigNumber(0);
108
+ if (t.mode !== "claimReward" && validatorAmount.lte(0)) {
109
+ errors.amount = new AmountRequired();
110
+ }
92
111
 
93
- if (!t.fees) {
94
- errors.fees = new FeeNotLoaded();
95
- }
112
+ const estimatedFees = t.fees || new BigNumber(0);
96
113
 
97
- let totalSpent = estimatedFees;
114
+ if (!t.fees) {
115
+ errors.fees = new FeeNotLoaded();
116
+ }
98
117
 
99
- if (["claimReward", "claimRewardCompound"].includes(t.mode)) {
100
- const { cosmosResources } = a;
101
- invariant(cosmosResources, "cosmosResources should exist");
102
- const claimReward =
103
- t.validators.length && cosmosResources
104
- ? cosmosResources.delegations.find(
105
- (delegation) =>
106
- delegation.validatorAddress === t.validators[0].address
107
- )
108
- : null;
109
-
110
- if (claimReward && estimatedFees.gt(claimReward.pendingRewards)) {
111
- warnings.claimReward = new ClaimRewardsFeesWarning();
118
+ let totalSpent = estimatedFees;
119
+
120
+ if (["claimReward", "claimRewardCompound"].includes(t.mode)) {
121
+ const { cosmosResources } = a;
122
+ invariant(cosmosResources, "cosmosResources should exist");
123
+ const claimReward =
124
+ t.validators.length && cosmosResources
125
+ ? cosmosResources.delegations.find(
126
+ (delegation) =>
127
+ delegation.validatorAddress === t.validators[0].address
128
+ )
129
+ : null;
130
+
131
+ if (claimReward && estimatedFees.gt(claimReward.pendingRewards)) {
132
+ warnings.claimReward = new ClaimRewardsFeesWarning();
133
+ }
112
134
  }
113
- }
114
135
 
115
- if (
116
- !errors.recipient &&
117
- !errors.amount &&
118
- (validatorAmount.lt(0) || totalSpent.gt(a.spendableBalance))
119
- ) {
120
- errors.amount = new NotEnoughBalance();
121
- totalSpent = new BigNumber(0);
122
- }
136
+ if (
137
+ !errors.recipient &&
138
+ !errors.amount &&
139
+ (validatorAmount.lt(0) || totalSpent.gt(a.spendableBalance))
140
+ ) {
141
+ errors.amount = new NotEnoughBalance();
142
+ totalSpent = new BigNumber(0);
143
+ }
123
144
 
124
- return Promise.resolve({
125
- errors,
126
- warnings,
127
- estimatedFees,
128
- amount: new BigNumber(0),
129
- totalSpent,
130
- });
131
- };
132
-
133
- const getDelegateTransactionStatus = async (
134
- a: CosmosAccount,
135
- t: Transaction
136
- ): Promise<TransactionStatus> => {
137
- const errors: StatusErrorMap = {};
138
- const warnings: StatusErrorMap = {};
139
- if (
140
- t.validators.some(
141
- (v) => !v.address || !v.address.includes("cosmosvaloper")
142
- ) ||
143
- t.validators.length === 0
144
- )
145
- errors.recipient = new InvalidAddress(undefined, {
146
- currencyName: a.currency.name,
145
+ return Promise.resolve({
146
+ errors,
147
+ warnings,
148
+ estimatedFees,
149
+ amount: new BigNumber(0),
150
+ totalSpent,
147
151
  });
152
+ };
153
+
154
+ private getDelegateTransactionStatus = async (
155
+ a: CosmosAccount,
156
+ t: CosmosLikeTransaction
157
+ ): Promise<TransactionStatus> => {
158
+ const errors: StatusErrorMap = {};
159
+ const warnings: StatusErrorMap = {};
160
+ if (
161
+ t.validators.some(
162
+ (v) =>
163
+ !v.address ||
164
+ !v.address.includes(this._validatorOperatorAddressPrefix)
165
+ ) ||
166
+ t.validators.length === 0
167
+ )
168
+ errors.recipient = new InvalidAddress(undefined, {
169
+ currencyName: a.currency.name,
170
+ });
148
171
 
149
- if (t.validators.length > COSMOS_MAX_DELEGATIONS) {
150
- errors.validators = new CosmosTooManyValidators();
151
- }
172
+ if (t.validators.length > COSMOS_MAX_DELEGATIONS) {
173
+ errors.validators = new CosmosTooManyValidators();
174
+ }
152
175
 
153
- const estimatedFees = t.fees || new BigNumber(0);
176
+ const estimatedFees = t.fees || new BigNumber(0);
154
177
 
155
- if (!t.fees || !t.fees.gt(0)) {
156
- errors.fees = new FeeNotLoaded();
157
- }
178
+ if (this._api instanceof OsmosisAPI) {
179
+ if (!t.fees) {
180
+ errors.fees = new FeeNotLoaded();
181
+ }
182
+ } else {
183
+ if (!t.fees || !t.fees.gt(0)) {
184
+ errors.fees = new FeeNotLoaded();
185
+ }
186
+ }
187
+ let amount;
188
+
189
+ // TODO, refactor this block. We should use cosmosResources for Osmosis
190
+ if (this._api instanceof OsmosisAPI) {
191
+ amount = t.useAllAmount
192
+ ? a.spendableBalance.minus(estimatedFees)
193
+ : new BigNumber(t.amount);
194
+ } else {
195
+ amount = t.useAllAmount
196
+ ? getMaxEstimatedBalance(a, estimatedFees)
197
+ : t.amount;
198
+ }
199
+ const totalSpent = amount.plus(estimatedFees);
158
200
 
159
- const amount = t.useAllAmount
160
- ? getMaxEstimatedBalance(a, estimatedFees)
161
- : t.amount;
162
- const totalSpent = amount.plus(estimatedFees);
201
+ if (amount.eq(0)) {
202
+ errors.amount = new AmountRequired();
203
+ }
163
204
 
164
- if (amount.eq(0)) {
165
- errors.amount = new AmountRequired();
166
- }
205
+ if (
206
+ !errors.recipient &&
207
+ !errors.amount &&
208
+ (amount.lt(0) || totalSpent.gt(a.spendableBalance))
209
+ ) {
210
+ errors.amount = new NotEnoughBalance();
211
+ }
167
212
 
168
- if (
169
- !errors.recipient &&
170
- !errors.amount &&
171
- (amount.lt(0) || totalSpent.gt(a.spendableBalance))
172
- ) {
173
- errors.amount = new NotEnoughBalance();
174
- }
213
+ if (!errors.amount && t.useAllAmount) {
214
+ warnings.amount = new CosmosDelegateAllFundsWarning();
215
+ }
175
216
 
176
- if (!errors.amount && t.useAllAmount) {
177
- warnings.amount = new CosmosDelegateAllFundsWarning();
178
- }
217
+ return Promise.resolve({
218
+ errors,
219
+ warnings,
220
+ estimatedFees,
221
+ amount,
222
+ totalSpent,
223
+ });
224
+ };
225
+
226
+ private getSendTransactionStatus = async (
227
+ a: CosmosAccount,
228
+ t: CosmosLikeTransaction
229
+ ): Promise<TransactionStatus> => {
230
+ const errors: StatusErrorMap = {};
231
+ const warnings: StatusErrorMap = {};
232
+
233
+ if (!t.recipient) {
234
+ errors.recipient = new RecipientRequired("");
235
+ } else if (a.freshAddress === t.recipient) {
236
+ errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
237
+ } else {
238
+ if (!(await this._api.isValidRecipent(t.recipient))) {
239
+ errors.recipient = new InvalidAddress(undefined, {
240
+ currencyName: a.currency.name,
241
+ });
242
+ }
243
+ }
179
244
 
180
- return Promise.resolve({
181
- errors,
182
- warnings,
183
- estimatedFees,
184
- amount,
185
- totalSpent,
186
- });
187
- };
188
-
189
- const getSendTransactionStatus = async (
190
- a: CosmosAccount,
191
- t: Transaction
192
- ): Promise<TransactionStatus> => {
193
- const errors: StatusErrorMap = {};
194
- const warnings: StatusErrorMap = {};
195
-
196
- if (!t.recipient) {
197
- errors.recipient = new RecipientRequired("");
198
- } else if (a.freshAddress === t.recipient) {
199
- errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
200
- } else {
201
- if (!(await isValidRecipent(t.recipient))) {
202
- errors.recipient = new InvalidAddress(undefined, {
203
- currencyName: a.currency.name,
204
- });
245
+ let amount = t.amount;
246
+
247
+ if (amount.lte(0) && !t.useAllAmount) {
248
+ errors.amount = new AmountRequired();
205
249
  }
206
- }
207
250
 
208
- let amount = t.amount;
251
+ const estimatedFees = t.fees || new BigNumber(0);
209
252
 
210
- if (amount.lte(0) && !t.useAllAmount) {
211
- errors.amount = new AmountRequired();
212
- }
253
+ if (this._api instanceof OsmosisAPI) {
254
+ if (!t.fees) {
255
+ errors.fees = new FeeNotLoaded();
256
+ }
257
+ } else {
258
+ if (!t.fees || !t.fees.gt(0)) {
259
+ errors.fees = new FeeNotLoaded();
260
+ }
261
+ }
213
262
 
214
- const estimatedFees = t.fees || new BigNumber(0);
263
+ amount = t.useAllAmount ? getMaxEstimatedBalance(a, estimatedFees) : amount;
264
+ const totalSpent = amount.plus(estimatedFees);
215
265
 
216
- if (!t.fees || !t.fees.gt(0)) {
217
- errors.fees = new FeeNotLoaded();
218
- }
266
+ if (
267
+ (amount.lte(0) && t.useAllAmount) || // if use all Amount sets an amount at 0
268
+ (!errors.recipient && !errors.amount && totalSpent.gt(a.spendableBalance)) // if spendable balance lower than total
269
+ ) {
270
+ errors.amount = new NotEnoughBalance();
271
+ }
219
272
 
220
- amount = t.useAllAmount ? getMaxEstimatedBalance(a, estimatedFees) : amount;
221
- const totalSpent = amount.plus(estimatedFees);
273
+ if (
274
+ a.cosmosResources &&
275
+ a.cosmosResources.delegations.length > 0 &&
276
+ t.useAllAmount
277
+ ) {
278
+ warnings.amount = new RecommendUndelegation();
279
+ }
222
280
 
223
- if (
224
- (amount.lte(0) && t.useAllAmount) || // if use all Amount sets an amount at 0
225
- (!errors.recipient && !errors.amount && totalSpent.gt(a.spendableBalance)) // if spendable balance lower than total
226
- ) {
227
- errors.amount = new NotEnoughBalance();
228
- }
281
+ return Promise.resolve({
282
+ errors,
283
+ warnings,
284
+ estimatedFees,
285
+ amount,
286
+ totalSpent,
287
+ });
288
+ };
289
+
290
+ private redelegationStatusError = (
291
+ a: CosmosAccount,
292
+ t: CosmosLikeTransaction
293
+ ) => {
294
+ if (a.cosmosResources) {
295
+ const redelegations = a.cosmosResources.redelegations;
296
+ invariant(
297
+ redelegations.length < COSMOS_MAX_REDELEGATIONS,
298
+ "redelegation should not have more than 6 entries"
299
+ );
300
+ if (
301
+ redelegations.some((redelegation) => {
302
+ const dstValidator = redelegation.validatorDstAddress;
303
+ return (
304
+ dstValidator === t.sourceValidator &&
305
+ redelegation.completionDate > new Date()
306
+ );
307
+ })
308
+ )
309
+ return new CosmosRedelegationInProgress();
310
+ if (t.sourceValidator === t.validators[0].address)
311
+ return new InvalidAddressBecauseDestinationIsAlsoSource();
312
+ }
229
313
 
230
- if (
231
- a.cosmosResources &&
232
- a.cosmosResources.delegations.length > 0 &&
233
- t.useAllAmount
234
- ) {
235
- warnings.amount = new RecommendUndelegation();
236
- }
314
+ return this.isDelegable(a, t.sourceValidator, t.validators[0].amount);
315
+ };
316
+
317
+ private isDelegable = (
318
+ a: CosmosAccount,
319
+ address: string | undefined | null,
320
+ amount: BigNumber
321
+ ) => {
322
+ const { cosmosResources } = a;
323
+ invariant(cosmosResources, "cosmosResources should exist");
237
324
 
238
- return Promise.resolve({
239
- errors,
240
- warnings,
241
- estimatedFees,
242
- amount,
243
- totalSpent,
244
- });
245
- };
246
-
247
- const redelegationStatusError = (a: CosmosAccount, t: Transaction) => {
248
- if (a.cosmosResources) {
249
- const redelegations = a.cosmosResources.redelegations;
250
- invariant(
251
- redelegations.length < COSMOS_MAX_REDELEGATIONS,
252
- "redelegation should not have more than 6 entries"
253
- );
254
325
  if (
255
- redelegations.some((redelegation) => {
256
- const dstValidator = redelegation.validatorDstAddress;
257
- return (
258
- dstValidator === t.cosmosSourceValidator &&
259
- redelegation.completionDate > new Date()
260
- );
261
- })
262
- )
263
- return new CosmosRedelegationInProgress();
264
- if (t.cosmosSourceValidator === t.validators[0].address)
265
- return new InvalidAddressBecauseDestinationIsAlsoSource();
266
- }
326
+ cosmosResources &&
327
+ cosmosResources.delegations.some(
328
+ (delegation) =>
329
+ delegation.validatorAddress === address &&
330
+ delegation.amount.lt(amount)
331
+ )
332
+ ) {
333
+ return new NotEnoughDelegationBalance();
334
+ }
267
335
 
268
- return isDelegable(a, t.cosmosSourceValidator, t.validators[0].amount);
269
- };
270
-
271
- const isDelegable = (
272
- a: CosmosAccount,
273
- address: string | undefined | null,
274
- amount: BigNumber
275
- ) => {
276
- const { cosmosResources } = a;
277
- invariant(cosmosResources, "cosmosResources should exist");
278
-
279
- if (
280
- cosmosResources &&
281
- cosmosResources.delegations.some(
282
- (delegation) =>
283
- delegation.validatorAddress === address && delegation.amount.lt(amount)
284
- )
285
- ) {
286
- return new NotEnoughDelegationBalance();
287
- }
336
+ return null;
337
+ };
338
+ }
288
339
 
289
- return null;
290
- };
340
+ const cosmosTransactionStatusManager = new CosmosTransactionStatusManager();
291
341
 
292
- export default getTransactionStatus;
342
+ export default cosmosTransactionStatusManager.getTransactionStatus;
@@ -1,6 +1,6 @@
1
1
  import { CosmosAccount, Transaction } from "./types";
2
2
  import BigNumber from "bignumber.js";
3
- import { simulate } from "./api/Cosmos";
3
+ import { defaultCosmosAPI } from "./api/Cosmos";
4
4
  import { getEnv } from "../../env";
5
5
  import { buildTransaction, postBuildTransaction } from "./js-buildTransaction";
6
6
  import { getMaxEstimatedBalance } from "./logic";
@@ -34,7 +34,7 @@ export const calculateFees: CacheRes<
34
34
  ? transaction.validators.map((v) => v.address).join("-")
35
35
  : ""
36
36
  }_${transaction.memo ? transaction.memo.toString() : ""}_${
37
- transaction.cosmosSourceValidator ? transaction.cosmosSourceValidator : ""
37
+ transaction.sourceValidator ? transaction.sourceValidator : ""
38
38
  }`
39
39
  );
40
40
 
@@ -65,7 +65,7 @@ const getEstimatedFees = async (
65
65
  new Uint8Array(Buffer.from(account.seedIdentifier, "hex"))
66
66
  );
67
67
 
68
- const gasUsed = await simulate(tx_bytes);
68
+ const gasUsed = await defaultCosmosAPI.simulate(tx_bytes);
69
69
 
70
70
  if (gasUsed.gt(0)) {
71
71
  gasQty = gasUsed
@@ -1,5 +1,5 @@
1
1
  import type { CosmosAccount, Transaction } from "./types";
2
- import { getAccount, getChainId } from "./api/Cosmos";
2
+ import { defaultCosmosAPI } from "./api/Cosmos";
3
3
  import { Observable } from "rxjs";
4
4
  import { withDevice } from "../../hw/deviceAccess";
5
5
  import { encodeOperationId } from "../../operation";
@@ -33,11 +33,11 @@ const signOperation = ({
33
33
  async function main() {
34
34
  const hwApp = new Cosmos(transport);
35
35
 
36
- const { accountNumber, sequence } = await getAccount(
36
+ const { accountNumber, sequence } = await defaultCosmosAPI.getAccount(
37
37
  account.freshAddress
38
38
  );
39
39
 
40
- const chainId = await getChainId();
40
+ const chainId = await defaultCosmosAPI.getChainId();
41
41
 
42
42
  o.next({ type: "device-signature-requested" });
43
43
 
@@ -138,7 +138,7 @@ const signOperation = ({
138
138
 
139
139
  if (transaction.mode === "redelegate") {
140
140
  Object.assign(extra, {
141
- cosmosSourceValidator: transaction.cosmosSourceValidator,
141
+ sourceValidator: transaction.sourceValidator,
142
142
  });
143
143
  }
144
144
 
@@ -6,7 +6,7 @@ import {
6
6
  mergeOps,
7
7
  } from "../../bridge/jsHelpers";
8
8
  import { encodeAccountId } from "../../account";
9
- import { getAccountInfo } from "./api/Cosmos";
9
+ import { defaultCosmosAPI } from "./api/Cosmos";
10
10
  import { pubkeyToAddress, decodeBech32Pubkey } from "@cosmjs/amino";
11
11
  import { encodeOperationId } from "../../operation";
12
12
  import { CosmosDelegationInfo } from "./types";
@@ -122,7 +122,7 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => {
122
122
  address: attributes.destination_validator,
123
123
  amount: attributes.amount.replace(currency.units[1].code, ""),
124
124
  });
125
- op.extra.cosmosSourceValidator = attributes.source_validator;
125
+ op.extra.sourceValidator = attributes.source_validator;
126
126
  }
127
127
  break;
128
128
 
@@ -184,7 +184,7 @@ export const getAccountShape: GetAccountShape = async (info) => {
184
184
  redelegations,
185
185
  unbondings,
186
186
  withdrawAddress,
187
- } = await getAccountInfo(xpubOrAddress, currency);
187
+ } = await defaultCosmosAPI.getAccountInfo(xpubOrAddress, currency);
188
188
 
189
189
  const oldOperations = initialAccount?.operations || [];
190
190
  const newOperations = txToOps(info, accountId, txs);
@@ -215,7 +215,7 @@ export async function canClaimRewards(
215
215
  useAllAmount: false,
216
216
  networkInfo: null,
217
217
  memo: null,
218
- cosmosSourceValidator: null,
218
+ sourceValidator: null,
219
219
  validators: [
220
220
  {
221
221
  address: delegation.validatorAddress,
@@ -197,7 +197,7 @@ function addRedelegationOperation(
197
197
  address: toDelegation.validatorAddress,
198
198
  amount,
199
199
  },
200
- cosmosSourceValidator: fromDelegation.validatorAddress,
200
+ sourceValidator: fromDelegation.validatorAddress,
201
201
  };
202
202
  const delegations = cosmosResources.delegations
203
203
  .filter(