@rainlanguage/ui-components 0.0.1-alpha.24 → 0.0.1-alpha.241

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 (299) hide show
  1. package/README.md +14 -6
  2. package/dist/__fixtures__/settings.yaml +123 -0
  3. package/dist/__mocks__/CodeMirrorRainlang.svelte +4 -0
  4. package/dist/__mocks__/CodeMirrorRainlang.svelte.d.ts +18 -0
  5. package/dist/__mocks__/MockCodeMirrorEditor.svelte +17 -0
  6. package/dist/__mocks__/MockCodeMirrorEditor.svelte.d.ts +21 -0
  7. package/dist/__mocks__/MockComponent.js +1 -1
  8. package/dist/__mocks__/MockComponent.svelte +10 -2
  9. package/dist/__mocks__/MockComponent.svelte.d.ts +4 -1
  10. package/dist/__mocks__/mockWeb3Config.d.ts +1 -1
  11. package/dist/__mocks__/mockWeb3Config.js +10 -7
  12. package/dist/__mocks__/queries.js +9 -9
  13. package/dist/__mocks__/stores.d.ts +55 -45
  14. package/dist/__mocks__/stores.js +85 -68
  15. package/dist/app.css +3 -3
  16. package/dist/components/ButtonDarkMode.svelte +7 -1
  17. package/dist/components/ButtonLoading.svelte +1 -1
  18. package/dist/components/ButtonScrub.svelte +22 -0
  19. package/dist/components/ButtonScrub.svelte.d.ts +25 -0
  20. package/dist/components/ButtonVaultLink.svelte +12 -11
  21. package/dist/components/ButtonVaultLink.svelte.d.ts +4 -3
  22. package/dist/components/CheckboxInactiveOrdersVault.svelte +20 -0
  23. package/dist/components/CheckboxInactiveOrdersVault.svelte.d.ts +19 -0
  24. package/dist/components/CheckboxZeroBalanceVault.svelte.d.ts +2 -2
  25. package/dist/components/CodeMirrorDotrain.svelte +4 -0
  26. package/dist/components/CodeMirrorDotrain.svelte.d.ts +1 -0
  27. package/dist/components/CodeMirrorRainlang.svelte +20 -12
  28. package/dist/components/CodeMirrorRainlang.svelte.d.ts +3 -2
  29. package/dist/components/EditableSpan.svelte +3 -14
  30. package/dist/components/EditableSpan.svelte.d.ts +0 -1
  31. package/dist/components/Hash.svelte +6 -5
  32. package/dist/components/License.svelte +5 -4
  33. package/dist/components/ListViewRaindexFilters.svelte +64 -0
  34. package/dist/components/ListViewRaindexFilters.svelte.d.ts +32 -0
  35. package/dist/components/LocalDbStatusBadge.svelte +27 -0
  36. package/dist/components/LocalDbStatusBadge.svelte.d.ts +19 -0
  37. package/dist/components/LocalDbStatusCard.svelte +43 -0
  38. package/dist/components/LocalDbStatusCard.svelte.d.ts +20 -0
  39. package/dist/components/LocalDbStatusModal.svelte +105 -0
  40. package/dist/components/LocalDbStatusModal.svelte.d.ts +21 -0
  41. package/dist/components/OrderOrVaultHash.svelte +12 -12
  42. package/dist/components/OrderOrVaultHash.svelte.d.ts +4 -4
  43. package/dist/components/PageHeader.svelte +1 -1
  44. package/dist/components/Sensitive.svelte +16 -0
  45. package/dist/components/Sensitive.svelte.d.ts +28 -0
  46. package/dist/components/TanstackAppTable.svelte +270 -60
  47. package/dist/components/TanstackAppTable.svelte.d.ts +15 -9
  48. package/dist/components/ToastDetail.svelte +42 -0
  49. package/dist/components/ToastDetail.svelte.d.ts +20 -0
  50. package/dist/components/Tooltip.svelte +8 -0
  51. package/dist/components/Tooltip.svelte.d.ts +21 -0
  52. package/dist/components/VaultBalanceChangeTypeFilter.svelte +23 -0
  53. package/dist/components/VaultBalanceChangeTypeFilter.svelte.d.ts +19 -0
  54. package/dist/components/VaultCard.svelte +18 -0
  55. package/dist/components/VaultCard.svelte.d.ts +19 -0
  56. package/dist/components/charts/LightweightChart.svelte +1 -1
  57. package/dist/components/charts/LightweightChart.svelte.d.ts +5 -5
  58. package/dist/components/charts/OrderTradesChart.svelte +319 -28
  59. package/dist/components/charts/OrderTradesChart.svelte.d.ts +4 -4
  60. package/dist/components/charts/TanstackLightweightChartLine.svelte +5 -9
  61. package/dist/components/charts/VaultBalanceChart.svelte +8 -26
  62. package/dist/components/charts/VaultBalanceChart.svelte.d.ts +1 -7
  63. package/dist/components/charts/transformAndSortData.d.ts +24 -0
  64. package/dist/components/charts/transformAndSortData.js +111 -0
  65. package/dist/components/checkbox/CheckboxActiveOrders.svelte +11 -0
  66. package/dist/components/checkbox/CheckboxActiveOrders.svelte.d.ts +19 -0
  67. package/dist/components/deployment/ButtonSelectOption.svelte +2 -0
  68. package/dist/components/deployment/ButtonSelectOption.svelte.d.ts +1 -0
  69. package/dist/components/deployment/ComposedRainlangModal.svelte +3 -2
  70. package/dist/components/deployment/ComposedRainlangModal.svelte.d.ts +1 -4
  71. package/dist/components/deployment/DeploymentSectionHeader.svelte +7 -4
  72. package/dist/components/deployment/DeploymentSteps.svelte +196 -221
  73. package/dist/components/deployment/DeploymentSteps.svelte.d.ts +6 -12
  74. package/dist/components/deployment/DeploymentTile.svelte +2 -2
  75. package/dist/components/deployment/DeploymentTile.svelte.d.ts +1 -1
  76. package/dist/components/deployment/DeploymentsSection.svelte +15 -22
  77. package/dist/components/deployment/DeploymentsSection.svelte.d.ts +3 -2
  78. package/dist/components/deployment/DepositInput.svelte +10 -11
  79. package/dist/components/deployment/DepositInput.svelte.d.ts +2 -3
  80. package/dist/components/deployment/DisclaimerModal.svelte +6 -7
  81. package/dist/components/deployment/FieldDefinitionInput.svelte +10 -14
  82. package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +2 -3
  83. package/dist/components/deployment/InvalidOrdersSection.svelte +17 -0
  84. package/dist/components/deployment/InvalidOrdersSection.svelte.d.ts +19 -0
  85. package/dist/components/deployment/{StrategyPage.svelte → OrderPage.svelte} +15 -24
  86. package/dist/components/deployment/OrderPage.svelte.d.ts +21 -0
  87. package/dist/components/deployment/SelectToken.svelte +127 -50
  88. package/dist/components/deployment/SelectToken.svelte.d.ts +5 -4
  89. package/dist/components/deployment/TokenBalance.svelte +19 -0
  90. package/dist/components/deployment/TokenBalance.svelte.d.ts +19 -0
  91. package/dist/components/deployment/TokenIOInput.svelte +27 -17
  92. package/dist/components/deployment/TokenIOInput.svelte.d.ts +3 -3
  93. package/dist/components/deployment/TokenSelectionModal.svelte +148 -0
  94. package/dist/components/deployment/TokenSelectionModal.svelte.d.ts +20 -0
  95. package/dist/components/deployment/{ValidStrategiesSection.svelte → ValidOrdersSection.svelte} +7 -7
  96. package/dist/components/deployment/ValidOrdersSection.svelte.d.ts +19 -0
  97. package/dist/components/deployment/VaultIdInformation.svelte +17 -0
  98. package/dist/components/deployment/VaultIdInformation.svelte.d.ts +21 -0
  99. package/dist/components/detail/OrderDetail.svelte +220 -82
  100. package/dist/components/detail/OrderDetail.svelte.d.ts +21 -15
  101. package/dist/components/detail/TanstackOrderQuote.svelte +114 -46
  102. package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +14 -16
  103. package/dist/components/detail/VaultDetail.svelte +82 -79
  104. package/dist/components/detail/VaultDetail.svelte.d.ts +12 -18
  105. package/dist/components/dropdown/DropdownActiveNetworks.svelte +44 -0
  106. package/dist/components/dropdown/DropdownActiveNetworks.svelte.d.ts +19 -0
  107. package/dist/components/dropdown/DropdownCheckbox.svelte +4 -4
  108. package/dist/components/dropdown/DropdownRaindexesFilter.svelte +172 -0
  109. package/dist/components/dropdown/DropdownRaindexesFilter.svelte.d.ts +25 -0
  110. package/dist/components/dropdown/DropdownTokensFilter.svelte +152 -0
  111. package/dist/components/dropdown/DropdownTokensFilter.svelte.d.ts +28 -0
  112. package/dist/components/icon/Refresh.svelte +4 -2
  113. package/dist/components/icon/Refresh.svelte.d.ts +2 -0
  114. package/dist/components/input/InputOrderHash.svelte +1 -1
  115. package/dist/components/input/InputOrderHash.svelte.d.ts +3 -3
  116. package/dist/components/input/InputOwnerFilter.svelte +48 -0
  117. package/dist/components/input/InputOwnerFilter.svelte.d.ts +19 -0
  118. package/dist/components/input/InputRegistryUrl.svelte +36 -14
  119. package/dist/components/input/InputToken.svelte +2 -2
  120. package/dist/components/input/InputTokenAmount.svelte +30 -20
  121. package/dist/components/input/InputTokenAmount.svelte.d.ts +3 -3
  122. package/dist/components/tables/OrderAPY.svelte +6 -33
  123. package/dist/components/tables/OrderAPY.svelte.d.ts +1 -4
  124. package/dist/components/tables/OrderTradesListTable.svelte +132 -124
  125. package/dist/components/tables/OrderTradesListTable.svelte.d.ts +4 -4
  126. package/dist/components/tables/OrderVaultsVolTable.svelte +17 -22
  127. package/dist/components/tables/OrderVaultsVolTable.svelte.d.ts +2 -2
  128. package/dist/components/tables/OrdersListTable.svelte +206 -115
  129. package/dist/components/tables/OrdersListTable.svelte.d.ts +18 -23
  130. package/dist/components/tables/VaultBalanceChangesTable.svelte +83 -43
  131. package/dist/components/tables/VaultBalanceChangesTable.svelte.d.ts +13 -11
  132. package/dist/components/tables/VaultsListTable.svelte +275 -150
  133. package/dist/components/tables/VaultsListTable.svelte.d.ts +24 -33
  134. package/dist/components/transactions/FixedBottomTransaction.svelte +64 -0
  135. package/dist/components/transactions/FixedBottomTransaction.svelte.d.ts +16 -0
  136. package/dist/components/transactions/TransactionDetail.svelte +31 -0
  137. package/dist/components/transactions/TransactionDetail.svelte.d.ts +20 -0
  138. package/dist/components/transactions/TransactionList.svelte +17 -0
  139. package/dist/components/transactions/TransactionList.svelte.d.ts +16 -0
  140. package/dist/components/transactions/getStatusEmoji.d.ts +2 -0
  141. package/dist/components/transactions/getStatusEmoji.js +20 -0
  142. package/dist/components/wallet/WalletConnect.svelte +5 -4
  143. package/dist/components/wallet/WalletConnect.svelte.d.ts +0 -1
  144. package/dist/consts.d.ts +1 -0
  145. package/dist/consts.js +1 -0
  146. package/dist/errors/DeploymentStepsError.d.ts +11 -5
  147. package/dist/errors/DeploymentStepsError.js +13 -7
  148. package/dist/errors/index.d.ts +1 -1
  149. package/dist/errors/index.js +1 -1
  150. package/dist/hooks/useLocalDb.d.ts +3 -0
  151. package/dist/hooks/useLocalDb.js +10 -0
  152. package/dist/hooks/useRaindexClient.d.ts +3 -0
  153. package/dist/hooks/useRaindexClient.js +11 -0
  154. package/dist/hooks/useRaindexOrderBuilder.d.ts +3 -0
  155. package/dist/hooks/useRaindexOrderBuilder.js +11 -0
  156. package/dist/index.d.ts +122 -91
  157. package/dist/index.js +118 -87
  158. package/dist/models/Transaction.d.ts +75 -0
  159. package/dist/models/Transaction.js +100 -0
  160. package/dist/providers/LocalDbProvider.svelte +8 -0
  161. package/dist/providers/LocalDbProvider.svelte.d.ts +21 -0
  162. package/dist/providers/RaindexClientProvider.svelte +8 -0
  163. package/dist/providers/RaindexClientProvider.svelte.d.ts +21 -0
  164. package/dist/providers/RaindexOrderBuilderProvider.svelte +8 -0
  165. package/dist/providers/RaindexOrderBuilderProvider.svelte.d.ts +21 -0
  166. package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte +8 -0
  167. package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte.d.ts +24 -0
  168. package/dist/providers/dotrainRegistry/context.d.ts +9 -0
  169. package/dist/providers/dotrainRegistry/context.js +43 -0
  170. package/dist/providers/dotrainRegistry/useDotrainRegistry.d.ts +5 -0
  171. package/dist/providers/dotrainRegistry/useDotrainRegistry.js +35 -0
  172. package/dist/providers/registry/RegistryManager.d.ts +65 -0
  173. package/dist/providers/registry/RegistryManager.js +134 -0
  174. package/dist/providers/registry/RegistryProvider.svelte +6 -0
  175. package/dist/providers/registry/RegistryProvider.svelte.d.ts +21 -0
  176. package/dist/providers/registry/context.d.ts +10 -0
  177. package/dist/providers/registry/context.js +46 -0
  178. package/dist/providers/registry/useRegistry.d.ts +7 -0
  179. package/dist/providers/registry/useRegistry.js +29 -0
  180. package/dist/providers/toasts/ToastProvider.svelte +17 -0
  181. package/dist/providers/toasts/ToastProvider.svelte.d.ts +18 -0
  182. package/dist/providers/toasts/context.d.ts +14 -0
  183. package/dist/providers/toasts/context.js +22 -0
  184. package/dist/providers/toasts/useToasts.d.ts +16 -0
  185. package/dist/providers/toasts/useToasts.js +63 -0
  186. package/dist/providers/transactions/TransactionManager.d.ts +234 -0
  187. package/dist/providers/transactions/TransactionManager.js +509 -0
  188. package/dist/providers/transactions/TransactionProvider.svelte +11 -0
  189. package/dist/providers/transactions/TransactionProvider.svelte.d.ts +24 -0
  190. package/dist/providers/transactions/context.d.ts +19 -0
  191. package/dist/providers/transactions/context.js +28 -0
  192. package/dist/providers/transactions/useTransactions.d.ts +13 -0
  193. package/dist/providers/transactions/useTransactions.js +18 -0
  194. package/dist/providers/wallet/WalletProvider.svelte +7 -0
  195. package/dist/providers/wallet/WalletProvider.svelte.d.ts +21 -0
  196. package/dist/providers/wallet/context.d.ts +10 -0
  197. package/dist/providers/wallet/context.js +47 -0
  198. package/dist/providers/wallet/useAccount.d.ts +8 -0
  199. package/dist/providers/wallet/useAccount.js +148 -0
  200. package/dist/queries/keys.d.ts +1 -0
  201. package/dist/queries/keys.js +10 -9
  202. package/dist/queries/queryClient.d.ts +2 -2
  203. package/dist/queries/queryClient.js +16 -11
  204. package/dist/services/awaitTransactionIndexing.d.ts +107 -0
  205. package/dist/services/awaitTransactionIndexing.js +60 -0
  206. package/dist/services/getExplorerLink.d.ts +1 -1
  207. package/dist/services/getExplorerLink.js +3 -5
  208. package/dist/services/handleShareChoices.d.ts +2 -2
  209. package/dist/services/handleShareChoices.js +6 -5
  210. package/dist/services/historicalOrderCharts.d.ts +3 -3
  211. package/dist/services/historicalOrderCharts.js +364 -371
  212. package/dist/services/index.d.ts +5 -2
  213. package/dist/services/index.js +3 -1
  214. package/dist/services/loadRegistryUrl.d.ts +2 -0
  215. package/dist/services/loadRegistryUrl.js +22 -0
  216. package/dist/services/pairTradesChartData.d.ts +47 -0
  217. package/dist/services/pairTradesChartData.js +194 -0
  218. package/dist/services/registry.d.ts +5 -5
  219. package/dist/services/registry.js +17 -217
  220. package/dist/services/time.d.ts +12 -0
  221. package/dist/services/time.js +88 -6
  222. package/dist/services/validateAmount.d.ts +30 -0
  223. package/dist/services/validateAmount.js +53 -0
  224. package/dist/storesGeneric/cachedWritableStore.d.ts +57 -0
  225. package/dist/storesGeneric/cachedWritableStore.js +93 -0
  226. package/dist/storesGeneric/scrub.d.ts +14 -0
  227. package/dist/storesGeneric/scrub.js +22 -0
  228. package/dist/test/matchers.d.ts +2 -2
  229. package/dist/test/matchers.js +2 -2
  230. package/dist/types/account.d.ts +3 -0
  231. package/dist/types/appStores.d.ts +9 -16
  232. package/dist/types/modal.d.ts +26 -14
  233. package/dist/types/order.d.ts +10 -0
  234. package/dist/types/order.js +1 -0
  235. package/dist/types/toast.d.ts +11 -0
  236. package/dist/types/toast.js +1 -0
  237. package/dist/types/tokenBalance.d.ts +6 -0
  238. package/dist/types/tokenBalance.js +1 -0
  239. package/dist/types/transaction.d.ts +67 -22
  240. package/dist/types/transaction.js +31 -1
  241. package/dist/utils/breadcrumbs.js +2 -2
  242. package/dist/utils/codeMirrorThemes.js +80 -74
  243. package/dist/utils/configHelpers.d.ts +4 -0
  244. package/dist/utils/configHelpers.js +21 -0
  245. package/dist/utils/constructHashLink.d.ts +24 -0
  246. package/dist/utils/constructHashLink.js +117 -0
  247. package/dist/utils/getNetworkName.d.ts +1 -0
  248. package/dist/utils/getNetworkName.js +13 -0
  249. package/dist/utils/hex.js +1 -1
  250. package/dist/utils/lightweightChartsThemes.d.ts +1 -1
  251. package/dist/utils/lightweightChartsThemes.js +11 -11
  252. package/dist/utils/localDbStatus.d.ts +26 -0
  253. package/dist/utils/localDbStatus.js +22 -0
  254. package/dist/utils/number.d.ts +0 -7
  255. package/dist/utils/number.js +5 -30
  256. package/dist/utils/stripTrailingWhitespace.d.ts +16 -0
  257. package/dist/utils/stripTrailingWhitespace.js +22 -0
  258. package/dist/utils/tokens.d.ts +2 -0
  259. package/dist/utils/tokens.js +3 -0
  260. package/dist/utils/vaultBalanceChangeLabels.d.ts +4 -0
  261. package/dist/utils/vaultBalanceChangeLabels.js +18 -0
  262. package/package.json +89 -84
  263. package/dist/__fixtures__/orderDetail.d.ts +0 -99
  264. package/dist/__fixtures__/orderDetail.js +0 -204
  265. package/dist/__fixtures__/settings-12-11-24.json +0 -160
  266. package/dist/__mocks__/mockTransactionStore.d.ts +0 -22
  267. package/dist/__mocks__/mockTransactionStore.js +0 -56
  268. package/dist/__mocks__/settings.d.ts +0 -3
  269. package/dist/__mocks__/settings.js +0 -37
  270. package/dist/components/CheckboxMyItemsOnly.svelte +0 -23
  271. package/dist/components/CheckboxMyItemsOnly.svelte.d.ts +0 -21
  272. package/dist/components/ListViewOrderbookFilters.svelte +0 -58
  273. package/dist/components/ListViewOrderbookFilters.svelte.d.ts +0 -28
  274. package/dist/components/deployment/InvalidStrategiesSection.svelte +0 -19
  275. package/dist/components/deployment/InvalidStrategiesSection.svelte.d.ts +0 -19
  276. package/dist/components/deployment/StrategyPage.svelte.d.ts +0 -19
  277. package/dist/components/deployment/ValidStrategiesSection.svelte.d.ts +0 -19
  278. package/dist/components/deployment/getDeploymentTransactionArgs.d.ts +0 -17
  279. package/dist/components/deployment/getDeploymentTransactionArgs.js +0 -28
  280. package/dist/components/detail/DepositOrWithdrawButtons.svelte +0 -44
  281. package/dist/components/detail/DepositOrWithdrawButtons.svelte.d.ts +0 -26
  282. package/dist/components/dropdown/DropdownActiveSubgraphs.svelte +0 -38
  283. package/dist/components/dropdown/DropdownActiveSubgraphs.svelte.d.ts +0 -21
  284. package/dist/components/dropdown/DropdownOrderListAccounts.svelte +0 -15
  285. package/dist/components/dropdown/DropdownOrderListAccounts.svelte.d.ts +0 -20
  286. package/dist/components/dropdown/DropdownOrderStatus.svelte +0 -31
  287. package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +0 -19
  288. package/dist/hooks/useGui.d.ts +0 -3
  289. package/dist/hooks/useGui.js +0 -11
  290. package/dist/providers/GuiProvider.svelte +0 -8
  291. package/dist/providers/GuiProvider.svelte.d.ts +0 -21
  292. package/dist/stores/transactionStore.d.ts +0 -98
  293. package/dist/stores/transactionStore.js +0 -303
  294. package/dist/types/strategy.d.ts +0 -10
  295. package/dist/utils/time.d.ts +0 -12
  296. package/dist/utils/time.js +0 -27
  297. package/dist/utils/vault.d.ts +0 -2
  298. package/dist/utils/vault.js +0 -29
  299. /package/dist/types/{strategy.js → account.js} +0 -0
