@rainlanguage/ui-components 0.0.1-alpha.237 → 0.0.1-alpha.239

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 (176) hide show
  1. package/README.md +14 -6
  2. package/dist/__fixtures__/settings.yaml +18 -20
  3. package/dist/__mocks__/MockCodeMirrorEditor.svelte +17 -0
  4. package/dist/__mocks__/MockCodeMirrorEditor.svelte.d.ts +21 -0
  5. package/dist/__mocks__/MockComponent.js +1 -1
  6. package/dist/__mocks__/MockComponent.svelte +7 -3
  7. package/dist/__mocks__/MockComponent.svelte.d.ts +1 -0
  8. package/dist/__mocks__/mockWeb3Config.d.ts +1 -1
  9. package/dist/__mocks__/mockWeb3Config.js +10 -7
  10. package/dist/__mocks__/queries.js +9 -9
  11. package/dist/__mocks__/stores.d.ts +4 -4
  12. package/dist/__mocks__/stores.js +40 -40
  13. package/dist/app.css +3 -3
  14. package/dist/components/ButtonDarkMode.svelte +7 -1
  15. package/dist/components/ButtonScrub.svelte +22 -0
  16. package/dist/components/ButtonScrub.svelte.d.ts +25 -0
  17. package/dist/components/ButtonVaultLink.svelte +3 -2
  18. package/dist/components/ButtonVaultLink.svelte.d.ts +2 -2
  19. package/dist/components/CodeMirrorRainlang.svelte +19 -2
  20. package/dist/components/CodeMirrorRainlang.svelte.d.ts +2 -1
  21. package/dist/components/Hash.svelte +3 -2
  22. package/dist/components/{ListViewOrderbookFilters.svelte → ListViewRaindexFilters.svelte} +7 -7
  23. package/dist/components/{ListViewOrderbookFilters.svelte.d.ts → ListViewRaindexFilters.svelte.d.ts} +7 -7
  24. package/dist/components/LocalDbStatusBadge.svelte.d.ts +1 -1
  25. package/dist/components/LocalDbStatusCard.svelte +7 -4
  26. package/dist/components/LocalDbStatusCard.svelte.d.ts +2 -2
  27. package/dist/components/LocalDbStatusModal.svelte +16 -14
  28. package/dist/components/LocalDbStatusModal.svelte.d.ts +2 -2
  29. package/dist/components/OrderOrVaultHash.svelte +2 -2
  30. package/dist/components/OrderOrVaultHash.svelte.d.ts +2 -2
  31. package/dist/components/Sensitive.svelte +16 -0
  32. package/dist/components/Sensitive.svelte.d.ts +28 -0
  33. package/dist/components/TanstackAppTable.svelte +146 -87
  34. package/dist/components/TanstackAppTable.svelte.d.ts +1 -1
  35. package/dist/components/VaultBalanceChangeTypeFilter.svelte +1 -1
  36. package/dist/components/VaultBalanceChangeTypeFilter.svelte.d.ts +1 -1
  37. package/dist/components/VaultCard.svelte +1 -1
  38. package/dist/components/VaultCard.svelte.d.ts +1 -1
  39. package/dist/components/charts/OrderTradesChart.svelte +116 -97
  40. package/dist/components/charts/OrderTradesChart.svelte.d.ts +2 -2
  41. package/dist/components/charts/transformAndSortData.d.ts +1 -1
  42. package/dist/components/charts/transformAndSortData.js +19 -19
  43. package/dist/components/deployment/DeploymentSteps.svelte +5 -2
  44. package/dist/components/deployment/DeploymentSteps.svelte.d.ts +1 -1
  45. package/dist/components/deployment/DeploymentsSection.svelte.d.ts +1 -1
  46. package/dist/components/deployment/DepositInput.svelte +1 -1
  47. package/dist/components/deployment/DepositInput.svelte.d.ts +1 -1
  48. package/dist/components/deployment/FieldDefinitionInput.svelte +1 -1
  49. package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +1 -1
  50. package/dist/components/deployment/OrderPage.svelte.d.ts +1 -1
  51. package/dist/components/deployment/SelectToken.svelte.d.ts +1 -1
  52. package/dist/components/deployment/TokenIOInput.svelte +1 -1
  53. package/dist/components/deployment/TokenIOInput.svelte.d.ts +1 -1
  54. package/dist/components/deployment/TokenSelectionModal.svelte.d.ts +1 -1
  55. package/dist/components/detail/OrderDetail.svelte +12 -6
  56. package/dist/components/detail/OrderDetail.svelte.d.ts +2 -2
  57. package/dist/components/detail/TanstackOrderQuote.svelte +22 -0
  58. package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +1 -1
  59. package/dist/components/detail/VaultDetail.svelte +12 -10
  60. package/dist/components/detail/VaultDetail.svelte.d.ts +2 -2
  61. package/dist/components/dropdown/{DropdownOrderbooksFilter.svelte → DropdownRaindexesFilter.svelte} +54 -54
  62. package/dist/components/dropdown/DropdownRaindexesFilter.svelte.d.ts +25 -0
  63. package/dist/components/dropdown/DropdownTokensFilter.svelte.d.ts +1 -1
  64. package/dist/components/icon/Refresh.svelte +2 -1
  65. package/dist/components/icon/Refresh.svelte.d.ts +1 -0
  66. package/dist/components/input/InputTokenAmount.svelte +16 -1
  67. package/dist/components/input/InputTokenAmount.svelte.d.ts +1 -1
  68. package/dist/components/tables/OrderTradesListTable.svelte +113 -98
  69. package/dist/components/tables/OrderTradesListTable.svelte.d.ts +1 -1
  70. package/dist/components/tables/OrderVaultsVolTable.svelte +1 -1
  71. package/dist/components/tables/OrderVaultsVolTable.svelte.d.ts +1 -1
  72. package/dist/components/tables/OrdersListTable.svelte +19 -17
  73. package/dist/components/tables/OrdersListTable.svelte.d.ts +1 -1
  74. package/dist/components/tables/VaultBalanceChangesTable.svelte +1 -1
  75. package/dist/components/tables/VaultBalanceChangesTable.svelte.d.ts +1 -1
  76. package/dist/components/tables/VaultsListTable.svelte +24 -21
  77. package/dist/components/tables/VaultsListTable.svelte.d.ts +2 -2
  78. package/dist/components/transactions/FixedBottomTransaction.svelte +1 -0
  79. package/dist/components/transactions/getStatusEmoji.d.ts +1 -1
  80. package/dist/components/transactions/getStatusEmoji.js +13 -13
  81. package/dist/consts.js +1 -1
  82. package/dist/errors/DeploymentStepsError.js +3 -3
  83. package/dist/errors/index.d.ts +1 -1
  84. package/dist/errors/index.js +1 -1
  85. package/dist/hooks/useLocalDb.d.ts +1 -1
  86. package/dist/hooks/useLocalDb.js +3 -3
  87. package/dist/hooks/useRaindexClient.d.ts +1 -1
  88. package/dist/hooks/useRaindexClient.js +4 -4
  89. package/dist/hooks/useRaindexOrderBuilder.d.ts +1 -1
  90. package/dist/hooks/useRaindexOrderBuilder.js +4 -4
  91. package/dist/index.d.ts +122 -114
  92. package/dist/index.js +115 -109
  93. package/dist/models/Transaction.d.ts +4 -4
  94. package/dist/models/Transaction.js +9 -9
  95. package/dist/providers/RaindexClientProvider.svelte +1 -1
  96. package/dist/providers/RaindexClientProvider.svelte.d.ts +1 -1
  97. package/dist/providers/RaindexOrderBuilderProvider.svelte +1 -1
  98. package/dist/providers/RaindexOrderBuilderProvider.svelte.d.ts +1 -1
  99. package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte.d.ts +1 -1
  100. package/dist/providers/dotrainRegistry/context.d.ts +2 -2
  101. package/dist/providers/dotrainRegistry/context.js +13 -10
  102. package/dist/providers/dotrainRegistry/useDotrainRegistry.d.ts +1 -1
  103. package/dist/providers/dotrainRegistry/useDotrainRegistry.js +8 -8
  104. package/dist/providers/registry/RegistryManager.js +8 -7
  105. package/dist/providers/registry/context.d.ts +1 -1
  106. package/dist/providers/registry/context.js +9 -9
  107. package/dist/providers/registry/useRegistry.d.ts +1 -1
  108. package/dist/providers/registry/useRegistry.js +5 -5
  109. package/dist/providers/toasts/context.d.ts +2 -2
  110. package/dist/providers/toasts/context.js +4 -4
  111. package/dist/providers/toasts/useToasts.d.ts +1 -1
  112. package/dist/providers/toasts/useToasts.js +4 -4
  113. package/dist/providers/transactions/TransactionManager.d.ts +14 -15
  114. package/dist/providers/transactions/TransactionManager.js +107 -107
  115. package/dist/providers/transactions/context.d.ts +1 -1
  116. package/dist/providers/transactions/context.js +4 -4
  117. package/dist/providers/transactions/useTransactions.js +2 -2
  118. package/dist/providers/wallet/context.d.ts +1 -1
  119. package/dist/providers/wallet/context.js +11 -11
  120. package/dist/providers/wallet/useAccount.js +27 -27
  121. package/dist/queries/keys.js +10 -10
  122. package/dist/queries/queryClient.d.ts +1 -1
  123. package/dist/queries/queryClient.js +8 -8
  124. package/dist/services/awaitTransactionIndexing.d.ts +8 -8
  125. package/dist/services/awaitTransactionIndexing.js +10 -8
  126. package/dist/services/getExplorerLink.js +2 -2
  127. package/dist/services/handleShareChoices.d.ts +1 -1
  128. package/dist/services/handleShareChoices.js +4 -4
  129. package/dist/services/historicalOrderCharts.d.ts +2 -2
  130. package/dist/services/historicalOrderCharts.js +260 -201
  131. package/dist/services/index.d.ts +5 -3
  132. package/dist/services/index.js +3 -2
  133. package/dist/services/loadRegistryUrl.d.ts +1 -1
  134. package/dist/services/loadRegistryUrl.js +5 -5
  135. package/dist/services/pairTradesChartData.d.ts +2 -2
  136. package/dist/services/pairTradesChartData.js +28 -24
  137. package/dist/services/registry.d.ts +1 -1
  138. package/dist/services/registry.js +10 -10
  139. package/dist/services/time.d.ts +1 -1
  140. package/dist/services/time.js +35 -35
  141. package/dist/services/validateAmount.d.ts +30 -0
  142. package/dist/services/validateAmount.js +53 -0
  143. package/dist/storesGeneric/cachedWritableStore.d.ts +2 -2
  144. package/dist/storesGeneric/cachedWritableStore.js +3 -3
  145. package/dist/storesGeneric/scrub.d.ts +14 -0
  146. package/dist/storesGeneric/scrub.js +22 -0
  147. package/dist/test/matchers.d.ts +2 -2
  148. package/dist/test/matchers.js +2 -2
  149. package/dist/types/account.d.ts +2 -2
  150. package/dist/types/appStores.d.ts +3 -3
  151. package/dist/types/modal.d.ts +3 -3
  152. package/dist/types/order.d.ts +1 -1
  153. package/dist/types/toast.d.ts +2 -2
  154. package/dist/types/tokenBalance.d.ts +1 -1
  155. package/dist/types/transaction.d.ts +4 -4
  156. package/dist/utils/breadcrumbs.js +2 -2
  157. package/dist/utils/codeMirrorThemes.js +80 -74
  158. package/dist/utils/configHelpers.d.ts +1 -1
  159. package/dist/utils/configHelpers.js +6 -6
  160. package/dist/utils/constructHashLink.d.ts +3 -3
  161. package/dist/utils/constructHashLink.js +39 -37
  162. package/dist/utils/getNetworkName.js +5 -5
  163. package/dist/utils/hex.js +1 -1
  164. package/dist/utils/lightweightChartsThemes.d.ts +1 -1
  165. package/dist/utils/lightweightChartsThemes.js +11 -11
  166. package/dist/utils/localDbStatus.d.ts +26 -0
  167. package/dist/utils/localDbStatus.js +22 -0
  168. package/dist/utils/number.js +5 -3
  169. package/dist/utils/stripTrailingWhitespace.d.ts +16 -0
  170. package/dist/utils/stripTrailingWhitespace.js +22 -0
  171. package/dist/utils/tokens.d.ts +1 -1
  172. package/dist/utils/tokens.js +1 -1
  173. package/dist/utils/vaultBalanceChangeLabels.d.ts +1 -1
  174. package/dist/utils/vaultBalanceChangeLabels.js +11 -11
  175. package/package.json +89 -89
  176. package/dist/components/dropdown/DropdownOrderbooksFilter.svelte.d.ts +0 -25
