@metamask-previews/perps-controller 0.0.0-preview-e4aa1532 → 0.0.0-preview-6dfa4aeba

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 (498) hide show
  1. package/CHANGELOG.md +1 -11
  2. package/dist/PerpsController.cjs +66 -2224
  3. package/dist/PerpsController.cjs.map +1 -1
  4. package/dist/PerpsController.d.cts +79 -933
  5. package/dist/PerpsController.d.cts.map +1 -1
  6. package/dist/PerpsController.d.mts +79 -933
  7. package/dist/PerpsController.d.mts.map +1 -1
  8. package/dist/PerpsController.mjs +64 -2221
  9. package/dist/PerpsController.mjs.map +1 -1
  10. package/dist/index.cjs +1 -32
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +2 -6
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.mts +2 -6
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +1 -9
  17. package/dist/index.mjs.map +1 -1
  18. package/package.json +4 -19
  19. package/dist/__mocks__/hyperliquidMock.cjs +0 -68
  20. package/dist/__mocks__/hyperliquidMock.cjs.map +0 -1
  21. package/dist/__mocks__/hyperliquidMock.d.cts +0 -15
  22. package/dist/__mocks__/hyperliquidMock.d.cts.map +0 -1
  23. package/dist/__mocks__/hyperliquidMock.d.mts +0 -15
  24. package/dist/__mocks__/hyperliquidMock.d.mts.map +0 -1
  25. package/dist/__mocks__/hyperliquidMock.mjs +0 -65
  26. package/dist/__mocks__/hyperliquidMock.mjs.map +0 -1
  27. package/dist/__mocks__/providerMocks.cjs +0 -144
  28. package/dist/__mocks__/providerMocks.cjs.map +0 -1
  29. package/dist/__mocks__/providerMocks.d.cts +0 -44
  30. package/dist/__mocks__/providerMocks.d.cts.map +0 -1
  31. package/dist/__mocks__/providerMocks.d.mts +0 -44
  32. package/dist/__mocks__/providerMocks.d.mts.map +0 -1
  33. package/dist/__mocks__/providerMocks.mjs +0 -136
  34. package/dist/__mocks__/providerMocks.mjs.map +0 -1
  35. package/dist/__mocks__/serviceMocks.cjs +0 -187
  36. package/dist/__mocks__/serviceMocks.cjs.map +0 -1
  37. package/dist/__mocks__/serviceMocks.d.cts +0 -58
  38. package/dist/__mocks__/serviceMocks.d.cts.map +0 -1
  39. package/dist/__mocks__/serviceMocks.d.mts +0 -58
  40. package/dist/__mocks__/serviceMocks.d.mts.map +0 -1
  41. package/dist/__mocks__/serviceMocks.mjs +0 -180
  42. package/dist/__mocks__/serviceMocks.mjs.map +0 -1
  43. package/dist/aggregation/SubscriptionMultiplexer.cjs +0 -459
  44. package/dist/aggregation/SubscriptionMultiplexer.cjs.map +0 -1
  45. package/dist/aggregation/SubscriptionMultiplexer.d.cts +0 -222
  46. package/dist/aggregation/SubscriptionMultiplexer.d.cts.map +0 -1
  47. package/dist/aggregation/SubscriptionMultiplexer.d.mts +0 -222
  48. package/dist/aggregation/SubscriptionMultiplexer.d.mts.map +0 -1
  49. package/dist/aggregation/SubscriptionMultiplexer.mjs +0 -455
  50. package/dist/aggregation/SubscriptionMultiplexer.mjs.map +0 -1
  51. package/dist/aggregation/index.cjs +0 -9
  52. package/dist/aggregation/index.cjs.map +0 -1
  53. package/dist/aggregation/index.d.cts +0 -6
  54. package/dist/aggregation/index.d.cts.map +0 -1
  55. package/dist/aggregation/index.d.mts +0 -6
  56. package/dist/aggregation/index.d.mts.map +0 -1
  57. package/dist/aggregation/index.mjs +0 -5
  58. package/dist/aggregation/index.mjs.map +0 -1
  59. package/dist/constants/eventNames.cjs +0 -117
  60. package/dist/constants/eventNames.cjs.map +0 -1
  61. package/dist/constants/eventNames.d.cts +0 -106
  62. package/dist/constants/eventNames.d.cts.map +0 -1
  63. package/dist/constants/eventNames.d.mts +0 -106
  64. package/dist/constants/eventNames.d.mts.map +0 -1
  65. package/dist/constants/eventNames.mjs +0 -114
  66. package/dist/constants/eventNames.mjs.map +0 -1
  67. package/dist/constants/hyperLiquidConfig.cjs +0 -366
  68. package/dist/constants/hyperLiquidConfig.cjs.map +0 -1
  69. package/dist/constants/hyperLiquidConfig.d.cts +0 -276
  70. package/dist/constants/hyperLiquidConfig.d.cts.map +0 -1
  71. package/dist/constants/hyperLiquidConfig.d.mts +0 -276
  72. package/dist/constants/hyperLiquidConfig.d.mts.map +0 -1
  73. package/dist/constants/hyperLiquidConfig.mjs +0 -357
  74. package/dist/constants/hyperLiquidConfig.mjs.map +0 -1
  75. package/dist/constants/index.cjs +0 -23
  76. package/dist/constants/index.cjs.map +0 -1
  77. package/dist/constants/index.d.cts +0 -7
  78. package/dist/constants/index.d.cts.map +0 -1
  79. package/dist/constants/index.d.mts +0 -7
  80. package/dist/constants/index.d.mts.map +0 -1
  81. package/dist/constants/index.mjs +0 -7
  82. package/dist/constants/index.mjs.map +0 -1
  83. package/dist/constants/orderTypes.cjs +0 -31
  84. package/dist/constants/orderTypes.cjs.map +0 -1
  85. package/dist/constants/orderTypes.d.cts +0 -19
  86. package/dist/constants/orderTypes.d.cts.map +0 -1
  87. package/dist/constants/orderTypes.d.mts +0 -19
  88. package/dist/constants/orderTypes.d.mts.map +0 -1
  89. package/dist/constants/orderTypes.mjs +0 -27
  90. package/dist/constants/orderTypes.mjs.map +0 -1
  91. package/dist/constants/performanceMetrics.cjs +0 -61
  92. package/dist/constants/performanceMetrics.cjs.map +0 -1
  93. package/dist/constants/performanceMetrics.d.cts +0 -44
  94. package/dist/constants/performanceMetrics.d.cts.map +0 -1
  95. package/dist/constants/performanceMetrics.d.mts +0 -44
  96. package/dist/constants/performanceMetrics.d.mts.map +0 -1
  97. package/dist/constants/performanceMetrics.mjs +0 -58
  98. package/dist/constants/performanceMetrics.mjs.map +0 -1
  99. package/dist/constants/perpsConfig.cjs +0 -461
  100. package/dist/constants/perpsConfig.cjs.map +0 -1
  101. package/dist/constants/perpsConfig.d.cts +0 -343
  102. package/dist/constants/perpsConfig.d.cts.map +0 -1
  103. package/dist/constants/perpsConfig.d.mts +0 -343
  104. package/dist/constants/perpsConfig.d.mts.map +0 -1
  105. package/dist/constants/perpsConfig.mjs +0 -458
  106. package/dist/constants/perpsConfig.mjs.map +0 -1
  107. package/dist/constants/perpsErrorCodes.cjs +0 -79
  108. package/dist/constants/perpsErrorCodes.cjs.map +0 -1
  109. package/dist/constants/perpsErrorCodes.d.cts +0 -64
  110. package/dist/constants/perpsErrorCodes.d.cts.map +0 -1
  111. package/dist/constants/perpsErrorCodes.d.mts +0 -64
  112. package/dist/constants/perpsErrorCodes.d.mts.map +0 -1
  113. package/dist/constants/perpsErrorCodes.mjs +0 -76
  114. package/dist/constants/perpsErrorCodes.mjs.map +0 -1
  115. package/dist/platform-services/HyperLiquidClientService.cjs +0 -857
  116. package/dist/platform-services/HyperLiquidClientService.cjs.map +0 -1
  117. package/dist/platform-services/HyperLiquidClientService.d.cts +0 -263
  118. package/dist/platform-services/HyperLiquidClientService.d.cts.map +0 -1
  119. package/dist/platform-services/HyperLiquidClientService.d.mts +0 -263
  120. package/dist/platform-services/HyperLiquidClientService.d.mts.map +0 -1
  121. package/dist/platform-services/HyperLiquidClientService.mjs +0 -853
  122. package/dist/platform-services/HyperLiquidClientService.mjs.map +0 -1
  123. package/dist/platform-services/HyperLiquidSubscriptionService.cjs +0 -2170
  124. package/dist/platform-services/HyperLiquidSubscriptionService.cjs.map +0 -1
  125. package/dist/platform-services/HyperLiquidSubscriptionService.d.cts +0 -424
  126. package/dist/platform-services/HyperLiquidSubscriptionService.d.cts.map +0 -1
  127. package/dist/platform-services/HyperLiquidSubscriptionService.d.mts +0 -424
  128. package/dist/platform-services/HyperLiquidSubscriptionService.d.mts.map +0 -1
  129. package/dist/platform-services/HyperLiquidSubscriptionService.mjs +0 -2166
  130. package/dist/platform-services/HyperLiquidSubscriptionService.mjs.map +0 -1
  131. package/dist/platform-services/HyperLiquidWalletService.cjs +0 -140
  132. package/dist/platform-services/HyperLiquidWalletService.cjs.map +0 -1
  133. package/dist/platform-services/HyperLiquidWalletService.d.cts +0 -78
  134. package/dist/platform-services/HyperLiquidWalletService.d.cts.map +0 -1
  135. package/dist/platform-services/HyperLiquidWalletService.d.mts +0 -78
  136. package/dist/platform-services/HyperLiquidWalletService.d.mts.map +0 -1
  137. package/dist/platform-services/HyperLiquidWalletService.mjs +0 -136
  138. package/dist/platform-services/HyperLiquidWalletService.mjs.map +0 -1
  139. package/dist/providers/AggregatedPerpsProvider.cjs +0 -777
  140. package/dist/providers/AggregatedPerpsProvider.cjs.map +0 -1
  141. package/dist/providers/AggregatedPerpsProvider.d.cts +0 -466
  142. package/dist/providers/AggregatedPerpsProvider.d.cts.map +0 -1
  143. package/dist/providers/AggregatedPerpsProvider.d.mts +0 -466
  144. package/dist/providers/AggregatedPerpsProvider.d.mts.map +0 -1
  145. package/dist/providers/AggregatedPerpsProvider.mjs +0 -773
  146. package/dist/providers/AggregatedPerpsProvider.mjs.map +0 -1
  147. package/dist/providers/HyperLiquidProvider.cjs +0 -5172
  148. package/dist/providers/HyperLiquidProvider.cjs.map +0 -1
  149. package/dist/providers/HyperLiquidProvider.d.cts +0 -881
  150. package/dist/providers/HyperLiquidProvider.d.cts.map +0 -1
  151. package/dist/providers/HyperLiquidProvider.d.mts +0 -881
  152. package/dist/providers/HyperLiquidProvider.d.mts.map +0 -1
  153. package/dist/providers/HyperLiquidProvider.mjs +0 -5168
  154. package/dist/providers/HyperLiquidProvider.mjs.map +0 -1
  155. package/dist/providers/index.cjs +0 -11
  156. package/dist/providers/index.cjs.map +0 -1
  157. package/dist/providers/index.d.cts +0 -6
  158. package/dist/providers/index.d.cts.map +0 -1
  159. package/dist/providers/index.d.mts +0 -6
  160. package/dist/providers/index.d.mts.map +0 -1
  161. package/dist/providers/index.mjs +0 -6
  162. package/dist/providers/index.mjs.map +0 -1
  163. package/dist/routing/ProviderRouter.cjs +0 -148
  164. package/dist/routing/ProviderRouter.cjs.map +0 -1
  165. package/dist/routing/ProviderRouter.d.cts +0 -124
  166. package/dist/routing/ProviderRouter.d.cts.map +0 -1
  167. package/dist/routing/ProviderRouter.d.mts +0 -124
  168. package/dist/routing/ProviderRouter.d.mts.map +0 -1
  169. package/dist/routing/ProviderRouter.mjs +0 -144
  170. package/dist/routing/ProviderRouter.mjs.map +0 -1
  171. package/dist/routing/index.cjs +0 -9
  172. package/dist/routing/index.cjs.map +0 -1
  173. package/dist/routing/index.d.cts +0 -6
  174. package/dist/routing/index.d.cts.map +0 -1
  175. package/dist/routing/index.d.mts +0 -6
  176. package/dist/routing/index.d.mts.map +0 -1
  177. package/dist/routing/index.mjs +0 -5
  178. package/dist/routing/index.mjs.map +0 -1
  179. package/dist/selectors.cjs +0 -161
  180. package/dist/selectors.cjs.map +0 -1
  181. package/dist/selectors.d.cts +0 -345
  182. package/dist/selectors.d.cts.map +0 -1
  183. package/dist/selectors.d.mts +0 -345
  184. package/dist/selectors.d.mts.map +0 -1
  185. package/dist/selectors.mjs +0 -153
  186. package/dist/selectors.mjs.map +0 -1
  187. package/dist/services/AccountService.cjs +0 -313
  188. package/dist/services/AccountService.cjs.map +0 -1
  189. package/dist/services/AccountService.d.cts +0 -53
  190. package/dist/services/AccountService.d.cts.map +0 -1
  191. package/dist/services/AccountService.d.mts +0 -53
  192. package/dist/services/AccountService.d.mts.map +0 -1
  193. package/dist/services/AccountService.mjs +0 -309
  194. package/dist/services/AccountService.mjs.map +0 -1
  195. package/dist/services/DataLakeService.cjs +0 -219
  196. package/dist/services/DataLakeService.cjs.map +0 -1
  197. package/dist/services/DataLakeService.d.cts +0 -49
  198. package/dist/services/DataLakeService.d.cts.map +0 -1
  199. package/dist/services/DataLakeService.d.mts +0 -49
  200. package/dist/services/DataLakeService.d.mts.map +0 -1
  201. package/dist/services/DataLakeService.mjs +0 -215
  202. package/dist/services/DataLakeService.mjs.map +0 -1
  203. package/dist/services/DepositService.cjs +0 -96
  204. package/dist/services/DepositService.cjs.map +0 -1
  205. package/dist/services/DepositService.d.cts +0 -37
  206. package/dist/services/DepositService.d.cts.map +0 -1
  207. package/dist/services/DepositService.d.mts +0 -37
  208. package/dist/services/DepositService.d.mts.map +0 -1
  209. package/dist/services/DepositService.mjs +0 -92
  210. package/dist/services/DepositService.mjs.map +0 -1
  211. package/dist/services/EligibilityService.cjs +0 -156
  212. package/dist/services/EligibilityService.cjs.map +0 -1
  213. package/dist/services/EligibilityService.d.cts +0 -48
  214. package/dist/services/EligibilityService.d.cts.map +0 -1
  215. package/dist/services/EligibilityService.d.mts +0 -48
  216. package/dist/services/EligibilityService.d.mts.map +0 -1
  217. package/dist/services/EligibilityService.mjs +0 -152
  218. package/dist/services/EligibilityService.mjs.map +0 -1
  219. package/dist/services/FeatureFlagConfigurationService.cjs +0 -258
  220. package/dist/services/FeatureFlagConfigurationService.cjs.map +0 -1
  221. package/dist/services/FeatureFlagConfigurationService.d.cts +0 -100
  222. package/dist/services/FeatureFlagConfigurationService.d.cts.map +0 -1
  223. package/dist/services/FeatureFlagConfigurationService.d.mts +0 -100
  224. package/dist/services/FeatureFlagConfigurationService.d.mts.map +0 -1
  225. package/dist/services/FeatureFlagConfigurationService.mjs +0 -254
  226. package/dist/services/FeatureFlagConfigurationService.mjs.map +0 -1
  227. package/dist/services/MarketDataService.cjs +0 -875
  228. package/dist/services/MarketDataService.cjs.map +0 -1
  229. package/dist/services/MarketDataService.d.cts +0 -289
  230. package/dist/services/MarketDataService.d.cts.map +0 -1
  231. package/dist/services/MarketDataService.d.mts +0 -289
  232. package/dist/services/MarketDataService.d.mts.map +0 -1
  233. package/dist/services/MarketDataService.mjs +0 -871
  234. package/dist/services/MarketDataService.mjs.map +0 -1
  235. package/dist/services/RewardsIntegrationService.cjs +0 -94
  236. package/dist/services/RewardsIntegrationService.cjs.map +0 -1
  237. package/dist/services/RewardsIntegrationService.d.cts +0 -30
  238. package/dist/services/RewardsIntegrationService.d.cts.map +0 -1
  239. package/dist/services/RewardsIntegrationService.d.mts +0 -30
  240. package/dist/services/RewardsIntegrationService.d.mts.map +0 -1
  241. package/dist/services/RewardsIntegrationService.mjs +0 -90
  242. package/dist/services/RewardsIntegrationService.mjs.map +0 -1
  243. package/dist/services/ServiceContext.cjs +0 -3
  244. package/dist/services/ServiceContext.cjs.map +0 -1
  245. package/dist/services/ServiceContext.d.cts +0 -110
  246. package/dist/services/ServiceContext.d.cts.map +0 -1
  247. package/dist/services/ServiceContext.d.mts +0 -110
  248. package/dist/services/ServiceContext.d.mts.map +0 -1
  249. package/dist/services/ServiceContext.mjs +0 -2
  250. package/dist/services/ServiceContext.mjs.map +0 -1
  251. package/dist/services/TradingService.cjs +0 -1481
  252. package/dist/services/TradingService.cjs.map +0 -1
  253. package/dist/services/TradingService.d.cts +0 -308
  254. package/dist/services/TradingService.d.cts.map +0 -1
  255. package/dist/services/TradingService.d.mts +0 -308
  256. package/dist/services/TradingService.d.mts.map +0 -1
  257. package/dist/services/TradingService.mjs +0 -1477
  258. package/dist/services/TradingService.mjs.map +0 -1
  259. package/dist/services/index.cjs +0 -26
  260. package/dist/services/index.cjs.map +0 -1
  261. package/dist/services/index.d.cts +0 -11
  262. package/dist/services/index.d.cts.map +0 -1
  263. package/dist/services/index.d.mts +0 -11
  264. package/dist/services/index.d.mts.map +0 -1
  265. package/dist/services/index.mjs +0 -10
  266. package/dist/services/index.mjs.map +0 -1
  267. package/dist/services/utils.cjs +0 -16
  268. package/dist/services/utils.cjs.map +0 -1
  269. package/dist/services/utils.d.cts +0 -8
  270. package/dist/services/utils.d.cts.map +0 -1
  271. package/dist/services/utils.d.mts +0 -8
  272. package/dist/services/utils.d.mts.map +0 -1
  273. package/dist/services/utils.mjs +0 -12
  274. package/dist/services/utils.mjs.map +0 -1
  275. package/dist/types/chart.cjs +0 -42
  276. package/dist/types/chart.cjs.map +0 -1
  277. package/dist/types/chart.d.cts +0 -62
  278. package/dist/types/chart.d.cts.map +0 -1
  279. package/dist/types/chart.d.mts +0 -62
  280. package/dist/types/chart.d.mts.map +0 -1
  281. package/dist/types/chart.mjs +0 -39
  282. package/dist/types/chart.mjs.map +0 -1
  283. package/dist/types/hyperliquid-types.cjs +0 -3
  284. package/dist/types/hyperliquid-types.cjs.map +0 -1
  285. package/dist/types/hyperliquid-types.d.cts +0 -52
  286. package/dist/types/hyperliquid-types.d.cts.map +0 -1
  287. package/dist/types/hyperliquid-types.d.mts +0 -52
  288. package/dist/types/hyperliquid-types.d.mts.map +0 -1
  289. package/dist/types/hyperliquid-types.mjs +0 -2
  290. package/dist/types/hyperliquid-types.mjs.map +0 -1
  291. package/dist/types/index.cjs +0 -96
  292. package/dist/types/index.cjs.map +0 -1
  293. package/dist/types/index.d.cts +0 -1153
  294. package/dist/types/index.d.cts.map +0 -1
  295. package/dist/types/index.d.mts +0 -1153
  296. package/dist/types/index.d.mts.map +0 -1
  297. package/dist/types/index.mjs +0 -79
  298. package/dist/types/index.mjs.map +0 -1
  299. package/dist/types/transactionTypes.cjs +0 -28
  300. package/dist/types/transactionTypes.cjs.map +0 -1
  301. package/dist/types/transactionTypes.d.cts +0 -64
  302. package/dist/types/transactionTypes.d.cts.map +0 -1
  303. package/dist/types/transactionTypes.d.mts +0 -64
  304. package/dist/types/transactionTypes.d.mts.map +0 -1
  305. package/dist/types/transactionTypes.mjs +0 -23
  306. package/dist/types/transactionTypes.mjs.map +0 -1
  307. package/dist/utils/accountUtils.cjs +0 -65
  308. package/dist/utils/accountUtils.cjs.map +0 -1
  309. package/dist/utils/accountUtils.d.cts +0 -26
  310. package/dist/utils/accountUtils.d.cts.map +0 -1
  311. package/dist/utils/accountUtils.d.mts +0 -26
  312. package/dist/utils/accountUtils.d.mts.map +0 -1
  313. package/dist/utils/accountUtils.mjs +0 -61
  314. package/dist/utils/accountUtils.mjs.map +0 -1
  315. package/dist/utils/amountConversion.cjs +0 -61
  316. package/dist/utils/amountConversion.cjs.map +0 -1
  317. package/dist/utils/amountConversion.d.cts +0 -16
  318. package/dist/utils/amountConversion.d.cts.map +0 -1
  319. package/dist/utils/amountConversion.d.mts +0 -16
  320. package/dist/utils/amountConversion.d.mts.map +0 -1
  321. package/dist/utils/amountConversion.mjs +0 -54
  322. package/dist/utils/amountConversion.mjs.map +0 -1
  323. package/dist/utils/chartUtils.cjs +0 -98
  324. package/dist/utils/chartUtils.cjs.map +0 -1
  325. package/dist/utils/chartUtils.d.cts +0 -14
  326. package/dist/utils/chartUtils.d.cts.map +0 -1
  327. package/dist/utils/chartUtils.d.mts +0 -14
  328. package/dist/utils/chartUtils.d.mts.map +0 -1
  329. package/dist/utils/chartUtils.mjs +0 -94
  330. package/dist/utils/chartUtils.mjs.map +0 -1
  331. package/dist/utils/errorUtils.cjs +0 -22
  332. package/dist/utils/errorUtils.cjs.map +0 -1
  333. package/dist/utils/errorUtils.d.cts +0 -13
  334. package/dist/utils/errorUtils.d.cts.map +0 -1
  335. package/dist/utils/errorUtils.d.mts +0 -13
  336. package/dist/utils/errorUtils.d.mts.map +0 -1
  337. package/dist/utils/errorUtils.mjs +0 -18
  338. package/dist/utils/errorUtils.mjs.map +0 -1
  339. package/dist/utils/formatUtils.cjs +0 -987
  340. package/dist/utils/formatUtils.cjs.map +0 -1
  341. package/dist/utils/formatUtils.d.cts +0 -387
  342. package/dist/utils/formatUtils.d.cts.map +0 -1
  343. package/dist/utils/formatUtils.d.mts +0 -387
  344. package/dist/utils/formatUtils.d.mts.map +0 -1
  345. package/dist/utils/formatUtils.mjs +0 -966
  346. package/dist/utils/formatUtils.mjs.map +0 -1
  347. package/dist/utils/hyperLiquidAdapter.cjs +0 -454
  348. package/dist/utils/hyperLiquidAdapter.cjs.map +0 -1
  349. package/dist/utils/hyperLiquidAdapter.d.cts +0 -158
  350. package/dist/utils/hyperLiquidAdapter.d.cts.map +0 -1
  351. package/dist/utils/hyperLiquidAdapter.d.mts +0 -158
  352. package/dist/utils/hyperLiquidAdapter.d.mts.map +0 -1
  353. package/dist/utils/hyperLiquidAdapter.mjs +0 -439
  354. package/dist/utils/hyperLiquidAdapter.mjs.map +0 -1
  355. package/dist/utils/hyperLiquidOrderBookProcessor.cjs +0 -89
  356. package/dist/utils/hyperLiquidOrderBookProcessor.cjs.map +0 -1
  357. package/dist/utils/hyperLiquidOrderBookProcessor.d.cts +0 -58
  358. package/dist/utils/hyperLiquidOrderBookProcessor.d.cts.map +0 -1
  359. package/dist/utils/hyperLiquidOrderBookProcessor.d.mts +0 -58
  360. package/dist/utils/hyperLiquidOrderBookProcessor.d.mts.map +0 -1
  361. package/dist/utils/hyperLiquidOrderBookProcessor.mjs +0 -84
  362. package/dist/utils/hyperLiquidOrderBookProcessor.mjs.map +0 -1
  363. package/dist/utils/hyperLiquidValidation.cjs +0 -426
  364. package/dist/utils/hyperLiquidValidation.cjs.map +0 -1
  365. package/dist/utils/hyperLiquidValidation.d.cts +0 -143
  366. package/dist/utils/hyperLiquidValidation.d.cts.map +0 -1
  367. package/dist/utils/hyperLiquidValidation.d.mts +0 -143
  368. package/dist/utils/hyperLiquidValidation.d.mts.map +0 -1
  369. package/dist/utils/hyperLiquidValidation.mjs +0 -413
  370. package/dist/utils/hyperLiquidValidation.mjs.map +0 -1
  371. package/dist/utils/idUtils.cjs +0 -50
  372. package/dist/utils/idUtils.cjs.map +0 -1
  373. package/dist/utils/idUtils.d.cts +0 -38
  374. package/dist/utils/idUtils.d.cts.map +0 -1
  375. package/dist/utils/idUtils.d.mts +0 -38
  376. package/dist/utils/idUtils.d.mts.map +0 -1
  377. package/dist/utils/idUtils.mjs +0 -42
  378. package/dist/utils/idUtils.mjs.map +0 -1
  379. package/dist/utils/marginUtils.cjs +0 -137
  380. package/dist/utils/marginUtils.cjs.map +0 -1
  381. package/dist/utils/marginUtils.d.cts +0 -64
  382. package/dist/utils/marginUtils.d.cts.map +0 -1
  383. package/dist/utils/marginUtils.d.mts +0 -64
  384. package/dist/utils/marginUtils.d.mts.map +0 -1
  385. package/dist/utils/marginUtils.mjs +0 -131
  386. package/dist/utils/marginUtils.mjs.map +0 -1
  387. package/dist/utils/marketDataTransform.cjs +0 -227
  388. package/dist/utils/marketDataTransform.cjs.map +0 -1
  389. package/dist/utils/marketDataTransform.d.cts +0 -45
  390. package/dist/utils/marketDataTransform.d.cts.map +0 -1
  391. package/dist/utils/marketDataTransform.d.mts +0 -45
  392. package/dist/utils/marketDataTransform.d.mts.map +0 -1
  393. package/dist/utils/marketDataTransform.mjs +0 -220
  394. package/dist/utils/marketDataTransform.mjs.map +0 -1
  395. package/dist/utils/marketUtils.cjs +0 -420
  396. package/dist/utils/marketUtils.cjs.map +0 -1
  397. package/dist/utils/marketUtils.d.cts +0 -227
  398. package/dist/utils/marketUtils.d.cts.map +0 -1
  399. package/dist/utils/marketUtils.d.mts +0 -227
  400. package/dist/utils/marketUtils.d.mts.map +0 -1
  401. package/dist/utils/marketUtils.mjs +0 -404
  402. package/dist/utils/marketUtils.mjs.map +0 -1
  403. package/dist/utils/orderBookGrouping.cjs +0 -151
  404. package/dist/utils/orderBookGrouping.cjs.map +0 -1
  405. package/dist/utils/orderBookGrouping.d.cts +0 -76
  406. package/dist/utils/orderBookGrouping.d.cts.map +0 -1
  407. package/dist/utils/orderBookGrouping.d.mts +0 -76
  408. package/dist/utils/orderBookGrouping.d.mts.map +0 -1
  409. package/dist/utils/orderBookGrouping.mjs +0 -143
  410. package/dist/utils/orderBookGrouping.mjs.map +0 -1
  411. package/dist/utils/orderCalculations.cjs +0 -283
  412. package/dist/utils/orderCalculations.cjs.map +0 -1
  413. package/dist/utils/orderCalculations.d.cts +0 -107
  414. package/dist/utils/orderCalculations.d.cts.map +0 -1
  415. package/dist/utils/orderCalculations.d.mts +0 -107
  416. package/dist/utils/orderCalculations.d.mts.map +0 -1
  417. package/dist/utils/orderCalculations.mjs +0 -274
  418. package/dist/utils/orderCalculations.mjs.map +0 -1
  419. package/dist/utils/orderUtils.cjs +0 -159
  420. package/dist/utils/orderUtils.cjs.map +0 -1
  421. package/dist/utils/orderUtils.d.cts +0 -66
  422. package/dist/utils/orderUtils.d.cts.map +0 -1
  423. package/dist/utils/orderUtils.d.mts +0 -66
  424. package/dist/utils/orderUtils.d.mts.map +0 -1
  425. package/dist/utils/orderUtils.mjs +0 -151
  426. package/dist/utils/orderUtils.mjs.map +0 -1
  427. package/dist/utils/pnlCalculations.cjs +0 -107
  428. package/dist/utils/pnlCalculations.cjs.map +0 -1
  429. package/dist/utils/pnlCalculations.d.cts +0 -79
  430. package/dist/utils/pnlCalculations.d.cts.map +0 -1
  431. package/dist/utils/pnlCalculations.d.mts +0 -79
  432. package/dist/utils/pnlCalculations.d.mts.map +0 -1
  433. package/dist/utils/pnlCalculations.mjs +0 -97
  434. package/dist/utils/pnlCalculations.mjs.map +0 -1
  435. package/dist/utils/positionCalculations.cjs +0 -176
  436. package/dist/utils/positionCalculations.cjs.map +0 -1
  437. package/dist/utils/positionCalculations.d.cts +0 -85
  438. package/dist/utils/positionCalculations.d.cts.map +0 -1
  439. package/dist/utils/positionCalculations.d.mts +0 -85
  440. package/dist/utils/positionCalculations.d.mts.map +0 -1
  441. package/dist/utils/positionCalculations.mjs +0 -165
  442. package/dist/utils/positionCalculations.mjs.map +0 -1
  443. package/dist/utils/sortMarkets.cjs +0 -88
  444. package/dist/utils/sortMarkets.cjs.map +0 -1
  445. package/dist/utils/sortMarkets.d.cts +0 -21
  446. package/dist/utils/sortMarkets.d.cts.map +0 -1
  447. package/dist/utils/sortMarkets.d.mts +0 -21
  448. package/dist/utils/sortMarkets.d.mts.map +0 -1
  449. package/dist/utils/sortMarkets.mjs +0 -84
  450. package/dist/utils/sortMarkets.mjs.map +0 -1
  451. package/dist/utils/standaloneInfoClient.cjs +0 -34
  452. package/dist/utils/standaloneInfoClient.cjs.map +0 -1
  453. package/dist/utils/standaloneInfoClient.d.cts +0 -31
  454. package/dist/utils/standaloneInfoClient.d.cts.map +0 -1
  455. package/dist/utils/standaloneInfoClient.d.mts +0 -31
  456. package/dist/utils/standaloneInfoClient.d.mts.map +0 -1
  457. package/dist/utils/standaloneInfoClient.mjs +0 -30
  458. package/dist/utils/standaloneInfoClient.mjs.map +0 -1
  459. package/dist/utils/stringParseUtils.cjs +0 -49
  460. package/dist/utils/stringParseUtils.cjs.map +0 -1
  461. package/dist/utils/stringParseUtils.d.cts +0 -35
  462. package/dist/utils/stringParseUtils.d.cts.map +0 -1
  463. package/dist/utils/stringParseUtils.d.mts +0 -35
  464. package/dist/utils/stringParseUtils.d.mts.map +0 -1
  465. package/dist/utils/stringParseUtils.mjs +0 -44
  466. package/dist/utils/stringParseUtils.mjs.map +0 -1
  467. package/dist/utils/time.cjs +0 -37
  468. package/dist/utils/time.cjs.map +0 -1
  469. package/dist/utils/time.d.cts +0 -17
  470. package/dist/utils/time.d.cts.map +0 -1
  471. package/dist/utils/time.d.mts +0 -17
  472. package/dist/utils/time.d.mts.map +0 -1
  473. package/dist/utils/time.mjs +0 -33
  474. package/dist/utils/time.mjs.map +0 -1
  475. package/dist/utils/tpslValidation.cjs +0 -505
  476. package/dist/utils/tpslValidation.cjs.map +0 -1
  477. package/dist/utils/tpslValidation.d.cts +0 -182
  478. package/dist/utils/tpslValidation.d.cts.map +0 -1
  479. package/dist/utils/tpslValidation.d.mts +0 -182
  480. package/dist/utils/tpslValidation.d.mts.map +0 -1
  481. package/dist/utils/tpslValidation.mjs +0 -482
  482. package/dist/utils/tpslValidation.mjs.map +0 -1
  483. package/dist/utils/transactionUtils.cjs +0 -36
  484. package/dist/utils/transactionUtils.cjs.map +0 -1
  485. package/dist/utils/transactionUtils.d.cts +0 -17
  486. package/dist/utils/transactionUtils.d.cts.map +0 -1
  487. package/dist/utils/transactionUtils.d.mts +0 -17
  488. package/dist/utils/transactionUtils.d.mts.map +0 -1
  489. package/dist/utils/transactionUtils.mjs +0 -32
  490. package/dist/utils/transactionUtils.mjs.map +0 -1
  491. package/dist/utils/wait.cjs +0 -12
  492. package/dist/utils/wait.cjs.map +0 -1
  493. package/dist/utils/wait.d.cts +0 -8
  494. package/dist/utils/wait.d.cts.map +0 -1
  495. package/dist/utils/wait.d.mts +0 -8
  496. package/dist/utils/wait.d.mts.map +0 -1
  497. package/dist/utils/wait.mjs +0 -8
  498. package/dist/utils/wait.mjs.map +0 -1
