be-components 7.0.6 → 7.0.9

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 (180) hide show
  1. package/lib/commonjs/Components/BETimePicker.js +110 -0
  2. package/lib/commonjs/Components/BETimePicker.js.map +1 -0
  3. package/lib/commonjs/Components/Icons.js +37 -0
  4. package/lib/commonjs/Components/Icons.js.map +1 -1
  5. package/lib/commonjs/Components/ImageUploader.js +4 -0
  6. package/lib/commonjs/Components/ImageUploader.js.map +1 -1
  7. package/lib/commonjs/Components/Slider.js +2 -0
  8. package/lib/commonjs/Components/Slider.js.map +1 -1
  9. package/lib/commonjs/Components/Themed.js +4 -2
  10. package/lib/commonjs/Components/Themed.js.map +1 -1
  11. package/lib/commonjs/CreateEngagement/api/index.js +89 -1
  12. package/lib/commonjs/CreateEngagement/api/index.js.map +1 -1
  13. package/lib/commonjs/CreateEngagement/index.js +306 -5
  14. package/lib/commonjs/CreateEngagement/index.js.map +1 -1
  15. package/lib/commonjs/FlashMarket/FlashHolder.js +14 -1
  16. package/lib/commonjs/FlashMarket/FlashHolder.js.map +1 -1
  17. package/lib/commonjs/FlashMarket/api/index.js +42 -0
  18. package/lib/commonjs/FlashMarket/api/index.js.map +1 -1
  19. package/lib/commonjs/FlashMarket/components/FlashOptionCard.js +265 -0
  20. package/lib/commonjs/FlashMarket/components/FlashOptionCard.js.map +1 -0
  21. package/lib/commonjs/FlashMarket/components/ManageFlashMarket.js +1244 -0
  22. package/lib/commonjs/FlashMarket/components/ManageFlashMarket.js.map +1 -0
  23. package/lib/commonjs/FlashMarket/index.js +18 -6
  24. package/lib/commonjs/FlashMarket/index.js.map +1 -1
  25. package/lib/commonjs/Group/api/index.js +6 -3
  26. package/lib/commonjs/Group/api/index.js.map +1 -1
  27. package/lib/commonjs/Group/index.js +135 -20
  28. package/lib/commonjs/Group/index.js.map +1 -1
  29. package/lib/commonjs/Poll/api/index.js +0 -1
  30. package/lib/commonjs/Poll/api/index.js.map +1 -1
  31. package/lib/commonjs/constants/useColors.js +2 -0
  32. package/lib/commonjs/constants/useColors.js.map +1 -1
  33. package/lib/commonjs/index.js +7 -0
  34. package/lib/commonjs/index.js.map +1 -1
  35. package/lib/commonjs/types.d.js.map +1 -1
  36. package/lib/module/Components/BETimePicker.js +102 -0
  37. package/lib/module/Components/BETimePicker.js.map +1 -0
  38. package/lib/module/Components/Icons.js +37 -0
  39. package/lib/module/Components/Icons.js.map +1 -1
  40. package/lib/module/Components/ImageUploader.js +4 -0
  41. package/lib/module/Components/ImageUploader.js.map +1 -1
  42. package/lib/module/Components/Slider.js +2 -0
  43. package/lib/module/Components/Slider.js.map +1 -1
  44. package/lib/module/Components/Themed.js +4 -2
  45. package/lib/module/Components/Themed.js.map +1 -1
  46. package/lib/module/CreateEngagement/api/index.js +89 -1
  47. package/lib/module/CreateEngagement/api/index.js.map +1 -1
  48. package/lib/module/CreateEngagement/index.js +306 -5
  49. package/lib/module/CreateEngagement/index.js.map +1 -1
  50. package/lib/module/FlashMarket/FlashHolder.js +14 -1
  51. package/lib/module/FlashMarket/FlashHolder.js.map +1 -1
  52. package/lib/module/FlashMarket/api/index.js +42 -0
  53. package/lib/module/FlashMarket/api/index.js.map +1 -1
  54. package/lib/module/FlashMarket/components/FlashOptionCard.js +258 -0
  55. package/lib/module/FlashMarket/components/FlashOptionCard.js.map +1 -0
  56. package/lib/module/FlashMarket/components/ManageFlashMarket.js +1236 -0
  57. package/lib/module/FlashMarket/components/ManageFlashMarket.js.map +1 -0
  58. package/lib/module/FlashMarket/index.js +18 -6
  59. package/lib/module/FlashMarket/index.js.map +1 -1
  60. package/lib/module/Group/api/index.js +6 -3
  61. package/lib/module/Group/api/index.js.map +1 -1
  62. package/lib/module/Group/index.js +135 -20
  63. package/lib/module/Group/index.js.map +1 -1
  64. package/lib/module/Poll/api/index.js +0 -1
  65. package/lib/module/Poll/api/index.js.map +1 -1
  66. package/lib/module/constants/useColors.js +2 -0
  67. package/lib/module/constants/useColors.js.map +1 -1
  68. package/lib/module/index.js +2 -1
  69. package/lib/module/index.js.map +1 -1
  70. package/lib/module/types.d.js.map +1 -1
  71. package/lib/typescript/lib/commonjs/Components/BETimePicker.d.ts +8 -0
  72. package/lib/typescript/lib/commonjs/Components/BETimePicker.d.ts.map +1 -0
  73. package/lib/typescript/lib/commonjs/Components/Icons.d.ts +5 -0
  74. package/lib/typescript/lib/commonjs/Components/Icons.d.ts.map +1 -1
  75. package/lib/typescript/lib/commonjs/Components/ImageUploader.d.ts +2 -1
  76. package/lib/typescript/lib/commonjs/Components/ImageUploader.d.ts.map +1 -1
  77. package/lib/typescript/lib/commonjs/Components/Slider.d.ts +2 -1
  78. package/lib/typescript/lib/commonjs/Components/Slider.d.ts.map +1 -1
  79. package/lib/typescript/lib/commonjs/Components/Themed.d.ts.map +1 -1
  80. package/lib/typescript/lib/commonjs/CreateEngagement/api/index.d.ts +40 -1
  81. package/lib/typescript/lib/commonjs/CreateEngagement/api/index.d.ts.map +1 -1
  82. package/lib/typescript/lib/commonjs/CreateEngagement/index.d.ts.map +1 -1
  83. package/lib/typescript/lib/commonjs/FlashMarket/FlashHolder.d.ts +3 -1
  84. package/lib/typescript/lib/commonjs/FlashMarket/FlashHolder.d.ts.map +1 -1
  85. package/lib/typescript/lib/commonjs/FlashMarket/api/index.d.ts +2 -0
  86. package/lib/typescript/lib/commonjs/FlashMarket/api/index.d.ts.map +1 -1
  87. package/lib/typescript/lib/commonjs/FlashMarket/components/FlashOptionCard.d.ts +13 -0
  88. package/lib/typescript/lib/commonjs/FlashMarket/components/FlashOptionCard.d.ts.map +1 -0
  89. package/lib/typescript/lib/commonjs/FlashMarket/components/ManageFlashMarket.d.ts +11 -0
  90. package/lib/typescript/lib/commonjs/FlashMarket/components/ManageFlashMarket.d.ts.map +1 -0
  91. package/lib/typescript/lib/commonjs/FlashMarket/index.d.ts +2 -1
  92. package/lib/typescript/lib/commonjs/FlashMarket/index.d.ts.map +1 -1
  93. package/lib/typescript/lib/commonjs/Group/api/index.d.ts.map +1 -1
  94. package/lib/typescript/lib/commonjs/Group/index.d.ts +2 -1
  95. package/lib/typescript/lib/commonjs/Group/index.d.ts.map +1 -1
  96. package/lib/typescript/lib/commonjs/Poll/api/index.d.ts.map +1 -1
  97. package/lib/typescript/lib/commonjs/constants/useColors.d.ts +1 -0
  98. package/lib/typescript/lib/commonjs/constants/useColors.d.ts.map +1 -1
  99. package/lib/typescript/lib/commonjs/index.d.ts +1 -0
  100. package/lib/typescript/lib/commonjs/index.d.ts.map +1 -1
  101. package/lib/typescript/lib/module/Components/BETimePicker.d.ts +8 -0
  102. package/lib/typescript/lib/module/Components/BETimePicker.d.ts.map +1 -0
  103. package/lib/typescript/lib/module/Components/Icons.d.ts +5 -0
  104. package/lib/typescript/lib/module/Components/Icons.d.ts.map +1 -1
  105. package/lib/typescript/lib/module/Components/ImageUploader.d.ts +2 -1
  106. package/lib/typescript/lib/module/Components/ImageUploader.d.ts.map +1 -1
  107. package/lib/typescript/lib/module/Components/Slider.d.ts +2 -1
  108. package/lib/typescript/lib/module/Components/Slider.d.ts.map +1 -1
  109. package/lib/typescript/lib/module/Components/Themed.d.ts.map +1 -1
  110. package/lib/typescript/lib/module/CreateEngagement/api/index.d.ts +41 -1
  111. package/lib/typescript/lib/module/CreateEngagement/api/index.d.ts.map +1 -1
  112. package/lib/typescript/lib/module/CreateEngagement/index.d.ts.map +1 -1
  113. package/lib/typescript/lib/module/FlashMarket/FlashHolder.d.ts +3 -1
  114. package/lib/typescript/lib/module/FlashMarket/FlashHolder.d.ts.map +1 -1
  115. package/lib/typescript/lib/module/FlashMarket/api/index.d.ts +2 -0
  116. package/lib/typescript/lib/module/FlashMarket/api/index.d.ts.map +1 -1
  117. package/lib/typescript/lib/module/FlashMarket/components/FlashOptionCard.d.ts +13 -0
  118. package/lib/typescript/lib/module/FlashMarket/components/FlashOptionCard.d.ts.map +1 -0
  119. package/lib/typescript/lib/module/FlashMarket/components/ManageFlashMarket.d.ts +11 -0
  120. package/lib/typescript/lib/module/FlashMarket/components/ManageFlashMarket.d.ts.map +1 -0
  121. package/lib/typescript/lib/module/FlashMarket/index.d.ts +2 -1
  122. package/lib/typescript/lib/module/FlashMarket/index.d.ts.map +1 -1
  123. package/lib/typescript/lib/module/Group/api/index.d.ts.map +1 -1
  124. package/lib/typescript/lib/module/Group/index.d.ts +2 -1
  125. package/lib/typescript/lib/module/Group/index.d.ts.map +1 -1
  126. package/lib/typescript/lib/module/Poll/api/index.d.ts.map +1 -1
  127. package/lib/typescript/lib/module/constants/useColors.d.ts +1 -0
  128. package/lib/typescript/lib/module/constants/useColors.d.ts.map +1 -1
  129. package/lib/typescript/lib/module/index.d.ts +2 -1
  130. package/lib/typescript/lib/module/index.d.ts.map +1 -1
  131. package/lib/typescript/src/Components/BETimePicker.d.ts +11 -0
  132. package/lib/typescript/src/Components/BETimePicker.d.ts.map +1 -0
  133. package/lib/typescript/src/Components/Icons.d.ts +1 -0
  134. package/lib/typescript/src/Components/Icons.d.ts.map +1 -1
  135. package/lib/typescript/src/Components/ImageUploader.d.ts +2 -1
  136. package/lib/typescript/src/Components/ImageUploader.d.ts.map +1 -1
  137. package/lib/typescript/src/Components/Slider.d.ts +2 -1
  138. package/lib/typescript/src/Components/Slider.d.ts.map +1 -1
  139. package/lib/typescript/src/Components/Themed.d.ts.map +1 -1
  140. package/lib/typescript/src/CreateEngagement/api/index.d.ts +8 -2
  141. package/lib/typescript/src/CreateEngagement/api/index.d.ts.map +1 -1
  142. package/lib/typescript/src/CreateEngagement/index.d.ts.map +1 -1
  143. package/lib/typescript/src/FlashMarket/FlashHolder.d.ts +4 -2
  144. package/lib/typescript/src/FlashMarket/FlashHolder.d.ts.map +1 -1
  145. package/lib/typescript/src/FlashMarket/api/index.d.ts +2 -0
  146. package/lib/typescript/src/FlashMarket/api/index.d.ts.map +1 -1
  147. package/lib/typescript/src/FlashMarket/components/FlashOptionCard.d.ts +15 -0
  148. package/lib/typescript/src/FlashMarket/components/FlashOptionCard.d.ts.map +1 -0
  149. package/lib/typescript/src/FlashMarket/components/ManageFlashMarket.d.ts +15 -0
  150. package/lib/typescript/src/FlashMarket/components/ManageFlashMarket.d.ts.map +1 -0
  151. package/lib/typescript/src/FlashMarket/index.d.ts +2 -1
  152. package/lib/typescript/src/FlashMarket/index.d.ts.map +1 -1
  153. package/lib/typescript/src/Group/api/index.d.ts +5 -2
  154. package/lib/typescript/src/Group/api/index.d.ts.map +1 -1
  155. package/lib/typescript/src/Group/index.d.ts +3 -2
  156. package/lib/typescript/src/Group/index.d.ts.map +1 -1
  157. package/lib/typescript/src/Poll/api/index.d.ts.map +1 -1
  158. package/lib/typescript/src/constants/useColors.d.ts +1 -0
  159. package/lib/typescript/src/constants/useColors.d.ts.map +1 -1
  160. package/lib/typescript/src/index.d.ts +2 -1
  161. package/lib/typescript/src/index.d.ts.map +1 -1
  162. package/package.json +4 -2
  163. package/src/Components/BETimePicker.tsx +77 -0
  164. package/src/Components/Icons.tsx +17 -0
  165. package/src/Components/ImageUploader.tsx +3 -1
  166. package/src/Components/Slider.tsx +3 -1
  167. package/src/Components/Themed.tsx +6 -4
  168. package/src/CreateEngagement/api/index.ts +78 -2
  169. package/src/CreateEngagement/index.tsx +181 -7
  170. package/src/FlashMarket/FlashHolder.tsx +11 -2
  171. package/src/FlashMarket/api/index.ts +24 -1
  172. package/src/FlashMarket/components/FlashOptionCard.tsx +174 -0
  173. package/src/FlashMarket/components/ManageFlashMarket.tsx +769 -0
  174. package/src/FlashMarket/index.tsx +14 -8
  175. package/src/Group/api/index.ts +5 -5
  176. package/src/Group/index.tsx +84 -9
  177. package/src/Poll/api/index.ts +0 -2
  178. package/src/constants/useColors.tsx +2 -0
  179. package/src/index.tsx +2 -0
  180. package/src/types.d.ts +8 -1