@@ -1,12 +1,12 @@
1
- import { timestampSecondsToUTCTimestamp } from '../services/time';
2
- import { sortBy } from 'lodash';
1
+ import { timestampSecondsToUTCTimestamp } from "../services/time";
2
+ import { sortBy } from "lodash";
3
3
  export function prepareHistoricalOrderChartData(takeOrderEntities, colorTheme) {
4
4
  const transformedData = takeOrderEntities.map((d) => ({
5
5
  value: Math.abs(Number(d.inputVaultBalanceChange.formattedAmount) /
6
6
  Number(d.outputVaultBalanceChange.formattedAmount)),
7
7
  time: timestampSecondsToUTCTimestamp(BigInt(d.timestamp)),
8
- color: colorTheme == 'dark' ? '#5178FF' : '#4E4AF6',
9
- outputAmount: Number(d.outputVaultBalanceChange.amount)
8
+ color: colorTheme == "dark" ? "#5178FF" : "#4E4AF6",
9
+ outputAmount: Number(d.outputVaultBalanceChange.amount),
10
10
  }));
11
11
  // if we have multiple object in the array with the same timestamp, we need to merge them
12
12
  // we do this by taking the weighted average of the ioratio values for objects that share the same timestamp.
@@ -22,7 +22,7 @@ export function prepareHistoricalOrderChartData(takeOrderEntities, colorTheme) {
22
22
  finalData.push({
23
23
  value: ioratioAverage,
24
24
  time: timestamp,
25
- color: objectsWithSameTimestamp[0].color
25
+ color: objectsWithSameTimestamp[0].color,
26
26
  });
27
27
  }
28
28
  else {
@@ -33,196 +33,196 @@ export function prepareHistoricalOrderChartData(takeOrderEntities, colorTheme) {
33
33
  }
34
34
  if (import.meta.vitest) {
35
35
  const { it, expect } = import.meta.vitest;
36
- it('transforms and sorts data as expected', () => {
36
+ it("transforms and sorts data as expected", () => {
37
37
  const takeOrderEntities = [
38
38
  {
39
- id: '1',
39
+ id: "1",
40
40
  timestamp: BigInt(1632000000),
41
41
  transaction: {
42
- id: 'transaction_id',
43
- from: '0xsender_address',
42
+ id: "transaction_id",
43
+ from: "0xsender_address",
44
44
  timestamp: BigInt(1632000000),
45
- blockNumber: BigInt(0)
45
+ blockNumber: BigInt(0),
46
46
  },
47
47
  outputVaultBalanceChange: {
48
48
  amount: BigInt(100),
49
- formattedAmount: '100',
49
+ formattedAmount: "100",
50
50
  vaultId: BigInt(1),
51
- __typename: 'Withdraw',
51
+ __typename: "Withdraw",
52
52
  token: {
53
- id: 'output_token',
54
- address: '0xoutput_token',
55
- name: 'output_token',
56
- symbol: 'output_token',
57
- decimals: BigInt(1)
53
+ id: "output_token",
54
+ address: "0xoutput_token",
55
+ name: "output_token",
56
+ symbol: "output_token",
57
+ decimals: BigInt(1),
58
58
  },
59
59
  newBalance: BigInt(0),
60
- formattedNewBalance: '0',
60
+ formattedNewBalance: "0",
61
61
  oldBalance: BigInt(0),
62
- formattedOldBalance: '0',
62
+ formattedOldBalance: "0",
63
63
  timestamp: BigInt(0),
64
64
  transaction: {
65
- id: 'transaction_id',
66
- from: 'sender_address',
65
+ id: "transaction_id",
66
+ from: "sender_address",
67
67
  timestamp: BigInt(1632000000),
68
- blockNumber: BigInt(0)
68
+ blockNumber: BigInt(0),
69
69
  },
70
- orderbook: '0x1'
70
+ raindex: "0x1",
71
71
  },
72
- orderHash: 'orderHash',
72
+ orderHash: "orderHash",
73
73
  inputVaultBalanceChange: {
74
74
  vaultId: BigInt(1),
75
75
  token: {
76
- id: 'output_token',
77
- address: '0xoutput_token',
78
- name: 'output_token',
79
- symbol: 'output_token',
80
- decimals: BigInt(1)
76
+ id: "output_token",
77
+ address: "0xoutput_token",
78
+ name: "output_token",
79
+ symbol: "output_token",
80
+ decimals: BigInt(1),
81
81
  },
82
82
  amount: BigInt(50),
83
- formattedAmount: '50',
84
- __typename: 'Withdraw',
83
+ formattedAmount: "50",
84
+ __typename: "Withdraw",
85
85
  newBalance: BigInt(0),
86
- formattedNewBalance: '0',
86
+ formattedNewBalance: "0",
87
87
  oldBalance: BigInt(0),
88
- formattedOldBalance: '0',
88
+ formattedOldBalance: "0",
89
89
  timestamp: BigInt(0),
90
90
  transaction: {
91
- id: 'transaction_id',
92
- from: '0xsender_address',
91
+ id: "transaction_id",
92
+ from: "0xsender_address",
93
93
  timestamp: BigInt(1632000000),
94
- blockNumber: BigInt(0)
94
+ blockNumber: BigInt(0),
95
95
  },
96
- orderbook: '0x1'
96
+ raindex: "0x1",
97
97
  },
98
- orderbook: '0x00'
98
+ raindex: "0x00",
99
99
  },
100
100
  {
101
- id: '2',
101
+ id: "2",
102
102
  timestamp: BigInt(1631000000),
103
103
  transaction: {
104
- id: 'transaction_id',
105
- from: '0xsender_address',
104
+ id: "transaction_id",
105
+ from: "0xsender_address",
106
106
  timestamp: BigInt(1631000000),
107
- blockNumber: BigInt(0)
107
+ blockNumber: BigInt(0),
108
108
  },
109
109
  outputVaultBalanceChange: {
110
110
  amount: BigInt(100),
111
- formattedAmount: '100',
111
+ formattedAmount: "100",
112
112
  vaultId: BigInt(1),
113
113
  token: {
114
- id: 'output_token',
115
- address: '0xoutput_token',
116
- name: 'output_token',
117
- symbol: 'output_token',
118
- decimals: BigInt(1)
114
+ id: "output_token",
115
+ address: "0xoutput_token",
116
+ name: "output_token",
117
+ symbol: "output_token",
118
+ decimals: BigInt(1),
119
119
  },
120
120
  newBalance: BigInt(0),
121
- formattedNewBalance: '0',
121
+ formattedNewBalance: "0",
122
122
  oldBalance: BigInt(0),
123
- formattedOldBalance: '0',
124
- __typename: 'Withdraw',
123
+ formattedOldBalance: "0",
124
+ __typename: "Withdraw",
125
125
  timestamp: BigInt(0),
126
126
  transaction: {
127
- id: 'transaction_id',
128
- from: '0xsender_address',
127
+ id: "transaction_id",
128
+ from: "0xsender_address",
129
129
  timestamp: BigInt(1632000000),
130
- blockNumber: BigInt(0)
130
+ blockNumber: BigInt(0),
131
131
  },
132
- orderbook: '0x1'
132
+ raindex: "0x1",
133
133
  },
134
- orderHash: 'orderHash',
134
+ orderHash: "orderHash",
135
135
  inputVaultBalanceChange: {
136
136
  vaultId: BigInt(1),
137
137
  token: {
138
- id: 'output_token',
139
- address: '0xoutput_token',
140
- name: 'output_token',
141
- symbol: 'output_token',
142
- decimals: BigInt(1)
138
+ id: "output_token",
139
+ address: "0xoutput_token",
140
+ name: "output_token",
141
+ symbol: "output_token",
142
+ decimals: BigInt(1),
143
143
  },
144
144
  amount: BigInt(50),
145
- formattedAmount: '50',
146
- __typename: 'Withdraw',
145
+ formattedAmount: "50",
146
+ __typename: "Withdraw",
147
147
  newBalance: BigInt(0),
148
- formattedNewBalance: '0',
148
+ formattedNewBalance: "0",
149
149
  oldBalance: BigInt(0),
150
- formattedOldBalance: '0',
150
+ formattedOldBalance: "0",
151
151
  timestamp: BigInt(0),
152
152
  transaction: {
153
- id: 'transaction_id',
154
- from: '0xsender_address',
153
+ id: "transaction_id",
154
+ from: "0xsender_address",
155
155
  timestamp: BigInt(1632000000),
156
- blockNumber: BigInt(0)
156
+ blockNumber: BigInt(0),
157
157
  },
158
- orderbook: '0x1'
158
+ raindex: "0x1",
159
159
  },
160
- orderbook: '0x00'
160
+ raindex: "0x00",
161
161
  },
162
162
  {
163
- id: '3',
163
+ id: "3",
164
164
  timestamp: BigInt(1630000000),
165
165
  transaction: {
166
- id: 'transaction_id',
167
- from: '0xsender_address',
166
+ id: "transaction_id",
167
+ from: "0xsender_address",
168
168
  timestamp: BigInt(1630000000),
169
- blockNumber: BigInt(0)
169
+ blockNumber: BigInt(0),
170
170
  },
171
171
  outputVaultBalanceChange: {
172
172
  amount: BigInt(100),
173
- formattedAmount: '100',
173
+ formattedAmount: "100",
174
174
  vaultId: BigInt(1),
175
175
  token: {
176
- id: 'output_token',
177
- address: '0xoutput_token',
178
- name: 'output_token',
179
- symbol: 'output_token',
180
- decimals: BigInt(1)
176
+ id: "output_token",
177
+ address: "0xoutput_token",
178
+ name: "output_token",
179
+ symbol: "output_token",
180
+ decimals: BigInt(1),
181
181
  },
182
182
  newBalance: BigInt(0),
183
- formattedNewBalance: '0',
183
+ formattedNewBalance: "0",
184
184
  oldBalance: BigInt(0),
185
- formattedOldBalance: '0',
186
- __typename: 'Withdraw',
185
+ formattedOldBalance: "0",
186
+ __typename: "Withdraw",
187
187
  timestamp: BigInt(0),
188
188
  transaction: {
189
- id: 'transaction_id',
190
- from: 'sender_address',
189
+ id: "transaction_id",
190
+ from: "sender_address",
191
191
  timestamp: BigInt(1632000000),
192
- blockNumber: BigInt(0)
192
+ blockNumber: BigInt(0),
193
193
  },
194
- orderbook: '0x1'
194
+ raindex: "0x1",
195
195
  },
196
- orderHash: 'orderHash',
196
+ orderHash: "orderHash",
197
197
  inputVaultBalanceChange: {
198
198
  vaultId: BigInt(1),
199
199
  token: {
200
- id: 'output_token',
201
- address: '0xoutput_token',
202
- name: 'output_token',
203
- symbol: 'output_token',
204
- decimals: BigInt(1)
200
+ id: "output_token",
201
+ address: "0xoutput_token",
202
+ name: "output_token",
203
+ symbol: "output_token",
204
+ decimals: BigInt(1),
205
205
  },
206
206
  newBalance: BigInt(0),
207
- formattedNewBalance: '0',
207
+ formattedNewBalance: "0",
208
208
  oldBalance: BigInt(0),
209
- formattedOldBalance: '0',
209
+ formattedOldBalance: "0",
210
210
  amount: BigInt(50),
211
- formattedAmount: '50',
212
- __typename: 'Withdraw',
211
+ formattedAmount: "50",
212
+ __typename: "Withdraw",
213
213
  timestamp: BigInt(0),
214
214
  transaction: {
215
- id: 'transaction_id',
216
- from: 'sender_address',
215
+ id: "transaction_id",
216
+ from: "sender_address",
217
217
  timestamp: BigInt(1632000000),
218
- blockNumber: BigInt(0)
218
+ blockNumber: BigInt(0),
219
219
  },
220
- orderbook: '0x1'
220
+ raindex: "0x1",
221
221
  },
222
- orderbook: '0x00'
223
- }
222
+ raindex: "0x00",
223
+ },
224
224
  ];
225
- const result = prepareHistoricalOrderChartData(takeOrderEntities, 'dark');
225
+ const result = prepareHistoricalOrderChartData(takeOrderEntities, "dark");
226
226
  expect(result.length).toEqual(3);
227
227
  expect(result[0].value).toEqual(0.5);
228
228
  expect(result[0].time).toEqual(1630000000);
@@ -231,195 +231,195 @@ if (import.meta.vitest) {
231
231
  expect(result[2].value).toEqual(0.5);
232
232
  expect(result[2].time).toEqual(1632000000);
233
233
  // check the color
234
- expect(result[0].color).toEqual('#5178FF');
235
- expect(result[1].color).toEqual('#5178FF');
236
- 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");
237
237
  });
238
- it('handles the case where multiple trades have the same timestamp', () => {
238
+ it("handles the case where multiple trades have the same timestamp", () => {
239
239
  const takeOrderEntities = [
240
240
  {
241
- id: '1',
241
+ id: "1",
242
242
  timestamp: BigInt(1632000000),
243
243
  transaction: {
244
- id: 'transaction_id',
245
- from: '0xsender_address',
244
+ id: "transaction_id",
245
+ from: "0xsender_address",
246
246
  timestamp: BigInt(1632000000),
247
- blockNumber: BigInt(0)
247
+ blockNumber: BigInt(0),
248
248
  },
249
249
  outputVaultBalanceChange: {
250
250
  amount: BigInt(100),
251
- formattedAmount: '100',
251
+ formattedAmount: "100",
252
252
  vaultId: BigInt(1),
253
253
  token: {
254
- id: 'output_token',
255
- address: '0xoutput_token',
256
- name: 'output_token',
257
- symbol: 'output_token',
258
- decimals: BigInt(1)
254
+ id: "output_token",
255
+ address: "0xoutput_token",
256
+ name: "output_token",
257
+ symbol: "output_token",
258
+ decimals: BigInt(1),
259
259
  },
260
260
  newBalance: BigInt(0),
261
- formattedNewBalance: '0',
261
+ formattedNewBalance: "0",
262
262
  oldBalance: BigInt(0),
263
- formattedOldBalance: '0',
263
+ formattedOldBalance: "0",
264
264
  timestamp: BigInt(0),
265
265
  transaction: {
266
- id: 'transaction_id',
267
- from: '0xsender_address',
266
+ id: "transaction_id",
267
+ from: "0xsender_address",
268
268
  timestamp: BigInt(1632000000),
269
- blockNumber: BigInt(0)
269
+ blockNumber: BigInt(0),
270
270
  },
271
- __typename: 'Withdraw',
272
- orderbook: '0x1'
271
+ __typename: "Withdraw",
272
+ raindex: "0x1",
273
273
  },
274
- orderHash: 'orderHash',
274
+ orderHash: "orderHash",
275
275
  inputVaultBalanceChange: {
276
276
  vaultId: BigInt(1),
277
277
  token: {
278
- id: 'output_token',
279
- address: '0xoutput_token',
280
- name: 'output_token',
281
- symbol: 'output_token',
282
- decimals: BigInt(1)
278
+ id: "output_token",
279
+ address: "0xoutput_token",
280
+ name: "output_token",
281
+ symbol: "output_token",
282
+ decimals: BigInt(1),
283
283
  },
284
284
  amount: BigInt(50),
285
- formattedAmount: '50',
285
+ formattedAmount: "50",
286
286
  newBalance: BigInt(0),
287
- formattedNewBalance: '0',
287
+ formattedNewBalance: "0",
288
288
  oldBalance: BigInt(0),
289
- formattedOldBalance: '0',
289
+ formattedOldBalance: "0",
290
290
  timestamp: BigInt(0),
291
291
  transaction: {
292
- id: 'transaction_id',
293
- from: '0xsender_address',
292
+ id: "transaction_id",
293
+ from: "0xsender_address",
294
294
  timestamp: BigInt(1632000000),
295
- blockNumber: BigInt(0)
295
+ blockNumber: BigInt(0),
296
296
  },
297
- orderbook: '0x1'
297
+ raindex: "0x1",
298
298
  },
299
- orderbook: '0x00'
299
+ raindex: "0x00",
300
300
  },
301
301
  {
302
- id: '2',
302
+ id: "2",
303
303
  timestamp: BigInt(1632000000),
304
304
  transaction: {
305
- id: 'transaction_id',
306
- from: '0xsender_address',
305
+ id: "transaction_id",
306
+ from: "0xsender_address",
307
307
  timestamp: BigInt(1632000000),
308
- blockNumber: BigInt(0)
308
+ blockNumber: BigInt(0),
309
309
  },
310
310
  outputVaultBalanceChange: {
311
311
  amount: BigInt(200),
312
- formattedAmount: '200',
312
+ formattedAmount: "200",
313
313
  vaultId: BigInt(1),
314
314
  token: {
315
- id: 'output_token',
316
- address: '0xoutput_token',
317
- name: 'output_token',
318
- symbol: 'output_token',
319
- decimals: BigInt(1)
315
+ id: "output_token",
316
+ address: "0xoutput_token",
317
+ name: "output_token",
318
+ symbol: "output_token",
319
+ decimals: BigInt(1),
320
320
  },
321
321
  newBalance: BigInt(0),
322
- formattedNewBalance: '0',
322
+ formattedNewBalance: "0",
323
323
  oldBalance: BigInt(0),
324
- formattedOldBalance: '0',
324
+ formattedOldBalance: "0",
325
325
  timestamp: BigInt(0),
326
326
  transaction: {
327
- id: 'transaction_id',
328
- from: '0xsender_address',
327
+ id: "transaction_id",
328
+ from: "0xsender_address",
329
329
  timestamp: BigInt(1632000000),
330
- blockNumber: BigInt(0)
330
+ blockNumber: BigInt(0),
331
331
  },
332
- orderbook: '0x1'
332
+ raindex: "0x1",
333
333
  },
334
- orderHash: 'orderHash',
334
+ orderHash: "orderHash",
335
335
  inputVaultBalanceChange: {
336
336
  vaultId: BigInt(1),
337
337
  token: {
338
- id: 'output_token',
339
- address: '0xoutput_token',
340
- name: 'output_token',
341
- symbol: 'output_token',
342
- decimals: BigInt(1)
338
+ id: "output_token",
339
+ address: "0xoutput_token",
340
+ name: "output_token",
341
+ symbol: "output_token",
342
+ decimals: BigInt(1),
343
343
  },
344
344
  amount: BigInt(50),
345
- formattedAmount: '50',
345
+ formattedAmount: "50",
346
346
  newBalance: BigInt(0),
347
- formattedNewBalance: '0',
347
+ formattedNewBalance: "0",
348
348
  oldBalance: BigInt(0),
349
- formattedOldBalance: '0',
349
+ formattedOldBalance: "0",
350
350
  timestamp: BigInt(0),
351
351
  transaction: {
352
- id: 'transaction_id',
353
- from: '0xsender_address',
352
+ id: "transaction_id",
353
+ from: "0xsender_address",
354
354
  timestamp: BigInt(1632000000),
355
- blockNumber: BigInt(0)
355
+ blockNumber: BigInt(0),
356
356
  },
357
- orderbook: '0x1'
357
+ raindex: "0x1",
358
358
  },
359
- orderbook: '0x00'
359
+ raindex: "0x00",
360
360
  },
361
361
  {
362
- id: '3',
362
+ id: "3",
363
363
  timestamp: BigInt(1632000000),
364
364
  transaction: {
365
- id: 'transaction_id',
366
- from: '0xsender_address',
365
+ id: "transaction_id",
366
+ from: "0xsender_address",
367
367
  timestamp: BigInt(1632000000),
368
- blockNumber: BigInt(0)
368
+ blockNumber: BigInt(0),
369
369
  },
370
370
  outputVaultBalanceChange: {
371
371
  amount: BigInt(400),
372
- formattedAmount: '400',
372
+ formattedAmount: "400",
373
373
  vaultId: BigInt(1),
374
374
  token: {
375
- id: 'output_token',
376
- address: '0xoutput_token',
377
- name: 'output_token',
378
- symbol: 'output_token',
379
- decimals: BigInt(1)
375
+ id: "output_token",
376
+ address: "0xoutput_token",
377
+ name: "output_token",
378
+ symbol: "output_token",
379
+ decimals: BigInt(1),
380
380
  },
381
381
  newBalance: BigInt(0),
382
- formattedNewBalance: '0',
382
+ formattedNewBalance: "0",
383
383
  oldBalance: BigInt(0),
384
- formattedOldBalance: '0',
384
+ formattedOldBalance: "0",
385
385
  timestamp: BigInt(0),
386
386
  transaction: {
387
- id: 'transaction_id',
388
- from: '0xsender_address',
387
+ id: "transaction_id",
388
+ from: "0xsender_address",
389
389
  timestamp: BigInt(1632000000),
390
- blockNumber: BigInt(0)
390
+ blockNumber: BigInt(0),
391
391
  },
392
- orderbook: '0x1'
392
+ raindex: "0x1",
393
393
  },
394
- orderHash: 'orderHash',
394
+ orderHash: "orderHash",
395
395
  inputVaultBalanceChange: {
396
396
  vaultId: BigInt(1),
397
397
  token: {
398
- id: 'output_token_id',
399
- address: '0xoutput_token',
400
- name: 'output_token',
401
- symbol: 'output_token',
402
- decimals: BigInt(1)
398
+ id: "output_token_id",
399
+ address: "0xoutput_token",
400
+ name: "output_token",
401
+ symbol: "output_token",
402
+ decimals: BigInt(1),
403
403
  },
404
404
  amount: BigInt(50),
405
- formattedAmount: '50',
405
+ formattedAmount: "50",
406
406
  newBalance: BigInt(0),
407
- formattedNewBalance: '0',
407
+ formattedNewBalance: "0",
408
408
  oldBalance: BigInt(0),
409
- formattedOldBalance: '0',
409
+ formattedOldBalance: "0",
410
410
  timestamp: BigInt(0),
411
411
  transaction: {
412
- id: 'transaction_id',
413
- from: '0xsender_address',
412
+ id: "transaction_id",
413
+ from: "0xsender_address",
414
414
  timestamp: BigInt(1632000000),
415
- blockNumber: BigInt(0)
415
+ blockNumber: BigInt(0),
416
416
  },
417
- orderbook: '0x1'
417
+ raindex: "0x1",
418
418
  },
419
- orderbook: '0x00'
420
- }
419
+ raindex: "0x00",
420
+ },
421
421
  ];
422
- const result = prepareHistoricalOrderChartData(takeOrderEntities, 'dark');
422
+ const result = prepareHistoricalOrderChartData(takeOrderEntities, "dark");
423
423
  // calculate the weighted average of the ioratio values
424
424
  const ioratioSum = 0.5 * 100 + 0.25 * 200 + 0.125 * 400;
425
425
  const outputAmountSum = 100 + 200 + 400;
@@ -427,4 +427,63 @@ if (import.meta.vitest) {
427
427
  expect(result.length).toEqual(1);
428
428
  expect(result[0].value).toEqual(ioratioAverage);
429
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
+ });
430
489
  }