@@ -1,966 +0,0 @@
1
- /**
2
- * Shared formatting utilities for Perps components
3
- */
4
- import { BigNumber } from "bignumber.js";
5
- import { FUNDING_RATE_CONFIG, PERPS_CONSTANTS, DECIMAL_PRECISION_CONFIG } from "../constants/perpsConfig.mjs";
6
- /**
7
- * Price threshold constants for PRICE_RANGES_UNIVERSAL
8
- * These define the boundaries between different formatting ranges
9
- */
10
- export const PRICE_THRESHOLD = {
11
- /** Very high values boundary (> $100k) */
12
- VERY_HIGH: 100000,
13
- /** High values boundary (> $10k) */
14
- HIGH: 10000,
15
- /** Large values boundary (> $1k) */
16
- LARGE: 1000,
17
- /** Medium values boundary (> $100) */
18
- MEDIUM: 100,
19
- /** Medium-low values boundary (> $10) */
20
- MEDIUM_LOW: 10,
21
- /** Low values boundary (>= $0.01) */
22
- LOW: 0.01,
23
- /**
24
- * Very small values threshold (< $0.01)
25
- * This is the minimum value for formatWithThreshold and should align with
26
- * the 6 decimal maximum (0.000001 is the smallest representable value)
27
- */
28
- VERY_SMALL: 0.000001,
29
- };
30
- /**
31
- * Creates an Intl.NumberFormat formatter with memoization
32
- *
33
- * @param locale - The locale for formatting
34
- * @param options - NumberFormat options
35
- * @returns Formatted number formatter
36
- */
37
- const getIntlNumberFormatter = (locale, options) => {
38
- return new Intl.NumberFormat(locale, options);
39
- };
40
- /**
41
- * Creates an Intl.DateTimeFormat formatter
42
- *
43
- * @param locale - The locale for formatting
44
- * @param options - DateTimeFormat options
45
- * @returns Formatted date/time formatter
46
- */
47
- const getIntlDateTimeFormatter = (locale, options) => {
48
- return new Intl.DateTimeFormat(locale, options);
49
- };
50
- /**
51
- * Formats a value with threshold handling (shows "< threshold" for small values)
52
- *
53
- * @param value - The value to format
54
- * @param threshold - The threshold for showing "< threshold"
55
- * @param locale - The locale for formatting
56
- * @param options - NumberFormat options
57
- * @returns Formatted string
58
- */
59
- const formatWithThreshold = (value, threshold, locale, options) => {
60
- if (Math.abs(value) < threshold && value !== 0) {
61
- const formatter = getIntlNumberFormatter(locale, options);
62
- const formattedThreshold = formatter.format(threshold);
63
- return value < 0 ? `> -${formattedThreshold}` : `< ${formattedThreshold}`;
64
- }
65
- return getIntlNumberFormatter(locale, options).format(value);
66
- };
67
- /**
68
- * Formats a number to a specific number of significant digits
69
- * Strips trailing zeros unless minDecimals requires them
70
- *
71
- * @param value - The numeric value to format
72
- * @param significantDigits - Number of significant digits to maintain
73
- * @param minDecimals - Minimum decimal places to show (may add zeros)
74
- * @param maxDecimals - Maximum decimal places allowed
75
- * @returns Formatted number with appropriate precision, trailing zeros removed
76
- */
77
- export function formatWithSignificantDigits(value, significantDigits, minDecimals, maxDecimals) {
78
- // Handle special cases
79
- if (value === 0) {
80
- // Return zero with no trailing decimals by default (matches stripTrailingZeros behavior)
81
- // Can be overridden by explicit minDecimals if needed
82
- return { value: 0, decimals: minDecimals ?? 0 };
83
- }
84
- const absValue = Math.abs(value);
85
- // For numbers >= 1, calculate decimals based on magnitude to achieve target significant figures
86
- // This ensures consistent precision across different price ranges:
87
- // Examples with 4 significant figures:
88
- // $123,456.78 -> $123,456.78 (>=1000: 2 decimals minimum, 8 sig figs)
89
- // $456.12 -> $456.12 (>=10: 2 decimals minimum, 5 sig figs)
90
- // $56.123 -> $56.123 (>=10: 2 decimals minimum, 5 sig figs)
91
- // $5.123 -> $5.123 ($1-$10: 3 decimals = 4 sig figs)
92
- // $2.801 -> $2.801 ($1-$10: 3 decimals = 4 sig figs)
93
- // $1.234 -> $1.234 ($1-$10: 3 decimals = 4 sig figs)
94
- if (absValue >= 1) {
95
- let targetDecimals;
96
- // Calculate decimals needed based on integer digits to achieve target significant figures
97
- // For $38.388 with 5 sig figs: 2 integer digits, need 3 decimals (3,8,3,8,8)
98
- // For $123.45 with 5 sig figs: 3 integer digits, need 2 decimals (1,2,3,4,5)
99
- const integerDigits = Math.floor(Math.log10(absValue)) + 1;
100
- const decimalsNeeded = significantDigits - integerDigits;
101
- targetDecimals = Math.max(decimalsNeeded, 0); // Can't have negative decimals
102
- // Apply explicit minimum decimals constraint if provided (for special cases)
103
- if (minDecimals !== undefined && targetDecimals < minDecimals) {
104
- targetDecimals = minDecimals;
105
- }
106
- // Apply maximum decimals constraint if specified
107
- const finalDecimals = maxDecimals === undefined
108
- ? targetDecimals
109
- : Math.min(targetDecimals, maxDecimals);
110
- // Round to prevent floating-point artifacts (e.g., 2.820000000000003 -> 2.82)
111
- const roundedValue = Number(value.toFixed(finalDecimals));
112
- return {
113
- value: roundedValue,
114
- decimals: finalDecimals,
115
- };
116
- }
117
- // For numbers < 1, use toPrecision to limit to significantDigits
118
- // Examples: 0.1234, 0.01234 should show exactly 4 sig figs
119
- const precisionStr = absValue.toPrecision(significantDigits);
120
- const precisionNum = parseFloat(precisionStr);
121
- // Convert to string to count actual decimals after trailing zeros are removed
122
- const valueStr = precisionNum.toString();
123
- const [, decPart = ''] = valueStr.split('.');
124
- let actualDecimals = decPart.length;
125
- // Apply min/max decimal constraints
126
- if (minDecimals !== undefined && actualDecimals < minDecimals) {
127
- actualDecimals = minDecimals; // Will add zeros if needed
128
- }
129
- if (maxDecimals !== undefined && actualDecimals > maxDecimals) {
130
- actualDecimals = maxDecimals;
131
- }
132
- // Return the value with sign restored and decimal count
133
- return {
134
- value: value < 0 ? -precisionNum : precisionNum,
135
- decimals: actualDecimals,
136
- };
137
- }
138
- /**
139
- * Counts the number of significant figures in a numeric string
140
- * This matches HyperLiquid's validation rules:
141
- * - Trailing decimal zeros are trimmed first (via parseFloat().toString())
142
- * - Count non-zero integer digits (without leading zeros)
143
- * - Count ALL decimal digits (including leading zeros after decimal point)
144
- *
145
- * @param priceString - The price value as a string (may include $ or ,)
146
- * @returns The count of significant figures
147
- *
148
- * @example
149
- * countSignificantFigures('123.45') // 5 (3 integer + 2 decimal)
150
- * countSignificantFigures('123.4500') // 5 (trailing zeros trimmed first)
151
- * countSignificantFigures('0.000123') // 6 (0 integer + 6 decimal)
152
- * countSignificantFigures('12.345') // 5 (2 integer + 3 decimal)
153
- * countSignificantFigures('12000') // 2 (trailing zeros in integer not counted)
154
- */
155
- export const countSignificantFigures = (priceString) => {
156
- if (!priceString) {
157
- return 0;
158
- }
159
- // Clean the string - remove currency symbols and commas
160
- const cleaned = priceString.replace(/[$,]/gu, '').trim();
161
- // Parse and convert back to string to trim trailing decimal zeros
162
- // This matches formatHyperLiquidPrice: parseFloat(formattedPrice).toString()
163
- const parsedValue = parseFloat(cleaned);
164
- if (isNaN(parsedValue) || parsedValue === 0) {
165
- return 0;
166
- }
167
- // Normalize to remove trailing zeros (e.g., "123.4500" -> "123.45")
168
- const normalized = parsedValue.toString();
169
- // Split into integer and decimal parts
170
- const [integerPart, decimalPart = ''] = normalized.split('.');
171
- // Remove leading zeros and negative sign from integer part
172
- const trimmedInteger = integerPart.replace(/^-?0*/u, '') || '';
173
- // For integers without decimal, trailing zeros are ambiguous
174
- // We treat them as not significant (matching HyperLiquid behavior)
175
- const effectiveIntegerLength = decimalPart
176
- ? trimmedInteger.length
177
- : trimmedInteger.replace(/0+$/u, '').length ||
178
- (trimmedInteger.length > 0 ? 1 : 0);
179
- // Count ALL decimal digits (including leading zeros like 0.000123)
180
- // This matches HyperLiquid's validation behavior
181
- return effectiveIntegerLength + decimalPart.length;
182
- };
183
- /**
184
- * Checks if a price will be rounded due to exceeding significant figures
185
- * Only applies when the price has decimals - integers are never rounded
186
- * This matches the behavior in formatHyperLiquidPrice
187
- *
188
- * @param priceString - The price value as a string
189
- * @param maxSigFigs - Maximum allowed significant figures (default: MAX_SIGNIFICANT_FIGURES from config)
190
- * @returns true if the price will be rounded, false otherwise
191
- */
192
- export const hasExceededSignificantFigures = (priceString, maxSigFigs = DECIMAL_PRECISION_CONFIG.MaxSignificantFigures) => {
193
- if (!priceString || priceString.trim() === '') {
194
- return false;
195
- }
196
- // Clean the string and normalize (trim trailing zeros)
197
- const cleaned = priceString.replace(/[$,]/gu, '').trim();
198
- const parsedValue = parseFloat(cleaned);
199
- if (isNaN(parsedValue)) {
200
- return false;
201
- }
202
- // Normalize to check for decimal presence after trimming trailing zeros
203
- const normalized = parsedValue.toString();
204
- // If there's no decimal part after normalization, the price won't be rounded
205
- if (!normalized.includes('.')) {
206
- return false;
207
- }
208
- return countSignificantFigures(priceString) > maxSigFigs;
209
- };
210
- /**
211
- * Rounds a price string to the maximum allowed significant figures
212
- * Uses the same counting logic as countSignificantFigures:
213
- * - Count non-zero integer digits + ALL decimal digits (including leading zeros)
214
- *
215
- * @param priceString - The price value as a string
216
- * @param maxSigFigs - Maximum allowed significant figures (default: MAX_SIGNIFICANT_FIGURES from config)
217
- * @returns Price string rounded to max significant figures
218
- *
219
- * @example
220
- * roundToSignificantFigures('123.456') // '123.46' (3 int + 2 dec = 5)
221
- * roundToSignificantFigures('0.065242') // '0.06524' (0 int + 5 dec = 5)
222
- * roundToSignificantFigures('12345.67') // '12346' (5 int + 0 dec = 5)
223
- */
224
- export const roundToSignificantFigures = (priceString, maxSigFigs = DECIMAL_PRECISION_CONFIG.MaxSignificantFigures) => {
225
- if (!priceString || priceString.trim() === '') {
226
- return priceString;
227
- }
228
- const cleaned = priceString.replace(/[$,]/gu, '').trim();
229
- const parsedValue = Number.parseFloat(cleaned);
230
- if (Number.isNaN(parsedValue) || parsedValue === 0) {
231
- return priceString;
232
- }
233
- // Normalize to remove trailing zeros
234
- const normalized = parsedValue.toString();
235
- const [integerPart, decimalPart = ''] = normalized.split('.');
236
- // Count integer significant digits (without leading zeros)
237
- const trimmedInteger = integerPart.replace(/^-?0*/u, '') || '';
238
- const integerSigFigs = trimmedInteger.length;
239
- // If no decimal, return as is (integers are fine)
240
- if (!decimalPart) {
241
- return normalized;
242
- }
243
- // Calculate how many decimal digits we can keep
244
- const allowedDecimalDigits = maxSigFigs - integerSigFigs;
245
- if (allowedDecimalDigits <= 0) {
246
- // Round to integer
247
- return Math.round(parsedValue).toString();
248
- }
249
- if (decimalPart.length <= allowedDecimalDigits) {
250
- // Already within limit
251
- return normalized;
252
- }
253
- // Round to the allowed number of decimal places
254
- const rounded = parsedValue.toFixed(allowedDecimalDigits);
255
- // Remove trailing zeros
256
- return Number.parseFloat(rounded).toString();
257
- };
258
- /**
259
- * Minimal view fiat range configuration
260
- * Uses fiat-style stripping for clean currency display
261
- * Strips only .00 to avoid partial decimals like $1,250.1
262
- */
263
- export const PRICE_RANGES_MINIMAL_VIEW = [
264
- {
265
- // Large values (>= $1000): Strip .00 only ($5,000 not $5,000.00, but $5,000.10 stays)
266
- condition: (val) => Math.abs(val) >= PRICE_THRESHOLD.LARGE,
267
- minimumDecimals: 2,
268
- maximumDecimals: 2,
269
- threshold: PRICE_THRESHOLD.LARGE,
270
- stripTrailingZeros: true,
271
- fiatStyleStripping: true,
272
- },
273
- {
274
- // Small values (< $1000): Also use fiat-style stripping ($100 not $100.00, but $13.40 stays)
275
- condition: () => true,
276
- minimumDecimals: 2,
277
- maximumDecimals: 2,
278
- threshold: PRICE_THRESHOLD.LOW,
279
- stripTrailingZeros: true,
280
- fiatStyleStripping: true,
281
- },
282
- ];
283
- /**
284
- * Formats a balance value as USD currency with appropriate decimal places
285
- *
286
- * @param balance - Raw numeric balance value (e.g., 1234.56, not token minimal denomination)
287
- * @param options - Optional formatting options
288
- * @param options.minimumDecimals - Global minimum decimal places (overrides range configs)
289
- * @param options.maximumDecimals - Global maximum decimal places (overrides range configs)
290
- * @param options.significantDigits - Global significant digits (overrides decimal settings when set)
291
- * @param options.ranges - Custom range configurations (defaults to PRICE_RANGES_MINIMAL_VIEW)
292
- * @param options.currency - Currency code (default: 'USD')
293
- * @param options.locale - Locale for formatting (default: 'en-US')
294
- * @param options.stripTrailingZeros - Strip trailing zeros from output (default: false via PRICE_RANGES_MINIMAL_VIEW). When true, overrides minimumDecimals constraint.
295
- * @returns Formatted currency string with variable decimals based on configured ranges
296
- * @example
297
- * // Using defaults (preserves trailing zeros for fiat)
298
- * formatPerpsFiat(1234.56) => "$1,234.56"
299
- * formatPerpsFiat(1250.00) => "$1,250.00" // Trailing zeros preserved
300
- * formatPerpsFiat(50000) => "$50,000.00" // Trailing zeros preserved
301
- *
302
- * // Stripping trailing zeros when needed (e.g., for crypto)
303
- * formatPerpsFiat(1250, { stripTrailingZeros: true }) => "$1,250"
304
- *
305
- * // With custom ranges
306
- * formatPerpsFiat(0.00001, {
307
- * ranges: [
308
- * { condition: (val) => val < 0.001, minimumDecimals: 6, maximumDecimals: 8 },
309
- * { condition: () => true, minimumDecimals: 2, maximumDecimals: 2 }
310
- * ]
311
- * }) => "$0.00001" // Trailing zero stripped
312
- *
313
- * // With significant digits
314
- * formatPerpsFiat(1234.56789, { significantDigits: 5 }) => "$1,234.6"
315
- * formatPerpsFiat(0.0001234, { significantDigits: 3 }) => "$0.000123"
316
- */
317
- export const formatPerpsFiat = (balance, options) => {
318
- const parsedValue = typeof balance === 'string' ? parseFloat(balance) : balance;
319
- const currency = options?.currency ?? 'USD';
320
- const locale = options?.locale ?? 'en-US';
321
- let formatted;
322
- if (isNaN(parsedValue)) {
323
- // Return placeholder for invalid values to avoid confusion with actual $0 values
324
- return PERPS_CONSTANTS.FallbackPriceDisplay;
325
- }
326
- // Use custom ranges or defaults
327
- const ranges = options?.ranges ?? PRICE_RANGES_MINIMAL_VIEW;
328
- // Find the first matching range configuration
329
- const rangeConfig = ranges.find((range) => range.condition(parsedValue));
330
- if (rangeConfig) {
331
- // Check for significant digits (global or range-specific)
332
- const sigDigits = options?.significantDigits ?? rangeConfig.significantDigits;
333
- // If significant digits are specified, use them
334
- if (sigDigits) {
335
- // Get min/max decimals (global overrides range, range overrides default)
336
- const minDecimals = options?.minimumDecimals ?? rangeConfig.minimumDecimals;
337
- const maxDecimals = options?.maximumDecimals ?? rangeConfig.maximumDecimals;
338
- // Calculate appropriate formatting based on significant digits
339
- const { value: formattedValue, decimals } = formatWithSignificantDigits(parsedValue, sigDigits, minDecimals, maxDecimals);
340
- // Format with the calculated decimal places
341
- formatted = formatWithThreshold(formattedValue, rangeConfig.threshold ?? 0.01, locale, {
342
- style: 'currency',
343
- currency,
344
- minimumFractionDigits: decimals,
345
- maximumFractionDigits: decimals,
346
- });
347
- }
348
- else {
349
- // Standard decimal-based formatting (existing logic)
350
- const minDecimals = options?.minimumDecimals ?? rangeConfig.minimumDecimals;
351
- const maxDecimals = options?.maximumDecimals ?? rangeConfig.maximumDecimals;
352
- // Use custom formatting if provided
353
- if (rangeConfig.customFormat) {
354
- formatted = rangeConfig.customFormat(parsedValue, locale, currency);
355
- }
356
- else {
357
- // Use standard formatting with threshold
358
- formatted = formatWithThreshold(parsedValue, rangeConfig.threshold ?? 0.01, locale, {
359
- style: 'currency',
360
- currency,
361
- minimumFractionDigits: minDecimals,
362
- maximumFractionDigits: maxDecimals,
363
- });
364
- }
365
- }
366
- }
367
- else {
368
- // Fallback if no range matches (shouldn't happen with proper default config)
369
- const fallbackMin = options?.minimumDecimals ?? 2;
370
- const fallbackMax = options?.maximumDecimals ?? 2;
371
- formatted = formatWithThreshold(parsedValue, 0.01, locale, {
372
- style: 'currency',
373
- currency,
374
- minimumFractionDigits: fallbackMin,
375
- maximumFractionDigits: fallbackMax,
376
- });
377
- }
378
- // Post-process: strip trailing zeros unless explicitly disabled
379
- // Priority: explicit options.stripTrailingZeros false > rangeConfig > options default > true
380
- // If options.stripTrailingZeros is explicitly false, skip stripping entirely
381
- if (options?.stripTrailingZeros === false) {
382
- return formatted;
383
- }
384
- // Otherwise check range config or default to true
385
- const shouldStrip = rangeConfig?.stripTrailingZeros ?? options?.stripTrailingZeros ?? true;
386
- if (shouldStrip) {
387
- // Check if fiat-style stripping is enabled (only strips .00)
388
- const useFiatStyle = rangeConfig?.fiatStyleStripping ?? false;
389
- if (useFiatStyle) {
390
- // Fiat-style: Only strip .00 (no meaningful decimals), preserve 2-decimal format
391
- // Examples: $1,250.00 becomes $1,250 | $1,000.10 stays $1,000.10 | $13.40 stays $13.40
392
- return formatted.replace(/\.00$/u, '');
393
- }
394
- // Standard: Strip all trailing zeros after decimal point
395
- // Examples: $1,250.00 becomes $1,250 | $100.0 becomes $100 | $10.5 stays $10.5 | $1.234 stays $1.234
396
- return formatted.replace(/(\.\d*?)0+$/u, '$1').replace(/\.$/u, '');
397
- }
398
- return formatted;
399
- };
400
- /**
401
- * Formats a fee value as USD currency with appropriate decimal places
402
- *
403
- * @param fee - Raw numeric or string fee value (e.g., 1234.56, not token minimal denomination)
404
- * @returns Formatted currency string with variable decimals based on configured ranges
405
- * @example formatPositiveFiat(1234.56) => "$1,234.56"
406
- * @example formatPositiveFiat(0.005) => "< $0.01"
407
- * @example formatPositiveFiat(0) => "$0"
408
- */
409
- export const formatPositiveFiat = (fee) => {
410
- const smallFeeThreshold = 0.01;
411
- if (BigNumber(fee).isEqualTo(0)) {
412
- return '$0';
413
- }
414
- if (BigNumber(fee).isLessThan(smallFeeThreshold)) {
415
- return '< $0.01';
416
- }
417
- return formatPerpsFiat(fee);
418
- };
419
- /**
420
- * Default price range configurations
421
- * Applied in order - first matching condition wins
422
- */
423
- export const DEFAULT_PRICE_RANGES = [
424
- {
425
- // Medium-large numbers (>= 1000)
426
- condition: (val) => Math.abs(val) >= 1000,
427
- minimumDecimals: 2,
428
- maximumDecimals: 4,
429
- threshold: 100,
430
- },
431
- {
432
- // Default range (1 <= val < 1000)
433
- condition: () => true,
434
- minimumDecimals: 2,
435
- maximumDecimals: 4,
436
- threshold: 0.0001,
437
- },
438
- ];
439
- /**
440
- * Universal price range configuration following comprehensive rules from rules-decimals.md
441
- *
442
- * Rules:
443
- * - Max 6 decimals across all ranges (Hyperliquid limit)
444
- * - Strip trailing zeros by default
445
- * - Use |v| (absolute value) for conditions
446
- *
447
- * Significant digits by range:
448
- * - > $100,000: 6 sig digs
449
- * - $100,000 > x > $0.01: 5 sig digs
450
- * - < $0.01: 4 sig digs
451
- *
452
- * Decimal limits by price range:
453
- * - |v| > 10,000: min 0, max 0 decimals; 5 sig digs (6 if >100k)
454
- * - |v| > 1,000: min 0, max 1 decimal; 5 sig digs
455
- * - |v| > 100: min 0, max 2 decimals; 5 sig digs
456
- * - |v| > 10: min 0, max 4 decimals; 5 sig digs
457
- * - |v| >= 0.01: 5 sig digs, min 2, max 6 decimals
458
- * - |v| < 0.01: 4 sig digs, min 2, max 6 decimals
459
- *
460
- * Examples:
461
- * - $123,456.78 becomes $123,457 (>$10k: 0 decimals, 6 sig figs)
462
- * - $12,345.67 becomes $12,346 (>$10k: 0 decimals, 5 sig figs)
463
- * - $1,234.56 becomes $1,234.6 ($1k-$10k: 1 decimal, 5 sig figs)
464
- * - $123.456 becomes $123.46 ($100-$1k: 2 decimals, 5 sig figs)
465
- * - $12.34567 becomes $12.346 ($10-$100: 4 decimals, 5 sig figs)
466
- * - $1.3445555 becomes $1.3446 (>=$0.01: 5 sig figs)
467
- * - $0.333333 becomes $0.33333 (>=$0.01: 5 sig figs)
468
- * - $0.004236 stays $0.004236 (<$0.01: 4 sig figs, max 6 decimals)
469
- * - $0.0000006 becomes $0.000001 (<$0.01: 4 sig figs, rounds with max 6 decimals)
470
- */
471
- export const PRICE_RANGES_UNIVERSAL = [
472
- {
473
- // Very high values (> $100,000): No decimals, 6 significant figures
474
- // Ex: $123,456.78 becomes $123,457
475
- condition: (val) => Math.abs(val) > PRICE_THRESHOLD.VERY_HIGH,
476
- minimumDecimals: 0,
477
- maximumDecimals: 0,
478
- significantDigits: 6,
479
- threshold: PRICE_THRESHOLD.VERY_HIGH,
480
- },
481
- {
482
- // High values ($10,000-$100,000]: No decimals, 5 significant figures
483
- // Ex: $12,345.67 becomes $12,346
484
- condition: (val) => Math.abs(val) > PRICE_THRESHOLD.HIGH,
485
- minimumDecimals: 0,
486
- maximumDecimals: 0,
487
- significantDigits: 5,
488
- threshold: PRICE_THRESHOLD.HIGH,
489
- },
490
- {
491
- // Large values ($1,000-$10,000]: Max 1 decimal, 5 significant figures
492
- // Ex: $1,234.56 becomes $1,234.6
493
- condition: (val) => Math.abs(val) > PRICE_THRESHOLD.LARGE,
494
- minimumDecimals: 0,
495
- maximumDecimals: 1,
496
- significantDigits: 5,
497
- threshold: PRICE_THRESHOLD.LARGE,
498
- },
499
- {
500
- // Medium values ($100-$1,000]: Max 2 decimals, 5 significant figures
501
- // Ex: $123.456 becomes $123.46
502
- condition: (val) => Math.abs(val) > PRICE_THRESHOLD.MEDIUM,
503
- minimumDecimals: 0,
504
- maximumDecimals: 2,
505
- significantDigits: 5,
506
- threshold: PRICE_THRESHOLD.MEDIUM,
507
- },
508
- {
509
- // Medium-low values ($10-$100]: Max 4 decimals, 5 significant figures
510
- // Ex: $12.34567 becomes $12.346
511
- condition: (val) => Math.abs(val) > PRICE_THRESHOLD.MEDIUM_LOW,
512
- minimumDecimals: 0,
513
- maximumDecimals: 4,
514
- significantDigits: 5,
515
- threshold: PRICE_THRESHOLD.MEDIUM_LOW,
516
- },
517
- {
518
- // Low values ($0.01-$10]: 5 significant figures, min 2 max MAX_PRICE_DECIMALS decimals
519
- // Ex: $1.3445555 becomes $1.3446 | $0.333333 becomes $0.33333
520
- condition: (val) => Math.abs(val) >= PRICE_THRESHOLD.LOW,
521
- significantDigits: 5,
522
- minimumDecimals: 2,
523
- maximumDecimals: DECIMAL_PRECISION_CONFIG.MaxPriceDecimals,
524
- threshold: PRICE_THRESHOLD.LOW,
525
- },
526
- {
527
- // Very small values (< $0.01): 4 significant figures, min 2 max MAX_PRICE_DECIMALS decimals
528
- // Ex: $0.004236 stays $0.004236 | $0.0000006 becomes $0.000001
529
- condition: () => true,
530
- significantDigits: 4,
531
- minimumDecimals: 2,
532
- maximumDecimals: DECIMAL_PRECISION_CONFIG.MaxPriceDecimals,
533
- threshold: PRICE_THRESHOLD.VERY_SMALL,
534
- },
535
- ];
536
- /**
537
- * Formats a PnL (Profit and Loss) value with sign prefix
538
- *
539
- * @param pnl - Raw numeric PnL value (positive for profit, negative for loss)
540
- * @returns Format: "+$X,XXX.XX" or "-$X,XXX.XX" (always shows sign, 2 decimals)
541
- * @example formatPnl(1234.56) => "+$1,234.56"
542
- * @example formatPnl(-500) => "-$500.00"
543
- * @example formatPnl(0) => "+$0.00"
544
- */
545
- export const formatPnl = (pnl) => {
546
- const parsedValue = typeof pnl === 'string' ? parseFloat(pnl) : pnl;
547
- if (isNaN(parsedValue)) {
548
- return PERPS_CONSTANTS.ZeroAmountDetailedDisplay;
549
- }
550
- const formatted = getIntlNumberFormatter('en-US', {
551
- style: 'currency',
552
- currency: 'USD',
553
- minimumFractionDigits: 2,
554
- maximumFractionDigits: 2,
555
- }).format(Math.abs(parsedValue));
556
- return parsedValue >= 0 ? `+${formatted}` : `-${formatted}`;
557
- };
558
- /**
559
- * Formats a percentage value with sign prefix
560
- *
561
- * @param value - Raw percentage value (e.g., 5.25 for 5.25%, not 0.0525)
562
- * @param decimals - Number of decimal places to show (default: 2)
563
- * @returns Format: "+X.XX%" or "-X.XX%" (always shows sign, 2 decimals)
564
- * @example formatPercentage(5.25) => "+5.25%"
565
- * @example formatPercentage(-2.75) => "-2.75%"
566
- * @example formatPercentage(0) => "+0.00%"
567
- */
568
- export const formatPercentage = (value, decimals = 2) => {
569
- const parsedValue = typeof value === 'string' ? parseFloat(value) : value;
570
- if (isNaN(parsedValue)) {
571
- return '0.00%';
572
- }
573
- return `${parsedValue >= 0 ? '+' : ''}${parsedValue.toFixed(decimals)}%`;
574
- };
575
- /**
576
- * Formats funding rate for display
577
- *
578
- * @param value - Raw funding rate value (decimal, not percentage)
579
- * @param options - Optional formatting options
580
- * @param options.showZero - Whether to return zero display value for zero/undefined (default: true)
581
- * @returns Formatted funding rate as percentage string
582
- * @example formatFundingRate(0.0005) => "0.0500%"
583
- * @example formatFundingRate(-0.0001) => "-0.0100%"
584
- * @example formatFundingRate(undefined) => "0.0000%"
585
- */
586
- export const formatFundingRate = (value, options) => {
587
- const showZero = options?.showZero ?? true;
588
- if (value === undefined || value === null) {
589
- return showZero ? FUNDING_RATE_CONFIG.ZeroDisplay : '';
590
- }
591
- const percentage = value * FUNDING_RATE_CONFIG.PercentageMultiplier;
592
- const formatted = percentage.toFixed(FUNDING_RATE_CONFIG.Decimals);
593
- // Check if the result is effectively zero
594
- if (showZero && parseFloat(formatted) === 0) {
595
- return FUNDING_RATE_CONFIG.ZeroDisplay;
596
- }
597
- return `${formatted}%`;
598
- };
599
- /**
600
- * Default large number range configurations
601
- * Applied in order from largest to smallest
602
- */
603
- export const DEFAULT_LARGE_NUMBER_RANGES = [
604
- {
605
- threshold: 1000000000000, // >= 1T
606
- suffix: 'T',
607
- decimals: 0,
608
- },
609
- {
610
- threshold: 1000000000, // >= 1B
611
- suffix: 'B',
612
- decimals: 0,
613
- },
614
- {
615
- threshold: 1000000, // >= 1M
616
- suffix: 'M',
617
- decimals: 0,
618
- },
619
- {
620
- threshold: 1000, // >= 1K
621
- suffix: 'K',
622
- decimals: 0,
623
- },
624
- {
625
- threshold: 0, // < 1K (all remaining numbers)
626
- suffix: '',
627
- decimals: 2,
628
- },
629
- ];
630
- /**
631
- * Preset for detailed large number formatting with more decimal precision
632
- * Useful for displaying precise statistics or detailed financial data
633
- */
634
- export const LARGE_NUMBER_RANGES_DETAILED = [
635
- {
636
- threshold: 1000000000000, // >= 1T
637
- suffix: 'T',
638
- decimals: 2,
639
- },
640
- {
641
- threshold: 1000000000, // >= 1B
642
- suffix: 'B',
643
- decimals: 2,
644
- },
645
- {
646
- threshold: 1000000, // >= 1M
647
- suffix: 'M',
648
- decimals: 2,
649
- },
650
- {
651
- threshold: 1000, // >= 1K
652
- suffix: 'K',
653
- decimals: 0,
654
- },
655
- {
656
- threshold: 0, // < 1K (all remaining numbers)
657
- suffix: '',
658
- decimals: 0,
659
- },
660
- ];
661
- /**
662
- * Formats large numbers with magnitude suffixes (K, M, B, T)
663
- *
664
- * @param value - The number to format
665
- * @param options - Optional formatting options
666
- * @param options.decimals - Legacy: Number of decimal places for all suffixed values (overrides range configs)
667
- * @param options.rawDecimals - Legacy: Number of decimal places for numbers below all thresholds (overrides range config for threshold: 0)
668
- * @param options.ranges - Custom range configurations for fine-grained control over decimals per range
669
- * @returns Formatted string with appropriate suffix
670
- * @example
671
- * // Using defaults
672
- * formatLargeNumber(1500000) => "2M"
673
- * formatLargeNumber(1234) => "1K"
674
- * formatLargeNumber(999) => "999.00"
675
- *
676
- * // Legacy: same decimals for all ranges
677
- * formatLargeNumber(1500000, { decimals: 1 }) => "1.5M"
678
- * formatLargeNumber(1234, { decimals: 2 }) => "1.23K"
679
- *
680
- * // New: custom decimals per range (including all remaining numbers)
681
- * formatLargeNumber(1500000, {
682
- * ranges: [
683
- * { threshold: 1000000000000, suffix: 'T', decimals: 2 },
684
- * { threshold: 1000000000, suffix: 'B', decimals: 1 },
685
- * { threshold: 1000000, suffix: 'M', decimals: 1 },
686
- * { threshold: 1000, suffix: 'K', decimals: 0 },
687
- * { threshold: 0, suffix: '', decimals: 4 }, // < 1K (all remaining numbers)
688
- * ]
689
- * }) => "1.5M"
690
- */
691
- export const formatLargeNumber = (value, options) => {
692
- const parsedValue = typeof value === 'string' ? parseFloat(value) : value;
693
- const ranges = options?.ranges ?? DEFAULT_LARGE_NUMBER_RANGES;
694
- if (isNaN(parsedValue)) {
695
- return '0';
696
- }
697
- const absValue = Math.abs(parsedValue);
698
- const sign = parsedValue < 0 ? '-' : '';
699
- // Check each range in order
700
- for (const range of ranges) {
701
- if (absValue >= range.threshold) {
702
- // Calculate divisor based on threshold (or 1 for no scaling)
703
- const divisor = range.threshold > 0 ? range.threshold : 1;
704
- const scaledValue = absValue / divisor;
705
- // Determine decimals to use
706
- let decimalPlaces = range.decimals;
707
- // Legacy support: override with options.decimals for suffixed values
708
- if (options?.decimals !== undefined && range.suffix !== '') {
709
- decimalPlaces = options.decimals;
710
- }
711
- // Legacy support: override with options.rawDecimals for non-suffixed values
712
- if (options?.rawDecimals !== undefined && range.suffix === '') {
713
- decimalPlaces = options.rawDecimals;
714
- }
715
- return `${sign}${scaledValue.toFixed(decimalPlaces)}${range.suffix}`;
716
- }
717
- }
718
- // This should never be reached if ranges includes a threshold: 0 entry
719
- // But keep as fallback for safety
720
- return parsedValue.toFixed(options?.rawDecimals ?? 2);
721
- };
722
- /**
723
- * Formats volume with appropriate magnitude suffixes
724
- *
725
- * @param volume - Raw volume value
726
- * @param decimals - Number of decimal places to show (optional, auto-determined by default)
727
- * @returns Format: "$XB" / "$X.XXM" / "$XK" / "$X.XX"
728
- * @example formatVolume(1234567890) => "$1.23B"
729
- * @example formatVolume(12345678) => "$12.35M"
730
- * @example formatVolume(123456) => "$123K"
731
- */
732
- export const formatVolume = (volume, decimals) => {
733
- const parsedValue = typeof volume === 'string' ? parseFloat(volume) : volume;
734
- // Handle invalid inputs - return fallback display for NaN/Infinity
735
- if (isNaN(parsedValue) || !isFinite(parsedValue)) {
736
- return '$---';
737
- }
738
- const absValue = Math.abs(parsedValue);
739
- // Auto-determine decimals based on magnitude if not specified
740
- let autoDecimals;
741
- if (decimals === undefined) {
742
- if (absValue >= 1000000000) {
743
- // Billions: 2 decimals
744
- autoDecimals = 2;
745
- }
746
- else if (absValue >= 1000000) {
747
- // Millions: 2 decimals
748
- autoDecimals = 2;
749
- }
750
- else if (absValue >= 1000) {
751
- // Thousands: 0 decimals
752
- autoDecimals = 0;
753
- }
754
- else {
755
- // Under 1000: 2 decimals
756
- autoDecimals = 2;
757
- }
758
- }
759
- else {
760
- autoDecimals = decimals;
761
- }
762
- const formatted = formatLargeNumber(volume, {
763
- decimals: autoDecimals,
764
- rawDecimals: autoDecimals,
765
- });
766
- // Handle negative values - ensure dollar sign comes after negative sign
767
- if (formatted.startsWith('-')) {
768
- return `-$${formatted.slice(1)}`;
769
- }
770
- return `$${formatted}`;
771
- };
772
- /**
773
- * Formats position size with variable decimal precision based on magnitude or asset-specific decimals
774
- * Removes trailing zeros to match task requirements
775
- *
776
- * @param size - Raw position size value
777
- * @param szDecimals - Optional asset-specific decimal precision from Hyperliquid metadata (e.g., BTC=5, ETH=4, DOGE=1)
778
- * @returns Format varies by size or uses asset-specific decimals, with trailing zeros removed:
779
- * If szDecimals provided: Uses exact decimals (e.g., 0.00009 BTC with szDecimals=5 => "0.00009")
780
- * Otherwise falls back to magnitude-based logic:
781
- * - Size < 0.01: Up to 6 decimals (e.g., "0.00009" not "0.000090")
782
- * - Size < 1: Up to 4 decimals (e.g., "0.0024" not "0.002400")
783
- * - Size >= 1: Up to 2 decimals (e.g., "44" not "44.00")
784
- * @example formatPositionSize(0.00009, 5) => "0.00009" (uses szDecimals)
785
- * @example formatPositionSize(44.00, 1) => "44" (uses szDecimals, trailing zeros removed)
786
- * @example formatPositionSize(0.0024) => "0.0024" (no szDecimals, uses magnitude logic)
787
- * @example formatPositionSize(44.00) => "44" (no szDecimals, uses magnitude logic)
788
- */
789
- export const formatPositionSize = (size, szDecimals) => {
790
- const parsedValue = typeof size === 'string' ? parseFloat(size) : size;
791
- if (isNaN(parsedValue) || parsedValue === 0) {
792
- return '0';
793
- }
794
- // Use asset-specific decimals if provided (Hyperliquid metadata)
795
- if (szDecimals !== undefined) {
796
- return parsedValue.toFixed(szDecimals).replace(/\.?0+$/u, '');
797
- }
798
- // Fallback: magnitude-based decimal logic for backwards compatibility
799
- const absValue = Math.abs(parsedValue);
800
- let formatted;
801
- if (absValue < 0.01) {
802
- // For very small numbers, use more decimal places
803
- formatted = parsedValue.toFixed(6);
804
- }
805
- else if (absValue < 1) {
806
- // For small numbers, use 4 decimal places
807
- formatted = parsedValue.toFixed(4);
808
- }
809
- else {
810
- // For normal numbers, use 2 decimal places
811
- formatted = parsedValue.toFixed(2);
812
- }
813
- // Remove trailing zeros and unnecessary decimal point
814
- return formatted.replace(/\.?0+$/u, '');
815
- };
816
- /**
817
- * Formats leverage value with 'x' suffix
818
- *
819
- * @param leverage - Raw leverage multiplier value
820
- * @returns Format: "X.Xx" (1 decimal place with 'x' suffix)
821
- * @example formatLeverage(5) => "5.0x"
822
- * @example formatLeverage(10.5) => "10.5x"
823
- * @example formatLeverage(1) => "1.0x"
824
- */
825
- export const formatLeverage = (leverage) => {
826
- const parsedValue = typeof leverage === 'string' ? parseFloat(leverage) : leverage;
827
- if (isNaN(parsedValue)) {
828
- return '1x';
829
- }
830
- return `${parsedValue.toFixed(1)}x`;
831
- };
832
- /**
833
- * Parses formatted currency strings back to numeric values
834
- *
835
- * @param formattedValue - Formatted currency string (handles $, commas, negative values)
836
- * @returns Raw numeric value
837
- * @example parseCurrencyString("$1,234.56") => 1234.56
838
- * @example parseCurrencyString("-$500.00") => -500
839
- * @example parseCurrencyString("$-123.45") => -123.45
840
- */
841
- export const parseCurrencyString = (formattedValue) => {
842
- if (!formattedValue) {
843
- return 0;
844
- }
845
- // Check for negative values (can be -$123.45 or $-123.45)
846
- const isNegative = formattedValue.includes('-');
847
- // Remove all non-numeric characters except dots
848
- // This regex removes currency symbols ($, etc.), commas, minus signs, and other formatting
849
- const cleanedValue = formattedValue
850
- .replace(/[^0-9.]/gu, '') // Remove everything except digits and dots
851
- .trim();
852
- // Handle multiple dots by keeping only the last one as decimal separator
853
- // NOTE: This assumes US format (comma for thousands, dot for decimal)
854
- // Numbers with dots as thousand separators (e.g., European format) will be parsed incorrectly
855
- const parts = cleanedValue.split('.');
856
- const integerPart = parts[0] || '0';
857
- const decimalPart = parts.length > 1 ? parts[parts.length - 1] : '';
858
- const finalValue = decimalPart
859
- ? `${integerPart}.${decimalPart}`
860
- : integerPart;
861
- const parsedResult = parseFloat(finalValue);
862
- if (isNaN(parsedResult)) {
863
- return 0;
864
- }
865
- return isNegative ? -parsedResult : parsedResult;
866
- };
867
- /**
868
- * Parses formatted percentage strings back to numeric values
869
- *
870
- * @param formattedValue - Formatted percentage string (handles %, +/- signs)
871
- * @returns Raw numeric percentage value
872
- * @example parsePercentageString("+2.50%") => 2.5
873
- * @example parsePercentageString("-10.75%") => -10.75
874
- * @example parsePercentageString("5%") => 5
875
- */
876
- export const parsePercentageString = (formattedValue) => {
877
- if (!formattedValue) {
878
- return 0;
879
- }
880
- const cleanedValue = formattedValue
881
- .replace(/%/gu, '')
882
- .replace(/\s/gu, '')
883
- .trim();
884
- const parsedResult = parseFloat(cleanedValue);
885
- return isNaN(parsedResult) ? 0 : parsedResult;
886
- };
887
- /**
888
- * Formats a timestamp for transaction detail views with time
889
- *
890
- * @param timestamp - Unix timestamp in milliseconds
891
- * @returns Formatted date string with time (e.g., "July 24, 2025 at 2:30 PM")
892
- * @example formatTransactionDate(1642492800000) => "January 18, 2022 at 12:00 AM"
893
- */
894
- export const formatTransactionDate = (timestamp) => {
895
- const date = new Date(timestamp);
896
- const dateStr = getIntlDateTimeFormatter('en-US', {
897
- year: 'numeric',
898
- month: 'long',
899
- day: 'numeric',
900
- }).format(date);
901
- const timeStr = getIntlDateTimeFormatter('en-US', {
902
- hour: 'numeric',
903
- minute: '2-digit',
904
- hour12: true,
905
- }).format(date);
906
- return `${dateStr} at ${timeStr}`;
907
- };
908
- /**
909
- * Formats a timestamp for order cards with time
910
- *
911
- * @param timestamp - Unix timestamp in milliseconds
912
- * @returns Formatted date string with time (e.g., "Jan 18 at 2:30 PM")
913
- * @example formatOrderCardDate(1642492800000) => "Jan 18 at 12:00 AM"
914
- */
915
- export const formatOrderCardDate = (timestamp) => {
916
- const date = new Date(timestamp);
917
- const dateStr = getIntlDateTimeFormatter('en-US', {
918
- month: 'short',
919
- day: 'numeric',
920
- }).format(date);
921
- const timeStr = getIntlDateTimeFormatter('en-US', {
922
- hour: 'numeric',
923
- minute: '2-digit',
924
- hour12: true,
925
- }).format(date);
926
- return `${dateStr} at ${timeStr}`;
927
- };
928
- /**
929
- * Formats a timestamp for transaction section headers
930
- *
931
- * @param timestamp - Unix timestamp in milliseconds
932
- * @param labels - Localized labels for "Today" and "Yesterday"
933
- * @param labels.today - Label text for today
934
- * @param labels.yesterday - Label text for yesterday
935
- * @returns Formatted date section string ("Today", "Yesterday", or "Month Day")
936
- * @example formatDateSection(Date.now(), { today: 'Today', yesterday: 'Yesterday' }) => "Today"
937
- */
938
- export const formatDateSection = (timestamp, labels = {
939
- today: 'Today',
940
- yesterday: 'Yesterday',
941
- }) => {
942
- const date = new Date(timestamp);
943
- const today = new Date();
944
- const yesterday = new Date(today);
945
- yesterday.setDate(yesterday.getDate() - 1);
946
- // Check if it's today
947
- if (date.getDate() === today.getDate() &&
948
- date.getMonth() === today.getMonth() &&
949
- date.getFullYear() === today.getFullYear()) {
950
- return labels.today;
951
- }
952
- // Check if it's yesterday
953
- if (date.getDate() === yesterday.getDate() &&
954
- date.getMonth() === yesterday.getMonth() &&
955
- date.getFullYear() === yesterday.getFullYear()) {
956
- return labels.yesterday;
957
- }
958
- const month = getIntlDateTimeFormatter('en-US', {
959
- month: 'short',
960
- }).format(new Date(timestamp));
961
- const day = getIntlDateTimeFormatter('en-US', {
962
- day: 'numeric',
963
- }).format(new Date(timestamp));
964
- return `${month} ${day}`; // 'Jul 26'
965
- };
966
- //# sourceMappingURL=formatUtils.mjs.map