@@ -1,13 +1,12 @@
1
- import { timestampSecondsToUTCTimestamp } from '../utils/time';
2
- import { sortBy } from 'lodash';
3
- import { formatUnits } from 'viem';
1
+ import { timestampSecondsToUTCTimestamp } from "../services/time";
2
+ import { sortBy } from "lodash";
4
3
  export function prepareHistoricalOrderChartData(takeOrderEntities, colorTheme) {
5
4
  const transformedData = takeOrderEntities.map((d) => ({
6
- value: Math.abs(Number(formatUnits(BigInt(d.inputVaultBalanceChange.amount), Number(d.inputVaultBalanceChange.vault.token.decimals ?? 0))) /
7
- Number(formatUnits(BigInt(d.outputVaultBalanceChange.amount), Number(d.outputVaultBalanceChange.vault.token.decimals ?? 0)))),
5
+ value: Math.abs(Number(d.inputVaultBalanceChange.formattedAmount) /
6
+ Number(d.outputVaultBalanceChange.formattedAmount)),
8
7
  time: timestampSecondsToUTCTimestamp(BigInt(d.timestamp)),
9
- color: colorTheme == 'dark' ? '#5178FF' : '#4E4AF6',
10
- outputAmount: +d.outputVaultBalanceChange.amount
8
+ color: colorTheme == "dark" ? "#5178FF" : "#4E4AF6",
9
+ outputAmount: Number(d.outputVaultBalanceChange.amount),
11
10
  }));
12
11
  // if we have multiple object in the array with the same timestamp, we need to merge them
13
12
  // we do this by taking the weighted average of the ioratio values for objects that share the same timestamp.
@@ -23,7 +22,7 @@ export function prepareHistoricalOrderChartData(takeOrderEntities, colorTheme) {
23
22
  finalData.push({
24
23
  value: ioratioAverage,
25
24
  time: timestamp,
26
- color: objectsWithSameTimestamp[0].color
25
+ color: objectsWithSameTimestamp[0].color,
27
26
  });
28
27
  }
29
28
  else {
@@ -34,226 +33,196 @@ export function prepareHistoricalOrderChartData(takeOrderEntities, colorTheme) {
34
33
  }
35
34
  if (import.meta.vitest) {
36
35
  const { it, expect } = import.meta.vitest;
37
- it('transforms and sorts data as expected', () => {
36
+ it("transforms and sorts data as expected", () => {
38
37
  const takeOrderEntities = [
39
38
  {
40
- id: '1',
41
- timestamp: '1632000000',
42
- tradeEvent: {
43
- sender: 'sender_address',
44
- transaction: {
45
- id: 'transaction_id',
46
- from: 'sender_address',
47
- timestamp: '1632000000',
48
- blockNumber: '0'
49
- }
39
+ id: "1",
40
+ timestamp: BigInt(1632000000),
41
+ transaction: {
42
+ id: "transaction_id",
43
+ from: "0xsender_address",
44
+ timestamp: BigInt(1632000000),
45
+ blockNumber: BigInt(0),
50
46
  },
51
47
  outputVaultBalanceChange: {
52
- amount: '100',
53
- vault: {
54
- id: '1',
55
- vaultId: 'vault-id1',
56
- token: {
57
- id: 'output_token',
58
- address: 'output_token',
59
- name: 'output_token',
60
- symbol: 'output_token',
61
- decimals: '1'
62
- }
48
+ amount: BigInt(100),
49
+ formattedAmount: "100",
50
+ vaultId: BigInt(1),
51
+ __typename: "Withdraw",
52
+ token: {
53
+ id: "output_token",
54
+ address: "0xoutput_token",
55
+ name: "output_token",
56
+ symbol: "output_token",
57
+ decimals: BigInt(1),
63
58
  },
64
- id: '1',
65
- __typename: 'Withdraw',
66
- newVaultBalance: '0',
67
- oldVaultBalance: '0',
68
- timestamp: '0',
59
+ newBalance: BigInt(0),
60
+ formattedNewBalance: "0",
61
+ oldBalance: BigInt(0),
62
+ formattedOldBalance: "0",
63
+ timestamp: BigInt(0),
69
64
  transaction: {
70
- id: 'transaction_id',
71
- from: 'sender_address',
72
- timestamp: '1632000000',
73
- blockNumber: '0'
65
+ id: "transaction_id",
66
+ from: "sender_address",
67
+ timestamp: BigInt(1632000000),
68
+ blockNumber: BigInt(0),
74
69
  },
75
- orderbook: { id: '1' }
76
- },
77
- order: {
78
- id: 'order_id',
79
- orderHash: 'orderHash'
70
+ raindex: "0x1",
80
71
  },
72
+ orderHash: "orderHash",
81
73
  inputVaultBalanceChange: {
82
- vault: {
83
- id: '1',
84
- vaultId: 'vault-id1',
85
- token: {
86
- id: 'output_token',
87
- address: 'output_token',
88
- name: 'output_token',
89
- symbol: 'output_token',
90
- decimals: '1'
91
- }
74
+ vaultId: BigInt(1),
75
+ token: {
76
+ id: "output_token",
77
+ address: "0xoutput_token",
78
+ name: "output_token",
79
+ symbol: "output_token",
80
+ decimals: BigInt(1),
92
81
  },
93
- amount: '50',
94
- id: '1',
95
- __typename: 'Withdraw',
96
- newVaultBalance: '0',
97
- oldVaultBalance: '0',
98
- timestamp: '0',
82
+ amount: BigInt(50),
83
+ formattedAmount: "50",
84
+ __typename: "Withdraw",
85
+ newBalance: BigInt(0),
86
+ formattedNewBalance: "0",
87
+ oldBalance: BigInt(0),
88
+ formattedOldBalance: "0",
89
+ timestamp: BigInt(0),
99
90
  transaction: {
100
- id: 'transaction_id',
101
- from: 'sender_address',
102
- timestamp: '1632000000',
103
- blockNumber: '0'
91
+ id: "transaction_id",
92
+ from: "0xsender_address",
93
+ timestamp: BigInt(1632000000),
94
+ blockNumber: BigInt(0),
104
95
  },
105
- orderbook: { id: '1' }
96
+ raindex: "0x1",
106
97
  },
107
- orderbook: {
108
- id: '0x00'
109
- }
98
+ raindex: "0x00",
110
99
  },
111
100
  {
112
- id: '2',
113
- timestamp: '1631000000',
114
- tradeEvent: {
115
- sender: 'sender_address',
116
- transaction: {
117
- id: 'transaction_id',
118
- from: 'sender_address',
119
- timestamp: '1631000000',
120
- blockNumber: '0'
121
- }
101
+ id: "2",
102
+ timestamp: BigInt(1631000000),
103
+ transaction: {
104
+ id: "transaction_id",
105
+ from: "0xsender_address",
106
+ timestamp: BigInt(1631000000),
107
+ blockNumber: BigInt(0),
122
108
  },
123
109
  outputVaultBalanceChange: {
124
- amount: '100',
125
- vault: {
126
- id: '1',
127
- vaultId: 'vault-id1',
128
- token: {
129
- id: 'output_token',
130
- address: 'output_token',
131
- name: 'output_token',
132
- symbol: 'output_token',
133
- decimals: '1'
134
- }
110
+ amount: BigInt(100),
111
+ formattedAmount: "100",
112
+ vaultId: BigInt(1),
113
+ token: {
114
+ id: "output_token",
115
+ address: "0xoutput_token",
116
+ name: "output_token",
117
+ symbol: "output_token",
118
+ decimals: BigInt(1),
135
119
  },
136
- id: '1',
137
- __typename: 'Withdraw',
138
- newVaultBalance: '0',
139
- oldVaultBalance: '0',
140
- timestamp: '0',
120
+ newBalance: BigInt(0),
121
+ formattedNewBalance: "0",
122
+ oldBalance: BigInt(0),
123
+ formattedOldBalance: "0",
124
+ __typename: "Withdraw",
125
+ timestamp: BigInt(0),
141
126
  transaction: {
142
- id: 'transaction_id',
143
- from: 'sender_address',
144
- timestamp: '1632000000',
145
- blockNumber: '0'
127
+ id: "transaction_id",
128
+ from: "0xsender_address",
129
+ timestamp: BigInt(1632000000),
130
+ blockNumber: BigInt(0),
146
131
  },
147
- orderbook: { id: '1' }
148
- },
149
- order: {
150
- id: 'order_id',
151
- orderHash: 'orderHash'
132
+ raindex: "0x1",
152
133
  },
134
+ orderHash: "orderHash",
153
135
  inputVaultBalanceChange: {
154
- vault: {
155
- id: '1',
156
- vaultId: 'vault-id1',
157
- token: {
158
- id: 'output_token',
159
- address: 'output_token',
160
- name: 'output_token',
161
- symbol: 'output_token',
162
- decimals: '1'
163
- }
136
+ vaultId: BigInt(1),
137
+ token: {
138
+ id: "output_token",
139
+ address: "0xoutput_token",
140
+ name: "output_token",
141
+ symbol: "output_token",
142
+ decimals: BigInt(1),
164
143
  },
165
- amount: '50',
166
- id: '1',
167
- __typename: 'Withdraw',
168
- newVaultBalance: '0',
169
- oldVaultBalance: '0',
170
- timestamp: '0',
144
+ amount: BigInt(50),
145
+ formattedAmount: "50",
146
+ __typename: "Withdraw",
147
+ newBalance: BigInt(0),
148
+ formattedNewBalance: "0",
149
+ oldBalance: BigInt(0),
150
+ formattedOldBalance: "0",
151
+ timestamp: BigInt(0),
171
152
  transaction: {
172
- id: 'transaction_id',
173
- from: 'sender_address',
174
- timestamp: '1632000000',
175
- blockNumber: '0'
153
+ id: "transaction_id",
154
+ from: "0xsender_address",
155
+ timestamp: BigInt(1632000000),
156
+ blockNumber: BigInt(0),
176
157
  },
177
- orderbook: { id: '1' }
158
+ raindex: "0x1",
178
159
  },
179
- orderbook: {
180
- id: '0x00'
181
- }
160
+ raindex: "0x00",
182
161
  },
183
162
  {
184
- id: '3',
185
- timestamp: '1630000000',
186
- tradeEvent: {
187
- sender: 'sender_address',
188
- transaction: {
189
- id: 'transaction_id',
190
- from: 'sender_address',
191
- timestamp: '1630000000',
192
- blockNumber: '0'
193
- }
163
+ id: "3",
164
+ timestamp: BigInt(1630000000),
165
+ transaction: {
166
+ id: "transaction_id",
167
+ from: "0xsender_address",
168
+ timestamp: BigInt(1630000000),
169
+ blockNumber: BigInt(0),
194
170
  },
195
171
  outputVaultBalanceChange: {
196
- amount: '100',
197
- vault: {
198
- id: '1',
199
- vaultId: 'vault-id1',
200
- token: {
201
- id: 'output_token',
202
- address: 'output_token',
203
- name: 'output_token',
204
- symbol: 'output_token',
205
- decimals: '1'
206
- }
172
+ amount: BigInt(100),
173
+ formattedAmount: "100",
174
+ vaultId: BigInt(1),
175
+ token: {
176
+ id: "output_token",
177
+ address: "0xoutput_token",
178
+ name: "output_token",
179
+ symbol: "output_token",
180
+ decimals: BigInt(1),
207
181
  },
208
- id: '1',
209
- __typename: 'Withdraw',
210
- newVaultBalance: '0',
211
- oldVaultBalance: '0',
212
- timestamp: '0',
182
+ newBalance: BigInt(0),
183
+ formattedNewBalance: "0",
184
+ oldBalance: BigInt(0),
185
+ formattedOldBalance: "0",
186
+ __typename: "Withdraw",
187
+ timestamp: BigInt(0),
213
188
  transaction: {
214
- id: 'transaction_id',
215
- from: 'sender_address',
216
- timestamp: '1632000000',
217
- blockNumber: '0'
189
+ id: "transaction_id",
190
+ from: "sender_address",
191
+ timestamp: BigInt(1632000000),
192
+ blockNumber: BigInt(0),
218
193
  },
219
- orderbook: { id: '1' }
220
- },
221
- order: {
222
- id: 'order_id',
223
- orderHash: 'orderHash'
194
+ raindex: "0x1",
224
195
  },
196
+ orderHash: "orderHash",
225
197
  inputVaultBalanceChange: {
226
- vault: {
227
- id: '1',
228
- vaultId: 'vault-id1',
229
- token: {
230
- id: 'output_token',
231
- address: 'output_token',
232
- name: 'output_token',
233
- symbol: 'output_token',
234
- decimals: '1'
235
- }
198
+ vaultId: BigInt(1),
199
+ token: {
200
+ id: "output_token",
201
+ address: "0xoutput_token",
202
+ name: "output_token",
203
+ symbol: "output_token",
204
+ decimals: BigInt(1),
236
205
  },
237
- amount: '50',
238
- id: '1',
239
- __typename: 'Withdraw',
240
- newVaultBalance: '0',
241
- oldVaultBalance: '0',
242
- timestamp: '0',
206
+ newBalance: BigInt(0),
207
+ formattedNewBalance: "0",
208
+ oldBalance: BigInt(0),
209
+ formattedOldBalance: "0",
210
+ amount: BigInt(50),
211
+ formattedAmount: "50",
212
+ __typename: "Withdraw",
213
+ timestamp: BigInt(0),
243
214
  transaction: {
244
- id: 'transaction_id',
245
- from: 'sender_address',
246
- timestamp: '1632000000',
247
- blockNumber: '0'
215
+ id: "transaction_id",
216
+ from: "sender_address",
217
+ timestamp: BigInt(1632000000),
218
+ blockNumber: BigInt(0),
248
219
  },
249
- orderbook: { id: '1' }
220
+ raindex: "0x1",
250
221
  },
251
- orderbook: {
252
- id: '0x00'
253
- }
254
- }
222
+ raindex: "0x00",
223
+ },
255
224
  ];
256
- const result = prepareHistoricalOrderChartData(takeOrderEntities, 'dark');
225
+ const result = prepareHistoricalOrderChartData(takeOrderEntities, "dark");
257
226
  expect(result.length).toEqual(3);
258
227
  expect(result[0].value).toEqual(0.5);
259
228
  expect(result[0].time).toEqual(1630000000);
@@ -262,230 +231,195 @@ if (import.meta.vitest) {
262
231
  expect(result[2].value).toEqual(0.5);
263
232
  expect(result[2].time).toEqual(1632000000);
264
233
  // check the color
265
- expect(result[0].color).toEqual('#5178FF');
266
- expect(result[1].color).toEqual('#5178FF');
267
- expect(result[2].color).toEqual('#5178FF');
234
+ expect(result[0].color).toEqual("#5178FF");
235
+ expect(result[1].color).toEqual("#5178FF");
236
+ expect(result[2].color).toEqual("#5178FF");
268
237
  });
269
- it('handles the case where multiple trades have the same timestamp', () => {
238
+ it("handles the case where multiple trades have the same timestamp", () => {
270
239
  const takeOrderEntities = [
271
240
  {
272
- id: '1',
273
- timestamp: '1632000000',
274
- tradeEvent: {
275
- sender: 'sender_address',
276
- transaction: {
277
- id: 'transaction_id',
278
- from: 'sender_address',
279
- timestamp: '1632000000',
280
- blockNumber: '0'
281
- }
241
+ id: "1",
242
+ timestamp: BigInt(1632000000),
243
+ transaction: {
244
+ id: "transaction_id",
245
+ from: "0xsender_address",
246
+ timestamp: BigInt(1632000000),
247
+ blockNumber: BigInt(0),
282
248
  },
283
249
  outputVaultBalanceChange: {
284
- amount: '100',
285
- vault: {
286
- id: '1',
287
- vaultId: 'vault-id1',
288
- token: {
289
- id: 'output_token',
290
- address: 'output_token',
291
- name: 'output_token',
292
- symbol: 'output_token',
293
- decimals: '1'
294
- }
250
+ amount: BigInt(100),
251
+ formattedAmount: "100",
252
+ vaultId: BigInt(1),
253
+ token: {
254
+ id: "output_token",
255
+ address: "0xoutput_token",
256
+ name: "output_token",
257
+ symbol: "output_token",
258
+ decimals: BigInt(1),
295
259
  },
296
- id: '1',
297
- __typename: 'Withdraw',
298
- newVaultBalance: '0',
299
- oldVaultBalance: '0',
300
- timestamp: '0',
260
+ newBalance: BigInt(0),
261
+ formattedNewBalance: "0",
262
+ oldBalance: BigInt(0),
263
+ formattedOldBalance: "0",
264
+ timestamp: BigInt(0),
301
265
  transaction: {
302
- id: 'transaction_id',
303
- from: 'sender_address',
304
- timestamp: '1632000000',
305
- blockNumber: '0'
266
+ id: "transaction_id",
267
+ from: "0xsender_address",
268
+ timestamp: BigInt(1632000000),
269
+ blockNumber: BigInt(0),
306
270
  },
307
- orderbook: { id: '1' }
308
- },
309
- order: {
310
- id: 'order_id',
311
- orderHash: 'orderHash'
271
+ __typename: "Withdraw",
272
+ raindex: "0x1",
312
273
  },
274
+ orderHash: "orderHash",
313
275
  inputVaultBalanceChange: {
314
- vault: {
315
- id: '1',
316
- vaultId: 'vault-id1',
317
- token: {
318
- id: 'output_token',
319
- address: 'output_token',
320
- name: 'output_token',
321
- symbol: 'output_token',
322
- decimals: '1'
323
- }
276
+ vaultId: BigInt(1),
277
+ token: {
278
+ id: "output_token",
279
+ address: "0xoutput_token",
280
+ name: "output_token",
281
+ symbol: "output_token",
282
+ decimals: BigInt(1),
324
283
  },
325
- amount: '50',
326
- id: '1',
327
- __typename: 'Withdraw',
328
- newVaultBalance: '0',
329
- oldVaultBalance: '0',
330
- timestamp: '0',
284
+ amount: BigInt(50),
285
+ formattedAmount: "50",
286
+ newBalance: BigInt(0),
287
+ formattedNewBalance: "0",
288
+ oldBalance: BigInt(0),
289
+ formattedOldBalance: "0",
290
+ timestamp: BigInt(0),
331
291
  transaction: {
332
- id: 'transaction_id',
333
- from: 'sender_address',
334
- timestamp: '1632000000',
335
- blockNumber: '0'
292
+ id: "transaction_id",
293
+ from: "0xsender_address",
294
+ timestamp: BigInt(1632000000),
295
+ blockNumber: BigInt(0),
336
296
  },
337
- orderbook: { id: '1' }
297
+ raindex: "0x1",
338
298
  },
339
- orderbook: {
340
- id: '0x00'
341
- }
299
+ raindex: "0x00",
342
300
  },
343
301
  {
344
- id: '2',
345
- timestamp: '1632000000',
346
- tradeEvent: {
347
- sender: 'sender_address',
348
- transaction: {
349
- id: 'transaction_id',
350
- from: 'sender_address',
351
- timestamp: '1632000000',
352
- blockNumber: '0'
353
- }
302
+ id: "2",
303
+ timestamp: BigInt(1632000000),
304
+ transaction: {
305
+ id: "transaction_id",
306
+ from: "0xsender_address",
307
+ timestamp: BigInt(1632000000),
308
+ blockNumber: BigInt(0),
354
309
  },
355
310
  outputVaultBalanceChange: {
356
- amount: '200',
357
- vault: {
358
- id: '1',
359
- vaultId: 'vault-id1',
360
- token: {
361
- id: 'output_token',
362
- address: 'output_token',
363
- name: 'output_token',
364
- symbol: 'output_token',
365
- decimals: '1'
366
- }
311
+ amount: BigInt(200),
312
+ formattedAmount: "200",
313
+ vaultId: BigInt(1),
314
+ token: {
315
+ id: "output_token",
316
+ address: "0xoutput_token",
317
+ name: "output_token",
318
+ symbol: "output_token",
319
+ decimals: BigInt(1),
367
320
  },
368
- id: '1',
369
- __typename: 'Withdraw',
370
- newVaultBalance: '0',
371
- oldVaultBalance: '0',
372
- timestamp: '0',
321
+ newBalance: BigInt(0),
322
+ formattedNewBalance: "0",
323
+ oldBalance: BigInt(0),
324
+ formattedOldBalance: "0",
325
+ timestamp: BigInt(0),
373
326
  transaction: {
374
- id: 'transaction_id',
375
- from: 'sender_address',
376
- timestamp: '1632000000',
377
- blockNumber: '0'
327
+ id: "transaction_id",
328
+ from: "0xsender_address",
329
+ timestamp: BigInt(1632000000),
330
+ blockNumber: BigInt(0),
378
331
  },
379
- orderbook: { id: '1' }
380
- },
381
- order: {
382
- id: 'order_id',
383
- orderHash: 'orderHash'
332
+ raindex: "0x1",
384
333
  },
334
+ orderHash: "orderHash",
385
335
  inputVaultBalanceChange: {
386
- vault: {
387
- id: '1',
388
- vaultId: 'vault-id1',
389
- token: {
390
- id: 'output_token',
391
- address: 'output_token',
392
- name: 'output_token',
393
- symbol: 'output_token',
394
- decimals: '1'
395
- }
336
+ vaultId: BigInt(1),
337
+ token: {
338
+ id: "output_token",
339
+ address: "0xoutput_token",
340
+ name: "output_token",
341
+ symbol: "output_token",
342
+ decimals: BigInt(1),
396
343
  },
397
- amount: '50',
398
- id: '1',
399
- __typename: 'Withdraw',
400
- newVaultBalance: '0',
401
- oldVaultBalance: '0',
402
- timestamp: '0',
344
+ amount: BigInt(50),
345
+ formattedAmount: "50",
346
+ newBalance: BigInt(0),
347
+ formattedNewBalance: "0",
348
+ oldBalance: BigInt(0),
349
+ formattedOldBalance: "0",
350
+ timestamp: BigInt(0),
403
351
  transaction: {
404
- id: 'transaction_id',
405
- from: 'sender_address',
406
- timestamp: '1632000000',
407
- blockNumber: '0'
352
+ id: "transaction_id",
353
+ from: "0xsender_address",
354
+ timestamp: BigInt(1632000000),
355
+ blockNumber: BigInt(0),
408
356
  },
409
- orderbook: { id: '1' }
357
+ raindex: "0x1",
410
358
  },
411
- orderbook: {
412
- id: '0x00'
413
- }
359
+ raindex: "0x00",
414
360
  },
415
361
  {
416
- id: '3',
417
- timestamp: '1632000000',
418
- tradeEvent: {
419
- sender: 'sender_address',
420
- transaction: {
421
- id: 'transaction_id',
422
- from: 'sender_address',
423
- timestamp: '1632000000',
424
- blockNumber: '0'
425
- }
362
+ id: "3",
363
+ timestamp: BigInt(1632000000),
364
+ transaction: {
365
+ id: "transaction_id",
366
+ from: "0xsender_address",
367
+ timestamp: BigInt(1632000000),
368
+ blockNumber: BigInt(0),
426
369
  },
427
370
  outputVaultBalanceChange: {
428
- amount: '400',
429
- vault: {
430
- id: '1',
431
- vaultId: 'vault-id1',
432
- token: {
433
- id: 'output_token',
434
- address: 'output_token',
435
- name: 'output_token',
436
- symbol: 'output_token',
437
- decimals: '1'
438
- }
371
+ amount: BigInt(400),
372
+ formattedAmount: "400",
373
+ vaultId: BigInt(1),
374
+ token: {
375
+ id: "output_token",
376
+ address: "0xoutput_token",
377
+ name: "output_token",
378
+ symbol: "output_token",
379
+ decimals: BigInt(1),
439
380
  },
440
- id: '1',
441
- __typename: 'Withdraw',
442
- newVaultBalance: '0',
443
- oldVaultBalance: '0',
444
- timestamp: '0',
381
+ newBalance: BigInt(0),
382
+ formattedNewBalance: "0",
383
+ oldBalance: BigInt(0),
384
+ formattedOldBalance: "0",
385
+ timestamp: BigInt(0),
445
386
  transaction: {
446
- id: 'transaction_id',
447
- from: 'sender_address',
448
- timestamp: '1632000000',
449
- blockNumber: '0'
387
+ id: "transaction_id",
388
+ from: "0xsender_address",
389
+ timestamp: BigInt(1632000000),
390
+ blockNumber: BigInt(0),
450
391
  },
451
- orderbook: { id: '1' }
452
- },
453
- order: {
454
- id: 'order_id',
455
- orderHash: 'orderHash'
392
+ raindex: "0x1",
456
393
  },
394
+ orderHash: "orderHash",
457
395
  inputVaultBalanceChange: {
458
- vault: {
459
- id: '1',
460
- vaultId: 'vault-id1',
461
- token: {
462
- id: 'output_token',
463
- address: 'output_token',
464
- name: 'output_token',
465
- symbol: 'output_token',
466
- decimals: '1'
467
- }
396
+ vaultId: BigInt(1),
397
+ token: {
398
+ id: "output_token_id",
399
+ address: "0xoutput_token",
400
+ name: "output_token",
401
+ symbol: "output_token",
402
+ decimals: BigInt(1),
468
403
  },
469
- amount: '50',
470
- id: '1',
471
- __typename: 'Withdraw',
472
- newVaultBalance: '0',
473
- oldVaultBalance: '0',
474
- timestamp: '0',
404
+ amount: BigInt(50),
405
+ formattedAmount: "50",
406
+ newBalance: BigInt(0),
407
+ formattedNewBalance: "0",
408
+ oldBalance: BigInt(0),
409
+ formattedOldBalance: "0",
410
+ timestamp: BigInt(0),
475
411
  transaction: {
476
- id: 'transaction_id',
477
- from: 'sender_address',
478
- timestamp: '1632000000',
479
- blockNumber: '0'
412
+ id: "transaction_id",
413
+ from: "0xsender_address",
414
+ timestamp: BigInt(1632000000),
415
+ blockNumber: BigInt(0),
480
416
  },
481
- orderbook: { id: '1' }
417
+ raindex: "0x1",
482
418
  },
483
- orderbook: {
484
- id: '0x00'
485
- }
486
- }
419
+ raindex: "0x00",
420
+ },
487
421
  ];
488
- const result = prepareHistoricalOrderChartData(takeOrderEntities, 'dark');
422
+ const result = prepareHistoricalOrderChartData(takeOrderEntities, "dark");
489
423
  // calculate the weighted average of the ioratio values
490
424
  const ioratioSum = 0.5 * 100 + 0.25 * 200 + 0.125 * 400;
491
425
  const outputAmountSum = 100 + 200 + 400;
@@ -493,4 +427,63 @@ if (import.meta.vitest) {
493
427
  expect(result.length).toEqual(1);
494
428
  expect(result[0].value).toEqual(ioratioAverage);
495
429
  });
430
+ // Minimal trade builder: prepareHistoricalOrderChartData only reads
431
+ // timestamp, the two formattedAmount values and the output amount.
432
+ const makeTrade = (args) => ({
433
+ timestamp: BigInt(args.timestamp),
434
+ inputVaultBalanceChange: {
435
+ formattedAmount: args.inputFormatted,
436
+ },
437
+ outputVaultBalanceChange: {
438
+ formattedAmount: args.outputFormatted,
439
+ amount: args.outputAmount,
440
+ },
441
+ });
442
+ it("uses the light theme colour when colorTheme is not 'dark'", () => {
443
+ const trades = [
444
+ makeTrade({
445
+ timestamp: 1632000000,
446
+ inputFormatted: "50",
447
+ outputFormatted: "100",
448
+ outputAmount: BigInt(100),
449
+ }),
450
+ ];
451
+ const result = prepareHistoricalOrderChartData(trades, "light");
452
+ expect(result.length).toEqual(1);
453
+ expect(result[0].color).toEqual("#4E4AF6");
454
+ });
455
+ it("returns the absolute value of the io ratio (the output vault balance change is negative)", () => {
456
+ // The output vault balance change is debited, so its formattedAmount is negative;
457
+ // the raw input/output ratio is negative (50 / -100 = -0.5) and Math.abs yields
458
+ // the positive charted value.
459
+ const trades = [
460
+ makeTrade({
461
+ timestamp: 1632000000,
462
+ inputFormatted: "50",
463
+ outputFormatted: "-100",
464
+ outputAmount: BigInt(100),
465
+ }),
466
+ ];
467
+ const result = prepareHistoricalOrderChartData(trades, "dark");
468
+ expect(result.length).toEqual(1);
469
+ expect(result[0].value).toEqual(0.5);
470
+ });
471
+ it("keeps a single trade's value as-is even when its output amount is zero", () => {
472
+ // A lone trade at a timestamp must go through the single-trade branch and
473
+ // be preserved verbatim. The merge (weighted-average) branch would divide
474
+ // by the zero output amount and produce NaN, so a zero output amount
475
+ // distinguishes the two branches.
476
+ const trades = [
477
+ makeTrade({
478
+ timestamp: 1632000000,
479
+ inputFormatted: "50",
480
+ outputFormatted: "100",
481
+ outputAmount: BigInt(0),
482
+ }),
483
+ ];
484
+ const result = prepareHistoricalOrderChartData(trades, "dark");
485
+ expect(result.length).toEqual(1);
486
+ expect(result[0].value).toEqual(0.5);
487
+ expect(Number.isNaN(result[0].value)).toBe(false);
488
+ });
496
489
  }