@@ -0,0 +1,1236 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Button, Text, TextInput, View } from "../../Components/Themed";
3
+ import { FlatList, Image } from 'react-native';
4
+ import { Icons, Switch, Toggle } from '../../Components';
5
+ import { PollApi, PollCampaignApi, PollOptionApi } from '../../Poll/api';
6
+ import ImageUploader from '../../Components/ImageUploader';
7
+ import { useColors } from '../../constants/useColors';
8
+ import FlashOptionCard from './FlashOptionCard';
9
+ import moment from 'moment-mini';
10
+ import BETimePicker from '../../Components/BETimePicker';
11
+ import { FlashMarketHelpers } from '../api';
12
+ import { showConfirmAlert } from '../../Components/ConfirmAlert';
13
+ const sections = ['header', 'activate', 'pause_resume', 'closed', 'resolve', 'toggle', 'image', 'question', 'options', 'settings', 'results'];
14
+ const ManageFlashMarket = ({
15
+ float,
16
+ header_style,
17
+ player,
18
+ onClose,
19
+ poll_id,
20
+ onFocusPosition
21
+ }) => {
22
+ const Colors = useColors();
23
+ const [labels, setLabels] = useState({
24
+ base_stake: '0',
25
+ min_stake: '0',
26
+ max_stake: '0'
27
+ });
28
+ const {
29
+ min_stake,
30
+ max_stake,
31
+ base_stake
32
+ } = labels;
33
+ const [expand_participants, setExpandParticipants] = useState(false);
34
+ const [flash_state, setFlashState] = useState({
35
+ loading: false,
36
+ action_loading: false,
37
+ probability_changed: false,
38
+ active_step: 'settings',
39
+ players: [],
40
+ poll_summaries: [],
41
+ poll_options: []
42
+ });
43
+ const {
44
+ loading,
45
+ action_loading,
46
+ poll_options,
47
+ players,
48
+ active_step,
49
+ poll,
50
+ draft_poll,
51
+ poll_summaries,
52
+ probability_changed
53
+ } = flash_state;
54
+ const real_options = poll_options.filter(o => o.status != 'inactive');
55
+ const total_responses = poll_summaries.reduce((a, b) => a + b.count, 0);
56
+ const unlocked_options = real_options.filter(o => !o.probability_locked);
57
+ const prob_locked = unlocked_options.length <= 1 ? true : false;
58
+ const errors = FlashMarketHelpers.isNewValid(real_options, poll_summaries, poll);
59
+ const winning_option = real_options.find(o => o.poll_option_id == poll?.winning_option_id);
60
+ useEffect(() => {
61
+ PollCampaignApi.setEnvironment();
62
+ if (!poll_id) {
63
+ return;
64
+ }
65
+ getData(poll_id);
66
+ }, [poll_id]);
67
+ const getData = async id => {
68
+ setFlashState({
69
+ ...flash_state,
70
+ loading: true
71
+ });
72
+ const server_response = await PollApi.getPollById(id);
73
+ const server_campaign = await PollCampaignApi.getPollCampaignById(server_response.poll.poll_campaign_id);
74
+ let player_ids = [];
75
+ server_response.poll_summaries.map(s => {
76
+ s.player_ids.map(id => id != '4985' ? player_ids.push(id) : console.log(''));
77
+ });
78
+ const server_players = await PollCampaignApi.getPlayersByPlayerIds([...new Set(player_ids.map(id => id))]);
79
+ setFlashState({
80
+ ...flash_state,
81
+ poll: server_response.poll,
82
+ poll_options: server_response.poll_options,
83
+ draft_poll: server_response.poll,
84
+ poll_summaries: server_response.poll_summaries,
85
+ poll_campaign: server_campaign,
86
+ players: server_players,
87
+ loading: false
88
+ });
89
+ setLabels({
90
+ min_stake: server_response.poll.minimum_stake.toString(),
91
+ max_stake: server_response.poll.max_stake.toString(),
92
+ base_stake: server_response.poll.base_stake?.toString() ?? '0'
93
+ });
94
+ };
95
+ const updatePoll = async dp => {
96
+ if (action_loading) {
97
+ return;
98
+ }
99
+ setFlashState({
100
+ ...flash_state,
101
+ action_loading: true
102
+ });
103
+ const new_resp = await PollApi.updatePoll(dp);
104
+ if (!new_resp) {
105
+ return alert('Unable to update');
106
+ }
107
+ setFlashState({
108
+ ...flash_state,
109
+ action_loading: false,
110
+ poll: new_resp.poll,
111
+ draft_poll: new_resp.poll,
112
+ poll_options: new_resp.poll_options
113
+ });
114
+ };
115
+ const handleSelectWinningOption = (checked, option) => {
116
+ if (!poll) {
117
+ return alert('Unable to process');
118
+ }
119
+ if (checked) {
120
+ showConfirmAlert('Are you sure', `Confirm ${option.option_name} is the correct answer`, () => updatePoll({
121
+ ...poll,
122
+ winning_option_id: option.poll_option_id,
123
+ status: 'paused'
124
+ }), () => console.log(''));
125
+ } else {
126
+ if (!poll.winning_option_id) {
127
+ return;
128
+ }
129
+ showConfirmAlert('Are you sure', `Remove ${option.option_name} as the correct answer`, () => updatePoll({
130
+ ...poll,
131
+ winning_option_id: undefined
132
+ }), () => console.log(''));
133
+ }
134
+ };
135
+ const handleChangeProbability = (option, probability) => {
136
+ if (option.probability_locked) {
137
+ return;
138
+ }
139
+ if (probability < 0) {
140
+ return;
141
+ }
142
+ if (probability > 1) {
143
+ return;
144
+ }
145
+ let other_options = [...real_options.filter(o => o.poll_option_id != option.poll_option_id)];
146
+ //Find the min probability
147
+
148
+ //Other option probabilities
149
+ let other_option_probabilities = other_options.reduce((a, b) => a + (b.initial_odds ?? 0), 0);
150
+ //With new probabilities
151
+ let all_probs = other_option_probabilities + probability;
152
+ let difference = 1 - all_probs;
153
+ let unlocked_options = other_options.filter(po => !po.probability_locked);
154
+ if (unlocked_options.length == 0) {
155
+ return;
156
+ } //There are no options!
157
+
158
+ let new_option = {
159
+ ...option,
160
+ initial_odds: probability
161
+ };
162
+ //what is the current total probability
163
+ let delta = difference / unlocked_options.length;
164
+ //Map through the others and update those
165
+
166
+ let min_option = unlocked_options.reduce((min, item) => {
167
+ let item_init = item.initial_odds ?? 0;
168
+ let min_init = min.initial_odds ?? 0;
169
+ if (item_init < min_init) {
170
+ return item;
171
+ } else {
172
+ return min;
173
+ }
174
+ });
175
+ let max_option = unlocked_options.reduce((min, item) => {
176
+ let item_init = item.initial_odds ?? 0;
177
+ let min_init = min.initial_odds ?? 0;
178
+ if (item_init > min_init) {
179
+ return item;
180
+ } else {
181
+ return min;
182
+ }
183
+ });
184
+ let new_delta = delta;
185
+ if (delta < 0) {
186
+ //Make sure our min has enough room
187
+ let min_diff = (min_option.initial_odds ?? 0) + delta;
188
+ if (min_diff < 0) {
189
+ new_delta = min_option.initial_odds ?? 0;
190
+ }
191
+ } else {
192
+ let max_diff = (max_option.initial_odds ?? 0) + delta;
193
+ if (max_diff > 1) {
194
+ new_delta = 1 - (max_option.initial_odds ?? 0);
195
+ }
196
+ }
197
+ let delta_difference = new_delta - delta;
198
+ if (delta_difference != 0) {
199
+ return;
200
+ }
201
+ let failed = false;
202
+ other_options = other_options.map(o => {
203
+ if (o.probability_locked) {
204
+ return o;
205
+ }
206
+ let starting_odds = o.initial_odds ?? 0;
207
+ let new_odds = starting_odds + delta;
208
+ if (new_odds < 0) {
209
+ failed = true;
210
+ }
211
+ if (new_odds > 1) {
212
+ failed = true;
213
+ }
214
+ o.initial_odds = new_odds;
215
+ return o;
216
+ });
217
+ if (failed) {
218
+ return;
219
+ }
220
+ let final_options = other_options.concat(new_option);
221
+ //let check it
222
+ let total_prob = final_options.reduce((a, b) => a + (b.initial_odds ?? 0), 0);
223
+ if (total_prob.toFixed(2) != '1.00') {
224
+ return;
225
+ }
226
+ setFlashState({
227
+ ...flash_state,
228
+ probability_changed: true,
229
+ poll_options: poll_options.filter(po => !final_options.find(fo => fo.poll_option_id == po.poll_option_id)).concat(final_options)
230
+ });
231
+ };
232
+ const renderOptions = data => {
233
+ if (!poll) {
234
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
235
+ }
236
+ const summary = poll_summaries.find(ps => ps.poll_option_id == data.item.poll_option_id);
237
+ if (!summary) {
238
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
239
+ }
240
+ return /*#__PURE__*/React.createElement(View, {
241
+ style: {
242
+ padding: 5
243
+ }
244
+ }, /*#__PURE__*/React.createElement(FlashOptionCard, {
245
+ poll_option: data.item,
246
+ summary: summary,
247
+ poll: poll,
248
+ onSelectWinningOption: handleSelectWinningOption,
249
+ probability_locked: prob_locked,
250
+ onChangeProbability: probability => handleChangeProbability(data.item, probability),
251
+ onLockProbability: locked => {
252
+ setFlashState({
253
+ ...flash_state,
254
+ poll_options: poll_options.filter(po => po.poll_option_id != data.item.poll_option_id).concat({
255
+ ...data.item,
256
+ probability_locked: locked
257
+ })
258
+ });
259
+ },
260
+ onUpdateOption: option => {
261
+ setFlashState({
262
+ ...flash_state,
263
+ poll_options: poll_options.filter(po => po.poll_option_id != option.poll_option_id).concat(option)
264
+ });
265
+ }
266
+ }));
267
+ };
268
+ const handleSaveProbabilities = async () => {
269
+ if (!probability_changed) {
270
+ return;
271
+ }
272
+ if (poll?.status != 'pending') {
273
+ return;
274
+ }
275
+ let total_prob = real_options.reduce((a, b) => a + (b.initial_odds ?? 0), 0);
276
+ if (total_prob.toFixed(2) != '1.00') {
277
+ return;
278
+ }
279
+ setFlashState({
280
+ ...flash_state,
281
+ action_loading: true
282
+ });
283
+ let new_options = [];
284
+ const saveOptions = real_options.map(async o => {
285
+ new_options.push(await PollOptionApi.updatePollOption(o));
286
+ });
287
+ await Promise.all(saveOptions);
288
+ setFlashState({
289
+ ...flash_state,
290
+ poll_options: new_options,
291
+ probability_changed: false
292
+ });
293
+ };
294
+ const handleResolve = () => {
295
+ if (!poll) {
296
+ return;
297
+ }
298
+ if (!winning_option) {
299
+ return;
300
+ }
301
+ showConfirmAlert('Are you sure', `Confirm ${winning_option.option_name} is the correct answer and payout participants`, () => resolveFlashMarket(), () => console.log(''));
302
+ };
303
+ const resolveFlashMarket = async () => {
304
+ if (!poll) {
305
+ return;
306
+ }
307
+ if (!poll.winning_option_id) {
308
+ return;
309
+ }
310
+ setFlashState({
311
+ ...flash_state,
312
+ action_loading: true
313
+ });
314
+ const resolved_poll = await PollApi.closePoll(poll.poll_id);
315
+ if (!resolved_poll) {
316
+ return alert('Unable to activate market at this time');
317
+ }
318
+ setFlashState({
319
+ ...flash_state,
320
+ action_loading: false,
321
+ poll: resolved_poll
322
+ });
323
+ };
324
+ const handleAddOption = async () => {
325
+ if (poll?.status != 'pending') {
326
+ return;
327
+ }
328
+ if (action_loading) {
329
+ return;
330
+ }
331
+ setFlashState({
332
+ ...flash_state,
333
+ action_loading: true
334
+ });
335
+ let length = real_options.length;
336
+ const new_option = await PollOptionApi.createPollOption({
337
+ poll_id: poll.poll_id,
338
+ poll_option_id: '',
339
+ option_name: '',
340
+ initial_odds: length == 0 ? 1 : 0,
341
+ option_value: 'optional',
342
+ response_message: '',
343
+ priority: length + 1,
344
+ create_datetime: '',
345
+ last_update_datetime: '',
346
+ option_type: 'select',
347
+ status: 'pending'
348
+ });
349
+ if (!new_option) {
350
+ setFlashState({
351
+ ...flash_state,
352
+ action_loading: false
353
+ });
354
+ return alert('Unable to process');
355
+ }
356
+ let new_summary = {
357
+ poll_id: poll_id,
358
+ poll_option_id: new_option.poll_option_id,
359
+ count: 0,
360
+ stake: 0,
361
+ winnings: 0,
362
+ player_ids: [],
363
+ pct: 0
364
+ };
365
+ //We have a new option! Now we will need to update the probabilities
366
+ setFlashState({
367
+ ...flash_state,
368
+ action_loading: false,
369
+ poll_options: poll_options.filter(po => po.poll_option_id != new_option.poll_option_id).concat(new_option),
370
+ poll_summaries: poll_summaries.filter(ps => ps.poll_option_id != new_summary.poll_option_id).concat(new_summary)
371
+ });
372
+ };
373
+ const renderPlayers = data => {
374
+ return /*#__PURE__*/React.createElement(View, {
375
+ type: "row",
376
+ style: {
377
+ borderBottomWidth: 1,
378
+ borderColor: Colors.borders.light,
379
+ padding: 10
380
+ }
381
+ }, /*#__PURE__*/React.createElement(Image, {
382
+ source: {
383
+ uri: data.item.profile_pic
384
+ },
385
+ style: {
386
+ height: 30,
387
+ width: 30,
388
+ borderRadius: 100
389
+ }
390
+ }), /*#__PURE__*/React.createElement(View, {
391
+ transparent: true,
392
+ style: {
393
+ flex: 1,
394
+ marginLeft: 10
395
+ }
396
+ }, /*#__PURE__*/React.createElement(Text, {
397
+ theme: "h1"
398
+ }, "@", data.item.username), /*#__PURE__*/React.createElement(Text, {
399
+ theme: "description",
400
+ style: {
401
+ marginTop: 3
402
+ }
403
+ }, "Joined ", moment(data.item.create_datetime).fromNow())));
404
+ };
405
+ const renderSections = data => {
406
+ switch (data.item) {
407
+ case 'header':
408
+ return /*#__PURE__*/React.createElement(View, {
409
+ type: "header",
410
+ style: {
411
+ flexDirection: 'row',
412
+ alignItems: 'center',
413
+ padding: 10,
414
+ ...header_style
415
+ }
416
+ }, /*#__PURE__*/React.createElement(View, {
417
+ transparent: true,
418
+ style: {
419
+ flex: 1
420
+ }
421
+ }, /*#__PURE__*/React.createElement(Text, {
422
+ theme: "h1"
423
+ }, "Flash Market"), /*#__PURE__*/React.createElement(Text, {
424
+ theme: "description",
425
+ style: {
426
+ marginTop: 3
427
+ }
428
+ }, "Use the form below to manage your custom flash market!")), /*#__PURE__*/React.createElement(Button, {
429
+ float: true,
430
+ title: "X",
431
+ title_color: Colors.text.error,
432
+ onPress: () => onClose()
433
+ }));
434
+ case 'activate':
435
+ if (poll?.status != 'pending') {
436
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
437
+ }
438
+ const ready = errors.length == 0 ? true : false;
439
+ return /*#__PURE__*/React.createElement(View, {
440
+ transparent: true,
441
+ style: {
442
+ flexDirection: 'row',
443
+ alignItems: 'center',
444
+ padding: 10
445
+ }
446
+ }, /*#__PURE__*/React.createElement(View, {
447
+ transparent: true,
448
+ style: {
449
+ flex: 1
450
+ }
451
+ }, /*#__PURE__*/React.createElement(Text, {
452
+ theme: "h1"
453
+ }, "Flash Market is Pending"), /*#__PURE__*/React.createElement(Text, {
454
+ theme: "description"
455
+ }, "Complete set up and select activate when you are ready")), /*#__PURE__*/React.createElement(Button, {
456
+ type: "success",
457
+ title: "Activate",
458
+ loading: action_loading,
459
+ disabled: errors.length > 0 ? true : probability_changed ? true : false,
460
+ style: {
461
+ opacity: ready && !action_loading && !probability_changed ? 1 : 0.5
462
+ },
463
+ onPress: async () => {
464
+ if (errors.length > 0) {
465
+ return alert(errors.map(e => e));
466
+ }
467
+ if (probability_changed) {
468
+ return;
469
+ }
470
+ setFlashState({
471
+ ...flash_state,
472
+ action_loading: true
473
+ });
474
+ const resp = await PollApi.activatePoll(poll.poll_id);
475
+ if (!resp) {
476
+ return alert('Unable to activate market at this time');
477
+ }
478
+ setFlashState({
479
+ ...flash_state,
480
+ action_loading: false,
481
+ poll: resp.poll,
482
+ poll_options: resp.poll_options
483
+ });
484
+ }
485
+ }));
486
+ case 'closed':
487
+ if (!poll) {
488
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
489
+ }
490
+ if (poll.status != 'closed') {
491
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
492
+ }
493
+ return /*#__PURE__*/React.createElement(View, {
494
+ transparent: true,
495
+ style: {
496
+ flexDirection: 'row',
497
+ alignItems: 'center',
498
+ padding: 10,
499
+ backgroundColor: Colors.views.liquidMarket
500
+ }
501
+ }, /*#__PURE__*/React.createElement(View, {
502
+ transparent: true,
503
+ style: {
504
+ flex: 1
505
+ }
506
+ }, /*#__PURE__*/React.createElement(Text, {
507
+ theme: "h1"
508
+ }, "Flash Market is Closed"), /*#__PURE__*/React.createElement(Text, {
509
+ theme: "description"
510
+ }, "This flash market has been completed and all participants have been paid out")));
511
+ case 'pause_resume':
512
+ if (!poll) {
513
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
514
+ }
515
+ if (!['active', 'paused', ''].includes(poll.status)) {
516
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
517
+ }
518
+ if (poll.winning_option_id) {
519
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
520
+ }
521
+ return /*#__PURE__*/React.createElement(View, {
522
+ transparent: true,
523
+ style: {
524
+ flexDirection: 'row',
525
+ alignItems: 'center',
526
+ padding: 10
527
+ }
528
+ }, /*#__PURE__*/React.createElement(View, {
529
+ transparent: true,
530
+ style: {
531
+ flex: 1
532
+ }
533
+ }, /*#__PURE__*/React.createElement(Text, {
534
+ theme: "h1"
535
+ }, "Flash Market is ", poll.status), /*#__PURE__*/React.createElement(Text, {
536
+ theme: "description"
537
+ }, "Complete set up and select activate when you are ready")), poll.status == 'paused' ? /*#__PURE__*/React.createElement(Button, {
538
+ type: "success",
539
+ title: "Resume",
540
+ loading: action_loading,
541
+ disabled: action_loading ? true : false,
542
+ style: {
543
+ opacity: action_loading ? 0.5 : 1
544
+ },
545
+ onPress: async () => {
546
+ updatePoll({
547
+ ...poll,
548
+ status: 'active'
549
+ });
550
+ }
551
+ }) : /*#__PURE__*/React.createElement(Button, {
552
+ type: "warning",
553
+ title: "Pause",
554
+ loading: action_loading,
555
+ disabled: action_loading ? true : false,
556
+ style: {
557
+ opacity: action_loading ? 0.5 : 1
558
+ },
559
+ onPress: async () => {
560
+ updatePoll({
561
+ ...poll,
562
+ status: 'paused'
563
+ });
564
+ }
565
+ }));
566
+ case 'resolve':
567
+ if (!poll) {
568
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
569
+ }
570
+ if (!poll.winning_option_id) {
571
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
572
+ }
573
+ if (!winning_option) {
574
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
575
+ }
576
+ if (poll.status == 'closed') {
577
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
578
+ }
579
+ return /*#__PURE__*/React.createElement(View, {
580
+ transparent: true,
581
+ style: {
582
+ flexDirection: 'row',
583
+ alignItems: 'center',
584
+ padding: 10
585
+ }
586
+ }, /*#__PURE__*/React.createElement(View, {
587
+ transparent: true,
588
+ style: {
589
+ flex: 1
590
+ }
591
+ }, /*#__PURE__*/React.createElement(Text, {
592
+ theme: "h1"
593
+ }, "Resolve Flash Market"), /*#__PURE__*/React.createElement(Text, {
594
+ theme: "description"
595
+ }, "Resolve with option: ", winning_option.option_name, " as the winner")), /*#__PURE__*/React.createElement(Button, {
596
+ type: "success",
597
+ title: "Resolve",
598
+ loading: action_loading,
599
+ disabled: action_loading,
600
+ style: {
601
+ opacity: action_loading ? 0.5 : 1
602
+ },
603
+ onPress: async () => handleResolve()
604
+ }));
605
+ case 'toggle':
606
+ return /*#__PURE__*/React.createElement(View, {
607
+ style: {
608
+ padding: 10
609
+ }
610
+ }, /*#__PURE__*/React.createElement(Toggle, {
611
+ options: [{
612
+ key: 'question',
613
+ label: 'Question'
614
+ }, {
615
+ key: 'options',
616
+ label: 'Options'
617
+ }, {
618
+ key: 'settings',
619
+ label: 'Settings'
620
+ }, {
621
+ key: 'results',
622
+ label: 'Results'
623
+ }],
624
+ selected_option: active_step,
625
+ onSelectOption: key => setFlashState({
626
+ ...flash_state,
627
+ active_step: key
628
+ })
629
+ }));
630
+ case 'image':
631
+ if (active_step != 'question') {
632
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
633
+ }
634
+ if (!draft_poll || !poll) {
635
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
636
+ }
637
+ return /*#__PURE__*/React.createElement(View, {
638
+ style: {
639
+ flexDirection: 'row',
640
+ alignItems: 'center',
641
+ padding: 10,
642
+ borderBottomWidth: 1,
643
+ borderColor: Colors.borders.light
644
+ }
645
+ }, /*#__PURE__*/React.createElement(View, {
646
+ transparent: true,
647
+ style: {
648
+ flex: 1,
649
+ marginRight: 10
650
+ }
651
+ }, /*#__PURE__*/React.createElement(Text, {
652
+ theme: "h1"
653
+ }, "Flash Market Image"), /*#__PURE__*/React.createElement(Text, {
654
+ theme: "description",
655
+ style: {
656
+ marginTop: 3
657
+ }
658
+ }, "Give the question an image that aligns with the question")), /*#__PURE__*/React.createElement(ImageUploader, {
659
+ disabled: poll.status == 'closed' ? true : false,
660
+ public_id: `poll_${poll_id}_${Math.random().toFixed(9)}`,
661
+ onFinishUpload: obj => {
662
+ updatePoll({
663
+ ...draft_poll,
664
+ poll_image: {
665
+ ...obj,
666
+ url: obj.secure_url
667
+ }
668
+ });
669
+ }
670
+ }, poll.poll_image ? /*#__PURE__*/React.createElement(Image, {
671
+ source: {
672
+ uri: poll.poll_image.url
673
+ },
674
+ style: {
675
+ height: 45,
676
+ width: 45
677
+ },
678
+ resizeMode: "contain"
679
+ }) : /*#__PURE__*/React.createElement(Icons.ImageIcon, {
680
+ size: 45,
681
+ color: Colors.text.h1
682
+ }), /*#__PURE__*/React.createElement(Text, {
683
+ style: {
684
+ marginTop: 5
685
+ },
686
+ textAlign: "center",
687
+ theme: "action"
688
+ }, draft_poll.poll_image ? 'CHANGE' : 'UPLOAD')));
689
+ case 'question':
690
+ if (active_step != 'question') {
691
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
692
+ }
693
+ if (!draft_poll || !poll) {
694
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
695
+ }
696
+ const is_q_changed = JSON.stringify(poll.poll_question) != JSON.stringify(draft_poll.poll_question) ? true : false;
697
+ const edit_allowed = poll_summaries.length == 0 && ['pending', 'paused'].includes(poll.status) ? true : false;
698
+ return /*#__PURE__*/React.createElement(View, {
699
+ transparent: true
700
+ }, /*#__PURE__*/React.createElement(View, {
701
+ style: {
702
+ flexDirection: 'row',
703
+ alignItems: 'center',
704
+ padding: 10
705
+ }
706
+ }, /*#__PURE__*/React.createElement(View, {
707
+ transparent: true,
708
+ style: {
709
+ flex: 1
710
+ }
711
+ }, /*#__PURE__*/React.createElement(Text, {
712
+ theme: "h1"
713
+ }, "Flash Market Question"), /*#__PURE__*/React.createElement(Text, {
714
+ theme: "description",
715
+ style: {
716
+ marginTop: 3
717
+ }
718
+ }, "Edit your question below. Questions can be edited until a response is recorded."))), /*#__PURE__*/React.createElement(View, {
719
+ transparent: true,
720
+ style: {
721
+ padding: 20
722
+ }
723
+ }, /*#__PURE__*/React.createElement(TextInput, {
724
+ style: {
725
+ height: 150,
726
+ textAlign: 'center'
727
+ },
728
+ multiline: true,
729
+ editable: edit_allowed,
730
+ placeholder: "Enter Question Here",
731
+ value: draft_poll.poll_question,
732
+ onChangeText: text => setFlashState({
733
+ ...flash_state,
734
+ draft_poll: {
735
+ ...draft_poll,
736
+ poll_question: text
737
+ }
738
+ })
739
+ })), /*#__PURE__*/React.createElement(Button, {
740
+ title: "SAVE QUESTION",
741
+ type: "success",
742
+ disabled: !edit_allowed || !is_q_changed ? true : false,
743
+ style: {
744
+ margin: 10,
745
+ opacity: !edit_allowed || !is_q_changed ? 0.5 : 1
746
+ },
747
+ loading: action_loading,
748
+ onPress: () => updatePoll(draft_poll)
749
+ }));
750
+ case 'results':
751
+ if (!poll) {
752
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
753
+ }
754
+ if (active_step != 'results') {
755
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
756
+ }
757
+ let staked = poll_summaries.reduce((a, b) => a + b.stake, 0) - (poll.base_stake ?? 0);
758
+ let responses = poll_summaries.reduce((a, b) => a + b.count, 0) - poll_summaries.length;
759
+ if (responses < 0) {
760
+ responses = 0;
761
+ }
762
+ let participants = players.length;
763
+ let total_stake = poll_summaries.reduce((a, b) => a + b.stake, 0);
764
+ let winnings = poll_summaries.reduce((a, b) => a + b.winnings, 0);
765
+ let revenue = total_stake - winnings;
766
+ return /*#__PURE__*/React.createElement(View, {
767
+ transparent: true
768
+ }, /*#__PURE__*/React.createElement(View, {
769
+ transparent: true,
770
+ type: "row",
771
+ style: {
772
+ padding: 20,
773
+ borderBottomWidth: 1,
774
+ borderColor: Colors.borders.light
775
+ }
776
+ }, /*#__PURE__*/React.createElement(View, {
777
+ transparent: true,
778
+ style: {
779
+ flex: 1,
780
+ marginRight: 10
781
+ }
782
+ }, /*#__PURE__*/React.createElement(Text, {
783
+ theme: "h1"
784
+ }, "Total Revenue"), /*#__PURE__*/React.createElement(Text, {
785
+ theme: "description",
786
+ style: {
787
+ marginTop: 3
788
+ }
789
+ }, "Total amount of revenue earned on this flash market")), /*#__PURE__*/React.createElement(Text, {
790
+ theme: "h1"
791
+ }, "$", revenue.toFixed(2))), /*#__PURE__*/React.createElement(View, {
792
+ transparent: true,
793
+ type: "row",
794
+ style: {
795
+ padding: 20,
796
+ borderBottomWidth: 1,
797
+ borderColor: Colors.borders.light
798
+ }
799
+ }, /*#__PURE__*/React.createElement(View, {
800
+ transparent: true,
801
+ style: {
802
+ flex: 1,
803
+ marginRight: 10
804
+ }
805
+ }, /*#__PURE__*/React.createElement(Text, {
806
+ theme: "h1"
807
+ }, "Total Volume"), /*#__PURE__*/React.createElement(Text, {
808
+ theme: "description",
809
+ style: {
810
+ marginTop: 3
811
+ }
812
+ }, "Total amount bet on this market")), /*#__PURE__*/React.createElement(Text, {
813
+ theme: "h1"
814
+ }, "$", staked.toFixed(2))), /*#__PURE__*/React.createElement(View, {
815
+ transparent: true,
816
+ type: "row",
817
+ style: {
818
+ padding: 20,
819
+ borderBottomWidth: 1,
820
+ borderColor: Colors.borders.light
821
+ }
822
+ }, /*#__PURE__*/React.createElement(View, {
823
+ transparent: true,
824
+ style: {
825
+ flex: 1,
826
+ marginRight: 10
827
+ }
828
+ }, /*#__PURE__*/React.createElement(Text, {
829
+ theme: "h1"
830
+ }, "Total Responses"), /*#__PURE__*/React.createElement(Text, {
831
+ theme: "description",
832
+ style: {
833
+ marginTop: 3
834
+ }
835
+ }, "Total number of bets on this market")), /*#__PURE__*/React.createElement(Text, {
836
+ theme: "h1"
837
+ }, responses.toFixed())), /*#__PURE__*/React.createElement(View, {
838
+ transparent: true,
839
+ type: "row",
840
+ style: {
841
+ padding: 20,
842
+ borderBottomWidth: 1,
843
+ borderColor: Colors.borders.light
844
+ }
845
+ }, /*#__PURE__*/React.createElement(View, {
846
+ transparent: true,
847
+ style: {
848
+ flex: 1,
849
+ marginRight: 10
850
+ }
851
+ }, /*#__PURE__*/React.createElement(Text, {
852
+ theme: "h1"
853
+ }, "Participants"), /*#__PURE__*/React.createElement(Text, {
854
+ theme: "description",
855
+ style: {
856
+ marginTop: 3
857
+ }
858
+ }, "Players that participated in this flash market")), /*#__PURE__*/React.createElement(Text, {
859
+ theme: "h1"
860
+ }, participants.toFixed()), /*#__PURE__*/React.createElement(Button, {
861
+ onPress: () => setExpandParticipants(!expand_participants),
862
+ float: true,
863
+ style: {
864
+ marginLeft: 10,
865
+ height: 30,
866
+ width: 30,
867
+ borderRadius: 100,
868
+ padding: 10,
869
+ justifyContent: 'center',
870
+ alignItems: 'center'
871
+ }
872
+ }, /*#__PURE__*/React.createElement(Icons.ChevronIcon, {
873
+ direction: expand_participants ? 'up' : 'down',
874
+ size: 8,
875
+ color: Colors.text.action
876
+ }))), expand_participants ? /*#__PURE__*/React.createElement(View, {
877
+ transparent: true,
878
+ style: {
879
+ margin: 10
880
+ }
881
+ }, /*#__PURE__*/React.createElement(FlatList, {
882
+ data: players,
883
+ renderItem: renderPlayers,
884
+ key: 'participant_list_poll',
885
+ keyExtractor: item => item.player_id.toString()
886
+ })) : /*#__PURE__*/React.createElement(React.Fragment, null));
887
+ case 'options':
888
+ if (!poll) {
889
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
890
+ }
891
+ if (active_step != 'options') {
892
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
893
+ }
894
+ const add_allowed = ['pending', 'paused'].includes(poll.status) && total_responses == 0 ? true : false;
895
+ return /*#__PURE__*/React.createElement(View, {
896
+ transparent: true
897
+ }, /*#__PURE__*/React.createElement(View, {
898
+ style: {
899
+ flexDirection: 'row',
900
+ alignItems: 'center',
901
+ padding: 10
902
+ }
903
+ }, /*#__PURE__*/React.createElement(View, {
904
+ transparent: true,
905
+ style: {
906
+ flex: 1
907
+ }
908
+ }, /*#__PURE__*/React.createElement(Text, {
909
+ theme: "h1"
910
+ }, "Flash Market Options"), poll.status == 'pending' ? /*#__PURE__*/React.createElement(Text, {
911
+ theme: "description",
912
+ style: {
913
+ marginTop: 3
914
+ }
915
+ }, "Enter the options below!") : /*#__PURE__*/React.createElement(Text, {
916
+ theme: "description",
917
+ style: {
918
+ marginTop: 3
919
+ }
920
+ }, "Select the winning option below")), probability_changed ? /*#__PURE__*/React.createElement(Button, {
921
+ title: "SAVE PROBABILITIES",
922
+ onPress: () => handleSaveProbabilities(),
923
+ type: "success",
924
+ disabled: action_loading,
925
+ loading: action_loading,
926
+ style: {
927
+ margin: 5,
928
+ padding: 10,
929
+ opacity: loading ? 0.5 : 1
930
+ }
931
+ }) : /*#__PURE__*/React.createElement(React.Fragment, null)), /*#__PURE__*/React.createElement(View, {
932
+ transparent: true,
933
+ style: {
934
+ padding: 10
935
+ }
936
+ }, /*#__PURE__*/React.createElement(FlatList, {
937
+ data: real_options.sort((a, b) => a.priority - b.priority || moment(a.create_datetime).unix() - moment(b.create_datetime).unix()),
938
+ key: "option_list",
939
+ keyboardShouldPersistTaps: true,
940
+ keyExtractor: item => item.poll_option_id.toString(),
941
+ renderItem: renderOptions
942
+ }), add_allowed ? /*#__PURE__*/React.createElement(Button, {
943
+ transparent: true,
944
+ title_color: Colors.text.action,
945
+ title: real_options.length > 0 ? 'Add another option' : 'Add an option',
946
+ style: {
947
+ alignItems: 'flex-start',
948
+ padding: 10
949
+ },
950
+ onPress: async () => handleAddOption()
951
+ }) : /*#__PURE__*/React.createElement(React.Fragment, null)));
952
+ case 'settings':
953
+ if (active_step != 'settings') {
954
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
955
+ }
956
+ if (!draft_poll) {
957
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
958
+ }
959
+ let settings_edit_allowed = ['paused', 'pending'].includes(draft_poll.status) && total_responses == 0 ? true : false;
960
+ const min_stake_changed = settings_edit_allowed && poll?.minimum_stake != parseFloat(min_stake) ? true : false;
961
+ const max_stake_changed = settings_edit_allowed && poll?.max_stake != parseFloat(max_stake) ? true : false;
962
+ const base_stake_changed = settings_edit_allowed && poll?.base_stake != parseFloat(base_stake) ? true : false;
963
+ return /*#__PURE__*/React.createElement(View, {
964
+ transparent: true
965
+ }, player?.role == 'admin' ? /*#__PURE__*/React.createElement(View, {
966
+ type: "row",
967
+ style: {
968
+ padding: 20,
969
+ borderBottomWidth: 1,
970
+ borderColor: Colors.borders.light
971
+ }
972
+ }, /*#__PURE__*/React.createElement(View, {
973
+ transparent: true,
974
+ style: {
975
+ flex: 1,
976
+ marginRight: 10
977
+ }
978
+ }, /*#__PURE__*/React.createElement(Text, {
979
+ theme: "h1"
980
+ }, "Base Stake"), /*#__PURE__*/React.createElement(Text, {
981
+ theme: "description",
982
+ style: {
983
+ marginTop: 3
984
+ }
985
+ }, "Fill responses with a base stake based on their probabilities.")), /*#__PURE__*/React.createElement(TextInput, {
986
+ value: base_stake,
987
+ editable: settings_edit_allowed,
988
+ style: {
989
+ width: 75,
990
+ textAlign: 'center'
991
+ },
992
+ onFocusPosition: onFocusPosition,
993
+ onChangeText: text => setLabels({
994
+ ...labels,
995
+ base_stake: text
996
+ })
997
+ }), base_stake_changed && poll?.status == 'pending' ? /*#__PURE__*/React.createElement(Button, {
998
+ title: "SAVE",
999
+ type: "success",
1000
+ onPress: () => {
1001
+ let num = parseFloat(base_stake);
1002
+ if (isNaN(num)) {
1003
+ return alert('Invalid value');
1004
+ }
1005
+ if (num < 0) {
1006
+ return alert('Invalid amount');
1007
+ }
1008
+ updatePoll({
1009
+ ...draft_poll,
1010
+ base_stake: parseFloat(base_stake)
1011
+ });
1012
+ }
1013
+ }) : /*#__PURE__*/React.createElement(React.Fragment, null)) : /*#__PURE__*/React.createElement(React.Fragment, null), /*#__PURE__*/React.createElement(View, {
1014
+ transparent: true,
1015
+ type: "row",
1016
+ style: {
1017
+ padding: 20,
1018
+ borderBottomWidth: 1,
1019
+ borderColor: Colors.borders.light
1020
+ }
1021
+ }, /*#__PURE__*/React.createElement(View, {
1022
+ transparent: true,
1023
+ style: {
1024
+ flex: 1,
1025
+ marginRight: 10
1026
+ }
1027
+ }, /*#__PURE__*/React.createElement(Text, {
1028
+ theme: "h1"
1029
+ }, "Minimum Stake Allowed"), /*#__PURE__*/React.createElement(Text, {
1030
+ theme: "description",
1031
+ style: {
1032
+ marginTop: 3
1033
+ }
1034
+ }, "The smallest bet allowed to be placed on this market.")), /*#__PURE__*/React.createElement(TextInput, {
1035
+ value: min_stake,
1036
+ editable: settings_edit_allowed,
1037
+ onFocus: () => min_stake == '0' ? setLabels({
1038
+ ...labels,
1039
+ min_stake: ''
1040
+ }) : console.log(''),
1041
+ style: {
1042
+ width: 75,
1043
+ textAlign: 'center'
1044
+ },
1045
+ onFocusPosition: onFocusPosition,
1046
+ onChangeText: text => setLabels({
1047
+ ...labels,
1048
+ min_stake: text
1049
+ })
1050
+ }), min_stake_changed ? /*#__PURE__*/React.createElement(Button, {
1051
+ title: "SAVE",
1052
+ type: "success",
1053
+ onPress: () => {
1054
+ let num = parseFloat(min_stake);
1055
+ if (isNaN(num)) {
1056
+ return alert('Invalid value');
1057
+ }
1058
+ if (num < 0) {
1059
+ return alert('Invalid amount');
1060
+ }
1061
+ updatePoll({
1062
+ ...draft_poll,
1063
+ minimum_stake: parseFloat(min_stake)
1064
+ });
1065
+ }
1066
+ }) : /*#__PURE__*/React.createElement(React.Fragment, null)), /*#__PURE__*/React.createElement(View, {
1067
+ transparent: true,
1068
+ type: "row",
1069
+ style: {
1070
+ padding: 20,
1071
+ borderBottomWidth: 1,
1072
+ borderColor: Colors.borders.light
1073
+ }
1074
+ }, /*#__PURE__*/React.createElement(View, {
1075
+ transparent: true,
1076
+ style: {
1077
+ flex: 1,
1078
+ marginRight: 10
1079
+ }
1080
+ }, /*#__PURE__*/React.createElement(Text, {
1081
+ theme: "h1"
1082
+ }, "Max Stake Allowed"), /*#__PURE__*/React.createElement(Text, {
1083
+ theme: "description",
1084
+ style: {
1085
+ marginTop: 3
1086
+ }
1087
+ }, "The largest bet allowed to be placed on this market.")), /*#__PURE__*/React.createElement(TextInput, {
1088
+ value: max_stake,
1089
+ editable: settings_edit_allowed,
1090
+ onFocus: () => max_stake == '0' ? setLabels({
1091
+ ...labels,
1092
+ max_stake: ''
1093
+ }) : console.log(''),
1094
+ style: {
1095
+ width: 75,
1096
+ textAlign: 'center'
1097
+ },
1098
+ onFocusPosition: onFocusPosition,
1099
+ onChangeText: text => setLabels({
1100
+ ...labels,
1101
+ max_stake: text
1102
+ })
1103
+ }), max_stake_changed ? /*#__PURE__*/React.createElement(Button, {
1104
+ title: "SAVE",
1105
+ type: "success",
1106
+ onPress: () => {
1107
+ let num = parseFloat(max_stake);
1108
+ if (isNaN(num)) {
1109
+ return alert('Invalid value');
1110
+ }
1111
+ if (num < 0) {
1112
+ return alert('Invalid amount');
1113
+ }
1114
+ updatePoll({
1115
+ ...draft_poll,
1116
+ max_stake: parseFloat(max_stake)
1117
+ });
1118
+ }
1119
+ }) : /*#__PURE__*/React.createElement(React.Fragment, null)), /*#__PURE__*/React.createElement(View, {
1120
+ transparent: true,
1121
+ type: "row",
1122
+ style: {
1123
+ padding: 20,
1124
+ borderBottomWidth: 1,
1125
+ borderColor: Colors.borders.light
1126
+ }
1127
+ }, /*#__PURE__*/React.createElement(View, {
1128
+ transparent: true,
1129
+ style: {
1130
+ flex: 1,
1131
+ marginRight: 10
1132
+ }
1133
+ }, /*#__PURE__*/React.createElement(Text, {
1134
+ theme: "h1"
1135
+ }, "Allow Multiple Responses"), /*#__PURE__*/React.createElement(Text, {
1136
+ theme: "description",
1137
+ style: {
1138
+ marginTop: 3
1139
+ }
1140
+ }, "If on, players can select multiple options.")), /*#__PURE__*/React.createElement(Switch, {
1141
+ switch_type: "on_off",
1142
+ disabled: settings_edit_allowed ? false : true,
1143
+ value: draft_poll.multi_responses_allowed ?? false,
1144
+ onChange: async val => {
1145
+ updatePoll({
1146
+ ...draft_poll,
1147
+ multi_responses_allowed: val
1148
+ });
1149
+ }
1150
+ })), /*#__PURE__*/React.createElement(View, {
1151
+ transparent: true,
1152
+ type: "row",
1153
+ style: {
1154
+ padding: 20,
1155
+ borderBottomWidth: 1,
1156
+ borderColor: Colors.borders.light
1157
+ }
1158
+ }, /*#__PURE__*/React.createElement(View, {
1159
+ transparent: true,
1160
+ style: {
1161
+ flex: 1,
1162
+ marginRight: 10
1163
+ }
1164
+ }, /*#__PURE__*/React.createElement(Text, {
1165
+ theme: "h1"
1166
+ }, "Allow Increase Stake"), /*#__PURE__*/React.createElement(Text, {
1167
+ theme: "description",
1168
+ style: {
1169
+ marginTop: 3
1170
+ }
1171
+ }, "If on, players can continue to add more funds to a selected option.")), /*#__PURE__*/React.createElement(Switch, {
1172
+ switch_type: "on_off",
1173
+ disabled: settings_edit_allowed ? false : true,
1174
+ value: draft_poll.stake_increase_allowed ?? false,
1175
+ onChange: async val => {
1176
+ updatePoll({
1177
+ ...draft_poll,
1178
+ stake_increase_allowed: val
1179
+ });
1180
+ }
1181
+ })), /*#__PURE__*/React.createElement(View, {
1182
+ transparent: true,
1183
+ type: "row",
1184
+ style: {
1185
+ padding: 20,
1186
+ borderBottomWidth: 1,
1187
+ borderColor: Colors.borders.light
1188
+ }
1189
+ }, /*#__PURE__*/React.createElement(View, {
1190
+ transparent: true,
1191
+ style: {
1192
+ flex: 1,
1193
+ marginRight: 10
1194
+ }
1195
+ }, /*#__PURE__*/React.createElement(Text, {
1196
+ theme: "h1"
1197
+ }, "Flash Close Time"), /*#__PURE__*/React.createElement(Text, {
1198
+ theme: "description",
1199
+ style: {
1200
+ marginTop: 3
1201
+ }
1202
+ }, "When should this market close?")), /*#__PURE__*/React.createElement(BETimePicker, {
1203
+ selected_time: moment(poll?.end_datetime),
1204
+ disabled: settings_edit_allowed ? false : true,
1205
+ onSelectTime: val => {
1206
+ updatePoll({
1207
+ ...draft_poll,
1208
+ end_datetime: val
1209
+ });
1210
+ }
1211
+ })));
1212
+ default:
1213
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
1214
+ }
1215
+ };
1216
+ return /*#__PURE__*/React.createElement(View, {
1217
+ float: float,
1218
+ style: {
1219
+ flex: 1
1220
+ }
1221
+ }, /*#__PURE__*/React.createElement(View, {
1222
+ transparent: true,
1223
+ style: {
1224
+ flex: 1
1225
+ }
1226
+ }, /*#__PURE__*/React.createElement(FlatList, {
1227
+ data: sections
1228
+ //keyboardShouldPersistTaps
1229
+ ,
1230
+ key: "flash_market_sections",
1231
+ keyExtractor: item => item,
1232
+ renderItem: renderSections
1233
+ })));
1234
+ };
1235
+ export default ManageFlashMarket;
1236
+ //# sourceMappingURL=ManageFlashMarket.js.map